Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
9cb8c52
feat: recipe generator
b8raoult May 8, 2025
01774dd
update
b8raoult May 8, 2025
33793a6
update
b8raoult May 8, 2025
920d523
update
b8raoult May 8, 2025
ed5d190
update
b8raoult May 8, 2025
2562baf
fix: better handling of xarray metadata
b8raoult May 10, 2025
f048a4b
update
b8raoult May 10, 2025
8ad5eb0
update
b8raoult May 10, 2025
5db7a97
Merge branch 'fix/better-handling-of-xarray-metadata' into feat/recip…
b8raoult May 10, 2025
b33f3ac
fix: support other keys that param in rename filter
b8raoult May 10, 2025
71d8180
Merge branch 'fix/support-other-keys-than-param-in-rename-filter' int…
b8raoult May 10, 2025
6d23027
typo
b8raoult May 10, 2025
6933574
Merge branch 'fix/support-other-keys-than-param-in-rename-filter' int…
b8raoult May 10, 2025
9179dae
add command line
b8raoult May 10, 2025
79a391b
update
b8raoult May 11, 2025
203e09b
update
b8raoult May 11, 2025
b4433bd
update
b8raoult May 11, 2025
6f3fdb0
update
b8raoult May 11, 2025
45365a1
upadte
b8raoult May 12, 2025
d7cc82c
update
b8raoult May 12, 2025
f381b00
update
b8raoult May 12, 2025
da93ad6
update
b8raoult May 14, 2025
3082edf
refactor missing
b8raoult Jul 9, 2025
ef4a5c9
add references
b8raoult Jul 9, 2025
93410d5
refactor
b8raoult Jul 9, 2025
1df0ef7
refactor
b8raoult Jul 9, 2025
18df4eb
refactor
b8raoult Jul 9, 2025
3341d4c
update
b8raoult Jul 9, 2025
58dc8a2
work on migrate
b8raoult Jul 10, 2025
3e180f9
work on migrate
b8raoult Jul 10, 2025
255c22d
merge
b8raoult Aug 11, 2025
83936f7
merge
b8raoult Aug 11, 2025
5209f26
update
b8raoult Aug 11, 2025
c7a0e5d
update
b8raoult Aug 12, 2025
b78a098
update
b8raoult Aug 12, 2025
d641ea7
update
b8raoult Aug 13, 2025
3754eb2
update
b8raoult Aug 14, 2025
39ebc13
update
b8raoult Aug 14, 2025
5d32745
update
b8raoult Aug 14, 2025
6c1f146
update
b8raoult Aug 14, 2025
37de369
update
b8raoult Aug 14, 2025
24f2c2a
update
b8raoult Aug 15, 2025
db4d895
add dumper
b8raoult Aug 15, 2025
55f740d
update
b8raoult Aug 15, 2025
014dbbc
update
b8raoult Aug 15, 2025
8ad9396
bug fix in path
b8raoult Aug 15, 2025
9756618
join recipe command
b8raoult Aug 15, 2025
a493a96
join recipe command
b8raoult Aug 15, 2025
1cde9f8
use ampersand
b8raoult Aug 15, 2025
cdb1a9a
use ampersand
b8raoult Aug 15, 2025
e69eb10
add settings
b8raoult Aug 16, 2025
92165b4
add settings
b8raoult Aug 16, 2025
a044e14
udpate
b8raoult Aug 16, 2025
cb9c576
use ruamel
b8raoult Aug 16, 2025
99a5fb7
fix source as parameters
b8raoult Aug 16, 2025
ce027f4
update
b8raoult Aug 18, 2025
3bf7c35
Merge branch 'feat/refactor-create' of github.com:ecmwf/anemoi-datase…
b8raoult Aug 22, 2025
96dfe3d
Merge branch 'feat/recipe-generator' into feat/refactor-create
b8raoult Aug 22, 2025
f68a11e
Merge remote-tracking branch 'origin/main' into feat/refactor-create
b8raoult Aug 22, 2025
3d5f0ef
tidy
b8raoult Aug 22, 2025
70272f6
update
b8raoult Aug 22, 2025
38ced18
update tests
b8raoult Aug 22, 2025
cb3847e
fix tests
b8raoult Aug 22, 2025
00477c9
add missing package
b8raoult Aug 25, 2025
839a077
Merge branch 'main' into feat/refactor-create
floriankrb Sep 5, 2025
619c416
remove unsused file
b8raoult Sep 15, 2025
21321cb
Update copyright year
mchantry Sep 15, 2025
90e21ee
Fix copyright header
mchantry Sep 15, 2025
fa35755
bug fix in repeated dates
b8raoult Sep 18, 2025
2fc4189
bug fix in repeated dates
b8raoult Sep 18, 2025
9cb1b63
remove python generating code that will be in another PR
b8raoult Sep 21, 2025
5746b04
remove python generating code that will be in another PR
b8raoult Sep 21, 2025
e916035
Merge remote-tracking branch 'origin/main' into feat/refactor-create
b8raoult Sep 21, 2025
e4712f0
remove python generating code that will be in another PR
b8raoult Sep 21, 2025
976c6a4
feat: python recipes
b8raoult Sep 21, 2025
6a3cab8
work on doc
b8raoult Sep 22, 2025
0cc8026
update docs
b8raoult Sep 22, 2025
066d1ce
update docs
b8raoult Sep 22, 2025
423f8a3
update docs
b8raoult Sep 22, 2025
8bfa5d3
update
b8raoult Sep 22, 2025
e4f3ddb
update
b8raoult Sep 22, 2025
83694ef
update
b8raoult Sep 22, 2025
66945f0
Update docs/datasets/building/code/using-python-3.py
b8raoult Sep 23, 2025
e26ce75
add docs
b8raoult Sep 23, 2025
ebdc9a6
Merge remote-tracking branch 'origin/main' into feat/python-recipes
b8raoult Nov 17, 2025
ec4e74c
update
b8raoult Nov 17, 2025
3c0ae14
update with main
b8raoult Nov 17, 2025
26dfbaa
update with main
b8raoult Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ _version.py
*.to_upload
tempCodeRunnerFile.python
Untitled-*.py
*.zip
*.json
*.db
*.tgz
_api/
trace.txt
?/
*.prof
Expand Down
3 changes: 3 additions & 0 deletions docs/building/code/using-python-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()
13 changes: 13 additions & 0 deletions docs/building/code/using-python-10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

r.input = (
(a := r.grib(path="dir1/*.grib"))
& r.grib(path="dir2/*.grib")
& r.forcings(param=["cos_latitude", "sin_latitude"], template=a)
)

r.dump()
14 changes: 14 additions & 0 deletions docs/building/code/using-python-11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

r.input = r.concat(
{
("2023-01-01T00:00:00", "2023-06-30T18:00:00", "12h"): r.grib(path="gribs/*.grib"),
("2023-07-01T00:00:00", "2023-12-31T18:00:00", "12h"): r.netcdf(path="ncdfs/*.nc"),
}
)

r.dump()
249 changes: 249 additions & 0 deletions docs/building/code/using-python-12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
import datetime

from anemoi.datasets.recipe import Recipe

r = Recipe()

r.description = """
This is a complex example of a dataset recipe written in Python.
It uses data from two different ECMWF research experiments for atmospheric and wave data,
from ECMWF's MARS archive. For the atmospheric data, it combines data from two
12-hourly data streams (oper and lwda) to create a dataset with a 6-hourly frequency.
"""

r.name = "aifs-rd-an-oper-ioku-mars-n320-2024-2024-6h-v1"
r.licence = "CC-BY-4.0"
r.attribution = "ECMWF"

start_date = datetime.datetime(2024, 5, 2, 0, 0)
end_date = datetime.datetime(2024, 9, 8, 18, 0)

r.dates = {
"start": start_date,
"end": end_date,
"frequency": "6h",
}

r.build = {"use_grib_paramid": True}
r.statistics = {"allow_nans": True}


grid = "n320"

ioku = {
"class": "rd",
"grid": grid,
"expver": "ioku",
}

ikdi = {
"class": "rd",
"grid": grid,
"expver": "ikdi",
}

accumulations_stream = {
"oper": "lwda",
"lwda": "oper",
}


def accumulations(stream):
return r.accumulations(
levtype="sfc",
param=["cp", "tp", "sf", "strd", "ssrd"],
stream=accumulations_stream[stream],
**ioku,
)


def pressure_levels(stream):
return r.mars(
stream=stream,
level=[
1,
10,
30,
50,
70,
100,
150,
200,
250,
300,
400,
500,
600,
700,
850,
925,
1000,
],
levtype="pl",
param=["t", "u", "v", "w", "z"],
**ioku,
)


def pressure_levels_q(stream):
return r.mars(
levtype="pl",
param=["q"],
level=[50, 100, 150, 200, 250, 300, 400, 500, 600, 700, 850, 925, 1000],
stream=stream,
**ioku,
)


def sfc_fields(stream):
return r.mars(
levtype="sfc",
param=[
"10u",
"10v",
"2d",
"2t",
"lsm",
"msl",
"sdor",
"skt",
"slor",
"tcw",
"z",
# Land parameters below
"stl1",
"stl2",
"tcc",
"mcc",
"hcc",
"lcc",
"100u",
"100v",
],
stream=stream,
**ioku,
)


def surface_pressure(stream):
return (
r.mars(
levtype="ml",
levelist=1,
param="lnsp",
stream=stream,
**ioku,
)
| r.lnsp_to_sp()
)


def apply_mask():
return r.apply_mask(
path="/data/climate.v015/319_3/lsm.grib",
mask_value=0,
)


def land_params(stream):
soil_params = r.mars(
levtype="sfc",
param=["swvl1", "swvl2", "sd"],
stream=stream,
**ioku,
)

snow_cover = (
r.mars(
levtype="sfc",
param=["sd", "rsn"],
stream=stream,
**ioku,
)
| r.snow_cover()
)

run_off = r.accumulations(
levtype="sfc",
param=["ro"],
stream=accumulations_stream[stream],
**ioku,
)

return (soil_params & snow_cover & run_off) | apply_mask()


def constants(template):
return r.constants(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, the constants source is deprecated and says we should use forcings instead. I think this should be updated to be consistent with the other examples/rest of the docs.

param=[
"cos_latitude",
"cos_longitude",
"sin_latitude",
"sin_longitude",
"cos_julian_day",
"cos_local_time",
"sin_julian_day",
"sin_local_time",
"insolation",
],
template=template,
)


def wave_data():
return (
r.mars(
param=[
"swh",
"cdww",
"mwp",
"mwd",
"wmb",
"h1012",
"h1214",
"h1417",
"h1721",
"h2125",
"h2530",
],
stream="wave",
**ikdi,
)
| r.cos_sin_mean_wave_direction()
)


def atmos_data(stream):
return (
(a := sfc_fields(stream))
& surface_pressure(stream)
& pressure_levels(stream)
& pressure_levels_q(stream)
& accumulations(stream)
& land_params(stream)
& constants(template=a)
)


def dates(hour):
s = start_date.replace(hour=hour)
e = end_date.replace(hour=hour + 12)
while s > start_date:
s -= datetime.timedelta(hours=24)
while e < end_date:
e += datetime.timedelta(hours=24)
return (s, e, "12h")


def input_data():
return r.concat(
{
dates(0): atmos_data("oper"),
dates(6): atmos_data("lwda"),
}
)


r.input = input_data() & wave_data()

r.dump()
8 changes: 8 additions & 0 deletions docs/building/code/using-python-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from anemoi.datasets.recipe import Recipe

r = Recipe(
description="Example dataset recipe",
name="example-dataset",
licence="CC-BY-4.0",
attribution="my-organisation",
)
12 changes: 12 additions & 0 deletions docs/building/code/using-python-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.description = """
Example dataset recipe using Python, with attributes set one by one
and a multi-line description.
"""

r.name = "example-dataset"
r.licence = "CC-BY-4.0"
r.attribution = "my-organisation"
22 changes: 22 additions & 0 deletions docs/building/code/using-python-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime

from anemoi.datasets.recipe import Recipe

r = Recipe()

# As a tuple (start, end, frequency)
r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

# As a dictionary
r.dates = {
"start": "2023-01-01T00:00:00",
"end": "2023-12-31T18:00:00",
"frequency": "12h",
}

# You can also provide datetime objects
r.dates = {
"start": datetime(2023, 1, 1, 0, 0),
"end": datetime(2023, 12, 31, 18, 0),
"frequency": "12h",
}
7 changes: 7 additions & 0 deletions docs/building/code/using-python-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

r.input = r.grib(path="data/*.grib") | r.clip(minimum=0, maximum=100)
7 changes: 7 additions & 0 deletions docs/building/code/using-python-6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

r.input = r.grib(path="dir1/*.grib") & r.grib(path="dir2/*.grib")
7 changes: 7 additions & 0 deletions docs/building/code/using-python-7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

r.input = (r.grib(path="dir1/*.grib") & r.grib(path="dir2/*.grib")) | r.clip(minimum=0, maximum=100)
9 changes: 9 additions & 0 deletions docs/building/code/using-python-8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

r.input = (r.grib(path="dir1/*.grib") & r.grib(path="dir2/*.grib")) | r.clip(minimum=0, maximum=100)

r.dump()
13 changes: 13 additions & 0 deletions docs/building/code/using-python-9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from anemoi.datasets.recipe import Recipe

r = Recipe()

r.dates = ("2023-01-01T00:00:00", "2023-12-31T18:00:00", "12h")

a = r.grib(path="dir1/*.grib")
b = r.grib(path="dir2/*.grib")
c = r.forcings(param=["cos_latitude", "sin_latitude"], template=a)

r.input = a & b & c

r.dump()
Loading
Loading