MCPcopy
hub / github.com/mne-tools/mne-python / _prep_data_for_plot

Function _prep_data_for_plot

mne/time_frequency/tfr.py:4243–4285  ·  view source on GitHub ↗
(
    data,
    times,
    freqs,
    *,
    tmin=None,
    tmax=None,
    fmin=None,
    fmax=None,
    baseline=None,
    mode=None,
    dB=False,
    taper_weights=None,
    verbose=None,
)

Source from the content-addressed store, hash-verified

4241
4242@verbose
4243def _prep_data_for_plot(
4244 data,
4245 times,
4246 freqs,
4247 *,
4248 tmin=None,
4249 tmax=None,
4250 fmin=None,
4251 fmax=None,
4252 baseline=None,
4253 mode=None,
4254 dB=False,
4255 taper_weights=None,
4256 verbose=None,
4257):
4258 # baseline
4259 copy = baseline is not None
4260 data = rescale(data, times, baseline, mode, copy=copy, verbose=verbose)
4261 # crop times
4262 time_mask = np.nonzero(_time_mask(times, tmin, tmax))[0]
4263 times = times[time_mask]
4264 # crop freqs
4265 freq_mask = np.nonzero(_time_mask(freqs, fmin, fmax))[0]
4266 freqs = freqs[freq_mask]
4267 # crop data
4268 data = data[..., freq_mask, :][..., time_mask]
4269 # handle unaggregated multitaper (complex or phase multitaper data)
4270 if taper_weights is not None: # assumes a taper dimension
4271 logger.info("Aggregating multitaper estimates before plotting...")
4272 if np.iscomplexobj(data): # complex coefficients → power
4273 data = _tfr_from_mt(data, taper_weights)
4274 else: # tapered phase data → weighted phase data
4275 # channels, tapers, freqs, time
4276 assert data.ndim == 4
4277 # weights as a function of (tapers, freqs)
4278 assert taper_weights.ndim == 2
4279 data = (data * taper_weights[np.newaxis, :, :, np.newaxis]).mean(axis=1)
4280 # handle remaining complex amplitude → real power
4281 if np.iscomplexobj(data):
4282 data = (data * data.conj()).real
4283 if dB:
4284 data = 10 * np.log10(data)
4285 return data, times, freqs
4286
4287
4288def _tfr_from_mt(x_mt, weights):

Callers 4

_onselectMethod · 0.85
plotMethod · 0.85
plot_jointMethod · 0.85
plot_topoMethod · 0.85

Calls 5

rescaleFunction · 0.85
_time_maskFunction · 0.85
_tfr_from_mtFunction · 0.85
infoMethod · 0.80
meanMethod · 0.45

Tested by

no test coverage detected