@@ -359,6 +359,22 @@ def _compute_opm_orientation_topomap_data(data, ch_names, pos, overlapping_chann
359359 ]
360360
361361
362+ def _should_use_opm_orientation_groups (info , picks , merge_channels , ch_type ):
363+ """Return whether OPM orientation grouping should be enabled.
364+
365+ Grouping is only used for OPM magnetometer channels with overlap sets that
366+ include at least 3 colocated channels (triaxial-style sensors).
367+ """
368+ if ch_type != "mag" or not merge_channels :
369+ return False
370+
371+ pick_chs = [info ["chs" ][pick ] for pick in picks ]
372+ if not pick_chs or not all (ch ["coil_type" ] in _opm_coils for ch in pick_chs ):
373+ return False
374+
375+ return any (len (overlap_set ) >= 3 for overlap_set in merge_channels )
376+
377+
362378def _plot_update_evoked_topomap (params , bools ):
363379 """Update topomaps."""
364380 from ..channels .layout import _merge_ch_data
@@ -1744,9 +1760,9 @@ def plot_ica_components(
17441760
17451761 axes = axes .flatten () if isinstance (axes , np .ndarray ) else axes
17461762 for k , picks in enumerate (pick_groups ):
1747- try : # either an iterable, 1D numpy array or others
1748- _axes = axes [ k * max_subplots : ( k + 1 ) * max_subplots ]
1749- except TypeError : # None or Axes
1763+ if axes is None :
1764+ _axes = None
1765+ else :
17501766 _axes = axes
17511767
17521768 (
@@ -1767,10 +1783,8 @@ def plot_ica_components(
17671783 data = np .atleast_2d (data )
17681784 data = data [:, data_picks ]
17691785
1770- use_opm_orientation_groups = (
1771- ch_type == "mag"
1772- and any (ch ["coil_type" ] in _opm_coils for ch in ica .info ["chs" ])
1773- and bool (merge_channels )
1786+ use_opm_orientation_groups = _should_use_opm_orientation_groups (
1787+ ica .info , data_picks , merge_channels , ch_type
17741788 )
17751789 n_group_axes = 2 if use_opm_orientation_groups else 1
17761790
@@ -2320,8 +2334,9 @@ def plot_evoked_topomap(
23202334 clip_origin ,
23212335 ) = _prepare_topomap_plot (evoked , ch_type , sphere = sphere )
23222336 outlines = _make_head_outlines (sphere , pos , outlines , clip_origin )
2323- is_opm = any (ch ["coil_type" ] in _opm_coils for ch in evoked .info ["chs" ])
2324- use_opm_orientation_groups = ch_type == "mag" and is_opm and bool (merge_channels )
2337+ use_opm_orientation_groups = _should_use_opm_orientation_groups (
2338+ evoked .info , picks , merge_channels , ch_type
2339+ )
23252340 # check interactive
23262341 axes_given = axes is not None
23272342 interactive = isinstance (times , str ) and times == "interactive"
@@ -2456,7 +2471,10 @@ def plot_evoked_topomap(
24562471 grouped_data = None
24572472 if merge_channels :
24582473 # check modality
2459- if is_opm :
2474+ is_opm_picks = len (picks ) > 0 and all (
2475+ evoked .info ["chs" ][pick ]["coil_type" ] in _opm_coils for pick in picks
2476+ )
2477+ if is_opm_picks :
24602478 modality = "opm"
24612479 elif ch_type in _fnirs_types :
24622480 modality = "fnirs"
0 commit comments