示例#1
0
文件: unit.py 项目: Guillemdb/asdf
    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))
示例#2
0
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()
示例#3
0
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()
示例#4
0
 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")
示例#5
0
文件: unit.py 项目: Cadair/astropy
 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))