def evoked_ndvar(evoked, name='MEG'): "Convert an mne Evoked object of a list thereof to an ndvar" if isinstance(evoked, mne.fiff.Evoked): x = evoked.data dims = () else: x = np.array([e.data for e in evoked]) dims = ('case',) evoked = evoked[0] sensor = sensor_net(evoked) time = var(evoked.times, name='time') properties = {'colorspace': _cs.get_MEG(2e-13)} return ndvar(x, dims + (sensor, time), properties=properties, name=name)
def defaultColorspace(self, vmax='auto', vmin='auto', **kwargs): "When symmetric, vmax is more important" if vmax == 'auto': vmax = np.max(np.abs(self.data)) kwargs['vmax'] = vmax if vmin != 'auto': kwargs['vmin'] = vmin if self.ndim=='wavelet': raise NotImplementedError else: return _cs.get_MEG(**kwargs)
""" # create the time dimension T = var(np.arange(-.2, .8, .01), name='time') # random data x = np.random.normal(0,1,(30,5,len(T))) # add an effect to the random data x[15:,:3,20:40] += np.hanning(20) * 2 # create the sensor dimension from 5 sensor locations in 3d space sensor = sensor_net([[0,0,0],[1,0,0],[0,-1,0],[-1,0,0],[0,1,0]], name='testnet', transform_2d=None) # combine all these into the ndvar Y = ndvar(x, dims=('case', sensor, T), name='Y', properties={'samplingrate':100, 'colorspace':cs.get_MEG(2)}) # To describe the cases ('case' dimension), create a condition and a subject factor A = factor(['a0', 'a1'], rep=15, name='A') subject = factor(xrange(15), tile=2, random=True, name='subject') if 01: # plot topographically an uncorrected t-test plot.topo.array(testnd.ttest(Y, A, match=subject)) if 01: # and a butterfly plot plot.topo.butterfly(testnd.ttest(Y, A, match=subject))
def epochs_ndvar(epochs, name='MEG', meg=True, eeg=False, exclude='bads', mult=1, unit='T', properties=None, sensors=None): """ Convert an mne.Epochs object to an ndvar. Parameters ---------- epoch : mne.Epochs The epochs object name : None | str Name for the ndvar. meg : bool or string MEG channels to include (:func:`mne.fiff.pick_types` kwarg). If True include all MEG channels. If False include None If string it can be 'mag' or 'grad' to select only gradiometers or magnetometers. It can also be 'ref_meg' to get CTF reference channels. eeg : bool If True include EEG channels (:func:`mne.fiff.pick_types` kwarg). exclude : list of string | str Channels to exclude (:func:`mne.fiff.pick_types` kwarg). If 'bads' (default), exclude channels in info['bads']. If empty do not exclude any. mult : scalar multiply all data by a constant. If used, the ``unit`` kwarg should specify the target unit, not the source unit. unit : str Unit of the data (default is 'T'). target : str name for the new ndvar containing the epoch data reject : None | scalar Threshold for rejecting epochs (peak to peak). Requires a for of mne-python which implements the Epochs.model['index'] variable. raw : None | mne.fiff.Raw Raw file providing the data; if ``None``, ``ds.info['raw']`` is used. sensors : None | eelbrain.vessels.sensors.sensor_net The default (``None``) reads the sensor locations from the fiff file. If the fiff file contains incorrect sensor locations, a different sensor_net can be supplied through this kwarg. """ props = {'proj': 'z root', 'unit': unit, 'ylim': 2e-12 * mult, 'summary_ylim': 3.5e-13 * mult, 'colorspace': _cs.get_MEG(2e-12 * mult), 'summary_colorspace': _cs.get_MEG(2e-13 * mult), 'samplingrate': epochs.info['sfreq'], } if properties: props.update(properties) picks = mne.fiff.pick_types(epochs.info, meg=meg, eeg=eeg, stim=False, eog=False, include=[], exclude=exclude) x = epochs.get_data()[:, picks] if mult != 1: x *= mult if sensors is None: sensor = sensor_net(epochs, picks=picks) else: sensor = sensors time = var(epochs.times, name='time') return ndvar(x, ('case', sensor, time), properties=props, name=name)