Module: wcs_utils#
A collection of utility functions for working with WCS in KBMOD.
- kbmod.wcs_utils.append_wcs_to_hdu_header(wcs, header)[source]#
Append the WCS fields to an existing HDU header.
- Parameters:
- wcsastropy.wcs.WCS or dict
The WCS to use or a dictionary with the necessary information.
- headerastropy.io.fits.Header
The header to which to append the data.
- kbmod.wcs_utils.calc_actual_image_fov(wcs)[source]#
Calculate the actual image field of view in degrees calculated for the wcs measured from image edge to edge along lines passing through the reference pixel.
- Parameters:
- wcsastropy.wcs.WCS
The WCS object to calculate the field of view for.
- Returns:
- astropy.units.Quantity
The field of view in degrees measured edge to edge across both image dimensions and through the reference pixel.
Notes
While this will work for any WCS, it is intended to be used with tangent plane projections where the reference pixel is on the image.
- kbmod.wcs_utils.calc_ecliptic_angle(wcs, center_pixel=(1000, 2000), step=12)[source]#
Projects an unit-vector parallel with the ecliptic onto the image and calculates the angle of the projected unit-vector in the pixel space.
- Parameters:
- wcs
astropy.wcs.WCS
World Coordinate System object.
- center_pixeltuple, array-like
Pixel coordinates of image center.
- step
float
orint
Size of step, in arcseconds, used to find the pixel coordinates of the second pixel in the image parallel to the ecliptic.
- wcs
- Returns:
- suggested_angle
float
Angle the projected unit-vector parallel to the eclipticc closes with the image axes. Used to transform the specified search angles, with respect to the ecliptic, to search angles within the image.
- suggested_angle
Notes
It is not neccessary to calculate this angle for each image in an image set if they have all been warped to a common WCS.
- kbmod.wcs_utils.construct_wcs_tangent_projection(ref_val, img_shape=[4096, 4096], ref_pix=None, pixel_scale: Quantity | None = None, image_fov: Quantity | None = None, solve_for_image_fov: bool = False)[source]#
Construct a WCS tangent projection.
- Parameters:
- ref_valastropy.coordinates.SkyCoord
The reference coordinate of the tangent projection. If None is given the reference coordinate is set to (0, -40) degrees.
- img_shapelist[int], optional
The shape of the image, by default [4096, 4096]
- ref_pixlist[float], optional
The reference pixel of the tangent projection, by default None If None is given, the image center pixel is used. Note that the values are one based in keeping with the astropy.wcs.WCS convention which contrasts with the zero based convention for the pixel coordinates.
- pixel_scaleastropy.units.Quantity, optional
The pixel scale of the image, by default None If None and image_fov is provided, the pixel scale is calculated from the image field of view. If None and image_fov is not provided, the pixel scale is set to 0.2 arcsec/pixel to match LSST.
- image_fovastropy.units.Quantity, optional
The field of view of the first image dimension, by default None If provided the pixel scale is calculated from the image shape and the field of view
- solve_for_image_fovbool, optional
If True, image_fov is provided, and pixel_scale is None then a (slow) search is made to make the horizontal field of view match image_fov. This should be analytic but as yet no such solution is contained. The default is False.
- Returns:
- astropy.wcs.WCS
The WCS tangent projection.
- kbmod.wcs_utils.deserialize_wcs(wcs_str)[source]#
Convert a JSON string into a WCS object.
- Parameters:
- wcs_strstr
The serialized WCS.
- Returns:
- wcsastropy.wcs.WCS or None
The resulting WCS or None if no data is provided.
- kbmod.wcs_utils.extract_wcs_from_hdu_header(header)[source]#
Read an WCS from the an HDU header and do basic validity checking.
- Parameters:
- headerastropy.io.fits.Header
The header from which to read the data.
- Returns:
- curr_wcsastropy.wcs.WCS
The WCS or None if it does not exist.
- kbmod.wcs_utils.make_fake_wcs(center_ra, center_dec, height, width, deg_per_pixel=None)[source]#
Create a fake WCS given basic information. This is not a realistic WCS in terms of astronomy, but can provide a place holder for many tests.
- Parameters:
- center_rafloat
The center of the pointing in RA (degrees)
- center_devfloat
The center of the pointing in DEC (degrees)
- heightint
The image height (pixels).
- widthint
The image width (pixels).
- deg_per_pixelfloat, optional
The angular resolution of a pixel (degrees).
- Returns:
- resultastropy.wcs.WCS
The resulting WCS.
- kbmod.wcs_utils.make_fake_wcs_info(center_ra, center_dec, height, width, deg_per_pixel=None)[source]#
Create a fake WCS dictionary given basic information. This is not a realistic WCS in terms of astronomy, but can provide a place holder for many tests.
- Parameters:
- center_rafloat
The center of the pointing in RA (degrees)
- center_devfloat
The center of the pointing in DEC (degrees)
- heightint
The image height (pixels).
- widthint
The image width (pixels).
- deg_per_pixelfloat, optional
The angular resolution of a pixel (degrees).
- Returns:
- wcs_dictdict
A dictionary with the information needed for a WCS.
- kbmod.wcs_utils.serialize_wcs(wcs)[source]#
Convert a WCS into a JSON string.
- Parameters:
- wcsastropy.wcs.WCS or None
The WCS to convert.
- Returns:
- wcs_strstr
The serialized WCS. Returns an empty string if wcs is None.
- kbmod.wcs_utils.solve_wcs_for_fov(wcs, fov)[source]#
Solve for the pixel scale of the WCS given the field of view.
- Parameters:
- wcsastropy.wcs.WCS
The WCS to solve for.
- fovastropy.units.Quantity
The field of view of the first image dimension to solve for.
- Returns:
- astropy.wcs.WCS
The WCS with the pixel scale adjusted to match the field of view.
Notes
This is a slow iterative solution. It should be possible to solve this analytically. The method starts with the pixel scale of the reference pixel and then expands the lower and upper search bounds by a factor of two until the field of view is bracketed. Then a bisection search is performed to find the pixel scale that matches the field of view. An iteration limit is imposed to prevent an infinite loop.
- kbmod.wcs_utils.wcs_fits_equal(wcs_a, wcs_b)[source]#
Test if two WCS objects are equal at the level they would be written to FITS headers. Treats a pair of None values as equal.
- Parameters:
- wcs_aastropy.wcs.WCS
The WCS of the first object.
- wcs_bastropy.wcs.WCS
The WCS of the second object.