def get_quantity(self, element, name, default_unit=None):
# Import Astropy here to avoid import errors for this module for users without an Astropy installation
from astropy.units import Unit
prop = element.get(name)
if prop.startswith("[") and prop.endswith("]"): prop = prop[1:-1].split(":")[1]
splitted = prop.split()
value = float(splitted[0])
try: unit = splitted[1]
except IndexError: unit = default_unit
# Create a quantity object
if unit is not None: value = value * Unit(unit)
return value
# -----------------------------------------------------------------
# Overwrite the default implementation in SkiFile to incorporate labeled properties
评论列表
文章目录