PowerSpectrum¶
lumicks.pylake.force_calibration.power_spectrum.PowerSpectrum
- class PowerSpectrum(frequency, power, sample_rate, total_duration, unit='V', *, num_points_per_block=1, total_samples_used=None, variance=None)¶
Power spectrum data for a time series.
- frequency¶
Frequency values for the power spectrum. [Hz]
- Type:
- power¶
Power values for the power spectrum (typically in V^2/Hz).
- Type:
- downsampled_by(factor, reduce=<function mean>) PowerSpectrum¶
Returns a spectrum downsampled by a given factor.
- Parameters:
factor (int) – Factor to down-sample the spectrum by.
reduce (callable) – (Deprecated) Function to use for down-sampling the data. Only
np.meanwill be supported going forward.
- static from_data(data, sample_rate, unit='V', window_seconds=None) PowerSpectrum¶
Power spectrum
- Parameters:
data (numpy.ndarray) – Data from which to calculate a power spectrum.
sample_rate (float) – Sampling rate at which this data was acquired [Hz].
unit (str) – Units the data is in (default: V).
window_seconds (float) – Window duration [seconds]. When specified the data is divided into blocks of length window_seconds. Power spectra are computed for each block after which they are averaged. If omitted, no windowing is used.
- identify_peaks(model_fun: callable, *, peak_cutoff: float = 20.0, baseline: float = 1.0) List[Tuple[float, float]]¶
Identify peaks in the power spectrum, based on an exponential probability model with rate parameter (lambda) = 1. This means that the power spectrum cannot be blocked or windowed. This is beta functionality. While usable, this has not yet been tested in a large number of different scenarios. The API can still be subject to change without any prior deprecation notice! If you use this functionality keep a close eye on the changelog for any changes that may affect your analysis.
- Parameters:
model_fun (callable) – A function of one argument, frequency, that gives the theoretical power spectrum. The function is used to normalize the experimental power spectrum. Note that you can pass an instance of
CalibrationResults.peak_cutoff (float) – Indicates what value of the normalized spectrum is deemed abnormally high. Default is 20.0, which corresponds to a chance of about 2 in 1E9 that a peak of that magnitude occurs naturally in an exponential distribution with rate parameter = 1.0. The minimum is baseline (see below).
baseline (float) – The baseline level a peak needs to drop down to. Lower means that exponentially more data is considered to be part of the peak. The default is 1.0, and the range of baseline is [0.0, peak_cutoff]. No fit or data smoothing is performed, the peak starts or ends at the first data point that satisfies the criterion.
- Returns:
frequency_ranges – f_start is the frequency where a peak starts, and f_stop is the frequency where a peak ends (exclusive).
- Return type:
list of tuples (f_start, f_stop)
- Raises:
ValueError – Raises a ValueError if the function is called on a PowerSpectrum object with blocking applied. This function only works for PowerSpectrum objects without blocking or windowing.
ValueError – Raises a ValueError when the peak_cutoff is smaller than baseline and when baseline is less than zero
- in_range(frequency_min, frequency_max) PowerSpectrum¶
Returns part of the power spectrum within a given frequency range.
- plot(*, show_excluded=False, **kwargs)¶
Plot power spectrum
- Parameters:
show_excluded (bool) – Show ranges that were excluded from fitting.
**kwargs – Forwarded to
matplotlib.pyplot.plot().
- with_spectrum(power, num_points_per_block=1, variance=None) PowerSpectrum¶
Return a copy with a different spectrum
- Parameters:
power (numpy.ndarray) – Vector of power spectral values
num_points_per_block (int) – Number of points per block used to obtain power spectral values.
variance (numpy.ndarray, optional) – Variance of the power spectrum.
- Returns:
power_spectrum – Power spectrum with new spectral density values.
- Return type:
- Raises:
ValueError – If the power spectrum provided has a different length from the current one.