@@ -387,61 +387,71 @@ def parse_spikeglx_fname(fname):
387387 Consider the filenames: `Noise4Sam_g0_t0.nidq.bin` or `Noise4Sam_g0_t0.imec0.lf.bin`
388388 The filenames consist of 3 or 4 parts separated by `.`
389389 1. "Noise4Sam_g0_t0" will be the `name` variable. This choosen by the user at recording time.
390- 2. "_g0_ " is the "gate_num"
391- 3. "_t0_ " is the "trigger_num"
390+ 2. "g0 " is the "gate_num"
391+ 3. "t0 " is the "trigger_num"
392392 4. "nidq" or "imec0" will give the `device`
393393 5. "lf" or "ap" will be the `stream_kind`
394- `stream_name` variable is the concatenation of `device.stream_kind`
394+ `stream_name` variable is the concatenation of `device.stream_kind`
395+
396+ If CatGT is used, then the trigger numbers in the file names ("t0"/"t1"/etc.)
397+ will be renamed to "tcat". In this case, the parsed "trigger_num" will be set to "cat".
395398
396399 This function is copied/modified from Graham Findlay.
397400
398401 Notes:
399- * Sometimes the original file name is modified by the user and "_gt0_ " or "_t0_"
402+ * Sometimes the original file name is modified by the user and "_g0_ " or "_t0_"
400403 are manually removed. In that case gate_name and trigger_num will be None.
401404
402405 Parameters
403406 ---------
404407 fname: str
405408 The filename to parse without the extension, e.g. "my-run-name_g0_t1.imec2.lf"
409+
406410 Returns
407411 -------
408412 run_name: str
409413 The run name, e.g. "my-run-name".
410414 gate_num: int or None
411415 The gate identifier, e.g. 0.
412- trigger_num: int or None
413- The trigger identifier, e.g. 1.
416+ trigger_num: int | str or None
417+ The trigger identifier, e.g. 1. If CatGT is used, then the trigger_num will be set to "cat".
414418 device: str
415419 The probe identifier, e.g. "imec2"
416420 stream_kind: str or None
417421 The data type identifier, "lf" or "ap" or None
418422 """
419- r = re .findall (r"(\S*)_g(\d*)_t(\d*)\.(\S*).(ap|lf)" , fname )
420- if len (r ) == 1 :
423+ re_standard = re .findall (r"(\S*)_g(\d*)_t(\d*)\.(\S*).(ap|lf)" , fname )
424+ re_tcat = re .findall (r"(\S*)_g(\d*)_tcat.(\S*).(ap|lf)" , fname )
425+ re_nidq = re .findall (r"(\S*)_g(\d*)_t(\d*)\.(\S*)" , fname )
426+ if len (re_standard ) == 1 :
421427 # standard case with probe
422- run_name , gate_num , trigger_num , device , stream_kind = r [0 ]
428+ run_name , gate_num , trigger_num , device , stream_kind = re_standard [0 ]
429+ elif len (re_tcat ) == 1 :
430+ # tcat case
431+ run_name , gate_num , device , stream_kind = re_tcat [0 ]
432+ trigger_num = "cat"
433+ elif len (re_nidq ) == 1 :
434+ # case for nidaq
435+ run_name , gate_num , trigger_num , device = re_nidq [0 ]
436+ stream_kind = None
423437 else :
424- r = re .findall (r"(\S*)_g(\d*)_t(\d*)\.(\S*)" , fname )
425- if len (r ) == 1 :
426- # case for nidaq
427- run_name , gate_num , trigger_num , device = r [0 ]
428- stream_kind = None
438+ # the naming do not correspond lets try something more easy
439+ # example: sglx_xxx.imec0.ap
440+ re_else = re .findall (r"(\S*)\.(\S*).(ap|lf)" , fname )
441+ re_else_nidq = re .findall (r"(\S*)\.(\S*)" , fname )
442+ if len (re_else ) == 1 :
443+ run_name , device , stream_kind = re_else_nidq [0 ]
444+ gate_num , trigger_num = None , None
445+ elif len (re_else_nidq ) == 1 :
446+ # easy case for nidaq, example: sglx_xxx.nidq
447+ run_name , device = re_else_nidq [0 ]
448+ gate_num , trigger_num , stream_kind = None , None , None
429449 else :
430- # the naming do not correspond lets try something more easy
431- # example: sglx_xxx.imec0.ap
432- r = re .findall (r"(\S*)\.(\S*).(ap|lf)" , fname )
433- if len (r ) == 1 :
434- run_name , device , stream_kind = r [0 ]
435- gate_num , trigger_num = None , None
436- else :
437- # easy case for nidaq, example: sglx_xxx.nidq
438- r = re .findall (r"(\S*)\.(\S*)" , fname )
439- run_name , device = r [0 ]
440- gate_num , trigger_num , stream_kind = None , None , None
450+ raise ValueError (f"Cannot parse filename { fname } " )
441451
442452 if gate_num is not None :
443453 gate_num = int (gate_num )
444- if trigger_num is not None :
454+ if trigger_num is not None and trigger_num != "cat" :
445455 trigger_num = int (trigger_num )
446456
447457 return (run_name , gate_num , trigger_num , device , stream_kind )
0 commit comments