edges_analysis.averaging.averaging.bin_freq_unbiased_irregular¶
- edges_analysis.averaging.averaging.bin_freq_unbiased_irregular(spectrum: list | ndarray, freq: list | ndarray | None = None, weights: list | ndarray | None = None, resolution: float | int | None = None) tuple[ndarray, ndarray, ndarray] [source]¶
Average a spectrum, with weights, in frequency.
The average is optionally taken within bins along the frequency axis. Under the hood, uses
bin_array_unbiased_irregular()
, just adding some nicer call parameters.- Parameters:
spectrum (array-like) – The spectrum to average. Frequency axis is the last axis.
freq (array-like, optional) – The frequencies along which to average. If provided, must be the same shape as
spectrum
. Must be provided if eitherresolution
orn_samples
is provided.weights (array-like, optional) – The weights of the weighted averaged. If provided, same shape as
spectrum
. If not provided, all weights are considered to be one.resolution (float, optional) – The (frequency) resolution with which to perform the average, in same units as
freq
. For example, if an array of frequencies with resolution 0.1 MHz is passed in, andresolution
is 0.2, the output array will contain half the number of bins. Default is to average the whole array.
- Returns:
freq – An array with length determined automatically by the routine, giving the mean frequency in each output bin. Note that the frequencies in each row may be different.
spec – Array of same length as
freq
containing the weighted-average spectrumw (array) – Array of same length as
freq
containing the total weight in each bin.
Examples
>>> freq = np.linspace(0.1, 1, 10) >>> spectrum = [0, 2] * 5 >>> f, s, w = bin_freq_unbiased_irregular(spectrum, freq=freq, resolution=0.2) >>> f [0.15, 0.35, 0.55, 0.75, 0.95] >>> s [1, 1, 1, 1, 1] >>> w [1, 1, 1, 1, 1]