edges.averaging.freqbin¶
Functions for binning and decimating GSData objects in frequency.
- edges.averaging.freqbin.freq_bin(data: GSData, bins: ndarray | Quantity | float | None = None, debias: bool | None = None) GSData[source]¶
Bin a GSData object over the frequency/channel axis.
- Parameters:
data – The input GSData object to be binned.
bins – The bin edges (lower inclusive, upper not inclusive). If an
int, simply usebinscoords per bin, starting from the first bin. If a float or Quantity, use equi-spaced bin edges, starting from the start of coords, and ending past the end of coords. If an array, assumed to be the bin edges. If not provided, assume a single bin encompassing all the data.model – A model to be used for debiasing, by default None.
debias – Whether to debias the data using the provided model or residuals, by default None.
- Returns:
GSData – The binned and decimated GSData object.
Notes
If the data object has residuals, they will be set appropriately on the returned object. Furthermore, the frequencies of the returned object will be the mean of the frequencies in each bin, and therefore may not be regular. Finally, flags will only be maintained if they have no frquency axis (though flags will be utilized appropriately in the averaging process).
- edges.averaging.freqbin.gauss_smooth(data: GSData, size: int, decimate: bool = True, decimate_at: int | None = None, flag_threshold: float = 0, maintain_flags: int = 0, use_residuals: bool | None = None, nsmooth: int = 4, use_nsamples: bool = False) GSData[source]¶
Smooth data with a Gaussian function, and optionally decimate.
- Parameters:
data – The
GSDataobject over which to smooth.size – The size of the Gaussian smoothing kernel. The ultimate size of the kernel will be
nsmooth*size. The final array will be decimated by a factor ofsize, if thedecimateoption is set. Thus, to maintain the same number of samples, setsizeto unity andnsmoothlarger.decimate – Whether to decimate the array by a factor of
size.decimate_at – The first index to keep when decimating. If
None, this will besize//2.flag_threshold – The threshold of flagged samples to flag a channel. Set to 0.25 to flag in the same way as Alan’s C-Code. In detail, for a dataset with uniform weights (but potentially some flagged bins), any smoothed channel whose integrated window not counting flagged channels is smaller than
size*flag_thresholdwill be flagged.maintain_flags – Whether to maintain the flags in the data. If
True, any fine-channels that were originally flagged will be flagged in the output. The default behaviour is to simply sum all weights within the window, but Alan’s code uses this feature.use_residuals – Whether to smooth the residuals to a model fit instead of the spectrum itself. By default, this is
Trueif a model is present in the data.nsmooth – The ratio of the size of the smoothing kernel (in pixels) to the decimation length (i.e.
size).use_nsamples – Whether to weight the data by nsamples when performing the smoothing kernel convolution. Note that even if this is set to
False, the Nsamples in the output will be the kernel-weighted sum of the input samples to each resulting channel.
- Returns:
GSData – The smoothed and potentially decimated GSData object.
- Raises:
ValueError – If the residuals are to be smoothed and are not present in the data.