|
18 | 18 | from .probe import Probe |
19 | 19 | from .utils import import_safely |
20 | 20 |
|
| 21 | + |
| 22 | +global _np_probe_features |
| 23 | +_np_probe_features = None |
| 24 | + |
| 25 | +def _load_np_probe_features(): |
| 26 | + # this avoid loading the json several time |
| 27 | + global _np_probe_features |
| 28 | + if _np_probe_features is None: |
| 29 | + probe_features_filepath = Path(__file__).absolute().parent / Path("resources/neuropixels_probe_features.json") |
| 30 | + _np_probe_features = json.load(open(probe_features_filepath, "r")) |
| 31 | + return _np_probe_features |
| 32 | + |
21 | 33 | # Map imDatPrb_pn (probe number) to imDatPrb_type (probe type) when the latter is missing |
22 | 34 | # ONLY needed for `read_imro` function |
23 | 35 | probe_part_number_to_probe_type = { |
@@ -346,8 +358,7 @@ def _read_imro_string(imro_str: str, imDatPrb_pn: Optional[str] = None) -> Probe |
346 | 358 | # probe_type_num_chans looks like f"({probe_type},{num_chans}" |
347 | 359 | probe_type = probe_type_num_chans.split(",")[0][1:] |
348 | 360 |
|
349 | | - probe_features_filepath = Path(__file__).absolute().parent / Path("resources/probe_features.json") |
350 | | - probe_features = json.load(open(probe_features_filepath, "r")) |
| 361 | + probe_features = _load_np_probe_features() |
351 | 362 | pt_metadata, fields, mux_table = get_probe_metadata_from_probe_features(probe_features, imDatPrb_pn) |
352 | 363 |
|
353 | 364 | # fields = probe_description["fields_in_imro_table"] |
@@ -409,7 +420,7 @@ def get_probe_metadata_from_probe_features(probe_features: dict, imDatPrb_pn: st |
409 | 420 | Parameters |
410 | 421 | ---------- |
411 | 422 | probe_features : dict |
412 | | - Dictionary obtained when reading in the `probe_features.json` file. |
| 423 | + Dictionary obtained when reading in the `neuropixels_probe_features.json` file. |
413 | 424 | imDatPrb_pn : str |
414 | 425 | Probe part number. |
415 | 426 |
|
@@ -832,8 +843,7 @@ def read_openephys( |
832 | 843 | ) |
833 | 844 | return None |
834 | 845 |
|
835 | | - probe_features_filepath = Path(__file__).absolute().parent / Path("resources/probe_features.json") |
836 | | - probe_features = json.load(open(probe_features_filepath, "r")) |
| 846 | + probe_features = _load_np_probe_features() |
837 | 847 |
|
838 | 848 | # now load probe info from NP_PROBE fields |
839 | 849 | np_probes_info = [] |
|
0 commit comments