from typing import Dict, Hashable, List, Mapping, Optional, Set, Union
from ts_lib_units.tetra_unit import DeprecatedTetraUnit, TetraUnit
[docs]
class Unit:
"""TetraScience standard units"""
# When adding a units:
# Add a new class attribute with the type `TetraUnit`, including:
# - `ts_format`: The QUDT (or QUDT-like) unit string for the unit
# - `pint_format`: The `pint` unit string for the unit.
# You can reference other units in the library, or the
# [default pint registry](https://github.com/hgrecco/pint/blob/master/pint/default_en.txt)
# to build this string.
# - `qudt_link`: The QUDT link for the unit`, if available in:
# https://purl.allotrope.org/voc/qudt/REC/2022/09/qudt-merged.ttl.
# For the `ts_format` string:
# - If the unit is in QUDT or QUDT-ext, use the name in the URI.
# - Otherwise: Use camel case, use `Per` and do not capitalize after prefixes such as
# `Milli` or `Micro`
ABSORBANCE_UNIT = TetraUnit(
ts_format="AbsorbanceUnit",
pint_format=None,
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#AbsorbanceUnit",
)
AMPERE = TetraUnit(
ts_format="Ampere",
pint_format="ampere",
qudt_uri="http://qudt.org/vocab/unit/A",
)
ANGSTROM = TetraUnit(
ts_format="Angstrom",
pint_format="angstrom",
qudt_uri="http://qudt.org/vocab/unit/ANGSTROM",
)
ARBITRARY_UNIT = TetraUnit(
ts_format="ArbitraryUnit",
pint_format=None,
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#ArbitraryUnit",
)
BAR = TetraUnit(
ts_format="Bar",
pint_format="bar",
qudt_uri="http://qudt.org/vocab/unit/BAR",
)
BYTE = TetraUnit(
ts_format="Byte",
pint_format="byte",
qudt_uri="http://qudt.org/vocab/unit/BYTE",
)
CENTIMETER = TetraUnit(
ts_format="Centimeter",
pint_format="centimeter",
qudt_uri="http://qudt.org/vocab/unit/CentiM",
)
CENTIMETER_PER_HOUR = TetraUnit(
ts_format="CentimeterPerHour",
pint_format="centimeter / hour",
qudt_uri=None,
)
CENTIPOISE = TetraUnit(
ts_format="Centipoise",
pint_format="centipoise",
qudt_uri="http://qudt.org/vocab/unit/CentiPOISE",
)
COUNT = TetraUnit(
ts_format="Count",
pint_format="count",
# Count is a quantity in QUDT but not a unit, so there is no QUDT unit URI
qudt_uri=None,
)
COUNT_PER_LITER = TetraUnit(
ts_format="CountPerLiter",
pint_format="count / liter",
qudt_uri=None,
)
COUNT_PER_MICROLITER = TetraUnit(
ts_format="CountPerMicroliter",
pint_format="count / microliter",
qudt_uri=None,
)
COUNT_PER_MILLILITER = TetraUnit(
ts_format="CountPerMilliliter",
pint_format="count / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#CountsPerMilliliter",
)
COUNT_PER_NANOLITER = TetraUnit(
ts_format="CountPerNanoliter",
pint_format="count / nanoliter",
qudt_uri=None,
)
CUBIC_CENTIMETER_PER_MOLE = TetraUnit(
ts_format="CubicCentimeterPerMole",
pint_format="(centimeter ** 3) / mole",
qudt_uri=None,
)
CYCLE_NUMBER = TetraUnit(
ts_format="CycleNumber",
pint_format=None,
qudt_uri=None,
)
DALTON = TetraUnit(
ts_format="Dalton",
pint_format="dalton",
qudt_uri="http://qudt.org/vocab/unit/Da",
)
DAY = TetraUnit(
ts_format="Day",
pint_format="day",
qudt_uri="http://qudt.org/vocab/unit/DAY",
)
DECIBEL = TetraUnit(
ts_format="Decibel",
pint_format="decibel",
qudt_uri="http://qudt.org/vocab/unit/DeciB",
)
DEGREE_ANGLE = TetraUnit(
ts_format="DegreeAngle",
pint_format="degree",
qudt_uri="http://qudt.org/vocab/unit/DEG",
)
DEGREE_CELSIUS = TetraUnit(
ts_format="DegreeCelsius",
pint_format="degree_Celsius",
qudt_uri="http://qudt.org/vocab/unit/DEG_C",
)
DEGREE_CELSIUS_PER_MINUTE = TetraUnit(
ts_format="DegreeCelsiusPerMinute",
pint_format="degree_Celsius / minute",
qudt_uri="http://qudt.org/vocab/unit/DEG_C-PER-MIN",
)
DEGREE_FAHRENHEIT = TetraUnit(
ts_format="DegreeFahrenheit",
pint_format="degree_Fahrenheit",
qudt_uri="http://qudt.org/vocab/unit/DEG_F",
)
ELECTRON_VOLT = TetraUnit(
ts_format="ElectronVolt",
pint_format="electron_volt",
qudt_uri="http://qudt.org/vocab/unit/EV",
)
ENDOTOXIN_UNIT = TetraUnit(
ts_format="EndotoxinUnit",
pint_format="endotoxin_unit",
qudt_uri=None,
)
ENDOTOXIN_UNIT_PER_NANOGRAM = TetraUnit(
ts_format="EndotoxinUnitPerNanogram",
pint_format="endotoxin_unit / nanogram",
qudt_uri=None,
)
ENDOTOXIN_UNIT_PER_MICROGRAM = TetraUnit(
ts_format="EndotoxinUnitPerMicrogram",
pint_format="endotoxin_unit / microgram",
qudt_uri=None,
)
ENDOTOXIN_UNIT_PER_GRAM = TetraUnit(
ts_format="EndotoxinUnitPerGram",
pint_format="endotoxin_unit / gram",
qudt_uri=None,
)
ENDOTOXIN_UNIT_PER_MICROLITER = TetraUnit(
ts_format="EndotoxinUnitPerMicroliter",
pint_format="endotoxin_unit / microliter",
qudt_uri=None,
)
ENDOTOXIN_UNIT_PER_MILLILITER = TetraUnit(
ts_format="EndotoxinUnitPerMilliliter",
pint_format="endotoxin_unit / milliliter",
qudt_uri=None,
)
ENDOTOXIN_UNIT_PER_LITER = TetraUnit(
ts_format="EndotoxinUnitPerLiter",
pint_format="endotoxin_unit / liter",
qudt_uri=None,
)
FEMTOGRAM = TetraUnit(
ts_format="Femtogram",
pint_format="femtogram",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Femtogram",
)
FEMTOLITER = TetraUnit(
ts_format="Femtoliter",
pint_format="femtoliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Femtoliter",
)
FRAME_PER_SECOND = TetraUnit(
ts_format="FramePerSecond",
pint_format=None,
qudt_uri="http://qudt.org/vocab/unit/FRAME-PER-SEC",
)
GRAM = TetraUnit(
ts_format="Gram",
pint_format="gram",
qudt_uri="http://qudt.org/vocab/unit/GM",
)
GRAM_PER_MILLILITER = TetraUnit(
ts_format="GramPerMilliliter",
pint_format="gram / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#GramPerMilliliter",
)
GRAM_PER_LITER = TetraUnit(
ts_format="GramPerLiter",
pint_format="gram / liter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#GramPerLiter",
)
GRAM_PER_LITER_SOLVENT = TetraUnit(
ts_format="GramPerLiterSolvent",
pint_format=None,
qudt_uri=None,
)
GRAM_PER_LITER_SOLUTION = TetraUnit(
ts_format="GramPerLiterSolution",
pint_format=None,
qudt_uri=None,
)
GRAM_PER_MOLE = TetraUnit(
ts_format="GramPerMole",
pint_format="gram / mole",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#GramPerMole",
)
HERTZ = TetraUnit(
ts_format="Hertz",
pint_format="hertz",
qudt_uri="http://qudt.org/vocab/unit/HZ",
)
HOUR = TetraUnit(
ts_format="Hour",
pint_format="hour",
qudt_uri="http://qudt.org/vocab/unit/HR",
)
INCH = TetraUnit(
ts_format="Inch",
pint_format="inch",
qudt_uri="http://qudt.org/vocab/unit/IN",
)
INTENSITY = TetraUnit(
ts_format="Intensity",
pint_format=None,
qudt_uri=None,
)
JOULE = TetraUnit(
ts_format="Joule",
pint_format="joule",
qudt_uri="http://qudt.org/vocab/unit/J",
)
JOULE_PER_MOLE = TetraUnit(
ts_format="JoulePerMole",
pint_format="joule / mole",
qudt_uri=None,
)
KELVIN = TetraUnit(
ts_format="Kelvin",
pint_format="kelvin",
qudt_uri="http://qudt.org/vocab/unit/K",
)
KILOCALORIE_PER_MOLE = TetraUnit(
ts_format="KilocaloriePerMole",
pint_format="kilocalorie / mole",
qudt_uri="http://qudt.org/vocab/unit/KiloCAL-PER-MOL",
)
KILOCOUNT_PER_SECOND = TetraUnit(
ts_format="KilocountPerSecond",
pint_format="kilocount / second",
qudt_uri=None,
)
KILODALTON = TetraUnit(
ts_format="KiloDalton",
pint_format="kilodalton",
qudt_uri=None,
)
KILOGRAM = TetraUnit(
ts_format="Kilogram",
pint_format="kilogram",
qudt_uri="http://qudt.org/vocab/unit/KiloGM",
)
KILOGRAM_PER_CUBIC_METER = TetraUnit(
ts_format="KilogramPerCubicMeter",
pint_format="kilogram / (meter ** 3)",
qudt_uri="http://qudt.org/vocab/unit/KiloGM-PER-M3",
)
KILOGRAM_PER_METER = TetraUnit(
ts_format="KilogramPerMeter",
pint_format="kilogram / meter",
qudt_uri="http://qudt.org/vocab/unit/KiloGM-PER-M",
)
KILOGRAM_PER_MOLE = TetraUnit(
ts_format="KilogramPerMole",
pint_format="kilogram / mole",
qudt_uri="http://qudt.org/vocab/unit/KiloGM-PER-MOL",
)
KILOGRAM_PER_SQUARE_METER = TetraUnit(
ts_format="KilogramPerSquareMeter",
pint_format="kilogram / (meter ** 2)",
qudt_uri="http://qudt.org/vocab/unit/KiloGM-PER-M2",
)
KILOJOULE_PER_MOLE = TetraUnit(
ts_format="KiloJoulePerMole",
pint_format="kilojoule / mole",
qudt_uri=None,
)
KILOPOND = TetraUnit(
ts_format="KiloPond",
pint_format="kilopond",
qudt_uri="http://qudt.org/vocab/unit/KiloPOND",
)
KILOVOLT = TetraUnit(
ts_format="KiloVolt",
pint_format="kilovolt",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#KiloVolt",
)
LIGHT_SCATTERING_UNIT = TetraUnit(
ts_format="LightScatteringUnit",
pint_format=None,
qudt_uri=None,
)
LITER = TetraUnit(
ts_format="Liter",
pint_format="liter",
qudt_uri="http://qudt.org/vocab/unit/L",
)
LITER_PER_HOUR = TetraUnit(
ts_format="LiterPerHour",
pint_format="liter / hour",
qudt_uri=None,
)
LITER_PER_MINUTE = TetraUnit(
ts_format="LiterPerMinute",
pint_format="liter / minute",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#LiterPerMinute",
)
LITER_PER_SQUARE_METER = TetraUnit(
ts_format="LiterPerSquareMeter",
pint_format="liter / (meter ** 2)",
qudt_uri=None,
)
LMH_PER_PSI = TetraUnit(
ts_format="LiterPerSquareMeterPerHourPerPoundPerSquareInch",
pint_format="liter / ((meter**2) * hour * psi)",
qudt_uri=None,
)
LITER_PER_SQUARE_METER_PER_MINUTE = TetraUnit(
ts_format="LiterPerSquareMeterPerMinute",
pint_format="liter / ((meter**2) * minute)",
qudt_uri=None,
)
LITER_PER_SQUARE_METER_PER_HOUR = TetraUnit(
ts_format="LiterPerSquareMeterPerHour",
pint_format="liter / ((meter**2) * hour)",
qudt_uri=None,
)
MEGAHERTZ = TetraUnit(
ts_format="MegaHertz",
pint_format="megahertz",
qudt_uri="http://qudt.org/vocab/unit/MegaHZ",
)
MEGAPASCAL = TetraUnit(
ts_format="MegaPascal",
pint_format="megapascal",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MegaPascal",
)
METER = TetraUnit(
ts_format="Meter",
pint_format="meter",
qudt_uri="http://qudt.org/vocab/unit/M",
)
METER_PER_SECOND = TetraUnit(
ts_format="MeterPerSecond",
pint_format="meter / second",
qudt_uri="http://qudt.org/vocab/unit/M-PER-SEC",
)
METER_PER_SECOND_SQUARED = TetraUnit(
ts_format="MeterPerSecondSquared",
pint_format="meter / (second ** 2)",
qudt_uri="http://qudt.org/vocab/unit/M-PER-SEC2",
)
MICROGRAM = TetraUnit(
ts_format="Microgram",
pint_format="microgram",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Microgram",
)
MICROGRAM_PER_MILLILITER = TetraUnit(
ts_format="MicrogramPerMilliliter",
pint_format="microgram / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MicrogramPerMilliliter",
)
MICROGRAM_PER_LITER = TetraUnit(
ts_format="MicrogramPerLiter",
pint_format="microgram / liter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MicrogramPerLiter",
)
MICROLITER = TetraUnit(
ts_format="Microliter",
pint_format="microliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Microliter",
)
MICROLITER_PER_MINUTE = TetraUnit(
ts_format="MicroliterPerMinute",
pint_format="microliter / minute",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MicroliterPerMinute",
)
MICROMETER = TetraUnit(
ts_format="Micrometer",
pint_format="micrometer",
qudt_uri="http://qudt.org/vocab/unit/MicroM",
)
MICROMOLE = TetraUnit(
ts_format="Micromole",
pint_format="micromole",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Micromole",
)
MICROMOLAR = TetraUnit(
ts_format="Micromolar",
pint_format="micromolar",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Micromolar",
)
MICROSECOND = TetraUnit(
ts_format="MicroSecond",
pint_format="microsecond",
qudt_uri="http://qudt.org/vocab/unit/MicroSEC",
)
MICROVOLT = TetraUnit(
ts_format="Microvolt",
pint_format="microvolt",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Microvolt",
)
MILLI_ABSORBANCE_UNIT = TetraUnit(
ts_format="MilliAbsorbanceUnit",
pint_format=None,
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilliAbsorbanceUnit",
)
MILLI_ABSORBANCE_UNIT_TIMES_MINUTE = TetraUnit(
ts_format="MilliAbsorbanceUnitTimesMinute",
pint_format=None,
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilliAbsorbanceUnitTimesMinute",
)
MILLI_ABSORBANCE_UNIT_TIMES_MILLILITER = TetraUnit(
ts_format="MilliAbsorbanceUnitTimesMilliliter",
pint_format=None,
qudt_uri=None,
)
MILLIAMPERE = TetraUnit(
ts_format="MilliAmpere",
pint_format="milliampere",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilliAmpere",
)
MILLIDEGREE = TetraUnit(
ts_format="MilliDegreeAngle",
pint_format="millidegree",
qudt_uri=None,
)
MILLIGRAM = TetraUnit(
ts_format="Milligram",
pint_format="milligram",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Milligram",
)
MILLIGRAM_PER_KILOGRAM = TetraUnit(
ts_format="MilligramPerKilogram",
pint_format="milligram / kilogram",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilligramPerKilogram",
)
MILLIGRAM_PER_LITER = TetraUnit(
ts_format="MilligramPerLiter",
pint_format="milligram / liter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilligramPerLiter",
)
MILLIGRAM_PER_MILLILITER = TetraUnit(
ts_format="MilligramPerMilliliter",
pint_format="milligram / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilligramPerMilliliter",
)
MILLILITER = TetraUnit(
ts_format="Milliliter",
pint_format="milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Milliliter",
)
MILLILITER_PER_GRAM = TetraUnit(
ts_format="MilliliterPerGram",
pint_format="milliliter / gram",
qudt_uri=None,
)
MILLILITER_PER_MILLIGRAM_CENTIMETER = TetraUnit(
ts_format="MilliliterPerMilligramCentimeter",
pint_format="milliliter / (milligram * centimeter)",
qudt_uri=None,
)
MILLILITER_PER_MINUTE = TetraUnit(
ts_format="MilliliterPerMinute",
pint_format="milliliter / minute",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilliliterPerMinute",
)
MILLILITER_PER_SECOND = TetraUnit(
ts_format="MilliliterPerSecond",
pint_format="milliliter / second",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilliliterPerSecond",
)
MILLIMETER = TetraUnit(
ts_format="Millimeter",
pint_format="millimeter",
qudt_uri="http://qudt.org/vocab/unit/MilliM",
)
MILLIMETER_OF_MERCURY = TetraUnit(
ts_format="MillimeterOfMercury",
pint_format="millimeter_Hg",
qudt_uri="http://qudt.org/vocab/unit/MilliM_HG",
)
MILLIMETER_PER_SECOND_SQUARED = TetraUnit(
ts_format="MillimeterPerSecondSquared",
pint_format="millimeter / (second ** 2)",
qudt_uri=None,
)
MILLIMOLAR = TetraUnit(
ts_format="Millimolar",
pint_format="millimolar",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Millimolar",
)
MILLIMOLE = TetraUnit(
ts_format="Millimole",
pint_format="millimole",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Millimole",
)
MILLIMOLE_PER_LITER = TetraUnit(
ts_format="MillimolePerLiter",
pint_format="millimole / liter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MillimolePerLiter",
)
MILLINORMAL = TetraUnit(
ts_format="MilliNormal",
pint_format=None,
qudt_uri=None,
)
MILLION_CELLS_PER_MILLILITER = TetraUnit(
ts_format="MillionCellsPerMilliliter",
pint_format="megacount / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MillionCellsPerMilliliter",
)
MILLIOSMOLE_PER_KILOGRAM = TetraUnit(
ts_format="MilliOsmolePerKilogram",
pint_format=None,
qudt_uri=None,
)
MILLIPASCAL_SECOND = TetraUnit(
ts_format="MillipascalSecond",
pint_format="millipascal * second",
qudt_uri=None,
)
MILLISECOND = TetraUnit(
ts_format="MilliSecond",
pint_format="millisecond",
qudt_uri="http://qudt.org/vocab/unit/MilliSEC",
)
MILLISIEMEN = TetraUnit(
ts_format="Millisiemens",
pint_format="millisiemens",
qudt_uri=None,
)
MILLISIEMENS_PER_CM = TetraUnit(
ts_format="MillisiemensPerCentimeter", # Note: 'Millisiemens' is used since the base unit is 'Siemens' (trailing 's' is not for plural)
pint_format="millisiemens / centimeter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MillisiemenPerCentimeter",
)
MILLIVOLT = TetraUnit(
ts_format="MilliVolt",
pint_format="millivolt",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Millivolt",
)
MILLIVOLT_PER_PH = TetraUnit(
ts_format="MillivoltPerPH",
pint_format=None,
qudt_uri=None,
)
MILLIWATT = TetraUnit(
ts_format="MilliWatt",
pint_format="milliwatt",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#MilliWatt",
)
MINUTE_TIME = TetraUnit(
ts_format="MinuteTime",
pint_format="minute",
qudt_uri="http://qudt.org/vocab/unit/MIN",
)
MINUTE_TIME_SQUARED = TetraUnit(
ts_format="MinuteTimeSquared",
pint_format="minute ** 2",
qudt_uri=None,
)
MOLE = TetraUnit(
ts_format="Mole",
pint_format="mole",
qudt_uri="http://qudt.org/vocab/unit/MOL",
)
MOLAR = TetraUnit(
ts_format="Molar",
pint_format="molar",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Molar",
)
MOLE_FRACTION = TetraUnit(
ts_format="MoleFraction",
pint_format=None,
qudt_uri=None,
)
NANOAMPERE = TetraUnit(
ts_format="NanoAmpere",
pint_format="nanoampere",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#NanoAmpere",
)
NANOGRAM = TetraUnit(
ts_format="Nanogram",
pint_format="nanogram",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Nanogram",
)
NANOGRAM_PER_MICROLITER = TetraUnit(
ts_format="NanogramPerMicroliter",
pint_format="nanogram / microliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#NanogramPerMicroliter",
)
NANOGRAM_PER_MILLILITER = TetraUnit(
ts_format="NanogramPerMilliliter",
pint_format="nanogram / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#NanogramPerMilliliter",
)
NANOGRAM_PER_LITER = TetraUnit(
ts_format="NanogramPerLiter",
pint_format="nanogram / liter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#NanogramPerLiter",
)
NANOMETER = TetraUnit(
ts_format="Nanometer",
pint_format="nanometer",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Nanometer",
)
NANOMETERPERMINUTE = TetraUnit(
ts_format="NanometerPerMinute",
pint_format="nanometer / minute",
qudt_uri=None,
)
NANOMOLAR = TetraUnit(
ts_format="Nanomolar",
pint_format="nanomolar",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Nanomolar",
)
NANOLITER = TetraUnit(
ts_format="Nanoliter",
pint_format="nanoliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Nanoliter",
)
NANOMOLE = TetraUnit(
ts_format="Nanomole",
pint_format="nanomole",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Nanomole",
)
NANOSECOND = TetraUnit(
ts_format="NanoSecond",
pint_format="nanosecond",
qudt_uri=None,
)
NEWTON = TetraUnit(
ts_format="Newton",
pint_format="newton",
qudt_uri="http://qudt.org/vocab/unit/N",
)
OHM = TetraUnit(
ts_format="Ohm",
pint_format="ohm",
qudt_uri="http://qudt.org/vocab/unit/OHM",
)
OSMOLE = TetraUnit(
ts_format="Osmole",
pint_format=None,
qudt_uri=None,
)
OSMOLE_PER_KILOGRAM = TetraUnit(
ts_format="OsmolePerKilogram",
pint_format=None,
qudt_uri=None,
)
OSMOLE_PER_LITER = TetraUnit(
ts_format="OsmolesPerLiter",
pint_format=None,
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#OsmolesPerLiter",
)
PARTS_PER_MILLION = TetraUnit(
ts_format="PartsPerMillion",
pint_format="ppm",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#PartsPerMillion",
)
PASCAL = TetraUnit(
ts_format="Pascal",
pint_format="pascal",
qudt_uri="http://qudt.org/vocab/unit/PA",
)
PASCAL_SECOND = TetraUnit(
ts_format="PascalSecond",
pint_format="pascal * second",
qudt_uri="http://qudt.org/vocab/unit/PA-SEC",
)
PERCENT = TetraUnit(
ts_format="Percent",
pint_format="percent",
qudt_uri="http://qudt.org/vocab/unit/PERCENT",
)
PERCENT_VOLUME = TetraUnit(
ts_format="PercentVolume",
pint_format=None,
qudt_uri=None,
)
PERMITTIVITY = DeprecatedTetraUnit(
ts_format="Permittivity",
pint_format=None,
qudt_uri=None,
deprecated_message=(
"Permittivity is a quantity, not a unit. Find and use the relevant unit, "
"or request a unit to be added to this library."
),
)
PER_SECOND = TetraUnit(
ts_format="PerSecond",
pint_format="1 / second",
qudt_uri="http://qudt.org/vocab/unit/PER-SEC",
)
PICOGRAM = TetraUnit(
ts_format="Picogram",
pint_format="picogram",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Picogram",
)
PICOGRAM_PER_MILLILITER = TetraUnit(
ts_format="PicogramPerMilliliter",
pint_format="picogram / milliliter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#PicogramPerMilliliter",
)
PICOGRAM_PER_LITER = TetraUnit(
ts_format="PicogramPerLiter",
pint_format="picogram / liter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#PicogramPerLiter",
)
PICOMETER = TetraUnit(
ts_format="Picometer",
pint_format="picometer",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Picometer",
)
PICOMOLE = TetraUnit(
ts_format="Picomole",
pint_format="picomole",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Picomole",
)
PICOMOLAR = TetraUnit(
ts_format="Picomolar",
pint_format="picomolar",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Picomolar",
)
POISE = TetraUnit(
ts_format="Poise",
pint_format="poise",
qudt_uri="http://qudt.org/vocab/unit/POISE",
)
POUND_PER_SQUARE_FOOT = TetraUnit(
ts_format="PoundPerSquareFoot",
pint_format="pound / foot ** 2",
qudt_uri="http://qudt.org/vocab/unit/LB_F-PER-FT2",
)
POUND_PER_SQUARE_INCH = TetraUnit(
ts_format="PoundPerSquareInch", # Note: This unit string is widely used for psi in our task scripts, even though its different to QUDT
pint_format="psi",
qudt_uri="http://qudt.org/vocab/unit/LB_F-PER-IN2",
)
RADIAN = TetraUnit(
ts_format="Radian",
pint_format="radian",
qudt_uri="http://qudt.org/vocab/unit/RAD",
)
RECIPROCAL_CENTIMETER = TetraUnit(
ts_format="ReciprocalCentimeter",
pint_format="reciprocal_centimeter",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#ReciprocalCentimeter",
)
RECIPROCAL_MINUTE = DeprecatedTetraUnit( # NOTE: This is the old unit format, use PER_MINUTE instead
ts_format="ReciprocalMinute",
pint_format="1 / minute",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#PerMinute",
deprecated_message="This unit is now deprecated, use PER_MINUTE instead",
)
PER_MINUTE = TetraUnit(
ts_format="PerMinute",
pint_format="1 / minute",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#PerMinute",
)
RELATIVE_PERMITTIVITY = TetraUnit(
ts_format="RelativePermittivity",
pint_format=None,
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Unitless",
)
REVOLUTION_PER_HOUR = TetraUnit(
ts_format="RevolutionPerHour",
pint_format="revolution / hour",
qudt_uri="http://qudt.org/vocab/unit/REV-PER-HR",
)
REVOLUTION_PER_MINUTE = TetraUnit(
ts_format="RevolutionPerMinute",
pint_format="rpm",
qudt_uri="http://qudt.org/vocab/unit/REV-PER-MIN",
)
REVOLUTION_PER_SECOND = TetraUnit(
ts_format="RevolutionPerSecond",
pint_format="rps",
qudt_uri="http://qudt.org/vocab/unit/REV-PER-SEC",
)
SECOND_TIME = TetraUnit(
ts_format="SecondTime",
pint_format="second",
qudt_uri="http://qudt.org/vocab/unit/SEC",
)
SIEMENS_PER_CENTIMETER_SECOND = TetraUnit(
ts_format="SiemensPerCentimeterSecond",
pint_format="siemens / (centimeter * second)",
qudt_uri=None,
)
SQUARE_CENTIMETER = TetraUnit(
ts_format="SquareCentimeter",
pint_format="centimeter ** 2",
qudt_uri="http://qudt.org/vocab/unit/CentiM2",
)
SQUARE_CENTIMETER_PER_SECOND = TetraUnit(
ts_format="SquareCentimeterPerSecond",
pint_format="centimeter ** 2 / second",
qudt_uri=None,
)
SQUARE_METER = TetraUnit(
ts_format="SquareMeter",
pint_format="meter ** 2",
qudt_uri="http://qudt.org/vocab/unit/M2",
)
SQUARE_METER_PER_GRAM = TetraUnit(
ts_format="SquareMeterPerGram",
pint_format="meter ** 2 / gram",
qudt_uri=None,
)
SQUARE_MICROMETER = TetraUnit(
ts_format="SquareMicrometer",
pint_format="micrometer ** 2",
qudt_uri="http://qudt.org/vocab/unit/MicroM2",
)
SQUARE_ROOT_MEGAPASCAL = TetraUnit(
ts_format="SquareRootMegaPascal",
pint_format="megapascal ** 0.5",
qudt_uri=None,
)
TON_OF_REFRIGERATION = TetraUnit(
ts_format="TonOfRefrigeration",
pint_format=None,
qudt_uri="http://qudt.org/vocab/unit/TON_FG",
)
TORR = TetraUnit(
ts_format="Torr",
pint_format="torr",
qudt_uri="http://qudt.org/vocab/unit/TORR",
)
UNITLESS = TetraUnit(
ts_format="Unitless",
pint_format="1",
qudt_uri="http://purl.allotrope.org/ontology/qudt-ext/unit#Unitless",
)
ENZYME_UNIT_PER_LITER = TetraUnit(
ts_format="InternationalUnitPerLiter",
pint_format="enzyme_unit / liter",
qudt_uri="http://qudt.org/vocab/unit/ENZ-PER-L",
)
VOLT = TetraUnit(
ts_format="Volt",
pint_format="volt",
qudt_uri="http://qudt.org/vocab/unit/V",
)
VOXEL = TetraUnit(
ts_format="Voxel",
pint_format=None,
qudt_uri=None,
)
WATT = TetraUnit(
ts_format="Watt",
pint_format="watt",
qudt_uri="http://qudt.org/vocab/unit/W",
)
[docs]
@classmethod
def get_all_units(cls) -> Dict[str, TetraUnit]:
"""Get all units in the library"""
return {
key: val
for key, val in vars(cls).items()
if not key.startswith("__") and not isinstance(val, classmethod)
}
[docs]
@classmethod
def contains(cls, ts_format: str) -> bool:
"""Check if a unit is in the library"""
return any(
attr_value.ts_format.lower() == ts_format.lower()
for attr_value in cls.get_all_units().values()
)
[docs]
@classmethod
def get(cls, ts_format: str) -> TetraUnit:
"""Get a unit by its ts_string"""
for attr_value in cls.get_all_units().values():
if attr_value.ts_format.lower() == ts_format.lower():
return attr_value
raise ValueError(f"Unit {ts_format} is not in our library")
[docs]
class UnitParser:
"""Class for parsing raw unit strings to standard unit strings"""
mapping: Mapping[Hashable, Optional[str]] = {}
unmapped_units: Set[Hashable] = set()
def __init__(
self,
mappings: Union[
Mapping[Hashable, Optional[str]], List[Mapping[Hashable, Optional[str]]]
],
):
"""Instantiate a UnitParser object
Args:
mappings (List[Mapping[str, str]]): List of unit mappings
Raises:
ValueError: When duplicate keys are found in the unit mappings
"""
if isinstance(mappings, Mapping):
self.mapping = mappings
else:
self.mapping = {}
for mapping in mappings:
intersection = self.mapping.keys() & mapping.keys()
if not intersection:
self.mapping.update(mapping)
continue
different_value_keys = [
key for key in intersection if self.mapping[key] != mapping[key]
]
if different_value_keys:
raise ValueError(
(
"Found keys with multiple possible values:\n\n"
"Key | Value 1 | Value 2\n"
"-------------------------------\n"
)
+ "".join(
f"{key} | {self.mapping[key]} | {mapping[key]}\n"
for key in different_value_keys
)
+ "\nIf a key is present in multiple mappings, please ensure they all map it to the same value."
)
[docs]
def parse(self, raw_unit: Optional[str]) -> Optional[str]:
"""Parse a raw unit string to a standard unit string
If the raw unit string is not found in the mappings, it is returned as-is and
is added to the unmapped_units set.
Args:
raw_unit (str): Raw unit string
Returns:
str: Standard unit string
"""
if raw_unit is None:
return None
if isinstance(raw_unit, str) and raw_unit == "":
return None
if raw_unit in self.mapping:
return self.mapping[raw_unit]
self.unmapped_units.add(raw_unit)
return raw_unit
CONCENTRATION_MAPPING = {
"pg/ml": Unit.PICOGRAM_PER_MILLILITER,
"pg/mL": Unit.PICOGRAM_PER_MILLILITER,
"ng/ml": Unit.NANOGRAM_PER_MILLILITER,
"ng/mL": Unit.NANOGRAM_PER_MILLILITER,
"μg/ml": Unit.MICROGRAM_PER_MILLILITER,
"μg/mL": Unit.MICROGRAM_PER_MILLILITER,
"mg/ml": Unit.MILLIGRAM_PER_MILLILITER,
"mg/mL": Unit.MILLIGRAM_PER_MILLILITER,
"g/ml": Unit.GRAM_PER_MILLILITER,
"g/mL": Unit.GRAM_PER_MILLILITER,
"pg/l": Unit.PICOGRAM_PER_LITER,
"pg/L": Unit.PICOGRAM_PER_LITER,
"ng/l": Unit.NANOGRAM_PER_LITER,
"ng/L": Unit.NANOGRAM_PER_LITER,
"μg/l": Unit.MICROGRAM_PER_LITER,
"μg/L": Unit.MICROGRAM_PER_LITER,
"mg/l": Unit.MILLIGRAM_PER_LITER,
"mg/L": Unit.MILLIGRAM_PER_LITER,
"g/l": Unit.GRAM_PER_LITER,
"g/L": Unit.GRAM_PER_LITER,
"M": Unit.MOLAR,
"mM": Unit.MILLIMOLAR,
"mmol/L": Unit.MILLIMOLE_PER_LITER,
"μM": Unit.MICROMOLAR,
"nM": Unit.NANOMOLAR,
"pM": Unit.PICOMOLAR,
}
MOLE_MAPPING = {
"mol": Unit.MOLE,
"mmol": Unit.MILLIMOLE,
"μmol": Unit.MICROMOLE,
"nmol": Unit.NANOMOLE,
"pmol": Unit.PICOMOLE,
}
MOLAR_MASS_MAPPING = {
"g/mol": Unit.GRAM_PER_MOLE,
"g/mole": Unit.GRAM_PER_MOLE,
"kg/mol": Unit.KILOGRAM_PER_MOLE,
"kg/mole": Unit.KILOGRAM_PER_MOLE,
}
TEMPERATURE_MAPPING = {
"°C": Unit.DEGREE_CELSIUS,
"degC": Unit.DEGREE_CELSIUS,
"°F": Unit.DEGREE_FAHRENHEIT,
"degF": Unit.DEGREE_FAHRENHEIT,
"°K": Unit.KELVIN,
"degK": Unit.KELVIN,
"K": Unit.KELVIN,
}
LENGTH_MAPPING = {
"m": Unit.METER,
"cm": Unit.CENTIMETER,
"mm": Unit.MILLIMETER,
"μm": Unit.MICROMETER,
"nm": Unit.NANOMETER,
"NANOMETERS": Unit.NANOMETER,
"pm": Unit.PICOMETER,
"Å": Unit.ANGSTROM,
"inch": Unit.INCH,
}
MASS_MAPPING = {
"pg": Unit.PICOGRAM,
"ng": Unit.NANOGRAM,
"μg": Unit.MICROGRAM,
"mg": Unit.MILLIGRAM,
"g": Unit.GRAM,
"kg": Unit.KILOGRAM,
"Da": Unit.DALTON,
"kDa": Unit.KILODALTON,
}
TIME_MAPPING = {
"msec": Unit.MILLISECOND,
"s": Unit.SECOND_TIME,
"sec": Unit.SECOND_TIME,
"min": Unit.MINUTE_TIME,
"h": Unit.HOUR,
"hr": Unit.HOUR,
"hrs": Unit.HOUR,
}
VOLUME_MAPPING = {
"ul": Unit.MICROLITER,
"μl": Unit.MICROLITER,
"μL": Unit.MICROLITER,
"ml": Unit.MILLILITER,
"mL": Unit.MILLILITER,
"l": Unit.LITER,
"L": Unit.LITER,
}
PERCENT_MAPPING = {
"%": Unit.PERCENT,
}
CATALYTIC_ACTIVITY_MAPPING = {
"U/L": Unit.ENZYME_UNIT_PER_LITER,
}
ENDOTOXIN_MAPPING = {
"EU": Unit.ENDOTOXIN_UNIT,
"EU/ng": Unit.ENDOTOXIN_UNIT_PER_NANOGRAM,
"EU/ug": Unit.ENDOTOXIN_UNIT_PER_MICROGRAM,
"EU/μg": Unit.ENDOTOXIN_UNIT_PER_MICROGRAM,
"EU/g": Unit.ENDOTOXIN_UNIT_PER_GRAM,
"EU/uL": Unit.ENDOTOXIN_UNIT_PER_MICROLITER,
"EU/μL": Unit.ENDOTOXIN_UNIT_PER_MICROLITER,
"EU/mL": Unit.ENDOTOXIN_UNIT_PER_MILLILITER,
"EU/L": Unit.ENDOTOXIN_UNIT_PER_LITER,
}