@@ -902,7 +902,7 @@ def _auto_topomap_coords(info, picks, ignore_overlap, to_sphere, sphere):
902902 # Use channel locations if available
903903 locs3d = np .array ([ch ["loc" ][:3 ] for ch in chs ])
904904
905- # If electrode locations are not available, use digization points
905+ # If electrode locations are not available, use digitization points
906906 if not _check_ch_locs (info = info , picks = picks ):
907907 logging .warning (
908908 "Did not find any electrode locations (in the info "
@@ -1089,7 +1089,7 @@ def _pair_grad_sensors(
10891089 return picks
10901090
10911091
1092- def _merge_ch_data (data , ch_type , names , method = "rms" ):
1092+ def _merge_ch_data (data , ch_type , names , method = "rms" , * , modality = "opm" ):
10931093 """Merge data from channel pairs.
10941094
10951095 Parameters
@@ -1102,6 +1102,8 @@ def _merge_ch_data(data, ch_type, names, method="rms"):
11021102 List of channel names.
11031103 method : str
11041104 Can be 'rms' or 'mean'.
1105+ modality : str
1106+ The modality of the data, either 'grad', 'fnirs', or 'opm'
11051107
11061108 Returns
11071109 -------
@@ -1112,9 +1114,13 @@ def _merge_ch_data(data, ch_type, names, method="rms"):
11121114 """
11131115 if ch_type == "grad" :
11141116 data = _merge_grad_data (data , method )
1115- else :
1116- assert ch_type in _FNIRS_CH_TYPES_SPLIT
1117+ elif modality == "fnirs" or ch_type in _FNIRS_CH_TYPES_SPLIT :
11171118 data , names = _merge_nirs_data (data , names )
1119+ elif modality == "opm" and ch_type == "mag" :
1120+ data , names = _merge_opm_data (data , names )
1121+ else :
1122+ raise ValueError (f"Unknown modality { modality } for channel type { ch_type } " )
1123+
11181124 return data , names
11191125
11201126
@@ -1180,6 +1186,37 @@ def _merge_nirs_data(data, merged_names):
11801186 return data , merged_names
11811187
11821188
1189+ def _merge_opm_data (data , merged_names ):
1190+ """Merge data from multiple opm channel by just using the radial component.
1191+
1192+ Channel names that end in "MERGE_REMOVE" (ie non-radial channels) will be
1193+ removed. Only the the radial channel is kept.
1194+
1195+ Parameters
1196+ ----------
1197+ data : array, shape = (n_channels, ..., n_times)
1198+ Data for channels.
1199+ merged_names : list
1200+ List of strings containing the channel names. Channels that are to be
1201+ removed end in "MERGE_REMOVE".
1202+
1203+ Returns
1204+ -------
1205+ data : array
1206+ Data for channels with requested channels merged. Channels used in the
1207+ merge are removed from the array.
1208+ """
1209+ to_remove = np .empty (0 , dtype = np .int32 )
1210+ for idx , ch in enumerate (merged_names ):
1211+ if ch .endswith ("MERGE-REMOVE" ):
1212+ to_remove = np .append (to_remove , idx )
1213+ to_remove = np .unique (to_remove )
1214+ for rem in sorted (to_remove , reverse = True ):
1215+ del merged_names [rem ]
1216+ data = np .delete (data , to_remove , axis = 0 )
1217+ return data , merged_names
1218+
1219+
11831220def generate_2d_layout (
11841221 xy ,
11851222 w = 0.07 ,
0 commit comments