Covariance¶
- class spizzle.Covariance(out_shape, radius=None, dtype=<class 'numpy.float32'>, fillval=nan)¶
Bases:
objectCovariance between nearby pixels of the image of drizzled exposures.
Add the same operators as to Coadd, each with the variance of its exposure’s data (for example the sum of its variance planes); the image is Coadd.out_img. The covariance is kept for the offsets
(dy, dx)with|dy|, |dx| <= radius, for half of them, listed in offsets:(0, 0), then(0, 1)to(0, radius), then(dy, -radius)to(dy, radius)fordyfrom 1 toradius. The others follow fromCov(img[y, x], img[y - dy, x - dx]) = covariance(k)[y - dy, x - dx].Pixels farther apart than an input pixel’s footprint share no input pixel and have no covariance; Operator.reach is that distance. By default the radius is the reach of the first operator added. An operator that reaches farther than the radius gives a warning, as the covariance beyond the radius is left out.
The sums take
2 * radius * (radius + 1) + 1output-sized images ofdtype; each exposure’s contribution is computed in float64 before it is added. Output pixels that no exposure reaches are not written, so the system does not give them memory until the results are made. The results are made one image at a time.- Parameters:
- out_shapetuple of int
(ny_out, nx_out).- radiusint, optional
Largest offset kept, in output pixels, in y and in x; by default the reach of the first operator added.
- dtype{numpy.float32, numpy.float64}
Type of the sums and of the results.
- fillvalfloat
Value where the pixel or its neighbor has no weight or variance, or the neighbor is outside the output grid.
Attributes Summary
ndarray, shape out_shape: covariance of each pixel with every pixel, over its variance.
ndarray, shape (n_offsets,) + out_shape: covariance for every offset, all in memory at once.
ndarray, shape out_shape: variance of the image, covariance at offset (0, 0).
Methods Summary
add(W, var[, iscale])Add one exposure.
correlation(k)Correlation coefficient of each pixel with its neighbor at
offsets[k].covariance(k)Covariance of each pixel with its neighbor at
offsets[k].write_correlation(path[, overwrite])Write the correlation of each pixel with its neighbors to a FITS file.
Attributes Documentation
- noise_factor¶
ndarray, shape out_shape: covariance of each pixel with every pixel, over its variance.
The variance of a sum over an area much larger than an input pixel’s footprint is the sum of the variances of its pixels times this factor, so
sqrt(var * noise_factor)is the uncertainty of each pixel for such sums, wheresqrt(var)is that of the pixel alone. For evenly dithered exposures it is the square of the noise ratio R of Casertano et al. (2000). fillval where the pixel has no weight or variance.
- out_cov¶
ndarray, shape (n_offsets,) + out_shape: covariance for every offset, all in memory at once.
- out_var¶
ndarray, shape out_shape: variance of the image, covariance at offset (0, 0).
Methods Documentation
- add(W, var, iscale=1.0)¶
Add one exposure.
- Parameters:
- WOperator or scipy.sparse array
The exposure’s operator, as for Coadd.add. A sparse array records no reach, so it needs the radius to be set.
- varndarray, shape (ny, nx)
Variance of the exposure’s data.
- iscalefloat
Factor applied to the data; its square is applied to
var.
- correlation(k)¶
Correlation coefficient of each pixel with its neighbor at
offsets[k].- Parameters:
- kint
- Returns:
- ndarray, shape out_shape
Cov(img[o], img[o']) / sqrt(Var(img[o]) Var(img[o'])); fillval where either pixel has no variance or the neighbor is off the grid.
- covariance(k)¶
Covariance of each pixel with its neighbor at
offsets[k].- Parameters:
- kint
- Returns:
- ndarray, shape out_shape
Cov(img[y, x], img[y + dy, x + dx]); fillval where either pixel has no weight or the neighbor is off the grid.
- write_correlation(path, overwrite=False)¶
Write the correlation of each pixel with its neighbors to a FITS file.
Extension CORR is a float32 cube of shape
(n_offsets - 1,) + out_shapewhose planek - 1is correlation foroffsets[k], k from 1, and extension OFFSETS a table of theirdyanddx; the primary header has the radius. The planes are made and written one at a time. Needs astropy.- Parameters:
- pathstr or os.PathLike
- overwritebool
Replace an existing file.