Skip to content

Commit

Permalink
Removed unessesary copyRawFile in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Beliy Nikita committed Dec 24, 2024
1 parent 726c5f1 commit d6d092a
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 219 deletions.
128 changes: 0 additions & 128 deletions bidsme/Modules/EEG/EDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,131 +299,3 @@ def _adaptMetaField(self, field):
else:
return "epoched"
return None


"""
def copyRawFile(self, destination: str) -> None:
base = os.path.splitext(self.currentFile(True))[0]
dest_base = os.path.join(destination, base)
# Copiyng header
shutil.copy2(self.currentFile(), destination)
dig = self._CACHE.info['dig']
orient = _MNE.ORIENTATION.get(self._ext, 'n/a')
unit = _MNE.UNITS.get(self._ext, 'n/a')
manufacturer = _MNE.MANUFACTURERS.get(self._ext, 'n/a')
if dig:
# exporting coord system
coords = dict()
landmarks = {d['ident']: d for d in dig
if d['kind'] == FIFF.FIFFV_POINT_CARDINAL}
if landmarks:
if FIFF.FIFFV_POINT_NASION in landmarks:
coords['NAS'] = landmarks[FIFF.FIFFV_POINT_NASION]['r']\
.tolist()
if FIFF.FIFFV_POINT_LPA in landmarks:
coords['LPA'] = landmarks[FIFF.FIFFV_POINT_LPA]['r']\
.tolist()
if FIFF.FIFFV_POINT_RPA in landmarks:
coords['RPA'] = landmarks[FIFF.FIFFV_POINT_RPA]['r']\
.tolist()
hpi = {d['ident']: d for d in dig
if d['kind'] == FIFF.FIFFV_POINT_HPI}
if hpi:
for ident in hpi.keys():
coords['coil%d' % ident] = hpi[ident]['r'].tolist()
coord_frame = set([dig[ii]['coord_frame']
for ii in range(len(dig))])
if len(coord_frame) > 1:
raise ValueError('All HPI, electrodes, and fiducials '
'must be in the '
'same coordinate frame. Found: "{}"'
.format(coord_frame))
coordsystem_desc = _MNE.COORD_FRAME_DESCRIPTIONS\
.get(coord_frame[0], "n/a")
fid_json = {
'CoordinateSystem': coord_frame[0],
'CoordinateUnits': unit,
'CoordinateSystemDescription': coordsystem_desc,
'Coordinates': coords,
'LandmarkCoordinateSystem': orient,
'LandmarkCoordinateUnits': unit
}
json.dump(dest_base + "_coordsystem.json", fid_json)
# exporting electrodes
elec = self._elec_BIDS.GetTemplate()
with open(dest_base + "_electrodes.tsv", "w") as f:
f.write(self._elec_BIDS.GetHeader() + "\n")
for ch in self._CACHE.info['chs']:
elec["name"] = ch['ch_name']
if mne.utils_check_ch_locs([ch]):
elec["x"] = ch['loc'][0]
elec["y"] = ch['loc'][1]
elec["z"] = ch['loc'][2]
else:
elec["x"] = None
elec["y"] = None
elec["z"] = None
f.write(self._elec_BIDS.GetLine(elec) + "\n")
self._elec_BIDS.DumpDefinitions(dest_base + "_electrodes.json")
# exporting channels
channels = self._chan_BIDS.GetTemplate()
with open(dest_base + "_channels.tsv", "w") as f:
f.write(self._chan_BIDS.GetHeader() + "\n")
for idx, ch in enumerate(self._CACHE.info['chs']):
channels["name"] = ch["ch_name"]
ch_type = mne.io.pick.channel_type(self._CACHE.info, idx)
if ch_type in ('mag', 'ref_meg', 'grad'):
ch_type = _MNE.COIL_TYPES_MNE.get(ch['coil_type'], ch_type)
channels["type"] = _MNE.CHANNELS_TYPE_MNE_BIDS.get(ch_type)
if ch["ch_name"] in self._CACHE.info['bads']:
channels["status"] = "bad"
else:
channels["status"] = "good"
channels["low_cutoff"] = self._CACHE.info["highpass"]
channels["high_cutoff"] = self._CACHE.info["lowpass"]
if self._CACHE._orig_units:
channels["units"] = self._CACHE._orig_units\
.get(channels["name"])
channels["sampling_frequency"] = self._CACHE.info["sfreq"]
f.write(self._chan_BIDS.GetLine(channels) + "\n")
self._chan_BIDS.DumpDefinitions(dest_base + "_channels.json")
# exporting markers
events = self._chan_BIDS.GetTemplate()
with open(dest_base + "_events.tsv", "w") as f:
sfreq = self._CACHE.info['sfreq']
first_time = self._CACHE.first_time
evts = self._CACHE.annotations
f.write(self._task_BIDS.GetHeader() + "\n")
events = self._task_BIDS.GetTemplate()
for ev in evts:
events["onset"] = ev["onset"] - first_time
events["duration"] = ev["duration"]
events["trial_type"] = ev["description"]
events["sample"] = int(events["onset"] * sfreq)
f.write(self._task_BIDS.GetLine(events) + "\n")
# stimulus channels
first_samp = self._CACHE.first_samp
for ch in self._CACHE.info["chs"]:
if ch["kind"] != "sitm":
continue
evts = mne.find_events(self._CACHE, stim_channel=ch["ch_name"])
for ev in evts:
events["onset"] = (ev['onset'] - first_samp) / sfreq
events["duration"] = 0
events["trial_type"] = ch["ch_name"]
events["value"] = ev[2]
events["sample"] = ev["onset"] - first_samp
f.write(self._task_BIDS.GetLine(events) + "\n")
self._task_BIDS.DumpDefinitions(dest_base + "_events.json")
"""
12 changes: 0 additions & 12 deletions bidsme/Modules/MRI/NIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@ def _getField(self, field: list):
res = None
return res

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
if self._nii_type == "ni1":
data_file = tools.change_ext(self.currentFile(), "img")
shutil.copy2(data_file, destination)
return os.path.join(destination, self.currentFile(True))

def _copy_bidsified(self, directory: str, bidsname: str, ext: str) -> None:
if self._nii_type == "ni1":
shutil.copy2(self.currentFile(),
Expand Down
11 changes: 0 additions & 11 deletions bidsme/Modules/MRI/bidsmeNIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import os
import logging
import shutil
import json
from datetime import datetime

Expand Down Expand Up @@ -162,16 +161,6 @@ def clearCache(self) -> None:
self._HEADER_CACHE = None
self._FILE_CACHE = ""

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
shutil.copy2(self._header_file, destination)
return os.path.join(destination, self.currentFile(True))

def _getSubId(self) -> str:
return self._headerData["subId"]

Expand Down
12 changes: 0 additions & 12 deletions bidsme/Modules/MRI/hmriNIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import os
import logging
import json
import shutil
import pprint
from datetime import datetime, timedelta

Expand Down Expand Up @@ -226,17 +225,6 @@ def clearCache(self) -> None:
self._DICOMDICT_CACHE = None
self._DICOMFILE_CACHE = ""

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
shutil.copy2(tools.change_ext(self.currentFile(), "json"),
destination)
return os.path.join(destination, self.currentFile(True))

def _getSubId(self) -> str:
return str(self.getField("PatientID"))

Expand Down
11 changes: 0 additions & 11 deletions bidsme/Modules/MRI/jsonNIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import os
import logging
import shutil
import json
from datetime import datetime

Expand Down Expand Up @@ -157,16 +156,6 @@ def clearCache(self) -> None:
self._HEADER_CACHE = None
self._FILE_CACHE = ""

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
shutil.copy2(self._header_file, destination)
return os.path.join(destination, self.currentFile(True))

def _getSubId(self) -> str:
return self.getField("PatientID", "")

Expand Down
12 changes: 0 additions & 12 deletions bidsme/Modules/MRS/NIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@ def _getField(self, field: list):
res = None
return res

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
if self._nii_type == "ni1":
data_file = tools.change_ext(self.currentFile(), "img")
shutil.copy2(data_file, destination)
return os.path.join(destination, self.currentFile(True))

def _copy_bidsified(self, directory: str, bidsname: str, ext: str) -> None:
if self._nii_type == "ni1":
shutil.copy2(self.currentFile(),
Expand Down
11 changes: 0 additions & 11 deletions bidsme/Modules/MRS/jsonNIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import os
import logging
import shutil
import json
from datetime import datetime
from copy import copy
Expand Down Expand Up @@ -164,16 +163,6 @@ def clearCache(self) -> None:
self._HEADER_CACHE = None
self._FILE_CACHE = ""

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
shutil.copy2(self._header_file, destination)
return os.path.join(destination, self.currentFile(True))

def _getSubId(self) -> str:
return self.getField("PatientID", "")

Expand Down
11 changes: 0 additions & 11 deletions bidsme/Modules/PET/bidsmeNIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import os
import logging
import shutil
import json
from datetime import datetime

Expand Down Expand Up @@ -165,16 +164,6 @@ def clearCache(self) -> None:
self._HEADER_CACHE = None
self._FILE_CACHE = ""

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
shutil.copy2(self._header_file, destination)
return os.path.join(destination, self.currentFile(True))

def _getSubId(self) -> str:
return self._headerData["subId"]

Expand Down
11 changes: 0 additions & 11 deletions bidsme/Modules/PET/jsonNIFTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import os
import logging
import shutil
import json
from datetime import datetime

Expand Down Expand Up @@ -151,16 +150,6 @@ def clearCache(self) -> None:
self._HEADER_CACHE = None
self._FILE_CACHE = ""

def copyRawFile(self, destination: str) -> str:
if os.path.isfile(os.path.join(destination,
self.currentFile(True))):
logger.warning("{}: File {} exists at destination"
.format(self.recIdentity(),
self.currentFile(True)))
shutil.copy2(self.currentFile(), destination)
shutil.copy2(self._header_file, destination)
return os.path.join(destination, self.currentFile(True))

def _getSubId(self) -> str:
tags = ["patient_id", # ecat header dump
"PatientID" # dcm2niix
Expand Down

0 comments on commit d6d092a

Please sign in to comment.