ch_util.cal_utils

Tools for point source calibration

This module contains tools for performing point-source calibration.

Functions

estimate_directional_scale(z[, c])

Calculate robust, direction dependent estimate of scale.

fit_histogram(arr[, bins, rng, no_weight, ...])

Fit a gaussian to a histogram of the data.

fit_point_source_map(ra, dec, submap[, rms, ...])

Fits a map of a point source to a model.

flag_outliers(raw, flag[, window, nsigma])

Flag outliers with respect to rolling median.

func_2d_gauss(coord, peak_amplitude, ...)

Returns a parameteric model for the map of a point source, consisting of a 2-dimensional gaussian.

func_2d_sinc_gauss(coord, peak_amplitude, ...)

Returns a parameteric model for the map of a point source,

func_dirty_gauss(dirty_beam)

Returns a parameteric model for the map of a point source, consisting of the interpolated dirty beam along the y-axis and a gaussian along the x-axis.

func_real_dirty_gauss(dirty_beam)

Returns a parameteric model for the map of a point source, consisting of the interpolated dirty beam along the y-axis and a sinusoid with gaussian envelope along the x-axis.

get_reference_times_dataset_id(times, ...[, ...])

Calculate the relevant calibration reference times from the dataset IDs.

get_reference_times_file(times, cal_file[, ...])

For a given set of times determine when and how they were calibrated.

guess_fwhm(freq[, pol, dec, sigma, voltage, ...])

Provide rough estimate of the FWHM of the CHIME primary beam pattern.

interpolate_gain(freq, gain, weight[, flag, ...])

Replace gain at flagged frequencies with interpolated values.

interpolate_gain_quiet(*args, **kwargs)

Call interpolate_gain with ConvergenceWarnings silenced.

thermal_amplitude(delta_T, freq)

Computes the amplitude gain correction given a (set of) temperature difference and a (set of) frequency based on the thermal model.

Classes

FitAmpPhase(*args, **kwargs)

Base class for fitting models to the amplitude and phase.

FitGaussAmpPolyPhase([poly_deg_phi])

Class that enables fits of a gaussian to amplitude and a polynomial to phase.

FitPoly([poly_type])

Base class for fitting polynomials to point source transits.

FitPolyLogAmpPolyPhase([poly_deg_amp, ...])

Class that enables separate fits of a polynomial to log amplitude and phase.

FitPolyRealPolyImag([poly_deg, even, odd])

Class that enables separate fits of a polynomial to real and imag components.

FitRealImag(*args, **kwargs)

Base class for fitting models to the real and imag component.

FitTransit(*args, **kwargs)

Base class for fitting models to point source transits.

class ch_util.cal_utils.FitAmpPhase(*args, **kwargs)[source]

Bases: FitTransit

Base class for fitting models to the amplitude and phase.

Assumes an independent fit to amplitude and phase, and provides methods for predicting the uncertainty on each.

Instantiates a FitTransit object.

Parameters:
  • param (np.ndarray[..., nparam]) – Best-fit parameters.

  • param_cov (np.ndarray[..., nparam, nparam]) – Covariance of the fit parameters.

  • chisq (np.ndarray[..., ncomponent]) – Chi-squared.

  • ndof (np.ndarray[..., ncomponent]) – Number of degrees of freedom.

property nparam

Number of parameters.

Returns:

nparam – Number of fit parameters.

Return type:

int

uncertainty(ha, alpha=0.32, elementwise=False)[source]

Predicts the uncertainty on the response at given hour angle(s).

Returns the quadrature sum of the amplitude and phase uncertainty.

Parameters:
  • ha (np.ndarray[nha,] or float) – Hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

Returns:

err – Uncertainty on the response.

Return type:

np.ndarray[…, nha] or float

uncertainty_amp(ha, alpha=0.32, elementwise=False)[source]

Predicts the uncertainty on amplitude at given hour angle(s).

Parameters:
  • ha (np.ndarray[nha,] or float) – Hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

Returns:

err – Uncertainty on the amplitude in fractional units.

Return type:

np.ndarray[…, nha] or float

uncertainty_phi(ha, alpha=0.32, elementwise=False)[source]

Predicts the uncertainty on phase at given hour angle(s).

Parameters:
  • ha (np.ndarray[nha,] or float) – Hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

Returns:

err – Uncertainty on the phase in radians.

Return type:

np.ndarray[…, nha] or float

class ch_util.cal_utils.FitGaussAmpPolyPhase(poly_deg_phi=5, *args, **kwargs)[source]

Bases: FitPoly, FitAmpPhase

Class that enables fits of a gaussian to amplitude and a polynomial to phase.

Instantiates a FitGaussAmpPolyPhase object.

Parameters:

poly_deg_phi (int) – Degree of the polynomial to fit to phase.

property ndofa

Number of degrees of freedom for the amplitude fit.

Returns:

ndofa – Number of degrees of freedom of the amplitude fit.

Return type:

np.ndarray[…]

property ndofp

Number of degrees of freedom for the phase fit.

Returns:

ndofp – Number of degrees of freedom of the phase fit.

Return type:

np.ndarray[…]

property parameter_names

Array of strings containing the name of the fit parameters.

peak()[source]

Return the peak of the transit.

Returns:

peak – Centroid of the gaussian fit to amplitude.

Return type:

float

class ch_util.cal_utils.FitPoly(poly_type='standard', *args, **kwargs)[source]

Bases: FitTransit

Base class for fitting polynomials to point source transits.

Maps methods of np.polynomial to methods of the class for the requested polynomial type.

Instantiates a FitPoly object.

Parameters:

poly_type (str) – Type of polynomial. Can be ‘standard’, ‘hermite’, or ‘chebyshev’.

class ch_util.cal_utils.FitPolyLogAmpPolyPhase(poly_deg_amp=5, poly_deg_phi=5, *args, **kwargs)[source]

Bases: FitPoly, FitAmpPhase

Class that enables separate fits of a polynomial to log amplitude and phase.

Instantiates a FitPolyLogAmpPolyPhase object.

Parameters:
  • poly_deg_amp (int) – Degree of the polynomial to fit to log amplitude.

  • poly_deg_phi (int) – Degree of the polynomial to fit to phase.

property ndofa

Number of degrees of freedom for the amplitude fit.

Returns:

ndofa – Number of degrees of freedom of the amplitude fit.

Return type:

np.ndarray[…]

property ndofp

Number of degrees of freedom for the phase fit.

Returns:

ndofp – Number of degrees of freedom of the phase fit.

Return type:

np.ndarray[…]

property parameter_names

Array of strings containing the name of the fit parameters.

peak(param=None)[source]

Find the peak of the transit.

Parameters:

param (np.ndarray[..., nparam]) – Coefficients of the polynomial model for log amplitude. Defaults to self.param.

Returns:

peak – Location of the maximum amplitude in degrees hour angle. If the polynomial does not have a maximum, then NaN is returned.

Return type:

np.ndarray[…]

class ch_util.cal_utils.FitPolyRealPolyImag(poly_deg=5, even=False, odd=False, *args, **kwargs)[source]

Bases: FitPoly, FitRealImag

Class that enables separate fits of a polynomial to real and imag components.

Used to fit cross-polar response that is not well-described by the FitPolyLogAmpPolyPhase used for co-polar response.

Instantiates a FitPolyRealPolyImag object.

Parameters:

poly_deg (int) – Degree of the polynomial to fit to real and imaginary component.

deriv(ha, param=None)[source]

Calculate the derivative of the transit.

property ndofi

Number of degrees of freedom for the imag fit.

property ndofr

Number of degrees of freedom for the real fit.

property parameter_names

Array of strings containing the name of the fit parameters.

peak()[source]

Calculate the peak of the transit.

vander(ha, *args)[source]

Create the Vandermonde matrix.

class ch_util.cal_utils.FitRealImag(*args, **kwargs)[source]

Bases: FitTransit

Base class for fitting models to the real and imag component.

Assumes an independent fit to real and imaginary, and provides methods for predicting the uncertainty on each.

Instantiates a FitTransit object.

Parameters:
  • param (np.ndarray[..., nparam]) – Best-fit parameters.

  • param_cov (np.ndarray[..., nparam, nparam]) – Covariance of the fit parameters.

  • chisq (np.ndarray[..., ncomponent]) – Chi-squared.

  • ndof (np.ndarray[..., ncomponent]) – Number of degrees of freedom.

property nparam

Number of parameters.

Returns:

nparam – Number of fit parameters.

Return type:

int

uncertainty(ha, alpha=0.32, elementwise=False)[source]

Predicts the uncertainty on the response at given hour angle(s).

Returns the quadrature sum of the real and imag uncertainty.

Parameters:
  • ha (np.ndarray[nha,] or float) – Hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

Returns:

err – Uncertainty on the response.

Return type:

np.ndarray[…, nha] or float

uncertainty_imag(ha, alpha=0.32, elementwise=False)[source]

Predicts the uncertainty on imag component at given hour angle(s).

Parameters:
  • ha (np.ndarray[nha,] or float) – Hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

Returns:

err – Uncertainty on the imag component.

Return type:

np.ndarray[…, nha] or float

uncertainty_real(ha, alpha=0.32, elementwise=False)[source]

Predicts the uncertainty on real component at given hour angle(s).

Parameters:
  • ha (np.ndarray[nha,] or float) – Hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

Returns:

err – Uncertainty on the real component.

Return type:

np.ndarray[…, nha] or float

class ch_util.cal_utils.FitTransit(*args, **kwargs)[source]

Bases: object

Base class for fitting models to point source transits.

The fit method should be used to populate the param, param_cov, chisq, and ndof attributes. The predict and uncertainty methods can then be used to obtain the model prediction for the response and uncertainty on this quantity at a given hour angle.

param

Best-fit parameters.

Type:

np.ndarray[…, nparam]

param_cov

Covariance of the fit parameters.

Type:

np.ndarray[…, nparam, nparam]

chisq

Chi-squared of the fit.

Type:

np.ndarray[…]

ndof

Number of degrees of freedom.

Type:

np.ndarray[…]

Abstract Methods
----------------
Any subclass of FitTransit must define these methods

peak _fit _model _jacobian

Instantiates a FitTransit object.

Parameters:
  • param (np.ndarray[..., nparam]) – Best-fit parameters.

  • param_cov (np.ndarray[..., nparam, nparam]) – Covariance of the fit parameters.

  • chisq (np.ndarray[..., ncomponent]) – Chi-squared.

  • ndof (np.ndarray[..., ncomponent]) – Number of degrees of freedom.

property N

Number of independent transit fits contained in this object.

Returns:

N – Numpy-style shape indicating the number of fits that the object contains. Is None if the object contains a single fit.

Return type:

tuple

fit(ha, resp, resp_err, width=5, absolute_sigma=False, **kwargs)[source]

Apply subclass defined _fit method to multiple transits.

This function can be used to fit the transit for multiple inputs and frequencies. Populates the param, param_cov, chisq, and ndof attributes.

Parameters:
  • ha (np.ndarray[nha,]) – Hour angle in degrees.

  • resp (np.ndarray[..., nha]) – Measured response to the point source. Complex valued.

  • resp_err (np.ndarray[..., nha]) – Error on the measured response.

  • width (np.ndarray[...]) – Initial guess at the width (sigma) of the transit in degrees.

  • absolute_sigma (bool) – Set to True if the errors provided are absolute. Set to False if the errors provided are relative, in which case the parameter covariance will be scaled by the chi-squared per degree-of-freedom.

property ncomponent

Number of components.

Returns:

ncomponent – Number of components (i.e, real and imag, amp and phase, complex) that have been fit.

Return type:

int

property nparam

Number of parameters.

Returns:

nparam – Number of fit parameters.

Return type:

int

property param_corr

Parameter correlation matrix.

Returns:

param_corr – Correlation of the fit parameters.

Return type:

np.ndarray[…, nparam, nparam]

property parameter_names

Array of strings containing the name of the fit parameters.

Returns:

parameter_names – Names of the parameters.

Return type:

np.ndarray[nparam,]

abstract peak()[source]

Calculate the peak of the transit.

Any subclass of FitTransit must define this method.

predict(ha, elementwise=False)[source]

Predict the point source response.

Parameters:
  • ha (np.ndarray[nha,] or float) – The hour angle in degrees.

  • elementwise (bool) – If False, then the model will be evaluated at the requested hour angles for every set of parameters. If True, then the model will be evaluated at a separate hour angle for each set of parameters (requires ha.shape == self.N).

Returns:

model – Model for the point source response at the requested hour angles. Complex valued.

Return type:

np.ndarray[…, nha] or float

classmethod tval(alpha, ndof)[source]

Quantile of a standardized Student’s t random variable.

This quantity is slow to compute. Past values will be cached in a dictionary shared by all instances of the class.

Parameters:
  • alpha (float) – Calculate the quantile corresponding to the lower tail probability 1 - alpha / 2.

  • ndof (np.ndarray or int) – Number of degrees of freedom of the Student’s t variable.

Returns:

tval – Quantile of a standardized Student’s t random variable.

Return type:

np.ndarray or float

uncertainty(ha, alpha=0.32, elementwise=False)[source]

Predict the uncertainty on the point source response.

Parameters:
  • ha (np.ndarray[nha,] or float) – The hour angle in degrees.

  • alpha (float) – Confidence level given by 1 - alpha.

  • elementwise (bool) – If False, then the uncertainty will be evaluated at the requested hour angles for every set of parameters. If True, then the uncertainty will be evaluated at a separate hour angle for each set of parameters (requires ha.shape == self.N).

Returns:

err – Uncertainty on the point source response at the requested hour angles.

Return type:

np.ndarray[…, nha]

ch_util.cal_utils.estimate_directional_scale(z, c=2.1)[source]

Calculate robust, direction dependent estimate of scale.

Parameters:
  • z (np.ndarray) – 1D array containing the data.

  • c (float) – Cutoff in number of MAD. Data points whose absolute value is larger than c * MAD from the median are saturated at the maximum value in the estimator.

Returns:

  • zmed (float) – The median value of z.

  • sa (float) – Estimate of scale for z <= zmed.

  • sb (float) – Estimate of scale for z > zmed.

ch_util.cal_utils.fit_histogram(arr, bins='auto', rng=None, no_weight=False, test_normal=False, return_histogram=False)[source]

Fit a gaussian to a histogram of the data.

Parameters:
  • arr (np.ndarray) – 1D array containing the data. Arrays with more than one dimension are flattened.

  • bins (int or sequence of scalars or str) –

    • If bins is an int, it defines the number of equal-width bins in rng.

    • If bins is a sequence, it defines a monotonically increasing

      array of bin edges, including the rightmost edge, allowing for non-uniform bin widths.

    • If bins is a string, it defines a method for computing the bins.

  • rng ((float, float)) – The lower and upper range of the bins. If not provided, then the range spans the minimum to maximum value of arr.

  • no_weight (bool) – Give equal weighting to each histogram bin. Otherwise use proper weights based on number of counts observed in each bin.

  • test_normal (bool) – Apply the Shapiro-Wilk and Anderson-Darling tests for normality to the data.

  • return_histogram (bool) – Return the histogram. Otherwise return only the best fit parameters and test statistics.

Returns:

  • results (dict) – Dictionary containing the following fields:

  • indmin (int) – Only bins whose index is greater than indmin were included in the fit.

  • indmax (int) – Only bins whose index is less than indmax were included in the fit.

  • xmin (float) – The data value corresponding to the centre of the indmin bin.

  • xmax (float) – The data value corresponding to the centre of the indmax bin.

  • par ([float, float, float]) – The parameters of the fit, ordered as [peak, mu, sigma].

  • chisq (float) – The chi-squared of the fit.

  • ndof (int) – The number of degrees of freedom of the fit.

  • pte (float) – The probability to observe the chi-squared of the fit.

  • If return_histogram is True, then results will also contain the

  • following fields

    bin_centrenp.ndarray

    The bin centre of the histogram.

    bin_countnp.ndarray

    The bin counts of the histogram.

  • If test_normal is True, then results will also contain the following fields –

    shapirodict
    statfloat

    The Shapiro-Wilk test statistic.

    ptefloat

    The probability to observe stat if the data were drawn from a gaussian

    andersondict
    statfloat

    The Anderson-Darling test statistic.

    criticallist of float

    The critical values of the test statistic.

    alphalist of float

    The significance levels corresponding to each critical value.

    pastlist of bool

    Boolean indicating if the data passes the test for each critical value.

ch_util.cal_utils.fit_point_source_map(ra, dec, submap, rms=None, dirty_beam=None, real_map=False, freq=600.0, ra0=None, dec0=None)[source]

Fits a map of a point source to a model.

Parameters:
  • ra (np.ndarray[nra, ]) – Transit right ascension.

  • dec (np.ndarray[ndec, ]) – Transit declination.

  • submap (np.ndarray[..., nra, ndec]) – Region of the ringmap around the point source.

  • rms (np.ndarray[..., nra]) – RMS error on the map.

  • flag (np.ndarray[..., nra, ndec]) – Boolean array that indicates which pixels to fit.

  • dirty_beam (np.ndarray[..., nra, ndec] or [ra, dec, dirty_beam]) – Fourier transform of the weighting function used to create the map. If input, then the interpolated dirty beam will be used as the model for the point source response in the declination direction. Can either be an array that is the same size as submap, or a list/tuple of length 3 that contains [ra, dec, dirty_beam] since the shape of the dirty beam is likely to be larger than the shape of the subregion of the map, at least in the declination direction.

Returns:

  • param_name (np.ndarray[nparam, ]) – Names of the parameters.

  • param (np.ndarray[…, nparam]) – Best-fit parameters for each item.

  • param_cov (np.ndarray[…, nparam, nparam]) – Parameter covariance for each item.

ch_util.cal_utils.flag_outliers(raw, flag, window=25, nsigma=5.0)[source]

Flag outliers with respect to rolling median.

Parameters:
  • raw (np.ndarray[nsample,]) – Raw data sampled at fixed rate. Use the flag parameter to indicate missing or invalid data.

  • flag (np.ndarray[nsample,]) – Boolean array where True indicates valid data and False indicates invalid data.

  • window (int) – Window size (in number of samples) used to determine local median.

  • nsigma (float) – Data is considered an outlier if it is greater than this number of median absolute deviations away from the local median.

Returns:

not_outlier – Boolean array where True indicates valid data and False indicates data that is either an outlier or had flag = True.

Return type:

np.ndarray[nsample,]

ch_util.cal_utils.func_2d_gauss(coord, peak_amplitude, centroid_x, centroid_y, fwhm_x, fwhm_y, offset)[source]

Returns a parameteric model for the map of a point source, consisting of a 2-dimensional gaussian.

Parameters:
  • coord ((ra, dec)) – Tuple containing the right ascension and declination. These should be coordinate vectors of length nra and ndec, respectively.

  • peak_amplitude (float) – Model parameter. Normalization of the gaussian.

  • centroid_x (float) – Model parameter. Centroid of the gaussian in degrees in the right ascension direction.

  • centroid_y (float) – Model parameter. Centroid of the gaussian in degrees in the declination direction.

  • fwhm_x (float) – Model parameter. Full width at half maximum of the gaussian in degrees in the right ascension direction.

  • fwhm_y (float) – Model parameter. Full width at half maximum of the gaussian in degrees in the declination direction.

  • offset (float) – Model parameter. Constant background value of the map.

Returns:

model – Model prediction for the map of the point source.

Return type:

np.ndarray[nra*ndec]

ch_util.cal_utils.func_2d_sinc_gauss(coord, peak_amplitude, centroid_x, centroid_y, fwhm_x, fwhm_y, offset)[source]
Returns a parameteric model for the map of a point source,

consisting of a sinc function along the declination direction and gaussian along the right ascension direction.

Parameters:
  • coord ((ra, dec)) – Tuple containing the right ascension and declination. These should be coordinate vectors of length nra and ndec, respectively.

  • peak_amplitude (float) – Model parameter. Normalization of the gaussian.

  • centroid_x (float) – Model parameter. Centroid of the gaussian in degrees in the right ascension direction.

  • centroid_y (float) – Model parameter. Centroid of the sinc function in degrees in the declination direction.

  • fwhm_x (float) – Model parameter. Full width at half maximum of the gaussian in degrees in the right ascension direction.

  • fwhm_y (float) – Model parameter. Full width at half maximum of the sinc function in degrees in the declination direction.

  • offset (float) – Model parameter. Constant background value of the map.

Returns:

model – Model prediction for the map of the point source.

Return type:

np.ndarray[nra*ndec]

ch_util.cal_utils.func_dirty_gauss(dirty_beam)[source]

Returns a parameteric model for the map of a point source, consisting of the interpolated dirty beam along the y-axis and a gaussian along the x-axis.

This function is a wrapper that defines the interpolated dirty beam.

Parameters:

dirty_beam (scipy.interpolate.interp1d) – Interpolation function that takes as an argument el = sin(za) and outputs an np.ndarray[nel, nra] that represents the dirty beam evaluated at the same right ascension as the map.

Returns:

dirty_gauss – Model prediction for the map of the point source.

Return type:

np.ndarray[nra*ndec]

ch_util.cal_utils.func_real_dirty_gauss(dirty_beam)[source]

Returns a parameteric model for the map of a point source, consisting of the interpolated dirty beam along the y-axis and a sinusoid with gaussian envelope along the x-axis.

This function is a wrapper that defines the interpolated dirty beam.

Parameters:

dirty_beam (scipy.interpolate.interp1d) – Interpolation function that takes as an argument el = sin(za) and outputs an np.ndarray[nel, nra] that represents the dirty beam evaluated at the same right ascension as the map.

Returns:

real_dirty_gauss – Model prediction for the map of the point source.

Return type:

np.ndarray[nra*ndec]

ch_util.cal_utils.get_reference_times_dataset_id(times: ndarray, dataset_ids: ndarray, logger: Logger | None = None) dict[str, ndarray | dict][source]

Calculate the relevant calibration reference times from the dataset IDs.

Warning

Dataset IDs before 2020/10/10 are corrupt so this routine won’t work.

Parameters:
  • times – Unix times of data points to be calibrated as floats.

  • dataset_ids – The dataset IDs as an array of strings.

  • logger – A logging object to use for messages. If not provided, use a module level logger.

Returns:

A dictionary containing the results. See get_reference_times_file for a description of the contents.

Return type:

reftime_result

ch_util.cal_utils.get_reference_times_file(times: ndarray, cal_file: MemGroup, logger: Logger | None = None) dict[str, ndarray][source]

For a given set of times determine when and how they were calibrated.

This uses the pre-calculated calibration time reference files.

Parameters:
  • times – Unix times of data points to be calibrated as floats.

  • cal_file – memh5 container which containes the reference times for calibration source transits.

  • logger – A logging object to use for messages. If not provided, use a module level logger.

Returns:

reftime_result – A dictionary containing four entries:

  • reftime: Unix time of same length as times. Reference times of transit of the source used to calibrate the data at each time in times. Returns NaN for times without a reference.

  • reftime_prev: The Unix time of the previous gain update. Only set for time samples that need to be interpolated, otherwise NaN.

  • interp_start: The Unix time of the start of the interpolation period. Only set for time samples that need to be interpolated, otherwise NaN.

  • interp_stop: The Unix time of the end of the interpolation period. Only set for time samples that need to be interpolated, otherwise NaN.

Return type:

dict

ch_util.cal_utils.guess_fwhm(freq, pol='X', dec=None, sigma=False, voltage=False, seconds=False)[source]

Provide rough estimate of the FWHM of the CHIME primary beam pattern.

It uses a linear fit to the median FWHM(nu) over all feeds of a given polarization for CygA transits. CasA and TauA transits also showed good agreement with this relationship.

Parameters:
  • freq (float or np.ndarray) – Frequency in MHz.

  • pol (string or bool) – Polarization, can be ‘X’/’E’ or ‘Y’/’S’

  • dec (float) – Declination of the source in radians. If this quantity is input, then the FWHM is divided by cos(dec) to account for the increased rate at which a source rotates across the sky. Default is do not correct for this effect.

  • sigma (bool) – Return the standard deviation instead of the FWHM. Default is to return the FWHM.

  • voltage (bool) – Return the value for a voltage beam, otherwise returns value for a power beam.

  • seconds (bool) – Convert to elapsed time in units of seconds. Otherwise returns in units of degrees on the sky.

Returns:

fwhm – Rough estimate of the FWHM (or standard deviation if sigma=True).

Return type:

float or np.ndarray

ch_util.cal_utils.interpolate_gain(freq, gain, weight, flag=None, length_scale=30.0)[source]

Replace gain at flagged frequencies with interpolated values.

Uses a gaussian process regression to perform the interpolation with a Matern function describing the covariance between frequencies.

Parameters:
  • freq (np.ndarray[nfreq,]) – Frequencies in MHz.

  • gain (np.ndarray[nfreq, ninput]) – Complex gain for each input and frequency.

  • weight (np.ndarray[nfreq, ninput]) – Uncertainty on the complex gain, expressed as inverse variance.

  • flag (np.ndarray[nfreq, ninput]) – Boolean array indicating the good (True) and bad (False) gains. If not provided, then it will be determined by evaluating weight > 0.0.

  • length_scale (float) – Correlation length in frequency in MHz.

Returns:

  • interp_gain (np.ndarray[nfreq, ninput]) – For frequencies with flag = True, this will be equal to gain. For frequencies with flag = False, this will be an interpolation of the gains with flag = True.

  • interp_weight (np.ndarray[nfreq, ninput]) – For frequencies with flag = True, this will be equal to weight. For frequencies with flag = False, this will be the expected uncertainty on the interpolation.

ch_util.cal_utils.interpolate_gain_quiet(*args, **kwargs)[source]

Call interpolate_gain with ConvergenceWarnings silenced.

Accepts and passes all arguments and keyword arguments for interpolate_gain.

ch_util.cal_utils.thermal_amplitude(delta_T, freq)[source]

Computes the amplitude gain correction given a (set of) temperature difference and a (set of) frequency based on the thermal model.

Parameters:
  • delta_T (float or array of foats) – Temperature difference (T - T_0) for which to find a gain correction.

  • freq (float or array of foats) – Frequencies in MHz

Returns:

g – Gain amplitude corrections. Multiply by data to correct it.

Return type:

float or array of floats