Advanced power spectrum averaging functions¶
The hera_stats.average
module contains several advanced averaging functions for power spectra. Currently, this only consists of cumulative averaging in time or baseline-pair (average_spectra_cumul) and differencing redundant groups with respect to their average (redundant_diff).
-
hera_stats.average.
average_spectra_cumul
(uvp, blps, spw, polpair, mode='time', min_samples=1, shuffle=False, time_avg=True, verbose=False)[source]¶ Cumulatively average a set of delay spectra as a function of time or blpair. The cumulative average can be performed sequentially, e.g. in time order, or in a random (shuffled) order.
Parameters: - uvp (UVPSpec) – Set of power spectra to be cumulatively averaged.
- blps (list of ints or tuples) – List of blpair ints or tuples. Only one redundant set of blpairs should be passed at once.
- spw, polpair (int, str) – Spectral window ID (integer) and polarization-pair (integer or str) of the power spectra to average.
- mode (str, optional) – Whether to cumulatively average in time or blpair. The other dimension will be averaged over non-cumulatively. (See the ‘time_avg’ kwarg below for other behaviors.) Possible options are ‘time’ or ‘blpair’. Default: ‘time’.
- min_samples (int, optional) – Minimum number of samples to allow in the cumulative average. Default: 1.
- shuffle (bool, optional) – Whether to randomly shuffle the order of the cumulative averaging, or to keep it in order. Default: False.
- time_avg (bool, optional) – Whether to average over times. This option is only used if mode=’blpair’; otherwise it will be ignored. Default: True.
- verbose (bool, optional) – Whether to print status messages as the cumulative averaging progresses. Default: False.
Returns: - ps (array_like) – Cumulative averages of delay spectra, in a 2D array of shape (Nsamp, Ndelay), where Nsamp = Ntimes or Nblpairs.
- dly (array_like) – Power spectrum delay modes (in s).
- n_samples (array_like) – Number of times or blpairs that went into each average in the ps array.
-
hera_stats.average.
redundant_diff
(uvd, bls, pol, return_mean=False)[source]¶ Calculate the difference between all baselines in a redundant group and the mean of the redundant group (as a fn. of frequency and time).
Empty (fully flagged) baselines are excluded from the average.
N.B. The averaging does not currently take into account data weights or number of samples.
Parameters: - uvd (UVData) – UVData object containing the data that will be averaged and differenced.
- bls (list of tuple or int) – List of baseline tuples or integers to be treated as a group. The mean will be calculated over all
- pol (str) – Which polarization to extract from the UVData file.
- return_mean (bool, optional) – If True, return the mean over the redundant group too. Default: False
Returns: - bls (list of baseline tuple or int) – List of baselines that were kept in the average.
- diffs (list of array_like) – List of arrays of differences between each baseline and the group mean.
- mean (array_like, optional) – Mean over data from all non-flagged baselines, as a function of freq. and time. Only retuend if return_mean is True.
-
hera_stats.average.
redundant_diff_summary
(uvd, red_bls, pol, op_upper=<Mock name='mock.max' id='140500795349200'>, op_lower=None, verbose=False)[source]¶ Calculate summary stats on the differences of baselines with the mean of their redundant group. Returns an antenna-antenna matrix where each element is the value of the summary statistic for a given antenna pair.
See hera_stats.plot.antenna_matrix for an accompanying plotting function.
Parameters: uvd (UVData) – Visibility data object.
red_bls (list of lists) – List of redundant baseline group lists.
pol (str or int) – String or integer specifying the polarization to use.
op_upper (func) – Function that operates on the difference waterfall (visibility for baseline minus the mean over its redundant group) to return a single number, to be used as the summary statistic for that baseline.
Functions must have the following signature:
scalar = func(d, grp_mean)
where d is the difference data (a 2D complex array) and grp_mean is the mean over the redundant group (also a 2D complex array).
The values of the summary statistic are placed on the upper triangle of the output matrix.
op_lower (func, optional) – Same as op_upper, but places values on the lower triangle of the output matrix.
verbose (bool, optional) – Whether to print progress messages. Default: False.
Returns: unique_ants (array_like) – Ordered array of unique antennas that were found in the redundant groups.
mat (array_like) – 2D array of summary statistic values for every pair of antennas.
NB. np.nan values are returned for antenna pairs that were not present in the data/redundant baseline list.