33import shutil
44from pathlib import Path
55import re
6+ from typing import Union , List
67
78import iblutil .io .params as params
89from one .alf .spec import is_uuid_string , is_session_path
@@ -346,6 +347,23 @@ def confirm_ephys_remote_folder(
346347 check_create_raw_session_flag (remote_session_path )
347348
348349
350+ def probe_labels_from_session_path (session_path : Union [str , Path ]) -> List [str ]:
351+ """
352+ Finds ephys probes according to the metadata spikeglx files. Only returns first subfolder
353+ name under raw_ephys_data folder, ie. raw_ephys_data/probe00/copy_of_probe00 won't be returned
354+ :param session_path:
355+ :return: list of strings
356+ """
357+ plabels = []
358+ raw_ephys_folder = session_path .joinpath ('raw_ephys_data' )
359+ for meta_file in raw_ephys_folder .rglob ('*.ap.meta' ):
360+ if meta_file .parents [1 ] != raw_ephys_folder :
361+ continue
362+ plabels .append (meta_file .parts [- 2 ])
363+ plabels .sort ()
364+ return plabels
365+
366+
349367def create_alyx_probe_insertions (
350368 session_path : str ,
351369 force : bool = False ,
@@ -363,24 +381,15 @@ def create_alyx_probe_insertions(
363381 pmodel = "3B2" if probe_model == "3B" else probe_model
364382 else :
365383 pmodel = model
366- raw_ephys_data_path = Path (session_path ) / "raw_ephys_data"
367- if labels is None :
368- probe_labels = [
369- x .name
370- for x in Path (raw_ephys_data_path ).glob ("*" )
371- if x .is_dir () and ("00" in x .name or "01" in x .name )
372- ]
373- else :
374- probe_labels = labels
375-
384+ labels = labels or probe_labels_from_session_path (session_path )
376385 # create the qc fields in the json field
377386 qc_dict = {}
378387 qc_dict .update ({"qc" : "NOT_SET" })
379388 qc_dict .update ({"extended_qc" : {}})
380389
381390 # create the dictionary
382391 insertions = []
383- for plabel in probe_labels :
392+ for plabel in labels :
384393 insdict = {"session" : eid , "name" : plabel , "model" : pmodel , "json" : qc_dict }
385394 # search for the corresponding insertion in Alyx
386395 alyx_insertion = one .alyx .get (f'/insertions?&session={ eid } &name={ plabel } ' , clobber = True )
0 commit comments