@@ -319,15 +319,42 @@ def plot_projs_topomap(self, ch_type=None, cmap=None,
319319 fig : instance of Figure
320320 Figure distributing one image per channel across sensor topography.
321321 """
322- if self .info ['projs' ] is not None or len (self .info ['projs' ]) != 0 :
323- from ..viz .topomap import plot_projs_topomap
324- fig = plot_projs_topomap (self .info ['projs' ], self .info , cmap = cmap ,
325- sensors = sensors , colorbar = colorbar ,
326- res = res , size = size , show = show ,
327- outlines = outlines , contours = contours ,
328- image_interp = image_interp , axes = axes ,
329- vlim = vlim , sphere = sphere ,
330- extrapolate = extrapolate , border = border )
322+ _projs = [deepcopy (_proj ) for _proj in self .info ['projs' ]]
323+ if _projs is not None and len (_projs ) > 0 :
324+ # XXX TODO FIXME there is probably a better way to do this ↓↓↓↓↓↓↓
325+ if ch_type is not None :
326+ _validate_type (ch_type , (str , list , tuple ), 'ch_type' )
327+ if isinstance (ch_type , str ):
328+ ch_type = [ch_type ]
329+ ch_type = np .array (ch_type )
330+ available_ch_types = np .array (self .get_channel_types ())
331+ bad_ch_types = np .isin (ch_type , available_ch_types ,
332+ invert = True )
333+ if any (bad_ch_types ):
334+ raise ValueError (
335+ f'ch_type { ch_type [bad_ch_types ]} not present in '
336+ f'{ self .__class__ .__name__ } .' )
337+ for _proj in _projs [::- 1 ]:
338+ idx = np .isin (self .ch_names , _proj ['data' ]['col_names' ])
339+ _ch_type = np .unique (available_ch_types [idx ])
340+ err_msg = 'Projector contains multiple channel types'
341+ assert len (_ch_type ) == 1 , err_msg
342+ if _ch_type [0 ] != ch_type :
343+ _projs .remove (_proj )
344+ # XXX TODO FIXME there is probably a better way to do this ↑↑↑↑↑↑↑
345+ if len (_projs ) > 0 :
346+ from ..viz .topomap import plot_projs_topomap
347+ fig = plot_projs_topomap (_projs , self .info , cmap = cmap ,
348+ sensors = sensors , colorbar = colorbar ,
349+ res = res , size = size , show = show ,
350+ outlines = outlines , contours = contours ,
351+ image_interp = image_interp , axes = axes ,
352+ vlim = vlim , sphere = sphere ,
353+ extrapolate = extrapolate ,
354+ border = border )
355+ else :
356+ raise ValueError ('Nothing to plot (no projectors for channel '
357+ f'type { ch_type } ).' )
331358 else :
332359 raise ValueError ("Info is missing projs. Nothing to plot." )
333360 return fig
0 commit comments