PowerSpectrum

lumicks.pylake.force_calibration.power_spectrum.PowerSpectrum

class PowerSpectrum(data, sample_rate, unit='V', window_seconds=None)

Power spectrum data for a time series.

frequency

Frequency values for the power spectrum. [Hz]

Type:

numpy.ndarray

power

Power values for the power spectrum (typically in V^2/Hz).

Type:

numpy.ndarray

sample_rate

The sampling rate for the original data. [Hz]

Type:

float

total_duration

The total duration of the original data. [seconds]

Type:

float

downsampled_by(factor, reduce=<function mean>) PowerSpectrum

Returns a spectrum downsampled by a given factor.

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:
  • power_spectrum (PowerSpectrum) – The power spectrum of the Brownian motion of the bead in a trap

  • 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

  • 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(**kwargs)

Plot power spectrum

Parameters:

**kwargs – Forwarded to matplotlib.pyplot.plot().

with_spectrum(power, num_points_per_block=1) 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.

Returns:

power_spectrum – Power spectrum with new spectral density values.

Return type:

PowerSpectrum

Raises:

ValueError – If the power spectrum provided has a different length from the current one.

property frequency_bin_width

Returns the frequency bin width of the spectrum