unxt-api 1.8.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.
- unxt_api/__init__.py +23 -0
- unxt_api/_dimensions.py +38 -0
- unxt_api/_quantity.py +85 -0
- unxt_api/_units.py +20 -0
- unxt_api/_unitsystems.py +15 -0
- unxt_api/_version.py +34 -0
- unxt_api-1.8.0.dist-info/METADATA +81 -0
- unxt_api-1.8.0.dist-info/RECORD +9 -0
- unxt_api-1.8.0.dist-info/WHEEL +4 -0
unxt_api/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Abstract dispatch API for unxt.
|
|
2
|
+
|
|
3
|
+
This package defines the abstract dispatch interfaces for unxt's core functionality.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = (
|
|
7
|
+
"__version__",
|
|
8
|
+
"dimension",
|
|
9
|
+
"dimension_of",
|
|
10
|
+
"uconvert",
|
|
11
|
+
"ustrip",
|
|
12
|
+
"is_unit_convertible",
|
|
13
|
+
"wrap_to",
|
|
14
|
+
"unit",
|
|
15
|
+
"unit_of",
|
|
16
|
+
"unitsystem_of",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from ._dimensions import dimension, dimension_of
|
|
20
|
+
from ._quantity import is_unit_convertible, uconvert, ustrip, wrap_to
|
|
21
|
+
from ._units import unit, unit_of
|
|
22
|
+
from ._unitsystems import unitsystem_of
|
|
23
|
+
from ._version import version as __version__
|
unxt_api/_dimensions.py
ADDED
|
@@ -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
|
+
"""
|
unxt_api/_quantity.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Quantity API for unxt.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = ("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(u: Any, x: Any, /) -> Any:
|
|
15
|
+
"""Convert the quantity to the specified units.
|
|
16
|
+
|
|
17
|
+
Examples
|
|
18
|
+
--------
|
|
19
|
+
>>> import unxt as u
|
|
20
|
+
|
|
21
|
+
>>> q = u.Quantity(1, "km")
|
|
22
|
+
>>> u.uconvert(u.unit("m"), q)
|
|
23
|
+
Quantity(Array(1000., dtype=float32, ...), unit='m')
|
|
24
|
+
|
|
25
|
+
>>> u.uconvert("m", q)
|
|
26
|
+
Quantity(Array(1000., dtype=float32, ...), unit='m')
|
|
27
|
+
|
|
28
|
+
For further examples, see the other method dispatches.
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
raise NotImplementedError # pragma: no cover
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@plum.dispatch.abstract
|
|
35
|
+
def ustrip(*args: Any) -> Any:
|
|
36
|
+
"""Strip the units from the quantity, first converting if necessary.
|
|
37
|
+
|
|
38
|
+
Examples
|
|
39
|
+
--------
|
|
40
|
+
>>> import unxt as u
|
|
41
|
+
|
|
42
|
+
>>> q = u.Quantity(1, "km")
|
|
43
|
+
>>> ustrip(u.unit("m"), q)
|
|
44
|
+
Array(1000., dtype=float32, ...)
|
|
45
|
+
|
|
46
|
+
>>> u.ustrip("m", q)
|
|
47
|
+
Array(1000., dtype=float32, ...)
|
|
48
|
+
|
|
49
|
+
For further examples, see the other method dispatches.
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
raise NotImplementedError # pragma: no cover
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@plum.dispatch.abstract
|
|
56
|
+
def is_unit_convertible(to_unit: Any, from_: Any, /) -> bool:
|
|
57
|
+
"""Check if the units are convertible."""
|
|
58
|
+
return False
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@plum.dispatch.abstract
|
|
62
|
+
def wrap_to(x: Any, min: Any, max: Any, /) -> Any:
|
|
63
|
+
"""Wrap to the range [min, max).
|
|
64
|
+
|
|
65
|
+
Examples
|
|
66
|
+
--------
|
|
67
|
+
>>> import unxt as u
|
|
68
|
+
>>>
|
|
69
|
+
>>> angle = u.Angle(370, "deg")
|
|
70
|
+
>>> min, max = u.Quantity(0, "deg"), u.Quantity(360, "deg")
|
|
71
|
+
>>>
|
|
72
|
+
>>> u.quantity.wrap_to(angle, min, max)
|
|
73
|
+
Angle(Array(10, dtype=int32, ...), unit='deg')
|
|
74
|
+
>>>
|
|
75
|
+
>>> u.quantity.wrap_to(angle, min=min, max=max)
|
|
76
|
+
Angle(Array(10, dtype=int32, ...), unit='deg')
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
raise NotImplementedError # pragma: no cover
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@plum.dispatch
|
|
83
|
+
def wrap_to(x: Any, /, *, min: Any, max: Any) -> Any:
|
|
84
|
+
"""Wrap to the range [min, max)."""
|
|
85
|
+
return wrap_to(x, min, max) # redirect to the standard method
|
unxt_api/_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."""
|
unxt_api/_unitsystems.py
ADDED
|
@@ -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."""
|
unxt_api/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '1.8.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 8, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unxt-api
|
|
3
|
+
Version: 1.8.0
|
|
4
|
+
Summary: Abstract dispatch API definitions for unxt
|
|
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: BSD-3-Clause
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
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.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: astropy>=7.0.0
|
|
24
|
+
Requires-Dist: plum-dispatch>=2.5.7
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# unxt-api
|
|
28
|
+
|
|
29
|
+
Abstract dispatch API definitions for unxt.
|
|
30
|
+
|
|
31
|
+
This package defines the abstract dispatch interfaces that unxt and other
|
|
32
|
+
packages can implement. It provides a minimal dependency set for packages that
|
|
33
|
+
want to define or use unxt's dispatch-based API without pulling in the full unxt
|
|
34
|
+
implementation.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install unxt-api
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
This package is typically used as a dependency by unxt and related packages. It
|
|
45
|
+
defines abstract dispatch signatures using plum-dispatch that concrete
|
|
46
|
+
implementations register against.
|
|
47
|
+
|
|
48
|
+
For comprehensive documentation, examples, and extension guides, see:
|
|
49
|
+
|
|
50
|
+
- [unxt-api API Reference](https://unxt.readthedocs.io/en/latest/api/unxt-api.html)
|
|
51
|
+
- [Extending unxt Guide](https://unxt.readthedocs.io/en/latest/guides/extending.html)
|
|
52
|
+
- [Main unxt Documentation](https://unxt.readthedocs.io/)
|
|
53
|
+
|
|
54
|
+
## Quick Example
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from plum import dispatch
|
|
58
|
+
import unxt as u
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class Temperature:
|
|
62
|
+
def __init__(self, value, unit="K"):
|
|
63
|
+
self.value = value
|
|
64
|
+
self.unit_str = unit
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dispatch
|
|
68
|
+
def unit_of(obj: Temperature, /):
|
|
69
|
+
return u.unit(obj.unit_str)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dispatch
|
|
73
|
+
def dimension_of(obj: Temperature, /):
|
|
74
|
+
return u.dimension("temperature")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# Now Temperature works with unxt!
|
|
78
|
+
temp = Temperature(300, "K")
|
|
79
|
+
u.unit_of(temp) # Unit("K")
|
|
80
|
+
u.dimension_of(temp) # PhysicalType('temperature')
|
|
81
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
unxt_api/__init__.py,sha256=HV4CJJquvOaculUlM4Radph0SJypwDUC5d1SicIigcM,555
|
|
2
|
+
unxt_api/_dimensions.py,sha256=xODGFHdXQ5ci0aSngzAjPsfcQyoOjDQjEdrF7sDEd8M,928
|
|
3
|
+
unxt_api/_quantity.py,sha256=7mDc4zyTSWOXHJVxFMnF02qgv1pwKlEXkMgueEeEjOs,2035
|
|
4
|
+
unxt_api/_units.py,sha256=BSkDv7alBxMYKckWgwaMKOyLb9JcD9iuCfs1vGusNgk,362
|
|
5
|
+
unxt_api/_unitsystems.py,sha256=1ICoIWVZHGsJrFFsvbF-DTIzDAytCmgiMxkbiiEUHzY,273
|
|
6
|
+
unxt_api/_version.py,sha256=phQCmpksYlbZjXJhFI2j2KILuWjD0mXWO3Hg8g_EC8c,704
|
|
7
|
+
unxt_api-1.8.0.dist-info/METADATA,sha256=XfnohXwQPv7hSgAlEa73ui92-yHIJADOOR5AyojsW78,2488
|
|
8
|
+
unxt_api-1.8.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
9
|
+
unxt_api-1.8.0.dist-info/RECORD,,
|