Skip to content

Commit 0c30cfd

Browse files
committed
cleanup
Signed-off-by: Callan Gray <cal.j.gray@gmail.com>
1 parent 0a57e8e commit 0c30cfd

9 files changed

Lines changed: 77 additions & 265 deletions

File tree

astropy_xarray/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import astropy.units
1919

20-
import astropy_xarray.time_compat
20+
import astropy_xarray.time_compat # noqa: F401
2121
from astropy_xarray import accessors, formatting, testing # noqa: F401
2222
from astropy_xarray.index import AstropyIndex
2323

astropy_xarray/coordinates/sky_coord.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import itertools
22
from collections.abc import Generator
3-
from enum import Enum, auto
43

54
import astropy.units as u
65
import numpy as np
@@ -10,35 +9,6 @@
109
from astropy_xarray.coordinates.frame import dump_frame, load_frame, load_representation
1110

1211

13-
class DatasetRepresentation(Enum):
14-
FRAME = auto()
15-
"""
16-
Frame selected repesentation and differential component names, simplifying for any `unitspherical` types in data.
17-
18-
Same as `get_representation_component_names()` and `get_differential_component_names()`
19-
"""
20-
21-
FRAME_FULL = auto()
22-
"""
23-
Frame selected repesentation and differential component names.
24-
25-
Same as `get_representation_component_names()` and `get_differential_component_names()`
26-
"""
27-
28-
FRAME_DEFAULT = auto()
29-
"""Frame default components names."""
30-
31-
FRAME_DATA = auto()
32-
"""
33-
Frame component names from resetting the display representation and differential to match the data.
34-
35-
Guarentees roundtrip accuracy.
36-
"""
37-
38-
DATA = auto()
39-
"""Data representation components. Guarentees roundtrip accuracy."""
40-
41-
4212
def _skycoord_representation_component_names(
4313
skycoord: SkyCoord,
4414
) -> tuple[str, ...]:

astropy_xarray/tests/multi_index_utils.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

astropy_xarray/tests/test_frame_rep.py renamed to astropy_xarray/tests/test_frame_conversion.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from importlib.metadata import version
2+
13
import astropy.units as u
24
import numpy.testing
35
import pytest
@@ -7,6 +9,7 @@
79
SkyCoord,
810
)
911
from astropy.coordinates.builtin_frames import ICRS
12+
from packaging.version import Version
1013

1114
from astropy_xarray.coordinates import (
1215
skycoord_to_dataset,
@@ -41,7 +44,10 @@ def test_frame_conversion_aliasing():
4144
numpy.testing.assert_array_equal(sc.pm_ra_cosdec, sc2.pm_ra_cosdec)
4245

4346

44-
@pytest.mark.xfail(reason="astropy 6.0.0 skycoords not supported")
47+
@pytest.mark.xfail(
48+
condition=Version(version("astropy")) <= Version("7.0.0"),
49+
reason="astropy 6.0.0 skycoords not supported",
50+
)
4551
def test_frame_conversion_components():
4652
sc = SkyCoord(
4753
ICRS().realize_frame(

astropy_xarray/tests/test_sky_coord.py

Lines changed: 21 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from collections.abc import Generator
2-
from typing import Any
1+
import sys
32

43
import astropy.units as u
54
import numpy as np
@@ -47,18 +46,21 @@
4746
Supergalactic,
4847
)
4948
from astropy.time import Time
50-
from xarray.tests import requires_zarr
5149

5250
from astropy_xarray.coordinates import (
5351
dataset_to_skycoord,
5452
skycoord_to_dataset,
5553
)
5654
from astropy_xarray.coordinates.sky_coord import (
57-
DatasetRepresentation,
5855
_skycoord_differential_component_names,
5956
_skycoord_representation_component_names,
6057
)
6158

59+
pytestmark = pytest.mark.skipif(
60+
sys.version_info < (3, 11),
61+
reason="python3.10 or higher required for skycoords support",
62+
)
63+
6264

6365
@pytest.mark.parametrize(
6466
("expected_base", "expected_s"),
@@ -84,26 +86,15 @@ def test_unitspherical_repr_components(expected_base, expected_s):
8486

8587

8688
@pytest.mark.parametrize(
87-
("representation", "expected_base", "expected_s"),
89+
("expected_base", "expected_s"),
8890
[
8991
(
90-
DatasetRepresentation.FRAME,
9192
("ra", "dec", "distance"),
9293
("pm_ra_cosdec", "pm_dec"),
93-
),
94-
(
95-
DatasetRepresentation.FRAME_DEFAULT,
96-
("ra", "dec", "distance"),
97-
("pm_ra_cosdec", "pm_dec", "radial_velocity"),
98-
),
99-
(
100-
DatasetRepresentation.DATA,
101-
("lon", "lat", "distance"),
102-
("d_lon_coslat", "d_lat"),
103-
),
94+
)
10495
],
10596
)
106-
def test_unitspherical_diff_components(representation, expected_base, expected_s):
97+
def test_unitspherical_diff_components(expected_base, expected_s):
10798
sc = SkyCoord(
10899
ra=[[0.1], [2], [0.2]] * u.deg,
109100
dec=[[0.5], [7], [0.7]] * u.deg,
@@ -118,31 +109,26 @@ def test_unitspherical_diff_components(representation, expected_base, expected_s
118109

119110

120111
@pytest.mark.parametrize(
121-
("representation", "frame", "expected_base", "expected_s"),
112+
("frame", "expected_base", "expected_s"),
122113
[
123114
(
124-
DatasetRepresentation.FRAME_DATA,
125115
ICRS(),
126116
("ra", "dec"),
127117
("pm_ra_cosdec", "pm_dec"),
128118
),
129119
(
130-
DatasetRepresentation.FRAME_DATA,
131120
AltAz(),
132121
("az", "alt"),
133122
("pm_az_cosalt", "pm_alt"),
134123
),
135124
(
136-
DatasetRepresentation.FRAME_DATA,
137125
ITRS(),
138126
("lon", "lat"),
139127
("pm_lon_coslat", "pm_lat"),
140128
),
141129
],
142130
)
143-
def test_spherical_direction_components_realize_frame(
144-
representation, frame, expected_base, expected_s
145-
):
131+
def test_spherical_direction_components_realize_frame(frame, expected_base, expected_s):
146132
rep = UnitSphericalRepresentation(
147133
[[0.1], [2], [0.2]] * u.deg,
148134
[[0.5], [7], [0.7]] * u.deg,
@@ -157,12 +143,12 @@ def test_spherical_direction_components_realize_frame(
157143

158144

159145
@pytest.mark.parametrize(
160-
("representation", "expected_base", "expected_s"),
146+
("expected_base", "expected_s"),
161147
[
162-
(DatasetRepresentation.FRAME_DATA, ("x", "y", "z"), ("v_x", "v_y", "v_z")),
148+
(("x", "y", "z"), ("v_x", "v_y", "v_z")),
163149
],
164150
)
165-
def test_cartesian_direction_components(representation, expected_base, expected_s):
151+
def test_cartesian_direction_components(expected_base, expected_s):
166152
sc = SkyCoord(
167153
x=[[0.1], [2], [0.2]] * u.dimensionless_unscaled,
168154
y=[[0.5], [7], [0.7]] * u.dimensionless_unscaled,
@@ -176,20 +162,11 @@ def test_cartesian_direction_components(representation, expected_base, expected_
176162
assert _skycoord_differential_component_names(sc) == expected_s
177163

178164

179-
@pytest.fixture(name="store", scope="session")
180-
def store_fixture() -> Generator[Any, None, None]:
181-
import zarr.storage as zs
182-
183-
with zs.MemoryStore() as store:
184-
yield store
185-
186-
187-
@requires_zarr
188165
@pytest.mark.parametrize(
189-
"representation",
166+
"use_default_representation",
190167
[
191-
pytest.param(DatasetRepresentation.FRAME_DATA),
192-
pytest.param(DatasetRepresentation.FRAME_DEFAULT),
168+
pytest.param(True),
169+
pytest.param(False),
193170
],
194171
)
195172
@pytest.mark.parametrize(
@@ -308,37 +285,29 @@ def store_fixture() -> Generator[Any, None, None]:
308285
ids=lambda param: param.name,
309286
)
310287
def test_skycoord_roundtrip(
311-
store,
312288
frame: BaseCoordinateFrame,
313289
data: BaseRepresentation,
314290
expected_data_classes: tuple[type, ...],
315-
representation: DatasetRepresentation,
291+
use_default_representation: bool,
316292
):
317293
# all frames support all representation types
318294
representation_type = type(data)
319295
differential_type = type(data.differentials["s"])
320296

321-
if representation == DatasetRepresentation.FRAME_DATA:
322-
expected = SkyCoord(frame.realize_frame(data))
323-
elif representation == DatasetRepresentation.FRAME_DEFAULT:
297+
if use_default_representation:
324298
expected = SkyCoord(
325299
frame.realize_frame(
326300
data.represent_as(
327301
frame.default_representation, frame.default_differential
328302
)
329303
)
330304
)
331-
else:
332-
raise NotImplementedError()
333-
334-
if representation == DatasetRepresentation.FRAME_DEFAULT:
335305
expected_frame_data_rep_name = frame.default_representation.name
336306
expected_frame_data_diff_name = frame.default_differential.name
337-
elif representation == DatasetRepresentation.FRAME_DATA:
307+
else:
308+
expected = SkyCoord(frame.realize_frame(data))
338309
expected_frame_data_rep_name = representation_type.name
339310
expected_frame_data_diff_name = differential_type.name
340-
else:
341-
raise NotImplementedError()
342311

343312
assert expected.frame.data.name == expected_frame_data_rep_name
344313
assert expected.frame.data.differentials["s"].name == expected_frame_data_diff_name
@@ -360,46 +329,9 @@ def test_skycoord_roundtrip(
360329
)
361330
assert set(ds.data_vars) == expected_keys
362331

363-
# data_var value types
364-
if representation in (
365-
DatasetRepresentation.FRAME,
366-
DatasetRepresentation.FRAME_DEFAULT,
367-
):
368-
print(expected_keys)
369-
elif representation == DatasetRepresentation.DATA:
370-
expected_classes = zip(
371-
expected.get_representation_component_names(), expected_data_classes
372-
)
373-
for expected_key, expected_class_type in expected_classes:
374-
assert isinstance(ds.data_vars[expected_key].data, expected_class_type)
375-
assert ds.data_vars[expected_key].coords.identical(
376-
xr.Coordinates(dict(coords))
377-
)
378-
379-
# sanity check dataset
380-
assert ds.attrs["frame"]["representation_type"] == representation_type.name
381-
assert ds.attrs["frame"]["differential_type"] == differential_type.name
382-
assert ds.attrs["frame"]["data"]["representation_type"] == data.name
383-
assert (
384-
ds.attrs["frame"]["data"]["differential_type"]
385-
== data.differentials["s"].name
386-
)
387-
388332
# Convert back
389333
actual = dataset_to_skycoord(ds)
390334

391-
# check representations
392-
if representation in (
393-
DatasetRepresentation.FRAME,
394-
DatasetRepresentation.FRAME_DEFAULT,
395-
):
396-
print(actual)
397-
if representation == DatasetRepresentation.DATA:
398-
assert actual.representation_type.name == representation_type.name
399-
assert actual.differential_type.name == differential_type.name
400-
assert actual.frame.data.name == data.name
401-
assert actual.frame.data.differentials["s"].name == data.differentials["s"].name
402-
403335
# Check Representation
404336
for component_name in actual.frame.representation_component_names:
405337
np.testing.assert_array_equal(
@@ -418,10 +350,3 @@ def test_skycoord_roundtrip(
418350
assert actual.is_equivalent_frame(expected)
419351
assert ds.coords.equals(xr.Coordinates(dict(coords)))
420352
np.testing.assert_array_equal(actual, expected)
421-
422-
# Check intermediate dataset is serializable
423-
# ds.astropy.dequantify().to_zarr(store, mode="w", consolidated=True)
424-
# ds_store = xr.open_dataset(
425-
# store, engine="zarr", consolidated=True
426-
# ).astropy.quantify()
427-
# xr.testing.assert_identical(ds, ds_store)

0 commit comments

Comments
 (0)