-
Notifications
You must be signed in to change notification settings - Fork 24
feat: Add entrypoint for anemoi-datasets to PyEarthTools #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tennlee
merged 6 commits into
ACCESS-Community-Hub:develop
from
HCookie:feat/add-entrypoint-for-anemoi
Nov 17, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
01d0799
feat: Add entrypoint for anemoi-datasets to PyEarthTools
HCookie 34154e8
Fix indent
HCookie 175e3a2
Allow usage of pipeline directly
HCookie bd79859
Add ECMWF License
HCookie 59dbbfd
Merge branch 'develop' into feat/add-entrypoint-for-anemoi
HCookie 413733b
Apply suggestions from code review
HCookie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Pipeline Entrypoints | ||
|
|
||
| As `PyEarthTools` pipelines propose a generic way to load and prepare various earth system datasets, it is possible to use | ||
| a pipeline as a source for [anemoi-datasets](https://anemoi.readthedocs.io/projects/datasets/en/latest/). | ||
|
|
||
| ## Example | ||
|
|
||
| Below is a minimal example of using a `PyEarthTools` pipeline to load data and prepare it for `anemoi`, please see the `anemoi` docs | ||
| for more information on the `datasets` config. | ||
|
|
||
| ### Create the Pipeline in PyEarthTools | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| import pyearthtools.data | ||
| import pyearthtools.pipeline | ||
|
|
||
| pipeline = pyearthtools.pipeline.Pipeline( | ||
| pyearthtools.data.download.arcoera5.ARCOERA5(['t2m', 'u10', 'v10']), | ||
| pyearthtools.pipeline.operations.xarray.values.FillNan() | ||
| ) | ||
| pipeline.save('/PATH/TO/PIPELINE.yaml') | ||
|
|
||
| ### Create the anemoi-datasets config | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| name: pyearthtools_to_anemoi | ||
| description: PyEarthTools Pipeline converted to Anemoi | ||
| attribution: PyEarthTools | ||
|
|
||
| dates: | ||
| start: '2025-11-10T00:00:00' | ||
| end: '2025-11-12T00:00:00' | ||
| frequency: 1h | ||
|
|
||
| input: | ||
| pyearthtools: # Use the pyearthtools input object | ||
| pipeline: /PATH/TO/PIPELINE.yaml | ||
|
|
||
| ### Run anemoi-datasets | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| anemoi-datasets create /path/to/anemoi/dataset.yaml | ||
|
|
||
| ## Function Contract | ||
|
|
||
| The expected contract and result from the `PyEarthTools` pipeline is to return an `xarray` object of a single time index. | ||
|
|
||
| Both tools provide methods to modify the metadata of the data, and should be used accordingly to prepare for downstream uses. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/pipeline/src/pyearthtools/pipeline/entrypoints/anemoi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # (C) Copyright 2025- European Centre for Medium-Range Weather Forecasts (ECMWF) | ||
|
|
||
| # This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # In applying this licence, ECMWF does not waive the privileges and immunities | ||
| # granted to it by virtue of its status as an intergovernmental organisation nor | ||
| # does it submit to any jurisdiction. | ||
|
|
||
|
|
||
| from functools import cached_property | ||
| from pathlib import Path | ||
|
|
||
| from pyearthtools.pipeline import load | ||
| from pyearthtools.pipeline import Pipeline | ||
|
|
||
| import earthkit.data as ekd | ||
| from anemoi.datasets.create.source import Source | ||
| from anemoi.datasets.create.typing import DateList | ||
|
|
||
|
|
||
| class pyearthtoolsSource(Source): | ||
| emoji = "🌏" # For tracing | ||
|
|
||
| def __init__(self, context, pipeline: str | Path | Pipeline): | ||
| """Initialise the source. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| context : Any | ||
| The context for the data source. | ||
| pipeline: str | ||
| The path to the pyearthtools pipeline file. | ||
| """ | ||
| super().__init__(context) | ||
| self._pyearthtools_pipeline = pipeline | ||
|
|
||
| @cached_property | ||
| def pipeline(self) -> Pipeline: | ||
| pipeline = self._pyearthtools_pipeline | ||
| if isinstance(pipeline, Pipeline): | ||
| return pipeline | ||
| return load(pipeline) | ||
|
|
||
| def execute(self, dates: DateList) -> ekd.FieldList: | ||
| """Execute the source. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dates : DateList | ||
| The input dates. | ||
|
|
||
| Returns | ||
| ------- | ||
| ekd.FieldList | ||
| The output data. | ||
| """ | ||
| fields = [] | ||
| for date in dates: | ||
| fields.extend(ekd.from_object(self.pipeline[date.isoformat()])) # type: ignore | ||
| return ekd.FieldList.from_fields(fields) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.