Module: fits_standardizer#
FitsStandardizer standardize local file-system FITS files.
Prefer to use specific FITS standardizers that specify the type of the FITS file, such as SingleExtensionFits or MultiExtensionFits, whenever possible.
FitsStandardizer is primarily useful to handle shared functionality and simplify further processing, so there is not much to gain by using it directly.
- class kbmod.standardizers.fits_standardizers.fits_standardizer.FitsStandardizer(location=None, hdulist=None, config=None, **kwargs)[source]#
Supports processing of a single FITS file.
This is an Standardizer stub and can not be used directly. Its intended use is to facilitate implementing of new standardizers. If you are implementing a FitsStandardizer, consider inheriting from SingleExtensionFits or MultiExtensionFits.
Standardizers inheriting from FitsStandardizer` require that FITS file is readable by AstroPy.
- Parameters:
- locationstr or None, optional
Location of the file (if any) that is standardized. Required if
hdulist
is not provided.- hdulistastropy.io.fits.HDUList or None, optional
HDUList to standardize. Required if
location
is not provided. If provided, andlocation
is not given, defaults to:memory:
.- configStandardizerConfig or dict, optional
Configuration key-values used when standardizing the file. When not provided, uses configClass to determine the defaults configuration class.
- Attributes:
- hdulist~astropy.io.fits.HDUList
All HDUs found in the FITS file
- primary~astropy.io.fits.PrimaryHDU
The primary HDU.
- processablelist
Any additional extensions marked by the standardizer for further processing. Does not include the primary HDU if it doesn’t contain any image data. Contains at least 1 entry.
Methods
canStandardize
(tgt)Returns
True
when the standardizer knows how to process the given upload (file) type.close
([output_verify, verbose, closed])Close the associated FITS file and memmap object, if any.
get
(tgt[, force, config])Get the standardizer class that can handle given file.
resolveFromPath
(tgt)Successfully resolves FITS files on a local file system, that are readable by AstroPy.
resolveTarget
(tgt)Returns
True
if the target is a FITS file on a local filesystem, that can be read by AstroPy FITS module, or an ~astropy.io.fits.HDUList.standardize
()Invokes standardize metadata, image, variance, mask and PSF and returns the results as a dictionary.
Calculate the standardized bounding box, the world coordinates at image corner and image center.
standardizeMaskImage
()Standardizes the mask data as an simple 0 (not masked) and 1 (masked) bitmap.
Standardizes required and optional metadata from the given data.
Returns PSF for each extension marked as processable.
Standardizes the science image data.
standardizeVarianceImage
()Standardizes the variance data.
Creates an WCS for every processable science image.
Returns a list of ~kbmod.search.layered_image objects for each entry marked as processable.
translateHeader
(*args, **kwargs)Maps the header keywords to the required and optional metadata.
configClass
- property bbox#
A list of bounding boxes or None for each entry marked as processable.
Key
Description
center_ra
On-sky (ICRS) right ascension coordinate, expressed in decimal degrees, of the center of an rectangular bounding box.
center_dec
On-sky (ICRS) declination coordinate, expressed in decimal degrees, of the center of an rectangular bounding box.
corner_ra
On-sky (ICRS) right ascension coordinate, expressed in decimal degrees, of an corner of a rectangular bounding box.
corner_dec
On-sky (ICRS) declination coordinate, expressed in decimal degrees, of an corner of a rectangular bounding box.
Often, when WCS can not be constructed, the BBOX can not be constructed. Then None is expected to be returned in it’s place.
- close(output_verify='exception', verbose=False, closed=True)[source]#
Close the associated FITS file and memmap object, if any.
See astropy.io.fits.HDUList.close.
- Parameters:
- output_verifystr
Output verification option. Must be one of
"fix"
,"silentfix"
,"ignore"
,"warn"
, or"exception"
. May also be any combination of"fix"
or"silentfix"
with"+ignore"
,"+warn"
, or"+exception"
(e.g."fix+warn"
). See Astropy Verification Options for more info.- verbosebool
When True, print out verbose messages.
- closedbool
When True, close the underlying file object.
- configClass#
alias of
FitsStandardizerConfig
- classmethod resolveFromPath(tgt)[source]#
Successfully resolves FITS files on a local file system, that are readable by AstroPy.
- Parameters:
- tgtstr
Path to FITS file.
- Returns:
- canStandardizebool
True if target is a FITS file readable by AstroPy. False otherwise.
- resourcesdict
Empty dict when
canStandardize
is False, otherwise the “hdulist”` key contains the constructed ~fits.HDUList object.
- Raises:
- FileNotFoundError - when file doesn’t exist
- classmethod resolveTarget(tgt)[source]#
Returns
True
if the target is a FITS file on a local filesystem, that can be read by AstroPy FITS module, or an ~astropy.io.fits.HDUList.- Parameters:
- tgtstr
Path to FITS file.
- Returns:
- canStandardizebool
True if target is a FITS file readable by AstroPy. False otherwise.
- resourcesdict, optional
An empty dictionary when
canStandardize
is False. A dict containing ~fits.HDUList whencanStandardize
is True.
- Raises:
- FileNotFoundError - when target is path to file that doesn’t exist
- TypeError - when target is not HDUList or a filepath.
- standardizeBBox()[source]#
Calculate the standardized bounding box, the world coordinates at image corner and image center.
- Returns:
- standardizedBBoxdict
Calculated coordinate values, a dict with,
wcs_center_[ra, dec]
andwcs_corner_[ra, dec]
keys.
Notes
Center can be assumed to be at the (dimX/2, dimY/2) pixel coordinates, rounded down. Corner is taken to be the (0,0)-th pixel.
- standardizeMetadata()[source]#
Standardizes required and optional metadata from the given data.
The standardized metadata is expected to be a dict containing the following keys and values:
Key
Description
location
Path, URL or URI to the data.
mjd
Decimal MJD timestamp of the start of the observation
ra
Right Ascension in ICRS coordinate system of the extracted, or calculated on-sky poisiton of the central pixel, pointing data.
dec
Declination in ICRS coordinate system, expressed in decimal degrees, of the extracted, or calculated, on-sky poisiton of the data.
wcs
Result of ~standardizeWCS, a list of ~astropy.wcs.WCS objects or a list of `None`s if they can not be constructed.
bbox
Result of standardizeBBox, a list of standardized bounding boxes or a list of `None`s if they can not be calculated.
- Returns:
- metadatadict
Standardized metadata.
Notes
If a target being standardized contains only 1 image that can be standardized and processed by KBMOD, the values in the dictionary can be strings, integers, floats, and other such single-values non-iterable types, or an iterable type containing only 1 element. When the target being standardized contains multiple images/extensions that are processable by KBMOD the single-valued dict entries will be considered as shared by all the processable images/extension/units of the target. The iterable values in the dictionary must match the number and order of the units marked as processable.
- standardizePSF()[source]#
Returns PSF for each extension marked as processable.
- Returns:
- psfslist[numpy.ndarray]
List of PSF kernels as numpy matrices.
- standardizeScienceImage()[source]#
Standardizes the science image data.
For FITS files, this is usually a trivial no-op operation that returns the data attribute of the correct HDU. For different data sources this is a type casting, or a download operation.
- Returns:
- imagelist[~np.array]
Science images.
- standardizeWCS()[source]#
Creates an WCS for every processable science image.
- Returns:
- wcslist
List of ~astropy.wcs.WCS objects.
- toLayeredImage()[source]#
Returns a list of ~kbmod.search.layered_image objects for each entry marked as processable.
- Returns:
- layeredImagelist
Layered image objects.
- abstract translateHeader(*args, **kwargs)[source]#
Maps the header keywords to the required and optional metadata.
Is required to return a dictionary containing at least the following keys and values:
Key
Description
mjd_mid
Decimal MJD timestamp of the start of the observation (in UTC)
ra
Right Ascension in ICRS coordinate system of the extracted, or calculated on-sky poisiton of the central pixel, pointing data.
dec
Declination in ICRS coordinate system, expressed in decimal degrees, of the extracted, or calculated, on-sky poisiton of the data.
- Returns:
- metadatadict
Required and optional metadata.
- valid_extensions = ['.fit', '.fits', '.fits.fz']#
File extensions this processor can handle.
- property wcs#
A list of WCS’s or None for each entry marked as processable.
Expected to be an WCS object, but when it is not possible to construct one None will be returned in its place.
- class kbmod.standardizers.fits_standardizers.fits_standardizer.FitsStandardizerConfig(config=None, **kwargs)[source]#
Methods
items
()A set-like object providing a view on config's items.
keys
()A set-like object providing a view on config's keys.
toDict
()Return this config as a dict.
update
([conf])Update this config from dict/other config/iterable.
values
()A set-like object providing a view on config's values.
- greedy_export = False#
When True, the FITS standardizer will not remove the data attribute from the HDUList objects after standardization. This can be useful when the data is needed for further processing, but can lead to increased memory.
- psf_std = 1#
Standard deviation of the Point Spread Function. When a
float
, uniform STD applied to all processable items in the standardizer. When a list, must be of the equal length as number of processable items, an index-matched STD per processable item.