-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
357 additions
and
191 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,3 +177,4 @@ bar | |
dev/ | ||
*.out | ||
_version.py | ||
*.tar |
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,100 @@ | ||
# (C) Copyright 2023 European Centre for Medium-Range Weather Forecasts. | ||
# 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 logging | ||
from functools import cached_property | ||
|
||
import earthkit.data as ekd | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class RequestBasedInput: | ||
def __init__(self, owner, **kwargs): | ||
self.owner = owner | ||
|
||
def _patch(self, **kargs): | ||
r = dict(**kargs) | ||
self.owner.patch_retrieve_request(r) | ||
return r | ||
|
||
@cached_property | ||
def fields_sfc(self): | ||
param = self.owner.param_sfc | ||
if not param: | ||
return ekd.from_source("empty") | ||
|
||
LOG.info(f"Loading surface fields from {self.WHERE}") | ||
|
||
return ekd.from_source( | ||
"multi", | ||
[ | ||
self.sfc_load_source( | ||
**self._patch( | ||
date=date, | ||
time=time, | ||
param=param, | ||
grid=self.owner.grid, | ||
area=self.owner.area, | ||
**self.owner.retrieve, | ||
) | ||
) | ||
for date, time in self.owner.datetimes() | ||
], | ||
) | ||
|
||
@cached_property | ||
def fields_pl(self): | ||
param, level = self.owner.param_level_pl | ||
if not (param and level): | ||
return ekd.from_source("empty") | ||
|
||
LOG.info(f"Loading pressure fields from {self.WHERE}") | ||
return ekd.from_source( | ||
"multi", | ||
[ | ||
self.pl_load_source( | ||
**self._patch( | ||
date=date, | ||
time=time, | ||
param=param, | ||
level=level, | ||
grid=self.owner.grid, | ||
area=self.owner.area, | ||
) | ||
) | ||
for date, time in self.owner.datetimes() | ||
], | ||
) | ||
|
||
@cached_property | ||
def fields_ml(self): | ||
param, level = self.owner.param_level_ml | ||
if not (param and level): | ||
return ekd.from_source("empty") | ||
|
||
LOG.info(f"Loading model fields from {self.WHERE}") | ||
return ekd.from_source( | ||
"multi", | ||
[ | ||
self.ml_load_source( | ||
**self._patch( | ||
date=date, | ||
time=time, | ||
param=param, | ||
level=level, | ||
grid=self.owner.grid, | ||
area=self.owner.area, | ||
) | ||
) | ||
for date, time in self.owner.datetimes() | ||
], | ||
) | ||
|
||
@cached_property | ||
def all_fields(self): | ||
return self.fields_sfc + self.fields_pl + self.fields_ml |
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,29 @@ | ||
# (C) Copyright 2023 European Centre for Medium-Range Weather Forecasts. | ||
# 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 logging | ||
|
||
import earthkit.data as ekd | ||
|
||
from .base import RequestBasedInput | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class CdsInput(RequestBasedInput): | ||
WHERE = "CDS" | ||
|
||
def pl_load_source(self, **kwargs): | ||
kwargs["product_type"] = "reanalysis" | ||
return ekd.from_source("cds", "reanalysis-era5-pressure-levels", kwargs) | ||
|
||
def sfc_load_source(self, **kwargs): | ||
kwargs["product_type"] = "reanalysis" | ||
return ekd.from_source("cds", "reanalysis-era5-single-levels", kwargs) | ||
|
||
def ml_load_source(self, **kwargs): | ||
raise NotImplementedError("CDS does not support model levels") |
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,47 @@ | ||
# (C) Copyright 2023 European Centre for Medium-Range Weather Forecasts. | ||
# 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 logging | ||
from functools import cached_property | ||
|
||
import earthkit.data as ekd | ||
import entrypoints | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class FileInput: | ||
def __init__(self, owner, file, **kwargs): | ||
self.file = file | ||
self.owner = owner | ||
|
||
@cached_property | ||
def fields_sfc(self): | ||
return self.all_fields.sel(levtype="sfc") | ||
|
||
@cached_property | ||
def fields_pl(self): | ||
return self.all_fields.sel(levtype="pl") | ||
|
||
@cached_property | ||
def fields_ml(self): | ||
return self.all_fields.sel(levtype="ml") | ||
|
||
@cached_property | ||
def all_fields(self): | ||
return ekd.from_source("file", self.file) | ||
|
||
|
||
def get_input(name, *args, **kwargs): | ||
return available_inputs()[name].load()(*args, **kwargs) | ||
|
||
|
||
def available_inputs(): | ||
result = {} | ||
for e in entrypoints.get_group_all("ai_models.input"): | ||
result[e.name] = e | ||
return result |
Oops, something went wrong.