Skip to content

Commit 1f9816f

Browse files
authored
#175 Merge pull request from astropenguin/astropenguin/issue174
Add v2 specs module
2 parents 5c5d744 + 2eb51e7 commit 1f9816f

File tree

7 files changed

+403
-384
lines changed

7 files changed

+403
-384
lines changed

tests/test_data.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# standard library
2+
from dataclasses import dataclass
3+
from typing import Collection, Tuple, Union
4+
5+
6+
# dependencies
7+
import numpy as np
8+
from typing_extensions import Annotated as Ann, Literal as L
9+
from xarray_dataclasses.v2.typing import Attr, Coord, Coordof, Data
10+
11+
12+
# type hints
13+
X = L["x"]
14+
Y = L["y"]
15+
T = L["time"]
16+
_ = Tuple[()]
17+
18+
19+
# test data
20+
@dataclass
21+
class Longitude:
22+
"""Specification of longitude."""
23+
24+
data: Data[Tuple[X, Y], float]
25+
units: Attr[str] = "deg"
26+
27+
28+
@dataclass
29+
class Latitude:
30+
"""Specification of latitude."""
31+
32+
data: Data[Tuple[X, Y], float]
33+
units: Attr[str] = "deg"
34+
35+
36+
@dataclass
37+
class Weather:
38+
"""Weather information."""
39+
40+
temp: Ann[Data[Tuple[X, Y, T], float], "Temperature ({.temp_unit})"]
41+
"""Measured temperature."""
42+
43+
prec: Ann[Data[Tuple[X, Y, T], float], "Precipitation ({.prec_unit})"]
44+
"""Measured precipitation."""
45+
46+
lon: Union[Ann[Coordof[Longitude], "Longitude"], Collection[float]]
47+
"""Longitude of the measured location."""
48+
49+
lat: Union[Ann[Coordof[Latitude], "Latitude"], Collection[float]]
50+
"""Latitude of the measured location."""
51+
52+
time: Coord[T, L["M8[ns]"]]
53+
"""Measured time."""
54+
55+
reference_time: Union[Coord[_, L["M8[ns]"]], np.datetime64]
56+
"""Reference time."""
57+
58+
temp_unit: str = "deg C"
59+
"""Unit of the temperature."""
60+
61+
prec_unit: str = "mm"
62+
"""Unit of the precipitation."""
63+
64+
65+
weather = Weather(
66+
15 + 8 * np.random.randn(2, 2, 3),
67+
10 * np.random.rand(2, 2, 3),
68+
np.array([[-99.83, -99.32], [-99.79, -99.23]]),
69+
np.array([[42.25, 42.21], [42.63, 42.59]]),
70+
np.array(["2014-09-06", "2014-09-07", "2014-09-08"], "M8[ns]"),
71+
np.datetime64("2014-09-05"),
72+
)

tests/test_specs.py

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

0 commit comments

Comments
 (0)