1818from .probe import Probe
1919from .utils import import_safely
2020
21-
2221global _np_probe_features
2322_np_probe_features = None
2423
@@ -28,7 +27,8 @@ def _load_np_probe_features():
2827 global _np_probe_features
2928 if _np_probe_features is None :
3029 probe_features_filepath = Path (__file__ ).absolute ().parent / Path ("resources/neuropixels_probe_features.json" )
31- _np_probe_features = json .load (open (probe_features_filepath , "r" ))
30+ with open (probe_features_filepath , "r" ) as f :
31+ _np_probe_features = json .load (f )
3232 return _np_probe_features
3333
3434
@@ -92,8 +92,7 @@ def _load_np_probe_features():
9292
9393def get_probe_length (probe_part_number : str ) -> int :
9494 """
95- Returns the length of a given probe. We assume a length of
96- 1cm (10_000 microns) by default.
95+ Returns the length of a given probe from ProbeTable specifications.
9796
9897 Parameters
9998 ----------
@@ -103,12 +102,16 @@ def get_probe_length(probe_part_number: str) -> int:
103102 Returns
104103 -------
105104 probe_length : int
106- Length of full probe (microns)
105+ Length of full probe shank from tip to base (microns)
107106 """
107+ np_features = _load_np_probe_features ()
108+ probe_spec = np_features ["neuropixels_probes" ].get (probe_part_number )
108109
109- probe_length = 10_000
110+ if probe_spec is not None and "shank_tip_to_base_um" in probe_spec :
111+ return int (probe_spec ["shank_tip_to_base_um" ])
110112
111- return probe_length
113+ # Fallback for unknown probes or missing field
114+ return 10_000
112115
113116
114117def make_mux_table_array (mux_information ) -> np .array :
@@ -1218,7 +1221,6 @@ def read_openephys(
12181221 "probe" : sliced_probe ,
12191222 }
12201223 else :
1221-
12221224 channel_names = np .array (list (channels .attrib .keys ()))
12231225 channel_ids = np .array ([int (ch [2 :]) for ch in channel_names ])
12241226 channel_order = np .argsort (channel_ids )
@@ -1304,6 +1306,7 @@ def read_openephys(
13041306 np_probe_dict = {
13051307 "shank_ids" : shank_ids ,
13061308 "elec_ids" : elec_ids ,
1309+ "channel_names" : channel_names ,
13071310 "pt_metadata" : pt_metadata ,
13081311 "slot" : slot ,
13091312 "port" : port ,
@@ -1426,6 +1429,9 @@ def read_openephys(
14261429 pt_metadata , probe_part_number , elec_ids , shank_ids = shank_ids , mux_info = mux_info
14271430 )
14281431
1432+ if "channel_names" in np_probe_info :
1433+ probe .annotate_contacts (channel_name = np_probe_info ["channel_names" ])
1434+
14291435 chans_saved = get_saved_channel_indices_from_openephys_settings (settings_file , stream_name = stream_name )
14301436 if chans_saved is not None :
14311437 probe = probe .get_slice (chans_saved )
0 commit comments