@@ -103,7 +103,7 @@ def write_probeinterface(file: Union[str, Path], probe_or_probegroup: Union[Prob
103103tsv_label_map_to_probeinterface = {v : k for k , v in tsv_label_map_to_BIDS .items ()}
104104
105105
106- def read_BIDS_probe (folder : Union [str , Path ], prefix : bool = None ) -> ProbeGroup :
106+ def read_BIDS_probe (folder : Union [str , Path ], prefix : Optional [ str ] = None ) -> ProbeGroup :
107107 """
108108 Read to BIDS probe format.
109109
@@ -114,7 +114,7 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: bool = None) -> ProbeGroup
114114 ----------
115115 folder: Path or str
116116 The folder to scan for probes and contacts files
117- prefix : None or str
117+ prefix : str
118118 Prefix of the probes and contacts files
119119
120120 Returns
@@ -140,8 +140,8 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: bool = None) -> ProbeGroup
140140 probes_file = probes_files [0 ]
141141 contacts_file = contacts_files [0 ]
142142 else :
143- probes_file = folder / prefix + " _probes.tsv"
144- contacts_file = folder / prefix + " _contacts.tsv"
143+ probes_file = folder / f" { prefix } _probes.tsv"
144+ contacts_file = folder / f" { prefix } _contacts.tsv"
145145 for file in [probes_file , contacts_file ]:
146146 if not file .exists ():
147147 raise ValueError (f"Source file does not exist ({ file } )" )
@@ -919,7 +919,8 @@ def write_csv(file, probe):
919919 },
920920}
921921
922- # Map imDatPrb_pn to imDatPrb_type (values from the meta file) when the latter is missing
922+
923+ # Map imDatPrb_pn (probe number) to imDatPrb_type (probe type) when the latter is missing
923924probe_number_to_probe_type = {
924925 "PRB_1_4_0480_1" : 0 ,
925926 "PRB_1_4_0480_1_C" : 0 ,
@@ -928,16 +929,17 @@ def write_csv(file, probe):
928929 "NP1030" : 1030 ,
929930 "NP1031" : 1031 ,
930931 "NP1032" : 1032 ,
932+ None : 0 ,
931933}
932934
933935
934- def read_imro (file : Union [str , Path ]) -> Probe :
936+ def read_imro (file_path : Union [str , Path ]) -> Probe :
935937 """
936938 Read probe position from the imro file used in input of SpikeGlx and Open-Ephys for neuropixels probes.
937939
938940 Parameters
939941 ----------
940- file : Path or str
942+ file_path : Path or str
941943 The .imro file path
942944
943945 Returns
@@ -946,14 +948,14 @@ def read_imro(file: Union[str, Path]) -> Probe:
946948
947949 """
948950 # the input is an imro file
949- meta_file = Path (file )
951+ meta_file = Path (file_path )
950952 assert meta_file .suffix == ".imro" , "'file' should point to the .imro file"
951953 with meta_file .open (mode = 'r' ) as f :
952954 imro_str = str (f .read ())
953955 return _read_imro_string (imro_str )
954956
955957
956- def _read_imro_string (imro_str : str , imDatPrb_pn : str = None ) -> Probe :
958+ def _read_imro_string (imro_str : str , imDatPrb_pn : Optional [ str ] = None ) -> Probe :
957959 """
958960 Parse the IMRO table when presented as a string and create a Probe object.
959961
@@ -984,8 +986,9 @@ def _read_imro_string(imro_str: str, imDatPrb_pn: str = None) -> Probe:
984986 elif len (imro_table_header ) == 2 :
985987 imDatPrb_type , num_contact = imro_table_header
986988 else :
987- raise RuntimeError (f'read_imro error, the header has a strange length: { imro_table_header } ' )
989+ raise ValueError (f'read_imro error, the header has a strange length: { imro_table_header } ' )
988990
991+
989992 if imDatPrb_type in [0 , None ]:
990993 imDatPrb_type = probe_number_to_probe_type [imDatPrb_pn ]
991994
@@ -1096,7 +1099,7 @@ def write_imro(file, probe):
10961099 f"({ data ['device_channel_indices' ][ch ]} { data ['shank_ids' ][ch ]} { annotations ['banks' ][ch ]} "
10971100 f"{ annotations ['references' ][ch ]} { data ['contact_ids' ][ch ][3 :]} )" )
10981101 else :
1099- raise RuntimeError (f'unknown imro type : { probe_type } ' )
1102+ raise ValueError (f'unknown imro type : { probe_type } ' )
11001103 with open (file , "w" ) as f :
11011104 f .write ('' .join (ret ))
11021105
0 commit comments