def to_tree(cls, node, ctx): from astropy.units import Unit, UnitBase if isinstance(node, six.string_types): node = Unit(node, format='vounit', parse_strict='warn') if isinstance(node, UnitBase): return node.to_string(format='vounit') raise TypeError("'{0}' is not a valid unit".format(node))
def units_to_fits(unit): """ Convert an astropy unit to a FITS format string. uses the to_string() method built-in to astropy Unit() Notes ----- 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. """ if unit is None: unit = Unit('') return unit.to_string("fits").upper()
def to_tree(cls, node, ctx): if isinstance(node, six.string_types): node = Unit(node, format='vounit', parse_strict='warn') if isinstance(node, UnitBase): return node.to_string(format='vounit') raise TypeError(f"'{node}' is not a valid unit")
def to_tree(cls, node, ctx): if isinstance(node, six.string_types): node = Unit(node, format='vounit', parse_strict='warn') if isinstance(node, UnitBase): return node.to_string(format='vounit') raise TypeError("'{0}' is not a valid unit".format(node))