-
Notifications
You must be signed in to change notification settings - Fork 45
feat: refactor dataset create #379
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
Merged
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
9cb8c52
feat: recipe generator
b8raoult 01774dd
update
b8raoult 33793a6
update
b8raoult 920d523
update
b8raoult ed5d190
update
b8raoult 2562baf
fix: better handling of xarray metadata
b8raoult f048a4b
update
b8raoult 8ad5eb0
update
b8raoult 5db7a97
Merge branch 'fix/better-handling-of-xarray-metadata' into feat/recip…
b8raoult b33f3ac
fix: support other keys that param in rename filter
b8raoult 71d8180
Merge branch 'fix/support-other-keys-than-param-in-rename-filter' int…
b8raoult 6d23027
typo
b8raoult 6933574
Merge branch 'fix/support-other-keys-than-param-in-rename-filter' int…
b8raoult 9179dae
add command line
b8raoult 79a391b
update
b8raoult 203e09b
update
b8raoult b4433bd
update
b8raoult 6f3fdb0
update
b8raoult 45365a1
upadte
b8raoult d7cc82c
update
b8raoult f381b00
update
b8raoult da93ad6
update
b8raoult 3082edf
refactor missing
b8raoult ef4a5c9
add references
b8raoult 93410d5
refactor
b8raoult 1df0ef7
refactor
b8raoult 18df4eb
refactor
b8raoult 3341d4c
update
b8raoult 58dc8a2
work on migrate
b8raoult 3e180f9
work on migrate
b8raoult 255c22d
merge
b8raoult 83936f7
merge
b8raoult 5209f26
update
b8raoult c7a0e5d
update
b8raoult b78a098
update
b8raoult d641ea7
update
b8raoult 3754eb2
update
b8raoult 39ebc13
update
b8raoult 5d32745
update
b8raoult 6c1f146
update
b8raoult 37de369
update
b8raoult 24f2c2a
update
b8raoult db4d895
add dumper
b8raoult 55f740d
update
b8raoult 014dbbc
update
b8raoult 8ad9396
bug fix in path
b8raoult 9756618
join recipe command
b8raoult a493a96
join recipe command
b8raoult 1cde9f8
use ampersand
b8raoult cdb1a9a
use ampersand
b8raoult e69eb10
add settings
b8raoult 92165b4
add settings
b8raoult a044e14
udpate
b8raoult cb9c576
use ruamel
b8raoult 99a5fb7
fix source as parameters
b8raoult ce027f4
update
b8raoult 3bf7c35
Merge branch 'feat/refactor-create' of github.com:ecmwf/anemoi-datase…
b8raoult 96dfe3d
Merge branch 'feat/recipe-generator' into feat/refactor-create
b8raoult f68a11e
Merge remote-tracking branch 'origin/main' into feat/refactor-create
b8raoult 3d5f0ef
tidy
b8raoult 70272f6
update
b8raoult 38ced18
update tests
b8raoult cb3847e
fix tests
b8raoult 00477c9
add missing package
b8raoult 839a077
Merge branch 'main' into feat/refactor-create
floriankrb 619c416
remove unsused file
b8raoult 21321cb
Update copyright year
mchantry 90e21ee
Fix copyright header
mchantry fa35755
bug fix in repeated dates
b8raoult 2fc4189
bug fix in repeated dates
b8raoult 9cb1b63
remove python generating code that will be in another PR
b8raoult 5746b04
remove python generating code that will be in another PR
b8raoult e916035
Merge remote-tracking branch 'origin/main' into feat/refactor-create
b8raoult e4712f0
remove python generating code that will be in another PR
b8raoult ba1edd8
Update config.py
mchantry 6f5f308
Update src/anemoi/datasets/create/input/action.py
mchantry 07c67b2
Update src/anemoi/datasets/create/input/action.py
mchantry a06c682
Document classes
b8raoult 218c75b
Update src/anemoi/datasets/create/input/__init__.py
b8raoult b1ca566
Update src/anemoi/datasets/create/input/context/__init__.py
b8raoult 6d3a320
Update src/anemoi/datasets/create/input/context/__init__.py
b8raoult 1543ec6
Update src/anemoi/datasets/create/input/context/__init__.py
b8raoult a9535f8
Update src/anemoi/datasets/create/sources/legacy.py
b8raoult 60aa759
typo
b8raoult 4beb151
Update pyproject.toml
b8raoult 5de2b08
Update src/anemoi/datasets/commands/copy.py
b8raoult baf85bd
Update src/anemoi/datasets/commands/copy.py
b8raoult 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,93 @@ | ||
# (C) Copyright 2024 Anemoi contributors. | ||
# | ||
# 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. | ||
|
||
|
||
import argparse | ||
import logging | ||
import sys | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
from anemoi.datasets.create import validate_config | ||
|
||
from .. import Command | ||
from .format import format_recipe | ||
from .migrate import migrate_recipe | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Recipe(Command): | ||
def add_arguments(self, command_parser: Any) -> None: | ||
"""Add arguments to the command parser. | ||
|
||
Parameters | ||
---------- | ||
command_parser : Any | ||
Command parser object. | ||
""" | ||
|
||
command_parser.add_argument("--validate", action="store_true", help="Validate recipe.") | ||
command_parser.add_argument("--format", action="store_true", help="Format the recipe.") | ||
command_parser.add_argument("--migrate", action="store_true", help="Migrate the recipe to the latest version.") | ||
|
||
group = command_parser.add_mutually_exclusive_group() | ||
group.add_argument("--inplace", action="store_true", help="Overwrite the recipe file in place.") | ||
group.add_argument("--output", type=str, help="Output file path for the converted recipe.") | ||
|
||
command_parser.add_argument( | ||
"path", | ||
help="Path to recipe.", | ||
) | ||
|
||
def run(self, args: Any) -> None: | ||
|
||
if not args.validate and not args.format and not args.migrate: | ||
args.validate = True | ||
|
||
with open(args.path) as file: | ||
config = yaml.safe_load(file) | ||
|
||
assert isinstance(config, dict) | ||
|
||
if args.validate: | ||
if args.inplace and (not args.format and not args.migrate): | ||
argparse.ArgumentError(None, "--inplace is not supported with --validate.") | ||
|
||
if args.output and (not args.format and not args.migrate): | ||
argparse.ArgumentError(None, "--output is not supported with --validate.") | ||
|
||
validate_config(config) | ||
LOG.info(f"{args.path}: Recipe is valid.") | ||
return | ||
|
||
if args.migrate: | ||
config = migrate_recipe(args, config) | ||
if config is None: | ||
LOG.info(f"{args.path}: No changes needed.") | ||
return | ||
|
||
args.format = True | ||
|
||
if args.format: | ||
formatted = format_recipe(args, config) | ||
assert "dates" in formatted | ||
f = sys.stdout | ||
if args.output: | ||
f = open(args.output, "w") | ||
|
||
if args.inplace: | ||
f = open(args.path, "w") | ||
|
||
print(formatted, file=f) | ||
f.close() | ||
|
||
|
||
command = Recipe |
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,55 @@ | ||
# (C) Copyright 2025 Anemoi contributors. | ||
# | ||
# 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. | ||
|
||
|
||
import datetime | ||
import logging | ||
|
||
from ...dumper import yaml_dump | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def make_dates(config): | ||
if isinstance(config, dict): | ||
return {k: make_dates(v) for k, v in config.items()} | ||
if isinstance(config, list): | ||
return [make_dates(v) for v in config] | ||
if isinstance(config, str): | ||
try: | ||
return datetime.datetime.fromisoformat(config) | ||
except ValueError: | ||
return config | ||
return config | ||
|
||
|
||
ORDER = ( | ||
aaron-hopkinson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"name", | ||
"description", | ||
"dataset_status", | ||
"licence", | ||
"attribution", | ||
"env", | ||
"dates", | ||
"common", | ||
"data_sources", | ||
"input", | ||
"output", | ||
"statistics", | ||
"build", | ||
"platform", | ||
) | ||
|
||
|
||
def format_recipe(args, config: dict) -> str: | ||
|
||
config = make_dates(config) | ||
assert config | ||
|
||
return yaml_dump(config, order=ORDER) | ||
aaron-hopkinson marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
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.