@@ -17,6 +17,70 @@ 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
+
57
+ @runtime_checkable
58
+ class DimensionSystem (Protocol ):
59
+ """A system of dimensions.
60
+
61
+ This is a collection of base dimensions. Most unit systems, like the
62
+ International System of Units, have a dimension system involving Length,
63
+ Mass, Time, Electric Current, Temperature Amount of Substance, and Luminous
64
+ Intensity. However, other dimension systems are possible, such as 'natural'
65
+ systems where the speed of light is set to 1. The `DimensionsSystem` class
66
+ is the API for any choice of dimension system.
67
+
68
+ Examples
69
+ --------
70
+ As this is an API protocol, no runtime examples are possible. The following
71
+ is an illustrative example:
72
+
73
+ >>> import metrology as u
74
+
75
+ >>> dim_sys = u.DimensionSystem(u.Length, u.Time)
76
+
77
+ >>> dim_sys = u.DimensionSystem(u.Velocity)
78
+
79
+ """
80
+
81
+ base_dimensions : tuple [Dimension , ...]
82
+ """The base dimensions of the system."""
83
+
20
84
21
85
@runtime_checkable
22
86
class Unit (Protocol ):
0 commit comments