Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
-------
psds : ndarray, shape (..., n_freqs) or (..., n_freqs, n_segments)
The power spectral densities. If ``average='mean`` or
``average='median'``, the returned array will have the same shape
as the input data plus an additional frequency dimension.
If ``average=None``, the returned array will have the same shape as
the input data plus two additional dimensions corresponding to
frequencies and the unaggregated segments, respectively.
freqs : ndarray, shape (n_freqs,)
The frequencies.
Notes
-----
.. versionadded:: 0.14.0
"""
_check_option('average', average, (None, 'mean', 'median'))
dshape = x.shape[:-1]
n_times = x.shape[-1]
x = x.reshape(-1, n_times)
# Prep the PSD
n_fft, n_per_seg, n_overlap = _check_nfft(n_times, n_fft, n_per_seg,
n_overlap)
win_size = n_fft / float(sfreq)
logger.info("Effective window size : %0.3f (s)" % win_size)
freqs = np.arange(n_fft // 2 + 1, dtype=float) * (sfreq / n_fft)
freq_mask = (freqs >= fmin) & (freqs <= fmax)
freqs = freqs[freq_mask]
# Parallelize across first N-1 dimensions
x_splits = np.array_split(x, n_jobs)
The start time of each fitting interval
chpi_digs :ndarray, shape (N, 1)
Array of dig structures containing the cHPI locations. Includes
goodness of fit for each cHPI.
Notes
-----
The number of time points ``N`` will depend on the velocity of head
movements as well as ``t_step_max`` and ``t_step_min``.
See Also
--------
read_head_pos
write_head_pos
"""
_check_option('too_close', too_close, ['raise', 'warning', 'info'])
# extract initial geometry from info['hpi_results']
hpi_dig_head_rrs = _get_hpi_initial_fit(raw.info)
# extract hpi system information
hpi = _setup_hpi_struct(raw.info, int(round(t_window * raw.info['sfreq'])))
# move to device coords
head_dev_t = invert_transform(raw.info['dev_head_t'])['trans']
hpi_dig_dev_rrs = apply_trans(head_dev_t, hpi_dig_head_rrs)
# setup last iteration structure
last = dict(sin_fit=None, fit_time=t_step_min,
coil_dev_rrs=hpi_dig_dev_rrs)
t_begin = raw.times[0]
def _permutation_cluster_test(X, threshold, n_permutations, tail, stat_fun,
connectivity, n_jobs, seed, max_step,
exclude, step_down_p, t_power, out_type,
check_disjoint, buffer_size):
n_jobs = check_n_jobs(n_jobs)
"""Aux Function.
Note. X is required to be a list. Depending on the length of X
either a 1 sample t-test or an F test / more sample permutation scheme
is elicited.
"""
_check_option('out_type', out_type, ['mask', 'indices'])
if not isinstance(threshold, dict):
threshold = float(threshold)
if (tail < 0 and threshold > 0 or tail > 0 and threshold < 0 or
tail == 0 and threshold < 0):
raise ValueError('incompatible tail and threshold signs, got '
'%s and %s' % (tail, threshold))
# check dimensions for each group in X (a list at this stage).
X = [x[:, np.newaxis] if x.ndim == 1 else x for x in X]
n_samples = X[0].shape[0]
n_times = X[0].shape[1]
sample_shape = X[0].shape[1:]
for x in X:
if x.shape[1:] != sample_shape:
raise ValueError('All samples mush have the same size')
epochs = [epochs]
return epochs
if not isinstance(epochs, list):
epochs = _unpack_epochs(epochs)
else:
epochs = sum([_unpack_epochs(epoch) for epoch in epochs], [])
# check for baseline correction
if any(epochs_t.baseline is None and epochs_t.info['highpass'] < 0.5 and
keep_sample_mean for epochs_t in epochs):
warn('Epochs are not baseline corrected, covariance '
'matrix may be inaccurate')
orig = epochs[0].info['dev_head_t']
_check_option('on_mismatch', on_mismatch, ['raise', 'warn', 'ignore'])
for ei, epoch in enumerate(epochs):
epoch.info._check_consistency()
if (orig is None) != (epoch.info['dev_head_t'] is None) or \
(orig is not None and not
np.allclose(orig['trans'],
epoch.info['dev_head_t']['trans'])):
msg = ('MEG<->Head transform mismatch between epochs[0]:\n%s\n\n'
'and epochs[%s]:\n%s'
% (orig, ei, epoch.info['dev_head_t']))
if on_mismatch == 'raise':
raise ValueError(msg)
elif on_mismatch == 'warn':
warn(msg)
bads = epochs[0].info['bads']
if projs is None:
def _check_image_format(rep, image_format):
"""Ensure fmt is valid."""
if rep is None:
_check_option('image_format', image_format, ['png', 'svg'])
elif image_format is not None:
_check_option('image_format', image_format, ['png', 'svg', None])
else: # rep is not None and image_format is None
image_format = rep.image_format
return image_format
def _check_unit_and_get_scaling(unit, valid_scales):
_check_option('unit', unit, list(valid_scales.keys()))
return valid_scales[unit]
def _check_method(method, iir_params, extra_types=()):
"""Parse method arguments."""
allowed_types = ['iir', 'fir', 'fft'] + list(extra_types)
_validate_type(method, 'str', 'method')
_check_option('method', method, allowed_types)
if method == 'fft':
method = 'fir' # use the better name
if method == 'iir':
if iir_params is None:
iir_params = dict()
if len(iir_params) == 0 or (len(iir_params) == 1 and
'output' in iir_params):
iir_params = dict(order=4, ftype='butter',
output=iir_params.get('output', 'sos'))
elif iir_params is not None:
raise ValueError('iir_params must be None if method != "iir"')
return iir_params, method
be the same as input.
freqs : array
The frequency points in Hz of the PSD.
See Also
--------
mne.io.Raw.plot_psd
mne.Epochs.plot_psd
csd_multitaper
psd_multitaper
Notes
-----
.. versionadded:: 0.14.0
"""
_check_option('normalization', normalization, ['length', 'full'])
# Reshape data so its 2-D for parallelization
ndim_in = x.ndim
x = np.atleast_2d(x)
n_times = x.shape[-1]
dshape = x.shape[:-1]
x = x.reshape(-1, n_times)
dpss, eigvals, adaptive = _compute_mt_params(
n_times, sfreq, bandwidth, low_bias, adaptive)
# decide which frequencies to keep
freqs = rfftfreq(n_times, 1. / sfreq)
freq_mask = (freqs >= fmin) & (freqs <= fmax)
freqs = freqs[freq_mask]
def _check_image_format(rep, image_format):
"""Ensure fmt is valid."""
if rep is None:
_check_option('image_format', image_format, ['png', 'svg'])
elif image_format is not None:
_check_option('image_format', image_format, ['png', 'svg', None])
else: # rep is not None and image_format is None
image_format = rep.image_format
return image_format