From d6d092a90e978dac37a08a6930ed1e0358ead6bc Mon Sep 17 00:00:00 2001 From: Beliy Nikita Date: Tue, 24 Dec 2024 14:06:09 +0100 Subject: [PATCH] Removed unessesary copyRawFile in modules --- bidsme/Modules/EEG/EDF.py | 128 ------------------------------ bidsme/Modules/MRI/NIFTI.py | 12 --- bidsme/Modules/MRI/bidsmeNIFTI.py | 11 --- bidsme/Modules/MRI/hmriNIFTI.py | 12 --- bidsme/Modules/MRI/jsonNIFTI.py | 11 --- bidsme/Modules/MRS/NIFTI.py | 12 --- bidsme/Modules/MRS/jsonNIFTI.py | 11 --- bidsme/Modules/PET/bidsmeNIFTI.py | 11 --- bidsme/Modules/PET/jsonNIFTI.py | 11 --- 9 files changed, 219 deletions(-) diff --git a/bidsme/Modules/EEG/EDF.py b/bidsme/Modules/EEG/EDF.py index f7aaa07..f0cb999 100644 --- a/bidsme/Modules/EEG/EDF.py +++ b/bidsme/Modules/EEG/EDF.py @@ -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") -""" diff --git a/bidsme/Modules/MRI/NIFTI.py b/bidsme/Modules/MRI/NIFTI.py index 852a92f..7c4bb91 100644 --- a/bidsme/Modules/MRI/NIFTI.py +++ b/bidsme/Modules/MRI/NIFTI.py @@ -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(), diff --git a/bidsme/Modules/MRI/bidsmeNIFTI.py b/bidsme/Modules/MRI/bidsmeNIFTI.py index 9795ed7..41dd8a2 100644 --- a/bidsme/Modules/MRI/bidsmeNIFTI.py +++ b/bidsme/Modules/MRI/bidsmeNIFTI.py @@ -24,7 +24,6 @@ import os import logging -import shutil import json from datetime import datetime @@ -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"] diff --git a/bidsme/Modules/MRI/hmriNIFTI.py b/bidsme/Modules/MRI/hmriNIFTI.py index 7f3aafe..27c3563 100644 --- a/bidsme/Modules/MRI/hmriNIFTI.py +++ b/bidsme/Modules/MRI/hmriNIFTI.py @@ -26,7 +26,6 @@ import os import logging import json -import shutil import pprint from datetime import datetime, timedelta @@ -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")) diff --git a/bidsme/Modules/MRI/jsonNIFTI.py b/bidsme/Modules/MRI/jsonNIFTI.py index aaa2773..970f2d0 100644 --- a/bidsme/Modules/MRI/jsonNIFTI.py +++ b/bidsme/Modules/MRI/jsonNIFTI.py @@ -24,7 +24,6 @@ import os import logging -import shutil import json from datetime import datetime @@ -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", "") diff --git a/bidsme/Modules/MRS/NIFTI.py b/bidsme/Modules/MRS/NIFTI.py index 94d78ab..caa83a9 100644 --- a/bidsme/Modules/MRS/NIFTI.py +++ b/bidsme/Modules/MRS/NIFTI.py @@ -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(), diff --git a/bidsme/Modules/MRS/jsonNIFTI.py b/bidsme/Modules/MRS/jsonNIFTI.py index 9e7a48d..0f91ad1 100644 --- a/bidsme/Modules/MRS/jsonNIFTI.py +++ b/bidsme/Modules/MRS/jsonNIFTI.py @@ -24,7 +24,6 @@ import os import logging -import shutil import json from datetime import datetime from copy import copy @@ -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", "") diff --git a/bidsme/Modules/PET/bidsmeNIFTI.py b/bidsme/Modules/PET/bidsmeNIFTI.py index 6c03424..7c9df42 100644 --- a/bidsme/Modules/PET/bidsmeNIFTI.py +++ b/bidsme/Modules/PET/bidsmeNIFTI.py @@ -29,7 +29,6 @@ import os import logging -import shutil import json from datetime import datetime @@ -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"] diff --git a/bidsme/Modules/PET/jsonNIFTI.py b/bidsme/Modules/PET/jsonNIFTI.py index 2e2a46d..c31f313 100644 --- a/bidsme/Modules/PET/jsonNIFTI.py +++ b/bidsme/Modules/PET/jsonNIFTI.py @@ -27,7 +27,6 @@ import os import logging -import shutil import json from datetime import datetime @@ -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