timescales.fit.PSD
timescales.fit.PSD¶
- class timescales.fit.PSD(freqs=None, powers=None)[source]¶
Power spectral density class.
- Parameters
- freqs1d array
Frequencies at which the measure was calculated.
- powers1d or 2d array
Power spectral density.
- Attributes
- powers_fit1d or 2d array
Aperiodic fit.
- params1d or 2d array
Parameters as [offset, knee_freq, exp, const].
- param_nameslist of str
Parameter names in order of params.
- knee_freqfloat or 1d array
Knee frequency.
- rsqfloat
R-squared of the aperiodic fit.
- guesslist, optional, default: None
Inital parameter estimates.
- boundslist, optional, default: None
Methods
__init__
([freqs, powers])Initialize object.
compute_spectrum
(sig, fs[, ar_order, ...])Compute powers spectral density.
fit
([freqs, powers, f_range, ap_mode, ...])Fit power spectra.
plot
([ax, title])Plot spectra.
- compute_spectrum(sig, fs, ar_order=None, f_range=None, norm_range=None, n_jobs=1, **kwargs)[source]¶
Compute powers spectral density.
- Parameters
- sig1d or 2d array
Voltage time series or spike counts.
- fsfloat
Sampling rate, in Hz.
- ar_orderint, optional, default: None
Compute an autoregressive spectra when not None.
- f_rangetuple of (float, float)
Frequency range of interest, inclusive.
- norm_rangetuple of (float, float), optional, default: None
The lower and upper normalization range.
- n_jobsint, optional, default: -1
Number of jobs to run in parralel, when powers is 2d. Only available when using an ar_order.
- **kwargs
Additional keyword arguments to pass to compute_spectrum or compute_ar_spectrum.
- fit(freqs=None, powers=None, f_range=None, ap_mode='single', method='huber', fooof_init=None, bounds=None, guess=None, n_resample=None, f_scale=0.1, r_thresh=None, maxfev=1000, sigma=None, n_jobs=1, progress=None)[source]¶
Fit power spectra.
- Parameters
- freqs1d array
Frequencies at which the measure was calculated.
- powers1d or 2d array
Power spectral density.
- f_rangetuple of (float, float)
Frequency range of interest, inclusive.
- ap_mode{‘single’, ‘double’}
Aperiodic mode as a single or double timescales (knee) process. Only availble for non-fooof methods.
- method{‘huber’, ‘cauchy’, ‘soft_l1’, ‘arctan’, ‘fooof’}
Fit using a single scipy curve_fit call using robust regression or use the fooof model.
- fooof_initdict, optional, default: None
Fooof initialization arguments. Only used if method is ‘fooof’.
- bounds2d array-like
Parameter bounds.
- guess1d array-like
Initial parameter estimates.
- n_resampleint, optional, default: None:
Evenly resample in log-log space to improve robust regression.
- f_scalefloat or 1d array-like, optional, default: 0.1
Value of soft margin between inlier and outlier residuals. Only used if method is in {‘huber’, ‘cauchy’, ‘soft_l1’, ‘arctan’}.
- r_threshfloat, optional, default: None
Minimum r-squared required to accept f_scale. Only used when f_scale is a 1d array. When None, all f_scale values are attempted and the highest resulting r-squared is accepted.
- maxfevint
Maximum number of fitting iterations. Only availble for huber method.
- sigmadict, optional, default: None
Target error per sample.
- n_jobsint
Number of jobs to run in parralel, when powers is 2d.
- progress{None, ‘tqdm’, ‘tqdm.notebook’}
Specify whether to display a progress bar. Uses ‘tqdm’, if installed.