-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/rename_condition_to_state
- Loading branch information
Showing
8 changed files
with
309 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,50 @@ | ||
#!/usr/bin/env python | ||
# (C) Copyright 2024 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 anemoi.utils.grib import shortname_to_paramid | ||
|
||
from ..checkpoint import Checkpoint | ||
from . import Command | ||
|
||
|
||
class RequestCmd(Command): | ||
"""Inspect the contents of a checkpoint file.""" | ||
|
||
need_logging = False | ||
|
||
def add_arguments(self, command_parser): | ||
command_parser.description = self.__doc__ | ||
command_parser.add_argument("--mars", action="store_true", help="Print the MARS request.") | ||
command_parser.add_argument("--use-grib-paramid", action="store_true", help="Use paramId instead of param.") | ||
command_parser.add_argument("path", help="Path to the checkpoint.") | ||
|
||
def run(self, args): | ||
|
||
c = Checkpoint(args.path) | ||
|
||
for r in c.mars_requests(use_grib_paramid=args.use_grib_paramid): | ||
if args.mars: | ||
req = ["retrieve,target=data"] | ||
for k, v in r.items(): | ||
|
||
if args.use_grib_paramid and k == "param": | ||
if not isinstance(v, (list, tuple)): | ||
v = [v] | ||
v = [shortname_to_paramid(x) for x in v] | ||
|
||
if isinstance(v, (list, tuple)): | ||
v = "/".join([str(x) for x in v]) | ||
req.append(f"{k}={v}") | ||
r = ",".join(req) | ||
print(r) | ||
|
||
|
||
command = RequestCmd |
This file contains 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,77 @@ | ||
#!/usr/bin/env python | ||
# (C) Copyright 2024 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. | ||
# | ||
|
||
|
||
import datetime | ||
import logging | ||
|
||
from anemoi.utils.dates import as_datetime | ||
|
||
from ..runner import DefaultRunner | ||
from . import Command | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class RunCmd(Command): | ||
"""Inspect the contents of a checkpoint file.""" | ||
|
||
need_logging = False | ||
|
||
def add_arguments(self, command_parser): | ||
command_parser.description = self.__doc__ | ||
command_parser.add_argument("--use-grib-paramid", action="store_true", help="Use paramId instead of param.") | ||
command_parser.add_argument("--date", help="Date to use for the request.") | ||
command_parser.add_argument("path", help="Path to the checkpoint.") | ||
|
||
def run(self, args): | ||
import earthkit.data as ekd | ||
|
||
runner = DefaultRunner(args.path) | ||
|
||
date = as_datetime(args.date) | ||
dates = [date + datetime.timedelta(hours=h) for h in runner.lagged] | ||
|
||
print("------------------------------------") | ||
for n in runner.checkpoint.mars_requests( | ||
dates=dates[0], | ||
expver="0001", | ||
use_grib_paramid=False, | ||
): | ||
print("MARS", n) | ||
print("------------------------------------") | ||
|
||
requests = runner.checkpoint.mars_requests( | ||
dates=dates, | ||
expver="0001", | ||
use_grib_paramid=args.use_grib_paramid, | ||
) | ||
|
||
input_fields = ekd.from_source("empty") | ||
for r in requests: | ||
if r["class"] == "rd": | ||
r["class"] = "od" | ||
|
||
r["grid"] = runner.checkpoint.grid | ||
r["area"] = runner.checkpoint.area | ||
|
||
print("MARS", r) | ||
|
||
input_fields += ekd.from_source("mars", r) | ||
|
||
LOGGER.info("Running the model with the following %s fields, for %s dates", len(input_fields), len(dates)) | ||
|
||
run = runner.make_runner(input_fields=input_fields, lead_time=240, device="cuda") | ||
run.run() | ||
|
||
runner.run(input_fields=input_fields, lead_time=244, device="cuda") | ||
|
||
|
||
command = RunCmd |
Oops, something went wrong.