Skip to content

Commit 3f0caa6

Browse files
committed
Add more attributes to typed variables
1 parent 1136cb2 commit 3f0caa6

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
Please add your functional changes to the appropriate section in the PR.
99
Keep it human-readable, your future self will thank you!
10+
11+
## [Unreleased]
12+
13+
### Changed
14+
15+
- Add more attributes to typed variables

dev/dev.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
mars = source_factory(
88
"mars",
9+
)
10+
11+
r = dict(
912
param=["u", "v", "t", "q"],
1013
grid=[20, 20],
1114
date="20200101/to/20200105",
1215
levelist=[1000, 850, 500],
1316
)
1417

15-
data = mars.forward(None)
18+
data = mars.forward(r)
1619

1720
for f in data:
1821
print(f)
@@ -35,11 +38,16 @@
3538
################
3639

3740
pipeline = workflow_factory("pipeline", filters=[mars, uv_2_ddff, ddff_2_uv])
38-
for f in pipeline(None):
41+
for f in pipeline(r):
3942
print(f)
4043

4144
################
42-
pipeline = mars | uv_2_ddff | ddff_2_uv
45+
46+
47+
pipeline = r | mars | uv_2_ddff | ddff_2_uv
4348

4449
for f in pipeline:
4550
print(f)
51+
52+
53+
ipipe = pipeline.to_infernece()

src/anemoi/transform/grids/unstructured.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def __init__(self, latitudes, longitudes, uuidOfHGrid=None):
2828
assert isinstance(latitudes, np.ndarray), type(latitudes)
2929
assert isinstance(longitudes, np.ndarray), type(longitudes)
3030

31-
LOG.info(f"Latitudes: {len(latitudes)}, Longitudes: {len(longitudes)}")
3231
assert len(latitudes) == len(longitudes)
3332

3433
self.uuidOfHGrid = uuidOfHGrid
@@ -95,7 +94,7 @@ def from_grib(cls, latitudes_url_or_path, longitudes_url_or_path, latitudes_para
9594
return cls([UnstructuredGridField(Geography(latitudes, longitudes))])
9695

9796
@classmethod
98-
def from_values(cls, latitudes, longitudes):
97+
def from_values(cls, *, latitudes, longitudes):
9998
if isinstance(latitudes, (list, tuple)):
10099
latitudes = np.array(latitudes)
101100

src/anemoi/transform/sources/mars.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ class Mars(Source):
1818
"""A demo source"""
1919

2020
def __init__(self, **request):
21-
self.request = request
21+
pass
2222

2323
def forward(self, data):
24-
assert data is None
24+
return ekd.from_source("mars", **data)
2525

26-
return ekd.from_source("mars", **self.request)
26+
def __ror__(self, data):
27+
28+
class Input:
29+
def __init__(self, data):
30+
self.data = data
31+
32+
return Input(data)
2733

2834

2935
register_source("mars", Mars)

src/anemoi/transform/variables/variables.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# granted to it by virtue of its status as an intergovernmental organisation
66
# nor does it submit to any jurisdiction.
77

8-
import json
98

109
from . import Variable
1110

@@ -16,11 +15,7 @@ class VariableFromMarsVocabulary(Variable):
1615
def __init__(self, name, data: dict) -> None:
1716
super().__init__(name)
1817
self.data = data
19-
print(json.dumps(data, indent=4))
20-
if "mars" in self.data:
21-
self.mars = self.data["mars"]
22-
else:
23-
self.mars = self.data
18+
self.mars = self.data.get("mars", {})
2419

2520
@property
2621
def is_pressure_level(self):
@@ -32,7 +27,15 @@ def level(self):
3227

3328
@property
3429
def is_constant_in_time(self):
35-
return self.data.get("is_constant_in_time", False)
30+
return self.data.get("constant_in_time", False)
31+
32+
@property
33+
def is_from_input(self):
34+
return "mars" in self.data
35+
36+
@property
37+
def is_computed_forcing(self):
38+
return self.data.get("computed_forcing", False)
3639

3740

3841
class VariableFromDict(VariableFromMarsVocabulary):

tests/test_grids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
tlon = "tlon"
1717

1818

19-
def test_unstructured_from_url():
19+
def do_not_test_unstructured_from_url():
2020
ds = UnstructuredGridFieldList.from_grib(latitude_url, longitudes_url, tlat, tlon)
2121

2222
assert len(ds) == 1

0 commit comments

Comments
 (0)