Skip to content

Commit 7913807

Browse files
committed
to solve some changes in file saving convention by wse
1 parent 14543de commit 7913807

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

visual_behavior/ophys/io/convert_level_1_to_level_2.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,18 @@ def get_roi_group(lims_data):
190190
def get_sync_path(lims_data):
191191
ophys_session_dir = get_ophys_session_dir(lims_data)
192192
analysis_dir = get_analysis_dir(lims_data)
193-
# try getting sync file from analysis folder first - needed for early mesoscope data where lims sync file is missing line labels
194-
try:
195-
logger.info('using sync file from analysis directory instead of lims')
196-
sync_file = [file for file in os.listdir(analysis_dir) if 'sync' in file][0]
197-
sync_path = os.path.join(analysis_dir, sync_file)
198-
except Exception as e:
199-
print(e)
200-
sync_file = [file for file in os.listdir(ophys_session_dir) if 'sync' in file][0]
201-
sync_path = os.path.join(ophys_session_dir, sync_file)
193+
194+
# First attempt
195+
sync_file = [file for file in os.listdir(ophys_session_dir) if 'sync' in file]
196+
if len(sync_file)>0:
197+
sync_file = sync_file[0]
198+
else:
199+
json_path = [file for file in os.listdir(ophys_session_dir) if '_platform.json' in file][0]
200+
with open(os.path.join(ophys_session_dir, json_path)) as pointer_json:
201+
json_data = json.load(pointer_json)
202+
sync_file = json_data['sync_file']
203+
sync_path = os.path.join(ophys_session_dir, sync_file)
204+
202205
if sync_file not in os.listdir(analysis_dir):
203206
logger.info('moving %s to analysis dir', sync_file) # flake8: noqa: E999
204207
shutil.copy2(sync_path, os.path.join(analysis_dir, sync_file))
@@ -373,7 +376,7 @@ def save_metadata(metadata, lims_data):
373376
def get_stimulus_pkl_path(lims_data):
374377
ophys_session_dir = get_ophys_session_dir(lims_data)
375378
# first try lims folder
376-
pkl_file = [file for file in os.listdir(ophys_session_dir) if 'stim.pkl' in file]
379+
pkl_file = [file for file in os.listdir(ophys_session_dir) if '.pkl' in file]
377380
if len(pkl_file) > 0:
378381
stimulus_pkl_path = os.path.join(ophys_session_dir, pkl_file[0])
379382
else: # then try behavior directory

0 commit comments

Comments
 (0)