Skip to content

Commit 2d0e745

Browse files
Add missing units (#40)
Add celsius, fahrenheit, bar, and the von Klitzing constant
2 parents 88b067e + ba815d1 commit 2d0e745

5 files changed

Lines changed: 1236 additions & 1221 deletions

File tree

tunits/core/cython/base_unit_data.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ __SI_BASE_UNITS = [
5151
__OTHER_BASE_UNITS = [
5252
BaseUnitData('dB', 'decibel', use_prefixes=False),
5353
BaseUnitData('dBm', 'decibel-milliwatt', use_prefixes=False),
54+
BaseUnitData('degC', 'celsius', use_prefixes=False),
55+
BaseUnitData('degF', 'fahrenheit', use_prefixes=False),
5456
]
5557

5658
ALL_BASE_UNITS = __SI_BASE_UNITS + __OTHER_BASE_UNITS

tunits/core/cython/derived_unit_data.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ __OTHER_UNITS = [
113113
DerivedUnitData('ton', None, 'lb', 2000),
114114
# Pressure.
115115
DerivedUnitData('psi', 'pounds_per_square_inch', 'Pa', 6894.75729317),
116+
DerivedUnitData('bar', 'barometric_pressure', 'Pa', 1e5),
116117
]
117118

118119
# Units that aren't technically exact, but close enough for our purposes.

tunits/core/cython/dimension.pyx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ This module creates the dimension abstraction which allows the creation of value
1818
that belong to a dimension (e.g. t: Time, x: Length, ...etc). This allows us to
1919
use static types to check code correctness (e.g. time_method(t: Time)).
2020
21-
To add a new dimension, create 3 classes:
21+
To add a new dimension, create 3 classes:
2222
- `class _NewDimension(Dimension):` which implements the abstract methods from
2323
the abstract `Dimension` class.
2424
- `class NewDimension(_NewDimension, ValueWithDimension)` which represents scalar
2525
values and doesn't need to implement any methods.
2626
- `class AccelerationArray(_Acceleration, ArrayWithDimension)` which represents
27-
an array of values sharing the same dimension and
27+
an array of values sharing the same dimension and
2828
"""
2929

3030
import abc
@@ -696,7 +696,11 @@ class _Temperature(Dimension):
696696
@staticmethod
697697
@cache
698698
def valid_base_units() -> tuple[Value, ...]:
699-
return (default_unit_database.known_units['kelvin'],)
699+
return (
700+
default_unit_database.known_units['kelvin'],
701+
default_unit_database.known_units['celsius'],
702+
default_unit_database.known_units['fahrenheit'],
703+
)
700704

701705
def _value_class(self) -> type[Value]:
702706
return Temperature

tunits/core/cython/physical_constant_data.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ _DERIVED_CONSTANTS = [
6969
# degrees Rankine
7070
PhysicalConstantData('degR', None, 5.0 / 9.0, 'K'),
7171
PhysicalConstantData('bohr_magneton', None, 9.2740096820e-24, 'J/T'),
72+
PhysicalConstantData('R_k', 'resistance_quantum', 25812.78277321444, 'ohm'), # h/e^2
7273
]
7374

7475
ALL_PHYSICAL_CONSTANT_DATA = _PHYSICAL_CONSTANTS + _DERIVED_CONSTANTS

0 commit comments

Comments
 (0)