@@ -87,7 +87,7 @@ def get_input_fnames_sync_eyelink(
8787 extension = ".fif" ,
8888 )
8989
90- et_bids_basename = BIDSPath (
90+ et_asc_bids_basename = BIDSPath (
9191 subject = subject ,
9292 session = session ,
9393 task = et_task ,
@@ -121,23 +121,30 @@ def get_input_fnames_sync_eyelink(
121121 )
122122 _update_for_splits (in_files , key , single = True )
123123
124-
125- key = f"et_run-{ run } "
126- in_files [key ] = et_bids_basename .copy ()
124+ et_bids_basename_temp = et_asc_bids_basename .copy ()
127125
128126 if cfg .et_has_run :
129- in_files [ key ] .update (run = run )
127+ et_bids_basename_temp .update (run = run )
130128
131129 # _update_for_splits(in_files, key, single=True) # TODO: Find out if we need to add this or not
132130
133- key = f"et_edf_run- { run } "
134- in_files [ key ] = et_edf_bids_basename . copy ( )
131+ if not os . path . isfile ( et_bids_basename_temp ):
132+ logger . info ( ** gen_log_kwargs ( message = f"Couldn't find { et_bids_basename_temp } file. If edf file exists, edf2asc will be called." ) )
135133
136- if cfg .et_has_run :
137- in_files [key ].update (run = run )
134+ et_bids_basename_temp = et_edf_bids_basename .copy ()
138135
139- # _update_for_splits(in_files, key, single=True) # TODO: Find out if we need to add this or not
140-
136+ if cfg .et_has_run :
137+ et_bids_basename_temp .update (run = run )
138+
139+ # _update_for_splits(in_files, key, single=True) # TODO: Find out if we need to add this or not
140+
141+ if not os .path .isfile (et_bids_basename_temp ):
142+ logger .error (** gen_log_kwargs (message = f"Also didn't find { et_bids_basename_temp } file, one of both needs to exist for ET sync." ))
143+ raise FileNotFoundError (f"For run { run } , could neither find .asc or .edf eye-tracking file. Please double-check the file names." )
144+
145+ key = f"et_run-{ run } "
146+ in_files [key ] = et_bids_basename_temp
147+
141148 return in_files
142149
143150
@@ -153,30 +160,33 @@ def sync_eyelink(
153160 session : str | None ,
154161 in_files : dict ,
155162) -> dict :
163+
156164 """Run Sync for Eyelink."""
157165 import matplotlib .pyplot as plt
158166 from scipy .signal import correlate
159167
160168 raw_fnames = [in_files .pop (f"raw_run-{ run } " ) for run in cfg .runs ]
161169 et_fnames = [in_files .pop (f"et_run-{ run } " ) for run in cfg .runs ]
162- et_edf_fnames = [in_files .pop (f"et_edf_run-{ run } " ) for run in cfg .runs ]
163170
164- logger .info (** gen_log_kwargs (message = f"et_fnames { et_fnames } " ))
171+ logger .info (** gen_log_kwargs (message = f"Found the following eye-tracking files: { et_fnames } " ))
165172 out_files = dict ()
166173 bids_basename = raw_fnames [0 ].copy ().update (processing = None , split = None , run = None )
167174 out_files ["eyelink" ] = bids_basename .copy ().update (processing = "eyelink" , suffix = "raw" )
168175 del bids_basename
169176
170- for idx , (run , raw_fname ,et_fname , et_edf_fname ) in enumerate (zip (cfg .runs , raw_fnames ,et_fnames , et_edf_fnames )):
171- msg = f"Syncing eyelink data (fake for now) { raw_fname .basename } "
177+ for idx , (run , raw_fname ,et_fname ) in enumerate (zip (cfg .runs , raw_fnames ,et_fnames )):
178+ msg = f"Syncing Eyelink ( { et_fname . basename } ) and EEG data ( { raw_fname .basename } ). "
172179 logger .info (** gen_log_kwargs (message = msg ))
173180 raw = mne .io .read_raw_fif (raw_fname , preload = True )
174- if not os .path .isfile (et_fname ):
175- logger .info (** gen_log_kwargs (message = f"Couldn't find { et_fname } file, trying to call edf2asc." ))
176- if not os .path .isfile (et_edf_fname ):
177- logger .error (** gen_log_kwargs (message = f"Also didn't find { et_edf_fname } file, one of both need to exist for ET sync." ))
181+
182+ et_format = et_fname .extension
183+
184+ if not et_format == '.asc' :
185+ assert et_format == '.edf' , "ET file is neither an `.asc` nor an `.edf`. This should not have happened."
186+ logger .info (** gen_log_kwargs (message = f"Converting { et_fname } file to `.asc` using edf2asc." ))
178187 import subprocess
179- subprocess .run (["edf2asc" , et_edf_fname ]) # TODO: Still needs to be tested
188+ subprocess .run (["edf2asc" , et_fname ]) # TODO: Still needs to be tested
189+ et_fname .update (extension = '.asc' )
180190
181191 raw_et = mne .io .read_raw_eyelink (et_fname , find_overlaps = True )
182192
0 commit comments