coordax 0.2.2__tar.gz → 0.2.3__tar.gz
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.
- {coordax-0.2.2 → coordax-0.2.3}/PKG-INFO +1 -1
- {coordax-0.2.2 → coordax-0.2.3}/coordax/__init__.py +1 -1
- {coordax-0.2.2 → coordax-0.2.3}/coordax/coordinate_systems.py +36 -1
- {coordax-0.2.2 → coordax-0.2.3}/coordax/coordinate_systems_test.py +21 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/coords.py +1 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax.egg-info/PKG-INFO +1 -1
- {coordax-0.2.2 → coordax-0.2.3}/pyproject.toml +1 -1
- {coordax-0.2.2 → coordax-0.2.3}/LICENSE +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/README.md +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/doctest_test.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/experimental.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/fields.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/fields_test.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/jax_datetime_integration_test.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/named_axes.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/named_axes_test.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/ndarrays.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/testing.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/utils.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax/xarray_test.py +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax.egg-info/SOURCES.txt +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax.egg-info/dependency_links.txt +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax.egg-info/requires.txt +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/coordax.egg-info/top_level.txt +0 -0
- {coordax-0.2.2 → coordax-0.2.3}/setup.cfg +0 -0
|
@@ -25,7 +25,7 @@ import dataclasses
|
|
|
25
25
|
import functools
|
|
26
26
|
import itertools
|
|
27
27
|
import typing
|
|
28
|
-
from typing import Any, Self, TYPE_CHECKING, TypeAlias, TypeVar
|
|
28
|
+
from typing import Any, Self, TYPE_CHECKING, Type, TypeAlias, TypeVar
|
|
29
29
|
import warnings
|
|
30
30
|
|
|
31
31
|
from coordax import utils
|
|
@@ -636,6 +636,41 @@ def replace_axes(
|
|
|
636
636
|
return compose(*axes)
|
|
637
637
|
|
|
638
638
|
|
|
639
|
+
@functools.partial(utils.export, module='coordax.coords')
|
|
640
|
+
def extract(
|
|
641
|
+
coord: Coordinate,
|
|
642
|
+
component_type: Type[Coordinate] | tuple[Type[Coordinate], ...],
|
|
643
|
+
) -> Coordinate:
|
|
644
|
+
"""Extracts component of type `component_type` from the `coord`.
|
|
645
|
+
|
|
646
|
+
Args:
|
|
647
|
+
coord: The coordinate system to search.
|
|
648
|
+
component_type: The type(s) of coordinate to extract.
|
|
649
|
+
|
|
650
|
+
Returns:
|
|
651
|
+
The single coordinate component matching the given type(s).
|
|
652
|
+
|
|
653
|
+
Raises:
|
|
654
|
+
ValueError: If there is not exactly one component of the given type(s).
|
|
655
|
+
|
|
656
|
+
Examples:
|
|
657
|
+
>>> import coordax as cx
|
|
658
|
+
>>> import numpy as np
|
|
659
|
+
>>> x = cx.LabeledAxis('x', np.linspace(0, np.pi, 4))
|
|
660
|
+
>>> y = cx.SizedAxis('y', 3)
|
|
661
|
+
>>> cx.coords.extract(cx.coords.compose(x, y), cx.SizedAxis)
|
|
662
|
+
coordax.SizedAxis('y', size=3)
|
|
663
|
+
"""
|
|
664
|
+
components = canonicalize(coord)
|
|
665
|
+
of_type = [c for c in components if isinstance(c, component_type)]
|
|
666
|
+
if len(of_type) != 1:
|
|
667
|
+
raise ValueError(
|
|
668
|
+
f'Expected exactly one instance of {component_type}, found {of_type}'
|
|
669
|
+
)
|
|
670
|
+
[result] = of_type
|
|
671
|
+
return result
|
|
672
|
+
|
|
673
|
+
|
|
639
674
|
@functools.partial(utils.export, module='coordax.coords')
|
|
640
675
|
def from_xarray(
|
|
641
676
|
data_array: xarray.DataArray,
|
|
@@ -459,6 +459,27 @@ class CoordinateSystemsTest(parameterized.TestCase):
|
|
|
459
459
|
):
|
|
460
460
|
cx.CartesianProduct((x, y))
|
|
461
461
|
|
|
462
|
+
def test_extract(self):
|
|
463
|
+
x = cx.SizedAxis('x', 2)
|
|
464
|
+
y = cx.SizedAxis('y', 3)
|
|
465
|
+
z = cx.LabeledAxis('z', np.arange(4))
|
|
466
|
+
xy = cx.coords.compose(x, y)
|
|
467
|
+
xz = cx.coords.compose(x, z)
|
|
468
|
+
|
|
469
|
+
self.assertEqual(cx.coords.extract(x, cx.SizedAxis), x)
|
|
470
|
+
self.assertEqual(cx.coords.extract(z, cx.LabeledAxis), z)
|
|
471
|
+
self.assertEqual(cx.coords.extract(xz, cx.LabeledAxis), z)
|
|
472
|
+
self.assertEqual(cx.coords.extract(z, (cx.SizedAxis, cx.LabeledAxis)), z)
|
|
473
|
+
|
|
474
|
+
with self.assertRaisesRegex(ValueError, 'Expected exactly one instance'):
|
|
475
|
+
cx.coords.extract(xy, cx.SizedAxis)
|
|
476
|
+
|
|
477
|
+
with self.assertRaisesRegex(ValueError, 'Expected exactly one instance'):
|
|
478
|
+
cx.coords.extract(xz, (cx.SizedAxis, cx.LabeledAxis))
|
|
479
|
+
|
|
480
|
+
with self.assertRaisesRegex(ValueError, 'Expected exactly one instance'):
|
|
481
|
+
cx.coords.extract(x, cx.LabeledAxis)
|
|
482
|
+
|
|
462
483
|
def test_deprecated_aliases(self):
|
|
463
484
|
with self.assertWarnsRegex(
|
|
464
485
|
DeprecationWarning,
|
|
@@ -7,7 +7,7 @@ packages = ["coordax"]
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "coordax"
|
|
10
|
-
version = "0.2.
|
|
10
|
+
version = "0.2.3" # keep sync with __init__.py
|
|
11
11
|
description = "Coordinate axes for scientific computing in JAX"
|
|
12
12
|
authors = [
|
|
13
13
|
{name = "Google LLC", email = "noreply@google.com"},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|