edges.cal.noise_waves

Functions for calibrating the receiver.

class edges.cal.noise_waves.NoiseWaveLinearModel(freq: ~numpy.ndarray, gamma_rec: ~numpy.ndarray, gamma_src: dict[str, ~numpy.ndarray], model_type: ~edges.modeling.core.Model = <class 'edges.modeling.models.Polynomial'>, n_terms: int = 5, delay: float = 0.0)[source]

A linear model for the noise wave terms.

Parameters:
  • Kopen (tuple) – The K terms for the open load.

  • Kshort (tuple) – The K terms for the short load.

Returns:

model (np.poly1d) – The linear model for the noise wave terms.

cos_kfactor(freq)[source]

Compute the scaler to the Tcos basis function.

fit(spectrum: dict[str, ndarray], temp_thermistor: dict[str, ndarray], method='lstsq')[source]

Obtain a fit of the compositie model to given data.

sin_kfactor(freq)[source]

Compute the scaler to the Tsin basis function.

unc_kfactor(freq)[source]

Compute the scaler to the Tunc basis function.

class edges.cal.noise_waves.NoiseWaveLinearModelFit(freq: ndarray, gamma_rec: ndarray, gamma_src: dict[str, ndarray], modelfit: CompositeModel, delay: float = 0.0)[source]

A class representing a fit of the :class:NoiseWaveLinearModel` to data.

Parameters:
  • freq (numpy.ndarray) – The frequencies at which the fit was performed.

  • gamma_rec (numpy.ndarray) – The S11 of the receiver used in the fit.

  • gamma_src (dict[str, numpy.ndarray]) – The S11s of the calibration sources used in the fit.

  • modelfit (edges.modeling.composite.CompositeModel) – The composite model defining the model that was fit to the data.

  • delay (float) – The delay corrected for in the fit.

get_tcos(freq: Annotated[Quantity, PhysicalType('frequency')] | None = None, full_term=False)[source]

Compute the model for Tcos(freq).

If full_term is True, return the full term, i.e.

\[Tcos \frac{|Gamma_{\rm ant}| |F| \cos\alpha}{1 - |Gamma_{\rm rcv}|^2}\]

otherwise just return Tcos itself. This is not implemented yet (it’s a little trickier because it depends on which source you want it for).

get_tsin(freq: Annotated[Quantity, PhysicalType('frequency')] | None = None, full_term=False)[source]

Compute the model for Tsin(freq).

If full_term is True, return the full term, i.e.

\[Tsin \frac{|Gamma_{\rm ant}| |F| \sin\alpha}{1 - |Gamma_{\rm rcv}|^2}\]

otherwise just return Tsin itself. This is not implemented yet (it’s a little trickier because it depends on which source you want it for).

get_tunc(freq: Annotated[Quantity, PhysicalType('frequency')] | None = None, full_term=False)[source]

Compute the model for Tunc(freq).

If full_term is True, return the full term, i.e.

\[Tunc \frac{|Gamma_{\rm ant}|^2 |F|^2}{1 - |Gamma_{\rm rcv}|^2}\]

otherwise just return Tunc itself. This is not implemented yet (it’s a little trickier because it depends on which source you want it for).

property model

The model, with assigned parameters from best-fit.

property residual

The residual of the fit.

property rms

The RMS of the residual of the fit.

class edges.cal.noise_waves.NoiseWaves(*, freq: ndarray, gamma_src: dict[str, ndarray], gamma_rec: ndarray, c_terms: int = 5, w_terms: int = 6, parameters: Sequence | None = None, with_tload: bool = True)[source]

A class to manage linear models for fitting noise-wave parameters.

This is different from NoiseWaveLinearModel in several ways (ultimately they may be merged). The main way they are different is that this class allows for fitting not only the three noise-wave models (Tunc, Tcos, Tsin) but also the offset Tload – which is related to the known temperatures via a linear model as well. Also, this class is not restricted to accepting only the long-cable data (short and open), but can also accept the ambient and hot load calibration sources as input data, to which the noise-wave models are fitted simultaneously.

classmethod from_calobs(calobs, cterms: int, wterms: int, sources=None, with_tload: bool = True, loads: dict | None = None) Self[source]

Initialize a noise wave model from a calibration observation.

get_fitted(data: ndarray, weights: ndarray | None = None, **kwargs) Self[source]

Get a new noise wave model with fitted parameters.

get_full_model(src: str, parameters: Sequence | None = None) ndarray[source]

Get the full model (all noise-waves) for a particular input source.

get_linear_model(with_k: bool = True) CompositeModel[source]

Define and return a Model.

Parameters:

with_k – Whether to use the K matrix as an “extra basis” in the linear model.

get_noise_wave(noise_wave: str, parameters: Sequence | None = None, src: str | None = None) ndarray[source]

Get the model for a particular noise-wave term.

property linear_model: CompositeModel

The actual composite linear model object associated with the noise waves.

property src_names: tuple[str]

List of names of inputs sources (eg. ambient, hot_load, open, short).

edges.cal.noise_waves.get_F(gamma_rec: ndarray, gamma_ant: ndarray) ndarray[source]

Get the F parameter for a given receiver and antenna.

Parameters:
  • gamma_rec (np.ndarray) – The reflection coefficient (S11) of the receiver.

  • gamma_ant (np.ndarray) – The reflection coefficient (S11) of the antenna

Returns:

F (np.ndarray) – The F parameter (see M17)

edges.cal.noise_waves.get_K(gamma_rec, gamma_ant, f_ratio=None, alpha=None, gain=None)[source]

Determine the S11-dependent factors for each term in Eq. 7 (Monsalve 2017).

Parameters:
  • gamma_rec (array_like) – Receiver S11

  • gamma_ant (array_like) – Antenna (or load) S11.

  • f_ratio (array_like, optional) – The F factor (Eq. 3 of Monsalve 2017). Computed if not given.

  • alpha (array_like, optional) – The alpha factor (Eq. 4 of Monsalve, 2017). Computed if not given.

  • gain (array_like, optional) – The transmission function, (1 - Gamma_rec^2). Computed if not given.

Returns:

K0, K1, K2, K3 (array_like) – Factors corresponding to T_ant, T_unc, T_cos, T_sin respectively.

edges.cal.noise_waves.get_alpha(gamma_rec: ndarray, gamma_ant: ndarray) ndarray[source]

Get the alpha parameter for a given receiver and antenna.

Parameters:
  • gamma_rec (np.ndarray) – The reflection coefficient of the receiver.

  • gamma_ant (np.ndarray) – The reflection coefficient fo the antenna.

edges.cal.noise_waves.get_calibration_quantities_iterative(freqs: ~astropy.units.quantity.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')], source_q: dict, source_s11s: dict[str, ~numpy.ndarray], source_true_temps: dict[str, ~astropy.units.quantity.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')]], receiver_s11: ~numpy.ndarray, cterms: int, wterms: int, t_load_guess: ~astropy.units.quantity.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')] = <Quantity 300. K>, t_load_ns_guess: ~astropy.units.quantity.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')] = <Quantity 1000. K>, niter: int = 4, hot_load_loss: ~numpy.ndarray | None = None, smooth_scale_offset_within_loop: bool = True, delays_to_fit: ~numpy.ndarray = array([0.]), fit_method='lstsq', poly_spacing: float = 1.0, return_early: bool = False) Generator[tuple[Polynomial, Polynomial, NoiseWaveLinearModelFit]][source]

Derive calibration parameters using the scheme laid out in Monsalve (2017).

All equation numbers and symbol names come from M17 (arxiv:1602.08065).

Parameters:
  • freqs – The frequencies at which the data is specified.

  • source_q – The PSD ratios, Q, of the calibration sources, as a dictionary with the source names as keys.

  • source_s11s – A dictionary with the same keys as source_q, containing callable S11 models for each calibration source.

  • source_true_temps – A dictionary with the same keys as source_q, containing the true temperature of each calibration source, to which to calibrate the source_q. These must be astropy temperature Quantities, but may be scalar or arrays. If an array, must be the same length as freqs.

  • receiver_s11 – Receiver S11 as a function of frequency (callable).

  • cterms (int) – Number of polynomial terms for the C_i

  • wterms (int) – Number of polynonmial temrs for the T_i

  • t_load_guess – An initial guess for the internal dicke-switch load temperature, used to initialize the iterative algorithm.

  • t_load_ns_guess – An initial guess for the internal dicke-switch load+noise-sourc temperature, used to initialize the iterative algorithm.

  • niter (int) – The number of iterations to perform.

  • hot_load_loss (array_like, optional) – The loss of the hot load. If None, then either no loss is assumed, or the loss is already assumed to be applied to the “true” temperature of the hot load.

  • smooth_scale_offset_within_loop (bool) – If True, then the scale and offset are smoothed within the loop. If False, then the scale and offset are only smoothed at the end of the loop.

  • delays_to_fit (array_like) – The delays to sweep over when fitting noise-wave parameters. The delay resulting in the lowest residuals will be used.

  • poly_spacing – Spacing between polynomial term powers for scale and offset. Default of 1.0 is for a standard polynomial basis set. Alan’s C code use 0.5 for the scale/offset.

  • return_early – Whether to return from the iterative loop early if the RMS of the residuals stops decreasing.

Yields:
  • t_sca_model – A fitted polynomial model for the temperature scale (approximately, the true internal load+noise-source temperature, but with corrections from internal path-lengths).

  • t_off_model – A fitted polynomial model for the temperature offset (approximately, the true internal load temperature, but with corrections from internal path-lengths)

  • nwp – A fitted model for the noise-wave parameters. The values of each of the noise-wave temperatures can be accessed via e.g. nwp.get_tunc().

Notes

To achieve the same results as the legacy C pipeline, the hot_load_loss parameter should be given, and not applied to the “true” temperature. There is a small mathematical difference that arises if you do it the other way. Furthermore, the smooth_scale_offset_within_loop parameter should be set to False.

edges.cal.noise_waves.get_linear_coefficients(gamma_ant, gamma_rec, t_sca, t_off, t_unc, t_cos, t_sin)[source]

Use Monsalve (2017) Eq. 7 to determine a and b, such that T = aT* + b.

Parameters:
  • gamma_ant (array_like) – S11 of the antenna/load.

  • gamma_rec (array_like) – S11 of the receiver.

  • sca,off (array_like) – Scale and offset calibration parameters (i.e. Tsca and Toff). These are in the form of arrays over frequency (i.e. it is not the polynomial coefficients).

  • t_unc, t_cos, t_sin (array_like) – Noise-wave calibration parameters (uncorrelated, cosine, sine). These are in the form of arrays over frequency (i.e. not the polynomial coefficients).

edges.cal.noise_waves.get_linear_coefficients_from_K(k, t_sca, t_off, t_unc, t_cos, t_sin)[source]

Calculate linear coefficients a and b from noise-wave parameters K0-4.

Parameters:
  • k (np.ndarray) – Shape (4, nfreq) array with each of the K-coefficients.

  • sca,off (array_like) – Scale and offset calibration temperatures. These are in the form of arrays over frequency (i.e. it is not the polynomial coefficients).

  • t_unc, t_cos, t_sin (array_like) – Noise-wave calibration parameters (uncorrelated, cosine, sine). These are in the form of arrays over frequency (i.e. not the polynomial coefficients).

  • t_load (float, optional) – The nominal temperature of the internal ambient load. This must match the value used to derive the calibration parameters in the first place.

edges.cal.noise_waves.power_ratio(temp_ant, gamma_ant, gamma_rec, scale, offset, temp_unc, temp_cos, temp_sin, temp_noise_source, temp_load, return_terms=False)[source]

Compute the ratio of raw powers from the three-position switch.

Parameters:
  • temp_ant (array_like, shape (NFREQS,)) – Temperature of the antenna, or simulator.

  • gamma_ant (array_like, shape (NFREQS,)) – S11 of the antenna (or simulator)

  • gamma_rec (array_like, shape (NFREQS,)) – S11 of the receiver.

  • scale (np.poly1d) – A polynomial representing the C_1 term.

  • offset (np.poly1d) – A polynomial representing the C_2 term

  • temp_unc (np.poly1d) – A polynomial representing the uncorrelated noise-wave parameter

  • temp_cos (np.poly1d) – A polynomial representing the cosine noise-wave parameter

  • temp_sin (np.poly1d) – A polynomial representing the sine noise-wave parameter

  • temp_noise_source (array_like, shape (NFREQS,)) – Temperature of the internal noise source.

  • temp_load (array_like, shape (NFREQS,)) – Temperature of the internal load

  • return_terms (bool, optional) – If True, return the terms of Qp, rather than the sum of them._

Returns:

array_like (the quantity Q_P as a function of frequency.)

Notes

Computes (as a model)

\[Q_P = (P_ant - P_L)/(P_NS - P_L)\]