@@ -199,10 +199,9 @@ def read_BIDS_probe(folder: str | Path, prefix: str | None = None) -> ProbeGroup
199199
200200 # create probe object and register with probegroup
201201 probe = Probe .from_dataframe (df = df_probe )
202- probe .annotate (probe_id = probe_id )
203202
204203 probes [str (probe_id )] = probe
205- probegroup .add_probe (probe )
204+ probegroup .add_probe (probe , probe_id = str ( probe_id ) )
206205
207206 ignore_annotations = [
208207 "probe_ids" ,
@@ -322,7 +321,7 @@ def write_BIDS_probe(folder: str | Path, probe_or_probegroup: Probe | ProbeGroup
322321 probegroup = probe_or_probegroup
323322 else :
324323 raise TypeError (
325- f"probe_or_probegroup has to be" " of type Probe or ProbeGroup " f" not type: { type (probe_or_probegroup )} "
324+ f"probe_or_probegroup has to be of type Probe or ProbeGroup not type: { type (probe_or_probegroup )} "
326325 )
327326 folder = Path (folder )
328327
@@ -333,22 +332,12 @@ def write_BIDS_probe(folder: str | Path, probe_or_probegroup: Probe | ProbeGroup
333332 probes = probegroup .probes
334333
335334 # Step 1: GENERATION OF PROBE.TSV
336- # ensure required keys (probe_id, probe_type) are present
337-
338- if any ("probe_id" not in p .annotations for p in probes ):
339- probegroup .auto_generate_probe_ids ()
335+ # ensure required keys (probe_type) are present
340336
341337 for probe in probes :
342- if "probe_id" not in probe .annotations :
343- raise ValueError (
344- "Export to BIDS probe format requires "
345- "the probe id to be specified as an annotation "
346- "(probe_id). You can do this via "
347- "`probegroup.auto_generate_ids."
348- )
349338 if "type" not in probe .annotations :
350339 raise ValueError (
351- "Export to BIDS probe format requires " " the probe type to be specified as an " " annotation (type)"
340+ "Export to BIDS probe format requires the probe type to be specified as an annotation (type)"
352341 )
353342
354343 # extract all used annotation keys
@@ -357,11 +346,12 @@ def write_BIDS_probe(folder: str | Path, probe_or_probegroup: Probe | ProbeGroup
357346 annotation_keys = np .unique (keys_concatenated )
358347
359348 # generate a tsv table capturing probe information
360- index = range (len ([ p . annotations [ "probe_id" ] for p in probes ] ))
349+ index = range (len (probes ))
361350 df = pd .DataFrame (index = index )
362351 for annotation_key in annotation_keys :
363352 df [annotation_key ] = [p .annotations [annotation_key ] for p in probes ]
364353 df ["n_shanks" ] = [len (np .unique (p .shank_ids )) for p in probes ]
354+ df ["probe_id" ] = probegroup .probe_ids
365355
366356 # Note: in principle it would also be possible to add the probe width and
367357 # depth here based on the probe contour information. However this would
@@ -374,8 +364,7 @@ def write_BIDS_probe(folder: str | Path, probe_or_probegroup: Probe | ProbeGroup
374364
375365 # Step 2: GENERATION OF PROBE.JSON
376366 probes_dict = {}
377- for probe in probes :
378- probe_id = probe .annotations ["probe_id" ]
367+ for probe_id , probe in zip (probegroup .probe_ids , probes ):
379368 probes_dict [probe_id ] = {
380369 "contour" : probe .probe_planar_contour .tolist (),
381370 "units" : probe .si_units ,
@@ -399,7 +388,7 @@ def write_BIDS_probe(folder: str | Path, probe_or_probegroup: Probe | ProbeGroup
399388 index = range (sum ([p .get_contact_count () for p in probes ]))
400389 df .rename (columns = tsv_label_map_to_BIDS , inplace = True )
401390
402- df ["probe_id" ] = [p . annotations [ " probe_id" ] for p in probes for _ in p .contact_ids ]
391+ df ["probe_id" ] = [probe_id for probe_id , probe in zip ( probegroup . probe_ids , probes ) for _ in probe .contact_ids ]
403392 df ["coordinate_system" ] = ["relative cartesian" ] * len (index )
404393
405394 channel_indices = []
0 commit comments