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
splitted = element.get(name).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
# -----------------------------------------------------------------
## This function sets the value of a certain parameter of the specified tree element from an Astropy quantity.
评论列表
文章目录