astrophot.image.mixins package#
Submodules#
astrophot.image.mixins.cmos_mixin module#
- class astrophot.image.mixins.cmos_mixin.CMOSMixin(*args, subpixel_loc: Tuple[float, float] = (0, 0), subpixel_scale: float = 1.0, filename: str | None = None, **kwargs)[source]#
Bases:
objectA mixin class for CMOS image processing. This class can be used to add CMOS-specific functionality to image processing classes.
- property base_scale#
Get the base scale of the image, which is the subpixel scale.
astrophot.image.mixins.data_mixin module#
- class astrophot.image.mixins.data_mixin.DataMixin(*args, mask: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, std: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, variance: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, weight: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, _mask: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, _weight: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, **kwargs)[source]#
Bases:
objectMixin for data handling in image objects.
This mixin provides functionality for handling variance and mask, as well as other ancillary data.
Args: - mask: A boolean mask indicating which pixels to ignore. - std: Standard deviation of the image pixels. - variance: Variance of the image pixels. - weight: Weights for the image pixels.
Note that only one of std, variance, or weight should be provided at a time. If multiple are provided, an error will be raised.
- copy_kwargs(**kwargs)[source]#
Produce a copy of this image with all of the same properties. This can be used when one wishes to make temporary modifications to an image and then will want the original again.
- get_window(other: Image | Window, indices=None, **kwargs)[source]#
Get a sub-region of the image as defined by an other image on the sky.
- load(filename: str, hduext: int = 0)[source]#
Load the image from a FITS file. This will load the data, WCS, and any ancillary data such as variance, mask, and PSF.
- property mask#
The mask stores a tensor of boolean values which indicate any pixels to be ignored. These pixels will be skipped in likelihood evaluations and in parameter optimization. It is common practice to mask pixels with pathological values such as due to cosmic rays or satellites passing through the image.
In a mask, a True value indicates that the pixel is masked and should be ignored. False indicates a normal pixel which will inter into most calculations.
If no mask is provided, all pixels are assumed valid.
- reduce(scale: int, **kwargs) Image[source]#
Returns a new TargetImage object with a reduced resolution compared to the current image. scale should be an integer indicating how much to reduce the resolution. If the TargetImage was originally (48,48) pixels across with a pixelscale of 1 and reduce(2) is called then the image will be (24,24) pixels and the pixelscale will be 2. If reduce(3) is called then the returned image will be (16,16) pixels across and the pixelscale will be 3.
- property std#
Stores the standard deviation of the image pixels. This represents the uncertainty in each pixel value. It should always have the same shape as the image data. In the case where the standard deviation is not known, a tensor of ones will be created to stand in as the standard deviation values.
The standard deviation is not stored directly, instead it is computed as $sqrt{1/W}$ where $W$ is the weights.
- to(dtype=None, device=None)[source]#
Converts the stored Target_Image data, variance, psf, etc to a given data type and device.
- property variance#
Stores the variance of the image pixels. This represents the uncertainty in each pixel value. It should always have the same shape as the image data. In the case where the variance is not known, a tensor of ones will be created to stand in as the variance values.
The variance is not stored directly, instead it is computed as $frac{1}{W}$ where $W$ is the weights.
- property weight#
Stores the weight of the image pixels. This represents the uncertainty in each pixel value. It should always have the same shape as the image data. In the case where the weight is not known, a tensor of ones will be created to stand in as the weight values.
The weights are used to proprtionately scale residuals in the likelihood. Most commonly this shows up as a \(\chi^2\) like:
$$chi^2 = (vec{y} - vec{f(theta)})^TW(vec{y} - vec{f(theta)})$$
which can be optimized to find parameter values. Using the Jacobian, which in this case is the derivative of every pixel wrt every parameter, the weight matrix also appears in the gradient:
$$vec{g} = J^TW(vec{y} - vec{f(theta)})$$
and the hessian approximation used in Levenberg-Marquardt:
$$H approx J^TWJ$$
astrophot.image.mixins.sip_mixin module#
- class astrophot.image.mixins.sip_mixin.SIPMixin(*args, sipA: dict[Tuple[int, int], float] = {}, sipB: dict[Tuple[int, int], float] = {}, sipAP: dict[Tuple[int, int], float] = {}, sipBP: dict[Tuple[int, int], float] = {}, pixel_area_map: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, distortion_ij: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, distortion_IJ: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, filename: str | None = None, **kwargs)[source]#
Bases:
objectA mixin class for SIP (Simple Image Polynomial) distortion model.
- property A_ORDER: int#
- property B_ORDER: int#
- compute_backward_sip_coefs()[source]#
Credit: Shu Liu and Lei Hi, see here: Roman-Supernova-PIT/sfft
Compute the backward transformation from (U, V) to (u, v)
- expect_ctype = (('RA---TAN-SIP',), ('DEC--TAN-SIP',))#
- get_window(other: Image | Window, indices=None, **kwargs)[source]#
Get a sub-region of the image as defined by an other image on the sky.
- property pixel_area_map#
- pixel_to_plane(i: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], j: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], crtan: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], CD: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']) Tuple[Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']][source]#
- plane_to_pixel(x: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], y: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], crtan: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], CD: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']) Tuple[Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']][source]#
- update_distortion_model(distortion_ij: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, distortion_IJ: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, pixel_area_map: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None)[source]#
Update the pixel area map based on the current SIP coefficients.
Module contents#
- class astrophot.image.mixins.CMOSMixin(*args, subpixel_loc: Tuple[float, float] = (0, 0), subpixel_scale: float = 1.0, filename: str | None = None, **kwargs)[source]#
Bases:
objectA mixin class for CMOS image processing. This class can be used to add CMOS-specific functionality to image processing classes.
- property base_scale#
Get the base scale of the image, which is the subpixel scale.
- class astrophot.image.mixins.DataMixin(*args, mask: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, std: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, variance: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, weight: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, _mask: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, _weight: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, **kwargs)[source]#
Bases:
objectMixin for data handling in image objects.
This mixin provides functionality for handling variance and mask, as well as other ancillary data.
Args: - mask: A boolean mask indicating which pixels to ignore. - std: Standard deviation of the image pixels. - variance: Variance of the image pixels. - weight: Weights for the image pixels.
Note that only one of std, variance, or weight should be provided at a time. If multiple are provided, an error will be raised.
- copy_kwargs(**kwargs)[source]#
Produce a copy of this image with all of the same properties. This can be used when one wishes to make temporary modifications to an image and then will want the original again.
- get_window(other: Image | Window, indices=None, **kwargs)[source]#
Get a sub-region of the image as defined by an other image on the sky.
- load(filename: str, hduext: int = 0)[source]#
Load the image from a FITS file. This will load the data, WCS, and any ancillary data such as variance, mask, and PSF.
- property mask#
The mask stores a tensor of boolean values which indicate any pixels to be ignored. These pixels will be skipped in likelihood evaluations and in parameter optimization. It is common practice to mask pixels with pathological values such as due to cosmic rays or satellites passing through the image.
In a mask, a True value indicates that the pixel is masked and should be ignored. False indicates a normal pixel which will inter into most calculations.
If no mask is provided, all pixels are assumed valid.
- reduce(scale: int, **kwargs) Image[source]#
Returns a new TargetImage object with a reduced resolution compared to the current image. scale should be an integer indicating how much to reduce the resolution. If the TargetImage was originally (48,48) pixels across with a pixelscale of 1 and reduce(2) is called then the image will be (24,24) pixels and the pixelscale will be 2. If reduce(3) is called then the returned image will be (16,16) pixels across and the pixelscale will be 3.
- property std#
Stores the standard deviation of the image pixels. This represents the uncertainty in each pixel value. It should always have the same shape as the image data. In the case where the standard deviation is not known, a tensor of ones will be created to stand in as the standard deviation values.
The standard deviation is not stored directly, instead it is computed as $sqrt{1/W}$ where $W$ is the weights.
- to(dtype=None, device=None)[source]#
Converts the stored Target_Image data, variance, psf, etc to a given data type and device.
- property variance#
Stores the variance of the image pixels. This represents the uncertainty in each pixel value. It should always have the same shape as the image data. In the case where the variance is not known, a tensor of ones will be created to stand in as the variance values.
The variance is not stored directly, instead it is computed as $frac{1}{W}$ where $W$ is the weights.
- property weight#
Stores the weight of the image pixels. This represents the uncertainty in each pixel value. It should always have the same shape as the image data. In the case where the weight is not known, a tensor of ones will be created to stand in as the weight values.
The weights are used to proprtionately scale residuals in the likelihood. Most commonly this shows up as a \(\chi^2\) like:
$$chi^2 = (vec{y} - vec{f(theta)})^TW(vec{y} - vec{f(theta)})$$
which can be optimized to find parameter values. Using the Jacobian, which in this case is the derivative of every pixel wrt every parameter, the weight matrix also appears in the gradient:
$$vec{g} = J^TW(vec{y} - vec{f(theta)})$$
and the hessian approximation used in Levenberg-Marquardt:
$$H approx J^TWJ$$
- class astrophot.image.mixins.SIPMixin(*args, sipA: dict[Tuple[int, int], float] = {}, sipB: dict[Tuple[int, int], float] = {}, sipAP: dict[Tuple[int, int], float] = {}, sipBP: dict[Tuple[int, int], float] = {}, pixel_area_map: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, distortion_ij: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, distortion_IJ: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, filename: str | None = None, **kwargs)[source]#
Bases:
objectA mixin class for SIP (Simple Image Polynomial) distortion model.
- property A_ORDER: int#
- property B_ORDER: int#
- compute_backward_sip_coefs()[source]#
Credit: Shu Liu and Lei Hi, see here: Roman-Supernova-PIT/sfft
Compute the backward transformation from (U, V) to (u, v)
- expect_ctype = (('RA---TAN-SIP',), ('DEC--TAN-SIP',))#
- get_window(other: Image | Window, indices=None, **kwargs)[source]#
Get a sub-region of the image as defined by an other image on the sky.
- property pixel_area_map#
- pixel_to_plane(i: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], j: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], crtan: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], CD: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']) Tuple[Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']][source]#
- plane_to_pixel(x: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], y: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], crtan: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], CD: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']) Tuple[Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'], Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.']][source]#
- update_distortion_model(distortion_ij: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, distortion_IJ: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None, pixel_area_map: Annotated[Tensor, 'One of: torch.Tensor or jax.numpy.ndarray depending on the chosen backend.'] | None = None)[source]#
Update the pixel area map based on the current SIP coefficients.