Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ecmwf/anemoi-inference into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed May 26, 2024
2 parents da245e7 + 8e9d712 commit a240885
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ classifiers = [
"Operating System :: OS Independent",
]

dependencies = ["anemoi-utils"]
dependencies = ["anemoi-utils", "semantic-version"]

[project.optional-dependencies]

Expand Down
2 changes: 1 addition & 1 deletion src/anemoi/inference/checkpoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _checkpoint_metadata(self, name):
@cached_property
def operational_config(self):
try:
result = self._checkpoint_metadata("operational-config.json")
result = load_metadata(self.path, "operational-config.json")
LOG.info(f"Using operational configuration from checkpoint {self.path}")
return result
except ValueError:
Expand Down
7 changes: 7 additions & 0 deletions src/anemoi/inference/checkpoint/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Metadata:
def __init__(self, metadata):
self._metadata = metadata

def to_dict(self):
return self._metadata

@classmethod
def from_metadata(cls, metadata):
if isinstance(metadata["dataset"], list):
Expand Down Expand Up @@ -292,6 +295,10 @@ def prognostic_params(self):
return [self.index_to_variable[i] for i in self._indices["data"]["input"]["prognostic"]]

###########################################################################
@cached_property
def precision(self):
return self._config_training["precision"]

@cached_property
def multi_step(self):
return self._config_training["multistep_input"]
Expand Down
12 changes: 8 additions & 4 deletions src/anemoi/inference/commands/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#


import json

from ..checkpoint import Checkpoint
from . import Command

Expand All @@ -18,11 +20,15 @@ class CheckpointCmd(Command):
need_logging = False

def add_arguments(self, command_parser):
command_parser.add_argument("--json", action="store_true", help="Output in JSON format")
command_parser.add_argument("path", help="Path to the checkpoint.")

def run(self, args):

c = Checkpoint(args.path)
if args.json:
print(json.dumps(c.to_dict(), indent=4, sort_keys=True))
return

print("area:", c.area)
print("computed_constants:", c.computed_constants)
Expand All @@ -39,6 +45,7 @@ def run(self, args):
print("from_metadata:", c.from_metadata)
print("grid:", c.grid)
print("hour_steps:", c.hour_steps)
print("imputable variables", c.imputable_variables)
print("imputable variables:", c.imputable_variables)
print("imputable_variables:", c.imputable_variables)
print("index_to_variable:", c.index_to_variable)
Expand All @@ -50,6 +57,7 @@ def run(self, args):
print("param_level_ml:", c.param_level_ml)
print("param_level_pl:", c.param_level_pl)
print("param_sfc:", c.param_sfc)
print("precision", c.precision)
print("prognostic_data_input_mask:", c.prognostic_data_input_mask)
print("prognostic_input_mask:", c.prognostic_input_mask)
print("prognostic_output_mask:", c.prognostic_output_mask)
Expand All @@ -59,10 +67,6 @@ def run(self, args):
print("select:", c.select)
print("variable_to_index:", c.variable_to_index)
print("variables:", c.variables)
print()
result = list(range(0, c.multi_step))
result = [-s * c.hour_steps for s in result]
print(sorted(result))


command = CheckpointCmd
Loading

0 comments on commit a240885

Please sign in to comment.