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