draco.util.regrid

Routines for regridding irregular data using a Lanczos/Wiener filtering approach.

This is described in some detail in doclib:173.

Functions

band_wiener(R, Ni, Si, y, bw)

Calculate the Wiener filter assuming various bandedness properties.

grad_1d(x, si, mask[, period])

Gradient with boundary samples wrapped.

lanczos_forward_matrix(x, y[, a, periodic])

Lanczos interpolation matrix.

lanczos_inverse_matrix(x, y[, a, cond])

Regrid data using a maximum likelihood inverse Lanczos.

lanczos_kernel(x, a)

Lanczos interpolation kernel.

rebin_matrix(tra, ra[, width_t])

Construct a matrix to rebin the samples.

taylor_coeff(x, N, M, Ni, Si[, period, xc])

Return a set of sparse matrices that estimates expansion coefficients.

draco.util.regrid.band_wiener(R, Ni, Si, y, bw)[source]

Calculate the Wiener filter assuming various bandedness properties.

In particular this asserts that a particular element in the filtered output will only couple to the nearest bw elements. Equivalently, this is that the covariance matrix will be band diagonal. This allows us to use fast routines to generate the solution.

Note that the inverse noise estimate returned is \(\mathrm{diag}(\mathbf{R}^T \mathbf{N}^{-1} \mathbf{R})\) and not the full Bayesian estimate including a contribution from the signal covariance.

Parameters:
  • R (np.ndarray[m, n]) – Transfer matrix for the Wiener filter.

  • Ni (np.ndarray[k, n]) – Inverse noise matrix. Noise assumed to be uncorrelated (i.e. diagonal matrix).

  • Si (np.narray[m]) – Inverse signal matrix. Signal model assumed to be uncorrelated (i.e. diagonal matrix).

  • y (np.ndarray[k, n]) – Data to apply to.

  • bw (int) – Bandwidth, i.e. how many elements couple together.

Returns:

  • xhat (np.ndarray[k, m]) – Filtered data.

  • nw (np.ndarray[k, m]) – Estimate of variance of each element.

draco.util.regrid.grad_1d(x: ndarray, si: ndarray, mask: ndarray, period: float | None = None) ndarray[source]

Gradient with boundary samples wrapped.

Parameters:
  • x – Data to calculate the gradient for.

  • si – Positions of the samples. Must be monotonically increasing.

  • mask – Boolean mask, True where a sample is flagged.

  • period – Period of samples. Default is None, which produces a non-periodic gradient.

Returns:

  • gradient – Gradient of x. Gradient is set to zero where any sample in the calculation was flagged.

  • mask – Boolean mask corresponding to samples for which a proper gradient could not be calculated. True where a sample is flagged.

draco.util.regrid.lanczos_forward_matrix(x, y, a=5, periodic=False)[source]

Lanczos interpolation matrix.

Parameters:
  • x (np.ndarray[m]) – Points we have data at. Must be regularly spaced.

  • y (np.ndarray[n]) – Point we want to interpolate data onto.

  • a (integer, optional) – Lanczos width parameter.

  • periodic (boolean, optional) – Treat input points as periodic.

Returns:

matrix – Lanczos regridding matrix. Apply to data with np.dot(matrix, data).

Return type:

np.ndarray[m, n]

draco.util.regrid.lanczos_inverse_matrix(x, y, a=5, cond=0.1)[source]

Regrid data using a maximum likelihood inverse Lanczos.

Parameters:
  • x (np.ndarray[m]) – Points to regrid data onto. Must be regularly spaced.

  • y (np.ndarray[n]) – Points we have data at. Irregular spacing.

  • a (integer, optional) – Lanczos width parameter.

  • cond (float) – Relative condition number for pseudo-inverse.

Returns:

matrix – Lanczos regridding matrix. Apply to data with np.dot(matrix, data).

Return type:

np.ndarray[m, n]

draco.util.regrid.lanczos_kernel(x, a)[source]

Lanczos interpolation kernel.

Parameters:
  • x (array_like) – Point separation.

  • a (integer) – Lanczos kernel width.

Returns:

kernel

Return type:

np.ndarray

draco.util.regrid.rebin_matrix(tra: ndarray, ra: ndarray, width_t: float = 0) ndarray[source]

Construct a matrix to rebin the samples.

Parameters:
  • tra – The samples we have in the time stream.

  • ra – The target samples we want in the sidereal stream.

  • width_t – The width of a time sample. Set to zero to do a nearest bin assignment.

Returns:

A matrix to perform the rebinning.

Return type:

R

draco.util.regrid.taylor_coeff(x: ndarray, N: int, M: int, Ni: ndarray, Si: float, period: float | None = None, xc: ndarray | None = None) list[csr_array][source]

Return a set of sparse matrices that estimates expansion coefficients.

Parameters:
  • x – Positions of each element.

  • N – Number of positions each side to estimate from.

  • M – The number of terms in the expansion.

  • Ni – The weight for each position. The inverse noise variance if interpreted as a Wiener filter.

  • Si – A regulariser. The inverse signal variance if interpreted as a Wiener filter.

  • period – If set, assume the axis is periodic with this period.

  • xc – An optional parameter giving the location to return the coefficients at. If not set, just use the locations of each individual sample.

Returns:

A set of sparse matrices that will estimate the coefficents at each location. Each matrix is for a different coefficient.

Return type:

matrices