astra.pointer#
Astronomical pointing correction and plate solving utilities.
This module provides comprehensive tools for correcting telescope pointing errors by analyzing astronomical images and comparing detected stars with catalog data. The primary workflow involves star detection, world coordinate system (WCS) computation, and pointing offset calculation.
Key Features: - Multi-scale star detection algorithms for robust identification in noisy images - Gaia star catalog integration for precise astrometric reference - World Coordinate System (WCS) computation using the twirl library - Automatic pointing correction calculation and validation - Support for FITS file processing with metadata extraction - Background subtraction and image cleaning utilities
The module supports two main use cases: 1. Real-time pointing correction during observations 2. Post-processing analysis of astronomical images
- Typical Workflow:
Load or generate an astronomical image
Detect stars using multi-scale algorithms
Query Gaia catalog for reference stars in the field
Compute WCS transformation between image and sky coordinates
Calculate pointing correction based on target vs actual position
Apply corrections to telescope pointing
- Classes:
PointingCorrection: Stores target vs actual pointing coordinates ImageStarMapping: Handles star detection and catalog matching
- Functions:
calculate_pointing_correction_from_fits: Complete pointing correction from FITS file calculate_pointing_correction_from_image: Complete pointing correction from image array find_stars: Basic star detection using DAOStarFinder local_gaia_db_query: Query local Gaia database for reference stars local_db_query: Low-level database query for astronomical catalogs
Example
# Process a FITS file for pointing correction pointing_correction, image_star_mapping, num_stars = (
- calculate_pointing_correction_from_fits(
“observation.fits”, target_ra=150.25, target_dec=2.18
)
)
# Get the pointing offset ra_offset = pointing_correction.offset_ra dec_offset = pointing_correction.offset_dec
print(f”Pointing error: RA={ra_offset:.3f}°, Dec={dec_offset:.3f}°”)
Functions
|
Calculate pointing correction from a FITS file. |
Calculate pointing correction from an image array. |
|
|
Find stars using DAOStarFinder algorithm. |
|
Query astronomical database for objects within coordinate bounds. |
|
Query local Gaia database to retrieve RA-DEC coordinates of stars within a given field-of-view. |
Classes
|
A class to handle the mapping of stars detected in an image to their corresponding Gaia star coordinates using World Coordinate System (WCS) transformations. |
|
Class to store the pointing correction between the desired target center and the plating center. |
- astra.pointer.calculate_pointing_correction_from_fits(filepath: str | Path | None, dark_frame: str | Path | None = None, target_ra: float | None = None, target_dec: float | None = None, filter_band: str | None = None, fraction_of_stars_to_match: float = 0.70, or_min_number_of_stars_to_match: int = 8)[source]#
Calculate pointing correction from a FITS file.
Performs the complete plate solving workflow from a FITS file, including metadata extraction, image cleaning, star detection, and pointing correction.
- Parameters:
filepath (str or Path) – Path to the FITS file.
dark_frame (str or Path, optional) – Path to a dark frame for subtraction. Defaults to None.
target_ra (float, optional) – Target right ascension in degrees. If not provided, it’s read from FITS header. Defaults to None.
target_dec (float, optional) – Target declination in degrees. If not provided, it’s read from FITS header. Defaults to None.
filter_band (str, optional) – Filter band used for observation. Defaults to None.
fraction_of_stars_to_match (float, optional) – Fraction of detected stars required to be matched for a valid plate solve. Defaults to 0.70.
or_min_number_of_stars_to_match (int, optional) – Minimum number of stars required to be matched for a valid plate solve. Defaults to 8.
- Returns:
Tuple[PointingCorrection, ImageStarMapping, int] –
- A tuple containing:
PointingCorrection: Object with computed pointing correction
ImageStarMapping: Mapping of image stars to Gaia stars
int: Number of stars used from the image for plate solving
- Raises:
Exception – If insufficient stars are detected for plate solving, if the offset is larger than the field of view, or if too few stars are matched.
- astra.pointer.calculate_pointing_correction_from_image(image: ndarray, target_ra: float, target_dec: float, dateobs: datetime, plate_scale: float, filter_band: str | None = None, fraction_of_stars_to_match: float = 0.70, or_min_number_of_stars_to_match: int = 8)[source]#
Calculate pointing correction from an image array.
Performs the complete plate solving workflow: image cleaning, star detection, Gaia catalog matching, WCS computation, and pointing correction calculation.
- Parameters:
image (np.ndarray) – The 2D astronomical image data.
target_ra (float) – Target right ascension in degrees.
target_dec (float) – Target declination in degrees.
dateobs (datetime) – Observation date for proper motion corrections.
plate_scale (float) – Image plate scale in degrees per pixel.
filter_band (str, optional) – Filter band used for observation.
fraction_of_stars_to_match (float, optional) – Fraction of detected stars required to be matched for a valid plate solve. Defaults to 0.70.
or_min_number_of_stars_to_match (int, optional) – Minimum number of stars required to be matched for a valid plate solve. Defaults to 8.
- Returns:
Tuple[PointingCorrection, ImageStarMapping, int] –
- A tuple containing:
PointingCorrection: Object with computed pointing correction
ImageStarMapping: Mapping of image stars to Gaia stars
int: Number of stars used from the image for plate solving
- Raises:
Exception – If insufficient stars are detected for plate solving, if the offset is larger than the field of view, or if too few stars are matched.
- astra.pointer.find_stars(data: ndarray, threshold: float = 5.0, fwhm: float = 3.0) ndarray[source]#
Find stars using DAOStarFinder algorithm.
Uses the photutils DAOStarFinder algorithm to detect point sources in astronomical images. The function performs background subtraction and returns star coordinates sorted by brightness.
- Parameters:
data (np.ndarray) – The 2D image data array.
threshold (float, optional) – Detection threshold in units of background standard deviation. Higher values detect fewer, brighter stars. Defaults to 5.0.
fwhm (float, optional) – Expected Full Width at Half Maximum of stars in pixels. Should match the typical seeing conditions. Defaults to 3.0.
- Returns:
np.ndarray –
- Array of detected star coordinates sorted by brightness.
Shape is (N, 2) where N is the number of stars, and each row is (x, y). Returns an empty array if no stars are found.
- class astra.pointer.PointingCorrection(target_ra: float, target_dec: float, plating_ra: float, plating_dec: float)[source]#
Bases:
objectClass to store the pointing correction between the desired target center and the plating center.
Stores target and actual telescope pointing coordinates and provides methods to calculate offsets, angular separations, and proxy coordinates for correction. The proxy coordinates represent where the telescope should point to achieve the desired target position.
- Properties:
offset_ra: RA offset (plating - target) in degrees offset_dec: Dec offset (plating - target) in degrees angular_separation: Angular distance between target and actual position proxy_ra: RA coordinate to point telescope to reach target proxy_dec: Dec coordinate to point telescope to reach target
Example
>>> from astra.pointer import PointingCorrection >>> pointing_correction = PointingCorrection( ... target_ra=10.685, target_dec=41.269, ... plating_ra=10.68471, plating_dec=41.26917 ... ) >>> print(f"RA offset: {pointing_correction.offset_ra:.4f} degrees")
- property offset_ra#
Calculate the RA offset between plating and target coordinates.
- Returns:
float –
- RA offset (plating_ra - target_ra) in degrees. Positive values
indicate the telescope pointed east of the target.
- property offset_dec#
Calculate the Dec offset between plating and target coordinates.
- Returns:
float –
- Dec offset (plating_dec - target_dec) in degrees. Positive values
indicate the telescope pointed north of the target.
- property angular_separation: float#
Calculate the angular separation between target and plating coordinates.
- Returns:
float –
- Angular distance between target and actual position in degrees.
Always positive, represents the magnitude of the pointing error.
- property proxy_ra#
Calculate the RA coordinate to point the telescope to reach the target RA.
This assumes that the offset is independent of the telescope’s position in the sky. The proxy coordinate compensates for the systematic pointing error.
- Returns:
float –
- RA coordinate in degrees where the telescope should point to
effectively arrive at the target RA.
See also
ConstantDistorter: Verify sign convention of correction.
- property proxy_dec#
Calculate the Dec coordinate to point the telescope to reach the target Dec.
This assumes that the offset is independent of the telescope’s position in the sky. The proxy coordinate compensates for the systematic pointing error.
- Returns:
float –
- Dec coordinate in degrees where the telescope should point to
effectively arrive at the target Dec.
See also
ConstantDistorter: Verify sign convention of correction.
- class astra.pointer.ImageStarMapping(wcs: WCS, stars_in_image: ndarray, gaia_stars_in_image: ndarray)[source]#
Bases:
objectA class to handle the mapping of stars detected in an image to their corresponding Gaia star coordinates using World Coordinate System (WCS) transformations.
Manages the relationship between pixel coordinates of detected stars and their celestial coordinates from the Gaia catalog. Provides methods for coordinate transformations, star matching, and validation of the plate solving process.
- wcs#
The World Coordinate System object used for mapping celestial coordinates to pixel coordinates.
- Type:
WCS
- stars_in_image#
An array of detected star coordinates in the image, represented in pixel format (x, y).
- Type:
np.ndarray
- gaia_stars_in_image#
An array of Gaia star coordinates projected into the image’s pixel space using the WCS transformation.
- Type:
np.ndarray
- classmethod from_gaia_coordinates(stars_in_image: ndarray, gaia_stars: ndarray)[source]#
Create an ImageStarMapping instance from detected stars and Gaia coordinates.
Computes the World Coordinate System (WCS) transformation using the twirl library to map between pixel and sky coordinates.
- Parameters:
stars_in_image (np.ndarray) – Array of detected star coordinates in pixels (x, y).
gaia_stars (np.ndarray) – Array of Gaia star coordinates in degrees (ra, dec).
- Returns:
ImageStarMapping – New instance with computed WCS and transformed coordinates.
- get_plating_center(image_shape: Tuple[int, int]) Tuple[float, float][source]#
Calculate the sky coordinates of the image center (plating center).
- Parameters:
image_shape (Tuple[int, int]) – Shape of the image as (height, width).
- Returns:
Tuple[float, float] – RA and Dec coordinates of the image center in degrees.
- skycoord_to_pixels(ra: float, dec: float) Tuple[float, float][source]#
Convert sky coordinates to pixel coordinates using the WCS.
- Parameters:
ra (float) – Right ascension in degrees.
dec (float) – Declination in degrees.
- Returns:
Tuple[float, float] – Pixel coordinates (x, y) in the image.
- pixels_to_skycoord(pixels: ndarray)[source]#
Convert pixel coordinates to sky coordinates using the WCS.
- Parameters:
pixels (np.ndarray) – Array of pixel coordinates.
- Returns:
Array of sky coordinates corresponding to the input pixels.
- find_gaia_match()[source]#
Find the closest Gaia star match for each detected star in the image.
Calculates the distance between each detected star and all Gaia stars in pixel space, then returns the closest match and distance for each.
- Returns:
Tuple[np.ndarray, np.ndarray] – - Matched Gaia star positions in pixel coordinates - Distances to the closest matches in pixels
- number_of_matched_stars(pixel_threshold: int = 10)[source]#
Count the number of stars matched within a pixel threshold.
- Parameters:
pixel_threshold (int, optional) – Maximum distance in pixels to consider a match valid. Defaults to 10.
- Returns:
int – Number of detected stars that have a Gaia match within the threshold.
- plot(ax=None, transpose=False, **kwargs)[source]#
Plot detected stars and their Gaia matches for visualization.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates new figure.
transpose (bool, optional) – If True, transpose x and y coordinates for plotting. Defaults to False.
**kwargs – Additional keyword arguments passed to scatter plot.
- astra.pointer._read_fits_file(filepath: str | Path)[source]#
Read image data and header from a FITS file.
- Parameters:
filepath (str or Path) – Path to the FITS file.
- Returns:
Tuple[np.ndarray, Header] – Image data and header.
- astra.pointer._extract_plate_scale_and_dateobs(header)[source]#
Extract plate scale and observation date from FITS header.
- Parameters:
header (fits.Header) – FITS header containing metadata.
- Returns:
Tuple[float, datetime] – Plate scale in degrees per pixel and observation date.
- astra.pointer._map_filter_band_to_gaia_tmass(filter_band: str | None) str | None[source]#
Map a given filter band to the corresponding Gaia or 2MASS band.
- Parameters:
filter_band (str, optional) – The filter band used for observation.
- Returns:
str – Corresponding Gaia or 2MASS band, or defaults to G if not found.
- astra.pointer._get_gaia_star_coordinates(ra, dec, image_clean, dateobs, plate_scale, filter_band=None, fov_scale=1.1, limit=24)[source]#
Get Gaia star coordinates for a given field of view.
- Parameters:
ra (float) – Right ascension of field center in degrees.
dec (float) – Declination of field center in degrees.
image_clean (np.ndarray) – The cleaned image data.
dateobs (datetime) – Observation date.
plate_scale (float) – Plate scale in degrees per pixel.
filter_band (str, optional) – Filter band used for observation.
fov_scale (float, optional) – Factor to scale field of view. Defaults to 1.1.
limit (int, optional) – Maximum number of stars to query. Defaults to 24.
- Returns:
np.ndarray – Array of Gaia star coordinates.
- astra.pointer._verify_offset_within_fov(pointing_correction: PointingCorrection, plate_scale: float, image_shape: Tuple[int, int])[source]#
Verify that the pointing offset is within the field of view.
- Parameters:
pointing_correction (PointingCorrection) – The pointing correction object.
plate_scale (float) – Plate scale in degrees per pixel.
image_shape (Tuple[int, int]) – Shape of the image.
- Raises:
Exception – If the offset is larger than the field of view.
- astra.pointer._verify_plate_solve(image_star_mapping: ImageStarMapping, pixel_threshold: int = 20, fraction_of_stars_to_match: float = 0.70, or_min_number_of_stars_to_match: int = 8)[source]#
Verify the plate solve by checking the number of matched stars.
- Parameters:
image_star_mapping (ImageStarMapping) – The image-star mapping object.
pixel_threshold (int, optional) – Pixel distance threshold for a match. Defaults to 20.
fraction_of_stars_to_match (float, optional) – Minimum fraction of stars that must be matched. Defaults to 0.70.
or_min_number_of_stars_to_match (int, optional) – Minimum absolute number of stars that must be matched. Defaults to 8.
- Raises:
Exception – If too few stars are matched.
- astra.pointer.local_gaia_db_query(center: Tuple[float, float] | SkyCoord, fov: float | Quantity, limit: int = 1000, tmass: bool = False, dateobs: datetime | None = None) ndarray[source]#
Query local Gaia database to retrieve RA-DEC coordinates of stars within a given field-of-view.
Retrieves star positions from a local Gaia database within a rectangular region centered on the specified coordinates. Optionally applies proper motion corrections for a specific observation date and sorts by magnitude (Gaia G-band or 2MASS J-band).
- Parameters:
center (tuple or SkyCoord) – The sky coordinates of the center of the FOV. If a tuple is given, it should contain the RA and DEC in degrees.
fov (float or Quantity) – The field-of-view size in degrees. If a float is given, it is assumed to be in degrees. Can be a single value (square FOV) or tuple (RA_fov, Dec_fov).
limit (int, optional) – The maximum number of sources to retrieve from the database. Defaults to 1000.
tmass (bool, optional) – Whether to sort by 2MASS J magnitudes instead of Gaia G magnitudes. Defaults to False.
dateobs (datetime, optional) – The date of the observation. If given, the proper motions of the sources will be applied to update positions from J2015.5 to the observation date. Defaults to None.
- Returns:
np.ndarray –
- An array of shape (n, 2) containing the RA-DEC coordinates
of the retrieved sources in degrees, sorted by magnitude (brightest first).
- astra.pointer.local_db_query(db: str | Path, min_dec: float, max_dec: float, min_ra: float, max_ra: float, crosses_zero: bool = False) DataFrame[source]#
Query astronomical database for objects within coordinate bounds.
Performs federated query across sharded SQLite database tables to retrieve astronomical catalog data within specified declination and right ascension ranges.
- Parameters:
db (Union[str, Path]) – Path to the SQLite database file.
min_dec (float) – Minimum declination in degrees.
max_dec (float) – Maximum declination in degrees.
min_ra (float) – Minimum right ascension in degrees.
max_ra (float) – Maximum right ascension in degrees.
crosses_zero (bool, optional) – Whether the RA range crosses the 0-degree line. Defaults to False.
- Returns:
pd.DataFrame – Combined results from all relevant database shards.