wf_psf.utils.centroids

Centroids.

A module with utils to handle PSF centroids.

Author:

Tobias Liaudat <tobias.liaudat@cea.fr> and Jennifer Pollack <jennifer.pollack@cea.fr>

Functions

compute_zernike_tip_tilt(star_images[, ...])

Compute Zernike tip-tilt corrections for a batch of PSF images.

decim(im, d[, av_en, fft])

Decimate image to lower resolution.

degradation_op(X, shift_ker, D)

Shift and decimate fine-grid image.

lanczos(U[, n, n2])

Generate Lanczos kernel for a given shift.

shift_ker_stack(shifts, upfact[, lanc_rad])

Generate shifting kernels and rotated shifting kernels.

Classes

CentroidEstimator(im[, mask, sigma_init, ...])

Calculate centroids and estimate intra-pixel shifts for a batch of star images.

class wf_psf.utils.centroids.CentroidEstimator(im, mask=None, sigma_init=7.5, n_iter=5, auto_run=True, xc=None, yc=None)[source]

Bases: object

Calculate centroids and estimate intra-pixel shifts for a batch of star images.

This class estimates the centroid of each star in a batch of images using an iterative process that fits an elliptical Gaussian model to the star images. The estimated centroids are returned along with the intra-pixel shifts, which represent the difference between the estimated centroid and the center of the image grid (or pixel grid).

The process is vectorized, allowing multiple star images to be processed in parallel, which significantly improves performance when working with large batches.

Parameters:
  • im (numpy.ndarray) – A 3D numpy array of star image stamps. The shape of the array should be (n_images, height, width), where n_images is the number of stars, and height and width are the dimensions of each star’s image.

  • mask (numpy.ndarray, optional) – A 3D numpy array of the same shape as im, representing the mask for each star image. A mask value of 0 indicates that the pixel is fully considered (unmasked), while a value of 1 means the pixel is completely ignored (masked). Values between 0 and 1 act as weights, allowing partial consideration of the pixel. If not provided, no mask is applied.

  • sigma_init (float, optional) – The initial guess for the standard deviation (sigma) of the elliptical Gaussian that models the star. Default is 7.5.

  • n_iter (int, optional) – The number of iterations for the iterative centroid estimation procedure. Default is 5.

  • auto_run (bool, optional) – If True, the centroid estimation procedure will be automatically run upon initialization. Default is True.

  • xc (float, optional) – The initial guess for the x-component of the centroid. If None, it is set to the center of the image. Default is None.

  • yc (float, optional) – The initial guess for the y-component of the centroid. If None, it is set to the center of the image. Default is None.

xc

The x-components of the estimated centroids for each image. Shape is (n_images,).

Type:

numpy.ndarray

yc

The y-components of the estimated centroids for each image. Shape is (n_images,).

Type:

numpy.ndarray

update_grid()[source]

Updates the grid of pixel positions based on the current centroid estimates.

elliptical_gaussian(e1=0, e2=0)[source]

Computes an elliptical 2D Gaussian with the specified shear parameters.

compute_moments()[source]

Computes the first-order moments of the star images and updates the centroid estimates.

estimate()[source]

Runs the iterative centroid estimation procedure for all images.

get_centroids()[source]

Returns the estimated centroids for all images as a 2D numpy array.

get_intra_pixel_shifts()[source]

Gets the intra-pixel shifts for all images as a list of x and y displacements.

Notes

The iterative centroid estimation procedure fits an elliptical Gaussian to each star image and computes the centroid by calculating the weighted moments. The estimate() method performs the centroid calculation for a batch of images using the iterative approach defined by the n_iter parameter. This class is designed to be efficient and scalable when processing large batches of star images.

Methods

compute_moments()

Compute the moments for multiple PSFs at once.

elliptical_gaussian([e1, e2])

Compute an elliptical 2D Gaussian with arbitrary centroid.

estimate()

Estimate centroids for all images.

get_centroids()

Return centroids for all images.

get_intra_pixel_shifts()

Get intra-pixel shifts for all images.

update_grid()

Vectorized update of the grid coordinates for multiple star stamps.

compute_moments()[source]

Compute the moments for multiple PSFs at once.

elliptical_gaussian(e1=0, e2=0)[source]

Compute an elliptical 2D Gaussian with arbitrary centroid.

estimate()[source]

Estimate centroids for all images.

get_centroids()[source]

Return centroids for all images.

get_intra_pixel_shifts()[source]

Get intra-pixel shifts for all images.

Intra-pixel shifts are the differences between the estimated centroid and the center of the image stamp (or pixel grid). These shifts are calculated for all images in the batch.

Returns:

A 2D array of shape (num_of_images, 2), where each row corresponds to the x and y shifts for each image.

Return type:

np.array

update_grid()[source]

Vectorized update of the grid coordinates for multiple star stamps.

wf_psf.utils.centroids.compute_zernike_tip_tilt(star_images: ndarray, star_masks: ndarray | None = None, pixel_sampling: float = 1.2e-05, reference_shifts: list[float] = [-0.3333333333333333, -0.3333333333333333], sigma_init: float = 2.5, n_iter: int = 20) ndarray[source]

Compute Zernike tip-tilt corrections for a batch of PSF images.

This function estimates the centroid shifts of multiple PSFs and computes the corresponding Zernike tip-tilt corrections to align them with a reference.

Parameters:
  • star_images (np.ndarray) – A batch of PSF images (3D array of shape (num_images, height, width)).

  • star_masks (np.ndarray, optional) – A batch of masks (same shape as star_postage_stamps). Each mask can have: - 0 to ignore the pixel. - 1 to fully consider the pixel. - Values in (0,1] as weights for partial consideration. Defaults to None.

  • pixel_sampling (float, optional) – The pixel size in meters. Defaults to 12e-6 m (12 microns).

  • reference_shifts (list[float], optional) – The target centroid shifts in pixels, specified as [dy, dx]. Defaults to [-1/3, -1/3] (nominal Euclid conditions).

  • sigma_init (float, optional) – Initial standard deviation for centroid estimation. Default is 2.5.

  • n_iter (int, optional) – Number of iterations for centroid refinement. Default is 20.

Returns:

An array of shape (num_images, 2), where: - Column 0 contains Zk1 (tip) values. - Column 1 contains Zk2 (tilt) values.

Return type:

np.ndarray

Notes

  • This function processes all images at once using vectorized operations.

  • The Zernike coefficients are computed in the WaveDiff convention.

wf_psf.utils.centroids.decim(im, d, av_en=1, fft=1)[source]

Decimate image to lower resolution.

wf_psf.utils.centroids.degradation_op(X, shift_ker, D)[source]

Shift and decimate fine-grid image.

wf_psf.utils.centroids.lanczos(U, n=10, n2=None)[source]

Generate Lanczos kernel for a given shift.

wf_psf.utils.centroids.shift_ker_stack(shifts, upfact, lanc_rad=8)[source]

Generate shifting kernels and rotated shifting kernels.