unxts.api 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unxts/api/__init__.py +31 -0
- unxts/api/_src/__init__.py +0 -0
- unxts/api/_src/dimensions.py +38 -0
- unxts/api/_src/quantity.py +140 -0
- unxts/api/_src/units.py +20 -0
- unxts/api/_src/unitsystems.py +15 -0
- unxts/api/_version.py +24 -0
- unxts/api/py.typed +0 -0
- unxts_api-2.0.0.dist-info/METADATA +42 -0
- unxts_api-2.0.0.dist-info/RECORD +12 -0
- unxts_api-2.0.0.dist-info/WHEEL +4 -0
- unxts_api-2.0.0.dist-info/licenses/LICENSE +29 -0
unxts/api/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Abstract dispatch API for unxt.
|
|
2
|
+
|
|
3
|
+
This is the canonical package (unxts.api). The legacy ``unxt_api`` package
|
|
4
|
+
continues to work via a thin backward-compatible shim.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__all__ = (
|
|
8
|
+
"__version__",
|
|
9
|
+
"dimension",
|
|
10
|
+
"dimension_of",
|
|
11
|
+
"uconvert_value",
|
|
12
|
+
"uconvert",
|
|
13
|
+
"ustrip",
|
|
14
|
+
"is_unit_convertible",
|
|
15
|
+
"wrap_to",
|
|
16
|
+
"unit",
|
|
17
|
+
"unit_of",
|
|
18
|
+
"unitsystem_of",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from ._src.dimensions import dimension, dimension_of
|
|
22
|
+
from ._src.quantity import (
|
|
23
|
+
is_unit_convertible,
|
|
24
|
+
uconvert,
|
|
25
|
+
uconvert_value,
|
|
26
|
+
ustrip,
|
|
27
|
+
wrap_to,
|
|
28
|
+
)
|
|
29
|
+
from ._src.units import unit, unit_of
|
|
30
|
+
from ._src.unitsystems import unitsystem_of
|
|
31
|
+
from ._version import version as __version__
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Dimension API for unxt.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = ("dimension", "dimension_of")
|
|
7
|
+
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import plum
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@plum.dispatch.abstract
|
|
14
|
+
def dimension(obj: Any, /) -> Any:
|
|
15
|
+
"""Construct the dimension.
|
|
16
|
+
|
|
17
|
+
.. note::
|
|
18
|
+
|
|
19
|
+
This function uses multiple dispatch. Dispatches made in other modules
|
|
20
|
+
may not be included in the rendered docs. To see the full range of
|
|
21
|
+
options, execute ``unxt.dims.dimension.methods`` in an interactive
|
|
22
|
+
Python session.
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@plum.dispatch.abstract
|
|
28
|
+
def dimension_of(obj: Any, /) -> Any:
|
|
29
|
+
"""Return the dimension of the given units.
|
|
30
|
+
|
|
31
|
+
.. note::
|
|
32
|
+
|
|
33
|
+
This function uses multiple dispatch. Dispatches made in other modules
|
|
34
|
+
may not be included in the rendered docs. To see the full range of
|
|
35
|
+
options, execute ``unxt.dimension_of.methods`` in an interactive Python
|
|
36
|
+
session.
|
|
37
|
+
|
|
38
|
+
"""
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Quantity API for unxt.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = ("uconvert_value", "uconvert", "ustrip", "is_unit_convertible", "wrap_to")
|
|
7
|
+
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import plum
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@plum.dispatch.abstract
|
|
14
|
+
def uconvert_value(uto: Any, ufrom: Any, x: Any, /) -> Any:
|
|
15
|
+
"""Convert the value from specified units to specified units.
|
|
16
|
+
|
|
17
|
+
General signature: ``(to_unit, from_unit, value) -> converted_value``.
|
|
18
|
+
Other signatures are defined via method dispatch.
|
|
19
|
+
See ``uconvert_value.methods`` for details.
|
|
20
|
+
|
|
21
|
+
Examples
|
|
22
|
+
--------
|
|
23
|
+
>>> import unxt as u # implements `unxts.api.uconvert_value`
|
|
24
|
+
|
|
25
|
+
>>> u.uconvert_value(u.unit("m"), u.unit("km"), 1)
|
|
26
|
+
1000.0
|
|
27
|
+
|
|
28
|
+
>>> u.uconvert_value("m", "km", 1)
|
|
29
|
+
1000.0
|
|
30
|
+
|
|
31
|
+
For further examples, see the other method dispatches.
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
raise NotImplementedError # pragma: no cover
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@plum.dispatch.abstract
|
|
38
|
+
def uconvert(u: Any, x: Any, /) -> Any:
|
|
39
|
+
"""Convert the quantity to the specified units.
|
|
40
|
+
|
|
41
|
+
General signature: ``(to_unit, quantity) -> converted_quantity``.
|
|
42
|
+
Other signatures are defined via method dispatch.
|
|
43
|
+
See ``uconvert.methods`` for details.
|
|
44
|
+
|
|
45
|
+
Internally, {func}`unxts.api.uconvert` often calls to
|
|
46
|
+
{func}`unxts.api.uconvert_value` to perform the numerical conversion on the
|
|
47
|
+
Quantity's value.
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
--------
|
|
51
|
+
>>> import unxt as u # implements `unxts.api.uconvert`
|
|
52
|
+
|
|
53
|
+
>>> q = u.Q(1, "km")
|
|
54
|
+
>>> u.uconvert(u.unit("m"), q)
|
|
55
|
+
Quantity(Array(1000., dtype=float32, ...), unit='m')
|
|
56
|
+
|
|
57
|
+
>>> u.uconvert("m", q)
|
|
58
|
+
Quantity(Array(1000., dtype=float32, ...), unit='m')
|
|
59
|
+
|
|
60
|
+
For further examples, see the other method dispatches.
|
|
61
|
+
|
|
62
|
+
"""
|
|
63
|
+
raise NotImplementedError # pragma: no cover
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@plum.dispatch.abstract
|
|
67
|
+
def ustrip(*args: Any) -> Any:
|
|
68
|
+
"""Strip the units from the quantity, first converting if necessary.
|
|
69
|
+
|
|
70
|
+
General signature: ``(to_unit, quantity) -> value_array``.
|
|
71
|
+
Other signatures are defined via method dispatch.
|
|
72
|
+
See ``ustrip.methods`` for details.
|
|
73
|
+
|
|
74
|
+
Examples
|
|
75
|
+
--------
|
|
76
|
+
>>> import unxt as u # implements `unxts.api.ustrip`
|
|
77
|
+
|
|
78
|
+
>>> q = u.Q(1, "km")
|
|
79
|
+
>>> u.ustrip(u.unit("m"), q)
|
|
80
|
+
Array(1000., dtype=float32, ...)
|
|
81
|
+
|
|
82
|
+
>>> u.ustrip("m", q)
|
|
83
|
+
Array(1000., dtype=float32, ...)
|
|
84
|
+
|
|
85
|
+
For further examples, see the other method dispatches.
|
|
86
|
+
|
|
87
|
+
"""
|
|
88
|
+
raise NotImplementedError # pragma: no cover
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@plum.dispatch.abstract
|
|
92
|
+
def is_unit_convertible(to_unit: Any, from_: Any, /) -> bool:
|
|
93
|
+
"""Check if the units are convertible.
|
|
94
|
+
|
|
95
|
+
General signature is ``(to_unit, from_unit) -> bool``.
|
|
96
|
+
Other signatures are defined via method dispatch.
|
|
97
|
+
See ``is_unit_convertible.methods`` for details.
|
|
98
|
+
|
|
99
|
+
Examples
|
|
100
|
+
--------
|
|
101
|
+
>>> import unxt as u # implements `unxts.api.is_unit_convertible`
|
|
102
|
+
>>> u.is_unit_convertible(u.unit("m"), u.unit("km"))
|
|
103
|
+
True
|
|
104
|
+
|
|
105
|
+
>>> u.is_unit_convertible(u.unit("m"), u.unit("s"))
|
|
106
|
+
False
|
|
107
|
+
|
|
108
|
+
"""
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@plum.dispatch.abstract
|
|
113
|
+
def wrap_to(x: Any, min: Any, max: Any, /) -> Any:
|
|
114
|
+
"""Wrap to the range [min, max).
|
|
115
|
+
|
|
116
|
+
General signature: ``(x, min, max) -> wrapped_x``.
|
|
117
|
+
Other signatures are defined via method dispatch.
|
|
118
|
+
See ``wrap_to.methods`` for details.
|
|
119
|
+
|
|
120
|
+
Examples
|
|
121
|
+
--------
|
|
122
|
+
>>> import unxt as u
|
|
123
|
+
>>>
|
|
124
|
+
>>> angle = u.Angle(370, "deg")
|
|
125
|
+
>>> min, max = u.Q(0, "deg"), u.Q(360, "deg")
|
|
126
|
+
>>>
|
|
127
|
+
>>> u.quantity.wrap_to(angle, min, max)
|
|
128
|
+
Angle(Array(10, dtype=int32...), unit='deg')
|
|
129
|
+
>>>
|
|
130
|
+
>>> u.quantity.wrap_to(angle, min=min, max=max)
|
|
131
|
+
Angle(Array(10, dtype=int32...), unit='deg')
|
|
132
|
+
|
|
133
|
+
"""
|
|
134
|
+
raise NotImplementedError # pragma: no cover
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@plum.dispatch
|
|
138
|
+
def wrap_to(x: Any, /, *, min: Any, max: Any) -> Any:
|
|
139
|
+
"""Wrap to the range [min, max)."""
|
|
140
|
+
return wrap_to(x, min, max) # redirect to the standard method
|
unxts/api/_src/units.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Units API for unxt.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = ("unit", "unit_of")
|
|
7
|
+
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import plum
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@plum.dispatch.abstract
|
|
14
|
+
def unit(obj: Any, /) -> Any:
|
|
15
|
+
"""Construct the units from a units object."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@plum.dispatch.abstract
|
|
19
|
+
def unit_of(obj: Any, /) -> Any:
|
|
20
|
+
"""Return the units of an object."""
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Unit systems API for unxt.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = ("unitsystem_of",)
|
|
7
|
+
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import plum
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@plum.dispatch.abstract
|
|
14
|
+
def unitsystem_of(obj: Any, /) -> Any:
|
|
15
|
+
"""Return the unit system of an object."""
|
unxts/api/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '2.0.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (2, 0, 0)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
unxts/api/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unxts.api
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Abstract dispatch API definitions for unxt (canonical: unxts.api)
|
|
5
|
+
Project-URL: Bug Tracker, https://github.com/GalacticDynamics/unxt/issues
|
|
6
|
+
Project-URL: Homepage, https://github.com/GalacticDynamics/unxt
|
|
7
|
+
Author-email: GalacticDynamics <nstarman@users.noreply.github.com>, Nathaniel Starkman <nstarman@users.noreply.github.com>
|
|
8
|
+
License-Expression: BSD-3-Clause
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Requires-Dist: plum-dispatch>=2.5.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# unxts.api
|
|
27
|
+
|
|
28
|
+
Abstract dispatch API definitions for [unxt](https://github.com/GalacticDynamics/unxt).
|
|
29
|
+
|
|
30
|
+
This is the canonical package (`unxts.api`). It defines the abstract single-dispatch functions that libraries implement to support `unxt`-style unit-aware quantities.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install unxts.api
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import unxts.api as uapi
|
|
42
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
unxts/api/__init__.py,sha256=MRhg6MGv0Ne3ad3MCcuE2gq35k3agaU3tud1IhOtE4A,679
|
|
2
|
+
unxts/api/_version.py,sha256=M8-womMCm6RC2xFuYRGDGvgpBN64psyQZImZ5vOrGmc,520
|
|
3
|
+
unxts/api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
unxts/api/_src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
unxts/api/_src/dimensions.py,sha256=xODGFHdXQ5ci0aSngzAjPsfcQyoOjDQjEdrF7sDEd8M,928
|
|
6
|
+
unxts/api/_src/quantity.py,sha256=Lfo6ygbArH8V2P5VeH8Qs4_xG-S7A-gvK06L5ANHOpA,3792
|
|
7
|
+
unxts/api/_src/units.py,sha256=BSkDv7alBxMYKckWgwaMKOyLb9JcD9iuCfs1vGusNgk,362
|
|
8
|
+
unxts/api/_src/unitsystems.py,sha256=1ICoIWVZHGsJrFFsvbF-DTIzDAytCmgiMxkbiiEUHzY,273
|
|
9
|
+
unxts_api-2.0.0.dist-info/METADATA,sha256=r4FiJm7HHXF9mkzEAJI4YDO9aCEFvz6pDfl1oXt5N6E,1480
|
|
10
|
+
unxts_api-2.0.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
11
|
+
unxts_api-2.0.0.dist-info/licenses/LICENSE,sha256=dZw7glr5UgpWO9a1jlC004HhtLTytJbcQO9pQVMLk7g,1519
|
|
12
|
+
unxts_api-2.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, Nathaniel Starkman.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|