mirar.processors.astrometry.autoastrometry package

autoastrometry.py - a fast astrometric solver

author: Daniel Perley (dperley@astro.caltech.edu) last significant modifications 2012-04-23

Submodules

mirar.processors.astrometry.autoastrometry.autoastrometry module

autoastrometry.py - a fast astrometric solver

author: Daniel Perley (dperley@astro.caltech.edu) last significant modifications 2012-04-23

4/23: program can actually be overwhelmed by too many good matches (too high maxrad). need to fix this.

Modified by Kishalay De (kde@astro.caltech.edu) for removing dependency on deprecated pyfits and making it compatible with astropy headers and python 3.6 (June 11, 2018)

Modified/dissected by Robert Stein (rdstein@caltech.edu) in 2021/2022 for incorporation into mirar Also converted to python 3.10

mirar.processors.astrometry.autoastrometry.autoastrometry.autoastrometry(filename: str | Path, pixel_scale: float | None = None, pa: float | None = None, inv: bool = False, unc_pa: float | None = None, user_ra_deg: float | None = None, user_dec_deg: float | None = None, max_ellip: float = 0.5, box_size_arcsec: float | None = None, max_rad: float | None = None, tolerance: float = 0.01, catalog: str | None = None, overwrite: bool = True, outfile: str = '', output_dir: str = PosixPath('/home/docs'), temp_file: str | None = None, saturation: float = 10000000000.0, no_rot: bool = False, min_fwhm: float = 1.5, max_fwhm: float = 40, write_crosscheck_files: bool = False)[source]

Parameters

filename: Path of file pixel_scale: The pixel scale in arcsec/pix. Must be within ~1%. By default: ??? pa: The position angle in degrees. Not usually needed. unc_pa: Uncertainty of the position angle (degrees) inv: Reverse(=positive) parity. user_ra_deg: RA in deg user_dec_deg: Dec in deg max_ellip: Maximum elliptical something? box_size_arcsec: Half-width of box for reference catalog query (arcsec) max_rad: Maximum distance to look for star pairs. tolerance: Amount of slack allowed in match determination catalog: Catalog to use (ub2, tmc, sdss, or file) overwrite: Overwrite output files outfile: Output file output_dir: Directory for output file temp_file: Temporary file saturation: Saturation level; do not use stars exceeding. no_rot: Some kind of bool min_fwhm: Minimum fwhm max_fwhm: Maximum fwhm write_crosscheck_files: Bool for whether to write region and other crosscheck files

Returns

mirar.processors.astrometry.autoastrometry.autoastrometry.run_autoastrometry_batch(files: str | Path | list[str | Path], seeing: float | None = None, pixel_scale: float | None = None, pa: float | None = None, uncpa: float | None = None, inv: bool = False, user_ra: float | None = None, user_dec: float | None = None, max_ellip: float = 0.5, box_size: float | None = None, max_rad: float | None = None, tolerance: float = 0.01, catalog: str | None = None, overwrite: bool = False, outfile: str | None = None, output_dir: str = PosixPath('/home/docs'), saturation: float = 10000000000.0, no_rot: bool = False, write_crosscheck_files: bool = False)[source]

Function based on ‘autoastrometry.py’ by Daniel Perley and Kishalay De.

This function runs sextractor and automatically performs astrometry.

Supplying the correct pixel scale (within 1%) and correct parity is critical if the image does not already contain this information in the FITS header. If you have difficulty solving a field correctly, double-check these values. If still having trouble, try opening temp.fits and an archival image of the field (from DSS, etc.) and loading the .reg files in DS9. The problem might be in the telescope pointing/header info (in this case, increase the boxsize) or good matching stars may be thrown away or confused by artifacts (in this case, specify a seeing value). If the PA is known, restricting it can also help (try -upa 0.5); by default all orientations are searched.

Catalog info: Leave the catalog field blank will use SDSS if available and USNO otherwise. The catalog query uses wcstools (tdc-www.harvard.edu/wcstools). However, you can also use your own catalog file on disk if you prefer using -c [img_path] The default format is a text file with the first three columns indicating ra, dec, magnitude. However, you can change the order of the columns by adding, e.g.#:1,2,6 to the first line. In this case, this would indicate that the RA is in the 1st column, dec in the 2nd, and magnitude in the 6th. The mag column can be omitted completely, although if the catalog is not the same depth as the image this may compromise the search results.

Parameters

files: Files to reduce seeing: Approximate seeing in pixels for CR/star/galaxy ID’ing. pixel_scale: The pixel scale in arcsec/pix. Must be within ~1%. By default: ??? pa: The position angle in degrees. Not usually needed. uncpa: Uncertainty of the position angle (degrees) inv: Reverse(=positive) parity. user_ra: RA in deg user_dec: Dec in deg max_ellip: Maximum elliptical something? box_size: Half-width of box for reference catalog query (arcsec) max_rad: Maximum distance to look for star pairs. tolerance: Amount of slack allowed in match determination catalog: Catalog to use (ub2, tmc, sdss, or file) overwrite: Overwrite output files outfile: Output file output_dir: Output directory saturation: Saturation level; do not use stars exceeding. no_rot: Some kind of bool involving rotation write_crosscheck_files: Bool for whether to write region and other crosscheck files

Returns

mirar.processors.astrometry.autoastrometry.autoastrometry.run_autoastrometry_single(img_path: str | Path, seeing: float | None = None, pixel_scale: float | None = None, pa: float | None = None, uncpa: float | None = None, inv: bool = False, user_ra: float | None = None, user_dec: float | None = None, max_ellip: float = 0.5, box_size: float | None = None, max_rad: float | None = None, tolerance: float = 0.01, catalog: str | None = None, overwrite: bool = False, outfile: str | None = None, output_dir: str = PosixPath('/home/docs'), saturation: float = 10000000000.0, no_rot: bool = False, write_crosscheck_files: bool = False)[source]

Function based on ‘autoastrometry.py’ by Daniel Perley and Kishalay De.

This function runs sextractor and automatically performs astrometry.

Supplying the correct pixel scale (within 1%) and correct parity is critical if the image does not already contain this information in the FITS header. If you have difficulty solving a field correctly, double-check these values. If still having trouble, try opening temp.fits and an archival image of the field (from DSS, etc.) and loading the .reg files in DS9. The problem might be in the telescope pointing/header info (in this case, increase the boxsize) or good matching stars may be thrown away or confused by artifacts (in this case, specify a seeing value). If the PA is known, restricting it can also help (try -upa 0.5); by default all orientations are searched.

Catalog info: Leave the catalog field blank will use SDSS if available and USNO otherwise. The catalog query uses wcstools (tdc-www.harvard.edu/wcstools). However, you can also use your own catalog file on disk if you prefer using -c [img_path] The default format is a text file with the first three columns indicating ra, dec, magnitude. However, you can change the order of the columns by adding, e.g.#:1,2,6 to the first line. In this case, this would indicate that the RA is in the 1st column, dec in the 2nd, and magnitude in the 6th. The mag column can be omitted completely, although if the catalog is not the same depth as the image this may compromise the search results.

Parameters

img_path: File to reduce seeing: Approximate seeing in pixels for CR/star/galaxy ID’ing. pixel_scale: The pixel scale in arcsec/pix. Must be within ~1%. By default: ??? pa: The position angle in degrees. Not usually needed. uncpa: Uncertainty of the position angle (degrees) inv: Reverse(=positive) parity. user_ra: RA in deg user_dec: Dec in deg max_ellip: Maximum elliptical something? box_size: Half-width of box for reference catalog query (arcsec) max_rad: Maximum distance to look for star pairs. tolerance: Amount of slack allowed in match determination catalog: Catalog to use (ub2, tmc, sdss, or file) overwrite: Overwrite output files outfile: Output file output_dir: Output directory saturation: Saturation level; do not use stars exceeding. no_rot: Some kind of bool involving rotation write_crosscheck_files: Bool for whether to write region and other crosscheck files

Returns

mirar.processors.astrometry.autoastrometry.autoastrometry_processor module

Module containing a processor to run automastrometry

class mirar.processors.astrometry.autoastrometry.autoastrometry_processor.AutoAstrometry(temp_output_sub_dir: str = 'autoastrometry', write_crosscheck_files: bool = False, catalog: str | None = None, pixel_scale: float | None = None, inv: bool = False, pa: float | None = None)[source]

Bases: BaseImageProcessor

Processor to run automastrometry

base_key = 'autoastrometry'

mirar.processors.astrometry.autoastrometry.crossmatch module

Component module for autoastrometry, dealing with crossmatching image sources with reference sources

mirar.processors.astrometry.autoastrometry.crossmatch.crosscheck_source_lists(img_src_list: list[SextractorSource], n_img: int, img_density: float, ref_src_list: list[BaseSource], n_ref: int, ref_density: float, box_size_arcsec: float, area_sq_min: float) tuple[list[SextractorSource], int, float, list[BaseSource], int, float][source]

Compares detected sources in image and reference, and trims so they are of comparable density

Parameters:
  • img_src_list – list of image sources

  • n_img – number of image sources

  • img_density – img source density

  • ref_src_list – list of reference images

  • n_ref – number of reference sources

  • ref_density – ref source density

  • box_size_arcsec – radius of search box

  • area_sq_min – area of image

Returns:

trimmed list of sources, number, density, trimmed ref sources, number & density

mirar.processors.astrometry.autoastrometry.crossmatch.distance_match(img_src_list: list[SextractorSource], ref_src_list: list[BaseSource], base_output_path: str, max_rad: float = 180.0, min_rad: float = 10.0, tolerance: float = 0.01, req_match: int = 3, pa_tolerance: float = 1.2, unc_pa: float | None = None, write_crosscheck_files: bool = False) tuple[list[int], list[int], list[float]][source]

Cross-match sources in image with reference sources

Parameters:
  • img_src_list – sources in image

  • ref_src_list – reference sources

  • base_output_path – output path to save crossmatch

  • max_rad – max radius (degrees)

  • min_rad – min radius (degrees)

  • tolerance

  • req_match – minimum number of matches needed

  • pa_tolerance – pa tolerance needed

  • unc_pa – uncertainty in pa

  • write_crosscheck_files – boolean whether to write crosscheck files

Returns:

image_matches, ref_matches, mpa

mirar.processors.astrometry.autoastrometry.detect module

Component of autoastrometry which detects sources in the science image

mirar.processors.astrometry.autoastrometry.detect.get_img_src_list(img_path: str, base_output_path: str, nx_pix: int, ny_pix: int, border: int = 3, corner: int = 12, min_fwhm: float = 1.5, max_fwhm: float = 40, max_ellip: float = 0.5, saturation: float = 10000000000.0, config_path: str = '/home/docs/checkouts/readthedocs.org/user_builds/mirar-anu/checkouts/latest/mirar/processors/astromatic/config/sex.config', output_catalog: str | Path | None = None, write_crosscheck_files: bool = False) list[SextractorSource][source]

Run sextractor on an image, and then extract all the sources

Parameters:
  • img_path – image to evaluate

  • base_output_path

  • nx_pix – number of x pixels

  • ny_pix – number of y pixels

  • border – number of border pixels

  • corner – number of corner pixels

  • min_fwhm – min FWHM to allow

  • max_fwhm – max FWHM to allow

  • max_ellip – max ellipse

  • saturation – saturation level

  • config_path – sextractor config path

  • output_catalog – output path

  • write_crosscheck_files – boolean to write additional crosscheck files

Returns:

list of sextractor sources

mirar.processors.astrometry.autoastrometry.errors module

Module containing custom errors for autoastrometry

exception mirar.processors.astrometry.autoastrometry.errors.AstrometryCrossmatchError[source]

Bases: AstrometryError

Error related to crossmatching astrometry source/reference catalogue

exception mirar.processors.astrometry.autoastrometry.errors.AstrometryError[source]

Bases: ProcessorError

Parent Error relating to autoastrometry

exception mirar.processors.astrometry.autoastrometry.errors.AstrometryReferenceError[source]

Bases: AstrometryError

Error related to astrometry reference catalogue

exception mirar.processors.astrometry.autoastrometry.errors.AstrometrySourceError[source]

Bases: AstrometryError

Error with astrometry source catalogue

exception mirar.processors.astrometry.autoastrometry.errors.AstrometryURLError[source]

Bases: AstrometryError

Error related to astrometry URL query

mirar.processors.astrometry.autoastrometry.io module

Module component of autoastrometry, handling I/O

mirar.processors.astrometry.autoastrometry.io.export_src_lists(img_src_list: list[SextractorSource], ref_src_list: list[BaseSource], base_output_path: str)[source]

Export both image and reference source lists to txt/region files

Parameters:
  • img_src_list – Image sources

  • ref_src_list – Reference sources

  • base_output_path – base output path

Returns:

None

mirar.processors.astrometry.autoastrometry.io.parse_header(file_path: str | Path, temp_path: str | Path, pixel_scale: float | None = None, pa: float | None = None, inv: bool = False, user_ra_deg: float | None = None, user_dec_deg: float | None = None) tuple[int, int, float, float, float, float, float, float, float, float][source]

Extract relevant info for astrometry from header of file

Parameters:
  • file_path – File to parse

  • temp_path – Temp path to write updated version to

  • pixel_scale – Pixel scale

  • pa – PA

  • inv

  • user_ra_deg

  • user_dec_deg

Returns:

nxpix, nypix, cd11, cd12, cd21, cd22, crpix1, crpix2, cra, cdec

mirar.processors.astrometry.autoastrometry.io.write_region_file(file_path: str, src_list: list[BaseSource], color: str = 'green', system: str | None = None)[source]

Write a region file

Parameters:
  • file_path – Output path

  • src_list – List of sources

  • color – Colour to use

  • system – system to use (default wcs)

Returns:

mirar.processors.astrometry.autoastrometry.io.write_text_file(file_path: str, src_list: list[BaseSource])[source]

Write a text file with a list of sources

Parameters:
  • file_path – Output file

  • src_list – List of sources

Returns:

None

mirar.processors.astrometry.autoastrometry.reference module

Module for downloading a reference image to perform calibration, and extracting sources from that reference image

mirar.processors.astrometry.autoastrometry.reference.get_catalog(catalog: str, ra: float, dec: float, box_size_arcsec: float, min_mag: float = 8.0, max_mag: float | None = None, max_pm: float = 60.0) list[BaseSource][source]

Get a reference catalog around ra/dec, with radius

Parameters:
  • catalog – Catalog to use (‘ub2’/’sdss’/’tmc’)

  • ra – ra

  • dec – declination

  • box_size_arcsec – box to use

  • min_mag – min mag of sources

  • max_mag – max mag of sources

  • max_pm – max pm

Returns:

list of reference sources

mirar.processors.astrometry.autoastrometry.reference.get_catalog_astroquery(catalog: str, ra: float, dec: float, box_size_arcsec: float, min_mag: float = 8.0, max_mag: float | None = None, max_pm: float = 60.0) list[BaseSource][source]

Get a reference catalogue using astroquery, around ra/dec

Parameters:
  • catalog – Catalog to use

  • ra – ra

  • dec – dec

  • box_size_arcsec – radius of box

  • min_mag – min mag of stars

  • max_mag – max mag of stars

  • max_pm – max pm

Returns:

list of reference stars

mirar.processors.astrometry.autoastrometry.reference.get_ref_sources_from_catalog(catalog: str, center_ra: float, center_dec: float, box_size_arcsec: float) tuple[list[BaseSource], int, float][source]

Get reference sources from a catalogue

Parameters:
  • catalog – catalog to use

  • center_ra – ra

  • center_dec – dec

  • box_size_arcsec – radius

Returns:

ref catalog, n_cat, cat_density

mirar.processors.astrometry.autoastrometry.reference.get_ref_sources_from_catalog_astroquery(catalog: str, center_ra: float, center_dec: float, box_size_arcsec: float) tuple[list[BaseSource], int, float][source]

Get reference sources from an astropquery catalogue

Parameters:
  • catalog – catalog to use

  • center_ra – ra

  • center_dec – dec

  • box_size_arcsec – radius

Returns:

ref catalog, n_cat, cat_density

mirar.processors.astrometry.autoastrometry.sources module

Module containing base Source classes used by autoastrometry

class mirar.processors.astrometry.autoastrometry.sources.BaseSource(ra_deg: float, dec_deg: float, in_mag: float)[source]

Bases: object

A standard source object

rotate(dpa_deg: float, ra0: float, dec0: float)[source]

Function to rotate a source by dpa around ra0/dec0?

Parameters:
  • dpa_deg – delta-pa (deg)

  • ra0 – ra

  • dec0 – dec

Returns:

None

class mirar.processors.astrometry.autoastrometry.sources.SextractorSource(line: str)[source]

Bases: BaseSource

Source from sextractor

mirar.processors.astrometry.autoastrometry.sources.compare_mag(source: SextractorSource) float[source]

# Compare objects using magnitude. “useful for sorting; Altered by KD for compatibility with python 3

Parameters:

source – Source to compare

Returns:

magnitude of source

mirar.processors.astrometry.autoastrometry.sources.distance(obj1: BaseSource, obj2: BaseSource) float[source]

# Great circle distance between two points.

Parameters:
  • obj1 – object 1

  • obj2 – object 2

Returns:

great circle distance

mirar.processors.astrometry.autoastrometry.sources.pixel_distance(obj1: SextractorSource, obj2: SextractorSource) float[source]

Calculate pixel distance between obj1 and obj2

Parameters:
  • obj1 – Object 1

  • obj2 – Object 2

Returns:

pixel distance

mirar.processors.astrometry.autoastrometry.sources.position_angle(obj1: BaseSource, obj2: BaseSource) float[source]

Calculate the (spherical) position angle between two objects.

Parameters:
  • obj1 – Object 1

  • obj2 – Object 2

Returns:

angle (degrees)

mirar.processors.astrometry.autoastrometry.sources.quickdistance(obj1: BaseSource, obj2: BaseSource, cosdec: float) float[source]

Cartestian-approximation distance between two objects (Non-great-circle distance is much faster, but beware poles…)

Parameters:
  • obj1 – object 1

  • obj2 – object 2

  • cosdec – cos(declination)

Returns:

approximate distance

mirar.processors.astrometry.autoastrometry.utils module

Module containing helper functions for autoastrometry

mirar.processors.astrometry.autoastrometry.utils.dec_str_2_deg(dec_str: str) float[source]

Convert dec string to degrees

Parameters:

dec_str – hexadecismal ra

Returns:

dec (degrees)

mirar.processors.astrometry.autoastrometry.utils.median(float_list: list[float]) float[source]

Calculate median value of input list

Parameters:

float_list – list of floats

Returns:

median

mirar.processors.astrometry.autoastrometry.utils.mode(float_list: list[float]) float[source]

Calculate mode value of input list

Parameters:

float_list – list of floats

Returns:

mode

mirar.processors.astrometry.autoastrometry.utils.ra_str_2_deg(ra_str: str) float[source]

Convert ra string to degrees

Parameters:

ra_str – hexadecismal ra

Returns:

ra (degrees)

mirar.processors.astrometry.autoastrometry.utils.stdev(float_list: list[float]) float[source]

Calculate standard deviation value of input list

Parameters:

float_list – list of floats

Returns:

std deviation

mirar.processors.astrometry.autoastrometry.utils.unique(input_list: list) list[source]

Returns unique values in a list

Parameters:

input_list – list to check

Returns:

unique values