Allow units to be included in the value field
This commit is contained in:
parent
c3a32ed7af
commit
dac889a1fd
@ -11,9 +11,14 @@ Each parameter of the configuration is defined by a XML-tag which is indicated b
|
|||||||
|
|
||||||
A parameter can contain multiple attributes which are defined as key-value-pairs and some of them may be optional.
|
A parameter can contain multiple attributes which are defined as key-value-pairs and some of them may be optional.
|
||||||
All attribute values must be quoted as in the example below. The required types shown in the documentation refer to the unquoted value.
|
All attribute values must be quoted as in the example below. The required types shown in the documentation refer to the unquoted value.
|
||||||
Most numeric attributes require a unit which has to be defined as a second attribute with the suffix *_unit* which is also shown in the example below.
|
Most numeric attributes require a unit which can be either included in the value or defined as a second attribute with the suffix *_unit*.
|
||||||
|
The documentation uses the latter case for clarity. Both cases are shown as examples below.
|
||||||
All astropy units defined `here <https://docs.astropy.org/en/stable/units/>`_ can be used.
|
All astropy units defined `here <https://docs.astropy.org/en/stable/units/>`_ can be used.
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<tag_name val="10 s"/>
|
||||||
|
|
||||||
.. code-block:: xml
|
.. code-block:: xml
|
||||||
|
|
||||||
<tag_name val="10" val_unit="s"/>
|
<tag_name val="10" val_unit="s"/>
|
||||||
|
@ -79,8 +79,14 @@ class Entry(object):
|
|||||||
try:
|
try:
|
||||||
self.__setattr__(name, float(attr) * unit)
|
self.__setattr__(name, float(attr) * unit)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return "Expected parameter '" + name + "' with unit '" + unit.to_string() + \
|
try:
|
||||||
"' but got no unit and cannot convert '" + attr + "' to a numeric value."
|
self.__setattr__(name, u.Quantity(attr))
|
||||||
|
mes = self.check_quantity(name, unit, use_default)
|
||||||
|
if mes is not None:
|
||||||
|
return mes
|
||||||
|
except [ValueError, TypeError]:
|
||||||
|
return "Expected parameter '" + name + "' with unit '" + unit.to_string() + \
|
||||||
|
"' but got no unit and cannot convert '" + attr + "' to a numeric value."
|
||||||
else:
|
else:
|
||||||
return "Expected parameter '" + name + "' with unit '" + unit.to_string() + "' but got no unit."
|
return "Expected parameter '" + name + "' with unit '" + unit.to_string() + "' but got no unit."
|
||||||
elif not attr.unit.is_equivalent(unit):
|
elif not attr.unit.is_equivalent(unit):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user