mt_metadata.common.units ======================== .. py:module:: mt_metadata.common.units .. autoapi-nested-parse:: This is a placeholder module. See github issue #30 In the mt_metadata packaage, the standard is that units are described by all lower case strings. The dictionaries UNITS is keyed by these lower case strings. Attributes ---------- .. autoapisummary:: mt_metadata.common.units.prefixes mt_metadata.common.units.base_units mt_metadata.common.units.derived_units mt_metadata.common.units.all_units mt_metadata.common.units.unit_name mt_metadata.common.units.UNITS_DF Classes ------- .. autoapisummary:: mt_metadata.common.units.Unit Functions --------- .. autoapisummary:: mt_metadata.common.units.find_separator mt_metadata.common.units.parse_unit_string mt_metadata.common.units.get_unit_object mt_metadata.common.units.get_unit_from_df Module Contents --------------- .. py:data:: prefixes .. py:data:: base_units .. py:data:: derived_units .. py:data:: all_units .. py:data:: unit_name :value: '' .. py:data:: UNITS_DF .. py:class:: Unit(/, **data) Bases: :py:obj:`pydantic.BaseModel` !!! abstract "Usage Documentation" [Models](../concepts/models.md) A base class for creating Pydantic models. .. attribute:: __class_vars__ The names of the class variables defined on the model. .. attribute:: __private_attributes__ Metadata about the private attributes of the model. .. attribute:: __signature__ The synthesized `__init__` [`Signature`][inspect.Signature] of the model. .. attribute:: __pydantic_complete__ Whether model building is completed, or if there are still undefined fields. .. attribute:: __pydantic_core_schema__ The core schema of the model. .. attribute:: __pydantic_custom_init__ Whether the model has a custom `__init__` function. .. attribute:: __pydantic_decorators__ Metadata containing the decorators defined on the model. This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1. .. attribute:: __pydantic_generic_metadata__ Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these. .. attribute:: __pydantic_parent_namespace__ Parent namespace of the model, used for automatic rebuilding of models. .. attribute:: __pydantic_post_init__ The name of the post-init method for the model, if defined. .. attribute:: __pydantic_root_model__ Whether the model is a [`RootModel`][pydantic.root_model.RootModel]. .. attribute:: __pydantic_serializer__ The `pydantic-core` `SchemaSerializer` used to dump instances of the model. .. attribute:: __pydantic_validator__ The `pydantic-core` `SchemaValidator` used to validate instances of the model. .. attribute:: __pydantic_fields__ A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects. .. attribute:: __pydantic_computed_fields__ A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects. .. attribute:: __pydantic_extra__ A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra] is set to `'allow'`. .. attribute:: __pydantic_fields_set__ The names of fields explicitly set during instantiation. .. attribute:: __pydantic_private__ Values of private attributes set on the model instance. .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:attribute:: name :type: Annotated[str, Field(default=None, description='Common name of the unit.')] .. py:attribute:: description :type: Annotated[str, Field(default=None, description='Description of the unit.')] .. py:attribute:: symbol :type: Annotated[str, Field(default=None, description='Symbol like representation of the unit', validation_alias=AliasChoices('symbol', 'abbrviation'))] .. py:attribute:: plot_label :type: Annotated[str, Field(default=None, description='Plot label of the unit.')] .. py:method:: combine(other, separator='/') Combine two unit objects into a single string representation. :param other: The other unit object to combine with. :type other: Unit :param separator: The separator to use between the two units, by default "/" :type separator: str, optional :returns: Combined string representation of the two units. :rtype: str .. py:method:: to_dict() .. py:method:: from_dict(value) .. py:function:: find_separator(unit_string) Find the first separator in a unit string. :param unit_string: The unit string to search for separators. :type unit_string: str :returns: The first separator found in the unit string. :rtype: str .. py:function:: parse_unit_string(unit_string) Parse a unit string into a list of units and separators, including nested units and brackets. :param unit_string: The unit string to parse (e.g., "mV nT/[km ohm]"). :type unit_string: str :returns: A list of dictionaries, each containing a unit name and its separator. Example: [{"name": "mV", "sep": " "}, {"name": "nT", "sep": "/"}, {"name": "[", "sep": None}, {"name": "km", "sep": " "}, {"name": "ohm", "sep": None}, {"name": "]", "sep": None}] :rtype: list[dict] .. py:function:: get_unit_object(unit, allow_none=True) From the unit name or symbol return a Unit object. This function will search the unit name, symbol and plot_label for a match. If the unit is not found, a KeyError will be raised. If allow_none is True, None will be returned if the unit is not found. :param unit: name or symbol of the unit to search for. :type unit: str :param allow_none: If the unit isn't found return an empty unit of unknons, by default True :type allow_none: bool, optional :returns: Unit object with the unit name, symbol, description and plot_label. :rtype: Unit :raises KeyError: If the unit is not found in the DataFrame. .. py:function:: get_unit_from_df(value, allow_none=True) Retrieve a row from the UNITS_DF DataFrame based on the unit's name or symbol. :param value: The name or symbol of the unit to search for. :type value: str :returns: A row from the UNITS_DF DataFrame corresponding to the given name or symbol. :rtype: pd.Series :raises KeyError: If the unit is not found in the DataFrame.