regularizepsf.transform#

Tools to transform from one PSF to another.

Classes#

ArrayPSFTransform

Representation of a transformation from a source to a target PSF that can be applied to images.

Module Contents#

class regularizepsf.transform.ArrayPSFTransform(transfer_kernel: regularizepsf.util.IndexedCube)[source]#

Representation of a transformation from a source to a target PSF that can be applied to images.

Initialize a PSFTransform.

Parameters:

transfer_kernel (TransferKernel) – the transfer kernel required by this ArrayPSFTransform

_transfer_kernel#
property psf_shape: tuple[int, int]#

Retrieve the shape of the individual PSFs for this transform.

property coordinates: list[tuple[int, int]]#

Retrieve the coordinates of the individual PSFs for this transform.

__len__() int[source]#

Retrieve the number of coordinates used to represent this transform.

classmethod construct(source: regularizepsf.psf.ArrayPSF, target: regularizepsf.psf.ArrayPSF, alpha: float, epsilon: float) ArrayPSFTransform[source]#

Construct an ArrayPSFTransform from a source to a target PSF.

Parameters:
  • source (ArrayPSF) – source point spread function

  • target (ArrayPSF) – target point spread function

  • alpha (float) – controls the “hardness” of the transition from amplification to attenuation

  • epsilon (float) – controls the maximum of the amplification

Returns:

corresponding ArrayPSFTransform instance

Return type:

ArrayPSFTransform

apply(image: numpy.ndarray, workers: int | None = None, pad_mode: str = 'symmetric', saturation_threshold: float = math.inf, saturation_dilation: int = 1, neighborhood_width: int = 7) numpy.ndarray[source]#

Apply the PSFTransform to an image.

Parameters:
  • image (np.ndarray) – image to apply the transform to

  • workers (int | None) – Maximum number of workers to use for parallel computation of FFT. If negative, the value wraps around from os.cpu_count(). See scipy.fft.fft for more details.

  • pad_mode (str) – how to pad the image when computing ffts, see np.pad for more details.

  • saturation_threshold (float) – pixels brighter than this threshold are filled with their neighborhood average before PSF correction and then refilled with the raw value after correction to avoid producing artifacts

  • saturation_dilation (int) – a nonnegative number of times to morphologically dilate the saturation mask before application

  • neighborhood_width (int) – an odd positive number indicating the size of the neighborhood used for filling saturated pixels

Returns:

image with psf transformed

Return type:

np.ndarray

visualize(fig: matplotlib.figure.Figure | None = None, fig_scale: int = 1, patch_stride: int = 1, edge_trim: int = 1, imshow_args: dict | None = None) None[source]#

Visualize the transform kernels.

Parameters:
  • fig (mp.figure.Figure) – the figure to plot in

  • fig_scale (int) – increasing this will make the figure higher resolution

  • edge_trim (int) – how many pixels to drop on each side of the PSF for plotting

  • patch_stride (int) – multiple of how many patches to skip when plotting, 1 means no skipping, 2 plots every other, 3 every third

  • imshow_args (dict) – additional arguments for imshow

Return type:

None

save(path: pathlib.Path, overwrite: bool = False) None[source]#

Save a PSFTransform to a file. Supports h5 and FITS.

Parameters:
  • path (pathlib.Path) – where to save the PSFTransform

  • overwrite (bool) – toggle to overwrite an existing file

Return type:

None

classmethod load(path: pathlib.Path) ArrayPSFTransform[source]#

Load a PSFTransform object. Supports h5 and FITS.

Parameters:

path (pathlib.Path) – file to load the PSFTransform from

Return type:

PSFTransform

__eq__(other: ArrayPSFTransform) bool[source]#

Test equality between two transforms.