unit_conversion.py

Functions for checking and sanitizing units that do not follow the FITS specification. This uses functions from astropy.unit to parse and handle units.

exception fits2hdf.unit_conversion.UnitWarning

Bases: astropy.io.fits.verify.VerifyWarning

Unit warning class

Used when units do not parse or parse oddly

fits2hdf.unit_conversion.fits_to_units(unit_str)

Do a lookup from a astropy unit and return a fits unit string

unit_str (str): a FITS unit string returns an astropy.units.Unit(), or UnrecognizedUnit()

This will attempt to correct some common mistakes in the FITS format.

fits2hdf.unit_conversion.units_to_fits(unit)

Convert an astropy unit to a FITS format string.

uses the to_string() method built-in to astropy Unit()

The output will be the format defined in the FITS standard: http://fits.gsfc.nasa.gov/fits_standard.html

A roundtrip from fits_to_units -> units_to_fits may not return the original string, as people often don’t follow the standard.