Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nomad-lab/nomad-FAIR
  • pgoel/nomad-FAIR
  • jpd47/nomad-FAIR
3 results
Show changes
Commits on Source (7)
......@@ -39,6 +39,17 @@ test('conversion works both ways for each compatible unit', async () => {
}
})
test.each([
['dimensionless', 'dimensionless', 1],
['percent', 'percent', 100],
['ppm', 'ppm', 1000000]
]
)('test conversion between ratios: %s', async (name, unit, value) => {
const a = new Quantity(1, 'dimensionless')
const b = a.to(unit)
expect(b.value()).toBe(value)
})
test.each([
['same unit', 'kelvin', 'kelvin', 1, 1],
['temperature celsius', 'kelvin', 'celsius', 1, -272.15],
......
......@@ -84,7 +84,8 @@ export class Unit {
let nDen = 0
function getName(unit) {
if (unit.base.key === DIMENSIONLESS) return ''
// For now, we forcibly abbreviate the base dimensionless unit
if (unit.name === DIMENSIONLESS) return ''
return abbreviate
? unitToAbbreviationMap?.[unit.name] || unit.name
: unit.name
......
......@@ -45,6 +45,7 @@ test('each unit can be created using its full name, alias or short form (+ all a
test.each([
['dimensionless', 'dimensionless', ''],
['percent', 'percent', '%'],
['non-abbreviated', 'celsius', '°C'],
['abbreviated', '°C', '°C'],
['prefix long', 'millikelvin', 'mK'],
......
......@@ -103789,6 +103789,17 @@ window.nomadArtifacts = {
"definition": "1e-08 kilogram * meter ^ 2 / ampere / second ^ 3",
"offset": 0.0
},
{
"name": "ampere_hour",
"dimension": "charge",
"label": "Ampere hour",
"abbreviation": "Ah",
"aliases": [
"Ah"
],
"definition": "3600 ampere * second",
"offset": 0.0
},
{
"name": "angstrom",
"dimension": "length",
......@@ -103828,6 +103839,26 @@ window.nomadArtifacts = {
"definition": "4.84813681109536e-06 radian",
"offset": 0.0
},
{
"name": "are",
"dimension": "area",
"label": "Are",
"abbreviation": "are",
"aliases": [],
"definition": "100 meter ^ 2",
"offset": 0.0
},
{
"name": "astronomical_unit",
"dimension": "length",
"label": "Astronomical unit",
"abbreviation": "au",
"aliases": [
"au"
],
"definition": "149597870700 meter",
"offset": 0.0
},
{
"name": "atomic_mass_constant",
"dimension": "mass",
......@@ -104083,6 +104114,17 @@ window.nomadArtifacts = {
"definition": "1333.2238741499998 kilogram / meter / second ^ 2",
"offset": 0.0
},
{
"name": "century",
"dimension": "time",
"label": "Century",
"abbreviation": "century",
"aliases": [
"centuries"
],
"definition": "3155760000.0 second",
"offset": 0.0
},
{
"name": "classical_electron_radius",
"dimension": "length",
......@@ -104105,6 +104147,15 @@ window.nomadArtifacts = {
"definition": "4.184 kilogram * meter ^ 2 / kelvin / second ^ 2",
"offset": 0.0
},
{
"name": "common_year",
"dimension": "time",
"label": "Common year",
"abbreviation": "common_year",
"aliases": [],
"definition": "31536000 second",
"offset": 0.0
},
{
"name": "conductance_quantum",
"dimension": "conductance",
......@@ -104258,6 +104309,17 @@ window.nomadArtifacts = {
"definition": "9.86923266716013e-13 meter ^ 2",
"offset": 0.0
},
{
"name": "day",
"dimension": "time",
"label": "Day",
"abbreviation": "d",
"aliases": [
"d"
],
"definition": "86400 second",
"offset": 0.0
},
{
"name": "debye",
"dimension": "electric_dipole",
......@@ -104420,6 +104482,15 @@ window.nomadArtifacts = {
"definition": "1.6666666666666667e-08 mole / second",
"offset": 0.0
},
{
"name": "eon",
"dimension": "time",
"label": "Eon",
"abbreviation": "eon",
"aliases": [],
"definition": "3.15576e+16 second",
"offset": 0.0
},
{
"name": "erg",
"dimension": "energy",
......@@ -104453,8 +104524,10 @@ window.nomadArtifacts = {
"name": "fermi",
"dimension": "length",
"label": "Fermi",
"abbreviation": "fermi",
"aliases": [],
"abbreviation": "fm",
"aliases": [
"fm"
],
"definition": "1e-15 meter",
"offset": 0.0
},
......@@ -104481,6 +104554,17 @@ window.nomadArtifacts = {
"definition": "2989.0669199999993 kilogram / meter / second ^ 2",
"offset": 0.0
},
{
"name": "foot_per_second",
"dimension": "velocity",
"label": "Foot per second",
"abbreviation": "fps",
"aliases": [
"fps"
],
"definition": "0.30479999999999996 meter / second",
"offset": 0.0
},
{
"name": "foot_per_second",
"dimension": "speed",
......@@ -104529,6 +104613,15 @@ window.nomadArtifacts = {
"definition": "9806.65 kilogram * meter / second ^ 2",
"offset": 0.0
},
{
"name": "fortnight",
"dimension": "time",
"label": "Fortnight",
"abbreviation": "fortnight",
"aliases": [],
"definition": "1209600 second",
"offset": 0.0
},
{
"name": "galileo",
"dimension": "acceleration",
......@@ -104605,6 +104698,15 @@ window.nomadArtifacts = {
"definition": "0.001 kilogram",
"offset": 0.0
},
{
"name": "gregorian_year",
"dimension": "time",
"label": "Gregorian year",
"abbreviation": "gregorian_year",
"aliases": [],
"definition": "31556951.999999996 second",
"offset": 0.0
},
{
"name": "hartree",
"dimension": "energy",
......@@ -104620,6 +104722,17 @@ window.nomadArtifacts = {
"definition": "4.35974472220717e-18 kilogram * meter ^ 2 / second ^ 2",
"offset": 0.0
},
{
"name": "hectare",
"dimension": "area",
"label": "Hectare",
"abbreviation": "ha",
"aliases": [
"ha"
],
"definition": "10000 meter ^ 2",
"offset": 0.0
},
{
"name": "henry",
"dimension": "inductance",
......@@ -104752,6 +104865,18 @@ window.nomadArtifacts = {
"definition": "1.0 mole / second",
"offset": 0.0
},
{
"name": "kilometer_per_hour",
"dimension": "velocity",
"label": "Kilometer per hour",
"abbreviation": "kph",
"aliases": [
"kph",
"KPH"
],
"definition": "0.2777777777777778 meter / second",
"offset": 0.0
},
{
"name": "kilometer_per_hour",
"dimension": "speed",
......@@ -104764,6 +104889,17 @@ window.nomadArtifacts = {
"definition": "0.2777777777777778 meter / second",
"offset": 0.0
},
{
"name": "kilometer_per_second",
"dimension": "velocity",
"label": "Kilometer per second",
"abbreviation": "kmps",
"aliases": [
"kps"
],
"definition": "1000.0 meter / second",
"offset": 0.0
},
{
"name": "kilometer_per_second",
"dimension": "speed",
......@@ -104786,6 +104922,32 @@ window.nomadArtifacts = {
"definition": "6894757.293168365 kilogram / meter / second ^ 2",
"offset": 0.0
},
{
"name": "knot",
"dimension": "velocity",
"label": "Knot",
"abbreviation": "kt",
"aliases": [
"kt",
"knot_international",
"international_knot"
],
"definition": "0.5144444444444445 meter / second",
"offset": 0.0
},
{
"name": "knot",
"dimension": "speed",
"label": "Knot",
"abbreviation": "kt",
"aliases": [
"kt",
"knot_international",
"international_knot"
],
"definition": "0.5144444444444445 meter / second",
"offset": 0.0
},
{
"name": "lambda",
"dimension": "volume",
......@@ -104806,6 +104968,27 @@ window.nomadArtifacts = {
"definition": "3183.098861837907 candela / meter ^ 2",
"offset": 0.0
},
{
"name": "leap_year",
"dimension": "time",
"label": "Leap year",
"abbreviation": "leap_year",
"aliases": [],
"definition": "31622400 second",
"offset": 0.0
},
{
"name": "light_year",
"dimension": "length",
"label": "Light year",
"abbreviation": "ly",
"aliases": [
"ly",
"lightyear"
],
"definition": "9460730472580800.0 meter",
"offset": 0.0
},
{
"name": "liter",
"dimension": "volume",
......@@ -104912,6 +105095,17 @@ window.nomadArtifacts = {
"definition": "13556.800000000001 kilogram / meter ^ 3",
"offset": 0.0
},
{
"name": "meter_per_second",
"dimension": "velocity",
"label": "Meter per second",
"abbreviation": "mps",
"aliases": [
"mps"
],
"definition": "1.0 meter / second",
"offset": 0.0
},
{
"name": "meter_per_second",
"dimension": "speed",
......@@ -104949,7 +105143,8 @@ window.nomadArtifacts = {
"label": "Micron",
"abbreviation": "\u00b5",
"aliases": [
"\u00b5"
"\u00b5",
"\u03bc"
],
"definition": "1e-06 meter",
"offset": 0.0
......@@ -104963,6 +105158,18 @@ window.nomadArtifacts = {
"definition": "9.817477042468104e-05 radian",
"offset": 0.0
},
{
"name": "mile_per_hour",
"dimension": "velocity",
"label": "Mile per hour",
"abbreviation": "mph",
"aliases": [
"mph",
"MPH"
],
"definition": "0.44704000000000005 meter / second",
"offset": 0.0
},
{
"name": "mile_per_hour",
"dimension": "speed",
......@@ -104975,6 +105182,17 @@ window.nomadArtifacts = {
"definition": "0.44704000000000005 meter / second",
"offset": 0.0
},
{
"name": "millennium",
"dimension": "time",
"label": "Millennium",
"abbreviation": "millennium",
"aliases": [
"millennia"
],
"definition": "31557600000.0 second",
"offset": 0.0
},
{
"name": "milliarcsecond",
"dimension": "angle",
......@@ -105030,6 +105248,26 @@ window.nomadArtifacts = {
"definition": "8.314462618153241 kilogram * meter ^ 2 / kelvin / mole / second ^ 2",
"offset": 0.0
},
{
"name": "month",
"dimension": "time",
"label": "Month",
"abbreviation": "month",
"aliases": [],
"definition": "2629800.0 second",
"offset": 0.0
},
{
"name": "nautical_mile",
"dimension": "length",
"label": "Nautical mile",
"abbreviation": "nmi",
"aliases": [
"nmi"
],
"definition": "1852 meter",
"offset": 0.0
},
{
"name": "neutron_mass",
"dimension": "mass",
......@@ -105084,6 +105322,17 @@ window.nomadArtifacts = {
"definition": "1.0 kilogram * meter ^ 2 / ampere ^ 2 / second ^ 3",
"offset": 0.0
},
{
"name": "parsec",
"dimension": "length",
"label": "Parsec",
"abbreviation": "pc",
"aliases": [
"pc"
],
"definition": "3.0856775814671916e+16 meter",
"offset": 0.0
},
{
"name": "particle",
"dimension": "substance",
......@@ -105107,6 +105356,14 @@ window.nomadArtifacts = {
"definition": "1.0 kilogram / meter / second ^ 2",
"offset": 0.0
},
{
"name": "percent",
"dimension": "dimensionless",
"label": "Percent",
"abbreviation": "%",
"definition": "0.01 dimensionless",
"offset": 0.0
},
{
"name": "pixels_per_centimeter",
"dimension": "pixel_density",
......@@ -105198,6 +105455,14 @@ window.nomadArtifacts = {
"definition": "6894.7572931683635 kilogram / meter / second ^ 2",
"offset": 0.0
},
{
"name": "ppm",
"dimension": "dimensionless",
"label": "Parts per million",
"abbreviation": "ppm",
"definition": "1e-06 dimensionless",
"offset": 0.0
},
{
"name": "proton_mass",
"dimension": "mass",
......@@ -105295,6 +105560,42 @@ window.nomadArtifacts = {
"definition": "10973731.56816 / meter",
"offset": 0.0
},
{
"name": "shake",
"dimension": "time",
"label": "Shake",
"abbreviation": "shake",
"aliases": [],
"definition": "1e-08 second",
"offset": 0.0
},
{
"name": "sidereal_day",
"dimension": "time",
"label": "Sidereal day",
"abbreviation": "sidereal_day",
"aliases": [],
"definition": "86164.09053083287 second",
"offset": 0.0
},
{
"name": "sidereal_month",
"dimension": "time",
"label": "Sidereal month",
"abbreviation": "sidereal_month",
"aliases": [],
"definition": "2360591.5579200005 second",
"offset": 0.0
},
{
"name": "sidereal_year",
"dimension": "time",
"label": "Sidereal year",
"abbreviation": "sidereal_year",
"aliases": [],
"definition": "31558149.763545603 second",
"offset": 0.0
},
{
"name": "siemens",
"dimension": "conductance",
......@@ -105307,6 +105608,18 @@ window.nomadArtifacts = {
"definition": "1.0 ampere ^ 2 * second ^ 3 / kilogram / meter ^ 2",
"offset": 0.0
},
{
"name": "speed_of_light",
"dimension": "velocity",
"label": "Speed of light",
"abbreviation": "c",
"aliases": [
"c",
"c_0"
],
"definition": "299792458.0 meter / second",
"offset": 0.0
},
{
"name": "speed_of_light",
"dimension": "speed",
......@@ -105377,6 +105690,26 @@ window.nomadArtifacts = {
"definition": "0.0001 meter ^ 2 / second",
"offset": 0.0
},
{
"name": "svedberg",
"dimension": "time",
"label": "Svedberg",
"abbreviation": "svedberg",
"aliases": [],
"definition": "1e-13 second",
"offset": 0.0
},
{
"name": "synodic_month",
"dimension": "time",
"label": "Synodic month",
"abbreviation": "synodic_month",
"aliases": [
"lunar_month"
],
"definition": "2551442.8896000003 second",
"offset": 0.0
},
{
"name": "tesla",
"dimension": "magnetic_field",
......@@ -105409,6 +105742,24 @@ window.nomadArtifacts = {
"definition": "133.32236842105263 kilogram / meter / second ^ 2",
"offset": 0.0
},
{
"name": "tropical_month",
"dimension": "time",
"label": "Tropical month",
"abbreviation": "tropical_month",
"aliases": [],
"definition": "2360584.6847999995 second",
"offset": 0.0
},
{
"name": "tropical_year",
"dimension": "time",
"label": "Tropical year",
"abbreviation": "tropical_year",
"aliases": [],
"definition": "31556925.2507328 second",
"offset": 0.0
},
{
"name": "unified_atomic_mass_unit",
"dimension": "mass",
......@@ -105528,6 +105879,28 @@ window.nomadArtifacts = {
],
"definition": "1.0 kilogram * meter ^ 2 / ampere / second ^ 2",
"offset": 0.0
},
{
"name": "week",
"dimension": "time",
"label": "Week",
"abbreviation": "week",
"aliases": [],
"definition": "604800 second",
"offset": 0.0
},
{
"name": "year",
"dimension": "time",
"label": "Year",
"abbreviation": "a",
"aliases": [
"a",
"yr",
"julian_year"
],
"definition": "31557600.0 second",
"offset": 0.0
}
],
"unitPrefixes": {
......@@ -105536,6 +105909,26 @@ window.nomadArtifacts = {
"value": 1,
"scientific": true
},
"quecto": {
"name": "quecto",
"value": 1e-30,
"scientific": true
},
"q": {
"name": "q",
"value": 1e-30,
"scientific": true
},
"ronto": {
"name": "ronto",
"value": 1e-27,
"scientific": true
},
"r": {
"name": "r",
"value": 1e-27,
"scientific": true
},
"yocto": {
"name": "yocto",
"value": 1e-24,
......@@ -105606,6 +105999,11 @@ window.nomadArtifacts = {
"value": 1e-06,
"scientific": true
},
"\u03bc": {
"name": "\u03bc",
"value": 1e-06,
"scientific": true
},
"u": {
"name": "u",
"value": 1e-06,
......@@ -105746,6 +106144,26 @@ window.nomadArtifacts = {
"value": 1e+24,
"scientific": true
},
"ronna": {
"name": "ronna",
"value": 1e+27,
"scientific": true
},
"R": {
"name": "R",
"value": 1e+27,
"scientific": true
},
"quetta": {
"name": "quetta",
"value": 1e+30,
"scientific": true
},
"Q": {
"name": "Q",
"value": 1e+30,
"scientific": true
},
"kibi": {
"name": "kibi",
"value": 1024,
......@@ -15,7 +15,7 @@
# limitations under the License.
#
from typing import Tuple, Any
from typing import Tuple, Any, cast
import sys
import json
import os
......@@ -452,7 +452,7 @@ def example_data(username: str):
def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
from pint.converters import ScaleConverter
from pint.facets.plain import ScaleConverter
from collections import defaultdict
from nomad.units import ureg
......@@ -464,7 +464,7 @@ def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
prefixes = {}
for name, prefix in ureg._prefixes.items():
if isinstance(prefix.converter, int):
scale = prefix.converter
scale = cast(float, prefix.converter)
elif isinstance(prefix.converter, ScaleConverter):
scale = prefix.converter.scale
else:
......@@ -480,7 +480,7 @@ def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
aliases[unit_long_name].append(unit_name)
# For each defined dimension, get the available units if there are any.
def get_unit_data(unit, dimension):
def get_unit_data(unit_name, dimension):
unit_long_name = ureg.get_name(unit_name)
unit_abbreviation = ureg.get_symbol(unit_name)
unit_label = unit_long_name.replace('_', ' ')
......@@ -498,13 +498,13 @@ def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
unit_list = []
for dimension in dimensions:
try:
units = ureg.get_compatible_units(dimension)
units = ureg.get_compatible_units(dimension) # type: ignore
except KeyError:
continue
else:
for unit in units:
unit_name = str(unit)
unit_list.append(get_unit_data(unit_name, dimension))
for unit_obj in units:
unit_str = str(unit_obj)
unit_list.append(get_unit_data(unit_str, dimension))
# Some units need to be added manually.
unit_list.extend(
......@@ -516,6 +516,7 @@ def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
'label': 'Kilogram',
'abbreviation': 'kg',
},
# TODO: Could the dimensionless quantities be added programmatically?
# Dimensionless
{
'name': 'dimensionless',
......@@ -523,6 +524,20 @@ def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
'label': 'Dimensionless',
'abbreviation': '',
},
# Percent
{
'name': 'percent',
'dimension': 'dimensionless',
'label': 'Percent',
'abbreviation': '%',
},
# Ppm
{
'name': 'ppm',
'dimension': 'dimensionless',
'label': 'Parts per million',
'abbreviation': 'ppm',
},
]
)
......@@ -563,36 +578,15 @@ def _generate_units_json(all_metainfo) -> Tuple[Any, Any]:
unit_list.sort(key=lambda x: x.get('name'))
unit_list.sort(key=lambda x: 0 if x.get('definition') is None else 1)
# Go through the metainfo and check that all units are defined. Note that
# this will break if complex derived units are used in the metainfo. In
# this case they can only be validated in a GUI test.
unit_names = set()
for unit in unit_list:
unit_names.add(unit['name'])
for alias in unit.get('aliases', []):
unit_names.add(alias)
units = set()
for package in all_metainfo.packages:
for section in package.section_definitions:
for quantity in section.quantities:
unit = quantity.unit
if unit is not None:
parts = str(unit).split()
for part in parts:
is_operator = part in {'/', '**', '*'}
is_number = True
try:
int(part)
except Exception:
is_number = False
if not is_operator and not is_number:
units.add(part)
# Check that the defined units do not contain 'delta_' or 'Δ' in them. This is
# reserved to indicate that a quantity should be treated without offset.
# MathJS does not have explicit support for these delta-units, but instead
# uses them implicitly when non-multiplicative units appear in expressions.
unit_names = set()
for unit_info in unit_list:
unit_names.add(unit_info['name'])
for alias in unit_info.get('aliases', []):
unit_names.add(alias)
for unit in unit_names:
assert 'delta_' not in unit and 'Δ' not in unit, (
f'Invalid unit name {unit}. "delta_" and "Δ" are reserved for unit variants '
......
......@@ -1655,7 +1655,7 @@ class MSection(
m_quantity = self.__dict__[item_name][item_name]
if isinstance(value, pint.Quantity):
m_quantity.value = value.m
m_quantity.unit = value.u
m_quantity.unit = cast(pint.Unit, value.u)
else:
m_quantity.value = value
except KeyError:
......
......@@ -18,13 +18,12 @@
import email.utils
import hashlib
import os
import re
from dataclasses import dataclass
from datetime import date, datetime
from difflib import SequenceMatcher
from functools import reduce
from typing import Any, Dict, Optional, Sequence, Tuple, Union
from typing import Any, Dict, Optional, Sequence, Tuple, Union, cast
from urllib.parse import SplitResult, urlsplit, urlunsplit
import aniso8601
......@@ -78,7 +77,7 @@ class MRegEx:
)
def normalize_complex(value, complex_type, to_unit: Union[str, ureg.Unit, None]):
def normalize_complex(value, complex_type, to_unit: Union[str, pint.Unit, None]):
"""
Try to convert a given value to a complex number.
"""
......@@ -352,7 +351,7 @@ class MQuantity:
self.unit = None
if isinstance(in_value, pint.Quantity):
self.value = in_value.m # magnitude
self.unit = in_value.u # unit
self.unit = cast(pint.Unit, in_value.u) # unit
assert in_unit is None, f'Unit is already defined in the value {in_value}'
else:
# the input argument is not a pint quantity
......@@ -521,7 +520,7 @@ def to_dict(entries):
def convert_to(
from_magnitude, from_unit: Optional[ureg.Unit], to_unit: Optional[ureg.Unit]
from_magnitude, from_unit: Optional[pint.Unit], to_unit: Optional[pint.Unit]
):
"""
Convert a magnitude from one unit to another.
......@@ -538,7 +537,7 @@ def convert_to(
if to_unit is None:
return from_magnitude
from_quantity: ureg.Quantity = from_magnitude * from_unit
from_quantity: pint.Quantity = from_magnitude * from_unit
return from_quantity.to(to_unit).m
......
......@@ -21,7 +21,7 @@ import numpy as np
import re
import ase.data
import ase.formula
import pint.quantity
from pint import Quantity
from nomad.atomutils import Formula
from nomad.normalizing.normalizer import SystemBasedNormalizer
......@@ -120,7 +120,7 @@ class OptimadeNormalizer(SystemBasedNormalizer):
return np.array(value)
if numpy and unit is not None:
if isinstance(value, pint.quantity._Quantity):
if isinstance(value, Quantity):
value = value.to(unit)
elif value is not None:
value = value * unit
......
......@@ -26,6 +26,7 @@ from nomad.metainfo import MSection, nexus
from nomad.metainfo.util import MQuantity, MSubSectionList, resolve_variadic_name
from nomad.parsing import Parser
from nomad.units import ureg
import pint
from pint.errors import UndefinedUnitError
from nomad.utils import get_logger
from nomad.datamodel.results import Material
......@@ -220,7 +221,7 @@ class NexusParser(Parser):
# check if unit is given
unit = hdf_node.attrs.get('units', None)
pint_unit: Optional[ureg.Unit] = None
pint_unit: Optional[pint.Unit] = None
if unit:
try:
if unit != 'counts':
......
......@@ -62,13 +62,17 @@
#### PREFIXES ####
# decimal prefixes
quecto- = 1e-30 = q-
ronto- = 1e-27 = r-
yocto- = 1e-24 = y-
zepto- = 1e-21 = z-
atto- = 1e-18 = a-
femto- = 1e-15 = f-
pico- = 1e-12 = p-
nano- = 1e-9 = n-
micro- = 1e-6 = µ- = u-
# The micro (U+00B5) and Greek mu (U+03BC) are both valid prefixes,
# and they often use the same glyph.
micro- = 1e-6 = µ- = μ- = u-
milli- = 1e-3 = m-
centi- = 1e-2 = c-
deci- = 1e-1 = d-
......@@ -82,6 +86,8 @@ peta- = 1e15 = P-
exa- = 1e18 = E-
zetta- = 1e21 = Z-
yotta- = 1e24 = Y-
ronna- = 1e27 = R-
quetta- = 1e30 = Q-
# binary_prefixes
kibi- = 2**10 = Ki-
......@@ -130,14 +136,28 @@ steradian = radian ** 2 = sr
square_degree = (π / 180) ** 2 * sr = sq_deg = sqdeg
# Information
byte = 8 * bit = B = octet
baud = bit / second = Bd = bps
byte = 8 * bit = B = octet
# byte = 8 * bit = _ = octet
## NOTE: B (byte) symbol can conflict with Bell
# Ratios
percent = 0.01 = %
ppm = 1e-6
# Length
angstrom = 1e-10 * meter = Å = ångström = Å
micron = micrometer = µ
fermi = femtometer
micron = micrometer = µ = μ
fermi = femtometer = fm
light_year = speed_of_light * julian_year = ly = lightyear
astronomical_unit = 149597870700 * meter = au # since Aug 2012
parsec = 1 / tansec * astronomical_unit = pc
nautical_mile = 1852 * meter = nmi
atomic_unit_of_length = h_bar / (alpha * m_e * c) = bohr = a_0 = a0 = bohr_radius = a_u_length
x_unit_Cu = K_alpha_Cu_d_220 * d_220 / 1537.4 = Xu_Cu
x_unit_Mo = K_alpha_Mo_d_220 * d_220 / 707.831 = Xu_Mo
angstrom_star = K_alpha_W_d_220 * d_220 / 0.2090100 = Å_star
planck_length = (h_bar * gravitational_constant / c ** 3) ** 0.5
# Mass
......@@ -152,8 +172,32 @@ planck_mass = (h_bar * c / gravitational_constant) ** 0.5
# Time
minute = 60 * second
hour = 60 * minute = hr
atomic_unit_of_time = h_bar / E_h = a_u_time
day = 24 * hour = d
week = 7 * day
fortnight = 2 * week
year = 365.25 * day = a = yr = julian_year
month = year / 12
# decade = 10 * year
## NOTE: decade [time] can conflict with decade [dimensionless]
century = 100 * year = _ = centuries
millennium = 1e3 * year = _ = millennia
eon = 1e9 * year
shake = 1e-8 * second
svedberg = 1e-13 * second
atomic_unit_of_time = hbar / E_h = a_u_time
gregorian_year = 365.2425 * day
sidereal_year = 365.256363004 * day # approximate, as of J2000 epoch
tropical_year = 365.242190402 * day # approximate, as of J2000 epoch
common_year = 365 * day
leap_year = 366 * day
sidereal_day = day / 1.00273790935079524 # approximate
sidereal_month = 27.32166155 * day # approximate
tropical_month = 27.321582 * day # approximate
synodic_month = 29.530589 * day = _ = lunar_month # approximate
planck_time = (h_bar * gravitational_constant / c ** 5) ** 0.5
atomic_unit_of_time = h_bar / E_h = a_u_time
# Temperature
degree_Celsius = kelvin; offset: 273.15 = °C = celsius = degC = degreeC
......@@ -165,8 +209,10 @@ planck_temperature = (h_bar * c ** 5 / gravitational_constant / k ** 2) ** 0.5
# Area
[area] = [length] ** 2
are = 100 * meter ** 2
barn = 1e-28 * meter ** 2 = b
darcy = centipoise * centimeter ** 2 / (second * atmosphere)
hectare = 100 * are = ha
# Volume
[volume] = [length] ** 3
......@@ -184,8 +230,10 @@ counts_per_second = 1 / second = cps
[wavenumber] = 1 / [length]
reciprocal_centimeter = 1 / cm = cm_1 = kayser
# Speed
[speed] = [length] / [time]
# Velocity
[velocity] = [length] / [time]
[speed] = [velocity]
knot = nautical_mile / hour = kt = knot_international = international_knot
mile_per_hour = mile / hour = mph = MPH
kilometer_per_hour = kilometer / hour = kph = KPH
kilometer_per_second = kilometer / second = kps
......@@ -193,7 +241,7 @@ meter_per_second = meter / second = mps
foot_per_second = foot / second = fps
# Acceleration
[acceleration] = [speed] / [time]
[acceleration] = [velocity] / [time]
galileo = centimeter / second ** 2 = Gal
# Force
......@@ -331,6 +379,7 @@ coulomb = ampere * second = C
abcoulomb = 10 * C = abC
faraday = e * N_A * mole
conventional_coulomb_90 = K_J90 * R_K90 / (K_J * R_K) * coulomb = C_90
ampere_hour = ampere * hour = Ah
# Electric potential
[electric_potential] = [energy] / [charge]
......@@ -369,17 +418,17 @@ farad = coulomb / volt = F
abfarad = 1e9 * farad = abF
conventional_farad_90 = R_K90 / R_K * farad = F_90
# Magnetic flux
[magnetic_flux] = [electric_potential] * [time]
weber = volt * second = Wb
unit_pole = µ_0 * biot * centimeter
# Inductance
[inductance] = [magnetic_flux] / [current]
henry = weber / ampere = H
abhenry = 1e-9 * henry = abH
conventional_henry_90 = R_K / R_K90 * henry = H_90
# Magnetic flux
[magnetic_flux] = [electric_potential] * [time]
weber = volt * second = Wb
unit_pole = µ_0 * biot * centimeter
# Magnetic field
[magnetic_field] = [magnetic_flux] / [area]
tesla = weber / meter ** 2 = T
......
......@@ -19,7 +19,7 @@ dependencies = [
'pandas>=1.3.5,<2.0.0',
'cachetools>=4.2.4',
'docstring-parser>=0.12',
'pint==0.17',
'pint==0.23',
'orjson==3.9.4',
'click>=7.1.2',
'requests>=2.27.1',
......
......@@ -20,9 +20,9 @@
# in-depth tests in test_* files of the same module.
import pytest
import pint
import numpy as np
import pandas as pd
import pint.quantity
from nomad.metainfo.metainfo import (
MSection,
......@@ -631,12 +631,12 @@ class TestM1:
def test_np_array(self):
system = System()
system.atom_positions = [[1, 2, 3]]
assert isinstance(system.atom_positions, pint.quantity._Quantity)
assert isinstance(system.atom_positions, pint.Quantity)
def test_pd_dataframe(self):
system = System()
system.atom_positions = pd.DataFrame([[1, 2], [3, 4]])
assert isinstance(system.atom_positions, pint.quantity._Quantity)
assert isinstance(system.atom_positions, pint.Quantity)
assert np.all(system.atom_positions.m == [[1, 2], [3, 4]])
def test_np_scalar(self):
......@@ -695,8 +695,8 @@ class TestM1:
def test_synonym(self):
system = System()
system.lattice_vectors = [[1.2e-10, 0, 0], [0, 1.2e-10, 0], [0, 0, 1.2e-10]]
assert isinstance(system.lattice_vectors, pint.quantity._Quantity)
assert isinstance(system.unit_cell, pint.quantity._Quantity)
assert isinstance(system.lattice_vectors, pint.Quantity)
assert isinstance(system.unit_cell, pint.Quantity)
assert np.array_equal(
system.unit_cell.magnitude, system.lattice_vectors.magnitude
) # pylint: disable=no-member
......@@ -723,7 +723,7 @@ class TestM1:
assert system.m_def == System.m_def
assert system.n_atoms == 3
assert system.atom_labels == ['H', 'H', 'O']
assert isinstance(system.atom_positions, pint.quantity._Quantity)
assert isinstance(system.atom_positions, pint.Quantity)
def test_derived(self):
system = System()
......