@@ -593,54 +593,38 @@ def _read_imro_string(imro_str: str, imDatPrb_pn: Optional[str] = None) -> Probe
593593
594594 """
595595
596- probe_type_num_chans , * imro_table_values_list , _ = imro_str .strip ().split (")" )
596+ # Extract probe_type from the IMRO header "(probe_type,num_chans)"
597+ probe_type = imro_str .strip ().split (")" )[0 ].split ("," )[0 ][1 :]
597598
598- # probe_type_num_chans looks like f"({probe_type},{num_chans}"
599- probe_type = probe_type_num_chans . split ( "," )[ 0 ][ 1 :]
599+ # Parse the IMRO table into per-channel data (same parser used by read_spikeglx)
600+ imro_per_channel = _parse_imro_string ( imro_str , imDatPrb_pn )
600601
601- probe_features = _load_np_probe_features ()
602- pt_metadata , fields , mux_info = get_probe_metadata_from_probe_features ( probe_features , imDatPrb_pn )
602+ # Build full catalogue probe and slice to active electrodes
603+ full_probe = build_neuropixels_probe ( probe_part_number = imDatPrb_pn )
603604
604- # fields = probe_description["fields_in_imro_table"]
605- contact_info = {k : [] for k in fields }
606- for field_values_str in imro_table_values_list : # Imro table values look like '(value, value, value, ... '
607- # Split them by space to get int('value'), int('value'), int('value'), ...)
608- values = tuple (map (int , field_values_str [1 :].split (" " )))
609- for field , field_value in zip (fields , values ):
610- contact_info [field ].append (field_value )
605+ elec_ids = imro_per_channel ["electrode" ]
606+ shank_ids = imro_per_channel .get ("shank" , [None ] * len (elec_ids ))
607+ active_contact_ids = [
608+ _build_canonical_contact_id (elec_id , shank_id ) for shank_id , elec_id in zip (shank_ids , elec_ids )
609+ ]
611610
612- channel_ids = np .array (contact_info ["channel" ])
613- if "electrode" in contact_info :
614- elec_ids = np .array (contact_info ["electrode" ])
615- else :
616- if contact_info .get ("bank" ) is not None :
617- bank_key = "bank"
618- elif contact_info .get ("bank_mask" ) is not None :
619- bank_key = "bank_mask"
620- banks = np .array (contact_info [bank_key ])
621- elec_ids = banks * 384 + channel_ids
622-
623- if pt_metadata ["num_shanks" ] > 1 :
624- shank_ids = np .array (contact_info ["shank" ])
625- else :
626- shank_ids = None
611+ contact_id_to_index = {cid : i for i , cid in enumerate (full_probe .contact_ids )}
612+ selected_indices = np .array ([contact_id_to_index [cid ] for cid in active_contact_ids ])
613+ probe = full_probe .get_slice (selected_indices )
627614
628- probe = _make_npx_probe_from_description (pt_metadata , imDatPrb_pn , elec_ids , shank_ids , mux_info )
615+ # ADC sampling annotations
616+ adc_sampling_table = probe .annotations .get ("adc_sampling_table" )
617+ _annotate_probe_with_adc_sampling_info (probe , adc_sampling_table )
629618
630- # scalar annotations
631- probe .annotate (
632- probe_type = probe_type ,
633- )
619+ # Scalar annotations
620+ probe .annotate (probe_type = probe_type )
634621
635- # vector annotations
622+ # Vector annotations from IMRO fields
636623 vector_properties = ("channel" , "bank" , "bank_mask" , "ref_id" , "ap_gain" , "lf_gain" , "ap_hipas_flt" )
637-
638624 vector_properties_available = {}
639- for k , v in contact_info .items ():
640- if (k in vector_properties ) and (len (v ) > 0 ):
641- # convert to ProbeInterface naming for backwards compatibility
625+ for k , v in imro_per_channel .items ():
626+ if k in vector_properties and len (v ) > 0 :
642627 vector_properties_available [imro_field_to_pi_field .get (k )] = v
643-
644628 probe .annotate_contacts (** vector_properties_available )
645629
646630 return probe
0 commit comments