From a083583be50afe658523843dbfb380af9184ab45 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 10 Feb 2025 00:03:23 +0000 Subject: [PATCH 01/20] init --- pint/delegates/__init__.py | 3 +- pint/delegates/toml_parser/__init__.py | 16 ++ pint/delegates/toml_parser/common.py | 62 +++++ pint/delegates/toml_parser/plain.py | 302 ++++++++++++++++++++++ pint/delegates/toml_parser/toml_parser.py | 152 +++++++++++ pint/facets/context/registry.py | 3 + pint/facets/group/registry.py | 10 +- pint/facets/plain/registry.py | 14 +- pint/facets/system/registry.py | 3 + 9 files changed, 557 insertions(+), 8 deletions(-) create mode 100644 pint/delegates/toml_parser/__init__.py create mode 100644 pint/delegates/toml_parser/common.py create mode 100644 pint/delegates/toml_parser/plain.py create mode 100644 pint/delegates/toml_parser/toml_parser.py diff --git a/pint/delegates/__init__.py b/pint/delegates/__init__.py index dc4699cf9..4d80f05ff 100644 --- a/pint/delegates/__init__.py +++ b/pint/delegates/__init__.py @@ -11,6 +11,7 @@ from . import txt_defparser from .base_defparser import ParserConfig, build_disk_cache_class +from .toml_parser import toml_parser from .formatter import Formatter -__all__ = ["txt_defparser", "ParserConfig", "build_disk_cache_class", "Formatter"] +__all__ = ["txt_defparser", "ParserConfig", "build_disk_cache_class", "Formatter", "toml_parser"] diff --git a/pint/delegates/toml_parser/__init__.py b/pint/delegates/toml_parser/__init__.py new file mode 100644 index 000000000..b81750d96 --- /dev/null +++ b/pint/delegates/toml_parser/__init__.py @@ -0,0 +1,16 @@ +""" + pint.delegates.toml_parser + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Parser for the toml Pint Definition file. + + :copyright: 2025 by Pint Authors, see AUTHORS for more details. + :license: BSD, see LICENSE for more details. +""" +from __future__ import annotations + +from .toml_parser import TomlParser + +__all__ = [ + "TomlParser", +] diff --git a/pint/delegates/toml_parser/common.py b/pint/delegates/toml_parser/common.py new file mode 100644 index 000000000..def901d88 --- /dev/null +++ b/pint/delegates/toml_parser/common.py @@ -0,0 +1,62 @@ +""" + pint.delegates.txt_defparser.common + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Definitions for parsing an Import Statement + + Also DefinitionSyntaxError + + :copyright: 2022 by Pint Authors, see AUTHORS for more details. + :license: BSD, see LICENSE for more details. +""" + +from __future__ import annotations + +from dataclasses import dataclass + +import flexparser as fp + +from ... import errors +from ..base_defparser import ParserConfig + + +class DefinitionSyntaxError(errors.DefinitionSyntaxError, fp.ParsingError): + """A syntax error was found in a definition. Combines: + + DefinitionSyntaxError: which provides a message placeholder. + fp.ParsingError: which provides raw text, and start and end column and row + + and an extra location attribute in which the filename or reseource is stored. + """ + + msg: str + + def __init__(self, msg: str, location: str = ""): + self.msg = msg + self.location = location + + def __str__(self) -> str: + msg = ( + self.msg + "\n " + (self.format_position or "") + " " + (self.raw or "") + ) + if self.location: + msg += "\n " + self.location + return msg + + def set_location(self, value: str) -> None: + super().__setattr__("location", value) + + +@dataclass(frozen=True) +class ImportDefinition(fp.IncludeStatement[ParserConfig]): + value: str + + @property + def target(self) -> str: + return self.value + + @classmethod + def from_string(cls, s: str) -> fp.NullableParsedResult[ImportDefinition]: + if s.startswith("@import"): + return ImportDefinition(s[len("@import") :].strip()) + return None diff --git a/pint/delegates/toml_parser/plain.py b/pint/delegates/toml_parser/plain.py new file mode 100644 index 000000000..6785dbeb9 --- /dev/null +++ b/pint/delegates/toml_parser/plain.py @@ -0,0 +1,302 @@ +""" + pint.delegates.txt_defparser.plain + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Definitions for parsing: + - Equality + - CommentDefinition + - PrefixDefinition + - UnitDefinition + - DimensionDefinition + - DerivedDimensionDefinition + - AliasDefinition + + Notices that some of the checks are done within the + format agnostic parent definition class. + + See each one for a slighly longer description of the + syntax. + + :copyright: 2022 by Pint Authors, see AUTHORS for more details. + :license: BSD, see LICENSE for more details. +""" + +from __future__ import annotations + +from dataclasses import dataclass + +import flexparser as fp + +from ...converters import Converter +from ...facets.plain import definitions as definitions_ +from ...facets.group import GroupDefinition as GroupDefinition_ +from ...util import UnitsContainer +from ..base_defparser import ParserConfig +from . import common + +import copy + +@dataclass(frozen=True) +class Equality(definitions_.Equality): + """An equality statement contains a left and right hand separated + + lhs and rhs should be space stripped. + """ + + @classmethod + def from_string(cls, s: str) -> fp.NullableParsedResult[Equality]: + if "=" not in s: + return None + parts = [p.strip() for p in s.split("=")] + if len(parts) != 2: + return common.DefinitionSyntaxError( + f"Exactly two terms expected, not {len(parts)} (`{s}`)" + ) + return cls(*parts) + + +@dataclass(frozen=True) +class CommentDefinition(definitions_.CommentDefinition): + """Comments start with a # character. + + # This is a comment. + ## This is also a comment. + + Captured value does not include the leading # character and space stripped. + """ + + @classmethod + def from_string(cls, s: str) -> fp.NullableParsedResult[CommentDefinition]: + if not s.startswith("#"): + return None + return cls(s[1:].strip()) + + +@dataclass(frozen=True) +class PrefixDefinition(definitions_.PrefixDefinition): + """Definition of a prefix:: + + - = [= ] [= ] [ = ] [...] + + Example:: + + deca- = 1e+1 = da- = deka- + """ + + @classmethod + def from_dict_and_config( + cls, d: from_dict, config: ParserConfig + ) -> PrefixDefinition: + name = d["name"] + value = d["value"] + defined_symbol = d.get("defined_symbol", None) + aliases = d.get("aliases", []) + + name = name.strip() + # if not name.endswith("-"): + # return None + + # name = name.rstrip("-") + # aliases = tuple(alias.strip().rstrip("-") for alias in aliases) + + # defined_symbol = None + # if aliases: + # if aliases[0] == "_": + # aliases = aliases[1:] + # else: + # defined_symbol, *aliases = aliases + + # aliases = tuple(alias for alias in aliases if alias not in ("", "_")) + + try: + value = config.to_number(value) + except definitions_.NotNumeric as ex: + return common.DefinitionSyntaxError( + f"Prefix definition ('{name}') must contain only numbers, not {ex.value}" + ) + + try: + return cls(name, value, defined_symbol, aliases) + except Exception as exc: + return common.DefinitionSyntaxError(str(exc)) + + +@dataclass(frozen=True) +class UnitDefinition(definitions_.UnitDefinition): + """Definition of a unit:: + + = [= ] [= ] [ = ] [...] + + Example:: + + millennium = 1e3 * year = _ = millennia + + Parameters + ---------- + reference : UnitsContainer + Reference units. + is_base : bool + Indicates if it is a base unit. + + """ + + @classmethod + def from_dict_and_config( + cls, d: from_dict, config: ParserConfig + ) -> UnitDefinition: + name = d["name"] + value = d["value"] + aliases = d.get("aliases", []) + defined_symbol = d.get("defined_symbol", None) + + if ";" in value: + [converter, modifiers] = value.split(";", 1) + + try: + modifiers = { + key.strip(): config.to_number(value) + for key, value in (part.split(":") for part in modifiers.split(";")) + } + except definitions_.NotNumeric as ex: + return common.DefinitionSyntaxError( + f"Unit definition ('{name}') must contain only numbers in modifier, not {ex.value}" + ) + + else: + converter = value + modifiers = {} + + converter = config.to_scaled_units_container(converter) + + try: + reference = UnitsContainer(converter) + # reference = converter.to_units_container() + except common.DefinitionSyntaxError as ex: + return common.DefinitionSyntaxError(f"While defining {name}: {ex}") + + try: + converter = Converter.from_arguments(scale=converter.scale, **modifiers) + except Exception as ex: + return common.DefinitionSyntaxError( + f"Unable to assign a converter to the unit {ex}" + ) + + try: + return cls(name, defined_symbol, tuple(aliases), converter, reference) + except Exception as ex: + return common.DefinitionSyntaxError(str(ex)) + + +@dataclass(frozen=True) +class DimensionDefinition(definitions_.DimensionDefinition): + """Definition of a root dimension:: + + [dimension name] + + Example:: + + [volume] + """ + + @classmethod + def from_dict_and_config( + cls, d: from_dict, config: ParserConfig + ) -> DimensionDefinition: + + return cls(**d) + + +@dataclass(frozen=True) +class DerivedDimensionDefinition( + definitions_.DerivedDimensionDefinition +): + """Definition of a derived dimension:: + + [dimension name] = + + Example:: + + [density] = [mass] / [volume] + """ + + @classmethod + def from_dict_and_config( + cls, d: from_dict, config: ParserConfig + ) -> DerivedDimensionDefinition: + name = d["name"] + value = d["value"] + + try: + reference = config.to_dimension_container(value) + except common.DefinitionSyntaxError as exc: + return common.DefinitionSyntaxError( + f"In {name} derived dimensions must only be referenced " + f"to dimensions. {exc}" + ) + + try: + return cls(name.strip(), reference) + except Exception as exc: + return common.DefinitionSyntaxError(str(exc)) + + +@dataclass(frozen=True) +class AliasDefinition(definitions_.AliasDefinition): + """Additional alias(es) for an already existing unit:: + + @alias = [ = ] [...] + + Example:: + + @alias meter = my_meter + """ + + @classmethod + def from_string(cls, s: str) -> fp.NullableParsedResult[AliasDefinition]: + if not s.startswith("@alias "): + return None + name, *aliases = s[len("@alias ") :].split("=") + + try: + return cls(name.strip(), tuple(alias.strip() for alias in aliases)) + except Exception as exc: + return common.DefinitionSyntaxError(str(exc)) + + +@dataclass(frozen=True) +class GroupDefinition( + GroupDefinition_ +): + """Definition of a group. + + @group [using , ..., ] + + ... + + @end + + See UnitDefinition and Comment for more parsing related information. + + Example:: + + @group AvoirdupoisUS using Avoirdupois + US_hundredweight = hundredweight = US_cwt + US_ton = ton + US_force_ton = force_ton = _ = US_ton_force + @end + + """ + + @classmethod + def from_dict_and_config(cls, d, config) -> GroupDefinition: + name = d["name"] + using_group_names = d.get("using_group_names", ()) + definitions = [] + for key, value in d["definitions"].items(): + dat=copy.copy(value) + dat['name']=key + definitions.append(UnitDefinition.from_dict_and_config(dat, config)) + + return cls( + name, using_group_names, definitions + ) diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py new file mode 100644 index 000000000..3da30f0ca --- /dev/null +++ b/pint/delegates/toml_parser/toml_parser.py @@ -0,0 +1,152 @@ +from __future__ import annotations + +import pathlib +import typing as ty +import toml +import copy + +import flexcache as fc +import flexparser as fp + +from ..base_defparser import ParserConfig +# from . import block, common, context, defaults, group, plain, system +from . import plain + +# class PintRootBlock( +# fp.RootBlock[ +# ty.Union[ +# plain.CommentDefinition, +# common.ImportDefinition, +# context.ContextDefinition, +# defaults.DefaultsDefinition, +# system.SystemDefinition, +# group.GroupDefinition, +# plain.AliasDefinition, +# plain.DerivedDimensionDefinition, +# plain.DimensionDefinition, +# plain.PrefixDefinition, +# plain.UnitDefinition, +# ], +# ParserConfig, +# ] +# ): +# pass + + +# class _PintParser(fp.Parser[PintRootBlock, ParserConfig]): +# """Parser for the original Pint definition file, with cache.""" + +# _delimiters = { +# "#": ( +# fp.DelimiterInclude.SPLIT_BEFORE, +# fp.DelimiterAction.CAPTURE_NEXT_TIL_EOL, +# ), +# **fp.SPLIT_EOL, +# } +# _root_block_class = PintRootBlock +# _strip_spaces = True + +# _diskcache: fc.DiskCache | None + +# def __init__(self, config: ParserConfig, *args: ty.Any, **kwargs: ty.Any): +# self._diskcache = kwargs.pop("diskcache", None) +# super().__init__(config, *args, **kwargs) + +# def parse_file( +# self, path: pathlib.Path +# ) -> fp.ParsedSource[PintRootBlock, ParserConfig]: +# if self._diskcache is None: +# return super().parse_file(path) +# content, _basename = self._diskcache.load(path, super().parse_file) +# return content + + +class TomlParser: + + def __init__(self, default_config: ParserConfig, diskcache: fc.DiskCache): + self._default_config = default_config + self._diskcache = diskcache + + def iter_parsed_project( + self, parsed_project: fp.ParsedProject[PintRootBlock, ParserConfig] + ) -> ty.Generator[fp.ParsedStatement[ParserConfig], None, None]: + + stmts = { + 'unit': plain.UnitDefinition, + 'prefix': plain.PrefixDefinition, + 'dimension': plain.DerivedDimensionDefinition, + # 'system': system.SystemDefinition, + # 'context': context.ContextDefinition, + 'group': plain.GroupDefinition, + } + for definition_type in parsed_project.keys(): + for key, value in parsed_project[definition_type].items(): + d=copy.copy(value) + d['name']=key + stmt = stmts[definition_type].from_dict_and_config(d, self._default_config) + yield stmt + + + + # last_location = None + + # for stmt in parsed_project.iter_blocks(): + # if isinstance(stmt, fp.BOS): + # if isinstance(stmt, fp.BOF): + # last_location = str(stmt.path) + # continue + # elif isinstance(stmt, fp.BOR): + # last_location = ( + # f"[package: {stmt.package}, resource: {stmt.resource_name}]" + # ) + # continue + # else: + # last_location = "orphan string" + # continue + + # if isinstance(stmt, self.skip_classes): + # continue + + # assert isinstance(last_location, str) + # if isinstance(stmt, common.DefinitionSyntaxError): + # stmt.set_location(last_location) + # raise stmt + # elif isinstance(stmt, block.DirectiveBlock): + # for exc in stmt.errors: + # exc = common.DefinitionSyntaxError(str(exc)) + # exc.set_position(*stmt.get_position()) + # exc.set_raw( + # (stmt.opening.raw or "") + " [...] " + (stmt.closing.raw or "") + # ) + # exc.set_location(last_location) + # raise exc + + # try: + # yield stmt.derive_definition() + # except Exception as exc: + # exc = common.DefinitionSyntaxError(str(exc)) + # exc.set_position(*stmt.get_position()) + # exc.set_raw(stmt.opening.raw + " [...] " + stmt.closing.raw) + # exc.set_location(last_location) + # raise exc + # else: + # yield stmt + + def parse_file( + self, filename: pathlib.Path | str, cfg: ParserConfig | None = None + ) -> dict: + with open(filename, 'r', encoding="utf-8") as f: + data = toml.load(f) + return data + + def parse_string( + self, content: str, cfg: ParserConfig | None = None + ) -> fp.ParsedProject[PintRootBlock, ParserConfig]: + return fp.parse_bytes( + content.encode("utf-8"), + _PintParser, + cfg or self._default_config, + diskcache=self._diskcache, + strip_spaces=True, + delimiters=_PintParser._delimiters, + ) diff --git a/pint/facets/context/registry.py b/pint/facets/context/registry.py index 8f9f71ca5..bb627281e 100644 --- a/pint/facets/context/registry.py +++ b/pint/facets/context/registry.py @@ -67,6 +67,8 @@ def __init__(self, **kwargs: Any) -> None: # Map context chain to units override self._context_units = {} + self._context_definitions: list[ContextDefinition] = [] + super().__init__(**kwargs) # Allow contexts to add override layers to the units @@ -85,6 +87,7 @@ def add_context(self, context: objects.Context | ContextDefinition) -> None: see :meth:`enable_contexts`. """ if isinstance(context, ContextDefinition): + self._context_definitions.append(context) context = objects.Context.from_definition(context, self.get_dimensionality) if not context.name: diff --git a/pint/facets/group/registry.py b/pint/facets/group/registry.py index 33f78c645..1bf798ff2 100644 --- a/pint/facets/group/registry.py +++ b/pint/facets/group/registry.py @@ -49,6 +49,7 @@ def __init__(self, **kwargs): #: Map group name to group. self._groups: dict[str, objects.Group] = {} self._groups["root"] = self.Group("root") + self._group_definitions: list[GroupDefinition] = [] def _init_dynamic_classes(self) -> None: """Generate subclasses on the fly and attach them to self""" @@ -87,14 +88,15 @@ def _add_unit(self, definition: UnitDefinition): self.get_group("root").add_units(definition.name) def _add_group(self, gd: GroupDefinition): + self._group_definitions.append(gd) if gd.name in self._groups: raise ValueError(f"Group {gd.name} already present in registry") - try: + # try: # As a Group is a SharedRegistryObject # it adds itself to the registry. - self.Group.from_definition(gd) - except KeyError as e: - raise errors.DefinitionSyntaxError(f"unknown dimension {e} in context") + self.Group.from_definition(gd) + # except KeyError as e: + # raise errors.DefinitionSyntaxError(f"unknown dimension {e} in context") def get_group(self, name: str, create_if_needed: bool = True) -> objects.Group: """Return a Group. diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index be70a2ca8..a3004fde8 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -250,7 +250,9 @@ def __init__( self._def_parser = delegates.txt_defparser.DefParser( delegates.ParserConfig(non_int_type), diskcache=self._diskcache ) - + self._toml_parser = delegates.toml_parser.TomlParser( + delegates.ParserConfig(non_int_type), diskcache=self._diskcache + ) self.formatter = delegates.Formatter(self) self._filename = filename self.force_ndarray = force_ndarray @@ -594,11 +596,17 @@ def load_definitions( if isinstance(file, (list, tuple)): # TODO: this hack was to keep it backwards compatible. parsed_project = self._def_parser.parse_string("\n".join(file)) + elif str(file)[-5:] == ".toml": + parsed_project = self._toml_parser.parse_file(file) else: parsed_project = self._def_parser.parse_file(file) - for definition in self._def_parser.iter_parsed_project(parsed_project): - self._helper_dispatch_adder(definition) + if str(file)[-5:] == ".toml": + for definition in self._toml_parser.iter_parsed_project(parsed_project): + self._helper_dispatch_adder(definition) + else: + for definition in self._def_parser.iter_parsed_project(parsed_project): + self._helper_dispatch_adder(definition) return parsed_project diff --git a/pint/facets/system/registry.py b/pint/facets/system/registry.py index e5235a4cb..5a6dda8fe 100644 --- a/pint/facets/system/registry.py +++ b/pint/facets/system/registry.py @@ -61,6 +61,7 @@ def __init__(self, system: str | None = None, **kwargs): self._base_units_cache: dict[UnitsContainerT, UnitsContainerT] = {} self._default_system_name: str | None = system + self._system_definitions: list[SystemDefinition] = [] def _init_dynamic_classes(self) -> None: """Generate subclasses on the fly and attach them to self""" @@ -85,6 +86,8 @@ def _register_definition_adders(self) -> None: self._register_adder(SystemDefinition, self._add_system) def _add_system(self, sd: SystemDefinition) -> None: + self._system_definitions.append(sd) + if sd.name in self._systems: raise ValueError(f"System {sd.name} already present in registry") From cece760da15ca02063f2580fa354814325dbbb20 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 10 Feb 2025 00:04:30 +0000 Subject: [PATCH 02/20] init --- toml.ipynb | 2355 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2355 insertions(+) create mode 100644 toml.ipynb diff --git a/toml.ipynb b/toml.ipynb new file mode 100644 index 000000000..e9345ddc5 --- /dev/null +++ b/toml.ipynb @@ -0,0 +1,2355 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.13.1\n" + ] + } + ], + "source": [ + "import platform\n", + "print(platform.python_version())" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import pint\n", + "ureg = pint.UnitRegistry()\n", + "Q_= ureg.Quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from dataclasses import fields\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "import toml" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "skip_fields = ['name',\n", + " # 'value',\n", + " # 'defined_symbol',\n", + " # 'aliases',\n", + " 'is_position_set',\n", + " 'start_line',\n", + " 'start_col',\n", + " 'end_line',\n", + " 'end_col',\n", + " 'raw']\n", + "\n", + "keep_fields = [\n", + "\n", + " 'value',\n", + " 'defined_symbol',\n", + " 'aliases',\n", + "]\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "data = {\n", + " '_prefixes':{},\n", + " # '_suffixes':{},\n", + " '_units':{},\n", + " '_dimensions':{},\n", + " # '_contexts':{},\n", + " # 'system':{},\n", + " # 'group':{},\n", + "}\n", + "def add_key_if_not_empty(dat, key, value):\n", + " if value == () or value is None:\n", + " return dat\n", + " else:\n", + " dat[key]=value\n", + " return dat\n", + " \n", + "def parse_simple_definition(definition, definition_type):\n", + " attrs = [field.name for field in fields(definition) if field.name in keep_fields]\n", + " dat = {}\n", + " for attr in attrs:\n", + " dat=add_key_if_not_empty(dat, attr, getattr(definition,attr))\n", + " if definition_type ==\"_units\" and hasattr(definition,'raw'):\n", + " dat['value'] = definition.raw.split(\"=\")[1].strip()\n", + " if definition_type ==\"_dimensions\" and hasattr(definition,'raw'):\n", + " dat['value'] = definition.raw.split(\"=\")[1].strip()\n", + " if definition_type ==\"_prefixes\" and hasattr(definition,'raw'):\n", + " dat['value'] = definition.raw.split(\"=\")[1].strip()\n", + " return dat\n", + "prefixes = ureg._prefixes\n", + "for definition_type in data.keys():\n", + " definitions = getattr(ureg, definition_type).values()\n", + " for definition in definitions:\n", + " if hasattr(definition,'raw'):\n", + " data[definition_type][definition.name]=parse_simple_definition(definition, definition_type)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "data['prefix'] = data.pop('_prefixes')\n", + "data['unit'] = data.pop('_units')\n", + "data['dimension'] = data.pop('_dimensions')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "data['group']={}\n", + "for group in ureg._group_definitions:\n", + " dat = {}\n", + " for attr in [\"using_group_names\"]:\n", + " dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", + " dat['definitions']={}\n", + " for definition in group.definitions:\n", + " dat['definitions'][definition.name]=parse_simple_definition(definition, '_units')\n", + " data['group'][group.name] = dat" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "data['system']={}\n", + "for group in ureg._system_definitions:\n", + " dat = {}\n", + " for attr in [\"using_group_names\"]:\n", + " dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", + " dat['rules']=[]\n", + " for rule in group.rules:\n", + " dat['rules'].append(rule.raw)\n", + " data['system'][group.name] = dat" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "data['context']={}\n", + "for group in ureg._context_definitions:\n", + " dat = {}\n", + " for attr in [\"aliases\", \"defaults\", \"redefinitions\"]:\n", + " dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", + " dat['relations']=[]\n", + " for rule in group.relations:\n", + " dat['relations'].append(rule.raw)\n", + " data['system'][group.name] = dat" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'defaults': {},\n", + " 'relations': ['[mass] / [length] <-> [length] / [mass]: 1 / value']}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dat" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "# data['system']={}\n", + "# for group in ureg._system_definitions:\n", + "# dat = {}\n", + "# for attr in [\"using_group_names\"]:\n", + "# dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", + "# dat['rules']=[]\n", + "# for rule in group.rules:\n", + "# d_={'new_unit_name':rule.new_unit_name}\n", + "# if rule.old_unit_name:\n", + "# d_['old_unit_name'] = rule.old_unit_name\n", + "# dat['rules'].append(d_)\n", + "# data['system'][group.name] = dat" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "with open('test.toml', 'w', encoding=\"utf-8\") as f:\n", + " toml.dump(data, f)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "import tomli_w\n", + "with open('test.toml', 'wb') as f:\n", + " tomli_w.dump(data, f)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "with open('test.toml', 'r', encoding=\"utf-8\") as f:\n", + " config = toml.load(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'prefix': {'quecto': {'value': '1e-30', 'defined_symbol': 'q'},\n", + " 'ronto': {'value': '1e-27', 'defined_symbol': 'r'},\n", + " 'yocto': {'value': '1e-24', 'defined_symbol': 'y'},\n", + " 'zepto': {'value': '1e-21', 'defined_symbol': 'z'},\n", + " 'atto': {'value': '1e-18', 'defined_symbol': 'a'},\n", + " 'femto': {'value': '1e-15', 'defined_symbol': 'f'},\n", + " 'pico': {'value': '1e-12', 'defined_symbol': 'p'},\n", + " 'nano': {'value': '1e-9', 'defined_symbol': 'n'},\n", + " 'micro': {'value': '1e-6',\n", + " 'defined_symbol': 'µ',\n", + " 'aliases': ['μ', 'u', 'mu', 'mc']},\n", + " 'milli': {'value': '1e-3', 'defined_symbol': 'm'},\n", + " 'centi': {'value': '1e-2', 'defined_symbol': 'c'},\n", + " 'deci': {'value': '1e-1', 'defined_symbol': 'd'},\n", + " 'deca': {'value': '1e+1', 'defined_symbol': 'da', 'aliases': ['deka']},\n", + " 'hecto': {'value': '1e2', 'defined_symbol': 'h'},\n", + " 'kilo': {'value': '1e3', 'defined_symbol': 'k'},\n", + " 'mega': {'value': '1e6', 'defined_symbol': 'M'},\n", + " 'giga': {'value': '1e9', 'defined_symbol': 'G'},\n", + " 'tera': {'value': '1e12', 'defined_symbol': 'T'},\n", + " 'peta': {'value': '1e15', 'defined_symbol': 'P'},\n", + " 'exa': {'value': '1e18', 'defined_symbol': 'E'},\n", + " 'zetta': {'value': '1e21', 'defined_symbol': 'Z'},\n", + " 'yotta': {'value': '1e24', 'defined_symbol': 'Y'},\n", + " 'ronna': {'value': '1e27', 'defined_symbol': 'R'},\n", + " 'quetta': {'value': '1e30', 'defined_symbol': 'Q'},\n", + " 'kibi': {'value': '2**10', 'defined_symbol': 'Ki'},\n", + " 'mebi': {'value': '2**20', 'defined_symbol': 'Mi'},\n", + " 'gibi': {'value': '2**30', 'defined_symbol': 'Gi'},\n", + " 'tebi': {'value': '2**40', 'defined_symbol': 'Ti'},\n", + " 'pebi': {'value': '2**50', 'defined_symbol': 'Pi'},\n", + " 'exbi': {'value': '2**60', 'defined_symbol': 'Ei'},\n", + " 'zebi': {'value': '2**70', 'defined_symbol': 'Zi'},\n", + " 'yobi': {'value': '2**80', 'defined_symbol': 'Yi'},\n", + " 'semi': {'value': '0.5', 'aliases': ['demi']},\n", + " 'sesqui': {'value': '1.5'}},\n", + " 'unit': {'meter': {'defined_symbol': 'm',\n", + " 'aliases': ['metre'],\n", + " 'value': '[length]'},\n", + " 'second': {'defined_symbol': 's', 'aliases': ['sec'], 'value': '[time]'},\n", + " 'ampere': {'defined_symbol': 'A', 'aliases': ['amp'], 'value': '[current]'},\n", + " 'candela': {'defined_symbol': 'cd',\n", + " 'aliases': ['candle'],\n", + " 'value': '[luminosity]'},\n", + " 'gram': {'defined_symbol': 'g', 'value': '[mass]'},\n", + " 'mole': {'defined_symbol': 'mol', 'value': '[substance]'},\n", + " 'kelvin': {'defined_symbol': 'K',\n", + " 'aliases': ['degK', '°K', 'degree_Kelvin', 'degreeK'],\n", + " 'value': '[temperature]; offset: 0'},\n", + " 'radian': {'defined_symbol': 'rad', 'value': '[]'},\n", + " 'bit': {'value': '[]'},\n", + " 'count': {'value': '[]'},\n", + " 'pi': {'defined_symbol': 'π',\n", + " 'value': '3.1415926535897932384626433832795028841971693993751'},\n", + " 'tansec': {'value': '4.8481368111333441675396429478852851658848753880815e-6'},\n", + " 'ln10': {'value': '2.3025850929940456840179914546843642076011014886288'},\n", + " 'wien_x': {'value': '4.9651142317442763036987591313228939440555849867973'},\n", + " 'wien_u': {'value': '2.8214393721220788934031913302944851953458817440731'},\n", + " 'eulers_number': {'value': '2.71828182845904523536028747135266249775724709369995'},\n", + " 'speed_of_light': {'defined_symbol': 'c',\n", + " 'aliases': ['c_0'],\n", + " 'value': '299792458 m/s'},\n", + " 'planck_constant': {'defined_symbol': 'ℎ', 'value': '6.62607015e-34 J s'},\n", + " 'elementary_charge': {'defined_symbol': 'e', 'value': '1.602176634e-19 C'},\n", + " 'avogadro_number': {'value': '6.02214076e23'},\n", + " 'boltzmann_constant': {'defined_symbol': 'k',\n", + " 'aliases': ['k_B'],\n", + " 'value': '1.380649e-23 J K^-1'},\n", + " 'standard_gravity': {'defined_symbol': 'g_0',\n", + " 'aliases': ['g0', 'g_n', 'gravity'],\n", + " 'value': '9.80665 m/s^2'},\n", + " 'standard_atmosphere': {'defined_symbol': 'atm',\n", + " 'aliases': ['atmosphere'],\n", + " 'value': '1.01325e5 Pa'},\n", + " 'conventional_josephson_constant': {'defined_symbol': 'K_J90',\n", + " 'value': '4.835979e14 Hz / V'},\n", + " 'conventional_von_klitzing_constant': {'defined_symbol': 'R_K90',\n", + " 'value': '2.5812807e4 ohm'},\n", + " 'zeta': {'defined_symbol': 'ζ', 'value': 'c / (cm/s)'},\n", + " 'dirac_constant': {'defined_symbol': 'ħ',\n", + " 'aliases': ['hbar', 'atomic_unit_of_action', 'a_u_action'],\n", + " 'value': 'ℎ / (2 * π)'},\n", + " 'avogadro_constant': {'defined_symbol': 'N_A',\n", + " 'value': 'avogadro_number * mol^-1'},\n", + " 'molar_gas_constant': {'defined_symbol': 'R', 'value': 'k * N_A'},\n", + " 'faraday_constant': {'value': 'e * N_A'},\n", + " 'conductance_quantum': {'defined_symbol': 'G_0', 'value': '2 * e ** 2 / ℎ'},\n", + " 'magnetic_flux_quantum': {'defined_symbol': 'Φ_0',\n", + " 'aliases': ['Phi_0'],\n", + " 'value': 'ℎ / (2 * e)'},\n", + " 'josephson_constant': {'defined_symbol': 'K_J', 'value': '2 * e / ℎ'},\n", + " 'von_klitzing_constant': {'defined_symbol': 'R_K', 'value': 'ℎ / e ** 2'},\n", + " 'stefan_boltzmann_constant': {'defined_symbol': 'σ',\n", + " 'aliases': ['sigma'],\n", + " 'value': '2 / 15 * π ** 5 * k ** 4 / (ℎ ** 3 * c ** 2)'},\n", + " 'first_radiation_constant': {'defined_symbol': 'c_1',\n", + " 'value': '2 * π * ℎ * c ** 2'},\n", + " 'second_radiation_constant': {'defined_symbol': 'c_2', 'value': 'ℎ * c / k'},\n", + " 'wien_wavelength_displacement_law_constant': {'value': 'ℎ * c / (k * wien_x)'},\n", + " 'wien_frequency_displacement_law_constant': {'value': 'wien_u * k / ℎ'},\n", + " 'newtonian_constant_of_gravitation': {'aliases': ['gravitational_constant'],\n", + " 'value': '6.67430e-11 m^3/(kg s^2)'},\n", + " 'rydberg_constant': {'defined_symbol': 'R_∞',\n", + " 'aliases': ['R_inf'],\n", + " 'value': '1.0973731568157e7 * m^-1'},\n", + " 'electron_g_factor': {'defined_symbol': 'g_e', 'value': '-2.00231930436092'},\n", + " 'atomic_mass_constant': {'defined_symbol': 'm_u',\n", + " 'value': '1.66053906892e-27 kg'},\n", + " 'electron_mass': {'defined_symbol': 'm_e',\n", + " 'aliases': ['atomic_unit_of_mass', 'a_u_mass'],\n", + " 'value': '9.1093837139e-31 kg'},\n", + " 'proton_mass': {'defined_symbol': 'm_p', 'value': '1.67262192595e-27 kg'},\n", + " 'neutron_mass': {'defined_symbol': 'm_n', 'value': '1.67492750056e-27 kg'},\n", + " 'x_unit_Cu': {'defined_symbol': 'Xu_Cu', 'value': '1.00207697e-13 m'},\n", + " 'x_unit_Mo': {'defined_symbol': 'Xu_Mo', 'value': '1.00209952e-13 m'},\n", + " 'angstrom_star': {'defined_symbol': 'Å_star', 'value': '1.00001495e-10'},\n", + " 'fine_structure_constant': {'defined_symbol': 'α',\n", + " 'aliases': ['alpha'],\n", + " 'value': '(2 * ℎ * R_inf / (m_e * c)) ** 0.5'},\n", + " 'vacuum_permeability': {'defined_symbol': 'µ_0',\n", + " 'aliases': ['mu_0', 'mu0', 'magnetic_constant'],\n", + " 'value': '2 * α * ℎ / (e ** 2 * c)'},\n", + " 'vacuum_permittivity': {'defined_symbol': 'ε_0',\n", + " 'aliases': ['epsilon_0', 'eps_0', 'eps0', 'electric_constant'],\n", + " 'value': 'e ** 2 / (2 * α * ℎ * c)'},\n", + " 'impedance_of_free_space': {'defined_symbol': 'Z_0',\n", + " 'aliases': ['characteristic_impedance_of_vacuum'],\n", + " 'value': '2 * α * ℎ / e ** 2'},\n", + " 'coulomb_constant': {'defined_symbol': 'k_C',\n", + " 'value': 'α * hbar * c / e ** 2'},\n", + " 'classical_electron_radius': {'defined_symbol': 'r_e',\n", + " 'value': 'α * hbar / (m_e * c)'},\n", + " 'thomson_cross_section': {'defined_symbol': 'σ_e',\n", + " 'aliases': ['sigma_e'],\n", + " 'value': '8 / 3 * π * r_e ** 2'},\n", + " 'turn': {'aliases': ['revolution', 'cycle', 'circle'],\n", + " 'value': '2 * π * radian'},\n", + " 'degree': {'defined_symbol': 'deg',\n", + " 'aliases': ['arcdeg', 'arcdegree', 'angular_degree'],\n", + " 'value': 'π / 180 * radian'},\n", + " 'arcminute': {'defined_symbol': 'arcmin',\n", + " 'aliases': ['arc_minute', 'angular_minute'],\n", + " 'value': 'degree / 60'},\n", + " 'arcsecond': {'defined_symbol': 'arcsec',\n", + " 'aliases': ['arc_second', 'angular_second'],\n", + " 'value': 'arcminute / 60'},\n", + " 'milliarcsecond': {'defined_symbol': 'mas', 'value': '1e-3 * arcsecond'},\n", + " 'grade': {'defined_symbol': 'grad',\n", + " 'aliases': ['gon'],\n", + " 'value': 'π / 200 * radian'},\n", + " 'mil': {'value': 'π / 32000 * radian'},\n", + " 'steradian': {'defined_symbol': 'sr', 'value': 'radian ** 2'},\n", + " 'square_degree': {'defined_symbol': 'sq_deg',\n", + " 'aliases': ['sqdeg'],\n", + " 'value': '(π / 180) ** 2 * sr'},\n", + " 'baud': {'defined_symbol': 'Bd',\n", + " 'aliases': ['bps'],\n", + " 'value': 'bit / second'},\n", + " 'byte': {'defined_symbol': 'B', 'aliases': ['octet'], 'value': '8 * bit'},\n", + " 'percent': {'defined_symbol': '%', 'value': '0.01'},\n", + " 'permille': {'defined_symbol': '‰', 'value': '0.001'},\n", + " 'ppm': {'value': '1e-6'},\n", + " 'angstrom': {'defined_symbol': 'Å',\n", + " 'aliases': ['ångström', 'Å'],\n", + " 'value': '1e-10 * meter'},\n", + " 'micron': {'defined_symbol': 'µ', 'aliases': ['μ'], 'value': 'micrometer'},\n", + " 'fermi': {'defined_symbol': 'fm', 'value': 'femtometer'},\n", + " 'light_year': {'defined_symbol': 'ly',\n", + " 'aliases': ['lightyear'],\n", + " 'value': 'speed_of_light * julian_year'},\n", + " 'astronomical_unit': {'defined_symbol': 'au',\n", + " 'value': '149597870700 * meter'},\n", + " 'parsec': {'defined_symbol': 'pc',\n", + " 'value': '1 / tansec * astronomical_unit'},\n", + " 'nautical_mile': {'defined_symbol': 'nmi', 'value': '1852 * meter'},\n", + " 'bohr': {'defined_symbol': 'a_0',\n", + " 'aliases': ['a0', 'bohr_radius', 'atomic_unit_of_length', 'a_u_length'],\n", + " 'value': 'hbar / (alpha * m_e * c)'},\n", + " 'planck_length': {'value': '(hbar * gravitational_constant / c ** 3) ** 0.5'},\n", + " 'metric_ton': {'defined_symbol': 't',\n", + " 'aliases': ['tonne'],\n", + " 'value': '1e3 * kilogram'},\n", + " 'unified_atomic_mass_unit': {'defined_symbol': 'u',\n", + " 'aliases': ['amu'],\n", + " 'value': 'atomic_mass_constant'},\n", + " 'dalton': {'defined_symbol': 'Da', 'value': 'atomic_mass_constant'},\n", + " 'grain': {'defined_symbol': 'gr', 'value': '64.79891 * milligram'},\n", + " 'gamma_mass': {'value': 'microgram'},\n", + " 'carat': {'defined_symbol': 'ct',\n", + " 'aliases': ['karat'],\n", + " 'value': '200 * milligram'},\n", + " 'planck_mass': {'value': '(hbar * c / gravitational_constant) ** 0.5'},\n", + " 'minute': {'defined_symbol': 'min', 'value': '60 * second'},\n", + " 'hour': {'defined_symbol': 'h', 'aliases': ['hr'], 'value': '60 * minute'},\n", + " 'day': {'defined_symbol': 'd', 'value': '24 * hour'},\n", + " 'week': {'value': '7 * day'},\n", + " 'fortnight': {'value': '2 * week'},\n", + " 'year': {'defined_symbol': 'a',\n", + " 'aliases': ['yr', 'julian_year'],\n", + " 'value': '365.25 * day'},\n", + " 'month': {'value': 'year / 12'},\n", + " 'century': {'aliases': ['centuries'], 'value': '100 * year'},\n", + " 'millennium': {'aliases': ['millennia'], 'value': '1e3 * year'},\n", + " 'eon': {'value': '1e9 * year'},\n", + " 'shake': {'value': '1e-8 * second'},\n", + " 'svedberg': {'value': '1e-13 * second'},\n", + " 'atomic_unit_of_time': {'defined_symbol': 'a_u_time', 'value': 'hbar / E_h'},\n", + " 'gregorian_year': {'value': '365.2425 * day'},\n", + " 'sidereal_year': {'value': '365.256363004 * day'},\n", + " 'tropical_year': {'value': '365.242190402 * day'},\n", + " 'common_year': {'value': '365 * day'},\n", + " 'leap_year': {'value': '366 * day'},\n", + " 'sidereal_day': {'value': 'day / 1.00273790935079524'},\n", + " 'sidereal_month': {'value': '27.32166155 * day'},\n", + " 'tropical_month': {'value': '27.321582 * day'},\n", + " 'synodic_month': {'aliases': ['lunar_month'], 'value': '29.530589 * day'},\n", + " 'planck_time': {'value': '(hbar * gravitational_constant / c ** 5) ** 0.5'},\n", + " 'degree_Celsius': {'defined_symbol': '°C',\n", + " 'aliases': ['celsius', 'degC', 'degreeC'],\n", + " 'value': 'kelvin; offset: 273.15'},\n", + " 'degree_Rankine': {'defined_symbol': '°R',\n", + " 'aliases': ['rankine', 'degR', 'degreeR'],\n", + " 'value': '5 / 9 * kelvin; offset: 0'},\n", + " 'degree_Fahrenheit': {'defined_symbol': '°F',\n", + " 'aliases': ['fahrenheit', 'degF', 'degreeF'],\n", + " 'value': '5 / 9 * kelvin; offset: 233.15 + 200 / 9'},\n", + " 'degree_Reaumur': {'defined_symbol': '°Re',\n", + " 'aliases': ['reaumur', 'degRe', 'degreeRe', 'degree_Réaumur', 'réaumur'],\n", + " 'value': '4 / 5 * kelvin; offset: 273.15'},\n", + " 'atomic_unit_of_temperature': {'defined_symbol': 'a_u_temp',\n", + " 'value': 'E_h / k'},\n", + " 'planck_temperature': {'value': '(hbar * c ** 5 / gravitational_constant / k ** 2) ** 0.5'},\n", + " 'are': {'value': '100 * meter ** 2'},\n", + " 'barn': {'defined_symbol': 'b', 'value': '1e-28 * meter ** 2'},\n", + " 'darcy': {'value': 'centipoise * centimeter ** 2 / (second * atmosphere)'},\n", + " 'hectare': {'defined_symbol': 'ha', 'value': '100 * are'},\n", + " 'liter': {'defined_symbol': 'l',\n", + " 'aliases': ['L', 'ℓ', 'litre'],\n", + " 'value': 'decimeter ** 3'},\n", + " 'cubic_centimeter': {'defined_symbol': 'cc', 'value': 'centimeter ** 3'},\n", + " 'lambda': {'defined_symbol': 'λ', 'value': 'microliter'},\n", + " 'stere': {'value': 'meter ** 3'},\n", + " 'hertz': {'defined_symbol': 'Hz', 'value': '1 / second'},\n", + " 'revolutions_per_minute': {'defined_symbol': 'rpm',\n", + " 'value': 'revolution / minute'},\n", + " 'revolutions_per_second': {'defined_symbol': 'rps',\n", + " 'value': 'revolution / second'},\n", + " 'counts_per_second': {'defined_symbol': 'cps', 'value': 'count / second'},\n", + " 'reciprocal_centimeter': {'defined_symbol': 'cm_1',\n", + " 'aliases': ['kayser'],\n", + " 'value': '1 / cm'},\n", + " 'knot': {'defined_symbol': 'kt',\n", + " 'aliases': ['knot_international', 'international_knot'],\n", + " 'value': 'nautical_mile / hour'},\n", + " 'mile_per_hour': {'defined_symbol': 'mph',\n", + " 'aliases': ['MPH'],\n", + " 'value': 'mile / hour'},\n", + " 'kilometer_per_hour': {'defined_symbol': 'kph',\n", + " 'aliases': ['KPH'],\n", + " 'value': 'kilometer / hour'},\n", + " 'kilometer_per_second': {'defined_symbol': 'kps',\n", + " 'value': 'kilometer / second'},\n", + " 'meter_per_second': {'defined_symbol': 'mps', 'value': 'meter / second'},\n", + " 'foot_per_second': {'defined_symbol': 'fps', 'value': 'foot / second'},\n", + " 'sverdrup': {'defined_symbol': 'sv', 'value': '1e6 * meter ** 3 / second'},\n", + " 'galileo': {'defined_symbol': 'Gal', 'value': 'centimeter / second ** 2'},\n", + " 'newton': {'defined_symbol': 'N', 'value': 'kilogram * meter / second ** 2'},\n", + " 'dyne': {'defined_symbol': 'dyn',\n", + " 'value': 'gram * centimeter / second ** 2'},\n", + " 'force_kilogram': {'defined_symbol': 'kgf',\n", + " 'aliases': ['kilogram_force', 'pond'],\n", + " 'value': 'g_0 * kilogram'},\n", + " 'force_gram': {'defined_symbol': 'gf',\n", + " 'aliases': ['gram_force'],\n", + " 'value': 'g_0 * gram'},\n", + " 'force_metric_ton': {'defined_symbol': 'tf',\n", + " 'aliases': ['metric_ton_force', 'force_t', 't_force'],\n", + " 'value': 'g_0 * metric_ton'},\n", + " 'atomic_unit_of_force': {'defined_symbol': 'a_u_force',\n", + " 'value': 'E_h / a_0'},\n", + " 'joule': {'defined_symbol': 'J', 'value': 'newton * meter'},\n", + " 'erg': {'value': 'dyne * centimeter'},\n", + " 'watt_hour': {'defined_symbol': 'Wh',\n", + " 'aliases': ['watthour'],\n", + " 'value': 'watt * hour'},\n", + " 'electron_volt': {'defined_symbol': 'eV', 'value': 'e * volt'},\n", + " 'rydberg': {'defined_symbol': 'Ry', 'value': 'ℎ * c * R_inf'},\n", + " 'hartree': {'defined_symbol': 'E_h',\n", + " 'aliases': ['Eh', 'hartree_energy', 'atomic_unit_of_energy', 'a_u_energy'],\n", + " 'value': '2 * rydberg'},\n", + " 'calorie': {'defined_symbol': 'cal',\n", + " 'aliases': ['thermochemical_calorie', 'cal_th'],\n", + " 'value': '4.184 * joule'},\n", + " 'international_calorie': {'defined_symbol': 'cal_it',\n", + " 'aliases': ['international_steam_table_calorie'],\n", + " 'value': '4.1868 * joule'},\n", + " 'fifteen_degree_calorie': {'defined_symbol': 'cal_15',\n", + " 'value': '4.1855 * joule'},\n", + " 'british_thermal_unit': {'defined_symbol': 'Btu',\n", + " 'aliases': ['BTU', 'Btu_iso'],\n", + " 'value': '1055.056 * joule'},\n", + " 'international_british_thermal_unit': {'defined_symbol': 'Btu_it',\n", + " 'value': '1e3 * pound / kilogram * degR / kelvin * international_calorie'},\n", + " 'thermochemical_british_thermal_unit': {'defined_symbol': 'Btu_th',\n", + " 'value': '1e3 * pound / kilogram * degR / kelvin * calorie'},\n", + " 'quadrillion_Btu': {'defined_symbol': 'quad', 'value': '1e15 * Btu'},\n", + " 'therm': {'defined_symbol': 'thm',\n", + " 'aliases': ['EC_therm'],\n", + " 'value': '1e5 * Btu'},\n", + " 'US_therm': {'value': '1.054804e8 * joule'},\n", + " 'ton_TNT': {'defined_symbol': 'tTNT', 'value': '1e9 * calorie'},\n", + " 'tonne_of_oil_equivalent': {'defined_symbol': 'toe',\n", + " 'value': '1e10 * international_calorie'},\n", + " 'atmosphere_liter': {'defined_symbol': 'atm_l',\n", + " 'value': 'atmosphere * liter'},\n", + " 'watt': {'defined_symbol': 'W', 'value': 'joule / second'},\n", + " 'volt_ampere': {'defined_symbol': 'VA', 'value': 'volt * ampere'},\n", + " 'horsepower': {'defined_symbol': 'hp',\n", + " 'aliases': ['UK_horsepower', 'hydraulic_horsepower'],\n", + " 'value': '550 * foot * force_pound / second'},\n", + " 'boiler_horsepower': {'value': '33475 * Btu / hour'},\n", + " 'metric_horsepower': {'value': '75 * force_kilogram * meter / second'},\n", + " 'electrical_horsepower': {'value': '746 * watt'},\n", + " 'refrigeration_ton': {'aliases': ['ton_of_refrigeration'],\n", + " 'value': '12e3 * Btu / hour'},\n", + " 'cooling_tower_ton': {'value': '1.25 * refrigeration_ton'},\n", + " 'standard_liter_per_minute': {'defined_symbol': 'slpm',\n", + " 'aliases': ['slm'],\n", + " 'value': 'atmosphere * liter / minute'},\n", + " 'conventional_watt_90': {'defined_symbol': 'W_90',\n", + " 'value': 'K_J90 ** 2 * R_K90 / (K_J ** 2 * R_K) * watt'},\n", + " 'mercury': {'defined_symbol': 'Hg',\n", + " 'aliases': ['Hg_0C', 'Hg_32F', 'conventional_mercury'],\n", + " 'value': '13.5951 * kilogram / liter'},\n", + " 'water': {'defined_symbol': 'H2O',\n", + " 'aliases': ['conventional_water'],\n", + " 'value': '1.0 * kilogram / liter'},\n", + " 'mercury_60F': {'defined_symbol': 'Hg_60F',\n", + " 'value': '13.5568 * kilogram / liter'},\n", + " 'water_39F': {'defined_symbol': 'water_4C',\n", + " 'value': '0.999972 * kilogram / liter'},\n", + " 'water_60F': {'value': '0.999001 * kilogram / liter'},\n", + " 'pascal': {'defined_symbol': 'Pa', 'value': 'newton / meter ** 2'},\n", + " 'barye': {'defined_symbol': 'Ba',\n", + " 'aliases': ['barie', 'barad', 'barrie', 'baryd'],\n", + " 'value': 'dyne / centimeter ** 2'},\n", + " 'bar': {'value': '1e5 * pascal'},\n", + " 'technical_atmosphere': {'defined_symbol': 'at',\n", + " 'value': 'kilogram * g_0 / centimeter ** 2'},\n", + " 'torr': {'value': 'atm / 760'},\n", + " 'pound_force_per_square_inch': {'defined_symbol': 'psi',\n", + " 'value': 'force_pound / inch ** 2'},\n", + " 'kip_per_square_inch': {'defined_symbol': 'ksi', 'value': 'kip / inch ** 2'},\n", + " 'millimeter_Hg': {'defined_symbol': 'mmHg',\n", + " 'aliases': ['mm_Hg', 'millimeter_Hg_0C'],\n", + " 'value': 'millimeter * Hg * g_0'},\n", + " 'centimeter_Hg': {'defined_symbol': 'cmHg',\n", + " 'aliases': ['cm_Hg', 'centimeter_Hg_0C'],\n", + " 'value': 'centimeter * Hg * g_0'},\n", + " 'inch_Hg': {'defined_symbol': 'inHg',\n", + " 'aliases': ['in_Hg', 'inch_Hg_32F'],\n", + " 'value': 'inch * Hg * g_0'},\n", + " 'inch_Hg_60F': {'value': 'inch * Hg_60F * g_0'},\n", + " 'inch_H2O_39F': {'value': 'inch * water_39F * g_0'},\n", + " 'inch_H2O_60F': {'value': 'inch * water_60F * g_0'},\n", + " 'foot_H2O': {'defined_symbol': 'ftH2O',\n", + " 'aliases': ['feet_H2O'],\n", + " 'value': 'foot * water * g_0'},\n", + " 'centimeter_H2O': {'defined_symbol': 'cmH2O',\n", + " 'aliases': ['cm_H2O'],\n", + " 'value': 'centimeter * water * g_0'},\n", + " 'sound_pressure_level': {'defined_symbol': 'SPL', 'value': '20e-6 * pascal'},\n", + " 'foot_pound': {'defined_symbol': 'ft_lb',\n", + " 'aliases': ['footpound'],\n", + " 'value': 'foot * force_pound'},\n", + " 'poise': {'defined_symbol': 'P', 'value': '0.1 * Pa * second'},\n", + " 'reyn': {'value': 'psi * second'},\n", + " 'stokes': {'defined_symbol': 'St', 'value': 'centimeter ** 2 / second'},\n", + " 'rhe': {'value': '1 / poise'},\n", + " 'particle': {'aliases': ['molec', 'molecule'], 'value': '1 / N_A'},\n", + " 'molar': {'defined_symbol': 'M', 'value': 'mole / liter'},\n", + " 'katal': {'defined_symbol': 'kat', 'value': 'mole / second'},\n", + " 'enzyme_unit': {'defined_symbol': 'U',\n", + " 'aliases': ['enzymeunit'],\n", + " 'value': 'micromole / minute'},\n", + " 'clausius': {'defined_symbol': 'Cl', 'value': 'calorie / kelvin'},\n", + " 'entropy_unit': {'defined_symbol': 'eu', 'value': 'calorie / kelvin / mole'},\n", + " 'becquerel': {'defined_symbol': 'Bq', 'value': 'counts_per_second'},\n", + " 'curie': {'defined_symbol': 'Ci', 'value': '3.7e10 * becquerel'},\n", + " 'rutherford': {'defined_symbol': 'Rd', 'value': '1e6 * becquerel'},\n", + " 'gray': {'defined_symbol': 'Gy', 'value': 'joule / kilogram'},\n", + " 'sievert': {'defined_symbol': 'Sv', 'value': 'joule / kilogram'},\n", + " 'rads': {'value': '0.01 * gray'},\n", + " 'rem': {'value': '0.01 * sievert'},\n", + " 'roentgen': {'aliases': ['röntgen'],\n", + " 'value': '2.58e-4 * coulomb / kilogram'},\n", + " 'peak_sun_hour': {'defined_symbol': 'PSH',\n", + " 'value': '1e3 * watt_hour / meter ** 2'},\n", + " 'langley': {'defined_symbol': 'Ly',\n", + " 'value': 'thermochemical_calorie / centimeter ** 2'},\n", + " 'nit': {'value': 'candela / meter ** 2'},\n", + " 'stilb': {'value': 'candela / centimeter ** 2'},\n", + " 'lambert': {'value': '1 / π * candela / centimeter ** 2'},\n", + " 'lumen': {'defined_symbol': 'lm', 'value': 'candela * steradian'},\n", + " 'lux': {'defined_symbol': 'lx', 'value': 'lumen / meter ** 2'},\n", + " 'atomic_unit_of_intensity': {'defined_symbol': 'a_u_intensity',\n", + " 'value': '0.5 * ε_0 * c * atomic_unit_of_electric_field ** 2'},\n", + " 'biot': {'defined_symbol': 'Bi', 'value': '10 * ampere'},\n", + " 'abampere': {'defined_symbol': 'abA', 'value': 'biot'},\n", + " 'atomic_unit_of_current': {'defined_symbol': 'a_u_current',\n", + " 'value': 'e / atomic_unit_of_time'},\n", + " 'mean_international_ampere': {'defined_symbol': 'A_it',\n", + " 'value': 'mean_international_volt / mean_international_ohm'},\n", + " 'US_international_ampere': {'defined_symbol': 'A_US',\n", + " 'value': 'US_international_volt / US_international_ohm'},\n", + " 'conventional_ampere_90': {'defined_symbol': 'A_90',\n", + " 'value': 'K_J90 * R_K90 / (K_J * R_K) * ampere'},\n", + " 'planck_current': {'value': '(c ** 6 / gravitational_constant / k_C) ** 0.5'},\n", + " 'coulomb': {'defined_symbol': 'C', 'value': 'ampere * second'},\n", + " 'abcoulomb': {'defined_symbol': 'abC', 'value': '10 * C'},\n", + " 'faraday': {'value': 'e * N_A * mole'},\n", + " 'conventional_coulomb_90': {'defined_symbol': 'C_90',\n", + " 'value': 'K_J90 * R_K90 / (K_J * R_K) * coulomb'},\n", + " 'ampere_hour': {'defined_symbol': 'Ah', 'value': 'ampere * hour'},\n", + " 'volt': {'defined_symbol': 'V', 'value': 'joule / coulomb'},\n", + " 'abvolt': {'defined_symbol': 'abV', 'value': '1e-8 * volt'},\n", + " 'mean_international_volt': {'defined_symbol': 'V_it',\n", + " 'value': '1.00034 * volt'},\n", + " 'US_international_volt': {'defined_symbol': 'V_US',\n", + " 'value': '1.00033 * volt'},\n", + " 'conventional_volt_90': {'defined_symbol': 'V_90',\n", + " 'value': 'K_J90 / K_J * volt'},\n", + " 'atomic_unit_of_electric_field': {'defined_symbol': 'a_u_electric_field',\n", + " 'value': 'e * k_C / a_0 ** 2'},\n", + " 'townsend': {'defined_symbol': 'Td', 'value': '1e-21 * V * m^2'},\n", + " 'ohm': {'defined_symbol': 'Ω', 'value': 'volt / ampere'},\n", + " 'abohm': {'defined_symbol': 'abΩ', 'value': '1e-9 * ohm'},\n", + " 'mean_international_ohm': {'defined_symbol': 'Ω_it',\n", + " 'aliases': ['ohm_it'],\n", + " 'value': '1.00049 * ohm'},\n", + " 'US_international_ohm': {'defined_symbol': 'Ω_US',\n", + " 'aliases': ['ohm_US'],\n", + " 'value': '1.000495 * ohm'},\n", + " 'conventional_ohm_90': {'defined_symbol': 'Ω_90',\n", + " 'aliases': ['ohm_90'],\n", + " 'value': 'R_K / R_K90 * ohm'},\n", + " 'siemens': {'defined_symbol': 'S',\n", + " 'aliases': ['mho'],\n", + " 'value': 'ampere / volt'},\n", + " 'absiemens': {'defined_symbol': 'abS',\n", + " 'aliases': ['abmho'],\n", + " 'value': '1e9 * siemens'},\n", + " 'farad': {'defined_symbol': 'F', 'value': 'coulomb / volt'},\n", + " 'abfarad': {'defined_symbol': 'abF', 'value': '1e9 * farad'},\n", + " 'conventional_farad_90': {'defined_symbol': 'F_90',\n", + " 'value': 'R_K90 / R_K * farad'},\n", + " 'weber': {'defined_symbol': 'Wb', 'value': 'volt * second'},\n", + " 'unit_pole': {'value': 'µ_0 * biot * centimeter'},\n", + " 'henry': {'defined_symbol': 'H', 'value': 'weber / ampere'},\n", + " 'abhenry': {'defined_symbol': 'abH', 'value': '1e-9 * henry'},\n", + " 'conventional_henry_90': {'defined_symbol': 'H_90',\n", + " 'value': 'R_K / R_K90 * henry'},\n", + " 'tesla': {'defined_symbol': 'T', 'value': 'weber / meter ** 2'},\n", + " 'gamma': {'defined_symbol': 'γ', 'value': '1e-9 * tesla'},\n", + " 'ampere_turn': {'defined_symbol': 'At', 'value': 'ampere'},\n", + " 'biot_turn': {'value': 'biot'},\n", + " 'gilbert': {'defined_symbol': 'Gb', 'value': '1 / (4 * π) * biot_turn'},\n", + " 'debye': {'defined_symbol': 'D', 'value': '1e-9 / ζ * coulomb * angstrom'},\n", + " 'buckingham': {'value': 'debye * angstrom'},\n", + " 'bohr_magneton': {'defined_symbol': 'µ_B',\n", + " 'aliases': ['mu_B'],\n", + " 'value': 'e * hbar / (2 * m_e)'},\n", + " 'nuclear_magneton': {'defined_symbol': 'µ_N',\n", + " 'aliases': ['mu_N'],\n", + " 'value': 'e * hbar / (2 * m_p)'},\n", + " 'refractive_index_unit': {'defined_symbol': 'RIU', 'value': '[]'},\n", + " 'decibelwatt': {'defined_symbol': 'dBW',\n", + " 'value': 'watt; logbase: 10; logfactor: 10'},\n", + " 'decibelmilliwatt': {'defined_symbol': 'dBm',\n", + " 'value': '1e-3 watt; logbase: 10; logfactor: 10'},\n", + " 'decibelmicrowatt': {'defined_symbol': 'dBu',\n", + " 'value': '1e-6 watt; logbase: 10; logfactor: 10'},\n", + " 'decibel': {'defined_symbol': 'dB',\n", + " 'value': '1 ; logbase: 10; logfactor: 10'},\n", + " 'decade': {'value': '1 ; logbase: 10; logfactor: 1'},\n", + " 'octave': {'defined_symbol': 'oct', 'value': '1 ; logbase: 2; logfactor: 1'},\n", + " 'neper': {'defined_symbol': 'Np',\n", + " 'value': '1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfactor: 0.5'},\n", + " 'thou': {'defined_symbol': 'th',\n", + " 'aliases': ['mil_length'],\n", + " 'value': '1e-3 * inch'},\n", + " 'inch': {'defined_symbol': 'in',\n", + " 'aliases': ['international_inch', 'inches', 'international_inches'],\n", + " 'value': 'yard / 36'},\n", + " 'hand': {'value': '4 * inch'},\n", + " 'foot': {'defined_symbol': 'ft',\n", + " 'aliases': ['international_foot', 'feet', 'international_feet'],\n", + " 'value': 'yard / 3'},\n", + " 'yard': {'defined_symbol': 'yd',\n", + " 'aliases': ['international_yard'],\n", + " 'value': '0.9144 * meter'},\n", + " 'mile': {'defined_symbol': 'mi',\n", + " 'aliases': ['international_mile'],\n", + " 'value': '1760 * yard'},\n", + " 'circular_mil': {'defined_symbol': 'cmil',\n", + " 'value': 'π / 4 * mil_length ** 2'},\n", + " 'square_inch': {'defined_symbol': 'sq_in',\n", + " 'aliases': ['square_inches'],\n", + " 'value': 'inch ** 2'},\n", + " 'square_foot': {'defined_symbol': 'sq_ft',\n", + " 'aliases': ['square_feet'],\n", + " 'value': 'foot ** 2'},\n", + " 'square_yard': {'defined_symbol': 'sq_yd', 'value': 'yard ** 2'},\n", + " 'square_mile': {'defined_symbol': 'sq_mi', 'value': 'mile ** 2'},\n", + " 'cubic_inch': {'defined_symbol': 'cu_in', 'value': 'in ** 3'},\n", + " 'cubic_foot': {'defined_symbol': 'cu_ft',\n", + " 'aliases': ['cubic_feet'],\n", + " 'value': 'ft ** 3'},\n", + " 'cubic_yard': {'defined_symbol': 'cu_yd', 'value': 'yd ** 3'},\n", + " 'link': {'defined_symbol': 'li',\n", + " 'aliases': ['survey_link'],\n", + " 'value': '1e-2 * chain'},\n", + " 'survey_foot': {'defined_symbol': 'sft', 'value': '1200 / 3937 * meter'},\n", + " 'fathom': {'value': '6 * survey_foot'},\n", + " 'rod': {'defined_symbol': 'rd',\n", + " 'aliases': ['pole', 'perch'],\n", + " 'value': '16.5 * survey_foot'},\n", + " 'chain': {'value': '4 * rod'},\n", + " 'furlong': {'defined_symbol': 'fur', 'value': '40 * rod'},\n", + " 'cables_length': {'value': '120 * fathom'},\n", + " 'survey_mile': {'defined_symbol': 'smi',\n", + " 'aliases': ['us_statute_mile'],\n", + " 'value': '5280 * survey_foot'},\n", + " 'league': {'value': '3 * survey_mile'},\n", + " 'square_rod': {'defined_symbol': 'sq_rod',\n", + " 'aliases': ['sq_pole', 'sq_perch'],\n", + " 'value': 'rod ** 2'},\n", + " 'acre': {'value': '10 * chain ** 2'},\n", + " 'square_survey_mile': {'aliases': ['section'], 'value': 'survey_mile ** 2'},\n", + " 'square_league': {'value': 'league ** 2'},\n", + " 'acre_foot': {'aliases': ['acre_feet'], 'value': 'acre * survey_foot'},\n", + " 'dry_pint': {'defined_symbol': 'dpi',\n", + " 'aliases': ['US_dry_pint'],\n", + " 'value': 'bushel / 64'},\n", + " 'dry_quart': {'defined_symbol': 'dqt',\n", + " 'aliases': ['US_dry_quart'],\n", + " 'value': 'bushel / 32'},\n", + " 'dry_gallon': {'defined_symbol': 'dgal',\n", + " 'aliases': ['US_dry_gallon'],\n", + " 'value': 'bushel / 8'},\n", + " 'peck': {'defined_symbol': 'pk', 'value': 'bushel / 4'},\n", + " 'bushel': {'defined_symbol': 'bu', 'value': '2150.42 cubic_inch'},\n", + " 'dry_barrel': {'aliases': ['US_dry_barrel'], 'value': '7056 cubic_inch'},\n", + " 'board_foot': {'defined_symbol': 'FBM',\n", + " 'aliases': ['board_feet',\n", + " 'BF',\n", + " 'BDFT',\n", + " 'super_foot',\n", + " 'superficial_foot',\n", + " 'super_feet',\n", + " 'superficial_feet'],\n", + " 'value': 'ft * ft * in'},\n", + " 'minim': {'value': 'pint / 7680'},\n", + " 'fluid_dram': {'defined_symbol': 'fldr',\n", + " 'aliases': ['fluidram', 'US_fluid_dram', 'US_liquid_dram'],\n", + " 'value': 'pint / 128'},\n", + " 'fluid_ounce': {'defined_symbol': 'floz',\n", + " 'aliases': ['US_fluid_ounce', 'US_liquid_ounce'],\n", + " 'value': 'pint / 16'},\n", + " 'gill': {'defined_symbol': 'gi',\n", + " 'aliases': ['liquid_gill', 'US_liquid_gill'],\n", + " 'value': 'pint / 4'},\n", + " 'pint': {'defined_symbol': 'pt',\n", + " 'aliases': ['liquid_pint', 'US_pint'],\n", + " 'value': 'quart / 2'},\n", + " 'fifth': {'aliases': ['US_liquid_fifth'], 'value': 'gallon / 5'},\n", + " 'quart': {'defined_symbol': 'qt',\n", + " 'aliases': ['liquid_quart', 'US_liquid_quart'],\n", + " 'value': 'gallon / 4'},\n", + " 'gallon': {'defined_symbol': 'gal',\n", + " 'aliases': ['liquid_gallon', 'US_liquid_gallon'],\n", + " 'value': '231 * cubic_inch'},\n", + " 'teaspoon': {'defined_symbol': 'tsp', 'value': 'fluid_ounce / 6'},\n", + " 'tablespoon': {'defined_symbol': 'tbsp', 'value': 'fluid_ounce / 2'},\n", + " 'shot': {'defined_symbol': 'jig',\n", + " 'aliases': ['US_shot'],\n", + " 'value': '3 * tablespoon'},\n", + " 'cup': {'defined_symbol': 'cp',\n", + " 'aliases': ['liquid_cup', 'US_liquid_cup'],\n", + " 'value': 'pint / 2'},\n", + " 'barrel': {'defined_symbol': 'bbl', 'value': '31.5 * gallon'},\n", + " 'oil_barrel': {'defined_symbol': 'oil_bbl', 'value': '42 * gallon'},\n", + " 'beer_barrel': {'defined_symbol': 'beer_bbl', 'value': '31 * gallon'},\n", + " 'hogshead': {'value': '63 * gallon'},\n", + " 'dram': {'defined_symbol': 'dr',\n", + " 'aliases': ['avoirdupois_dram', 'avdp_dram', 'drachm'],\n", + " 'value': 'pound / 256'},\n", + " 'ounce': {'defined_symbol': 'oz',\n", + " 'aliases': ['avoirdupois_ounce', 'avdp_ounce'],\n", + " 'value': 'pound / 16'},\n", + " 'pound': {'defined_symbol': 'lb',\n", + " 'aliases': ['avoirdupois_pound', 'avdp_pound'],\n", + " 'value': '7e3 * grain'},\n", + " 'stone': {'value': '14 * pound'},\n", + " 'quarter': {'value': '28 * stone'},\n", + " 'bag': {'value': '94 * pound'},\n", + " 'hundredweight': {'defined_symbol': 'cwt',\n", + " 'aliases': ['short_hundredweight'],\n", + " 'value': '100 * pound'},\n", + " 'long_hundredweight': {'value': '112 * pound'},\n", + " 'ton': {'aliases': ['short_ton'], 'value': '2e3 * pound'},\n", + " 'long_ton': {'value': '2240 * pound'},\n", + " 'slug': {'value': 'g_0 * pound * second ** 2 / foot'},\n", + " 'slinch': {'defined_symbol': 'blob',\n", + " 'aliases': ['slugette'],\n", + " 'value': 'g_0 * pound * second ** 2 / inch'},\n", + " 'force_ounce': {'defined_symbol': 'ozf',\n", + " 'aliases': ['ounce_force'],\n", + " 'value': 'g_0 * ounce'},\n", + " 'force_pound': {'defined_symbol': 'lbf',\n", + " 'aliases': ['pound_force'],\n", + " 'value': 'g_0 * pound'},\n", + " 'force_ton': {'aliases': ['ton_force', 'force_short_ton', 'short_ton_force'],\n", + " 'value': 'g_0 * ton'},\n", + " 'force_long_ton': {'aliases': ['long_ton_force'], 'value': 'g_0 * long_ton'},\n", + " 'kip': {'value': '1e3 * force_pound'},\n", + " 'poundal': {'defined_symbol': 'pdl', 'value': 'pound * foot / second ** 2'},\n", + " 'UK_hundredweight': {'defined_symbol': 'UK_cwt',\n", + " 'value': 'long_hundredweight'},\n", + " 'UK_ton': {'value': 'long_ton'},\n", + " 'UK_force_ton': {'aliases': ['UK_ton_force'], 'value': 'force_long_ton'},\n", + " 'US_hundredweight': {'defined_symbol': 'US_cwt', 'value': 'hundredweight'},\n", + " 'US_ton': {'value': 'ton'},\n", + " 'US_force_ton': {'aliases': ['US_ton_force'], 'value': 'force_ton'},\n", + " 'pennyweight': {'defined_symbol': 'dwt', 'value': '24 * grain'},\n", + " 'troy_ounce': {'defined_symbol': 'toz',\n", + " 'aliases': ['ozt'],\n", + " 'value': '480 * grain'},\n", + " 'troy_pound': {'defined_symbol': 'tlb',\n", + " 'aliases': ['lbt'],\n", + " 'value': '12 * troy_ounce'},\n", + " 'scruple': {'value': '20 * grain'},\n", + " 'apothecary_dram': {'defined_symbol': 'ap_dr', 'value': '3 * scruple'},\n", + " 'apothecary_ounce': {'defined_symbol': 'ap_oz',\n", + " 'value': '8 * apothecary_dram'},\n", + " 'apothecary_pound': {'defined_symbol': 'ap_lb',\n", + " 'value': '12 * apothecary_ounce'},\n", + " 'imperial_minim': {'value': 'imperial_fluid_ounce / 480'},\n", + " 'imperial_fluid_scruple': {'value': 'imperial_fluid_ounce / 24'},\n", + " 'imperial_fluid_drachm': {'defined_symbol': 'imperial_fldr',\n", + " 'aliases': ['imperial_fluid_dram'],\n", + " 'value': 'imperial_fluid_ounce / 8'},\n", + " 'imperial_fluid_ounce': {'defined_symbol': 'imperial_floz',\n", + " 'aliases': ['UK_fluid_ounce'],\n", + " 'value': 'imperial_pint / 20'},\n", + " 'imperial_gill': {'defined_symbol': 'imperial_gi',\n", + " 'aliases': ['UK_gill'],\n", + " 'value': 'imperial_pint / 4'},\n", + " 'imperial_cup': {'defined_symbol': 'imperial_cp',\n", + " 'aliases': ['UK_cup'],\n", + " 'value': 'imperial_pint / 2'},\n", + " 'imperial_pint': {'defined_symbol': 'imperial_pt',\n", + " 'aliases': ['UK_pint'],\n", + " 'value': 'imperial_gallon / 8'},\n", + " 'imperial_quart': {'defined_symbol': 'imperial_qt',\n", + " 'aliases': ['UK_quart'],\n", + " 'value': 'imperial_gallon / 4'},\n", + " 'imperial_gallon': {'defined_symbol': 'imperial_gal',\n", + " 'aliases': ['UK_gallon'],\n", + " 'value': '4.54609 * liter'},\n", + " 'imperial_peck': {'defined_symbol': 'imperial_pk',\n", + " 'aliases': ['UK_pk'],\n", + " 'value': '2 * imperial_gallon'},\n", + " 'imperial_bushel': {'defined_symbol': 'imperial_bu',\n", + " 'aliases': ['UK_bushel'],\n", + " 'value': '8 * imperial_gallon'},\n", + " 'imperial_barrel': {'defined_symbol': 'imperial_bbl',\n", + " 'aliases': ['UK_bbl'],\n", + " 'value': '36 * imperial_gallon'},\n", + " 'pica': {'aliases': ['printers_pica'], 'value': 'inch / 6'},\n", + " 'point': {'defined_symbol': 'pp',\n", + " 'aliases': ['printers_point', 'big_point', 'bp'],\n", + " 'value': 'pica / 12'},\n", + " 'didot': {'value': '1 / 2660 * m'},\n", + " 'cicero': {'value': '12 * didot'},\n", + " 'tex_point': {'value': 'inch / 72.27'},\n", + " 'tex_pica': {'value': '12 * tex_point'},\n", + " 'tex_didot': {'value': '1238 / 1157 * tex_point'},\n", + " 'tex_cicero': {'value': '12 * tex_didot'},\n", + " 'scaled_point': {'value': 'tex_point / 65536'},\n", + " 'css_pixel': {'defined_symbol': 'px', 'value': 'inch / 96'},\n", + " 'pixel': {'aliases': ['dot', 'pel', 'picture_element'],\n", + " 'value': '[printing_unit]'},\n", + " 'pixels_per_centimeter': {'defined_symbol': 'PPCM', 'value': 'pixel / cm'},\n", + " 'pixels_per_inch': {'defined_symbol': 'dots_per_inch',\n", + " 'aliases': ['PPI', 'ppi', 'DPI', 'printers_dpi'],\n", + " 'value': 'pixel / inch'},\n", + " 'bits_per_pixel': {'defined_symbol': 'bpp', 'value': 'bit / pixel'},\n", + " 'tex': {'defined_symbol': 'Tt', 'value': 'gram / kilometer'},\n", + " 'dtex': {'value': 'decitex'},\n", + " 'denier': {'defined_symbol': 'den', 'value': 'gram / (9 * kilometer)'},\n", + " 'jute': {'defined_symbol': 'Tj', 'value': 'pound / (14400 * yard)'},\n", + " 'aberdeen': {'defined_symbol': 'Ta', 'value': 'jute'},\n", + " 'RKM': {'value': 'gf / tex'},\n", + " 'number_english': {'defined_symbol': 'Ne',\n", + " 'aliases': ['NeC', 'ECC'],\n", + " 'value': '840 * yard / pound'},\n", + " 'number_meter': {'defined_symbol': 'Nm', 'value': 'kilometer / kilogram'},\n", + " 'franklin': {'defined_symbol': 'Fr',\n", + " 'aliases': ['statcoulomb', 'statC', 'esu'],\n", + " 'value': 'erg ** 0.5 * centimeter ** 0.5'},\n", + " 'statvolt': {'defined_symbol': 'statV', 'value': 'erg / franklin'},\n", + " 'statampere': {'defined_symbol': 'statA', 'value': 'franklin / second'},\n", + " 'gauss': {'defined_symbol': 'G', 'value': 'dyne / franklin'},\n", + " 'maxwell': {'defined_symbol': 'Mx', 'value': 'gauss * centimeter ** 2'},\n", + " 'oersted': {'defined_symbol': 'Oe',\n", + " 'aliases': ['ørsted'],\n", + " 'value': 'dyne / maxwell'},\n", + " 'statohm': {'defined_symbol': 'statΩ', 'value': 'statvolt / statampere'},\n", + " 'statfarad': {'defined_symbol': 'statF', 'value': 'franklin / statvolt'},\n", + " 'statmho': {'value': 'statampere / statvolt'},\n", + " 'statweber': {'defined_symbol': 'statWb', 'value': 'statvolt * second'},\n", + " 'stattesla': {'defined_symbol': 'statT',\n", + " 'value': 'statweber / centimeter ** 2'},\n", + " 'stathenry': {'defined_symbol': 'statH', 'value': 'statweber / statampere'}},\n", + " 'dimension': {'[area]': {'value': '[length] ** 2'},\n", + " '[volume]': {'value': '[length] ** 3'},\n", + " '[frequency]': {'value': '1 / [time]'},\n", + " '[wavenumber]': {'value': '1 / [length]'},\n", + " '[velocity]': {'value': '[length] / [time]'},\n", + " '[speed]': {'value': '[velocity]'},\n", + " '[volumetric_flow_rate]': {'value': '[volume] / [time]'},\n", + " '[acceleration]': {'value': '[velocity] / [time]'},\n", + " '[force]': {'value': '[mass] * [acceleration]'},\n", + " '[energy]': {'value': '[force] * [length]'},\n", + " '[power]': {'value': '[energy] / [time]'},\n", + " '[momentum]': {'value': '[length] * [mass] / [time]'},\n", + " '[density]': {'value': '[mass] / [volume]'},\n", + " '[pressure]': {'value': '[force] / [area]'},\n", + " '[torque]': {'value': '[force] * [length]'},\n", + " '[viscosity]': {'value': '[pressure] * [time]'},\n", + " '[kinematic_viscosity]': {'value': '[area] / [time]'},\n", + " '[fluidity]': {'value': '1 / [viscosity]'},\n", + " '[concentration]': {'value': '[substance] / [volume]'},\n", + " '[activity]': {'value': '[substance] / [time]'},\n", + " '[entropy]': {'value': '[energy] / [temperature]'},\n", + " '[molar_entropy]': {'value': '[entropy] / [substance]'},\n", + " '[heat_transmission]': {'value': '[energy] / [area]'},\n", + " '[luminance]': {'value': '[luminosity] / [area]'},\n", + " '[luminous_flux]': {'value': '[luminosity]'},\n", + " '[illuminance]': {'value': '[luminous_flux] / [area]'},\n", + " '[intensity]': {'value': '[power] / [area]'},\n", + " '[charge]': {'value': '[current] * [time]'},\n", + " '[electric_potential]': {'value': '[energy] / [charge]'},\n", + " '[electric_field]': {'value': '[electric_potential] / [length]'},\n", + " '[electric_displacement_field]': {'value': '[charge] / [area]'},\n", + " '[reduced_electric_field]': {'value': '[electric_field] * [area]'},\n", + " '[resistance]': {'value': '[electric_potential] / [current]'},\n", + " '[resistivity]': {'value': '[resistance] * [length]'},\n", + " '[conductance]': {'value': '[current] / [electric_potential]'},\n", + " '[capacitance]': {'value': '[charge] / [electric_potential]'},\n", + " '[magnetic_flux]': {'value': '[electric_potential] * [time]'},\n", + " '[inductance]': {'value': '[magnetic_flux] / [current]'},\n", + " '[magnetic_field]': {'value': '[magnetic_flux] / [area]'},\n", + " '[magnetomotive_force]': {'value': '[current]'},\n", + " '[magnetic_field_strength]': {'value': '[current] / [length]'},\n", + " '[electric_dipole]': {'value': '[charge] * [length]'},\n", + " '[electric_quadrupole]': {'value': '[charge] * [area]'},\n", + " '[magnetic_dipole]': {'value': '[current] * [area]'},\n", + " '[refractive_index]': {'value': '[]'},\n", + " '[gaussian_charge]': {'value': '[length] ** 1.5 * [mass] ** 0.5 / [time]'},\n", + " '[gaussian_current]': {'value': '[gaussian_charge] / [time]'},\n", + " '[gaussian_electric_potential]': {'value': '[gaussian_charge] / [length]'},\n", + " '[gaussian_electric_field]': {'value': '[gaussian_electric_potential] / [length]'},\n", + " '[gaussian_electric_displacement_field]': {'value': '[gaussian_charge] / [area]'},\n", + " '[gaussian_electric_flux]': {'value': '[gaussian_charge]'},\n", + " '[gaussian_electric_dipole]': {'value': '[gaussian_charge] * [length]'},\n", + " '[gaussian_electric_quadrupole]': {'value': '[gaussian_charge] * [area]'},\n", + " '[gaussian_magnetic_field]': {'value': '[force] / [gaussian_charge]'},\n", + " '[gaussian_magnetic_field_strength]': {'value': '[gaussian_magnetic_field]'},\n", + " '[gaussian_magnetic_flux]': {'value': '[gaussian_magnetic_field] * [area]'},\n", + " '[gaussian_magnetic_dipole]': {'value': '[energy] / [gaussian_magnetic_field]'},\n", + " '[gaussian_resistance]': {'value': '[gaussian_electric_potential] / [gaussian_current]'},\n", + " '[gaussian_resistivity]': {'value': '[gaussian_resistance] * [length]'},\n", + " '[gaussian_capacitance]': {'value': '[gaussian_charge] / [gaussian_electric_potential]'},\n", + " '[gaussian_inductance]': {'value': '[gaussian_electric_potential] * [time] / [gaussian_current]'},\n", + " '[gaussian_conductance]': {'value': '[gaussian_current] / [gaussian_electric_potential]'},\n", + " '[esu_charge]': {'value': '[length] ** 1.5 * [mass] ** 0.5 / [time]'},\n", + " '[esu_current]': {'value': '[esu_charge] / [time]'},\n", + " '[esu_electric_potential]': {'value': '[esu_charge] / [length]'},\n", + " '[esu_magnetic_flux]': {'value': '[esu_electric_potential] * [time]'},\n", + " '[esu_magnetic_field]': {'value': '[esu_magnetic_flux] / [area]'},\n", + " '[esu_magnetic_field_strength]': {'value': '[esu_current] / [length]'},\n", + " '[esu_magnetic_dipole]': {'value': '[esu_current] * [area]'}},\n", + " 'group': {'USCSLengthInternational': {'definitions': {'thou': {'defined_symbol': 'th',\n", + " 'aliases': ['mil_length'],\n", + " 'value': '1e-3 * inch'},\n", + " 'inch': {'defined_symbol': 'in',\n", + " 'aliases': ['international_inch', 'inches', 'international_inches'],\n", + " 'value': 'yard / 36'},\n", + " 'hand': {'value': '4 * inch'},\n", + " 'foot': {'defined_symbol': 'ft',\n", + " 'aliases': ['international_foot', 'feet', 'international_feet'],\n", + " 'value': 'yard / 3'},\n", + " 'yard': {'defined_symbol': 'yd',\n", + " 'aliases': ['international_yard'],\n", + " 'value': '0.9144 * meter'},\n", + " 'mile': {'defined_symbol': 'mi',\n", + " 'aliases': ['international_mile'],\n", + " 'value': '1760 * yard'},\n", + " 'circular_mil': {'defined_symbol': 'cmil',\n", + " 'value': 'π / 4 * mil_length ** 2'},\n", + " 'square_inch': {'defined_symbol': 'sq_in',\n", + " 'aliases': ['square_inches'],\n", + " 'value': 'inch ** 2'},\n", + " 'square_foot': {'defined_symbol': 'sq_ft',\n", + " 'aliases': ['square_feet'],\n", + " 'value': 'foot ** 2'},\n", + " 'square_yard': {'defined_symbol': 'sq_yd', 'value': 'yard ** 2'},\n", + " 'square_mile': {'defined_symbol': 'sq_mi', 'value': 'mile ** 2'},\n", + " 'cubic_inch': {'defined_symbol': 'cu_in', 'value': 'in ** 3'},\n", + " 'cubic_foot': {'defined_symbol': 'cu_ft',\n", + " 'aliases': ['cubic_feet'],\n", + " 'value': 'ft ** 3'},\n", + " 'cubic_yard': {'defined_symbol': 'cu_yd', 'value': 'yd ** 3'}}},\n", + " 'USCSLengthSurvey': {'definitions': {'link': {'defined_symbol': 'li',\n", + " 'aliases': ['survey_link'],\n", + " 'value': '1e-2 * chain'},\n", + " 'survey_foot': {'defined_symbol': 'sft', 'value': '1200 / 3937 * meter'},\n", + " 'fathom': {'value': '6 * survey_foot'},\n", + " 'rod': {'defined_symbol': 'rd',\n", + " 'aliases': ['pole', 'perch'],\n", + " 'value': '16.5 * survey_foot'},\n", + " 'chain': {'value': '4 * rod'},\n", + " 'furlong': {'defined_symbol': 'fur', 'value': '40 * rod'},\n", + " 'cables_length': {'value': '120 * fathom'},\n", + " 'survey_mile': {'defined_symbol': 'smi',\n", + " 'aliases': ['us_statute_mile'],\n", + " 'value': '5280 * survey_foot'},\n", + " 'league': {'value': '3 * survey_mile'},\n", + " 'square_rod': {'defined_symbol': 'sq_rod',\n", + " 'aliases': ['sq_pole', 'sq_perch'],\n", + " 'value': 'rod ** 2'},\n", + " 'acre': {'value': '10 * chain ** 2'},\n", + " 'square_survey_mile': {'aliases': ['section'],\n", + " 'value': 'survey_mile ** 2'},\n", + " 'square_league': {'value': 'league ** 2'},\n", + " 'acre_foot': {'aliases': ['acre_feet'], 'value': 'acre * survey_foot'}}},\n", + " 'USCSDryVolume': {'definitions': {'dry_pint': {'defined_symbol': 'dpi',\n", + " 'aliases': ['US_dry_pint'],\n", + " 'value': 'bushel / 64'},\n", + " 'dry_quart': {'defined_symbol': 'dqt',\n", + " 'aliases': ['US_dry_quart'],\n", + " 'value': 'bushel / 32'},\n", + " 'dry_gallon': {'defined_symbol': 'dgal',\n", + " 'aliases': ['US_dry_gallon'],\n", + " 'value': 'bushel / 8'},\n", + " 'peck': {'defined_symbol': 'pk', 'value': 'bushel / 4'},\n", + " 'bushel': {'defined_symbol': 'bu', 'value': '2150.42 cubic_inch'},\n", + " 'dry_barrel': {'aliases': ['US_dry_barrel'], 'value': '7056 cubic_inch'},\n", + " 'board_foot': {'defined_symbol': 'FBM',\n", + " 'aliases': ['board_feet',\n", + " 'BF',\n", + " 'BDFT',\n", + " 'super_foot',\n", + " 'superficial_foot',\n", + " 'super_feet',\n", + " 'superficial_feet'],\n", + " 'value': 'ft * ft * in'}}},\n", + " 'USCSLiquidVolume': {'definitions': {'minim': {'value': 'pint / 7680'},\n", + " 'fluid_dram': {'defined_symbol': 'fldr',\n", + " 'aliases': ['fluidram', 'US_fluid_dram', 'US_liquid_dram'],\n", + " 'value': 'pint / 128'},\n", + " 'fluid_ounce': {'defined_symbol': 'floz',\n", + " 'aliases': ['US_fluid_ounce', 'US_liquid_ounce'],\n", + " 'value': 'pint / 16'},\n", + " 'gill': {'defined_symbol': 'gi',\n", + " 'aliases': ['liquid_gill', 'US_liquid_gill'],\n", + " 'value': 'pint / 4'},\n", + " 'pint': {'defined_symbol': 'pt',\n", + " 'aliases': ['liquid_pint', 'US_pint'],\n", + " 'value': 'quart / 2'},\n", + " 'fifth': {'aliases': ['US_liquid_fifth'], 'value': 'gallon / 5'},\n", + " 'quart': {'defined_symbol': 'qt',\n", + " 'aliases': ['liquid_quart', 'US_liquid_quart'],\n", + " 'value': 'gallon / 4'},\n", + " 'gallon': {'defined_symbol': 'gal',\n", + " 'aliases': ['liquid_gallon', 'US_liquid_gallon'],\n", + " 'value': '231 * cubic_inch'}}},\n", + " 'USCSVolumeOther': {'definitions': {'teaspoon': {'defined_symbol': 'tsp',\n", + " 'value': 'fluid_ounce / 6'},\n", + " 'tablespoon': {'defined_symbol': 'tbsp', 'value': 'fluid_ounce / 2'},\n", + " 'shot': {'defined_symbol': 'jig',\n", + " 'aliases': ['US_shot'],\n", + " 'value': '3 * tablespoon'},\n", + " 'cup': {'defined_symbol': 'cp',\n", + " 'aliases': ['liquid_cup', 'US_liquid_cup'],\n", + " 'value': 'pint / 2'},\n", + " 'barrel': {'defined_symbol': 'bbl', 'value': '31.5 * gallon'},\n", + " 'oil_barrel': {'defined_symbol': 'oil_bbl', 'value': '42 * gallon'},\n", + " 'beer_barrel': {'defined_symbol': 'beer_bbl', 'value': '31 * gallon'},\n", + " 'hogshead': {'value': '63 * gallon'}}},\n", + " 'Avoirdupois': {'definitions': {'dram': {'defined_symbol': 'dr',\n", + " 'aliases': ['avoirdupois_dram', 'avdp_dram', 'drachm'],\n", + " 'value': 'pound / 256'},\n", + " 'ounce': {'defined_symbol': 'oz',\n", + " 'aliases': ['avoirdupois_ounce', 'avdp_ounce'],\n", + " 'value': 'pound / 16'},\n", + " 'pound': {'defined_symbol': 'lb',\n", + " 'aliases': ['avoirdupois_pound', 'avdp_pound'],\n", + " 'value': '7e3 * grain'},\n", + " 'stone': {'value': '14 * pound'},\n", + " 'quarter': {'value': '28 * stone'},\n", + " 'bag': {'value': '94 * pound'},\n", + " 'hundredweight': {'defined_symbol': 'cwt',\n", + " 'aliases': ['short_hundredweight'],\n", + " 'value': '100 * pound'},\n", + " 'long_hundredweight': {'value': '112 * pound'},\n", + " 'ton': {'aliases': ['short_ton'], 'value': '2e3 * pound'},\n", + " 'long_ton': {'value': '2240 * pound'},\n", + " 'slug': {'value': 'g_0 * pound * second ** 2 / foot'},\n", + " 'slinch': {'defined_symbol': 'blob',\n", + " 'aliases': ['slugette'],\n", + " 'value': 'g_0 * pound * second ** 2 / inch'},\n", + " 'force_ounce': {'defined_symbol': 'ozf',\n", + " 'aliases': ['ounce_force'],\n", + " 'value': 'g_0 * ounce'},\n", + " 'force_pound': {'defined_symbol': 'lbf',\n", + " 'aliases': ['pound_force'],\n", + " 'value': 'g_0 * pound'},\n", + " 'force_ton': {'aliases': ['ton_force',\n", + " 'force_short_ton',\n", + " 'short_ton_force'],\n", + " 'value': 'g_0 * ton'},\n", + " 'force_long_ton': {'aliases': ['long_ton_force'],\n", + " 'value': 'g_0 * long_ton'},\n", + " 'kip': {'value': '1e3 * force_pound'},\n", + " 'poundal': {'defined_symbol': 'pdl',\n", + " 'value': 'pound * foot / second ** 2'}}},\n", + " 'AvoirdupoisUK': {'using_group_names': ['Avoirdupois'],\n", + " 'definitions': {'UK_hundredweight': {'defined_symbol': 'UK_cwt',\n", + " 'value': 'long_hundredweight'},\n", + " 'UK_ton': {'value': 'long_ton'},\n", + " 'UK_force_ton': {'aliases': ['UK_ton_force'], 'value': 'force_long_ton'}}},\n", + " 'AvoirdupoisUS': {'using_group_names': ['Avoirdupois'],\n", + " 'definitions': {'US_hundredweight': {'defined_symbol': 'US_cwt',\n", + " 'value': 'hundredweight'},\n", + " 'US_ton': {'value': 'ton'},\n", + " 'US_force_ton': {'aliases': ['US_ton_force'], 'value': 'force_ton'}}},\n", + " 'Troy': {'definitions': {'pennyweight': {'defined_symbol': 'dwt',\n", + " 'value': '24 * grain'},\n", + " 'troy_ounce': {'defined_symbol': 'toz',\n", + " 'aliases': ['ozt'],\n", + " 'value': '480 * grain'},\n", + " 'troy_pound': {'defined_symbol': 'tlb',\n", + " 'aliases': ['lbt'],\n", + " 'value': '12 * troy_ounce'}}},\n", + " 'Apothecary': {'definitions': {'scruple': {'value': '20 * grain'},\n", + " 'apothecary_dram': {'defined_symbol': 'ap_dr', 'value': '3 * scruple'},\n", + " 'apothecary_ounce': {'defined_symbol': 'ap_oz',\n", + " 'value': '8 * apothecary_dram'},\n", + " 'apothecary_pound': {'defined_symbol': 'ap_lb',\n", + " 'value': '12 * apothecary_ounce'}}},\n", + " 'ImperialVolume': {'definitions': {'imperial_minim': {'value': 'imperial_fluid_ounce / 480'},\n", + " 'imperial_fluid_scruple': {'value': 'imperial_fluid_ounce / 24'},\n", + " 'imperial_fluid_drachm': {'defined_symbol': 'imperial_fldr',\n", + " 'aliases': ['imperial_fluid_dram'],\n", + " 'value': 'imperial_fluid_ounce / 8'},\n", + " 'imperial_fluid_ounce': {'defined_symbol': 'imperial_floz',\n", + " 'aliases': ['UK_fluid_ounce'],\n", + " 'value': 'imperial_pint / 20'},\n", + " 'imperial_gill': {'defined_symbol': 'imperial_gi',\n", + " 'aliases': ['UK_gill'],\n", + " 'value': 'imperial_pint / 4'},\n", + " 'imperial_cup': {'defined_symbol': 'imperial_cp',\n", + " 'aliases': ['UK_cup'],\n", + " 'value': 'imperial_pint / 2'},\n", + " 'imperial_pint': {'defined_symbol': 'imperial_pt',\n", + " 'aliases': ['UK_pint'],\n", + " 'value': 'imperial_gallon / 8'},\n", + " 'imperial_quart': {'defined_symbol': 'imperial_qt',\n", + " 'aliases': ['UK_quart'],\n", + " 'value': 'imperial_gallon / 4'},\n", + " 'imperial_gallon': {'defined_symbol': 'imperial_gal',\n", + " 'aliases': ['UK_gallon'],\n", + " 'value': '4.54609 * liter'},\n", + " 'imperial_peck': {'defined_symbol': 'imperial_pk',\n", + " 'aliases': ['UK_pk'],\n", + " 'value': '2 * imperial_gallon'},\n", + " 'imperial_bushel': {'defined_symbol': 'imperial_bu',\n", + " 'aliases': ['UK_bushel'],\n", + " 'value': '8 * imperial_gallon'},\n", + " 'imperial_barrel': {'defined_symbol': 'imperial_bbl',\n", + " 'aliases': ['UK_bbl'],\n", + " 'value': '36 * imperial_gallon'}}},\n", + " 'Printer': {'definitions': {'pica': {'aliases': ['printers_pica'],\n", + " 'value': 'inch / 6'},\n", + " 'point': {'defined_symbol': 'pp',\n", + " 'aliases': ['printers_point', 'big_point', 'bp'],\n", + " 'value': 'pica / 12'},\n", + " 'didot': {'value': '1 / 2660 * m'},\n", + " 'cicero': {'value': '12 * didot'},\n", + " 'tex_point': {'value': 'inch / 72.27'},\n", + " 'tex_pica': {'value': '12 * tex_point'},\n", + " 'tex_didot': {'value': '1238 / 1157 * tex_point'},\n", + " 'tex_cicero': {'value': '12 * tex_didot'},\n", + " 'scaled_point': {'value': 'tex_point / 65536'},\n", + " 'css_pixel': {'defined_symbol': 'px', 'value': 'inch / 96'},\n", + " 'pixel': {'aliases': ['dot', 'pel', 'picture_element'],\n", + " 'value': '[printing_unit]'},\n", + " 'pixels_per_centimeter': {'defined_symbol': 'PPCM', 'value': 'pixel / cm'},\n", + " 'pixels_per_inch': {'defined_symbol': 'dots_per_inch',\n", + " 'aliases': ['PPI', 'ppi', 'DPI', 'printers_dpi'],\n", + " 'value': 'pixel / inch'},\n", + " 'bits_per_pixel': {'defined_symbol': 'bpp', 'value': 'bit / pixel'}}},\n", + " 'Textile': {'definitions': {'tex': {'defined_symbol': 'Tt',\n", + " 'value': 'gram / kilometer'},\n", + " 'dtex': {'value': 'decitex'},\n", + " 'denier': {'defined_symbol': 'den', 'value': 'gram / (9 * kilometer)'},\n", + " 'jute': {'defined_symbol': 'Tj', 'value': 'pound / (14400 * yard)'},\n", + " 'aberdeen': {'defined_symbol': 'Ta', 'value': 'jute'},\n", + " 'RKM': {'value': 'gf / tex'},\n", + " 'number_english': {'defined_symbol': 'Ne',\n", + " 'aliases': ['NeC', 'ECC'],\n", + " 'value': '840 * yard / pound'},\n", + " 'number_meter': {'defined_symbol': 'Nm',\n", + " 'value': 'kilometer / kilogram'}}},\n", + " 'Gaussian': {'definitions': {'franklin': {'defined_symbol': 'Fr',\n", + " 'aliases': ['statcoulomb', 'statC', 'esu'],\n", + " 'value': 'erg ** 0.5 * centimeter ** 0.5'},\n", + " 'statvolt': {'defined_symbol': 'statV', 'value': 'erg / franklin'},\n", + " 'statampere': {'defined_symbol': 'statA', 'value': 'franklin / second'},\n", + " 'gauss': {'defined_symbol': 'G', 'value': 'dyne / franklin'},\n", + " 'maxwell': {'defined_symbol': 'Mx', 'value': 'gauss * centimeter ** 2'},\n", + " 'oersted': {'defined_symbol': 'Oe',\n", + " 'aliases': ['ørsted'],\n", + " 'value': 'dyne / maxwell'},\n", + " 'statohm': {'defined_symbol': 'statΩ', 'value': 'statvolt / statampere'},\n", + " 'statfarad': {'defined_symbol': 'statF', 'value': 'franklin / statvolt'},\n", + " 'statmho': {'value': 'statampere / statvolt'}}},\n", + " 'ESU': {'using_group_names': ['Gaussian'],\n", + " 'definitions': {'statweber': {'defined_symbol': 'statWb',\n", + " 'value': 'statvolt * second'},\n", + " 'stattesla': {'defined_symbol': 'statT',\n", + " 'value': 'statweber / centimeter ** 2'},\n", + " 'stathenry': {'defined_symbol': 'statH',\n", + " 'value': 'statweber / statampere'}}}},\n", + " 'system': {'SI': {'using_group_names': ['root'],\n", + " 'rules': ['second',\n", + " 'meter',\n", + " 'kilogram',\n", + " 'ampere',\n", + " 'kelvin',\n", + " 'mole',\n", + " 'candela']},\n", + " 'mks': {'using_group_names': ['international'],\n", + " 'rules': ['meter', 'kilogram', 'second']},\n", + " 'cgs': {'using_group_names': ['international', 'Gaussian', 'ESU'],\n", + " 'rules': ['centimeter', 'gram', 'second']},\n", + " 'atomic': {'using_group_names': ['international'],\n", + " 'rules': ['bohr: meter',\n", + " 'electron_mass: gram',\n", + " 'atomic_unit_of_time: second',\n", + " 'atomic_unit_of_current: ampere',\n", + " 'atomic_unit_of_temperature: kelvin']},\n", + " 'Planck': {'using_group_names': ['international'],\n", + " 'rules': ['planck_length: meter',\n", + " 'planck_mass: gram',\n", + " 'planck_time: second',\n", + " 'planck_current: ampere',\n", + " 'planck_temperature: kelvin']},\n", + " 'imperial': {'using_group_names': ['ImperialVolume',\n", + " 'USCSLengthInternational',\n", + " 'AvoirdupoisUK'],\n", + " 'rules': ['yard', 'pound']},\n", + " 'US': {'using_group_names': ['USCSLiquidVolume',\n", + " 'USCSDryVolume',\n", + " 'USCSVolumeOther',\n", + " 'USCSLengthInternational',\n", + " 'USCSLengthSurvey',\n", + " 'AvoirdupoisUS'],\n", + " 'rules': ['yard', 'pound']},\n", + " 'Gaussian': {'aliases': ['Gau'],\n", + " 'relations': ['[gaussian_charge] -> [charge]: value / k_C ** 0.5',\n", + " '[charge] -> [gaussian_charge]: value * k_C ** 0.5',\n", + " '[gaussian_current] -> [current]: value / k_C ** 0.5',\n", + " '[current] -> [gaussian_current]: value * k_C ** 0.5',\n", + " '[gaussian_electric_potential] -> [electric_potential]: value * k_C ** 0.5',\n", + " '[electric_potential] -> [gaussian_electric_potential]: value / k_C ** 0.5',\n", + " '[gaussian_electric_field] -> [electric_field]: value * k_C ** 0.5',\n", + " '[electric_field] -> [gaussian_electric_field]: value / k_C ** 0.5',\n", + " '[gaussian_electric_displacement_field] -> [electric_displacement_field]: value / (4 * π / ε_0) ** 0.5',\n", + " '[electric_displacement_field] -> [gaussian_electric_displacement_field]: value * (4 * π / ε_0) ** 0.5',\n", + " '[gaussian_electric_dipole] -> [electric_dipole]: value / k_C ** 0.5',\n", + " '[electric_dipole] -> [gaussian_electric_dipole]: value * k_C ** 0.5',\n", + " '[gaussian_electric_quadrupole] -> [electric_quadrupole]: value / k_C ** 0.5',\n", + " '[electric_quadrupole] -> [gaussian_electric_quadrupole]: value * k_C ** 0.5',\n", + " '[gaussian_magnetic_field] -> [magnetic_field]: value / (4 * π / µ_0) ** 0.5',\n", + " '[magnetic_field] -> [gaussian_magnetic_field]: value * (4 * π / µ_0) ** 0.5',\n", + " '[gaussian_magnetic_flux] -> [magnetic_flux]: value / (4 * π / µ_0) ** 0.5',\n", + " '[magnetic_flux] -> [gaussian_magnetic_flux]: value * (4 * π / µ_0) ** 0.5',\n", + " '[gaussian_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π * µ_0) ** 0.5',\n", + " '[magnetic_field_strength] -> [gaussian_magnetic_field_strength]: value * (4 * π * µ_0) ** 0.5',\n", + " '[gaussian_magnetic_dipole] -> [magnetic_dipole]: value * (4 * π / µ_0) ** 0.5',\n", + " '[magnetic_dipole] -> [gaussian_magnetic_dipole]: value / (4 * π / µ_0) ** 0.5',\n", + " '[gaussian_resistance] -> [resistance]: value * k_C',\n", + " '[resistance] -> [gaussian_resistance]: value / k_C',\n", + " '[gaussian_resistivity] -> [resistivity]: value * k_C',\n", + " '[resistivity] -> [gaussian_resistivity]: value / k_C',\n", + " '[gaussian_capacitance] -> [capacitance]: value / k_C',\n", + " '[capacitance] -> [gaussian_capacitance]: value * k_C',\n", + " '[gaussian_inductance] -> [inductance]: value * k_C',\n", + " '[inductance] -> [gaussian_inductance]: value / k_C',\n", + " '[gaussian_conductance] -> [conductance]: value / k_C',\n", + " '[conductance] -> [gaussian_conductance]: value * k_C'],\n", + " 'defaults': {}},\n", + " 'ESU': {'aliases': ['esu'],\n", + " 'relations': ['[esu_magnetic_field] -> [magnetic_field]: value * k_C ** 0.5',\n", + " '[magnetic_field] -> [esu_magnetic_field]: value / k_C ** 0.5',\n", + " '[esu_magnetic_flux] -> [magnetic_flux]: value * k_C ** 0.5',\n", + " '[magnetic_flux] -> [esu_magnetic_flux]: value / k_C ** 0.5',\n", + " '[esu_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π / ε_0) ** 0.5',\n", + " '[magnetic_field_strength] -> [esu_magnetic_field_strength]: value * (4 * π / ε_0) ** 0.5',\n", + " '[esu_magnetic_dipole] -> [magnetic_dipole]: value / k_C ** 0.5',\n", + " '[magnetic_dipole] -> [esu_magnetic_dipole]: value * k_C ** 0.5'],\n", + " 'defaults': {}},\n", + " 'spectroscopy': {'aliases': ['sp'],\n", + " 'relations': ['[length] <-> [frequency]: speed_of_light / n / value',\n", + " '[frequency] -> [energy]: planck_constant * value',\n", + " '[energy] -> [frequency]: value / planck_constant',\n", + " '[wavenumber] <-> [length]: 1 / value'],\n", + " 'defaults': {'n': 1}},\n", + " 'boltzmann': {'relations': ['[temperature] -> [energy]: boltzmann_constant * value',\n", + " '[energy] -> [temperature]: value / boltzmann_constant'],\n", + " 'defaults': {}},\n", + " 'energy': {'relations': ['[energy] -> [energy] / [substance]: value * N_A',\n", + " '[energy] / [substance] -> [energy]: value / N_A',\n", + " '[energy] -> [mass]: value / c ** 2',\n", + " '[mass] -> [energy]: value * c ** 2'],\n", + " 'defaults': {}},\n", + " 'chemistry': {'aliases': ['chem'],\n", + " 'relations': ['[substance] -> [mass]: value * mw',\n", + " '[mass] -> [substance]: value / mw',\n", + " '[substance] / [volume] -> [mass] / [volume]: value * mw',\n", + " '[mass] / [volume] -> [substance] / [volume]: value / mw',\n", + " '[substance] / [mass] -> [mass] / [mass]: value * mw',\n", + " '[mass] / [mass] -> [substance] / [mass]: value / mw',\n", + " '[substance] / [volume] -> [substance]: value * volume',\n", + " '[substance] -> [substance] / [volume]: value / volume',\n", + " '[substance] / [mass] -> [substance]: value * solvent_mass',\n", + " '[substance] -> [substance] / [mass]: value / solvent_mass',\n", + " '[substance] / [mass] -> [substance]/[volume]: value * solvent_mass / volume',\n", + " '[substance] / [volume] -> [substance] / [mass]: value / solvent_mass * volume'],\n", + " 'defaults': {'mw': 0, 'volume': 0, 'solvent_mass': 0}},\n", + " 'textile': {'relations': ['[mass] / [length] <-> [length] / [mass]: 1 / value'],\n", + " 'defaults': {}}},\n", + " 'context': {}}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "config" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'system'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[17], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ureg_ \u001b[38;5;241m=\u001b[39m pint\u001b[38;5;241m.\u001b[39mUnitRegistry(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtest.toml\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\plain\\registry.py:158\u001b[0m, in \u001b[0;36mRegistryMeta.__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 156\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs: Any, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any):\n\u001b[0;32m 157\u001b[0m obj \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m--> 158\u001b[0m obj\u001b[38;5;241m.\u001b[39m_after_init()\n\u001b[0;32m 159\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m obj\n", + "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\system\\registry.py:77\u001b[0m, in \u001b[0;36mGenericSystemRegistry._after_init\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_after_init\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 72\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Invoked at the end of ``__init__``.\u001b[39;00m\n\u001b[0;32m 73\u001b[0m \n\u001b[0;32m 74\u001b[0m \u001b[38;5;124;03m - Create default group and add all orphan units to it\u001b[39;00m\n\u001b[0;32m 75\u001b[0m \u001b[38;5;124;03m - Set default system\u001b[39;00m\n\u001b[0;32m 76\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 77\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m_after_init()\n\u001b[0;32m 79\u001b[0m \u001b[38;5;66;03m#: System name to be used by default.\u001b[39;00m\n\u001b[0;32m 80\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_system_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_system_name \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_defaults\u001b[38;5;241m.\u001b[39mget(\n\u001b[0;32m 81\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msystem\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 82\u001b[0m )\n", + "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\group\\registry.py:65\u001b[0m, in \u001b[0;36mGenericGroupRegistry._after_init\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 59\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_after_init\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 60\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Invoked at the end of ``__init__``.\u001b[39;00m\n\u001b[0;32m 61\u001b[0m \n\u001b[0;32m 62\u001b[0m \u001b[38;5;124;03m - Create default group and add all orphan units to it\u001b[39;00m\n\u001b[0;32m 63\u001b[0m \u001b[38;5;124;03m - Set default system\u001b[39;00m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 65\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m_after_init()\n\u001b[0;32m 67\u001b[0m \u001b[38;5;66;03m#: Copy units not defined in any group to the default group\u001b[39;00m\n\u001b[0;32m 68\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgroup\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_defaults:\n", + "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\plain\\registry.py:337\u001b[0m, in \u001b[0;36mGenericPlainRegistry._after_init\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 335\u001b[0m loaded_files \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mload_definitions(path, \u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m 336\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filename \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 337\u001b[0m loaded_files \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mload_definitions(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filename)\n\u001b[0;32m 338\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 339\u001b[0m loaded_files \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n", + "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\plain\\registry.py:605\u001b[0m, in \u001b[0;36mGenericPlainRegistry.load_definitions\u001b[1;34m(self, file, is_resource)\u001b[0m\n\u001b[0;32m 602\u001b[0m parsed_project \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_def_parser\u001b[38;5;241m.\u001b[39mparse_file(file)\n\u001b[0;32m 604\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mstr\u001b[39m(file)[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m5\u001b[39m:] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.toml\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 605\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m definition \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_toml_parser\u001b[38;5;241m.\u001b[39miter_parsed_project(parsed_project):\n\u001b[0;32m 606\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_helper_dispatch_adder(definition)\n\u001b[0;32m 607\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\delegates\\toml_parser\\toml_parser.py:86\u001b[0m, in \u001b[0;36mTomlParser.iter_parsed_project\u001b[1;34m(self, parsed_project)\u001b[0m\n\u001b[0;32m 84\u001b[0m d\u001b[38;5;241m=\u001b[39mcopy\u001b[38;5;241m.\u001b[39mcopy(value)\n\u001b[0;32m 85\u001b[0m d[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m=\u001b[39mkey\n\u001b[1;32m---> 86\u001b[0m stmt \u001b[38;5;241m=\u001b[39m stmts[definition_type]\u001b[38;5;241m.\u001b[39mfrom_dict_and_config(d, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_config)\n\u001b[0;32m 87\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m stmt\n", + "\u001b[1;31mKeyError\u001b[0m: 'system'" + ] + } + ], + "source": [ + "ureg_ = pint.UnitRegistry(\"test.toml\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%debug" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pint\n", + "ureg = pint.UnitRegistry()\n", + "Q_= ureg.Quantity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ureg._group_definitions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ureg._units['J']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%debug" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "q=1*ureg.degC\n", + "q.to(\"K\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "config['database']['level2'] = 'new added information'\n", + "with open('config.toml', 'w') as f:\n", + " toml.dump(config, f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "x = pint.definitions.Definition.from_string('degF = 9 / 5 * kelvin; offset: 255.372222')\n", + "x" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(Q_(32.1, ureg.degF).to('degC'))\n", + "print(Q_(32.01, ureg.degF).to('degC'))\n", + "print(Q_(32.001, ureg.degF).to('degC'))\n", + "print(Q_(32.0001, ureg.degF).to('degC'))\n", + "print(Q_(32.00001, ureg.degF).to('degC'))\n", + "print(Q_(32.000001, ureg.degF).to('degC'))\n", + "print(Q_(32.0000001, ureg.degF).to('degC'))\n", + "print(Q_(32.00000001, ureg.degF).to('degC'))\n", + "print(Q_(32.000000001, ureg.degF).to('degC'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pint.__file__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# print(q(212, ureg.degF).to('degC'))\n", + "temps =[0,255.37,373.1339]\n", + "for temp in temps:\n", + " q= Q_(temp,\"K\")\n", + " print(q.to(\"K\"), q.to(\"degC\"), q.to(\"degF\"),q.to(\"degR\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "q" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(q(32, ureg.degF).to('degK'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "q(32, ureg.degF).to('degK').m\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "assertTrue(abs(self.Q_(0, ureg.degC).to('degF').m- 32)<1e-8)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "np.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pint\n", + "print(pint.compat.__file__)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pint._HAS_PINTPANDAS" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ureg=pint.UnitRegistry()\n", + "Q_=ureg.Quantity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "a=Q_(1,\"m\")\n", + "b=a*Q_([[1,2,3]],\"m\")\n", + "c=Q_(3,\"m\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "my_array = ureg.Quantity([1,2],\"m\")\n", + "my_array_mm = ureg.Quantity([1,2],\"mm\")\n", + "np.concatenate([my_array,my_array])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "getattr(np,\"linspace\")==np.linspace" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.power(a,[2, 3])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from pint.testsuite.test_numpy import TestNumpyMathematicalFunctions\n", + "self = TestNumpyMathematicalFunctions()\n", + "self.ureg = ureg\n", + "self.Q_ = Q_" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.unwrap([0,540]*self.ureg.deg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "self.test_unwrap()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "self.assertQuantityEqual(np.swapaxes(self.q, 1,0), np.array([[1,2],[3,4]]).T * self.ureg.m)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "a = np.ones((3, 2))\n", + "q = self.Q_(a, \"km\")\n", + "self.assertEqual(q.u, np.compress((q==q[0,0]).any(0), q).u)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.sum([self.q]*2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "self.assertQuantityEqual(np.atleast_1d(self.q), self.q)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "y = np.linspace(0 * ureg.meter, 0.1 * ureg.meter)\n", + "y" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "a.tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ureg.meter._REGISTRY.Quantity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.sum([my_array,my_array_mm],axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.arange(a,c,a)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def _():\n", + "# import pdb\n", + "# pdb.set_trace()\n", + " np.arange(a,c)\n", + "_()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%debug" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.sum([my_array,my_array_mm],axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def _([start, ]stop, [step, ]dtype=None):\n", + " print(start,stop,step)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Q_(np.array([1, 2]),\"m\").magnitude.dtype" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Q_(np.array([1, np.nan]),\"m\").magnitude.dtype" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import functools\n", + "import inspect\n", + "import numpy as np\n", + "import six\n", + "import sys\n", + "\n", + "\n", + "class ndarray(np.ndarray):\n", + " \"\"\"Updated version of numpy.ndarray.\"\"\"\n", + " def __array_function__(self, func, types, args, kwargs):\n", + " # Cannot handle items that have __array_function__ other than our own.\n", + " for t in types:\n", + " if (hasattr(t, '__array_function__') and\n", + " t.__array_function__ is not ndarray.__array_function__):\n", + " return NotImplemented\n", + "\n", + " # Arguments contain no overrides, so we can safely call the\n", + " # overloaded function again.\n", + " return func(*args, **kwargs)\n", + "\n", + "\n", + "def get_overloaded_types_and_args(relevant_args):\n", + " \"\"\"Returns a list of arguments on which to call __array_function__.\n", + " \n", + " __array_function__ implementations should be called in order on the return\n", + " values from this function.\n", + " \"\"\"\n", + " # Runtime is O(num_arguments * num_unique_types)\n", + " overloaded_types = []\n", + " overloaded_args = []\n", + " for arg in relevant_args:\n", + " arg_type = type(arg)\n", + " if arg_type not in overloaded_types:\n", + " try:\n", + " array_function = arg_type.__array_function__\n", + " except AttributeError:\n", + " continue\n", + "\n", + " overloaded_types.append(arg_type)\n", + "\n", + " if array_function is not ndarray.__array_function__:\n", + " index = len(overloaded_args)\n", + " for i, old_arg in enumerate(overloaded_args):\n", + " if issubclass(arg_type, type(old_arg)):\n", + " index = i\n", + " break\n", + " overloaded_args.insert(index, arg)\n", + "\n", + " return overloaded_types, overloaded_args\n", + "\n", + "\n", + "def full_name(obj):\n", + " return f'{obj.__module__}.{obj.__qualname__}'\n", + " \n", + "\n", + "def attempt_augmented_error_message(error, append_message):\n", + " \"\"\"Attempt to recreate an error with an appended message.\"\"\"\n", + " try:\n", + " return type(error)(error.args[0] + append_message, *error.args[1:])\n", + " except Exception:\n", + " return error\n", + " \n", + "def try_array_function_override(func, relevant_arguments, args, kwargs):\n", + " # TODO: consider simplifying the interface, to only require either `types`\n", + " # (by calling __array_function__ a classmethod) or `overloaded_args` (by\n", + " # dropping `types` from the signature of __array_function__)\n", + " types, overloaded_args = get_overloaded_types_and_args(relevant_arguments)\n", + " if not overloaded_args:\n", + " return False, None\n", + "\n", + " for overloaded_arg in overloaded_args:\n", + " # Note that we're only calling __array_function__ on the *first*\n", + " # occurence of each argument type. This is necessary for reasonable\n", + " # performance with a possibly long list of overloaded arguments, for\n", + " # which each __array_function__ implementation might reasonably need to\n", + " # check all argument types.\n", + " try:\n", + " result = overloaded_arg.__array_function__(\n", + " func, types, args, kwargs)\n", + " except Exception as error:\n", + " # Ensure the type of the overloaded argument ends up in the\n", + " # traceback\n", + " message = (\" [while calling {!r} implementation of {!r}]\"\n", + " .format(full_name(type(overloaded_arg)),\n", + " full_name(func)))\n", + " new_error = attempt_augmented_error_message(error, message)\n", + " # Would probably need to use six to do this sanely on Python 2:\n", + " # https://stackoverflow.com/questions/9157210/\n", + " raise new_error.with_traceback(error.__traceback__) from None\n", + "\n", + " if result is not NotImplemented:\n", + " return True, result\n", + "\n", + " raise TypeError('no implementation found for {} on types that implement '\n", + " '__array_function__: {}'\n", + " .format(func, list(map(type, overloaded_args))))\n", + "\n", + "\n", + "def array_function_dispatch(dispatcher):\n", + " \"\"\"Wrap a function for dispatch with the __array_function__ protocol.\"\"\"\n", + " def decorator(func):\n", + " @functools.wraps(func)\n", + " def new_func(*args, **kwargs):\n", + " relevant_arguments = dispatcher(*args, **kwargs)\n", + " success, value = try_array_function_override(\n", + " new_func, relevant_arguments, args, kwargs)\n", + " if success:\n", + " return value\n", + " return func(*args, **kwargs)\n", + " return new_func\n", + " return decorator\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "\n", + "\n", + "def _broadcast_to_dispatcher(array, shape, subok=None):\n", + " return (array,)\n", + "\n", + "@array_function_dispatch(_broadcast_to_dispatcher)\n", + "def broadcast_to(array, shape, subok=False):\n", + " return np.broadcast_to(array, shape, subok)\n", + "\n", + "\n", + "def _concatenate_dispatcher(arrays, axis=None, out=None):\n", + " for array in arrays:\n", + " yield array\n", + " if out is not None:\n", + " yield out\n", + " \n", + "@array_function_dispatch(_concatenate_dispatcher)\n", + "def concatenate(arrays, axis=0, out=None):\n", + " return np.concatenate(arrays, axis=axis, out=out)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "HANDLED_FUNCTIONS = {}\n", + "\n", + "class MyArray:\n", + " def __array_function__(self, func, types, args, kwargs):\n", + " if func not in HANDLED_FUNCTIONS:\n", + " return NotImplemented\n", + " if not all(issubclass(t, MyArray) for t in types):\n", + " return NotImplemented\n", + " return HANDLED_FUNCTIONS[func](*args, **kwargs)\n", + "\n", + "def implements(numpy_function):\n", + " \"\"\"Register an __array_function__ implementation for MyArray objects.\"\"\"\n", + " def decorator(func):\n", + " HANDLED_FUNCTIONS[numpy_function] = func\n", + " return func\n", + " return decorator\n", + "\n", + " \n", + "# dummy implementation to show how overloads work with new/unexpected arguments\n", + "@implements(concatenate)\n", + "def _(arrays):\n", + " pass\n", + "\n", + "my_array = MyArray()\n", + "concatenate([my_array]) # works\n", + "concatenate([my_array], axis=0) # not supported" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "HANDLED_FUNCTIONS = {}\n", + " \n", + "def __array_function__(self, func, types, args, kwargs):\n", + " if func not in HANDLED_FUNCTIONS:\n", + " return NotImplemented\n", + " if not all(issubclass(t, ureg.Quantity) for t in types):\n", + " return NotImplemented\n", + " return HANDLED_FUNCTIONS[func](*args, **kwargs)\n", + "\n", + "def implements(numpy_function):\n", + " \"\"\"Register an __array_function__ implementation for MyArray objects.\"\"\"\n", + " def decorator(func):\n", + " HANDLED_FUNCTIONS[numpy_function] = func\n", + " return func\n", + " return decorator\n", + "\n", + "setattr(ureg.Quantity, '__array_function__', __array_function__)\n", + " \n", + "# dummy implementation to show how overloads work with new/unexpected arguments\n", + "@implements(concatenate)\n", + "def _(arrays, axis=0, out=None):\n", + " out_units = arrays[0].units\n", + " arrays = [q.to(out_units) for q in arrays]\n", + " return ureg.Quantity(np.concatenate(arrays, axis=axis, out=out), out_units)\n", + "\n", + "my_array = ureg.Quantity([1,2],\"m\")\n", + "my_array_mm = ureg.Quantity([1,2],\"mm\")\n", + "concatenate([my_array,my_array_mm]) # works" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.concatenate([my_array,my_array_mm])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "concatenate([my_array,my_array_mm], axis=0) # not supported" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "interpretations = '''\n", + "~ energy = work = enthalpy\n", + " [energy] = [force] * [length]\n", + " joule = newton * meter = J\n", + " erg = dyne * centimeter\n", + " btu = 1.05505585262e3 * joule = Btu = BTU = british_thermal_unit\n", + " electron_volt = 1.60217653e-19 * J = eV\n", + " quadrillion_btu = 10**15 * btu = quad\n", + " thm = 100000 * BTU = therm = EC_therm\n", + " calorie = 4.184 * joule = cal = thermochemical_calorie\n", + " international_steam_table_calorie = 4.1868 * joule\n", + " ton_TNT = 4.184e9 * joule = tTNT\n", + " US_therm = 1.054804e8 * joule\n", + " watt_hour = watt * hour = Wh = watthour\n", + " hartree = 4.35974394e-18 * joule = = Eh = E_h = hartree_energy\n", + " toe = 41.868e9 * joule = tonne_of_oil_equivalent\n", + "~ energy\n", + "~ torque\n", + " [torque] = [force] * [length]\n", + " newton_meter = newton * meter = Nm\n", + "~torque\n", + "'''" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A single unit should return its interperetation only\n", + "\n", + "A dual unit should check all valid units for its dimensionality" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "nm=Q_(10.2345678,\"Nm\")\n", + "nmu=nm.units\n", + "\n", + "nmu.dimensionality" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "nmu._units" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "n_m=Q_(10.2345678,\"N m\")\n", + "n_mu=n_m.units\n", + "\n", + "n_mu.dimensionality" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "n_mu._units" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pint.PintType._metadata" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from pintpandas.test_pandas_interface import *" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "TestDataFrameAccessor().test_index_maintained()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%debug" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "scalars=PintArray([], dtype='pint[nanometer]')\n", + "next(i for i in scalars if hasattr(i,\"units\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "a=pint.PintType(\"m\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "self=pint.PintArray([1,2],\"m\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "self.data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pint.PintArray._from_sequence" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "na_sentinel = -1\n", + "from pandas.core.algorithms import _factorize_array\n", + "\n", + "arr, na_value = self._values_for_factorize()\n", + "\n", + "labels, uniques = _factorize_array(arr, na_sentinel=na_sentinel,\n", + " na_value=na_value)\n", + "uniques = self._from_factorized(uniques, self)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "labels, uniques" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "a=pd.core.arrays.period_array([2000, 2001, 2002], freq='D')\n", + "type(a.dtype)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "type(a.astype(a.dtype))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:pa_jan25]", + "language": "python", + "name": "conda-env-pa_jan25-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From b635315f833f55c4a039021bc004d02c9bc80898 Mon Sep 17 00:00:00 2001 From: Andrew Savage Date: Tue, 11 Feb 2025 00:02:29 +0000 Subject: [PATCH 03/20] docstings --- pint/delegates/toml_parser/plain.py | 328 ++- pint/delegates/toml_parser/toml_parser.py | 10 +- pint/facets/context/__init__.py | 4 +- pint/facets/system/__init__.py | 2 +- toml.ipynb | 2355 --------------------- 5 files changed, 240 insertions(+), 2459 deletions(-) delete mode 100644 toml.ipynb diff --git a/pint/delegates/toml_parser/plain.py b/pint/delegates/toml_parser/plain.py index 6785dbeb9..d25a95962 100644 --- a/pint/delegates/toml_parser/plain.py +++ b/pint/delegates/toml_parser/plain.py @@ -29,85 +29,50 @@ from ...converters import Converter from ...facets.plain import definitions as definitions_ -from ...facets.group import GroupDefinition as GroupDefinition_ -from ...util import UnitsContainer +from ...facets import group +from ...facets import system +from ...facets import context +from ...util import UnitsContainer, to_units_container from ..base_defparser import ParserConfig from . import common import copy -@dataclass(frozen=True) -class Equality(definitions_.Equality): - """An equality statement contains a left and right hand separated - - lhs and rhs should be space stripped. - """ - - @classmethod - def from_string(cls, s: str) -> fp.NullableParsedResult[Equality]: - if "=" not in s: - return None - parts = [p.strip() for p in s.split("=")] - if len(parts) != 2: - return common.DefinitionSyntaxError( - f"Exactly two terms expected, not {len(parts)} (`{s}`)" - ) - return cls(*parts) - - -@dataclass(frozen=True) -class CommentDefinition(definitions_.CommentDefinition): - """Comments start with a # character. - - # This is a comment. - ## This is also a comment. - - Captured value does not include the leading # character and space stripped. - """ - - @classmethod - def from_string(cls, s: str) -> fp.NullableParsedResult[CommentDefinition]: - if not s.startswith("#"): - return None - return cls(s[1:].strip()) - - @dataclass(frozen=True) class PrefixDefinition(definitions_.PrefixDefinition): """Definition of a prefix:: - - = [= ] [= ] [ = ] [...] + [.] + value = "" + defined_symbol = "" + aliases = [ + "", + ... + "", + ] Example:: - deca- = 1e+1 = da- = deka- + [prefix.micro] + value = "1e-6" + defined_symbol = "µ" + aliases = [ + "μ", + "u", + "mu", + "mc", + ] """ @classmethod def from_dict_and_config( cls, d: from_dict, config: ParserConfig ) -> PrefixDefinition: - name = d["name"] + name = d["name"].strip() value = d["value"] defined_symbol = d.get("defined_symbol", None) aliases = d.get("aliases", []) - name = name.strip() - # if not name.endswith("-"): - # return None - - # name = name.rstrip("-") - # aliases = tuple(alias.strip().rstrip("-") for alias in aliases) - - # defined_symbol = None - # if aliases: - # if aliases[0] == "_": - # aliases = aliases[1:] - # else: - # defined_symbol, *aliases = aliases - - # aliases = tuple(alias for alias in aliases if alias not in ("", "_")) - try: value = config.to_number(value) except definitions_.NotNumeric as ex: @@ -125,11 +90,42 @@ def from_dict_and_config( class UnitDefinition(definitions_.UnitDefinition): """Definition of a unit:: - = [= ] [= ] [ = ] [...] + [unit.] + aliases = [ + "", + ... + "", + ] + defined_symbol = "" + value = "" Example:: - millennium = 1e3 * year = _ = millennia + [unit.meter] + defined_symbol = "m" + aliases = [ + "metre", + ] + value = "[length]" + + [unit.kelvin] + defined_symbol = "K" + aliases = [ + "degK", + "°K", + "degree_Kelvin", + "degreeK", + ] + value = "[temperature]; offset: 0" + + [unit.radian] + defined_symbol = "rad" + value = "[]" + + + [unit.pi] + defined_symbol = "π" + value = "3.1415926535897932384626433832795028841971693993751" Parameters ---------- @@ -212,18 +208,21 @@ class DerivedDimensionDefinition( ): """Definition of a derived dimension:: - [dimension name] = + [dimension.] + value = "" Example:: - [density] = [mass] / [volume] + [dimension.density] + value = "[mass] / [volume]" + """ @classmethod def from_dict_and_config( cls, d: from_dict, config: ParserConfig ) -> DerivedDimensionDefinition: - name = d["name"] + name = "["+d["name"]+"]" value = d["value"] try: @@ -241,62 +240,199 @@ def from_dict_and_config( @dataclass(frozen=True) -class AliasDefinition(definitions_.AliasDefinition): - """Additional alias(es) for an already existing unit:: +class GroupDefinition( + group.GroupDefinition +): + """Definition of a group. Can be composed of other groups. - @alias = [ = ] [...] + [group.] + using_group_names = [ + "", + ... + "", + ] + # Definitions are the same as unit definitions + [group..definitions.] + aliases = [ + "", + ... + "", + ] + defined_symbol = "" + value = "" Example:: - @alias meter = my_meter + + [group.AvoirdupoisUK] + using_group_names = [ + "Avoirdupois", + ] + + [group.AvoirdupoisUK.definitions.UK_hundredweight] + defined_symbol = "UK_cwt" + value = "long_hundredweight" + + [group.AvoirdupoisUK.definitions.UK_ton] + value = "long_ton" + + """ @classmethod - def from_string(cls, s: str) -> fp.NullableParsedResult[AliasDefinition]: - if not s.startswith("@alias "): - return None - name, *aliases = s[len("@alias ") :].split("=") - - try: - return cls(name.strip(), tuple(alias.strip() for alias in aliases)) - except Exception as exc: - return common.DefinitionSyntaxError(str(exc)) + def from_dict_and_config(cls, d, config) -> GroupDefinition: + name = d["name"] + using_group_names = d.get("using_group_names", ()) + definitions = [] + for key, value in d["definitions"].items(): + dat=copy.copy(value) + dat['name']=key + definitions.append(UnitDefinition.from_dict_and_config(dat, config)) + + return cls( + name, using_group_names, definitions + ) @dataclass(frozen=True) -class GroupDefinition( - GroupDefinition_ +class SystemDefinition( + system.SystemDefinition ): - """Definition of a group. + """Definition of a system. - @group [using , ..., ] - + [system.] + using = [ + "", + ... + "", + ] + rules = [ + ": ", ... - - @end + ": ", + ] - See UnitDefinition and Comment for more parsing related information. + The syntax for the rule is: + + new_unit_name : old_unit_name + + where: + - old_unit_name: a root unit part which is going to be removed from the system. + - new_unit_name: a non root unit which is going to replace the old_unit. + + If the new_unit_name and the old_unit_name, the later and the colon can be omitted. + + See Rule for more parsing related information. Example:: - @group AvoirdupoisUS using Avoirdupois - US_hundredweight = hundredweight = US_cwt - US_ton = ton - US_force_ton = force_ton = _ = US_ton_force - @end + [system.Planck] + using_group_names = [ + "international", + ] + rules = [ + "planck_length: meter", + "planck_mass: gram", + "planck_time: second", + "planck_current: ampere", + "planck_temperature: kelvin", + ] """ @classmethod - def from_dict_and_config(cls, d, config) -> GroupDefinition: + def from_dict_and_config(cls, d, config) -> SystemDefinition: name = d["name"] using_group_names = d.get("using_group_names", ()) - definitions = [] - for key, value in d["definitions"].items(): - dat=copy.copy(value) - dat['name']=key - definitions.append(UnitDefinition.from_dict_and_config(dat, config)) - + + rules = [] + for dat in d["rules"]: + dat = [item.strip() for item in dat.split(":")] + rules.append(system.BaseUnitRule(*dat)) + return cls( - name, using_group_names, definitions + name, using_group_names, rules ) + + +@dataclass(frozen=True) +class ContextDefinition( + context.ContextDefinition +): + """Definition of a context. + + [context.] + aliases = [ + "", + ... + "", + ] + relations = [ + # can establish unidirectional relationships between dimensions: + "[dimension 1] -> [dimension A]: ", + # can establish bidirectional relationships between dimensions: + "[dimension 2] <-> [dimension B]: ", + ... + "[dimension N] -> [dimension Z]: ", + ] + [context..defaults] + # default parameters can be defined for use in equations + = "" + ... + = "" + + See ForwardRelation and BidirectionalRelation for more parsing related information. + + Example:: + + [context.chemistry] + aliases = [ + "chem", + ] + relations = [ + "[substance] -> [mass]: value * mw", + "[mass] -> [substance]: value / mw", + "[substance] / [volume] -> [mass] / [volume]: value * mw", + "[mass] / [volume] -> [substance] / [volume]: value / mw", + "[substance] / [mass] -> [mass] / [mass]: value * mw", + "[mass] / [mass] -> [substance] / [mass]: value / mw", + "[substance] / [volume] -> [substance]: value * volume", + "[substance] -> [substance] / [volume]: value / volume", + "[substance] / [mass] -> [substance]: value * solvent_mass", + "[substance] -> [substance] / [mass]: value / solvent_mass", + "[substance] / [mass] -> [substance]/[volume]: value * solvent_mass / volume", + "[substance] / [volume] -> [substance] / [mass]: value / solvent_mass * volume", + ] + + [context.chemistry.defaults] + mw = "0" + volume = "0" + solvent_mass = "0" + + """ + + @classmethod + def from_dict_and_config(cls, d, config) -> ContextDefinition: + name = d["name"] + aliases = d.get("aliases", ()) + defaults = d.get("defaults", {}) + relations = [] + + for dat in d["relations"]: + dat, eqn = dat.split(":") + if "<->" in dat: + src, dst = dat.split("<->") + obj = context.BidirectionalRelation + else: + src, dst = dat.split("->") + obj = context.ForwardRelation + src = to_units_container(src) + dst = to_units_container(dst) + relations.append( + obj(src, dst, eqn) + ) + redefinitions = d.get("redefinitions", {}) + + return cls( + name,aliases, defaults, relations, redefinitions + ) \ No newline at end of file diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py index 3da30f0ca..d68ca8bb4 100644 --- a/pint/delegates/toml_parser/toml_parser.py +++ b/pint/delegates/toml_parser/toml_parser.py @@ -2,7 +2,7 @@ import pathlib import typing as ty -import toml +import tomllib import copy import flexcache as fc @@ -75,8 +75,8 @@ def iter_parsed_project( 'unit': plain.UnitDefinition, 'prefix': plain.PrefixDefinition, 'dimension': plain.DerivedDimensionDefinition, - # 'system': system.SystemDefinition, - # 'context': context.ContextDefinition, + 'system': plain.SystemDefinition, + 'context': plain.ContextDefinition, 'group': plain.GroupDefinition, } for definition_type in parsed_project.keys(): @@ -135,8 +135,8 @@ def iter_parsed_project( def parse_file( self, filename: pathlib.Path | str, cfg: ParserConfig | None = None ) -> dict: - with open(filename, 'r', encoding="utf-8") as f: - data = toml.load(f) + with open(filename, 'rb') as f: + data = tomllib.load(f) return data def parse_string( diff --git a/pint/facets/context/__init__.py b/pint/facets/context/__init__.py index 28c7b5ced..ab5dcf20d 100644 --- a/pint/facets/context/__init__.py +++ b/pint/facets/context/__init__.py @@ -11,8 +11,8 @@ from __future__ import annotations -from .definitions import ContextDefinition +from .definitions import ContextDefinition, ForwardRelation, BidirectionalRelation from .objects import Context from .registry import ContextRegistry, GenericContextRegistry -__all__ = ["ContextDefinition", "Context", "ContextRegistry", "GenericContextRegistry"] +__all__ = ["ContextDefinition", "Context", "ContextRegistry", "GenericContextRegistry", "ForwardRelation", "BidirectionalRelation"] diff --git a/pint/facets/system/__init__.py b/pint/facets/system/__init__.py index b9cbc9593..f9e98e7bc 100644 --- a/pint/facets/system/__init__.py +++ b/pint/facets/system/__init__.py @@ -10,7 +10,7 @@ from __future__ import annotations -from .definitions import SystemDefinition +from .definitions import SystemDefinition, BaseUnitRule from .objects import System from .registry import GenericSystemRegistry, SystemRegistry diff --git a/toml.ipynb b/toml.ipynb deleted file mode 100644 index e9345ddc5..000000000 --- a/toml.ipynb +++ /dev/null @@ -1,2355 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3.13.1\n" - ] - } - ], - "source": [ - "import platform\n", - "print(platform.python_version())" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import pint\n", - "ureg = pint.UnitRegistry()\n", - "Q_= ureg.Quantity" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "from dataclasses import fields\n" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "import toml" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "skip_fields = ['name',\n", - " # 'value',\n", - " # 'defined_symbol',\n", - " # 'aliases',\n", - " 'is_position_set',\n", - " 'start_line',\n", - " 'start_col',\n", - " 'end_line',\n", - " 'end_col',\n", - " 'raw']\n", - "\n", - "keep_fields = [\n", - "\n", - " 'value',\n", - " 'defined_symbol',\n", - " 'aliases',\n", - "]\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "data = {\n", - " '_prefixes':{},\n", - " # '_suffixes':{},\n", - " '_units':{},\n", - " '_dimensions':{},\n", - " # '_contexts':{},\n", - " # 'system':{},\n", - " # 'group':{},\n", - "}\n", - "def add_key_if_not_empty(dat, key, value):\n", - " if value == () or value is None:\n", - " return dat\n", - " else:\n", - " dat[key]=value\n", - " return dat\n", - " \n", - "def parse_simple_definition(definition, definition_type):\n", - " attrs = [field.name for field in fields(definition) if field.name in keep_fields]\n", - " dat = {}\n", - " for attr in attrs:\n", - " dat=add_key_if_not_empty(dat, attr, getattr(definition,attr))\n", - " if definition_type ==\"_units\" and hasattr(definition,'raw'):\n", - " dat['value'] = definition.raw.split(\"=\")[1].strip()\n", - " if definition_type ==\"_dimensions\" and hasattr(definition,'raw'):\n", - " dat['value'] = definition.raw.split(\"=\")[1].strip()\n", - " if definition_type ==\"_prefixes\" and hasattr(definition,'raw'):\n", - " dat['value'] = definition.raw.split(\"=\")[1].strip()\n", - " return dat\n", - "prefixes = ureg._prefixes\n", - "for definition_type in data.keys():\n", - " definitions = getattr(ureg, definition_type).values()\n", - " for definition in definitions:\n", - " if hasattr(definition,'raw'):\n", - " data[definition_type][definition.name]=parse_simple_definition(definition, definition_type)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "data['prefix'] = data.pop('_prefixes')\n", - "data['unit'] = data.pop('_units')\n", - "data['dimension'] = data.pop('_dimensions')" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "data['group']={}\n", - "for group in ureg._group_definitions:\n", - " dat = {}\n", - " for attr in [\"using_group_names\"]:\n", - " dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", - " dat['definitions']={}\n", - " for definition in group.definitions:\n", - " dat['definitions'][definition.name]=parse_simple_definition(definition, '_units')\n", - " data['group'][group.name] = dat" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "data['system']={}\n", - "for group in ureg._system_definitions:\n", - " dat = {}\n", - " for attr in [\"using_group_names\"]:\n", - " dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", - " dat['rules']=[]\n", - " for rule in group.rules:\n", - " dat['rules'].append(rule.raw)\n", - " data['system'][group.name] = dat" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "data['context']={}\n", - "for group in ureg._context_definitions:\n", - " dat = {}\n", - " for attr in [\"aliases\", \"defaults\", \"redefinitions\"]:\n", - " dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", - " dat['relations']=[]\n", - " for rule in group.relations:\n", - " dat['relations'].append(rule.raw)\n", - " data['system'][group.name] = dat" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'defaults': {},\n", - " 'relations': ['[mass] / [length] <-> [length] / [mass]: 1 / value']}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dat" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "# data['system']={}\n", - "# for group in ureg._system_definitions:\n", - "# dat = {}\n", - "# for attr in [\"using_group_names\"]:\n", - "# dat=add_key_if_not_empty(dat, attr, getattr(group,attr))\n", - "# dat['rules']=[]\n", - "# for rule in group.rules:\n", - "# d_={'new_unit_name':rule.new_unit_name}\n", - "# if rule.old_unit_name:\n", - "# d_['old_unit_name'] = rule.old_unit_name\n", - "# dat['rules'].append(d_)\n", - "# data['system'][group.name] = dat" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "with open('test.toml', 'w', encoding=\"utf-8\") as f:\n", - " toml.dump(data, f)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "import tomli_w\n", - "with open('test.toml', 'wb') as f:\n", - " tomli_w.dump(data, f)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "with open('test.toml', 'r', encoding=\"utf-8\") as f:\n", - " config = toml.load(f)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'prefix': {'quecto': {'value': '1e-30', 'defined_symbol': 'q'},\n", - " 'ronto': {'value': '1e-27', 'defined_symbol': 'r'},\n", - " 'yocto': {'value': '1e-24', 'defined_symbol': 'y'},\n", - " 'zepto': {'value': '1e-21', 'defined_symbol': 'z'},\n", - " 'atto': {'value': '1e-18', 'defined_symbol': 'a'},\n", - " 'femto': {'value': '1e-15', 'defined_symbol': 'f'},\n", - " 'pico': {'value': '1e-12', 'defined_symbol': 'p'},\n", - " 'nano': {'value': '1e-9', 'defined_symbol': 'n'},\n", - " 'micro': {'value': '1e-6',\n", - " 'defined_symbol': 'µ',\n", - " 'aliases': ['μ', 'u', 'mu', 'mc']},\n", - " 'milli': {'value': '1e-3', 'defined_symbol': 'm'},\n", - " 'centi': {'value': '1e-2', 'defined_symbol': 'c'},\n", - " 'deci': {'value': '1e-1', 'defined_symbol': 'd'},\n", - " 'deca': {'value': '1e+1', 'defined_symbol': 'da', 'aliases': ['deka']},\n", - " 'hecto': {'value': '1e2', 'defined_symbol': 'h'},\n", - " 'kilo': {'value': '1e3', 'defined_symbol': 'k'},\n", - " 'mega': {'value': '1e6', 'defined_symbol': 'M'},\n", - " 'giga': {'value': '1e9', 'defined_symbol': 'G'},\n", - " 'tera': {'value': '1e12', 'defined_symbol': 'T'},\n", - " 'peta': {'value': '1e15', 'defined_symbol': 'P'},\n", - " 'exa': {'value': '1e18', 'defined_symbol': 'E'},\n", - " 'zetta': {'value': '1e21', 'defined_symbol': 'Z'},\n", - " 'yotta': {'value': '1e24', 'defined_symbol': 'Y'},\n", - " 'ronna': {'value': '1e27', 'defined_symbol': 'R'},\n", - " 'quetta': {'value': '1e30', 'defined_symbol': 'Q'},\n", - " 'kibi': {'value': '2**10', 'defined_symbol': 'Ki'},\n", - " 'mebi': {'value': '2**20', 'defined_symbol': 'Mi'},\n", - " 'gibi': {'value': '2**30', 'defined_symbol': 'Gi'},\n", - " 'tebi': {'value': '2**40', 'defined_symbol': 'Ti'},\n", - " 'pebi': {'value': '2**50', 'defined_symbol': 'Pi'},\n", - " 'exbi': {'value': '2**60', 'defined_symbol': 'Ei'},\n", - " 'zebi': {'value': '2**70', 'defined_symbol': 'Zi'},\n", - " 'yobi': {'value': '2**80', 'defined_symbol': 'Yi'},\n", - " 'semi': {'value': '0.5', 'aliases': ['demi']},\n", - " 'sesqui': {'value': '1.5'}},\n", - " 'unit': {'meter': {'defined_symbol': 'm',\n", - " 'aliases': ['metre'],\n", - " 'value': '[length]'},\n", - " 'second': {'defined_symbol': 's', 'aliases': ['sec'], 'value': '[time]'},\n", - " 'ampere': {'defined_symbol': 'A', 'aliases': ['amp'], 'value': '[current]'},\n", - " 'candela': {'defined_symbol': 'cd',\n", - " 'aliases': ['candle'],\n", - " 'value': '[luminosity]'},\n", - " 'gram': {'defined_symbol': 'g', 'value': '[mass]'},\n", - " 'mole': {'defined_symbol': 'mol', 'value': '[substance]'},\n", - " 'kelvin': {'defined_symbol': 'K',\n", - " 'aliases': ['degK', '°K', 'degree_Kelvin', 'degreeK'],\n", - " 'value': '[temperature]; offset: 0'},\n", - " 'radian': {'defined_symbol': 'rad', 'value': '[]'},\n", - " 'bit': {'value': '[]'},\n", - " 'count': {'value': '[]'},\n", - " 'pi': {'defined_symbol': 'π',\n", - " 'value': '3.1415926535897932384626433832795028841971693993751'},\n", - " 'tansec': {'value': '4.8481368111333441675396429478852851658848753880815e-6'},\n", - " 'ln10': {'value': '2.3025850929940456840179914546843642076011014886288'},\n", - " 'wien_x': {'value': '4.9651142317442763036987591313228939440555849867973'},\n", - " 'wien_u': {'value': '2.8214393721220788934031913302944851953458817440731'},\n", - " 'eulers_number': {'value': '2.71828182845904523536028747135266249775724709369995'},\n", - " 'speed_of_light': {'defined_symbol': 'c',\n", - " 'aliases': ['c_0'],\n", - " 'value': '299792458 m/s'},\n", - " 'planck_constant': {'defined_symbol': 'ℎ', 'value': '6.62607015e-34 J s'},\n", - " 'elementary_charge': {'defined_symbol': 'e', 'value': '1.602176634e-19 C'},\n", - " 'avogadro_number': {'value': '6.02214076e23'},\n", - " 'boltzmann_constant': {'defined_symbol': 'k',\n", - " 'aliases': ['k_B'],\n", - " 'value': '1.380649e-23 J K^-1'},\n", - " 'standard_gravity': {'defined_symbol': 'g_0',\n", - " 'aliases': ['g0', 'g_n', 'gravity'],\n", - " 'value': '9.80665 m/s^2'},\n", - " 'standard_atmosphere': {'defined_symbol': 'atm',\n", - " 'aliases': ['atmosphere'],\n", - " 'value': '1.01325e5 Pa'},\n", - " 'conventional_josephson_constant': {'defined_symbol': 'K_J90',\n", - " 'value': '4.835979e14 Hz / V'},\n", - " 'conventional_von_klitzing_constant': {'defined_symbol': 'R_K90',\n", - " 'value': '2.5812807e4 ohm'},\n", - " 'zeta': {'defined_symbol': 'ζ', 'value': 'c / (cm/s)'},\n", - " 'dirac_constant': {'defined_symbol': 'ħ',\n", - " 'aliases': ['hbar', 'atomic_unit_of_action', 'a_u_action'],\n", - " 'value': 'ℎ / (2 * π)'},\n", - " 'avogadro_constant': {'defined_symbol': 'N_A',\n", - " 'value': 'avogadro_number * mol^-1'},\n", - " 'molar_gas_constant': {'defined_symbol': 'R', 'value': 'k * N_A'},\n", - " 'faraday_constant': {'value': 'e * N_A'},\n", - " 'conductance_quantum': {'defined_symbol': 'G_0', 'value': '2 * e ** 2 / ℎ'},\n", - " 'magnetic_flux_quantum': {'defined_symbol': 'Φ_0',\n", - " 'aliases': ['Phi_0'],\n", - " 'value': 'ℎ / (2 * e)'},\n", - " 'josephson_constant': {'defined_symbol': 'K_J', 'value': '2 * e / ℎ'},\n", - " 'von_klitzing_constant': {'defined_symbol': 'R_K', 'value': 'ℎ / e ** 2'},\n", - " 'stefan_boltzmann_constant': {'defined_symbol': 'σ',\n", - " 'aliases': ['sigma'],\n", - " 'value': '2 / 15 * π ** 5 * k ** 4 / (ℎ ** 3 * c ** 2)'},\n", - " 'first_radiation_constant': {'defined_symbol': 'c_1',\n", - " 'value': '2 * π * ℎ * c ** 2'},\n", - " 'second_radiation_constant': {'defined_symbol': 'c_2', 'value': 'ℎ * c / k'},\n", - " 'wien_wavelength_displacement_law_constant': {'value': 'ℎ * c / (k * wien_x)'},\n", - " 'wien_frequency_displacement_law_constant': {'value': 'wien_u * k / ℎ'},\n", - " 'newtonian_constant_of_gravitation': {'aliases': ['gravitational_constant'],\n", - " 'value': '6.67430e-11 m^3/(kg s^2)'},\n", - " 'rydberg_constant': {'defined_symbol': 'R_∞',\n", - " 'aliases': ['R_inf'],\n", - " 'value': '1.0973731568157e7 * m^-1'},\n", - " 'electron_g_factor': {'defined_symbol': 'g_e', 'value': '-2.00231930436092'},\n", - " 'atomic_mass_constant': {'defined_symbol': 'm_u',\n", - " 'value': '1.66053906892e-27 kg'},\n", - " 'electron_mass': {'defined_symbol': 'm_e',\n", - " 'aliases': ['atomic_unit_of_mass', 'a_u_mass'],\n", - " 'value': '9.1093837139e-31 kg'},\n", - " 'proton_mass': {'defined_symbol': 'm_p', 'value': '1.67262192595e-27 kg'},\n", - " 'neutron_mass': {'defined_symbol': 'm_n', 'value': '1.67492750056e-27 kg'},\n", - " 'x_unit_Cu': {'defined_symbol': 'Xu_Cu', 'value': '1.00207697e-13 m'},\n", - " 'x_unit_Mo': {'defined_symbol': 'Xu_Mo', 'value': '1.00209952e-13 m'},\n", - " 'angstrom_star': {'defined_symbol': 'Å_star', 'value': '1.00001495e-10'},\n", - " 'fine_structure_constant': {'defined_symbol': 'α',\n", - " 'aliases': ['alpha'],\n", - " 'value': '(2 * ℎ * R_inf / (m_e * c)) ** 0.5'},\n", - " 'vacuum_permeability': {'defined_symbol': 'µ_0',\n", - " 'aliases': ['mu_0', 'mu0', 'magnetic_constant'],\n", - " 'value': '2 * α * ℎ / (e ** 2 * c)'},\n", - " 'vacuum_permittivity': {'defined_symbol': 'ε_0',\n", - " 'aliases': ['epsilon_0', 'eps_0', 'eps0', 'electric_constant'],\n", - " 'value': 'e ** 2 / (2 * α * ℎ * c)'},\n", - " 'impedance_of_free_space': {'defined_symbol': 'Z_0',\n", - " 'aliases': ['characteristic_impedance_of_vacuum'],\n", - " 'value': '2 * α * ℎ / e ** 2'},\n", - " 'coulomb_constant': {'defined_symbol': 'k_C',\n", - " 'value': 'α * hbar * c / e ** 2'},\n", - " 'classical_electron_radius': {'defined_symbol': 'r_e',\n", - " 'value': 'α * hbar / (m_e * c)'},\n", - " 'thomson_cross_section': {'defined_symbol': 'σ_e',\n", - " 'aliases': ['sigma_e'],\n", - " 'value': '8 / 3 * π * r_e ** 2'},\n", - " 'turn': {'aliases': ['revolution', 'cycle', 'circle'],\n", - " 'value': '2 * π * radian'},\n", - " 'degree': {'defined_symbol': 'deg',\n", - " 'aliases': ['arcdeg', 'arcdegree', 'angular_degree'],\n", - " 'value': 'π / 180 * radian'},\n", - " 'arcminute': {'defined_symbol': 'arcmin',\n", - " 'aliases': ['arc_minute', 'angular_minute'],\n", - " 'value': 'degree / 60'},\n", - " 'arcsecond': {'defined_symbol': 'arcsec',\n", - " 'aliases': ['arc_second', 'angular_second'],\n", - " 'value': 'arcminute / 60'},\n", - " 'milliarcsecond': {'defined_symbol': 'mas', 'value': '1e-3 * arcsecond'},\n", - " 'grade': {'defined_symbol': 'grad',\n", - " 'aliases': ['gon'],\n", - " 'value': 'π / 200 * radian'},\n", - " 'mil': {'value': 'π / 32000 * radian'},\n", - " 'steradian': {'defined_symbol': 'sr', 'value': 'radian ** 2'},\n", - " 'square_degree': {'defined_symbol': 'sq_deg',\n", - " 'aliases': ['sqdeg'],\n", - " 'value': '(π / 180) ** 2 * sr'},\n", - " 'baud': {'defined_symbol': 'Bd',\n", - " 'aliases': ['bps'],\n", - " 'value': 'bit / second'},\n", - " 'byte': {'defined_symbol': 'B', 'aliases': ['octet'], 'value': '8 * bit'},\n", - " 'percent': {'defined_symbol': '%', 'value': '0.01'},\n", - " 'permille': {'defined_symbol': '‰', 'value': '0.001'},\n", - " 'ppm': {'value': '1e-6'},\n", - " 'angstrom': {'defined_symbol': 'Å',\n", - " 'aliases': ['ångström', 'Å'],\n", - " 'value': '1e-10 * meter'},\n", - " 'micron': {'defined_symbol': 'µ', 'aliases': ['μ'], 'value': 'micrometer'},\n", - " 'fermi': {'defined_symbol': 'fm', 'value': 'femtometer'},\n", - " 'light_year': {'defined_symbol': 'ly',\n", - " 'aliases': ['lightyear'],\n", - " 'value': 'speed_of_light * julian_year'},\n", - " 'astronomical_unit': {'defined_symbol': 'au',\n", - " 'value': '149597870700 * meter'},\n", - " 'parsec': {'defined_symbol': 'pc',\n", - " 'value': '1 / tansec * astronomical_unit'},\n", - " 'nautical_mile': {'defined_symbol': 'nmi', 'value': '1852 * meter'},\n", - " 'bohr': {'defined_symbol': 'a_0',\n", - " 'aliases': ['a0', 'bohr_radius', 'atomic_unit_of_length', 'a_u_length'],\n", - " 'value': 'hbar / (alpha * m_e * c)'},\n", - " 'planck_length': {'value': '(hbar * gravitational_constant / c ** 3) ** 0.5'},\n", - " 'metric_ton': {'defined_symbol': 't',\n", - " 'aliases': ['tonne'],\n", - " 'value': '1e3 * kilogram'},\n", - " 'unified_atomic_mass_unit': {'defined_symbol': 'u',\n", - " 'aliases': ['amu'],\n", - " 'value': 'atomic_mass_constant'},\n", - " 'dalton': {'defined_symbol': 'Da', 'value': 'atomic_mass_constant'},\n", - " 'grain': {'defined_symbol': 'gr', 'value': '64.79891 * milligram'},\n", - " 'gamma_mass': {'value': 'microgram'},\n", - " 'carat': {'defined_symbol': 'ct',\n", - " 'aliases': ['karat'],\n", - " 'value': '200 * milligram'},\n", - " 'planck_mass': {'value': '(hbar * c / gravitational_constant) ** 0.5'},\n", - " 'minute': {'defined_symbol': 'min', 'value': '60 * second'},\n", - " 'hour': {'defined_symbol': 'h', 'aliases': ['hr'], 'value': '60 * minute'},\n", - " 'day': {'defined_symbol': 'd', 'value': '24 * hour'},\n", - " 'week': {'value': '7 * day'},\n", - " 'fortnight': {'value': '2 * week'},\n", - " 'year': {'defined_symbol': 'a',\n", - " 'aliases': ['yr', 'julian_year'],\n", - " 'value': '365.25 * day'},\n", - " 'month': {'value': 'year / 12'},\n", - " 'century': {'aliases': ['centuries'], 'value': '100 * year'},\n", - " 'millennium': {'aliases': ['millennia'], 'value': '1e3 * year'},\n", - " 'eon': {'value': '1e9 * year'},\n", - " 'shake': {'value': '1e-8 * second'},\n", - " 'svedberg': {'value': '1e-13 * second'},\n", - " 'atomic_unit_of_time': {'defined_symbol': 'a_u_time', 'value': 'hbar / E_h'},\n", - " 'gregorian_year': {'value': '365.2425 * day'},\n", - " 'sidereal_year': {'value': '365.256363004 * day'},\n", - " 'tropical_year': {'value': '365.242190402 * day'},\n", - " 'common_year': {'value': '365 * day'},\n", - " 'leap_year': {'value': '366 * day'},\n", - " 'sidereal_day': {'value': 'day / 1.00273790935079524'},\n", - " 'sidereal_month': {'value': '27.32166155 * day'},\n", - " 'tropical_month': {'value': '27.321582 * day'},\n", - " 'synodic_month': {'aliases': ['lunar_month'], 'value': '29.530589 * day'},\n", - " 'planck_time': {'value': '(hbar * gravitational_constant / c ** 5) ** 0.5'},\n", - " 'degree_Celsius': {'defined_symbol': '°C',\n", - " 'aliases': ['celsius', 'degC', 'degreeC'],\n", - " 'value': 'kelvin; offset: 273.15'},\n", - " 'degree_Rankine': {'defined_symbol': '°R',\n", - " 'aliases': ['rankine', 'degR', 'degreeR'],\n", - " 'value': '5 / 9 * kelvin; offset: 0'},\n", - " 'degree_Fahrenheit': {'defined_symbol': '°F',\n", - " 'aliases': ['fahrenheit', 'degF', 'degreeF'],\n", - " 'value': '5 / 9 * kelvin; offset: 233.15 + 200 / 9'},\n", - " 'degree_Reaumur': {'defined_symbol': '°Re',\n", - " 'aliases': ['reaumur', 'degRe', 'degreeRe', 'degree_Réaumur', 'réaumur'],\n", - " 'value': '4 / 5 * kelvin; offset: 273.15'},\n", - " 'atomic_unit_of_temperature': {'defined_symbol': 'a_u_temp',\n", - " 'value': 'E_h / k'},\n", - " 'planck_temperature': {'value': '(hbar * c ** 5 / gravitational_constant / k ** 2) ** 0.5'},\n", - " 'are': {'value': '100 * meter ** 2'},\n", - " 'barn': {'defined_symbol': 'b', 'value': '1e-28 * meter ** 2'},\n", - " 'darcy': {'value': 'centipoise * centimeter ** 2 / (second * atmosphere)'},\n", - " 'hectare': {'defined_symbol': 'ha', 'value': '100 * are'},\n", - " 'liter': {'defined_symbol': 'l',\n", - " 'aliases': ['L', 'ℓ', 'litre'],\n", - " 'value': 'decimeter ** 3'},\n", - " 'cubic_centimeter': {'defined_symbol': 'cc', 'value': 'centimeter ** 3'},\n", - " 'lambda': {'defined_symbol': 'λ', 'value': 'microliter'},\n", - " 'stere': {'value': 'meter ** 3'},\n", - " 'hertz': {'defined_symbol': 'Hz', 'value': '1 / second'},\n", - " 'revolutions_per_minute': {'defined_symbol': 'rpm',\n", - " 'value': 'revolution / minute'},\n", - " 'revolutions_per_second': {'defined_symbol': 'rps',\n", - " 'value': 'revolution / second'},\n", - " 'counts_per_second': {'defined_symbol': 'cps', 'value': 'count / second'},\n", - " 'reciprocal_centimeter': {'defined_symbol': 'cm_1',\n", - " 'aliases': ['kayser'],\n", - " 'value': '1 / cm'},\n", - " 'knot': {'defined_symbol': 'kt',\n", - " 'aliases': ['knot_international', 'international_knot'],\n", - " 'value': 'nautical_mile / hour'},\n", - " 'mile_per_hour': {'defined_symbol': 'mph',\n", - " 'aliases': ['MPH'],\n", - " 'value': 'mile / hour'},\n", - " 'kilometer_per_hour': {'defined_symbol': 'kph',\n", - " 'aliases': ['KPH'],\n", - " 'value': 'kilometer / hour'},\n", - " 'kilometer_per_second': {'defined_symbol': 'kps',\n", - " 'value': 'kilometer / second'},\n", - " 'meter_per_second': {'defined_symbol': 'mps', 'value': 'meter / second'},\n", - " 'foot_per_second': {'defined_symbol': 'fps', 'value': 'foot / second'},\n", - " 'sverdrup': {'defined_symbol': 'sv', 'value': '1e6 * meter ** 3 / second'},\n", - " 'galileo': {'defined_symbol': 'Gal', 'value': 'centimeter / second ** 2'},\n", - " 'newton': {'defined_symbol': 'N', 'value': 'kilogram * meter / second ** 2'},\n", - " 'dyne': {'defined_symbol': 'dyn',\n", - " 'value': 'gram * centimeter / second ** 2'},\n", - " 'force_kilogram': {'defined_symbol': 'kgf',\n", - " 'aliases': ['kilogram_force', 'pond'],\n", - " 'value': 'g_0 * kilogram'},\n", - " 'force_gram': {'defined_symbol': 'gf',\n", - " 'aliases': ['gram_force'],\n", - " 'value': 'g_0 * gram'},\n", - " 'force_metric_ton': {'defined_symbol': 'tf',\n", - " 'aliases': ['metric_ton_force', 'force_t', 't_force'],\n", - " 'value': 'g_0 * metric_ton'},\n", - " 'atomic_unit_of_force': {'defined_symbol': 'a_u_force',\n", - " 'value': 'E_h / a_0'},\n", - " 'joule': {'defined_symbol': 'J', 'value': 'newton * meter'},\n", - " 'erg': {'value': 'dyne * centimeter'},\n", - " 'watt_hour': {'defined_symbol': 'Wh',\n", - " 'aliases': ['watthour'],\n", - " 'value': 'watt * hour'},\n", - " 'electron_volt': {'defined_symbol': 'eV', 'value': 'e * volt'},\n", - " 'rydberg': {'defined_symbol': 'Ry', 'value': 'ℎ * c * R_inf'},\n", - " 'hartree': {'defined_symbol': 'E_h',\n", - " 'aliases': ['Eh', 'hartree_energy', 'atomic_unit_of_energy', 'a_u_energy'],\n", - " 'value': '2 * rydberg'},\n", - " 'calorie': {'defined_symbol': 'cal',\n", - " 'aliases': ['thermochemical_calorie', 'cal_th'],\n", - " 'value': '4.184 * joule'},\n", - " 'international_calorie': {'defined_symbol': 'cal_it',\n", - " 'aliases': ['international_steam_table_calorie'],\n", - " 'value': '4.1868 * joule'},\n", - " 'fifteen_degree_calorie': {'defined_symbol': 'cal_15',\n", - " 'value': '4.1855 * joule'},\n", - " 'british_thermal_unit': {'defined_symbol': 'Btu',\n", - " 'aliases': ['BTU', 'Btu_iso'],\n", - " 'value': '1055.056 * joule'},\n", - " 'international_british_thermal_unit': {'defined_symbol': 'Btu_it',\n", - " 'value': '1e3 * pound / kilogram * degR / kelvin * international_calorie'},\n", - " 'thermochemical_british_thermal_unit': {'defined_symbol': 'Btu_th',\n", - " 'value': '1e3 * pound / kilogram * degR / kelvin * calorie'},\n", - " 'quadrillion_Btu': {'defined_symbol': 'quad', 'value': '1e15 * Btu'},\n", - " 'therm': {'defined_symbol': 'thm',\n", - " 'aliases': ['EC_therm'],\n", - " 'value': '1e5 * Btu'},\n", - " 'US_therm': {'value': '1.054804e8 * joule'},\n", - " 'ton_TNT': {'defined_symbol': 'tTNT', 'value': '1e9 * calorie'},\n", - " 'tonne_of_oil_equivalent': {'defined_symbol': 'toe',\n", - " 'value': '1e10 * international_calorie'},\n", - " 'atmosphere_liter': {'defined_symbol': 'atm_l',\n", - " 'value': 'atmosphere * liter'},\n", - " 'watt': {'defined_symbol': 'W', 'value': 'joule / second'},\n", - " 'volt_ampere': {'defined_symbol': 'VA', 'value': 'volt * ampere'},\n", - " 'horsepower': {'defined_symbol': 'hp',\n", - " 'aliases': ['UK_horsepower', 'hydraulic_horsepower'],\n", - " 'value': '550 * foot * force_pound / second'},\n", - " 'boiler_horsepower': {'value': '33475 * Btu / hour'},\n", - " 'metric_horsepower': {'value': '75 * force_kilogram * meter / second'},\n", - " 'electrical_horsepower': {'value': '746 * watt'},\n", - " 'refrigeration_ton': {'aliases': ['ton_of_refrigeration'],\n", - " 'value': '12e3 * Btu / hour'},\n", - " 'cooling_tower_ton': {'value': '1.25 * refrigeration_ton'},\n", - " 'standard_liter_per_minute': {'defined_symbol': 'slpm',\n", - " 'aliases': ['slm'],\n", - " 'value': 'atmosphere * liter / minute'},\n", - " 'conventional_watt_90': {'defined_symbol': 'W_90',\n", - " 'value': 'K_J90 ** 2 * R_K90 / (K_J ** 2 * R_K) * watt'},\n", - " 'mercury': {'defined_symbol': 'Hg',\n", - " 'aliases': ['Hg_0C', 'Hg_32F', 'conventional_mercury'],\n", - " 'value': '13.5951 * kilogram / liter'},\n", - " 'water': {'defined_symbol': 'H2O',\n", - " 'aliases': ['conventional_water'],\n", - " 'value': '1.0 * kilogram / liter'},\n", - " 'mercury_60F': {'defined_symbol': 'Hg_60F',\n", - " 'value': '13.5568 * kilogram / liter'},\n", - " 'water_39F': {'defined_symbol': 'water_4C',\n", - " 'value': '0.999972 * kilogram / liter'},\n", - " 'water_60F': {'value': '0.999001 * kilogram / liter'},\n", - " 'pascal': {'defined_symbol': 'Pa', 'value': 'newton / meter ** 2'},\n", - " 'barye': {'defined_symbol': 'Ba',\n", - " 'aliases': ['barie', 'barad', 'barrie', 'baryd'],\n", - " 'value': 'dyne / centimeter ** 2'},\n", - " 'bar': {'value': '1e5 * pascal'},\n", - " 'technical_atmosphere': {'defined_symbol': 'at',\n", - " 'value': 'kilogram * g_0 / centimeter ** 2'},\n", - " 'torr': {'value': 'atm / 760'},\n", - " 'pound_force_per_square_inch': {'defined_symbol': 'psi',\n", - " 'value': 'force_pound / inch ** 2'},\n", - " 'kip_per_square_inch': {'defined_symbol': 'ksi', 'value': 'kip / inch ** 2'},\n", - " 'millimeter_Hg': {'defined_symbol': 'mmHg',\n", - " 'aliases': ['mm_Hg', 'millimeter_Hg_0C'],\n", - " 'value': 'millimeter * Hg * g_0'},\n", - " 'centimeter_Hg': {'defined_symbol': 'cmHg',\n", - " 'aliases': ['cm_Hg', 'centimeter_Hg_0C'],\n", - " 'value': 'centimeter * Hg * g_0'},\n", - " 'inch_Hg': {'defined_symbol': 'inHg',\n", - " 'aliases': ['in_Hg', 'inch_Hg_32F'],\n", - " 'value': 'inch * Hg * g_0'},\n", - " 'inch_Hg_60F': {'value': 'inch * Hg_60F * g_0'},\n", - " 'inch_H2O_39F': {'value': 'inch * water_39F * g_0'},\n", - " 'inch_H2O_60F': {'value': 'inch * water_60F * g_0'},\n", - " 'foot_H2O': {'defined_symbol': 'ftH2O',\n", - " 'aliases': ['feet_H2O'],\n", - " 'value': 'foot * water * g_0'},\n", - " 'centimeter_H2O': {'defined_symbol': 'cmH2O',\n", - " 'aliases': ['cm_H2O'],\n", - " 'value': 'centimeter * water * g_0'},\n", - " 'sound_pressure_level': {'defined_symbol': 'SPL', 'value': '20e-6 * pascal'},\n", - " 'foot_pound': {'defined_symbol': 'ft_lb',\n", - " 'aliases': ['footpound'],\n", - " 'value': 'foot * force_pound'},\n", - " 'poise': {'defined_symbol': 'P', 'value': '0.1 * Pa * second'},\n", - " 'reyn': {'value': 'psi * second'},\n", - " 'stokes': {'defined_symbol': 'St', 'value': 'centimeter ** 2 / second'},\n", - " 'rhe': {'value': '1 / poise'},\n", - " 'particle': {'aliases': ['molec', 'molecule'], 'value': '1 / N_A'},\n", - " 'molar': {'defined_symbol': 'M', 'value': 'mole / liter'},\n", - " 'katal': {'defined_symbol': 'kat', 'value': 'mole / second'},\n", - " 'enzyme_unit': {'defined_symbol': 'U',\n", - " 'aliases': ['enzymeunit'],\n", - " 'value': 'micromole / minute'},\n", - " 'clausius': {'defined_symbol': 'Cl', 'value': 'calorie / kelvin'},\n", - " 'entropy_unit': {'defined_symbol': 'eu', 'value': 'calorie / kelvin / mole'},\n", - " 'becquerel': {'defined_symbol': 'Bq', 'value': 'counts_per_second'},\n", - " 'curie': {'defined_symbol': 'Ci', 'value': '3.7e10 * becquerel'},\n", - " 'rutherford': {'defined_symbol': 'Rd', 'value': '1e6 * becquerel'},\n", - " 'gray': {'defined_symbol': 'Gy', 'value': 'joule / kilogram'},\n", - " 'sievert': {'defined_symbol': 'Sv', 'value': 'joule / kilogram'},\n", - " 'rads': {'value': '0.01 * gray'},\n", - " 'rem': {'value': '0.01 * sievert'},\n", - " 'roentgen': {'aliases': ['röntgen'],\n", - " 'value': '2.58e-4 * coulomb / kilogram'},\n", - " 'peak_sun_hour': {'defined_symbol': 'PSH',\n", - " 'value': '1e3 * watt_hour / meter ** 2'},\n", - " 'langley': {'defined_symbol': 'Ly',\n", - " 'value': 'thermochemical_calorie / centimeter ** 2'},\n", - " 'nit': {'value': 'candela / meter ** 2'},\n", - " 'stilb': {'value': 'candela / centimeter ** 2'},\n", - " 'lambert': {'value': '1 / π * candela / centimeter ** 2'},\n", - " 'lumen': {'defined_symbol': 'lm', 'value': 'candela * steradian'},\n", - " 'lux': {'defined_symbol': 'lx', 'value': 'lumen / meter ** 2'},\n", - " 'atomic_unit_of_intensity': {'defined_symbol': 'a_u_intensity',\n", - " 'value': '0.5 * ε_0 * c * atomic_unit_of_electric_field ** 2'},\n", - " 'biot': {'defined_symbol': 'Bi', 'value': '10 * ampere'},\n", - " 'abampere': {'defined_symbol': 'abA', 'value': 'biot'},\n", - " 'atomic_unit_of_current': {'defined_symbol': 'a_u_current',\n", - " 'value': 'e / atomic_unit_of_time'},\n", - " 'mean_international_ampere': {'defined_symbol': 'A_it',\n", - " 'value': 'mean_international_volt / mean_international_ohm'},\n", - " 'US_international_ampere': {'defined_symbol': 'A_US',\n", - " 'value': 'US_international_volt / US_international_ohm'},\n", - " 'conventional_ampere_90': {'defined_symbol': 'A_90',\n", - " 'value': 'K_J90 * R_K90 / (K_J * R_K) * ampere'},\n", - " 'planck_current': {'value': '(c ** 6 / gravitational_constant / k_C) ** 0.5'},\n", - " 'coulomb': {'defined_symbol': 'C', 'value': 'ampere * second'},\n", - " 'abcoulomb': {'defined_symbol': 'abC', 'value': '10 * C'},\n", - " 'faraday': {'value': 'e * N_A * mole'},\n", - " 'conventional_coulomb_90': {'defined_symbol': 'C_90',\n", - " 'value': 'K_J90 * R_K90 / (K_J * R_K) * coulomb'},\n", - " 'ampere_hour': {'defined_symbol': 'Ah', 'value': 'ampere * hour'},\n", - " 'volt': {'defined_symbol': 'V', 'value': 'joule / coulomb'},\n", - " 'abvolt': {'defined_symbol': 'abV', 'value': '1e-8 * volt'},\n", - " 'mean_international_volt': {'defined_symbol': 'V_it',\n", - " 'value': '1.00034 * volt'},\n", - " 'US_international_volt': {'defined_symbol': 'V_US',\n", - " 'value': '1.00033 * volt'},\n", - " 'conventional_volt_90': {'defined_symbol': 'V_90',\n", - " 'value': 'K_J90 / K_J * volt'},\n", - " 'atomic_unit_of_electric_field': {'defined_symbol': 'a_u_electric_field',\n", - " 'value': 'e * k_C / a_0 ** 2'},\n", - " 'townsend': {'defined_symbol': 'Td', 'value': '1e-21 * V * m^2'},\n", - " 'ohm': {'defined_symbol': 'Ω', 'value': 'volt / ampere'},\n", - " 'abohm': {'defined_symbol': 'abΩ', 'value': '1e-9 * ohm'},\n", - " 'mean_international_ohm': {'defined_symbol': 'Ω_it',\n", - " 'aliases': ['ohm_it'],\n", - " 'value': '1.00049 * ohm'},\n", - " 'US_international_ohm': {'defined_symbol': 'Ω_US',\n", - " 'aliases': ['ohm_US'],\n", - " 'value': '1.000495 * ohm'},\n", - " 'conventional_ohm_90': {'defined_symbol': 'Ω_90',\n", - " 'aliases': ['ohm_90'],\n", - " 'value': 'R_K / R_K90 * ohm'},\n", - " 'siemens': {'defined_symbol': 'S',\n", - " 'aliases': ['mho'],\n", - " 'value': 'ampere / volt'},\n", - " 'absiemens': {'defined_symbol': 'abS',\n", - " 'aliases': ['abmho'],\n", - " 'value': '1e9 * siemens'},\n", - " 'farad': {'defined_symbol': 'F', 'value': 'coulomb / volt'},\n", - " 'abfarad': {'defined_symbol': 'abF', 'value': '1e9 * farad'},\n", - " 'conventional_farad_90': {'defined_symbol': 'F_90',\n", - " 'value': 'R_K90 / R_K * farad'},\n", - " 'weber': {'defined_symbol': 'Wb', 'value': 'volt * second'},\n", - " 'unit_pole': {'value': 'µ_0 * biot * centimeter'},\n", - " 'henry': {'defined_symbol': 'H', 'value': 'weber / ampere'},\n", - " 'abhenry': {'defined_symbol': 'abH', 'value': '1e-9 * henry'},\n", - " 'conventional_henry_90': {'defined_symbol': 'H_90',\n", - " 'value': 'R_K / R_K90 * henry'},\n", - " 'tesla': {'defined_symbol': 'T', 'value': 'weber / meter ** 2'},\n", - " 'gamma': {'defined_symbol': 'γ', 'value': '1e-9 * tesla'},\n", - " 'ampere_turn': {'defined_symbol': 'At', 'value': 'ampere'},\n", - " 'biot_turn': {'value': 'biot'},\n", - " 'gilbert': {'defined_symbol': 'Gb', 'value': '1 / (4 * π) * biot_turn'},\n", - " 'debye': {'defined_symbol': 'D', 'value': '1e-9 / ζ * coulomb * angstrom'},\n", - " 'buckingham': {'value': 'debye * angstrom'},\n", - " 'bohr_magneton': {'defined_symbol': 'µ_B',\n", - " 'aliases': ['mu_B'],\n", - " 'value': 'e * hbar / (2 * m_e)'},\n", - " 'nuclear_magneton': {'defined_symbol': 'µ_N',\n", - " 'aliases': ['mu_N'],\n", - " 'value': 'e * hbar / (2 * m_p)'},\n", - " 'refractive_index_unit': {'defined_symbol': 'RIU', 'value': '[]'},\n", - " 'decibelwatt': {'defined_symbol': 'dBW',\n", - " 'value': 'watt; logbase: 10; logfactor: 10'},\n", - " 'decibelmilliwatt': {'defined_symbol': 'dBm',\n", - " 'value': '1e-3 watt; logbase: 10; logfactor: 10'},\n", - " 'decibelmicrowatt': {'defined_symbol': 'dBu',\n", - " 'value': '1e-6 watt; logbase: 10; logfactor: 10'},\n", - " 'decibel': {'defined_symbol': 'dB',\n", - " 'value': '1 ; logbase: 10; logfactor: 10'},\n", - " 'decade': {'value': '1 ; logbase: 10; logfactor: 1'},\n", - " 'octave': {'defined_symbol': 'oct', 'value': '1 ; logbase: 2; logfactor: 1'},\n", - " 'neper': {'defined_symbol': 'Np',\n", - " 'value': '1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfactor: 0.5'},\n", - " 'thou': {'defined_symbol': 'th',\n", - " 'aliases': ['mil_length'],\n", - " 'value': '1e-3 * inch'},\n", - " 'inch': {'defined_symbol': 'in',\n", - " 'aliases': ['international_inch', 'inches', 'international_inches'],\n", - " 'value': 'yard / 36'},\n", - " 'hand': {'value': '4 * inch'},\n", - " 'foot': {'defined_symbol': 'ft',\n", - " 'aliases': ['international_foot', 'feet', 'international_feet'],\n", - " 'value': 'yard / 3'},\n", - " 'yard': {'defined_symbol': 'yd',\n", - " 'aliases': ['international_yard'],\n", - " 'value': '0.9144 * meter'},\n", - " 'mile': {'defined_symbol': 'mi',\n", - " 'aliases': ['international_mile'],\n", - " 'value': '1760 * yard'},\n", - " 'circular_mil': {'defined_symbol': 'cmil',\n", - " 'value': 'π / 4 * mil_length ** 2'},\n", - " 'square_inch': {'defined_symbol': 'sq_in',\n", - " 'aliases': ['square_inches'],\n", - " 'value': 'inch ** 2'},\n", - " 'square_foot': {'defined_symbol': 'sq_ft',\n", - " 'aliases': ['square_feet'],\n", - " 'value': 'foot ** 2'},\n", - " 'square_yard': {'defined_symbol': 'sq_yd', 'value': 'yard ** 2'},\n", - " 'square_mile': {'defined_symbol': 'sq_mi', 'value': 'mile ** 2'},\n", - " 'cubic_inch': {'defined_symbol': 'cu_in', 'value': 'in ** 3'},\n", - " 'cubic_foot': {'defined_symbol': 'cu_ft',\n", - " 'aliases': ['cubic_feet'],\n", - " 'value': 'ft ** 3'},\n", - " 'cubic_yard': {'defined_symbol': 'cu_yd', 'value': 'yd ** 3'},\n", - " 'link': {'defined_symbol': 'li',\n", - " 'aliases': ['survey_link'],\n", - " 'value': '1e-2 * chain'},\n", - " 'survey_foot': {'defined_symbol': 'sft', 'value': '1200 / 3937 * meter'},\n", - " 'fathom': {'value': '6 * survey_foot'},\n", - " 'rod': {'defined_symbol': 'rd',\n", - " 'aliases': ['pole', 'perch'],\n", - " 'value': '16.5 * survey_foot'},\n", - " 'chain': {'value': '4 * rod'},\n", - " 'furlong': {'defined_symbol': 'fur', 'value': '40 * rod'},\n", - " 'cables_length': {'value': '120 * fathom'},\n", - " 'survey_mile': {'defined_symbol': 'smi',\n", - " 'aliases': ['us_statute_mile'],\n", - " 'value': '5280 * survey_foot'},\n", - " 'league': {'value': '3 * survey_mile'},\n", - " 'square_rod': {'defined_symbol': 'sq_rod',\n", - " 'aliases': ['sq_pole', 'sq_perch'],\n", - " 'value': 'rod ** 2'},\n", - " 'acre': {'value': '10 * chain ** 2'},\n", - " 'square_survey_mile': {'aliases': ['section'], 'value': 'survey_mile ** 2'},\n", - " 'square_league': {'value': 'league ** 2'},\n", - " 'acre_foot': {'aliases': ['acre_feet'], 'value': 'acre * survey_foot'},\n", - " 'dry_pint': {'defined_symbol': 'dpi',\n", - " 'aliases': ['US_dry_pint'],\n", - " 'value': 'bushel / 64'},\n", - " 'dry_quart': {'defined_symbol': 'dqt',\n", - " 'aliases': ['US_dry_quart'],\n", - " 'value': 'bushel / 32'},\n", - " 'dry_gallon': {'defined_symbol': 'dgal',\n", - " 'aliases': ['US_dry_gallon'],\n", - " 'value': 'bushel / 8'},\n", - " 'peck': {'defined_symbol': 'pk', 'value': 'bushel / 4'},\n", - " 'bushel': {'defined_symbol': 'bu', 'value': '2150.42 cubic_inch'},\n", - " 'dry_barrel': {'aliases': ['US_dry_barrel'], 'value': '7056 cubic_inch'},\n", - " 'board_foot': {'defined_symbol': 'FBM',\n", - " 'aliases': ['board_feet',\n", - " 'BF',\n", - " 'BDFT',\n", - " 'super_foot',\n", - " 'superficial_foot',\n", - " 'super_feet',\n", - " 'superficial_feet'],\n", - " 'value': 'ft * ft * in'},\n", - " 'minim': {'value': 'pint / 7680'},\n", - " 'fluid_dram': {'defined_symbol': 'fldr',\n", - " 'aliases': ['fluidram', 'US_fluid_dram', 'US_liquid_dram'],\n", - " 'value': 'pint / 128'},\n", - " 'fluid_ounce': {'defined_symbol': 'floz',\n", - " 'aliases': ['US_fluid_ounce', 'US_liquid_ounce'],\n", - " 'value': 'pint / 16'},\n", - " 'gill': {'defined_symbol': 'gi',\n", - " 'aliases': ['liquid_gill', 'US_liquid_gill'],\n", - " 'value': 'pint / 4'},\n", - " 'pint': {'defined_symbol': 'pt',\n", - " 'aliases': ['liquid_pint', 'US_pint'],\n", - " 'value': 'quart / 2'},\n", - " 'fifth': {'aliases': ['US_liquid_fifth'], 'value': 'gallon / 5'},\n", - " 'quart': {'defined_symbol': 'qt',\n", - " 'aliases': ['liquid_quart', 'US_liquid_quart'],\n", - " 'value': 'gallon / 4'},\n", - " 'gallon': {'defined_symbol': 'gal',\n", - " 'aliases': ['liquid_gallon', 'US_liquid_gallon'],\n", - " 'value': '231 * cubic_inch'},\n", - " 'teaspoon': {'defined_symbol': 'tsp', 'value': 'fluid_ounce / 6'},\n", - " 'tablespoon': {'defined_symbol': 'tbsp', 'value': 'fluid_ounce / 2'},\n", - " 'shot': {'defined_symbol': 'jig',\n", - " 'aliases': ['US_shot'],\n", - " 'value': '3 * tablespoon'},\n", - " 'cup': {'defined_symbol': 'cp',\n", - " 'aliases': ['liquid_cup', 'US_liquid_cup'],\n", - " 'value': 'pint / 2'},\n", - " 'barrel': {'defined_symbol': 'bbl', 'value': '31.5 * gallon'},\n", - " 'oil_barrel': {'defined_symbol': 'oil_bbl', 'value': '42 * gallon'},\n", - " 'beer_barrel': {'defined_symbol': 'beer_bbl', 'value': '31 * gallon'},\n", - " 'hogshead': {'value': '63 * gallon'},\n", - " 'dram': {'defined_symbol': 'dr',\n", - " 'aliases': ['avoirdupois_dram', 'avdp_dram', 'drachm'],\n", - " 'value': 'pound / 256'},\n", - " 'ounce': {'defined_symbol': 'oz',\n", - " 'aliases': ['avoirdupois_ounce', 'avdp_ounce'],\n", - " 'value': 'pound / 16'},\n", - " 'pound': {'defined_symbol': 'lb',\n", - " 'aliases': ['avoirdupois_pound', 'avdp_pound'],\n", - " 'value': '7e3 * grain'},\n", - " 'stone': {'value': '14 * pound'},\n", - " 'quarter': {'value': '28 * stone'},\n", - " 'bag': {'value': '94 * pound'},\n", - " 'hundredweight': {'defined_symbol': 'cwt',\n", - " 'aliases': ['short_hundredweight'],\n", - " 'value': '100 * pound'},\n", - " 'long_hundredweight': {'value': '112 * pound'},\n", - " 'ton': {'aliases': ['short_ton'], 'value': '2e3 * pound'},\n", - " 'long_ton': {'value': '2240 * pound'},\n", - " 'slug': {'value': 'g_0 * pound * second ** 2 / foot'},\n", - " 'slinch': {'defined_symbol': 'blob',\n", - " 'aliases': ['slugette'],\n", - " 'value': 'g_0 * pound * second ** 2 / inch'},\n", - " 'force_ounce': {'defined_symbol': 'ozf',\n", - " 'aliases': ['ounce_force'],\n", - " 'value': 'g_0 * ounce'},\n", - " 'force_pound': {'defined_symbol': 'lbf',\n", - " 'aliases': ['pound_force'],\n", - " 'value': 'g_0 * pound'},\n", - " 'force_ton': {'aliases': ['ton_force', 'force_short_ton', 'short_ton_force'],\n", - " 'value': 'g_0 * ton'},\n", - " 'force_long_ton': {'aliases': ['long_ton_force'], 'value': 'g_0 * long_ton'},\n", - " 'kip': {'value': '1e3 * force_pound'},\n", - " 'poundal': {'defined_symbol': 'pdl', 'value': 'pound * foot / second ** 2'},\n", - " 'UK_hundredweight': {'defined_symbol': 'UK_cwt',\n", - " 'value': 'long_hundredweight'},\n", - " 'UK_ton': {'value': 'long_ton'},\n", - " 'UK_force_ton': {'aliases': ['UK_ton_force'], 'value': 'force_long_ton'},\n", - " 'US_hundredweight': {'defined_symbol': 'US_cwt', 'value': 'hundredweight'},\n", - " 'US_ton': {'value': 'ton'},\n", - " 'US_force_ton': {'aliases': ['US_ton_force'], 'value': 'force_ton'},\n", - " 'pennyweight': {'defined_symbol': 'dwt', 'value': '24 * grain'},\n", - " 'troy_ounce': {'defined_symbol': 'toz',\n", - " 'aliases': ['ozt'],\n", - " 'value': '480 * grain'},\n", - " 'troy_pound': {'defined_symbol': 'tlb',\n", - " 'aliases': ['lbt'],\n", - " 'value': '12 * troy_ounce'},\n", - " 'scruple': {'value': '20 * grain'},\n", - " 'apothecary_dram': {'defined_symbol': 'ap_dr', 'value': '3 * scruple'},\n", - " 'apothecary_ounce': {'defined_symbol': 'ap_oz',\n", - " 'value': '8 * apothecary_dram'},\n", - " 'apothecary_pound': {'defined_symbol': 'ap_lb',\n", - " 'value': '12 * apothecary_ounce'},\n", - " 'imperial_minim': {'value': 'imperial_fluid_ounce / 480'},\n", - " 'imperial_fluid_scruple': {'value': 'imperial_fluid_ounce / 24'},\n", - " 'imperial_fluid_drachm': {'defined_symbol': 'imperial_fldr',\n", - " 'aliases': ['imperial_fluid_dram'],\n", - " 'value': 'imperial_fluid_ounce / 8'},\n", - " 'imperial_fluid_ounce': {'defined_symbol': 'imperial_floz',\n", - " 'aliases': ['UK_fluid_ounce'],\n", - " 'value': 'imperial_pint / 20'},\n", - " 'imperial_gill': {'defined_symbol': 'imperial_gi',\n", - " 'aliases': ['UK_gill'],\n", - " 'value': 'imperial_pint / 4'},\n", - " 'imperial_cup': {'defined_symbol': 'imperial_cp',\n", - " 'aliases': ['UK_cup'],\n", - " 'value': 'imperial_pint / 2'},\n", - " 'imperial_pint': {'defined_symbol': 'imperial_pt',\n", - " 'aliases': ['UK_pint'],\n", - " 'value': 'imperial_gallon / 8'},\n", - " 'imperial_quart': {'defined_symbol': 'imperial_qt',\n", - " 'aliases': ['UK_quart'],\n", - " 'value': 'imperial_gallon / 4'},\n", - " 'imperial_gallon': {'defined_symbol': 'imperial_gal',\n", - " 'aliases': ['UK_gallon'],\n", - " 'value': '4.54609 * liter'},\n", - " 'imperial_peck': {'defined_symbol': 'imperial_pk',\n", - " 'aliases': ['UK_pk'],\n", - " 'value': '2 * imperial_gallon'},\n", - " 'imperial_bushel': {'defined_symbol': 'imperial_bu',\n", - " 'aliases': ['UK_bushel'],\n", - " 'value': '8 * imperial_gallon'},\n", - " 'imperial_barrel': {'defined_symbol': 'imperial_bbl',\n", - " 'aliases': ['UK_bbl'],\n", - " 'value': '36 * imperial_gallon'},\n", - " 'pica': {'aliases': ['printers_pica'], 'value': 'inch / 6'},\n", - " 'point': {'defined_symbol': 'pp',\n", - " 'aliases': ['printers_point', 'big_point', 'bp'],\n", - " 'value': 'pica / 12'},\n", - " 'didot': {'value': '1 / 2660 * m'},\n", - " 'cicero': {'value': '12 * didot'},\n", - " 'tex_point': {'value': 'inch / 72.27'},\n", - " 'tex_pica': {'value': '12 * tex_point'},\n", - " 'tex_didot': {'value': '1238 / 1157 * tex_point'},\n", - " 'tex_cicero': {'value': '12 * tex_didot'},\n", - " 'scaled_point': {'value': 'tex_point / 65536'},\n", - " 'css_pixel': {'defined_symbol': 'px', 'value': 'inch / 96'},\n", - " 'pixel': {'aliases': ['dot', 'pel', 'picture_element'],\n", - " 'value': '[printing_unit]'},\n", - " 'pixels_per_centimeter': {'defined_symbol': 'PPCM', 'value': 'pixel / cm'},\n", - " 'pixels_per_inch': {'defined_symbol': 'dots_per_inch',\n", - " 'aliases': ['PPI', 'ppi', 'DPI', 'printers_dpi'],\n", - " 'value': 'pixel / inch'},\n", - " 'bits_per_pixel': {'defined_symbol': 'bpp', 'value': 'bit / pixel'},\n", - " 'tex': {'defined_symbol': 'Tt', 'value': 'gram / kilometer'},\n", - " 'dtex': {'value': 'decitex'},\n", - " 'denier': {'defined_symbol': 'den', 'value': 'gram / (9 * kilometer)'},\n", - " 'jute': {'defined_symbol': 'Tj', 'value': 'pound / (14400 * yard)'},\n", - " 'aberdeen': {'defined_symbol': 'Ta', 'value': 'jute'},\n", - " 'RKM': {'value': 'gf / tex'},\n", - " 'number_english': {'defined_symbol': 'Ne',\n", - " 'aliases': ['NeC', 'ECC'],\n", - " 'value': '840 * yard / pound'},\n", - " 'number_meter': {'defined_symbol': 'Nm', 'value': 'kilometer / kilogram'},\n", - " 'franklin': {'defined_symbol': 'Fr',\n", - " 'aliases': ['statcoulomb', 'statC', 'esu'],\n", - " 'value': 'erg ** 0.5 * centimeter ** 0.5'},\n", - " 'statvolt': {'defined_symbol': 'statV', 'value': 'erg / franklin'},\n", - " 'statampere': {'defined_symbol': 'statA', 'value': 'franklin / second'},\n", - " 'gauss': {'defined_symbol': 'G', 'value': 'dyne / franklin'},\n", - " 'maxwell': {'defined_symbol': 'Mx', 'value': 'gauss * centimeter ** 2'},\n", - " 'oersted': {'defined_symbol': 'Oe',\n", - " 'aliases': ['ørsted'],\n", - " 'value': 'dyne / maxwell'},\n", - " 'statohm': {'defined_symbol': 'statΩ', 'value': 'statvolt / statampere'},\n", - " 'statfarad': {'defined_symbol': 'statF', 'value': 'franklin / statvolt'},\n", - " 'statmho': {'value': 'statampere / statvolt'},\n", - " 'statweber': {'defined_symbol': 'statWb', 'value': 'statvolt * second'},\n", - " 'stattesla': {'defined_symbol': 'statT',\n", - " 'value': 'statweber / centimeter ** 2'},\n", - " 'stathenry': {'defined_symbol': 'statH', 'value': 'statweber / statampere'}},\n", - " 'dimension': {'[area]': {'value': '[length] ** 2'},\n", - " '[volume]': {'value': '[length] ** 3'},\n", - " '[frequency]': {'value': '1 / [time]'},\n", - " '[wavenumber]': {'value': '1 / [length]'},\n", - " '[velocity]': {'value': '[length] / [time]'},\n", - " '[speed]': {'value': '[velocity]'},\n", - " '[volumetric_flow_rate]': {'value': '[volume] / [time]'},\n", - " '[acceleration]': {'value': '[velocity] / [time]'},\n", - " '[force]': {'value': '[mass] * [acceleration]'},\n", - " '[energy]': {'value': '[force] * [length]'},\n", - " '[power]': {'value': '[energy] / [time]'},\n", - " '[momentum]': {'value': '[length] * [mass] / [time]'},\n", - " '[density]': {'value': '[mass] / [volume]'},\n", - " '[pressure]': {'value': '[force] / [area]'},\n", - " '[torque]': {'value': '[force] * [length]'},\n", - " '[viscosity]': {'value': '[pressure] * [time]'},\n", - " '[kinematic_viscosity]': {'value': '[area] / [time]'},\n", - " '[fluidity]': {'value': '1 / [viscosity]'},\n", - " '[concentration]': {'value': '[substance] / [volume]'},\n", - " '[activity]': {'value': '[substance] / [time]'},\n", - " '[entropy]': {'value': '[energy] / [temperature]'},\n", - " '[molar_entropy]': {'value': '[entropy] / [substance]'},\n", - " '[heat_transmission]': {'value': '[energy] / [area]'},\n", - " '[luminance]': {'value': '[luminosity] / [area]'},\n", - " '[luminous_flux]': {'value': '[luminosity]'},\n", - " '[illuminance]': {'value': '[luminous_flux] / [area]'},\n", - " '[intensity]': {'value': '[power] / [area]'},\n", - " '[charge]': {'value': '[current] * [time]'},\n", - " '[electric_potential]': {'value': '[energy] / [charge]'},\n", - " '[electric_field]': {'value': '[electric_potential] / [length]'},\n", - " '[electric_displacement_field]': {'value': '[charge] / [area]'},\n", - " '[reduced_electric_field]': {'value': '[electric_field] * [area]'},\n", - " '[resistance]': {'value': '[electric_potential] / [current]'},\n", - " '[resistivity]': {'value': '[resistance] * [length]'},\n", - " '[conductance]': {'value': '[current] / [electric_potential]'},\n", - " '[capacitance]': {'value': '[charge] / [electric_potential]'},\n", - " '[magnetic_flux]': {'value': '[electric_potential] * [time]'},\n", - " '[inductance]': {'value': '[magnetic_flux] / [current]'},\n", - " '[magnetic_field]': {'value': '[magnetic_flux] / [area]'},\n", - " '[magnetomotive_force]': {'value': '[current]'},\n", - " '[magnetic_field_strength]': {'value': '[current] / [length]'},\n", - " '[electric_dipole]': {'value': '[charge] * [length]'},\n", - " '[electric_quadrupole]': {'value': '[charge] * [area]'},\n", - " '[magnetic_dipole]': {'value': '[current] * [area]'},\n", - " '[refractive_index]': {'value': '[]'},\n", - " '[gaussian_charge]': {'value': '[length] ** 1.5 * [mass] ** 0.5 / [time]'},\n", - " '[gaussian_current]': {'value': '[gaussian_charge] / [time]'},\n", - " '[gaussian_electric_potential]': {'value': '[gaussian_charge] / [length]'},\n", - " '[gaussian_electric_field]': {'value': '[gaussian_electric_potential] / [length]'},\n", - " '[gaussian_electric_displacement_field]': {'value': '[gaussian_charge] / [area]'},\n", - " '[gaussian_electric_flux]': {'value': '[gaussian_charge]'},\n", - " '[gaussian_electric_dipole]': {'value': '[gaussian_charge] * [length]'},\n", - " '[gaussian_electric_quadrupole]': {'value': '[gaussian_charge] * [area]'},\n", - " '[gaussian_magnetic_field]': {'value': '[force] / [gaussian_charge]'},\n", - " '[gaussian_magnetic_field_strength]': {'value': '[gaussian_magnetic_field]'},\n", - " '[gaussian_magnetic_flux]': {'value': '[gaussian_magnetic_field] * [area]'},\n", - " '[gaussian_magnetic_dipole]': {'value': '[energy] / [gaussian_magnetic_field]'},\n", - " '[gaussian_resistance]': {'value': '[gaussian_electric_potential] / [gaussian_current]'},\n", - " '[gaussian_resistivity]': {'value': '[gaussian_resistance] * [length]'},\n", - " '[gaussian_capacitance]': {'value': '[gaussian_charge] / [gaussian_electric_potential]'},\n", - " '[gaussian_inductance]': {'value': '[gaussian_electric_potential] * [time] / [gaussian_current]'},\n", - " '[gaussian_conductance]': {'value': '[gaussian_current] / [gaussian_electric_potential]'},\n", - " '[esu_charge]': {'value': '[length] ** 1.5 * [mass] ** 0.5 / [time]'},\n", - " '[esu_current]': {'value': '[esu_charge] / [time]'},\n", - " '[esu_electric_potential]': {'value': '[esu_charge] / [length]'},\n", - " '[esu_magnetic_flux]': {'value': '[esu_electric_potential] * [time]'},\n", - " '[esu_magnetic_field]': {'value': '[esu_magnetic_flux] / [area]'},\n", - " '[esu_magnetic_field_strength]': {'value': '[esu_current] / [length]'},\n", - " '[esu_magnetic_dipole]': {'value': '[esu_current] * [area]'}},\n", - " 'group': {'USCSLengthInternational': {'definitions': {'thou': {'defined_symbol': 'th',\n", - " 'aliases': ['mil_length'],\n", - " 'value': '1e-3 * inch'},\n", - " 'inch': {'defined_symbol': 'in',\n", - " 'aliases': ['international_inch', 'inches', 'international_inches'],\n", - " 'value': 'yard / 36'},\n", - " 'hand': {'value': '4 * inch'},\n", - " 'foot': {'defined_symbol': 'ft',\n", - " 'aliases': ['international_foot', 'feet', 'international_feet'],\n", - " 'value': 'yard / 3'},\n", - " 'yard': {'defined_symbol': 'yd',\n", - " 'aliases': ['international_yard'],\n", - " 'value': '0.9144 * meter'},\n", - " 'mile': {'defined_symbol': 'mi',\n", - " 'aliases': ['international_mile'],\n", - " 'value': '1760 * yard'},\n", - " 'circular_mil': {'defined_symbol': 'cmil',\n", - " 'value': 'π / 4 * mil_length ** 2'},\n", - " 'square_inch': {'defined_symbol': 'sq_in',\n", - " 'aliases': ['square_inches'],\n", - " 'value': 'inch ** 2'},\n", - " 'square_foot': {'defined_symbol': 'sq_ft',\n", - " 'aliases': ['square_feet'],\n", - " 'value': 'foot ** 2'},\n", - " 'square_yard': {'defined_symbol': 'sq_yd', 'value': 'yard ** 2'},\n", - " 'square_mile': {'defined_symbol': 'sq_mi', 'value': 'mile ** 2'},\n", - " 'cubic_inch': {'defined_symbol': 'cu_in', 'value': 'in ** 3'},\n", - " 'cubic_foot': {'defined_symbol': 'cu_ft',\n", - " 'aliases': ['cubic_feet'],\n", - " 'value': 'ft ** 3'},\n", - " 'cubic_yard': {'defined_symbol': 'cu_yd', 'value': 'yd ** 3'}}},\n", - " 'USCSLengthSurvey': {'definitions': {'link': {'defined_symbol': 'li',\n", - " 'aliases': ['survey_link'],\n", - " 'value': '1e-2 * chain'},\n", - " 'survey_foot': {'defined_symbol': 'sft', 'value': '1200 / 3937 * meter'},\n", - " 'fathom': {'value': '6 * survey_foot'},\n", - " 'rod': {'defined_symbol': 'rd',\n", - " 'aliases': ['pole', 'perch'],\n", - " 'value': '16.5 * survey_foot'},\n", - " 'chain': {'value': '4 * rod'},\n", - " 'furlong': {'defined_symbol': 'fur', 'value': '40 * rod'},\n", - " 'cables_length': {'value': '120 * fathom'},\n", - " 'survey_mile': {'defined_symbol': 'smi',\n", - " 'aliases': ['us_statute_mile'],\n", - " 'value': '5280 * survey_foot'},\n", - " 'league': {'value': '3 * survey_mile'},\n", - " 'square_rod': {'defined_symbol': 'sq_rod',\n", - " 'aliases': ['sq_pole', 'sq_perch'],\n", - " 'value': 'rod ** 2'},\n", - " 'acre': {'value': '10 * chain ** 2'},\n", - " 'square_survey_mile': {'aliases': ['section'],\n", - " 'value': 'survey_mile ** 2'},\n", - " 'square_league': {'value': 'league ** 2'},\n", - " 'acre_foot': {'aliases': ['acre_feet'], 'value': 'acre * survey_foot'}}},\n", - " 'USCSDryVolume': {'definitions': {'dry_pint': {'defined_symbol': 'dpi',\n", - " 'aliases': ['US_dry_pint'],\n", - " 'value': 'bushel / 64'},\n", - " 'dry_quart': {'defined_symbol': 'dqt',\n", - " 'aliases': ['US_dry_quart'],\n", - " 'value': 'bushel / 32'},\n", - " 'dry_gallon': {'defined_symbol': 'dgal',\n", - " 'aliases': ['US_dry_gallon'],\n", - " 'value': 'bushel / 8'},\n", - " 'peck': {'defined_symbol': 'pk', 'value': 'bushel / 4'},\n", - " 'bushel': {'defined_symbol': 'bu', 'value': '2150.42 cubic_inch'},\n", - " 'dry_barrel': {'aliases': ['US_dry_barrel'], 'value': '7056 cubic_inch'},\n", - " 'board_foot': {'defined_symbol': 'FBM',\n", - " 'aliases': ['board_feet',\n", - " 'BF',\n", - " 'BDFT',\n", - " 'super_foot',\n", - " 'superficial_foot',\n", - " 'super_feet',\n", - " 'superficial_feet'],\n", - " 'value': 'ft * ft * in'}}},\n", - " 'USCSLiquidVolume': {'definitions': {'minim': {'value': 'pint / 7680'},\n", - " 'fluid_dram': {'defined_symbol': 'fldr',\n", - " 'aliases': ['fluidram', 'US_fluid_dram', 'US_liquid_dram'],\n", - " 'value': 'pint / 128'},\n", - " 'fluid_ounce': {'defined_symbol': 'floz',\n", - " 'aliases': ['US_fluid_ounce', 'US_liquid_ounce'],\n", - " 'value': 'pint / 16'},\n", - " 'gill': {'defined_symbol': 'gi',\n", - " 'aliases': ['liquid_gill', 'US_liquid_gill'],\n", - " 'value': 'pint / 4'},\n", - " 'pint': {'defined_symbol': 'pt',\n", - " 'aliases': ['liquid_pint', 'US_pint'],\n", - " 'value': 'quart / 2'},\n", - " 'fifth': {'aliases': ['US_liquid_fifth'], 'value': 'gallon / 5'},\n", - " 'quart': {'defined_symbol': 'qt',\n", - " 'aliases': ['liquid_quart', 'US_liquid_quart'],\n", - " 'value': 'gallon / 4'},\n", - " 'gallon': {'defined_symbol': 'gal',\n", - " 'aliases': ['liquid_gallon', 'US_liquid_gallon'],\n", - " 'value': '231 * cubic_inch'}}},\n", - " 'USCSVolumeOther': {'definitions': {'teaspoon': {'defined_symbol': 'tsp',\n", - " 'value': 'fluid_ounce / 6'},\n", - " 'tablespoon': {'defined_symbol': 'tbsp', 'value': 'fluid_ounce / 2'},\n", - " 'shot': {'defined_symbol': 'jig',\n", - " 'aliases': ['US_shot'],\n", - " 'value': '3 * tablespoon'},\n", - " 'cup': {'defined_symbol': 'cp',\n", - " 'aliases': ['liquid_cup', 'US_liquid_cup'],\n", - " 'value': 'pint / 2'},\n", - " 'barrel': {'defined_symbol': 'bbl', 'value': '31.5 * gallon'},\n", - " 'oil_barrel': {'defined_symbol': 'oil_bbl', 'value': '42 * gallon'},\n", - " 'beer_barrel': {'defined_symbol': 'beer_bbl', 'value': '31 * gallon'},\n", - " 'hogshead': {'value': '63 * gallon'}}},\n", - " 'Avoirdupois': {'definitions': {'dram': {'defined_symbol': 'dr',\n", - " 'aliases': ['avoirdupois_dram', 'avdp_dram', 'drachm'],\n", - " 'value': 'pound / 256'},\n", - " 'ounce': {'defined_symbol': 'oz',\n", - " 'aliases': ['avoirdupois_ounce', 'avdp_ounce'],\n", - " 'value': 'pound / 16'},\n", - " 'pound': {'defined_symbol': 'lb',\n", - " 'aliases': ['avoirdupois_pound', 'avdp_pound'],\n", - " 'value': '7e3 * grain'},\n", - " 'stone': {'value': '14 * pound'},\n", - " 'quarter': {'value': '28 * stone'},\n", - " 'bag': {'value': '94 * pound'},\n", - " 'hundredweight': {'defined_symbol': 'cwt',\n", - " 'aliases': ['short_hundredweight'],\n", - " 'value': '100 * pound'},\n", - " 'long_hundredweight': {'value': '112 * pound'},\n", - " 'ton': {'aliases': ['short_ton'], 'value': '2e3 * pound'},\n", - " 'long_ton': {'value': '2240 * pound'},\n", - " 'slug': {'value': 'g_0 * pound * second ** 2 / foot'},\n", - " 'slinch': {'defined_symbol': 'blob',\n", - " 'aliases': ['slugette'],\n", - " 'value': 'g_0 * pound * second ** 2 / inch'},\n", - " 'force_ounce': {'defined_symbol': 'ozf',\n", - " 'aliases': ['ounce_force'],\n", - " 'value': 'g_0 * ounce'},\n", - " 'force_pound': {'defined_symbol': 'lbf',\n", - " 'aliases': ['pound_force'],\n", - " 'value': 'g_0 * pound'},\n", - " 'force_ton': {'aliases': ['ton_force',\n", - " 'force_short_ton',\n", - " 'short_ton_force'],\n", - " 'value': 'g_0 * ton'},\n", - " 'force_long_ton': {'aliases': ['long_ton_force'],\n", - " 'value': 'g_0 * long_ton'},\n", - " 'kip': {'value': '1e3 * force_pound'},\n", - " 'poundal': {'defined_symbol': 'pdl',\n", - " 'value': 'pound * foot / second ** 2'}}},\n", - " 'AvoirdupoisUK': {'using_group_names': ['Avoirdupois'],\n", - " 'definitions': {'UK_hundredweight': {'defined_symbol': 'UK_cwt',\n", - " 'value': 'long_hundredweight'},\n", - " 'UK_ton': {'value': 'long_ton'},\n", - " 'UK_force_ton': {'aliases': ['UK_ton_force'], 'value': 'force_long_ton'}}},\n", - " 'AvoirdupoisUS': {'using_group_names': ['Avoirdupois'],\n", - " 'definitions': {'US_hundredweight': {'defined_symbol': 'US_cwt',\n", - " 'value': 'hundredweight'},\n", - " 'US_ton': {'value': 'ton'},\n", - " 'US_force_ton': {'aliases': ['US_ton_force'], 'value': 'force_ton'}}},\n", - " 'Troy': {'definitions': {'pennyweight': {'defined_symbol': 'dwt',\n", - " 'value': '24 * grain'},\n", - " 'troy_ounce': {'defined_symbol': 'toz',\n", - " 'aliases': ['ozt'],\n", - " 'value': '480 * grain'},\n", - " 'troy_pound': {'defined_symbol': 'tlb',\n", - " 'aliases': ['lbt'],\n", - " 'value': '12 * troy_ounce'}}},\n", - " 'Apothecary': {'definitions': {'scruple': {'value': '20 * grain'},\n", - " 'apothecary_dram': {'defined_symbol': 'ap_dr', 'value': '3 * scruple'},\n", - " 'apothecary_ounce': {'defined_symbol': 'ap_oz',\n", - " 'value': '8 * apothecary_dram'},\n", - " 'apothecary_pound': {'defined_symbol': 'ap_lb',\n", - " 'value': '12 * apothecary_ounce'}}},\n", - " 'ImperialVolume': {'definitions': {'imperial_minim': {'value': 'imperial_fluid_ounce / 480'},\n", - " 'imperial_fluid_scruple': {'value': 'imperial_fluid_ounce / 24'},\n", - " 'imperial_fluid_drachm': {'defined_symbol': 'imperial_fldr',\n", - " 'aliases': ['imperial_fluid_dram'],\n", - " 'value': 'imperial_fluid_ounce / 8'},\n", - " 'imperial_fluid_ounce': {'defined_symbol': 'imperial_floz',\n", - " 'aliases': ['UK_fluid_ounce'],\n", - " 'value': 'imperial_pint / 20'},\n", - " 'imperial_gill': {'defined_symbol': 'imperial_gi',\n", - " 'aliases': ['UK_gill'],\n", - " 'value': 'imperial_pint / 4'},\n", - " 'imperial_cup': {'defined_symbol': 'imperial_cp',\n", - " 'aliases': ['UK_cup'],\n", - " 'value': 'imperial_pint / 2'},\n", - " 'imperial_pint': {'defined_symbol': 'imperial_pt',\n", - " 'aliases': ['UK_pint'],\n", - " 'value': 'imperial_gallon / 8'},\n", - " 'imperial_quart': {'defined_symbol': 'imperial_qt',\n", - " 'aliases': ['UK_quart'],\n", - " 'value': 'imperial_gallon / 4'},\n", - " 'imperial_gallon': {'defined_symbol': 'imperial_gal',\n", - " 'aliases': ['UK_gallon'],\n", - " 'value': '4.54609 * liter'},\n", - " 'imperial_peck': {'defined_symbol': 'imperial_pk',\n", - " 'aliases': ['UK_pk'],\n", - " 'value': '2 * imperial_gallon'},\n", - " 'imperial_bushel': {'defined_symbol': 'imperial_bu',\n", - " 'aliases': ['UK_bushel'],\n", - " 'value': '8 * imperial_gallon'},\n", - " 'imperial_barrel': {'defined_symbol': 'imperial_bbl',\n", - " 'aliases': ['UK_bbl'],\n", - " 'value': '36 * imperial_gallon'}}},\n", - " 'Printer': {'definitions': {'pica': {'aliases': ['printers_pica'],\n", - " 'value': 'inch / 6'},\n", - " 'point': {'defined_symbol': 'pp',\n", - " 'aliases': ['printers_point', 'big_point', 'bp'],\n", - " 'value': 'pica / 12'},\n", - " 'didot': {'value': '1 / 2660 * m'},\n", - " 'cicero': {'value': '12 * didot'},\n", - " 'tex_point': {'value': 'inch / 72.27'},\n", - " 'tex_pica': {'value': '12 * tex_point'},\n", - " 'tex_didot': {'value': '1238 / 1157 * tex_point'},\n", - " 'tex_cicero': {'value': '12 * tex_didot'},\n", - " 'scaled_point': {'value': 'tex_point / 65536'},\n", - " 'css_pixel': {'defined_symbol': 'px', 'value': 'inch / 96'},\n", - " 'pixel': {'aliases': ['dot', 'pel', 'picture_element'],\n", - " 'value': '[printing_unit]'},\n", - " 'pixels_per_centimeter': {'defined_symbol': 'PPCM', 'value': 'pixel / cm'},\n", - " 'pixels_per_inch': {'defined_symbol': 'dots_per_inch',\n", - " 'aliases': ['PPI', 'ppi', 'DPI', 'printers_dpi'],\n", - " 'value': 'pixel / inch'},\n", - " 'bits_per_pixel': {'defined_symbol': 'bpp', 'value': 'bit / pixel'}}},\n", - " 'Textile': {'definitions': {'tex': {'defined_symbol': 'Tt',\n", - " 'value': 'gram / kilometer'},\n", - " 'dtex': {'value': 'decitex'},\n", - " 'denier': {'defined_symbol': 'den', 'value': 'gram / (9 * kilometer)'},\n", - " 'jute': {'defined_symbol': 'Tj', 'value': 'pound / (14400 * yard)'},\n", - " 'aberdeen': {'defined_symbol': 'Ta', 'value': 'jute'},\n", - " 'RKM': {'value': 'gf / tex'},\n", - " 'number_english': {'defined_symbol': 'Ne',\n", - " 'aliases': ['NeC', 'ECC'],\n", - " 'value': '840 * yard / pound'},\n", - " 'number_meter': {'defined_symbol': 'Nm',\n", - " 'value': 'kilometer / kilogram'}}},\n", - " 'Gaussian': {'definitions': {'franklin': {'defined_symbol': 'Fr',\n", - " 'aliases': ['statcoulomb', 'statC', 'esu'],\n", - " 'value': 'erg ** 0.5 * centimeter ** 0.5'},\n", - " 'statvolt': {'defined_symbol': 'statV', 'value': 'erg / franklin'},\n", - " 'statampere': {'defined_symbol': 'statA', 'value': 'franklin / second'},\n", - " 'gauss': {'defined_symbol': 'G', 'value': 'dyne / franklin'},\n", - " 'maxwell': {'defined_symbol': 'Mx', 'value': 'gauss * centimeter ** 2'},\n", - " 'oersted': {'defined_symbol': 'Oe',\n", - " 'aliases': ['ørsted'],\n", - " 'value': 'dyne / maxwell'},\n", - " 'statohm': {'defined_symbol': 'statΩ', 'value': 'statvolt / statampere'},\n", - " 'statfarad': {'defined_symbol': 'statF', 'value': 'franklin / statvolt'},\n", - " 'statmho': {'value': 'statampere / statvolt'}}},\n", - " 'ESU': {'using_group_names': ['Gaussian'],\n", - " 'definitions': {'statweber': {'defined_symbol': 'statWb',\n", - " 'value': 'statvolt * second'},\n", - " 'stattesla': {'defined_symbol': 'statT',\n", - " 'value': 'statweber / centimeter ** 2'},\n", - " 'stathenry': {'defined_symbol': 'statH',\n", - " 'value': 'statweber / statampere'}}}},\n", - " 'system': {'SI': {'using_group_names': ['root'],\n", - " 'rules': ['second',\n", - " 'meter',\n", - " 'kilogram',\n", - " 'ampere',\n", - " 'kelvin',\n", - " 'mole',\n", - " 'candela']},\n", - " 'mks': {'using_group_names': ['international'],\n", - " 'rules': ['meter', 'kilogram', 'second']},\n", - " 'cgs': {'using_group_names': ['international', 'Gaussian', 'ESU'],\n", - " 'rules': ['centimeter', 'gram', 'second']},\n", - " 'atomic': {'using_group_names': ['international'],\n", - " 'rules': ['bohr: meter',\n", - " 'electron_mass: gram',\n", - " 'atomic_unit_of_time: second',\n", - " 'atomic_unit_of_current: ampere',\n", - " 'atomic_unit_of_temperature: kelvin']},\n", - " 'Planck': {'using_group_names': ['international'],\n", - " 'rules': ['planck_length: meter',\n", - " 'planck_mass: gram',\n", - " 'planck_time: second',\n", - " 'planck_current: ampere',\n", - " 'planck_temperature: kelvin']},\n", - " 'imperial': {'using_group_names': ['ImperialVolume',\n", - " 'USCSLengthInternational',\n", - " 'AvoirdupoisUK'],\n", - " 'rules': ['yard', 'pound']},\n", - " 'US': {'using_group_names': ['USCSLiquidVolume',\n", - " 'USCSDryVolume',\n", - " 'USCSVolumeOther',\n", - " 'USCSLengthInternational',\n", - " 'USCSLengthSurvey',\n", - " 'AvoirdupoisUS'],\n", - " 'rules': ['yard', 'pound']},\n", - " 'Gaussian': {'aliases': ['Gau'],\n", - " 'relations': ['[gaussian_charge] -> [charge]: value / k_C ** 0.5',\n", - " '[charge] -> [gaussian_charge]: value * k_C ** 0.5',\n", - " '[gaussian_current] -> [current]: value / k_C ** 0.5',\n", - " '[current] -> [gaussian_current]: value * k_C ** 0.5',\n", - " '[gaussian_electric_potential] -> [electric_potential]: value * k_C ** 0.5',\n", - " '[electric_potential] -> [gaussian_electric_potential]: value / k_C ** 0.5',\n", - " '[gaussian_electric_field] -> [electric_field]: value * k_C ** 0.5',\n", - " '[electric_field] -> [gaussian_electric_field]: value / k_C ** 0.5',\n", - " '[gaussian_electric_displacement_field] -> [electric_displacement_field]: value / (4 * π / ε_0) ** 0.5',\n", - " '[electric_displacement_field] -> [gaussian_electric_displacement_field]: value * (4 * π / ε_0) ** 0.5',\n", - " '[gaussian_electric_dipole] -> [electric_dipole]: value / k_C ** 0.5',\n", - " '[electric_dipole] -> [gaussian_electric_dipole]: value * k_C ** 0.5',\n", - " '[gaussian_electric_quadrupole] -> [electric_quadrupole]: value / k_C ** 0.5',\n", - " '[electric_quadrupole] -> [gaussian_electric_quadrupole]: value * k_C ** 0.5',\n", - " '[gaussian_magnetic_field] -> [magnetic_field]: value / (4 * π / µ_0) ** 0.5',\n", - " '[magnetic_field] -> [gaussian_magnetic_field]: value * (4 * π / µ_0) ** 0.5',\n", - " '[gaussian_magnetic_flux] -> [magnetic_flux]: value / (4 * π / µ_0) ** 0.5',\n", - " '[magnetic_flux] -> [gaussian_magnetic_flux]: value * (4 * π / µ_0) ** 0.5',\n", - " '[gaussian_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π * µ_0) ** 0.5',\n", - " '[magnetic_field_strength] -> [gaussian_magnetic_field_strength]: value * (4 * π * µ_0) ** 0.5',\n", - " '[gaussian_magnetic_dipole] -> [magnetic_dipole]: value * (4 * π / µ_0) ** 0.5',\n", - " '[magnetic_dipole] -> [gaussian_magnetic_dipole]: value / (4 * π / µ_0) ** 0.5',\n", - " '[gaussian_resistance] -> [resistance]: value * k_C',\n", - " '[resistance] -> [gaussian_resistance]: value / k_C',\n", - " '[gaussian_resistivity] -> [resistivity]: value * k_C',\n", - " '[resistivity] -> [gaussian_resistivity]: value / k_C',\n", - " '[gaussian_capacitance] -> [capacitance]: value / k_C',\n", - " '[capacitance] -> [gaussian_capacitance]: value * k_C',\n", - " '[gaussian_inductance] -> [inductance]: value * k_C',\n", - " '[inductance] -> [gaussian_inductance]: value / k_C',\n", - " '[gaussian_conductance] -> [conductance]: value / k_C',\n", - " '[conductance] -> [gaussian_conductance]: value * k_C'],\n", - " 'defaults': {}},\n", - " 'ESU': {'aliases': ['esu'],\n", - " 'relations': ['[esu_magnetic_field] -> [magnetic_field]: value * k_C ** 0.5',\n", - " '[magnetic_field] -> [esu_magnetic_field]: value / k_C ** 0.5',\n", - " '[esu_magnetic_flux] -> [magnetic_flux]: value * k_C ** 0.5',\n", - " '[magnetic_flux] -> [esu_magnetic_flux]: value / k_C ** 0.5',\n", - " '[esu_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π / ε_0) ** 0.5',\n", - " '[magnetic_field_strength] -> [esu_magnetic_field_strength]: value * (4 * π / ε_0) ** 0.5',\n", - " '[esu_magnetic_dipole] -> [magnetic_dipole]: value / k_C ** 0.5',\n", - " '[magnetic_dipole] -> [esu_magnetic_dipole]: value * k_C ** 0.5'],\n", - " 'defaults': {}},\n", - " 'spectroscopy': {'aliases': ['sp'],\n", - " 'relations': ['[length] <-> [frequency]: speed_of_light / n / value',\n", - " '[frequency] -> [energy]: planck_constant * value',\n", - " '[energy] -> [frequency]: value / planck_constant',\n", - " '[wavenumber] <-> [length]: 1 / value'],\n", - " 'defaults': {'n': 1}},\n", - " 'boltzmann': {'relations': ['[temperature] -> [energy]: boltzmann_constant * value',\n", - " '[energy] -> [temperature]: value / boltzmann_constant'],\n", - " 'defaults': {}},\n", - " 'energy': {'relations': ['[energy] -> [energy] / [substance]: value * N_A',\n", - " '[energy] / [substance] -> [energy]: value / N_A',\n", - " '[energy] -> [mass]: value / c ** 2',\n", - " '[mass] -> [energy]: value * c ** 2'],\n", - " 'defaults': {}},\n", - " 'chemistry': {'aliases': ['chem'],\n", - " 'relations': ['[substance] -> [mass]: value * mw',\n", - " '[mass] -> [substance]: value / mw',\n", - " '[substance] / [volume] -> [mass] / [volume]: value * mw',\n", - " '[mass] / [volume] -> [substance] / [volume]: value / mw',\n", - " '[substance] / [mass] -> [mass] / [mass]: value * mw',\n", - " '[mass] / [mass] -> [substance] / [mass]: value / mw',\n", - " '[substance] / [volume] -> [substance]: value * volume',\n", - " '[substance] -> [substance] / [volume]: value / volume',\n", - " '[substance] / [mass] -> [substance]: value * solvent_mass',\n", - " '[substance] -> [substance] / [mass]: value / solvent_mass',\n", - " '[substance] / [mass] -> [substance]/[volume]: value * solvent_mass / volume',\n", - " '[substance] / [volume] -> [substance] / [mass]: value / solvent_mass * volume'],\n", - " 'defaults': {'mw': 0, 'volume': 0, 'solvent_mass': 0}},\n", - " 'textile': {'relations': ['[mass] / [length] <-> [length] / [mass]: 1 / value'],\n", - " 'defaults': {}}},\n", - " 'context': {}}" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "config" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'system'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[17], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ureg_ \u001b[38;5;241m=\u001b[39m pint\u001b[38;5;241m.\u001b[39mUnitRegistry(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtest.toml\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\plain\\registry.py:158\u001b[0m, in \u001b[0;36mRegistryMeta.__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 156\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs: Any, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any):\n\u001b[0;32m 157\u001b[0m obj \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m--> 158\u001b[0m obj\u001b[38;5;241m.\u001b[39m_after_init()\n\u001b[0;32m 159\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m obj\n", - "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\system\\registry.py:77\u001b[0m, in \u001b[0;36mGenericSystemRegistry._after_init\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_after_init\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 72\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Invoked at the end of ``__init__``.\u001b[39;00m\n\u001b[0;32m 73\u001b[0m \n\u001b[0;32m 74\u001b[0m \u001b[38;5;124;03m - Create default group and add all orphan units to it\u001b[39;00m\n\u001b[0;32m 75\u001b[0m \u001b[38;5;124;03m - Set default system\u001b[39;00m\n\u001b[0;32m 76\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 77\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m_after_init()\n\u001b[0;32m 79\u001b[0m \u001b[38;5;66;03m#: System name to be used by default.\u001b[39;00m\n\u001b[0;32m 80\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_system_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_system_name \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_defaults\u001b[38;5;241m.\u001b[39mget(\n\u001b[0;32m 81\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msystem\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 82\u001b[0m )\n", - "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\group\\registry.py:65\u001b[0m, in \u001b[0;36mGenericGroupRegistry._after_init\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 59\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_after_init\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 60\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Invoked at the end of ``__init__``.\u001b[39;00m\n\u001b[0;32m 61\u001b[0m \n\u001b[0;32m 62\u001b[0m \u001b[38;5;124;03m - Create default group and add all orphan units to it\u001b[39;00m\n\u001b[0;32m 63\u001b[0m \u001b[38;5;124;03m - Set default system\u001b[39;00m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 65\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m_after_init()\n\u001b[0;32m 67\u001b[0m \u001b[38;5;66;03m#: Copy units not defined in any group to the default group\u001b[39;00m\n\u001b[0;32m 68\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgroup\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_defaults:\n", - "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\plain\\registry.py:337\u001b[0m, in \u001b[0;36mGenericPlainRegistry._after_init\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 335\u001b[0m loaded_files \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mload_definitions(path, \u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m 336\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filename \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 337\u001b[0m loaded_files \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mload_definitions(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filename)\n\u001b[0;32m 338\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 339\u001b[0m loaded_files \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n", - "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\facets\\plain\\registry.py:605\u001b[0m, in \u001b[0;36mGenericPlainRegistry.load_definitions\u001b[1;34m(self, file, is_resource)\u001b[0m\n\u001b[0;32m 602\u001b[0m parsed_project \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_def_parser\u001b[38;5;241m.\u001b[39mparse_file(file)\n\u001b[0;32m 604\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mstr\u001b[39m(file)[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m5\u001b[39m:] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.toml\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 605\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m definition \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_toml_parser\u001b[38;5;241m.\u001b[39miter_parsed_project(parsed_project):\n\u001b[0;32m 606\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_helper_dispatch_adder(definition)\n\u001b[0;32m 607\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", - "File \u001b[1;32mF:\\A\\repos\\pint\\pint\\delegates\\toml_parser\\toml_parser.py:86\u001b[0m, in \u001b[0;36mTomlParser.iter_parsed_project\u001b[1;34m(self, parsed_project)\u001b[0m\n\u001b[0;32m 84\u001b[0m d\u001b[38;5;241m=\u001b[39mcopy\u001b[38;5;241m.\u001b[39mcopy(value)\n\u001b[0;32m 85\u001b[0m d[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m=\u001b[39mkey\n\u001b[1;32m---> 86\u001b[0m stmt \u001b[38;5;241m=\u001b[39m stmts[definition_type]\u001b[38;5;241m.\u001b[39mfrom_dict_and_config(d, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_config)\n\u001b[0;32m 87\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m stmt\n", - "\u001b[1;31mKeyError\u001b[0m: 'system'" - ] - } - ], - "source": [ - "ureg_ = pint.UnitRegistry(\"test.toml\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%debug" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pint\n", - "ureg = pint.UnitRegistry()\n", - "Q_= ureg.Quantity" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ureg._group_definitions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ureg._units['J']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%debug" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "q=1*ureg.degC\n", - "q.to(\"K\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "config['database']['level2'] = 'new added information'\n", - "with open('config.toml', 'w') as f:\n", - " toml.dump(config, f)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x = pint.definitions.Definition.from_string('degF = 9 / 5 * kelvin; offset: 255.372222')\n", - "x" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(Q_(32.1, ureg.degF).to('degC'))\n", - "print(Q_(32.01, ureg.degF).to('degC'))\n", - "print(Q_(32.001, ureg.degF).to('degC'))\n", - "print(Q_(32.0001, ureg.degF).to('degC'))\n", - "print(Q_(32.00001, ureg.degF).to('degC'))\n", - "print(Q_(32.000001, ureg.degF).to('degC'))\n", - "print(Q_(32.0000001, ureg.degF).to('degC'))\n", - "print(Q_(32.00000001, ureg.degF).to('degC'))\n", - "print(Q_(32.000000001, ureg.degF).to('degC'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pint.__file__" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print(q(212, ureg.degF).to('degC'))\n", - "temps =[0,255.37,373.1339]\n", - "for temp in temps:\n", - " q= Q_(temp,\"K\")\n", - " print(q.to(\"K\"), q.to(\"degC\"), q.to(\"degF\"),q.to(\"degR\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "q" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(q(32, ureg.degF).to('degK'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "q(32, ureg.degF).to('degK').m\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "assertTrue(abs(self.Q_(0, ureg.degC).to('degF').m- 32)<1e-8)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "np.__version__" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pint\n", - "print(pint.compat.__file__)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%load_ext autoreload\n", - "%autoreload 2\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pint._HAS_PINTPANDAS" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ureg=pint.UnitRegistry()\n", - "Q_=ureg.Quantity" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a=Q_(1,\"m\")\n", - "b=a*Q_([[1,2,3]],\"m\")\n", - "c=Q_(3,\"m\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "my_array = ureg.Quantity([1,2],\"m\")\n", - "my_array_mm = ureg.Quantity([1,2],\"mm\")\n", - "np.concatenate([my_array,my_array])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "getattr(np,\"linspace\")==np.linspace" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.power(a,[2, 3])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pint.testsuite.test_numpy import TestNumpyMathematicalFunctions\n", - "self = TestNumpyMathematicalFunctions()\n", - "self.ureg = ureg\n", - "self.Q_ = Q_" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.unwrap([0,540]*self.ureg.deg)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "self.test_unwrap()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "self.assertQuantityEqual(np.swapaxes(self.q, 1,0), np.array([[1,2],[3,4]]).T * self.ureg.m)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a = np.ones((3, 2))\n", - "q = self.Q_(a, \"km\")\n", - "self.assertEqual(q.u, np.compress((q==q[0,0]).any(0), q).u)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.sum([self.q]*2)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "self.assertQuantityEqual(np.atleast_1d(self.q), self.q)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "y = np.linspace(0 * ureg.meter, 0.1 * ureg.meter)\n", - "y" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a.tolist()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ureg.meter._REGISTRY.Quantity" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.sum([my_array,my_array_mm],axis=1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.arange(a,c,a)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def _():\n", - "# import pdb\n", - "# pdb.set_trace()\n", - " np.arange(a,c)\n", - "_()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%debug" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.sum([my_array,my_array_mm],axis=1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def _([start, ]stop, [step, ]dtype=None):\n", - " print(start,stop,step)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Q_(np.array([1, 2]),\"m\").magnitude.dtype" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Q_(np.array([1, np.nan]),\"m\").magnitude.dtype" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import functools\n", - "import inspect\n", - "import numpy as np\n", - "import six\n", - "import sys\n", - "\n", - "\n", - "class ndarray(np.ndarray):\n", - " \"\"\"Updated version of numpy.ndarray.\"\"\"\n", - " def __array_function__(self, func, types, args, kwargs):\n", - " # Cannot handle items that have __array_function__ other than our own.\n", - " for t in types:\n", - " if (hasattr(t, '__array_function__') and\n", - " t.__array_function__ is not ndarray.__array_function__):\n", - " return NotImplemented\n", - "\n", - " # Arguments contain no overrides, so we can safely call the\n", - " # overloaded function again.\n", - " return func(*args, **kwargs)\n", - "\n", - "\n", - "def get_overloaded_types_and_args(relevant_args):\n", - " \"\"\"Returns a list of arguments on which to call __array_function__.\n", - " \n", - " __array_function__ implementations should be called in order on the return\n", - " values from this function.\n", - " \"\"\"\n", - " # Runtime is O(num_arguments * num_unique_types)\n", - " overloaded_types = []\n", - " overloaded_args = []\n", - " for arg in relevant_args:\n", - " arg_type = type(arg)\n", - " if arg_type not in overloaded_types:\n", - " try:\n", - " array_function = arg_type.__array_function__\n", - " except AttributeError:\n", - " continue\n", - "\n", - " overloaded_types.append(arg_type)\n", - "\n", - " if array_function is not ndarray.__array_function__:\n", - " index = len(overloaded_args)\n", - " for i, old_arg in enumerate(overloaded_args):\n", - " if issubclass(arg_type, type(old_arg)):\n", - " index = i\n", - " break\n", - " overloaded_args.insert(index, arg)\n", - "\n", - " return overloaded_types, overloaded_args\n", - "\n", - "\n", - "def full_name(obj):\n", - " return f'{obj.__module__}.{obj.__qualname__}'\n", - " \n", - "\n", - "def attempt_augmented_error_message(error, append_message):\n", - " \"\"\"Attempt to recreate an error with an appended message.\"\"\"\n", - " try:\n", - " return type(error)(error.args[0] + append_message, *error.args[1:])\n", - " except Exception:\n", - " return error\n", - " \n", - "def try_array_function_override(func, relevant_arguments, args, kwargs):\n", - " # TODO: consider simplifying the interface, to only require either `types`\n", - " # (by calling __array_function__ a classmethod) or `overloaded_args` (by\n", - " # dropping `types` from the signature of __array_function__)\n", - " types, overloaded_args = get_overloaded_types_and_args(relevant_arguments)\n", - " if not overloaded_args:\n", - " return False, None\n", - "\n", - " for overloaded_arg in overloaded_args:\n", - " # Note that we're only calling __array_function__ on the *first*\n", - " # occurence of each argument type. This is necessary for reasonable\n", - " # performance with a possibly long list of overloaded arguments, for\n", - " # which each __array_function__ implementation might reasonably need to\n", - " # check all argument types.\n", - " try:\n", - " result = overloaded_arg.__array_function__(\n", - " func, types, args, kwargs)\n", - " except Exception as error:\n", - " # Ensure the type of the overloaded argument ends up in the\n", - " # traceback\n", - " message = (\" [while calling {!r} implementation of {!r}]\"\n", - " .format(full_name(type(overloaded_arg)),\n", - " full_name(func)))\n", - " new_error = attempt_augmented_error_message(error, message)\n", - " # Would probably need to use six to do this sanely on Python 2:\n", - " # https://stackoverflow.com/questions/9157210/\n", - " raise new_error.with_traceback(error.__traceback__) from None\n", - "\n", - " if result is not NotImplemented:\n", - " return True, result\n", - "\n", - " raise TypeError('no implementation found for {} on types that implement '\n", - " '__array_function__: {}'\n", - " .format(func, list(map(type, overloaded_args))))\n", - "\n", - "\n", - "def array_function_dispatch(dispatcher):\n", - " \"\"\"Wrap a function for dispatch with the __array_function__ protocol.\"\"\"\n", - " def decorator(func):\n", - " @functools.wraps(func)\n", - " def new_func(*args, **kwargs):\n", - " relevant_arguments = dispatcher(*args, **kwargs)\n", - " success, value = try_array_function_override(\n", - " new_func, relevant_arguments, args, kwargs)\n", - " if success:\n", - " return value\n", - " return func(*args, **kwargs)\n", - " return new_func\n", - " return decorator\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "\n", - "\n", - "def _broadcast_to_dispatcher(array, shape, subok=None):\n", - " return (array,)\n", - "\n", - "@array_function_dispatch(_broadcast_to_dispatcher)\n", - "def broadcast_to(array, shape, subok=False):\n", - " return np.broadcast_to(array, shape, subok)\n", - "\n", - "\n", - "def _concatenate_dispatcher(arrays, axis=None, out=None):\n", - " for array in arrays:\n", - " yield array\n", - " if out is not None:\n", - " yield out\n", - " \n", - "@array_function_dispatch(_concatenate_dispatcher)\n", - "def concatenate(arrays, axis=0, out=None):\n", - " return np.concatenate(arrays, axis=axis, out=out)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "HANDLED_FUNCTIONS = {}\n", - "\n", - "class MyArray:\n", - " def __array_function__(self, func, types, args, kwargs):\n", - " if func not in HANDLED_FUNCTIONS:\n", - " return NotImplemented\n", - " if not all(issubclass(t, MyArray) for t in types):\n", - " return NotImplemented\n", - " return HANDLED_FUNCTIONS[func](*args, **kwargs)\n", - "\n", - "def implements(numpy_function):\n", - " \"\"\"Register an __array_function__ implementation for MyArray objects.\"\"\"\n", - " def decorator(func):\n", - " HANDLED_FUNCTIONS[numpy_function] = func\n", - " return func\n", - " return decorator\n", - "\n", - " \n", - "# dummy implementation to show how overloads work with new/unexpected arguments\n", - "@implements(concatenate)\n", - "def _(arrays):\n", - " pass\n", - "\n", - "my_array = MyArray()\n", - "concatenate([my_array]) # works\n", - "concatenate([my_array], axis=0) # not supported" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "HANDLED_FUNCTIONS = {}\n", - " \n", - "def __array_function__(self, func, types, args, kwargs):\n", - " if func not in HANDLED_FUNCTIONS:\n", - " return NotImplemented\n", - " if not all(issubclass(t, ureg.Quantity) for t in types):\n", - " return NotImplemented\n", - " return HANDLED_FUNCTIONS[func](*args, **kwargs)\n", - "\n", - "def implements(numpy_function):\n", - " \"\"\"Register an __array_function__ implementation for MyArray objects.\"\"\"\n", - " def decorator(func):\n", - " HANDLED_FUNCTIONS[numpy_function] = func\n", - " return func\n", - " return decorator\n", - "\n", - "setattr(ureg.Quantity, '__array_function__', __array_function__)\n", - " \n", - "# dummy implementation to show how overloads work with new/unexpected arguments\n", - "@implements(concatenate)\n", - "def _(arrays, axis=0, out=None):\n", - " out_units = arrays[0].units\n", - " arrays = [q.to(out_units) for q in arrays]\n", - " return ureg.Quantity(np.concatenate(arrays, axis=axis, out=out), out_units)\n", - "\n", - "my_array = ureg.Quantity([1,2],\"m\")\n", - "my_array_mm = ureg.Quantity([1,2],\"mm\")\n", - "concatenate([my_array,my_array_mm]) # works" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "np.concatenate([my_array,my_array_mm])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "concatenate([my_array,my_array_mm], axis=0) # not supported" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "interpretations = '''\n", - "~ energy = work = enthalpy\n", - " [energy] = [force] * [length]\n", - " joule = newton * meter = J\n", - " erg = dyne * centimeter\n", - " btu = 1.05505585262e3 * joule = Btu = BTU = british_thermal_unit\n", - " electron_volt = 1.60217653e-19 * J = eV\n", - " quadrillion_btu = 10**15 * btu = quad\n", - " thm = 100000 * BTU = therm = EC_therm\n", - " calorie = 4.184 * joule = cal = thermochemical_calorie\n", - " international_steam_table_calorie = 4.1868 * joule\n", - " ton_TNT = 4.184e9 * joule = tTNT\n", - " US_therm = 1.054804e8 * joule\n", - " watt_hour = watt * hour = Wh = watthour\n", - " hartree = 4.35974394e-18 * joule = = Eh = E_h = hartree_energy\n", - " toe = 41.868e9 * joule = tonne_of_oil_equivalent\n", - "~ energy\n", - "~ torque\n", - " [torque] = [force] * [length]\n", - " newton_meter = newton * meter = Nm\n", - "~torque\n", - "'''" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A single unit should return its interperetation only\n", - "\n", - "A dual unit should check all valid units for its dimensionality" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "nm=Q_(10.2345678,\"Nm\")\n", - "nmu=nm.units\n", - "\n", - "nmu.dimensionality" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "nmu._units" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "n_m=Q_(10.2345678,\"N m\")\n", - "n_mu=n_m.units\n", - "\n", - "n_mu.dimensionality" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "n_mu._units" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pint.PintType._metadata" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pintpandas.test_pandas_interface import *" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "TestDataFrameAccessor().test_index_maintained()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%debug" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "scalars=PintArray([], dtype='pint[nanometer]')\n", - "next(i for i in scalars if hasattr(i,\"units\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a=pint.PintType(\"m\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "self=pint.PintArray([1,2],\"m\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "self.data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pint.PintArray._from_sequence" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "na_sentinel = -1\n", - "from pandas.core.algorithms import _factorize_array\n", - "\n", - "arr, na_value = self._values_for_factorize()\n", - "\n", - "labels, uniques = _factorize_array(arr, na_sentinel=na_sentinel,\n", - " na_value=na_value)\n", - "uniques = self._from_factorized(uniques, self)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "labels, uniques" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "a=pd.core.arrays.period_array([2000, 2001, 2002], freq='D')\n", - "type(a.dtype)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "type(a.astype(a.dtype))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [conda env:pa_jan25]", - "language": "python", - "name": "conda-env-pa_jan25-py" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.13.1" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From aaa2845435de6897c8c6f8a4ae4952293fac64e3 Mon Sep 17 00:00:00 2001 From: Andrew Savage Date: Tue, 11 Feb 2025 00:06:25 +0000 Subject: [PATCH 04/20] review diff --- pint/delegates/toml_parser/toml_parser.py | 94 ----------------------- pint/facets/group/registry.py | 8 +- 2 files changed, 4 insertions(+), 98 deletions(-) diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py index d68ca8bb4..d78a84f83 100644 --- a/pint/delegates/toml_parser/toml_parser.py +++ b/pint/delegates/toml_parser/toml_parser.py @@ -9,57 +9,8 @@ import flexparser as fp from ..base_defparser import ParserConfig -# from . import block, common, context, defaults, group, plain, system from . import plain -# class PintRootBlock( -# fp.RootBlock[ -# ty.Union[ -# plain.CommentDefinition, -# common.ImportDefinition, -# context.ContextDefinition, -# defaults.DefaultsDefinition, -# system.SystemDefinition, -# group.GroupDefinition, -# plain.AliasDefinition, -# plain.DerivedDimensionDefinition, -# plain.DimensionDefinition, -# plain.PrefixDefinition, -# plain.UnitDefinition, -# ], -# ParserConfig, -# ] -# ): -# pass - - -# class _PintParser(fp.Parser[PintRootBlock, ParserConfig]): -# """Parser for the original Pint definition file, with cache.""" - -# _delimiters = { -# "#": ( -# fp.DelimiterInclude.SPLIT_BEFORE, -# fp.DelimiterAction.CAPTURE_NEXT_TIL_EOL, -# ), -# **fp.SPLIT_EOL, -# } -# _root_block_class = PintRootBlock -# _strip_spaces = True - -# _diskcache: fc.DiskCache | None - -# def __init__(self, config: ParserConfig, *args: ty.Any, **kwargs: ty.Any): -# self._diskcache = kwargs.pop("diskcache", None) -# super().__init__(config, *args, **kwargs) - -# def parse_file( -# self, path: pathlib.Path -# ) -> fp.ParsedSource[PintRootBlock, ParserConfig]: -# if self._diskcache is None: -# return super().parse_file(path) -# content, _basename = self._diskcache.load(path, super().parse_file) -# return content - class TomlParser: @@ -87,51 +38,6 @@ def iter_parsed_project( yield stmt - - # last_location = None - - # for stmt in parsed_project.iter_blocks(): - # if isinstance(stmt, fp.BOS): - # if isinstance(stmt, fp.BOF): - # last_location = str(stmt.path) - # continue - # elif isinstance(stmt, fp.BOR): - # last_location = ( - # f"[package: {stmt.package}, resource: {stmt.resource_name}]" - # ) - # continue - # else: - # last_location = "orphan string" - # continue - - # if isinstance(stmt, self.skip_classes): - # continue - - # assert isinstance(last_location, str) - # if isinstance(stmt, common.DefinitionSyntaxError): - # stmt.set_location(last_location) - # raise stmt - # elif isinstance(stmt, block.DirectiveBlock): - # for exc in stmt.errors: - # exc = common.DefinitionSyntaxError(str(exc)) - # exc.set_position(*stmt.get_position()) - # exc.set_raw( - # (stmt.opening.raw or "") + " [...] " + (stmt.closing.raw or "") - # ) - # exc.set_location(last_location) - # raise exc - - # try: - # yield stmt.derive_definition() - # except Exception as exc: - # exc = common.DefinitionSyntaxError(str(exc)) - # exc.set_position(*stmt.get_position()) - # exc.set_raw(stmt.opening.raw + " [...] " + stmt.closing.raw) - # exc.set_location(last_location) - # raise exc - # else: - # yield stmt - def parse_file( self, filename: pathlib.Path | str, cfg: ParserConfig | None = None ) -> dict: diff --git a/pint/facets/group/registry.py b/pint/facets/group/registry.py index 1bf798ff2..3693e2ae1 100644 --- a/pint/facets/group/registry.py +++ b/pint/facets/group/registry.py @@ -91,12 +91,12 @@ def _add_group(self, gd: GroupDefinition): self._group_definitions.append(gd) if gd.name in self._groups: raise ValueError(f"Group {gd.name} already present in registry") - # try: + try: # As a Group is a SharedRegistryObject # it adds itself to the registry. - self.Group.from_definition(gd) - # except KeyError as e: - # raise errors.DefinitionSyntaxError(f"unknown dimension {e} in context") + self.Group.from_definition(gd) + except KeyError as e: + raise errors.DefinitionSyntaxError(f"unknown dimension {e} in context") def get_group(self, name: str, create_if_needed: bool = True) -> objects.Group: """Return a Group. From ec2ab937548997796589ef9c1cd4737c6da4a2e1 Mon Sep 17 00:00:00 2001 From: Andrew Savage Date: Tue, 11 Feb 2025 00:09:36 +0000 Subject: [PATCH 05/20] add default_en.toml --- pint/default_en.toml | 3232 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3232 insertions(+) create mode 100644 pint/default_en.toml diff --git a/pint/default_en.toml b/pint/default_en.toml new file mode 100644 index 000000000..33d37c835 --- /dev/null +++ b/pint/default_en.toml @@ -0,0 +1,3232 @@ +[prefix.quecto] +value = "1e-30" +defined_symbol = "q" + +[prefix.ronto] +value = "1e-27" +defined_symbol = "r" + +[prefix.yocto] +value = "1e-24" +defined_symbol = "y" + +[prefix.zepto] +value = "1e-21" +defined_symbol = "z" + +[prefix.atto] +value = "1e-18" +defined_symbol = "a" + +[prefix.femto] +value = "1e-15" +defined_symbol = "f" + +[prefix.pico] +value = "1e-12" +defined_symbol = "p" + +[prefix.nano] +value = "1e-9" +defined_symbol = "n" + +[prefix.micro] +value = "1e-6" +defined_symbol = "µ" +aliases = [ + "μ", + "u", + "mu", + "mc", +] + +[prefix.milli] +value = "1e-3" +defined_symbol = "m" + +[prefix.centi] +value = "1e-2" +defined_symbol = "c" + +[prefix.deci] +value = "1e-1" +defined_symbol = "d" + +[prefix.deca] +value = "1e+1" +defined_symbol = "da" +aliases = [ + "deka", +] + +[prefix.hecto] +value = "1e2" +defined_symbol = "h" + +[prefix.kilo] +value = "1e3" +defined_symbol = "k" + +[prefix.mega] +value = "1e6" +defined_symbol = "M" + +[prefix.giga] +value = "1e9" +defined_symbol = "G" + +[prefix.tera] +value = "1e12" +defined_symbol = "T" + +[prefix.peta] +value = "1e15" +defined_symbol = "P" + +[prefix.exa] +value = "1e18" +defined_symbol = "E" + +[prefix.zetta] +value = "1e21" +defined_symbol = "Z" + +[prefix.yotta] +value = "1e24" +defined_symbol = "Y" + +[prefix.ronna] +value = "1e27" +defined_symbol = "R" + +[prefix.quetta] +value = "1e30" +defined_symbol = "Q" + +[prefix.kibi] +value = "2**10" +defined_symbol = "Ki" + +[prefix.mebi] +value = "2**20" +defined_symbol = "Mi" + +[prefix.gibi] +value = "2**30" +defined_symbol = "Gi" + +[prefix.tebi] +value = "2**40" +defined_symbol = "Ti" + +[prefix.pebi] +value = "2**50" +defined_symbol = "Pi" + +[prefix.exbi] +value = "2**60" +defined_symbol = "Ei" + +[prefix.zebi] +value = "2**70" +defined_symbol = "Zi" + +[prefix.yobi] +value = "2**80" +defined_symbol = "Yi" + +[prefix.semi] +value = "0.5" +aliases = [ + "demi", +] + +[prefix.sesqui] +value = "1.5" + +[unit.meter] +defined_symbol = "m" +aliases = [ + "metre", +] +value = "[length]" + +[unit.second] +defined_symbol = "s" +aliases = [ + "sec", +] +value = "[time]" + +[unit.ampere] +defined_symbol = "A" +aliases = [ + "amp", +] +value = "[current]" + +[unit.candela] +defined_symbol = "cd" +aliases = [ + "candle", +] +value = "[luminosity]" + +[unit.gram] +defined_symbol = "g" +value = "[mass]" + +[unit.mole] +defined_symbol = "mol" +value = "[substance]" + +[unit.kelvin] +defined_symbol = "K" +aliases = [ + "degK", + "°K", + "degree_Kelvin", + "degreeK", +] +value = "[temperature]; offset: 0" + +[unit.radian] +defined_symbol = "rad" +value = "[]" + +[unit.bit] +value = "[]" + +[unit.count] +value = "[]" + +[unit.pi] +defined_symbol = "π" +value = "3.1415926535897932384626433832795028841971693993751" + +[unit.tansec] +value = "4.8481368111333441675396429478852851658848753880815e-6" + +[unit.ln10] +value = "2.3025850929940456840179914546843642076011014886288" + +[unit.wien_x] +value = "4.9651142317442763036987591313228939440555849867973" + +[unit.wien_u] +value = "2.8214393721220788934031913302944851953458817440731" + +[unit.eulers_number] +value = "2.71828182845904523536028747135266249775724709369995" + +[unit.speed_of_light] +defined_symbol = "c" +aliases = [ + "c_0", +] +value = "299792458 m/s" + +[unit.planck_constant] +defined_symbol = "ℎ" +value = "6.62607015e-34 J s" + +[unit.elementary_charge] +defined_symbol = "e" +value = "1.602176634e-19 C" + +[unit.avogadro_number] +value = "6.02214076e23" + +[unit.boltzmann_constant] +defined_symbol = "k" +aliases = [ + "k_B", +] +value = "1.380649e-23 J K^-1" + +[unit.standard_gravity] +defined_symbol = "g_0" +aliases = [ + "g0", + "g_n", + "gravity", +] +value = "9.80665 m/s^2" + +[unit.standard_atmosphere] +defined_symbol = "atm" +aliases = [ + "atmosphere", +] +value = "1.01325e5 Pa" + +[unit.conventional_josephson_constant] +defined_symbol = "K_J90" +value = "4.835979e14 Hz / V" + +[unit.conventional_von_klitzing_constant] +defined_symbol = "R_K90" +value = "2.5812807e4 ohm" + +[unit.zeta] +defined_symbol = "ζ" +value = "c / (cm/s)" + +[unit.dirac_constant] +defined_symbol = "ħ" +aliases = [ + "hbar", + "atomic_unit_of_action", + "a_u_action", +] +value = "ℎ / (2 * π)" + +[unit.avogadro_constant] +defined_symbol = "N_A" +value = "avogadro_number * mol^-1" + +[unit.molar_gas_constant] +defined_symbol = "R" +value = "k * N_A" + +[unit.faraday_constant] +value = "e * N_A" + +[unit.conductance_quantum] +defined_symbol = "G_0" +value = "2 * e ** 2 / ℎ" + +[unit.magnetic_flux_quantum] +defined_symbol = "Φ_0" +aliases = [ + "Phi_0", +] +value = "ℎ / (2 * e)" + +[unit.josephson_constant] +defined_symbol = "K_J" +value = "2 * e / ℎ" + +[unit.von_klitzing_constant] +defined_symbol = "R_K" +value = "ℎ / e ** 2" + +[unit.stefan_boltzmann_constant] +defined_symbol = "σ" +aliases = [ + "sigma", +] +value = "2 / 15 * π ** 5 * k ** 4 / (ℎ ** 3 * c ** 2)" + +[unit.first_radiation_constant] +defined_symbol = "c_1" +value = "2 * π * ℎ * c ** 2" + +[unit.second_radiation_constant] +defined_symbol = "c_2" +value = "ℎ * c / k" + +[unit.wien_wavelength_displacement_law_constant] +value = "ℎ * c / (k * wien_x)" + +[unit.wien_frequency_displacement_law_constant] +value = "wien_u * k / ℎ" + +[unit.newtonian_constant_of_gravitation] +aliases = [ + "gravitational_constant", +] +value = "6.67430e-11 m^3/(kg s^2)" + +[unit.rydberg_constant] +defined_symbol = "R_∞" +aliases = [ + "R_inf", +] +value = "1.0973731568157e7 * m^-1" + +[unit.electron_g_factor] +defined_symbol = "g_e" +value = "-2.00231930436092" + +[unit.atomic_mass_constant] +defined_symbol = "m_u" +value = "1.66053906892e-27 kg" + +[unit.electron_mass] +defined_symbol = "m_e" +aliases = [ + "atomic_unit_of_mass", + "a_u_mass", +] +value = "9.1093837139e-31 kg" + +[unit.proton_mass] +defined_symbol = "m_p" +value = "1.67262192595e-27 kg" + +[unit.neutron_mass] +defined_symbol = "m_n" +value = "1.67492750056e-27 kg" + +[unit.x_unit_Cu] +defined_symbol = "Xu_Cu" +value = "1.00207697e-13 m" + +[unit.x_unit_Mo] +defined_symbol = "Xu_Mo" +value = "1.00209952e-13 m" + +[unit.angstrom_star] +defined_symbol = "Å_star" +value = "1.00001495e-10" + +[unit.fine_structure_constant] +defined_symbol = "α" +aliases = [ + "alpha", +] +value = "(2 * ℎ * R_inf / (m_e * c)) ** 0.5" + +[unit.vacuum_permeability] +defined_symbol = "µ_0" +aliases = [ + "mu_0", + "mu0", + "magnetic_constant", +] +value = "2 * α * ℎ / (e ** 2 * c)" + +[unit.vacuum_permittivity] +defined_symbol = "ε_0" +aliases = [ + "epsilon_0", + "eps_0", + "eps0", + "electric_constant", +] +value = "e ** 2 / (2 * α * ℎ * c)" + +[unit.impedance_of_free_space] +defined_symbol = "Z_0" +aliases = [ + "characteristic_impedance_of_vacuum", +] +value = "2 * α * ℎ / e ** 2" + +[unit.coulomb_constant] +defined_symbol = "k_C" +value = "α * hbar * c / e ** 2" + +[unit.classical_electron_radius] +defined_symbol = "r_e" +value = "α * hbar / (m_e * c)" + +[unit.thomson_cross_section] +defined_symbol = "σ_e" +aliases = [ + "sigma_e", +] +value = "8 / 3 * π * r_e ** 2" + +[unit.turn] +aliases = [ + "revolution", + "cycle", + "circle", +] +value = "2 * π * radian" + +[unit.degree] +defined_symbol = "deg" +aliases = [ + "arcdeg", + "arcdegree", + "angular_degree", +] +value = "π / 180 * radian" + +[unit.arcminute] +defined_symbol = "arcmin" +aliases = [ + "arc_minute", + "angular_minute", +] +value = "degree / 60" + +[unit.arcsecond] +defined_symbol = "arcsec" +aliases = [ + "arc_second", + "angular_second", +] +value = "arcminute / 60" + +[unit.milliarcsecond] +defined_symbol = "mas" +value = "1e-3 * arcsecond" + +[unit.grade] +defined_symbol = "grad" +aliases = [ + "gon", +] +value = "π / 200 * radian" + +[unit.mil] +value = "π / 32000 * radian" + +[unit.steradian] +defined_symbol = "sr" +value = "radian ** 2" + +[unit.square_degree] +defined_symbol = "sq_deg" +aliases = [ + "sqdeg", +] +value = "(π / 180) ** 2 * sr" + +[unit.baud] +defined_symbol = "Bd" +aliases = [ + "bps", +] +value = "bit / second" + +[unit.byte] +defined_symbol = "B" +aliases = [ + "octet", +] +value = "8 * bit" + +[unit.percent] +defined_symbol = "%" +value = "0.01" + +[unit.permille] +defined_symbol = "‰" +value = "0.001" + +[unit.ppm] +value = "1e-6" + +[unit.angstrom] +defined_symbol = "Å" +aliases = [ + "ångström", + "Å", +] +value = "1e-10 * meter" + +[unit.micron] +defined_symbol = "µ" +aliases = [ + "μ", +] +value = "micrometer" + +[unit.fermi] +defined_symbol = "fm" +value = "femtometer" + +[unit.light_year] +defined_symbol = "ly" +aliases = [ + "lightyear", +] +value = "speed_of_light * julian_year" + +[unit.astronomical_unit] +defined_symbol = "au" +value = "149597870700 * meter" + +[unit.parsec] +defined_symbol = "pc" +value = "1 / tansec * astronomical_unit" + +[unit.nautical_mile] +defined_symbol = "nmi" +value = "1852 * meter" + +[unit.bohr] +defined_symbol = "a_0" +aliases = [ + "a0", + "bohr_radius", + "atomic_unit_of_length", + "a_u_length", +] +value = "hbar / (alpha * m_e * c)" + +[unit.planck_length] +value = "(hbar * gravitational_constant / c ** 3) ** 0.5" + +[unit.metric_ton] +defined_symbol = "t" +aliases = [ + "tonne", +] +value = "1e3 * kilogram" + +[unit.unified_atomic_mass_unit] +defined_symbol = "u" +aliases = [ + "amu", +] +value = "atomic_mass_constant" + +[unit.dalton] +defined_symbol = "Da" +value = "atomic_mass_constant" + +[unit.grain] +defined_symbol = "gr" +value = "64.79891 * milligram" + +[unit.gamma_mass] +value = "microgram" + +[unit.carat] +defined_symbol = "ct" +aliases = [ + "karat", +] +value = "200 * milligram" + +[unit.planck_mass] +value = "(hbar * c / gravitational_constant) ** 0.5" + +[unit.minute] +defined_symbol = "min" +value = "60 * second" + +[unit.hour] +defined_symbol = "h" +aliases = [ + "hr", +] +value = "60 * minute" + +[unit.day] +defined_symbol = "d" +value = "24 * hour" + +[unit.week] +value = "7 * day" + +[unit.fortnight] +value = "2 * week" + +[unit.year] +defined_symbol = "a" +aliases = [ + "yr", + "julian_year", +] +value = "365.25 * day" + +[unit.month] +value = "year / 12" + +[unit.century] +aliases = [ + "centuries", +] +value = "100 * year" + +[unit.millennium] +aliases = [ + "millennia", +] +value = "1e3 * year" + +[unit.eon] +value = "1e9 * year" + +[unit.shake] +value = "1e-8 * second" + +[unit.svedberg] +value = "1e-13 * second" + +[unit.atomic_unit_of_time] +defined_symbol = "a_u_time" +value = "hbar / E_h" + +[unit.gregorian_year] +value = "365.2425 * day" + +[unit.sidereal_year] +value = "365.256363004 * day" + +[unit.tropical_year] +value = "365.242190402 * day" + +[unit.common_year] +value = "365 * day" + +[unit.leap_year] +value = "366 * day" + +[unit.sidereal_day] +value = "day / 1.00273790935079524" + +[unit.sidereal_month] +value = "27.32166155 * day" + +[unit.tropical_month] +value = "27.321582 * day" + +[unit.synodic_month] +aliases = [ + "lunar_month", +] +value = "29.530589 * day" + +[unit.planck_time] +value = "(hbar * gravitational_constant / c ** 5) ** 0.5" + +[unit.degree_Celsius] +defined_symbol = "°C" +aliases = [ + "celsius", + "degC", + "degreeC", +] +value = "kelvin; offset: 273.15" + +[unit.degree_Rankine] +defined_symbol = "°R" +aliases = [ + "rankine", + "degR", + "degreeR", +] +value = "5 / 9 * kelvin; offset: 0" + +[unit.degree_Fahrenheit] +defined_symbol = "°F" +aliases = [ + "fahrenheit", + "degF", + "degreeF", +] +value = "5 / 9 * kelvin; offset: 233.15 + 200 / 9" + +[unit.degree_Reaumur] +defined_symbol = "°Re" +aliases = [ + "reaumur", + "degRe", + "degreeRe", + "degree_Réaumur", + "réaumur", +] +value = "4 / 5 * kelvin; offset: 273.15" + +[unit.atomic_unit_of_temperature] +defined_symbol = "a_u_temp" +value = "E_h / k" + +[unit.planck_temperature] +value = "(hbar * c ** 5 / gravitational_constant / k ** 2) ** 0.5" + +[unit.are] +value = "100 * meter ** 2" + +[unit.barn] +defined_symbol = "b" +value = "1e-28 * meter ** 2" + +[unit.darcy] +value = "centipoise * centimeter ** 2 / (second * atmosphere)" + +[unit.hectare] +defined_symbol = "ha" +value = "100 * are" + +[unit.liter] +defined_symbol = "l" +aliases = [ + "L", + "ℓ", + "litre", +] +value = "decimeter ** 3" + +[unit.cubic_centimeter] +defined_symbol = "cc" +value = "centimeter ** 3" + +[unit.lambda] +defined_symbol = "λ" +value = "microliter" + +[unit.stere] +value = "meter ** 3" + +[unit.hertz] +defined_symbol = "Hz" +value = "1 / second" + +[unit.revolutions_per_minute] +defined_symbol = "rpm" +value = "revolution / minute" + +[unit.revolutions_per_second] +defined_symbol = "rps" +value = "revolution / second" + +[unit.counts_per_second] +defined_symbol = "cps" +value = "count / second" + +[unit.reciprocal_centimeter] +defined_symbol = "cm_1" +aliases = [ + "kayser", +] +value = "1 / cm" + +[unit.knot] +defined_symbol = "kt" +aliases = [ + "knot_international", + "international_knot", +] +value = "nautical_mile / hour" + +[unit.mile_per_hour] +defined_symbol = "mph" +aliases = [ + "MPH", +] +value = "mile / hour" + +[unit.kilometer_per_hour] +defined_symbol = "kph" +aliases = [ + "KPH", +] +value = "kilometer / hour" + +[unit.kilometer_per_second] +defined_symbol = "kps" +value = "kilometer / second" + +[unit.meter_per_second] +defined_symbol = "mps" +value = "meter / second" + +[unit.foot_per_second] +defined_symbol = "fps" +value = "foot / second" + +[unit.sverdrup] +defined_symbol = "sv" +value = "1e6 * meter ** 3 / second" + +[unit.galileo] +defined_symbol = "Gal" +value = "centimeter / second ** 2" + +[unit.newton] +defined_symbol = "N" +value = "kilogram * meter / second ** 2" + +[unit.dyne] +defined_symbol = "dyn" +value = "gram * centimeter / second ** 2" + +[unit.force_kilogram] +defined_symbol = "kgf" +aliases = [ + "kilogram_force", + "pond", +] +value = "g_0 * kilogram" + +[unit.force_gram] +defined_symbol = "gf" +aliases = [ + "gram_force", +] +value = "g_0 * gram" + +[unit.force_metric_ton] +defined_symbol = "tf" +aliases = [ + "metric_ton_force", + "force_t", + "t_force", +] +value = "g_0 * metric_ton" + +[unit.atomic_unit_of_force] +defined_symbol = "a_u_force" +value = "E_h / a_0" + +[unit.joule] +defined_symbol = "J" +value = "newton * meter" + +[unit.erg] +value = "dyne * centimeter" + +[unit.watt_hour] +defined_symbol = "Wh" +aliases = [ + "watthour", +] +value = "watt * hour" + +[unit.electron_volt] +defined_symbol = "eV" +value = "e * volt" + +[unit.rydberg] +defined_symbol = "Ry" +value = "ℎ * c * R_inf" + +[unit.hartree] +defined_symbol = "E_h" +aliases = [ + "Eh", + "hartree_energy", + "atomic_unit_of_energy", + "a_u_energy", +] +value = "2 * rydberg" + +[unit.calorie] +defined_symbol = "cal" +aliases = [ + "thermochemical_calorie", + "cal_th", +] +value = "4.184 * joule" + +[unit.international_calorie] +defined_symbol = "cal_it" +aliases = [ + "international_steam_table_calorie", +] +value = "4.1868 * joule" + +[unit.fifteen_degree_calorie] +defined_symbol = "cal_15" +value = "4.1855 * joule" + +[unit.british_thermal_unit] +defined_symbol = "Btu" +aliases = [ + "BTU", + "Btu_iso", +] +value = "1055.056 * joule" + +[unit.international_british_thermal_unit] +defined_symbol = "Btu_it" +value = "1e3 * pound / kilogram * degR / kelvin * international_calorie" + +[unit.thermochemical_british_thermal_unit] +defined_symbol = "Btu_th" +value = "1e3 * pound / kilogram * degR / kelvin * calorie" + +[unit.quadrillion_Btu] +defined_symbol = "quad" +value = "1e15 * Btu" + +[unit.therm] +defined_symbol = "thm" +aliases = [ + "EC_therm", +] +value = "1e5 * Btu" + +[unit.US_therm] +value = "1.054804e8 * joule" + +[unit.ton_TNT] +defined_symbol = "tTNT" +value = "1e9 * calorie" + +[unit.tonne_of_oil_equivalent] +defined_symbol = "toe" +value = "1e10 * international_calorie" + +[unit.atmosphere_liter] +defined_symbol = "atm_l" +value = "atmosphere * liter" + +[unit.watt] +defined_symbol = "W" +value = "joule / second" + +[unit.volt_ampere] +defined_symbol = "VA" +value = "volt * ampere" + +[unit.horsepower] +defined_symbol = "hp" +aliases = [ + "UK_horsepower", + "hydraulic_horsepower", +] +value = "550 * foot * force_pound / second" + +[unit.boiler_horsepower] +value = "33475 * Btu / hour" + +[unit.metric_horsepower] +value = "75 * force_kilogram * meter / second" + +[unit.electrical_horsepower] +value = "746 * watt" + +[unit.refrigeration_ton] +aliases = [ + "ton_of_refrigeration", +] +value = "12e3 * Btu / hour" + +[unit.cooling_tower_ton] +value = "1.25 * refrigeration_ton" + +[unit.standard_liter_per_minute] +defined_symbol = "slpm" +aliases = [ + "slm", +] +value = "atmosphere * liter / minute" + +[unit.conventional_watt_90] +defined_symbol = "W_90" +value = "K_J90 ** 2 * R_K90 / (K_J ** 2 * R_K) * watt" + +[unit.mercury] +defined_symbol = "Hg" +aliases = [ + "Hg_0C", + "Hg_32F", + "conventional_mercury", +] +value = "13.5951 * kilogram / liter" + +[unit.water] +defined_symbol = "H2O" +aliases = [ + "conventional_water", +] +value = "1.0 * kilogram / liter" + +[unit.mercury_60F] +defined_symbol = "Hg_60F" +value = "13.5568 * kilogram / liter" + +[unit.water_39F] +defined_symbol = "water_4C" +value = "0.999972 * kilogram / liter" + +[unit.water_60F] +value = "0.999001 * kilogram / liter" + +[unit.pascal] +defined_symbol = "Pa" +value = "newton / meter ** 2" + +[unit.barye] +defined_symbol = "Ba" +aliases = [ + "barie", + "barad", + "barrie", + "baryd", +] +value = "dyne / centimeter ** 2" + +[unit.bar] +value = "1e5 * pascal" + +[unit.technical_atmosphere] +defined_symbol = "at" +value = "kilogram * g_0 / centimeter ** 2" + +[unit.torr] +value = "atm / 760" + +[unit.pound_force_per_square_inch] +defined_symbol = "psi" +value = "force_pound / inch ** 2" + +[unit.kip_per_square_inch] +defined_symbol = "ksi" +value = "kip / inch ** 2" + +[unit.millimeter_Hg] +defined_symbol = "mmHg" +aliases = [ + "mm_Hg", + "millimeter_Hg_0C", +] +value = "millimeter * Hg * g_0" + +[unit.centimeter_Hg] +defined_symbol = "cmHg" +aliases = [ + "cm_Hg", + "centimeter_Hg_0C", +] +value = "centimeter * Hg * g_0" + +[unit.inch_Hg] +defined_symbol = "inHg" +aliases = [ + "in_Hg", + "inch_Hg_32F", +] +value = "inch * Hg * g_0" + +[unit.inch_Hg_60F] +value = "inch * Hg_60F * g_0" + +[unit.inch_H2O_39F] +value = "inch * water_39F * g_0" + +[unit.inch_H2O_60F] +value = "inch * water_60F * g_0" + +[unit.foot_H2O] +defined_symbol = "ftH2O" +aliases = [ + "feet_H2O", +] +value = "foot * water * g_0" + +[unit.centimeter_H2O] +defined_symbol = "cmH2O" +aliases = [ + "cm_H2O", +] +value = "centimeter * water * g_0" + +[unit.sound_pressure_level] +defined_symbol = "SPL" +value = "20e-6 * pascal" + +[unit.foot_pound] +defined_symbol = "ft_lb" +aliases = [ + "footpound", +] +value = "foot * force_pound" + +[unit.poise] +defined_symbol = "P" +value = "0.1 * Pa * second" + +[unit.reyn] +value = "psi * second" + +[unit.stokes] +defined_symbol = "St" +value = "centimeter ** 2 / second" + +[unit.rhe] +value = "1 / poise" + +[unit.particle] +aliases = [ + "molec", + "molecule", +] +value = "1 / N_A" + +[unit.molar] +defined_symbol = "M" +value = "mole / liter" + +[unit.katal] +defined_symbol = "kat" +value = "mole / second" + +[unit.enzyme_unit] +defined_symbol = "U" +aliases = [ + "enzymeunit", +] +value = "micromole / minute" + +[unit.clausius] +defined_symbol = "Cl" +value = "calorie / kelvin" + +[unit.entropy_unit] +defined_symbol = "eu" +value = "calorie / kelvin / mole" + +[unit.becquerel] +defined_symbol = "Bq" +value = "counts_per_second" + +[unit.curie] +defined_symbol = "Ci" +value = "3.7e10 * becquerel" + +[unit.rutherford] +defined_symbol = "Rd" +value = "1e6 * becquerel" + +[unit.gray] +defined_symbol = "Gy" +value = "joule / kilogram" + +[unit.sievert] +defined_symbol = "Sv" +value = "joule / kilogram" + +[unit.rads] +value = "0.01 * gray" + +[unit.rem] +value = "0.01 * sievert" + +[unit.roentgen] +aliases = [ + "röntgen", +] +value = "2.58e-4 * coulomb / kilogram" + +[unit.peak_sun_hour] +defined_symbol = "PSH" +value = "1e3 * watt_hour / meter ** 2" + +[unit.langley] +defined_symbol = "Ly" +value = "thermochemical_calorie / centimeter ** 2" + +[unit.nit] +value = "candela / meter ** 2" + +[unit.stilb] +value = "candela / centimeter ** 2" + +[unit.lambert] +value = "1 / π * candela / centimeter ** 2" + +[unit.lumen] +defined_symbol = "lm" +value = "candela * steradian" + +[unit.lux] +defined_symbol = "lx" +value = "lumen / meter ** 2" + +[unit.atomic_unit_of_intensity] +defined_symbol = "a_u_intensity" +value = "0.5 * ε_0 * c * atomic_unit_of_electric_field ** 2" + +[unit.biot] +defined_symbol = "Bi" +value = "10 * ampere" + +[unit.abampere] +defined_symbol = "abA" +value = "biot" + +[unit.atomic_unit_of_current] +defined_symbol = "a_u_current" +value = "e / atomic_unit_of_time" + +[unit.mean_international_ampere] +defined_symbol = "A_it" +value = "mean_international_volt / mean_international_ohm" + +[unit.US_international_ampere] +defined_symbol = "A_US" +value = "US_international_volt / US_international_ohm" + +[unit.conventional_ampere_90] +defined_symbol = "A_90" +value = "K_J90 * R_K90 / (K_J * R_K) * ampere" + +[unit.planck_current] +value = "(c ** 6 / gravitational_constant / k_C) ** 0.5" + +[unit.coulomb] +defined_symbol = "C" +value = "ampere * second" + +[unit.abcoulomb] +defined_symbol = "abC" +value = "10 * C" + +[unit.faraday] +value = "e * N_A * mole" + +[unit.conventional_coulomb_90] +defined_symbol = "C_90" +value = "K_J90 * R_K90 / (K_J * R_K) * coulomb" + +[unit.ampere_hour] +defined_symbol = "Ah" +value = "ampere * hour" + +[unit.volt] +defined_symbol = "V" +value = "joule / coulomb" + +[unit.abvolt] +defined_symbol = "abV" +value = "1e-8 * volt" + +[unit.mean_international_volt] +defined_symbol = "V_it" +value = "1.00034 * volt" + +[unit.US_international_volt] +defined_symbol = "V_US" +value = "1.00033 * volt" + +[unit.conventional_volt_90] +defined_symbol = "V_90" +value = "K_J90 / K_J * volt" + +[unit.atomic_unit_of_electric_field] +defined_symbol = "a_u_electric_field" +value = "e * k_C / a_0 ** 2" + +[unit.townsend] +defined_symbol = "Td" +value = "1e-21 * V * m^2" + +[unit.ohm] +defined_symbol = "Ω" +value = "volt / ampere" + +[unit.abohm] +defined_symbol = "abΩ" +value = "1e-9 * ohm" + +[unit.mean_international_ohm] +defined_symbol = "Ω_it" +aliases = [ + "ohm_it", +] +value = "1.00049 * ohm" + +[unit.US_international_ohm] +defined_symbol = "Ω_US" +aliases = [ + "ohm_US", +] +value = "1.000495 * ohm" + +[unit.conventional_ohm_90] +defined_symbol = "Ω_90" +aliases = [ + "ohm_90", +] +value = "R_K / R_K90 * ohm" + +[unit.siemens] +defined_symbol = "S" +aliases = [ + "mho", +] +value = "ampere / volt" + +[unit.absiemens] +defined_symbol = "abS" +aliases = [ + "abmho", +] +value = "1e9 * siemens" + +[unit.farad] +defined_symbol = "F" +value = "coulomb / volt" + +[unit.abfarad] +defined_symbol = "abF" +value = "1e9 * farad" + +[unit.conventional_farad_90] +defined_symbol = "F_90" +value = "R_K90 / R_K * farad" + +[unit.weber] +defined_symbol = "Wb" +value = "volt * second" + +[unit.unit_pole] +value = "µ_0 * biot * centimeter" + +[unit.henry] +defined_symbol = "H" +value = "weber / ampere" + +[unit.abhenry] +defined_symbol = "abH" +value = "1e-9 * henry" + +[unit.conventional_henry_90] +defined_symbol = "H_90" +value = "R_K / R_K90 * henry" + +[unit.tesla] +defined_symbol = "T" +value = "weber / meter ** 2" + +[unit.gamma] +defined_symbol = "γ" +value = "1e-9 * tesla" + +[unit.ampere_turn] +defined_symbol = "At" +value = "ampere" + +[unit.biot_turn] +value = "biot" + +[unit.gilbert] +defined_symbol = "Gb" +value = "1 / (4 * π) * biot_turn" + +[unit.debye] +defined_symbol = "D" +value = "1e-9 / ζ * coulomb * angstrom" + +[unit.buckingham] +value = "debye * angstrom" + +[unit.bohr_magneton] +defined_symbol = "µ_B" +aliases = [ + "mu_B", +] +value = "e * hbar / (2 * m_e)" + +[unit.nuclear_magneton] +defined_symbol = "µ_N" +aliases = [ + "mu_N", +] +value = "e * hbar / (2 * m_p)" + +[unit.refractive_index_unit] +defined_symbol = "RIU" +value = "[]" + +[unit.decibelwatt] +defined_symbol = "dBW" +value = "watt; logbase: 10; logfactor: 10" + +[unit.decibelmilliwatt] +defined_symbol = "dBm" +value = "1e-3 watt; logbase: 10; logfactor: 10" + +[unit.decibelmicrowatt] +defined_symbol = "dBu" +value = "1e-6 watt; logbase: 10; logfactor: 10" + +[unit.decibel] +defined_symbol = "dB" +value = "1 ; logbase: 10; logfactor: 10" + +[unit.decade] +value = "1 ; logbase: 10; logfactor: 1" + +[unit.octave] +defined_symbol = "oct" +value = "1 ; logbase: 2; logfactor: 1" + +[unit.neper] +defined_symbol = "Np" +value = "1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfactor: 0.5" + +[unit.thou] +defined_symbol = "th" +aliases = [ + "mil_length", +] +value = "1e-3 * inch" + +[unit.inch] +defined_symbol = "in" +aliases = [ + "international_inch", + "inches", + "international_inches", +] +value = "yard / 36" + +[unit.hand] +value = "4 * inch" + +[unit.foot] +defined_symbol = "ft" +aliases = [ + "international_foot", + "feet", + "international_feet", +] +value = "yard / 3" + +[unit.yard] +defined_symbol = "yd" +aliases = [ + "international_yard", +] +value = "0.9144 * meter" + +[unit.mile] +defined_symbol = "mi" +aliases = [ + "international_mile", +] +value = "1760 * yard" + +[unit.circular_mil] +defined_symbol = "cmil" +value = "π / 4 * mil_length ** 2" + +[unit.square_inch] +defined_symbol = "sq_in" +aliases = [ + "square_inches", +] +value = "inch ** 2" + +[unit.square_foot] +defined_symbol = "sq_ft" +aliases = [ + "square_feet", +] +value = "foot ** 2" + +[unit.square_yard] +defined_symbol = "sq_yd" +value = "yard ** 2" + +[unit.square_mile] +defined_symbol = "sq_mi" +value = "mile ** 2" + +[unit.cubic_inch] +defined_symbol = "cu_in" +value = "in ** 3" + +[unit.cubic_foot] +defined_symbol = "cu_ft" +aliases = [ + "cubic_feet", +] +value = "ft ** 3" + +[unit.cubic_yard] +defined_symbol = "cu_yd" +value = "yd ** 3" + +[unit.link] +defined_symbol = "li" +aliases = [ + "survey_link", +] +value = "1e-2 * chain" + +[unit.survey_foot] +defined_symbol = "sft" +value = "1200 / 3937 * meter" + +[unit.fathom] +value = "6 * survey_foot" + +[unit.rod] +defined_symbol = "rd" +aliases = [ + "pole", + "perch", +] +value = "16.5 * survey_foot" + +[unit.chain] +value = "4 * rod" + +[unit.furlong] +defined_symbol = "fur" +value = "40 * rod" + +[unit.cables_length] +value = "120 * fathom" + +[unit.survey_mile] +defined_symbol = "smi" +aliases = [ + "us_statute_mile", +] +value = "5280 * survey_foot" + +[unit.league] +value = "3 * survey_mile" + +[unit.square_rod] +defined_symbol = "sq_rod" +aliases = [ + "sq_pole", + "sq_perch", +] +value = "rod ** 2" + +[unit.acre] +value = "10 * chain ** 2" + +[unit.square_survey_mile] +aliases = [ + "section", +] +value = "survey_mile ** 2" + +[unit.square_league] +value = "league ** 2" + +[unit.acre_foot] +aliases = [ + "acre_feet", +] +value = "acre * survey_foot" + +[unit.dry_pint] +defined_symbol = "dpi" +aliases = [ + "US_dry_pint", +] +value = "bushel / 64" + +[unit.dry_quart] +defined_symbol = "dqt" +aliases = [ + "US_dry_quart", +] +value = "bushel / 32" + +[unit.dry_gallon] +defined_symbol = "dgal" +aliases = [ + "US_dry_gallon", +] +value = "bushel / 8" + +[unit.peck] +defined_symbol = "pk" +value = "bushel / 4" + +[unit.bushel] +defined_symbol = "bu" +value = "2150.42 cubic_inch" + +[unit.dry_barrel] +aliases = [ + "US_dry_barrel", +] +value = "7056 cubic_inch" + +[unit.board_foot] +defined_symbol = "FBM" +aliases = [ + "board_feet", + "BF", + "BDFT", + "super_foot", + "superficial_foot", + "super_feet", + "superficial_feet", +] +value = "ft * ft * in" + +[unit.minim] +value = "pint / 7680" + +[unit.fluid_dram] +defined_symbol = "fldr" +aliases = [ + "fluidram", + "US_fluid_dram", + "US_liquid_dram", +] +value = "pint / 128" + +[unit.fluid_ounce] +defined_symbol = "floz" +aliases = [ + "US_fluid_ounce", + "US_liquid_ounce", +] +value = "pint / 16" + +[unit.gill] +defined_symbol = "gi" +aliases = [ + "liquid_gill", + "US_liquid_gill", +] +value = "pint / 4" + +[unit.pint] +defined_symbol = "pt" +aliases = [ + "liquid_pint", + "US_pint", +] +value = "quart / 2" + +[unit.fifth] +aliases = [ + "US_liquid_fifth", +] +value = "gallon / 5" + +[unit.quart] +defined_symbol = "qt" +aliases = [ + "liquid_quart", + "US_liquid_quart", +] +value = "gallon / 4" + +[unit.gallon] +defined_symbol = "gal" +aliases = [ + "liquid_gallon", + "US_liquid_gallon", +] +value = "231 * cubic_inch" + +[unit.teaspoon] +defined_symbol = "tsp" +value = "fluid_ounce / 6" + +[unit.tablespoon] +defined_symbol = "tbsp" +value = "fluid_ounce / 2" + +[unit.shot] +defined_symbol = "jig" +aliases = [ + "US_shot", +] +value = "3 * tablespoon" + +[unit.cup] +defined_symbol = "cp" +aliases = [ + "liquid_cup", + "US_liquid_cup", +] +value = "pint / 2" + +[unit.barrel] +defined_symbol = "bbl" +value = "31.5 * gallon" + +[unit.oil_barrel] +defined_symbol = "oil_bbl" +value = "42 * gallon" + +[unit.beer_barrel] +defined_symbol = "beer_bbl" +value = "31 * gallon" + +[unit.hogshead] +value = "63 * gallon" + +[unit.dram] +defined_symbol = "dr" +aliases = [ + "avoirdupois_dram", + "avdp_dram", + "drachm", +] +value = "pound / 256" + +[unit.ounce] +defined_symbol = "oz" +aliases = [ + "avoirdupois_ounce", + "avdp_ounce", +] +value = "pound / 16" + +[unit.pound] +defined_symbol = "lb" +aliases = [ + "avoirdupois_pound", + "avdp_pound", +] +value = "7e3 * grain" + +[unit.stone] +value = "14 * pound" + +[unit.quarter] +value = "28 * stone" + +[unit.bag] +value = "94 * pound" + +[unit.hundredweight] +defined_symbol = "cwt" +aliases = [ + "short_hundredweight", +] +value = "100 * pound" + +[unit.long_hundredweight] +value = "112 * pound" + +[unit.ton] +aliases = [ + "short_ton", +] +value = "2e3 * pound" + +[unit.long_ton] +value = "2240 * pound" + +[unit.slug] +value = "g_0 * pound * second ** 2 / foot" + +[unit.slinch] +defined_symbol = "blob" +aliases = [ + "slugette", +] +value = "g_0 * pound * second ** 2 / inch" + +[unit.force_ounce] +defined_symbol = "ozf" +aliases = [ + "ounce_force", +] +value = "g_0 * ounce" + +[unit.force_pound] +defined_symbol = "lbf" +aliases = [ + "pound_force", +] +value = "g_0 * pound" + +[unit.force_ton] +aliases = [ + "ton_force", + "force_short_ton", + "short_ton_force", +] +value = "g_0 * ton" + +[unit.force_long_ton] +aliases = [ + "long_ton_force", +] +value = "g_0 * long_ton" + +[unit.kip] +value = "1e3 * force_pound" + +[unit.poundal] +defined_symbol = "pdl" +value = "pound * foot / second ** 2" + +[unit.UK_hundredweight] +defined_symbol = "UK_cwt" +value = "long_hundredweight" + +[unit.UK_ton] +value = "long_ton" + +[unit.UK_force_ton] +aliases = [ + "UK_ton_force", +] +value = "force_long_ton" + +[unit.US_hundredweight] +defined_symbol = "US_cwt" +value = "hundredweight" + +[unit.US_ton] +value = "ton" + +[unit.US_force_ton] +aliases = [ + "US_ton_force", +] +value = "force_ton" + +[unit.pennyweight] +defined_symbol = "dwt" +value = "24 * grain" + +[unit.troy_ounce] +defined_symbol = "toz" +aliases = [ + "ozt", +] +value = "480 * grain" + +[unit.troy_pound] +defined_symbol = "tlb" +aliases = [ + "lbt", +] +value = "12 * troy_ounce" + +[unit.scruple] +value = "20 * grain" + +[unit.apothecary_dram] +defined_symbol = "ap_dr" +value = "3 * scruple" + +[unit.apothecary_ounce] +defined_symbol = "ap_oz" +value = "8 * apothecary_dram" + +[unit.apothecary_pound] +defined_symbol = "ap_lb" +value = "12 * apothecary_ounce" + +[unit.imperial_minim] +value = "imperial_fluid_ounce / 480" + +[unit.imperial_fluid_scruple] +value = "imperial_fluid_ounce / 24" + +[unit.imperial_fluid_drachm] +defined_symbol = "imperial_fldr" +aliases = [ + "imperial_fluid_dram", +] +value = "imperial_fluid_ounce / 8" + +[unit.imperial_fluid_ounce] +defined_symbol = "imperial_floz" +aliases = [ + "UK_fluid_ounce", +] +value = "imperial_pint / 20" + +[unit.imperial_gill] +defined_symbol = "imperial_gi" +aliases = [ + "UK_gill", +] +value = "imperial_pint / 4" + +[unit.imperial_cup] +defined_symbol = "imperial_cp" +aliases = [ + "UK_cup", +] +value = "imperial_pint / 2" + +[unit.imperial_pint] +defined_symbol = "imperial_pt" +aliases = [ + "UK_pint", +] +value = "imperial_gallon / 8" + +[unit.imperial_quart] +defined_symbol = "imperial_qt" +aliases = [ + "UK_quart", +] +value = "imperial_gallon / 4" + +[unit.imperial_gallon] +defined_symbol = "imperial_gal" +aliases = [ + "UK_gallon", +] +value = "4.54609 * liter" + +[unit.imperial_peck] +defined_symbol = "imperial_pk" +aliases = [ + "UK_pk", +] +value = "2 * imperial_gallon" + +[unit.imperial_bushel] +defined_symbol = "imperial_bu" +aliases = [ + "UK_bushel", +] +value = "8 * imperial_gallon" + +[unit.imperial_barrel] +defined_symbol = "imperial_bbl" +aliases = [ + "UK_bbl", +] +value = "36 * imperial_gallon" + +[unit.pica] +aliases = [ + "printers_pica", +] +value = "inch / 6" + +[unit.point] +defined_symbol = "pp" +aliases = [ + "printers_point", + "big_point", + "bp", +] +value = "pica / 12" + +[unit.didot] +value = "1 / 2660 * m" + +[unit.cicero] +value = "12 * didot" + +[unit.tex_point] +value = "inch / 72.27" + +[unit.tex_pica] +value = "12 * tex_point" + +[unit.tex_didot] +value = "1238 / 1157 * tex_point" + +[unit.tex_cicero] +value = "12 * tex_didot" + +[unit.scaled_point] +value = "tex_point / 65536" + +[unit.css_pixel] +defined_symbol = "px" +value = "inch / 96" + +[unit.pixel] +aliases = [ + "dot", + "pel", + "picture_element", +] +value = "[printing_unit]" + +[unit.pixels_per_centimeter] +defined_symbol = "PPCM" +value = "pixel / cm" + +[unit.pixels_per_inch] +defined_symbol = "dots_per_inch" +aliases = [ + "PPI", + "ppi", + "DPI", + "printers_dpi", +] +value = "pixel / inch" + +[unit.bits_per_pixel] +defined_symbol = "bpp" +value = "bit / pixel" + +[unit.tex] +defined_symbol = "Tt" +value = "gram / kilometer" + +[unit.dtex] +value = "decitex" + +[unit.denier] +defined_symbol = "den" +value = "gram / (9 * kilometer)" + +[unit.jute] +defined_symbol = "Tj" +value = "pound / (14400 * yard)" + +[unit.aberdeen] +defined_symbol = "Ta" +value = "jute" + +[unit.RKM] +value = "gf / tex" + +[unit.number_english] +defined_symbol = "Ne" +aliases = [ + "NeC", + "ECC", +] +value = "840 * yard / pound" + +[unit.number_meter] +defined_symbol = "Nm" +value = "kilometer / kilogram" + +[unit.franklin] +defined_symbol = "Fr" +aliases = [ + "statcoulomb", + "statC", + "esu", +] +value = "erg ** 0.5 * centimeter ** 0.5" + +[unit.statvolt] +defined_symbol = "statV" +value = "erg / franklin" + +[unit.statampere] +defined_symbol = "statA" +value = "franklin / second" + +[unit.gauss] +defined_symbol = "G" +value = "dyne / franklin" + +[unit.maxwell] +defined_symbol = "Mx" +value = "gauss * centimeter ** 2" + +[unit.oersted] +defined_symbol = "Oe" +aliases = [ + "ørsted", +] +value = "dyne / maxwell" + +[unit.statohm] +defined_symbol = "statΩ" +value = "statvolt / statampere" + +[unit.statfarad] +defined_symbol = "statF" +value = "franklin / statvolt" + +[unit.statmho] +value = "statampere / statvolt" + +[unit.statweber] +defined_symbol = "statWb" +value = "statvolt * second" + +[unit.stattesla] +defined_symbol = "statT" +value = "statweber / centimeter ** 2" + +[unit.stathenry] +defined_symbol = "statH" +value = "statweber / statampere" + +[dimension.area] +value = "[length] ** 2" + +[dimension.volume] +value = "[length] ** 3" + +[dimension.frequency] +value = "1 / [time]" + +[dimension.wavenumber] +value = "1 / [length]" + +[dimension.velocity] +value = "[length] / [time]" + +[dimension.speed] +value = "[velocity]" + +[dimension.volumetric_flow_rate] +value = "[volume] / [time]" + +[dimension.acceleration] +value = "[velocity] / [time]" + +[dimension.force] +value = "[mass] * [acceleration]" + +[dimension.energy] +value = "[force] * [length]" + +[dimension.power] +value = "[energy] / [time]" + +[dimension.momentum] +value = "[length] * [mass] / [time]" + +[dimension.density] +value = "[mass] / [volume]" + +[dimension.pressure] +value = "[force] / [area]" + +[dimension.torque] +value = "[force] * [length]" + +[dimension.viscosity] +value = "[pressure] * [time]" + +[dimension.kinematic_viscosity] +value = "[area] / [time]" + +[dimension.fluidity] +value = "1 / [viscosity]" + +[dimension.concentration] +value = "[substance] / [volume]" + +[dimension.activity] +value = "[substance] / [time]" + +[dimension.entropy] +value = "[energy] / [temperature]" + +[dimension.molar_entropy] +value = "[entropy] / [substance]" + +[dimension.heat_transmission] +value = "[energy] / [area]" + +[dimension.luminance] +value = "[luminosity] / [area]" + +[dimension.luminous_flux] +value = "[luminosity]" + +[dimension.illuminance] +value = "[luminous_flux] / [area]" + +[dimension.intensity] +value = "[power] / [area]" + +[dimension.charge] +value = "[current] * [time]" + +[dimension.electric_potential] +value = "[energy] / [charge]" + +[dimension.electric_field] +value = "[electric_potential] / [length]" + +[dimension.electric_displacement_field] +value = "[charge] / [area]" + +[dimension.reduced_electric_field] +value = "[electric_field] * [area]" + +[dimension.resistance] +value = "[electric_potential] / [current]" + +[dimension.resistivity] +value = "[resistance] * [length]" + +[dimension.conductance] +value = "[current] / [electric_potential]" + +[dimension.capacitance] +value = "[charge] / [electric_potential]" + +[dimension.magnetic_flux] +value = "[electric_potential] * [time]" + +[dimension.inductance] +value = "[magnetic_flux] / [current]" + +[dimension.magnetic_field] +value = "[magnetic_flux] / [area]" + +[dimension.magnetomotive_force] +value = "[current]" + +[dimension.magnetic_field_strength] +value = "[current] / [length]" + +[dimension.electric_dipole] +value = "[charge] * [length]" + +[dimension.electric_quadrupole] +value = "[charge] * [area]" + +[dimension.magnetic_dipole] +value = "[current] * [area]" + +[dimension.refractive_index] +value = "[]" + +[dimension.gaussian_charge] +value = "[length] ** 1.5 * [mass] ** 0.5 / [time]" + +[dimension.gaussian_current] +value = "[gaussian_charge] / [time]" + +[dimension.gaussian_electric_potential] +value = "[gaussian_charge] / [length]" + +[dimension.gaussian_electric_field] +value = "[gaussian_electric_potential] / [length]" + +[dimension.gaussian_electric_displacement_field] +value = "[gaussian_charge] / [area]" + +[dimension.gaussian_electric_flux] +value = "[gaussian_charge]" + +[dimension.gaussian_electric_dipole] +value = "[gaussian_charge] * [length]" + +[dimension.gaussian_electric_quadrupole] +value = "[gaussian_charge] * [area]" + +[dimension.gaussian_magnetic_field] +value = "[force] / [gaussian_charge]" + +[dimension.gaussian_magnetic_field_strength] +value = "[gaussian_magnetic_field]" + +[dimension.gaussian_magnetic_flux] +value = "[gaussian_magnetic_field] * [area]" + +[dimension.gaussian_magnetic_dipole] +value = "[energy] / [gaussian_magnetic_field]" + +[dimension.gaussian_resistance] +value = "[gaussian_electric_potential] / [gaussian_current]" + +[dimension.gaussian_resistivity] +value = "[gaussian_resistance] * [length]" + +[dimension.gaussian_capacitance] +value = "[gaussian_charge] / [gaussian_electric_potential]" + +[dimension.gaussian_inductance] +value = "[gaussian_electric_potential] * [time] / [gaussian_current]" + +[dimension.gaussian_conductance] +value = "[gaussian_current] / [gaussian_electric_potential]" + +[dimension.esu_charge] +value = "[length] ** 1.5 * [mass] ** 0.5 / [time]" + +[dimension.esu_current] +value = "[esu_charge] / [time]" + +[dimension.esu_electric_potential] +value = "[esu_charge] / [length]" + +[dimension.esu_magnetic_flux] +value = "[esu_electric_potential] * [time]" + +[dimension.esu_magnetic_field] +value = "[esu_magnetic_flux] / [area]" + +[dimension.esu_magnetic_field_strength] +value = "[esu_current] / [length]" + +[dimension.esu_magnetic_dipole] +value = "[esu_current] * [area]" + +[group.USCSLengthInternational.definitions.thou] +defined_symbol = "th" +aliases = [ + "mil_length", +] +value = "1e-3 * inch" + +[group.USCSLengthInternational.definitions.inch] +defined_symbol = "in" +aliases = [ + "international_inch", + "inches", + "international_inches", +] +value = "yard / 36" + +[group.USCSLengthInternational.definitions.hand] +value = "4 * inch" + +[group.USCSLengthInternational.definitions.foot] +defined_symbol = "ft" +aliases = [ + "international_foot", + "feet", + "international_feet", +] +value = "yard / 3" + +[group.USCSLengthInternational.definitions.yard] +defined_symbol = "yd" +aliases = [ + "international_yard", +] +value = "0.9144 * meter" + +[group.USCSLengthInternational.definitions.mile] +defined_symbol = "mi" +aliases = [ + "international_mile", +] +value = "1760 * yard" + +[group.USCSLengthInternational.definitions.circular_mil] +defined_symbol = "cmil" +value = "π / 4 * mil_length ** 2" + +[group.USCSLengthInternational.definitions.square_inch] +defined_symbol = "sq_in" +aliases = [ + "square_inches", +] +value = "inch ** 2" + +[group.USCSLengthInternational.definitions.square_foot] +defined_symbol = "sq_ft" +aliases = [ + "square_feet", +] +value = "foot ** 2" + +[group.USCSLengthInternational.definitions.square_yard] +defined_symbol = "sq_yd" +value = "yard ** 2" + +[group.USCSLengthInternational.definitions.square_mile] +defined_symbol = "sq_mi" +value = "mile ** 2" + +[group.USCSLengthInternational.definitions.cubic_inch] +defined_symbol = "cu_in" +value = "in ** 3" + +[group.USCSLengthInternational.definitions.cubic_foot] +defined_symbol = "cu_ft" +aliases = [ + "cubic_feet", +] +value = "ft ** 3" + +[group.USCSLengthInternational.definitions.cubic_yard] +defined_symbol = "cu_yd" +value = "yd ** 3" + +[group.USCSLengthSurvey.definitions.link] +defined_symbol = "li" +aliases = [ + "survey_link", +] +value = "1e-2 * chain" + +[group.USCSLengthSurvey.definitions.survey_foot] +defined_symbol = "sft" +value = "1200 / 3937 * meter" + +[group.USCSLengthSurvey.definitions.fathom] +value = "6 * survey_foot" + +[group.USCSLengthSurvey.definitions.rod] +defined_symbol = "rd" +aliases = [ + "pole", + "perch", +] +value = "16.5 * survey_foot" + +[group.USCSLengthSurvey.definitions.chain] +value = "4 * rod" + +[group.USCSLengthSurvey.definitions.furlong] +defined_symbol = "fur" +value = "40 * rod" + +[group.USCSLengthSurvey.definitions.cables_length] +value = "120 * fathom" + +[group.USCSLengthSurvey.definitions.survey_mile] +defined_symbol = "smi" +aliases = [ + "us_statute_mile", +] +value = "5280 * survey_foot" + +[group.USCSLengthSurvey.definitions.league] +value = "3 * survey_mile" + +[group.USCSLengthSurvey.definitions.square_rod] +defined_symbol = "sq_rod" +aliases = [ + "sq_pole", + "sq_perch", +] +value = "rod ** 2" + +[group.USCSLengthSurvey.definitions.acre] +value = "10 * chain ** 2" + +[group.USCSLengthSurvey.definitions.square_survey_mile] +aliases = [ + "section", +] +value = "survey_mile ** 2" + +[group.USCSLengthSurvey.definitions.square_league] +value = "league ** 2" + +[group.USCSLengthSurvey.definitions.acre_foot] +aliases = [ + "acre_feet", +] +value = "acre * survey_foot" + +[group.USCSDryVolume.definitions.dry_pint] +defined_symbol = "dpi" +aliases = [ + "US_dry_pint", +] +value = "bushel / 64" + +[group.USCSDryVolume.definitions.dry_quart] +defined_symbol = "dqt" +aliases = [ + "US_dry_quart", +] +value = "bushel / 32" + +[group.USCSDryVolume.definitions.dry_gallon] +defined_symbol = "dgal" +aliases = [ + "US_dry_gallon", +] +value = "bushel / 8" + +[group.USCSDryVolume.definitions.peck] +defined_symbol = "pk" +value = "bushel / 4" + +[group.USCSDryVolume.definitions.bushel] +defined_symbol = "bu" +value = "2150.42 cubic_inch" + +[group.USCSDryVolume.definitions.dry_barrel] +aliases = [ + "US_dry_barrel", +] +value = "7056 cubic_inch" + +[group.USCSDryVolume.definitions.board_foot] +defined_symbol = "FBM" +aliases = [ + "board_feet", + "BF", + "BDFT", + "super_foot", + "superficial_foot", + "super_feet", + "superficial_feet", +] +value = "ft * ft * in" + +[group.USCSLiquidVolume.definitions.minim] +value = "pint / 7680" + +[group.USCSLiquidVolume.definitions.fluid_dram] +defined_symbol = "fldr" +aliases = [ + "fluidram", + "US_fluid_dram", + "US_liquid_dram", +] +value = "pint / 128" + +[group.USCSLiquidVolume.definitions.fluid_ounce] +defined_symbol = "floz" +aliases = [ + "US_fluid_ounce", + "US_liquid_ounce", +] +value = "pint / 16" + +[group.USCSLiquidVolume.definitions.gill] +defined_symbol = "gi" +aliases = [ + "liquid_gill", + "US_liquid_gill", +] +value = "pint / 4" + +[group.USCSLiquidVolume.definitions.pint] +defined_symbol = "pt" +aliases = [ + "liquid_pint", + "US_pint", +] +value = "quart / 2" + +[group.USCSLiquidVolume.definitions.fifth] +aliases = [ + "US_liquid_fifth", +] +value = "gallon / 5" + +[group.USCSLiquidVolume.definitions.quart] +defined_symbol = "qt" +aliases = [ + "liquid_quart", + "US_liquid_quart", +] +value = "gallon / 4" + +[group.USCSLiquidVolume.definitions.gallon] +defined_symbol = "gal" +aliases = [ + "liquid_gallon", + "US_liquid_gallon", +] +value = "231 * cubic_inch" + +[group.USCSVolumeOther.definitions.teaspoon] +defined_symbol = "tsp" +value = "fluid_ounce / 6" + +[group.USCSVolumeOther.definitions.tablespoon] +defined_symbol = "tbsp" +value = "fluid_ounce / 2" + +[group.USCSVolumeOther.definitions.shot] +defined_symbol = "jig" +aliases = [ + "US_shot", +] +value = "3 * tablespoon" + +[group.USCSVolumeOther.definitions.cup] +defined_symbol = "cp" +aliases = [ + "liquid_cup", + "US_liquid_cup", +] +value = "pint / 2" + +[group.USCSVolumeOther.definitions.barrel] +defined_symbol = "bbl" +value = "31.5 * gallon" + +[group.USCSVolumeOther.definitions.oil_barrel] +defined_symbol = "oil_bbl" +value = "42 * gallon" + +[group.USCSVolumeOther.definitions.beer_barrel] +defined_symbol = "beer_bbl" +value = "31 * gallon" + +[group.USCSVolumeOther.definitions.hogshead] +value = "63 * gallon" + +[group.Avoirdupois.definitions.dram] +defined_symbol = "dr" +aliases = [ + "avoirdupois_dram", + "avdp_dram", + "drachm", +] +value = "pound / 256" + +[group.Avoirdupois.definitions.ounce] +defined_symbol = "oz" +aliases = [ + "avoirdupois_ounce", + "avdp_ounce", +] +value = "pound / 16" + +[group.Avoirdupois.definitions.pound] +defined_symbol = "lb" +aliases = [ + "avoirdupois_pound", + "avdp_pound", +] +value = "7e3 * grain" + +[group.Avoirdupois.definitions.stone] +value = "14 * pound" + +[group.Avoirdupois.definitions.quarter] +value = "28 * stone" + +[group.Avoirdupois.definitions.bag] +value = "94 * pound" + +[group.Avoirdupois.definitions.hundredweight] +defined_symbol = "cwt" +aliases = [ + "short_hundredweight", +] +value = "100 * pound" + +[group.Avoirdupois.definitions.long_hundredweight] +value = "112 * pound" + +[group.Avoirdupois.definitions.ton] +aliases = [ + "short_ton", +] +value = "2e3 * pound" + +[group.Avoirdupois.definitions.long_ton] +value = "2240 * pound" + +[group.Avoirdupois.definitions.slug] +value = "g_0 * pound * second ** 2 / foot" + +[group.Avoirdupois.definitions.slinch] +defined_symbol = "blob" +aliases = [ + "slugette", +] +value = "g_0 * pound * second ** 2 / inch" + +[group.Avoirdupois.definitions.force_ounce] +defined_symbol = "ozf" +aliases = [ + "ounce_force", +] +value = "g_0 * ounce" + +[group.Avoirdupois.definitions.force_pound] +defined_symbol = "lbf" +aliases = [ + "pound_force", +] +value = "g_0 * pound" + +[group.Avoirdupois.definitions.force_ton] +aliases = [ + "ton_force", + "force_short_ton", + "short_ton_force", +] +value = "g_0 * ton" + +[group.Avoirdupois.definitions.force_long_ton] +aliases = [ + "long_ton_force", +] +value = "g_0 * long_ton" + +[group.Avoirdupois.definitions.kip] +value = "1e3 * force_pound" + +[group.Avoirdupois.definitions.poundal] +defined_symbol = "pdl" +value = "pound * foot / second ** 2" + +[group.AvoirdupoisUK] +using_group_names = [ + "Avoirdupois", +] + +[group.AvoirdupoisUK.definitions.UK_hundredweight] +defined_symbol = "UK_cwt" +value = "long_hundredweight" + +[group.AvoirdupoisUK.definitions.UK_ton] +value = "long_ton" + +[group.AvoirdupoisUK.definitions.UK_force_ton] +aliases = [ + "UK_ton_force", +] +value = "force_long_ton" + +[group.AvoirdupoisUS] +using_group_names = [ + "Avoirdupois", +] + +[group.AvoirdupoisUS.definitions.US_hundredweight] +defined_symbol = "US_cwt" +value = "hundredweight" + +[group.AvoirdupoisUS.definitions.US_ton] +value = "ton" + +[group.AvoirdupoisUS.definitions.US_force_ton] +aliases = [ + "US_ton_force", +] +value = "force_ton" + +[group.Troy.definitions.pennyweight] +defined_symbol = "dwt" +value = "24 * grain" + +[group.Troy.definitions.troy_ounce] +defined_symbol = "toz" +aliases = [ + "ozt", +] +value = "480 * grain" + +[group.Troy.definitions.troy_pound] +defined_symbol = "tlb" +aliases = [ + "lbt", +] +value = "12 * troy_ounce" + +[group.Apothecary.definitions.scruple] +value = "20 * grain" + +[group.Apothecary.definitions.apothecary_dram] +defined_symbol = "ap_dr" +value = "3 * scruple" + +[group.Apothecary.definitions.apothecary_ounce] +defined_symbol = "ap_oz" +value = "8 * apothecary_dram" + +[group.Apothecary.definitions.apothecary_pound] +defined_symbol = "ap_lb" +value = "12 * apothecary_ounce" + +[group.ImperialVolume.definitions.imperial_minim] +value = "imperial_fluid_ounce / 480" + +[group.ImperialVolume.definitions.imperial_fluid_scruple] +value = "imperial_fluid_ounce / 24" + +[group.ImperialVolume.definitions.imperial_fluid_drachm] +defined_symbol = "imperial_fldr" +aliases = [ + "imperial_fluid_dram", +] +value = "imperial_fluid_ounce / 8" + +[group.ImperialVolume.definitions.imperial_fluid_ounce] +defined_symbol = "imperial_floz" +aliases = [ + "UK_fluid_ounce", +] +value = "imperial_pint / 20" + +[group.ImperialVolume.definitions.imperial_gill] +defined_symbol = "imperial_gi" +aliases = [ + "UK_gill", +] +value = "imperial_pint / 4" + +[group.ImperialVolume.definitions.imperial_cup] +defined_symbol = "imperial_cp" +aliases = [ + "UK_cup", +] +value = "imperial_pint / 2" + +[group.ImperialVolume.definitions.imperial_pint] +defined_symbol = "imperial_pt" +aliases = [ + "UK_pint", +] +value = "imperial_gallon / 8" + +[group.ImperialVolume.definitions.imperial_quart] +defined_symbol = "imperial_qt" +aliases = [ + "UK_quart", +] +value = "imperial_gallon / 4" + +[group.ImperialVolume.definitions.imperial_gallon] +defined_symbol = "imperial_gal" +aliases = [ + "UK_gallon", +] +value = "4.54609 * liter" + +[group.ImperialVolume.definitions.imperial_peck] +defined_symbol = "imperial_pk" +aliases = [ + "UK_pk", +] +value = "2 * imperial_gallon" + +[group.ImperialVolume.definitions.imperial_bushel] +defined_symbol = "imperial_bu" +aliases = [ + "UK_bushel", +] +value = "8 * imperial_gallon" + +[group.ImperialVolume.definitions.imperial_barrel] +defined_symbol = "imperial_bbl" +aliases = [ + "UK_bbl", +] +value = "36 * imperial_gallon" + +[group.Printer.definitions.pica] +aliases = [ + "printers_pica", +] +value = "inch / 6" + +[group.Printer.definitions.point] +defined_symbol = "pp" +aliases = [ + "printers_point", + "big_point", + "bp", +] +value = "pica / 12" + +[group.Printer.definitions.didot] +value = "1 / 2660 * m" + +[group.Printer.definitions.cicero] +value = "12 * didot" + +[group.Printer.definitions.tex_point] +value = "inch / 72.27" + +[group.Printer.definitions.tex_pica] +value = "12 * tex_point" + +[group.Printer.definitions.tex_didot] +value = "1238 / 1157 * tex_point" + +[group.Printer.definitions.tex_cicero] +value = "12 * tex_didot" + +[group.Printer.definitions.scaled_point] +value = "tex_point / 65536" + +[group.Printer.definitions.css_pixel] +defined_symbol = "px" +value = "inch / 96" + +[group.Printer.definitions.pixel] +aliases = [ + "dot", + "pel", + "picture_element", +] +value = "[printing_unit]" + +[group.Printer.definitions.pixels_per_centimeter] +defined_symbol = "PPCM" +value = "pixel / cm" + +[group.Printer.definitions.pixels_per_inch] +defined_symbol = "dots_per_inch" +aliases = [ + "PPI", + "ppi", + "DPI", + "printers_dpi", +] +value = "pixel / inch" + +[group.Printer.definitions.bits_per_pixel] +defined_symbol = "bpp" +value = "bit / pixel" + +[group.Textile.definitions.tex] +defined_symbol = "Tt" +value = "gram / kilometer" + +[group.Textile.definitions.dtex] +value = "decitex" + +[group.Textile.definitions.denier] +defined_symbol = "den" +value = "gram / (9 * kilometer)" + +[group.Textile.definitions.jute] +defined_symbol = "Tj" +value = "pound / (14400 * yard)" + +[group.Textile.definitions.aberdeen] +defined_symbol = "Ta" +value = "jute" + +[group.Textile.definitions.RKM] +value = "gf / tex" + +[group.Textile.definitions.number_english] +defined_symbol = "Ne" +aliases = [ + "NeC", + "ECC", +] +value = "840 * yard / pound" + +[group.Textile.definitions.number_meter] +defined_symbol = "Nm" +value = "kilometer / kilogram" + +[group.Gaussian.definitions.franklin] +defined_symbol = "Fr" +aliases = [ + "statcoulomb", + "statC", + "esu", +] +value = "erg ** 0.5 * centimeter ** 0.5" + +[group.Gaussian.definitions.statvolt] +defined_symbol = "statV" +value = "erg / franklin" + +[group.Gaussian.definitions.statampere] +defined_symbol = "statA" +value = "franklin / second" + +[group.Gaussian.definitions.gauss] +defined_symbol = "G" +value = "dyne / franklin" + +[group.Gaussian.definitions.maxwell] +defined_symbol = "Mx" +value = "gauss * centimeter ** 2" + +[group.Gaussian.definitions.oersted] +defined_symbol = "Oe" +aliases = [ + "ørsted", +] +value = "dyne / maxwell" + +[group.Gaussian.definitions.statohm] +defined_symbol = "statΩ" +value = "statvolt / statampere" + +[group.Gaussian.definitions.statfarad] +defined_symbol = "statF" +value = "franklin / statvolt" + +[group.Gaussian.definitions.statmho] +value = "statampere / statvolt" + +[group.ESU] +using_group_names = [ + "Gaussian", +] + +[group.ESU.definitions.statweber] +defined_symbol = "statWb" +value = "statvolt * second" + +[group.ESU.definitions.stattesla] +defined_symbol = "statT" +value = "statweber / centimeter ** 2" + +[group.ESU.definitions.stathenry] +defined_symbol = "statH" +value = "statweber / statampere" + +[system.SI] +using_group_names = [ + "root", +] +rules = [ + "second", + "meter", + "kilogram", + "ampere", + "kelvin", + "mole", + "candela", +] + +[system.mks] +using_group_names = [ + "international", +] +rules = [ + "meter", + "kilogram", + "second", +] + +[system.cgs] +using_group_names = [ + "international", + "Gaussian", + "ESU", +] +rules = [ + "centimeter", + "gram", + "second", +] + +[system.atomic] +using_group_names = [ + "international", +] +rules = [ + "bohr: meter", + "electron_mass: gram", + "atomic_unit_of_time: second", + "atomic_unit_of_current: ampere", + "atomic_unit_of_temperature: kelvin", +] + +[system.Planck] +using_group_names = [ + "international", +] +rules = [ + "planck_length: meter", + "planck_mass: gram", + "planck_time: second", + "planck_current: ampere", + "planck_temperature: kelvin", +] + +[system.imperial] +using_group_names = [ + "ImperialVolume", + "USCSLengthInternational", + "AvoirdupoisUK", +] +rules = [ + "yard", + "pound", +] + +[system.US] +using_group_names = [ + "USCSLiquidVolume", + "USCSDryVolume", + "USCSVolumeOther", + "USCSLengthInternational", + "USCSLengthSurvey", + "AvoirdupoisUS", +] +rules = [ + "yard", + "pound", +] + +[context.Gaussian] +aliases = [ + "Gau", +] +relations = [ + "[gaussian_charge] -> [charge]: value / k_C ** 0.5", + "[charge] -> [gaussian_charge]: value * k_C ** 0.5", + "[gaussian_current] -> [current]: value / k_C ** 0.5", + "[current] -> [gaussian_current]: value * k_C ** 0.5", + "[gaussian_electric_potential] -> [electric_potential]: value * k_C ** 0.5", + "[electric_potential] -> [gaussian_electric_potential]: value / k_C ** 0.5", + "[gaussian_electric_field] -> [electric_field]: value * k_C ** 0.5", + "[electric_field] -> [gaussian_electric_field]: value / k_C ** 0.5", + "[gaussian_electric_displacement_field] -> [electric_displacement_field]: value / (4 * π / ε_0) ** 0.5", + "[electric_displacement_field] -> [gaussian_electric_displacement_field]: value * (4 * π / ε_0) ** 0.5", + "[gaussian_electric_dipole] -> [electric_dipole]: value / k_C ** 0.5", + "[electric_dipole] -> [gaussian_electric_dipole]: value * k_C ** 0.5", + "[gaussian_electric_quadrupole] -> [electric_quadrupole]: value / k_C ** 0.5", + "[electric_quadrupole] -> [gaussian_electric_quadrupole]: value * k_C ** 0.5", + "[gaussian_magnetic_field] -> [magnetic_field]: value / (4 * π / µ_0) ** 0.5", + "[magnetic_field] -> [gaussian_magnetic_field]: value * (4 * π / µ_0) ** 0.5", + "[gaussian_magnetic_flux] -> [magnetic_flux]: value / (4 * π / µ_0) ** 0.5", + "[magnetic_flux] -> [gaussian_magnetic_flux]: value * (4 * π / µ_0) ** 0.5", + "[gaussian_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π * µ_0) ** 0.5", + "[magnetic_field_strength] -> [gaussian_magnetic_field_strength]: value * (4 * π * µ_0) ** 0.5", + "[gaussian_magnetic_dipole] -> [magnetic_dipole]: value * (4 * π / µ_0) ** 0.5", + "[magnetic_dipole] -> [gaussian_magnetic_dipole]: value / (4 * π / µ_0) ** 0.5", + "[gaussian_resistance] -> [resistance]: value * k_C", + "[resistance] -> [gaussian_resistance]: value / k_C", + "[gaussian_resistivity] -> [resistivity]: value * k_C", + "[resistivity] -> [gaussian_resistivity]: value / k_C", + "[gaussian_capacitance] -> [capacitance]: value / k_C", + "[capacitance] -> [gaussian_capacitance]: value * k_C", + "[gaussian_inductance] -> [inductance]: value * k_C", + "[inductance] -> [gaussian_inductance]: value / k_C", + "[gaussian_conductance] -> [conductance]: value / k_C", + "[conductance] -> [gaussian_conductance]: value * k_C", +] + +[context.ESU] +aliases = [ + "esu", +] +relations = [ + "[esu_magnetic_field] -> [magnetic_field]: value * k_C ** 0.5", + "[magnetic_field] -> [esu_magnetic_field]: value / k_C ** 0.5", + "[esu_magnetic_flux] -> [magnetic_flux]: value * k_C ** 0.5", + "[magnetic_flux] -> [esu_magnetic_flux]: value / k_C ** 0.5", + "[esu_magnetic_field_strength] -> [magnetic_field_strength]: value / (4 * π / ε_0) ** 0.5", + "[magnetic_field_strength] -> [esu_magnetic_field_strength]: value * (4 * π / ε_0) ** 0.5", + "[esu_magnetic_dipole] -> [magnetic_dipole]: value / k_C ** 0.5", + "[magnetic_dipole] -> [esu_magnetic_dipole]: value * k_C ** 0.5", +] + +[context.spectroscopy] +aliases = [ + "sp", +] +relations = [ + "[length] <-> [frequency]: speed_of_light / n / value", + "[frequency] -> [energy]: planck_constant * value", + "[energy] -> [frequency]: value / planck_constant", + "[wavenumber] <-> [length]: 1 / value", +] + +[context.spectroscopy.defaults] +n = "1" + +[context.boltzmann] +relations = [ + "[temperature] -> [energy]: boltzmann_constant * value", + "[energy] -> [temperature]: value / boltzmann_constant", +] + +[context.energy] +relations = [ + "[energy] -> [energy] / [substance]: value * N_A", + "[energy] / [substance] -> [energy]: value / N_A", + "[energy] -> [mass]: value / c ** 2", + "[mass] -> [energy]: value * c ** 2", +] + +[context.chemistry] +aliases = [ + "chem", +] +relations = [ + "[substance] -> [mass]: value * mw", + "[mass] -> [substance]: value / mw", + "[substance] / [volume] -> [mass] / [volume]: value * mw", + "[mass] / [volume] -> [substance] / [volume]: value / mw", + "[substance] / [mass] -> [mass] / [mass]: value * mw", + "[mass] / [mass] -> [substance] / [mass]: value / mw", + "[substance] / [volume] -> [substance]: value * volume", + "[substance] -> [substance] / [volume]: value / volume", + "[substance] / [mass] -> [substance]: value * solvent_mass", + "[substance] -> [substance] / [mass]: value / solvent_mass", + "[substance] / [mass] -> [substance]/[volume]: value * solvent_mass / volume", + "[substance] / [volume] -> [substance] / [mass]: value / solvent_mass * volume", +] + +[context.chemistry.defaults] +mw = "0" +volume = "0" +solvent_mass = "0" + +[context.textile] +relations = [ + "[mass] / [length] <-> [length] / [mass]: 1 / value", +] From 639acd9deb891d98227e7e642036a4cadb478e50 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Feb 2025 23:07:18 +0000 Subject: [PATCH 06/20] test toml --- pint/testsuite/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pint/testsuite/conftest.py b/pint/testsuite/conftest.py index 0a42f44af..da8a85cff 100644 --- a/pint/testsuite/conftest.py +++ b/pint/testsuite/conftest.py @@ -63,9 +63,9 @@ def registry_tiny(tiny_definition_file: pathlib.Path): return pint.UnitRegistry(tiny_definition_file) -@pytest.fixture -def func_registry(): - return pint.UnitRegistry() +@pytest.fixture(params=["pint/default_en.txt", "pint/default_en.toml"]) +def func_registry(request): + return pint.UnitRegistry(request.param) @pytest.fixture(scope="class") From cacbdecbfb93c5e8aaa24c03c9aad277f9b69440 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Feb 2025 23:37:08 +0000 Subject: [PATCH 07/20] test only 3.11+ --- pint/delegates/__init__.py | 10 +++- pint/delegates/toml_parser/plain.py | 70 +++++++---------------- pint/delegates/toml_parser/toml_parser.py | 55 ++++++++---------- pint/facets/context/__init__.py | 11 +++- pint/facets/system/__init__.py | 10 +++- pint/testsuite/conftest.py | 9 ++- 6 files changed, 79 insertions(+), 86 deletions(-) diff --git a/pint/delegates/__init__.py b/pint/delegates/__init__.py index 4d80f05ff..d22810cec 100644 --- a/pint/delegates/__init__.py +++ b/pint/delegates/__init__.py @@ -11,7 +11,13 @@ from . import txt_defparser from .base_defparser import ParserConfig, build_disk_cache_class -from .toml_parser import toml_parser from .formatter import Formatter +from .toml_parser import toml_parser -__all__ = ["txt_defparser", "ParserConfig", "build_disk_cache_class", "Formatter", "toml_parser"] +__all__ = [ + "txt_defparser", + "ParserConfig", + "build_disk_cache_class", + "Formatter", + "toml_parser", +] diff --git a/pint/delegates/toml_parser/plain.py b/pint/delegates/toml_parser/plain.py index d25a95962..48af549e7 100644 --- a/pint/delegates/toml_parser/plain.py +++ b/pint/delegates/toml_parser/plain.py @@ -23,20 +23,16 @@ from __future__ import annotations +import copy from dataclasses import dataclass -import flexparser as fp - from ...converters import Converter +from ...facets import context, group, system from ...facets.plain import definitions as definitions_ -from ...facets import group -from ...facets import system -from ...facets import context from ...util import UnitsContainer, to_units_container from ..base_defparser import ParserConfig from . import common -import copy @dataclass(frozen=True) class PrefixDefinition(definitions_.PrefixDefinition): @@ -65,9 +61,7 @@ class PrefixDefinition(definitions_.PrefixDefinition): """ @classmethod - def from_dict_and_config( - cls, d: from_dict, config: ParserConfig - ) -> PrefixDefinition: + def from_dict_and_config(cls, d: dict, config: ParserConfig) -> PrefixDefinition: name = d["name"].strip() value = d["value"] defined_symbol = d.get("defined_symbol", None) @@ -137,14 +131,12 @@ class UnitDefinition(definitions_.UnitDefinition): """ @classmethod - def from_dict_and_config( - cls, d: from_dict, config: ParserConfig - ) -> UnitDefinition: + def from_dict_and_config(cls, d: dict, config: ParserConfig) -> UnitDefinition: name = d["name"] value = d["value"] aliases = d.get("aliases", []) defined_symbol = d.get("defined_symbol", None) - + if ";" in value: [converter, modifiers] = value.split(";", 1) @@ -195,17 +187,12 @@ class DimensionDefinition(definitions_.DimensionDefinition): """ @classmethod - def from_dict_and_config( - cls, d: from_dict, config: ParserConfig - ) -> DimensionDefinition: - + def from_dict_and_config(cls, d: dict, config: ParserConfig) -> DimensionDefinition: return cls(**d) @dataclass(frozen=True) -class DerivedDimensionDefinition( - definitions_.DerivedDimensionDefinition -): +class DerivedDimensionDefinition(definitions_.DerivedDimensionDefinition): """Definition of a derived dimension:: [dimension.] @@ -220,9 +207,9 @@ class DerivedDimensionDefinition( @classmethod def from_dict_and_config( - cls, d: from_dict, config: ParserConfig + cls, d: dict, config: ParserConfig ) -> DerivedDimensionDefinition: - name = "["+d["name"]+"]" + name = "[" + d["name"] + "]" value = d["value"] try: @@ -240,9 +227,7 @@ def from_dict_and_config( @dataclass(frozen=True) -class GroupDefinition( - group.GroupDefinition -): +class GroupDefinition(group.GroupDefinition): """Definition of a group. Can be composed of other groups. [group.] @@ -286,18 +271,15 @@ def from_dict_and_config(cls, d, config) -> GroupDefinition: definitions = [] for key, value in d["definitions"].items(): - dat=copy.copy(value) - dat['name']=key + dat = copy.copy(value) + dat["name"] = key definitions.append(UnitDefinition.from_dict_and_config(dat, config)) - - return cls( - name, using_group_names, definitions - ) + + return cls(name, using_group_names, definitions) + @dataclass(frozen=True) -class SystemDefinition( - system.SystemDefinition -): +class SystemDefinition(system.SystemDefinition): """Definition of a system. [system.] @@ -350,15 +332,11 @@ def from_dict_and_config(cls, d, config) -> SystemDefinition: dat = [item.strip() for item in dat.split(":")] rules.append(system.BaseUnitRule(*dat)) - return cls( - name, using_group_names, rules - ) + return cls(name, using_group_names, rules) + - @dataclass(frozen=True) -class ContextDefinition( - context.ContextDefinition -): +class ContextDefinition(context.ContextDefinition): """Definition of a context. [context.] @@ -379,7 +357,7 @@ class ContextDefinition( # default parameters can be defined for use in equations = "" ... - = "" + = "" See ForwardRelation and BidirectionalRelation for more parsing related information. @@ -428,11 +406,7 @@ def from_dict_and_config(cls, d, config) -> ContextDefinition: obj = context.ForwardRelation src = to_units_container(src) dst = to_units_container(dst) - relations.append( - obj(src, dst, eqn) - ) + relations.append(obj(src, dst, eqn)) redefinitions = d.get("redefinitions", {}) - return cls( - name,aliases, defaults, relations, redefinitions - ) \ No newline at end of file + return cls(name, aliases, defaults, relations, redefinitions) diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py index d78a84f83..45f257df5 100644 --- a/pint/delegates/toml_parser/toml_parser.py +++ b/pint/delegates/toml_parser/toml_parser.py @@ -1,58 +1,51 @@ from __future__ import annotations -import pathlib -import typing as ty -import tomllib import copy +import pathlib import flexcache as fc -import flexparser as fp +import tomllib from ..base_defparser import ParserConfig from . import plain class TomlParser: - def __init__(self, default_config: ParserConfig, diskcache: fc.DiskCache): self._default_config = default_config self._diskcache = diskcache - def iter_parsed_project( - self, parsed_project: fp.ParsedProject[PintRootBlock, ParserConfig] - ) -> ty.Generator[fp.ParsedStatement[ParserConfig], None, None]: - + def iter_parsed_project(self, parsed_project: dict): stmts = { - 'unit': plain.UnitDefinition, - 'prefix': plain.PrefixDefinition, - 'dimension': plain.DerivedDimensionDefinition, - 'system': plain.SystemDefinition, - 'context': plain.ContextDefinition, - 'group': plain.GroupDefinition, + "unit": plain.UnitDefinition, + "prefix": plain.PrefixDefinition, + "dimension": plain.DerivedDimensionDefinition, + "system": plain.SystemDefinition, + "context": plain.ContextDefinition, + "group": plain.GroupDefinition, } for definition_type in parsed_project.keys(): for key, value in parsed_project[definition_type].items(): - d=copy.copy(value) - d['name']=key - stmt = stmts[definition_type].from_dict_and_config(d, self._default_config) + d = copy.copy(value) + d["name"] = key + stmt = stmts[definition_type].from_dict_and_config( + d, self._default_config + ) yield stmt - def parse_file( self, filename: pathlib.Path | str, cfg: ParserConfig | None = None ) -> dict: - with open(filename, 'rb') as f: + with open(filename, "rb") as f: data = tomllib.load(f) return data - def parse_string( - self, content: str, cfg: ParserConfig | None = None - ) -> fp.ParsedProject[PintRootBlock, ParserConfig]: - return fp.parse_bytes( - content.encode("utf-8"), - _PintParser, - cfg or self._default_config, - diskcache=self._diskcache, - strip_spaces=True, - delimiters=_PintParser._delimiters, - ) + # def parse_string(self, content: str, cfg: ParserConfig | None = None): + # return fp.parse_bytes( + # content.encode("utf-8"), + # _PintParser, + # cfg or self._default_config, + # diskcache=self._diskcache, + # strip_spaces=True, + # delimiters=_PintParser._delimiters, + # ) diff --git a/pint/facets/context/__init__.py b/pint/facets/context/__init__.py index ab5dcf20d..3f113889b 100644 --- a/pint/facets/context/__init__.py +++ b/pint/facets/context/__init__.py @@ -11,8 +11,15 @@ from __future__ import annotations -from .definitions import ContextDefinition, ForwardRelation, BidirectionalRelation +from .definitions import BidirectionalRelation, ContextDefinition, ForwardRelation from .objects import Context from .registry import ContextRegistry, GenericContextRegistry -__all__ = ["ContextDefinition", "Context", "ContextRegistry", "GenericContextRegistry", "ForwardRelation", "BidirectionalRelation"] +__all__ = [ + "ContextDefinition", + "Context", + "ContextRegistry", + "GenericContextRegistry", + "ForwardRelation", + "BidirectionalRelation", +] diff --git a/pint/facets/system/__init__.py b/pint/facets/system/__init__.py index f9e98e7bc..48d3c0c1d 100644 --- a/pint/facets/system/__init__.py +++ b/pint/facets/system/__init__.py @@ -10,8 +10,14 @@ from __future__ import annotations -from .definitions import SystemDefinition, BaseUnitRule +from .definitions import BaseUnitRule, SystemDefinition from .objects import System from .registry import GenericSystemRegistry, SystemRegistry -__all__ = ["SystemDefinition", "System", "SystemRegistry", "GenericSystemRegistry"] +__all__ = [ + "SystemDefinition", + "System", + "SystemRegistry", + "GenericSystemRegistry", + "BaseUnitRule", +] diff --git a/pint/testsuite/conftest.py b/pint/testsuite/conftest.py index da8a85cff..33453257a 100644 --- a/pint/testsuite/conftest.py +++ b/pint/testsuite/conftest.py @@ -2,6 +2,7 @@ from __future__ import annotations import pathlib +import sys import pytest @@ -63,7 +64,13 @@ def registry_tiny(tiny_definition_file: pathlib.Path): return pint.UnitRegistry(tiny_definition_file) -@pytest.fixture(params=["pint/default_en.txt", "pint/default_en.toml"]) +if sys.version_info >= (3, 11): + registry_files = ["pint/default_en.txt", "pint/default_en.toml"] +else: + registry_files = ["pint/default_en.txt"] + + +@pytest.fixture(params=registry_files) def func_registry(request): return pint.UnitRegistry(request.param) From d95175a1e27325622d1646f1285a18a816ee25c1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Feb 2025 23:41:47 +0000 Subject: [PATCH 08/20] Trigger Build From bd62fb8d8166ad0155021d08a51a8e0bce7f7748 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 09:20:03 +0000 Subject: [PATCH 09/20] compat --- pint/compat.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pint/compat.py b/pint/compat.py index 4b4cbab92..06f7e1574 100644 --- a/pint/compat.py +++ b/pint/compat.py @@ -49,6 +49,11 @@ else: from typing_extensions import deprecated # noqa +if sys.version_info >= (3, 11): + import tomllib # noqa +else: + pass + def missing_dependency( package: str, display_name: str | None = None From eb7df4f8455775dd8b706995d1ff0c4d2d85ed4c Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 09:50:18 +0000 Subject: [PATCH 10/20] compat --- pint/delegates/toml_parser/toml_parser.py | 2 +- pint/testsuite/test_formatting.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py index 45f257df5..2da1d249f 100644 --- a/pint/delegates/toml_parser/toml_parser.py +++ b/pint/delegates/toml_parser/toml_parser.py @@ -4,7 +4,7 @@ import pathlib import flexcache as fc -import tomllib +from ...compat import tomllib from ..base_defparser import ParserConfig from . import plain diff --git a/pint/testsuite/test_formatting.py b/pint/testsuite/test_formatting.py index d8f10715b..6614f10d5 100644 --- a/pint/testsuite/test_formatting.py +++ b/pint/testsuite/test_formatting.py @@ -56,14 +56,14 @@ def test_split_format(format, default, flag, expected): assert result == expected -def test_register_unit_format(func_registry): +def test_register_unit_format(registry_tiny): @fmt.register_unit_format("custom") def format_custom(unit, registry, **options): # Ensure the registry is correct.. registry.Unit(unit) return "" - quantity = 1.0 * func_registry.meter + quantity = 1.0 * registry_tiny.meter assert f"{quantity:custom}" == "1.0 " with pytest.raises(ValueError, match="format 'custom' already exists"): From 03925b870e533551bd0450635c59f8de949e25a3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 09:52:13 +0000 Subject: [PATCH 11/20] lint --- pint/delegates/toml_parser/toml_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py index 2da1d249f..d51dfc170 100644 --- a/pint/delegates/toml_parser/toml_parser.py +++ b/pint/delegates/toml_parser/toml_parser.py @@ -4,8 +4,8 @@ import pathlib import flexcache as fc -from ...compat import tomllib +from ...compat import tomllib from ..base_defparser import ParserConfig from . import plain From 3ba9d724818406643fa10aa88fef8ed291bf579e Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 10:01:38 +0000 Subject: [PATCH 12/20] compat --- pint/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pint/compat.py b/pint/compat.py index 06f7e1574..51b9afc25 100644 --- a/pint/compat.py +++ b/pint/compat.py @@ -52,7 +52,7 @@ if sys.version_info >= (3, 11): import tomllib # noqa else: - pass + tomllib = None def missing_dependency( From c8ac38ab2e7bee138b2d63b57d668d3b53c57c22 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 11:43:55 +0000 Subject: [PATCH 13/20] fix docs --- requirements_docs.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements_docs.txt b/requirements_docs.txt index 6b83371bd..6fecd6563 100644 --- a/requirements_docs.txt +++ b/requirements_docs.txt @@ -1,4 +1,4 @@ -sphinx>=6 +sphinx<8 ipython<=8.12 matplotlib mip>=1.13 @@ -7,6 +7,7 @@ numpy pytest jupyter_client ipykernel +ipython graphviz xarray pooch From f0f86f19945121f46d160003752b2374db0d1ea7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 14:58:11 +0000 Subject: [PATCH 14/20] write toml --- pint/delegates/__init__.py | 16 +-- pint/delegates/toml_parser/__init__.py | 15 +-- pint/delegates/toml_parser/toml_defparser.py | 51 +++++++++ pint/delegates/toml_parser/toml_writer.py | 103 +++++++++++++++++++ pint/facets/plain/registry.py | 43 ++++---- 5 files changed, 194 insertions(+), 34 deletions(-) create mode 100644 pint/delegates/toml_parser/toml_defparser.py create mode 100644 pint/delegates/toml_parser/toml_writer.py diff --git a/pint/delegates/__init__.py b/pint/delegates/__init__.py index d22810cec..46b61fab6 100644 --- a/pint/delegates/__init__.py +++ b/pint/delegates/__init__.py @@ -1,23 +1,25 @@ """ - pint.delegates - ~~~~~~~~~~~~~~ +pint.delegates +~~~~~~~~~~~~~~ - Defines methods and classes to handle autonomous tasks. +Defines methods and classes to handle autonomous tasks. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ + from __future__ import annotations from . import txt_defparser from .base_defparser import ParserConfig, build_disk_cache_class from .formatter import Formatter -from .toml_parser import toml_parser +from .toml_parser import toml_defparser, write_definitions __all__ = [ "txt_defparser", "ParserConfig", "build_disk_cache_class", "Formatter", - "toml_parser", + "toml_defparser", + "write_definitions", ] diff --git a/pint/delegates/toml_parser/__init__.py b/pint/delegates/toml_parser/__init__.py index b81750d96..e30c7ae77 100644 --- a/pint/delegates/toml_parser/__init__.py +++ b/pint/delegates/toml_parser/__init__.py @@ -1,16 +1,19 @@ """ - pint.delegates.toml_parser - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.toml_parser +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Parser for the toml Pint Definition file. +Parser for the toml Pint Definition file. - :copyright: 2025 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2025 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ + from __future__ import annotations -from .toml_parser import TomlParser +from .toml_defparser import TomlParser +from .toml_writer import write_definitions __all__ = [ "TomlParser", + "write_definitions", ] diff --git a/pint/delegates/toml_parser/toml_defparser.py b/pint/delegates/toml_parser/toml_defparser.py new file mode 100644 index 000000000..d51dfc170 --- /dev/null +++ b/pint/delegates/toml_parser/toml_defparser.py @@ -0,0 +1,51 @@ +from __future__ import annotations + +import copy +import pathlib + +import flexcache as fc + +from ...compat import tomllib +from ..base_defparser import ParserConfig +from . import plain + + +class TomlParser: + def __init__(self, default_config: ParserConfig, diskcache: fc.DiskCache): + self._default_config = default_config + self._diskcache = diskcache + + def iter_parsed_project(self, parsed_project: dict): + stmts = { + "unit": plain.UnitDefinition, + "prefix": plain.PrefixDefinition, + "dimension": plain.DerivedDimensionDefinition, + "system": plain.SystemDefinition, + "context": plain.ContextDefinition, + "group": plain.GroupDefinition, + } + for definition_type in parsed_project.keys(): + for key, value in parsed_project[definition_type].items(): + d = copy.copy(value) + d["name"] = key + stmt = stmts[definition_type].from_dict_and_config( + d, self._default_config + ) + yield stmt + + def parse_file( + self, filename: pathlib.Path | str, cfg: ParserConfig | None = None + ) -> dict: + with open(filename, "rb") as f: + data = tomllib.load(f) + return data + + # def parse_string(self, content: str, cfg: ParserConfig | None = None): + # return fp.parse_bytes( + # content.encode("utf-8"), + # _PintParser, + # cfg or self._default_config, + # diskcache=self._diskcache, + # strip_spaces=True, + # delimiters=_PintParser._delimiters, + # ) diff --git a/pint/delegates/toml_parser/toml_writer.py b/pint/delegates/toml_parser/toml_writer.py new file mode 100644 index 000000000..b0fde2510 --- /dev/null +++ b/pint/delegates/toml_parser/toml_writer.py @@ -0,0 +1,103 @@ +from __future__ import annotations + +from dataclasses import fields + +import tomli_w + +from ...facets.plain import GenericPlainRegistry + +keep_fields = [ + "value", + "defined_symbol", + "aliases", +] + + +def add_key_if_not_empty(dat, key, value): + if value == () or value is None: + return dat + else: + dat[key] = value + return dat + + +def parse_simple_definition(definition, definition_type): + attrs = [field.name for field in fields(definition) if field.name in keep_fields] + dat = {} + for attr in attrs: + dat = add_key_if_not_empty(dat, attr, getattr(definition, attr)) + if definition_type in ["units", "dimensions", "prefixes"] and hasattr( + definition, "raw" + ): + dat["value"] = definition.raw.split("=")[1].strip() + return dat + + +def prefixes_units_dimensions(ureg): + data = { + "prefix": {}, + "unit": {}, + "dimension": {}, + } + for definition_type, ureg_attr in zip( + ["unit", "prefix", "dimension"], + ["_units", "_prefixes", "_dimensions"], + ): + definitions = getattr(ureg, ureg_attr).values() + for definition in definitions: + for name, definition in getattr(ureg, ureg_attr).items(): + if hasattr(definition, "raw"): + data[definition_type][definition.name] = parse_simple_definition( + definition, definition_type + ) + return data + + +def groups(ureg): + group_data = {} + for group in ureg._group_definitions: + dat = {} + for attr in ["using_group_names"]: + dat = add_key_if_not_empty(dat, attr, getattr(group, attr)) + dat["definitions"] = {} + for definition in group.definitions: + dat["definitions"][definition.name] = parse_simple_definition( + definition, "_units" + ) + group_data[group.name] = dat + return group_data + + +def systems(ureg): + system_data = {} + for group in ureg._system_definitions: + dat = {} + for attr in ["using_group_names"]: + dat = add_key_if_not_empty(dat, attr, getattr(group, attr)) + dat["rules"] = [] + for rule in group.rules: + dat["rules"].append(rule.raw) + system_data[group.name] = dat + return system_data + + +def contexts(ureg): + context_data = {} + for group in ureg._context_definitions: + dat = {} + for attr in ["aliases", "defaults", "redefinitions"]: + dat = add_key_if_not_empty(dat, attr, getattr(group, attr)) + dat["relations"] = [] + for rule in group.relations: + dat["relations"].append(rule.raw) + context_data[group.name] = dat + return context_data + + +def write_definitions(filename: str, ureg: GenericPlainRegistry): + data = prefixes_units_dimensions(ureg) + data["group"] = groups(ureg) + data["system"] = systems(ureg) + data["context"] = contexts(ureg) + with open("test.toml", "wb") as f: + tomli_w.dump(data, f) diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index 12d1c4b3d..15aef0d3b 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -1,23 +1,23 @@ """ - pint.facets.plain.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. - - The registry contains the following important methods: - - - parse_unit_name: Parse a unit to identify prefix, unit name and suffix - by walking the list of prefix and suffix. - Result is cached: NO - - parse_units: Parse a units expression and returns a UnitContainer with - the canonical names. - The expression can only contain products, ratios and powers of units; - prefixed units and pluralized units. - Result is cached: YES - - parse_expression: Parse a mathematical expression including units and - return a quantity object. - Result is cached: NO +pint.facets.plain.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. + +The registry contains the following important methods: + +- parse_unit_name: Parse a unit to identify prefix, unit name and suffix + by walking the list of prefix and suffix. + Result is cached: NO +- parse_units: Parse a units expression and returns a UnitContainer with + the canonical names. + The expression can only contain products, ratios and powers of units; + prefixed units and pluralized units. + Result is cached: YES +- parse_expression: Parse a mathematical expression including units and + return a quantity object. + Result is cached: NO """ @@ -250,9 +250,10 @@ def __init__( self._def_parser = delegates.txt_defparser.DefParser( delegates.ParserConfig(non_int_type), diskcache=self._diskcache ) - self._toml_parser = delegates.toml_parser.TomlParser( + self._toml_parser = delegates.toml_defparser.TomlParser( delegates.ParserConfig(non_int_type), diskcache=self._diskcache ) + self.write_definitions = lambda x: delegates.write_definitions(x, self) self.formatter = delegates.Formatter(self) self._filename = filename self.force_ndarray = force_ndarray @@ -495,7 +496,7 @@ def _helper_dispatch_adder(self, definition: Any) -> None: break else: raise TypeError( - f"No loader function defined " f"for {definition.__class__.__name__}" + f"No loader function defined for {definition.__class__.__name__}" ) adder_func(definition) From 5ddb893bb71935a7d5c1b0847eae71ace3377e48 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 15:04:29 +0000 Subject: [PATCH 15/20] add tomli_w req --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a4ff41ada..c0016508a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,8 +50,9 @@ xarray = ["xarray"] dask = ["dask"] mip = ["mip >= 1.13"] matplotlib = ["matplotlib"] +tomli_w = ["tomli_w"] all = [ - "pint[numpy,uncertainties,babel,pandas,pandas,xarray,dask,mip,matplotlib]", + "pint[numpy,uncertainties,babel,pandas,pandas,xarray,dask,mip,matplotlib,tomli_w]", ] docs = [ "sphinx>=6,<8.2", From f29d67fab5800c6162b5652c946dda9d81cacb75 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 15:15:45 +0000 Subject: [PATCH 16/20] compat --- pint/compat.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pint/compat.py b/pint/compat.py index eb47794c7..500e0818c 100644 --- a/pint/compat.py +++ b/pint/compat.py @@ -31,11 +31,6 @@ else: from typing_extensions import deprecated # noqa -if sys.version_info >= (3, 11): - import tomllib # noqa -else: - tomllib = None - def missing_dependency( package: str, display_name: str | None = None @@ -245,6 +240,20 @@ class BehaviorChangeWarning(UserWarning): except ImportError: HAS_DASK = False +try: + import tomli_w # noqa: F401 + + HAS_TOMLLI_W = True +except ImportError: + HAS_TOMLLI_W = False + +if sys.version_info >= (3, 11): + import tomllib # noqa + + HAS_TOMLLIB = True +else: + HAS_TOMLLIB = False + ############################## # Imports are handled here @@ -253,6 +262,17 @@ class BehaviorChangeWarning(UserWarning): # in mypy configuration. ############################## +if HAS_TOMLLIB: + import tomllib # noqa: F401 +else: + tomllib = None + +if HAS_TOMLLI_W: + import tomli_w # noqa: F401 +else: + tomllib_w = None + + if HAS_BABEL: from babel import Locale from babel import units as babel_units From 30d6cdf65e3de243d37bc3cd8279cc738a95b275 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 15:24:46 +0000 Subject: [PATCH 17/20] compat --- pint/delegates/toml_parser/toml_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pint/delegates/toml_parser/toml_writer.py b/pint/delegates/toml_parser/toml_writer.py index b0fde2510..3220f9d5d 100644 --- a/pint/delegates/toml_parser/toml_writer.py +++ b/pint/delegates/toml_parser/toml_writer.py @@ -2,7 +2,7 @@ from dataclasses import fields -import tomli_w +from ...compat import tomli_w from ...facets.plain import GenericPlainRegistry From 2c84cbe5bbfdb250509dc03237e10b774b7eedaa Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 15:29:20 +0000 Subject: [PATCH 18/20] compat --- pint/compat.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pint/compat.py b/pint/compat.py index 500e0818c..c806dd84b 100644 --- a/pint/compat.py +++ b/pint/compat.py @@ -243,9 +243,9 @@ class BehaviorChangeWarning(UserWarning): try: import tomli_w # noqa: F401 - HAS_TOMLLI_W = True + HAS_TOMLI_W = True except ImportError: - HAS_TOMLLI_W = False + HAS_TOMLI_W = False if sys.version_info >= (3, 11): import tomllib # noqa @@ -267,10 +267,10 @@ class BehaviorChangeWarning(UserWarning): else: tomllib = None -if HAS_TOMLLI_W: +if HAS_TOMLI_W: import tomli_w # noqa: F401 else: - tomllib_w = None + tomli_w = None if HAS_BABEL: From 82c5cf294a61ba30e321dd51a2c40d92d6ce5690 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 15:35:51 +0000 Subject: [PATCH 19/20] compat --- pint/delegates/toml_parser/toml_parser.py | 51 ----------------------- 1 file changed, 51 deletions(-) delete mode 100644 pint/delegates/toml_parser/toml_parser.py diff --git a/pint/delegates/toml_parser/toml_parser.py b/pint/delegates/toml_parser/toml_parser.py deleted file mode 100644 index d51dfc170..000000000 --- a/pint/delegates/toml_parser/toml_parser.py +++ /dev/null @@ -1,51 +0,0 @@ -from __future__ import annotations - -import copy -import pathlib - -import flexcache as fc - -from ...compat import tomllib -from ..base_defparser import ParserConfig -from . import plain - - -class TomlParser: - def __init__(self, default_config: ParserConfig, diskcache: fc.DiskCache): - self._default_config = default_config - self._diskcache = diskcache - - def iter_parsed_project(self, parsed_project: dict): - stmts = { - "unit": plain.UnitDefinition, - "prefix": plain.PrefixDefinition, - "dimension": plain.DerivedDimensionDefinition, - "system": plain.SystemDefinition, - "context": plain.ContextDefinition, - "group": plain.GroupDefinition, - } - for definition_type in parsed_project.keys(): - for key, value in parsed_project[definition_type].items(): - d = copy.copy(value) - d["name"] = key - stmt = stmts[definition_type].from_dict_and_config( - d, self._default_config - ) - yield stmt - - def parse_file( - self, filename: pathlib.Path | str, cfg: ParserConfig | None = None - ) -> dict: - with open(filename, "rb") as f: - data = tomllib.load(f) - return data - - # def parse_string(self, content: str, cfg: ParserConfig | None = None): - # return fp.parse_bytes( - # content.encode("utf-8"), - # _PintParser, - # cfg or self._default_config, - # diskcache=self._diskcache, - # strip_spaces=True, - # delimiters=_PintParser._delimiters, - # ) From 38e32f737541e6e21772789527bcfbcdb7507591 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 23 Feb 2025 20:42:36 +0000 Subject: [PATCH 20/20] codspeed --- .github/workflows/bench.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 97dd9ccd7..73b9bf743 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -23,10 +23,10 @@ jobs: run: pip install "numpy>=1.23,<2.0.0" - name: Install bench dependencies - run: pip install .[bench] + run: pip install .[codspeed] - name: Run benchmarks - uses: CodSpeedHQ/action@v2 + uses: CodSpeedHQ/action@v3 with: token: ${{ secrets.CODSPEED_TOKEN }} run: pytest . --codspeed