neclib.core.data_type.parameters#

Interface to access NECLIB parameters.

This module defines the NECLIB standard parameter interface. The values can be any Python built-in type, or physical quantity which need units specified.

The parameters would be stored in TOML files, in the following format:

[parameter_kind]
parameter_name = value

[another_parameter_kind]
"parameter_with_units[units]" = value
parameter_without_units = value

The parameters should be grouped by their kind, which is specified by the TOML table name. This kind won’t be kept in the parameter interface, but we require its use to keep the parameter files readable.

Aliases#

NECSTAccessibilityWarning

Warning on limited usage.

NECSTParameterNameError

Error related to limitation on parameter name.

html_repr_of_dict

Return a HTML representation of a dictionary.

class Parameters(**kwargs)[source]#

Bases: object

General format of NECLIB parameters.

This class provides a convenient interface to access the parameters, whose values can be physical quantities; which contain units. The parameters can be stored in TOML files, so this class also provides a its parser.

Examples

If the parameters are stored in a TOML file, use from_file method:

>>> from neclib.parameters import Parameters
>>> params = Parameters.from_file("parameters.toml")
>>> params["distance"]
<Quantity 10. pc>

You can also provide the parameters as keyword arguments, but physical units may not be parsed:

>>> params = Parameters(distance="10 pc")
>>> params["distance"]
"10 pc"

To parse the units, use the following syntax:

>>> params = Parameters(**{"distance[pc]": 10})
>>> params["distance"]
<Quantity 10. pc>

Of course you can provide many parameters at once:

>>> params = Parameters(**{"distance[pc]": 10, "inclination[deg]": 45})
>>> params["distance"]
<Quantity 10. pc>

And you can convert the units on class initialization:

>>> params = Parameters(**{"distance[pc]": "10m")
>>> params["distance"]
<Quantity 3.24077929e-16 pc>

You can also access the parameters as attributes:

>>> params.distance
<Quantity 10. pc>

Notes

The units are parsed using astropy.units and astropy.coordinates.Angle. The units are parsed from the parameter name, so the parameter name must be in the following format: parameter_name[unit].

classmethod from_file(file, /)[source]#

Read parameters from a TOML file.

Parameters:

file (Union[PathLike, str, IO]) – The file path or file object.

attach_aliases(**kwargs)[source]#

Attach aliases to the parameters.

Different names can be used to access the same parameter. This is useful when the parameter name is too long, or when the parameter name has some dialects.

Parameters:

**kwargs (str) – The aliases to attach. The keys are the alias names, and the values are the existing parameter names.

Return type:

None

property parameters: Dict[str, Any]#

Return a copy of the raw parameters.