@@ -17,6 +17,69 @@ def __pow__(self, other: int, /) -> Self: ...
17
17
def __rmul__ (self , other : Self , / ) -> Self : ...
18
18
def __rtruediv__ (self , other : Self , / ) -> Self : ...
19
19
20
+ def decompose (self , dimension_system : "DimensionSystem" , / ) -> "dict[Dimension, float | int]" :
21
+ """Decompose the dimension into its base dimensions and exponents.
22
+
23
+ Parameters
24
+ ----------
25
+ dimension_system
26
+ The dimension system to use for decomposition. This defines the base
27
+ dimensions.
28
+
29
+ Notes
30
+ -----
31
+ By far the most common dimension system is (Length, Mass, Time, Electric
32
+ Current, Temperature, Amount of Substance, Luminous Intensity).
33
+ Implementing libraries are free to make this the default dimension
34
+ system and to set it as the default value in their ``decompose`` method.
35
+
36
+ Examples
37
+ --------
38
+ As this is an API protocol, no runtime examples are possible. The
39
+ following is an illustrative example:
40
+
41
+ >>> import metrology as u
42
+
43
+ >>> dim = u.Length / u.Time
44
+
45
+ >>> dim_sys = u.DimensionSystem(u.Length, u.Time)
46
+ >>> dim.decompose(dim_sys)
47
+ {Length: 1, Time: -1}
48
+
49
+ >>> dim_sys = u.DimensionSystem(u.Velocity)
50
+ >>> dim.decompose(dim_sys)
51
+ {Velocity: 1}
52
+
53
+ """
54
+
55
+
56
+ @runtime_checkable
57
+ class DimensionSystem (Protocol ):
58
+ """A system of dimensions.
59
+
60
+ This is a collection of base dimensions. Most unit systems, like the
61
+ International System of Units, have a dimension system involving Length,
62
+ Mass, Time, Electric Current, Temperature Amount of Substance, and Luminous
63
+ Intensity. However, other dimension systems are possible, such as 'natural'
64
+ systems where the speed of light is set to 1. The `DimensionsSystem` class
65
+ is the API for any choice of dimension system.
66
+
67
+ Examples
68
+ --------
69
+ As this is an API protocol, no runtime examples are possible. The following
70
+ is an illustrative example:
71
+
72
+ >>> import metrology as u
73
+
74
+ >>> dim_sys = u.DimensionSystem(u.Length, u.Time)
75
+
76
+ >>> dim_sys = u.DimensionSystem(u.Velocity)
77
+
78
+ """
79
+
80
+ base_dimensions : tuple [Dimension , ...]
81
+ """The base dimensions of the system."""
82
+
20
83
21
84
@runtime_checkable
22
85
class Unit (Protocol ):
0 commit comments