@@ -103,7 +103,7 @@ def write_probeinterface(file: Union[str, Path], probe_or_probegroup: Union[Prob
103
103
tsv_label_map_to_probeinterface = {v : k for k , v in tsv_label_map_to_BIDS .items ()}
104
104
105
105
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 :
107
107
"""
108
108
Read to BIDS probe format.
109
109
@@ -114,7 +114,7 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: bool = None) -> ProbeGroup
114
114
----------
115
115
folder: Path or str
116
116
The folder to scan for probes and contacts files
117
- prefix : None or str
117
+ prefix : str
118
118
Prefix of the probes and contacts files
119
119
120
120
Returns
@@ -140,8 +140,8 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: bool = None) -> ProbeGroup
140
140
probes_file = probes_files [0 ]
141
141
contacts_file = contacts_files [0 ]
142
142
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"
145
145
for file in [probes_file , contacts_file ]:
146
146
if not file .exists ():
147
147
raise ValueError (f"Source file does not exist ({ file } )" )
@@ -919,7 +919,8 @@ def write_csv(file, probe):
919
919
},
920
920
}
921
921
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
923
924
probe_number_to_probe_type = {
924
925
"PRB_1_4_0480_1" : 0 ,
925
926
"PRB_1_4_0480_1_C" : 0 ,
@@ -928,16 +929,17 @@ def write_csv(file, probe):
928
929
"NP1030" : 1030 ,
929
930
"NP1031" : 1031 ,
930
931
"NP1032" : 1032 ,
932
+ None : 0 ,
931
933
}
932
934
933
935
934
- def read_imro (file : Union [str , Path ]) -> Probe :
936
+ def read_imro (file_path : Union [str , Path ]) -> Probe :
935
937
"""
936
938
Read probe position from the imro file used in input of SpikeGlx and Open-Ephys for neuropixels probes.
937
939
938
940
Parameters
939
941
----------
940
- file : Path or str
942
+ file_path : Path or str
941
943
The .imro file path
942
944
943
945
Returns
@@ -946,14 +948,14 @@ def read_imro(file: Union[str, Path]) -> Probe:
946
948
947
949
"""
948
950
# the input is an imro file
949
- meta_file = Path (file )
951
+ meta_file = Path (file_path )
950
952
assert meta_file .suffix == ".imro" , "'file' should point to the .imro file"
951
953
with meta_file .open (mode = 'r' ) as f :
952
954
imro_str = str (f .read ())
953
955
return _read_imro_string (imro_str )
954
956
955
957
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 :
957
959
"""
958
960
Parse the IMRO table when presented as a string and create a Probe object.
959
961
@@ -984,8 +986,9 @@ def _read_imro_string(imro_str: str, imDatPrb_pn: str = None) -> Probe:
984
986
elif len (imro_table_header ) == 2 :
985
987
imDatPrb_type , num_contact = imro_table_header
986
988
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 } ' )
988
990
991
+
989
992
if imDatPrb_type in [0 , None ]:
990
993
imDatPrb_type = probe_number_to_probe_type [imDatPrb_pn ]
991
994
@@ -1096,7 +1099,7 @@ def write_imro(file, probe):
1096
1099
f"({ data ['device_channel_indices' ][ch ]} { data ['shank_ids' ][ch ]} { annotations ['banks' ][ch ]} "
1097
1100
f"{ annotations ['references' ][ch ]} { data ['contact_ids' ][ch ][3 :]} )" )
1098
1101
else :
1099
- raise RuntimeError (f'unknown imro type : { probe_type } ' )
1102
+ raise ValueError (f'unknown imro type : { probe_type } ' )
1100
1103
with open (file , "w" ) as f :
1101
1104
f .write ('' .join (ret ))
1102
1105
0 commit comments