-
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
5 changed files
with
210 additions
and
64 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 |
---|---|---|
|
@@ -47,6 +47,7 @@ dependencies = [ | |
"multiurl", | ||
"gputil", | ||
"earthkit-meteo", | ||
"earthkit-regrid", | ||
"pyyaml", | ||
"tqdm", | ||
] | ||
|
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,33 @@ | ||
# (C) Copyright 2024 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 earthkit.data.indexing.fieldlist import FieldArray | ||
|
||
from .transform import NewDataField | ||
from .transform import NewMetadataField | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def make_z_from_gh(previous): | ||
g = 9.80665 # Same a pgen | ||
|
||
def _proc(ds): | ||
|
||
ds = previous(ds) | ||
|
||
result = [] | ||
for f in ds: | ||
if f.metadata("param") == "gh": | ||
result.append(NewMetadataField(NewDataField(f, f.to_numpy() * g), param="z")) | ||
else: | ||
result.append(f) | ||
return FieldArray(result) | ||
|
||
return _proc |
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,28 @@ | ||
# (C) Copyright 2024 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.regrid as ekr | ||
from earthkit.data.indexing.fieldlist import FieldArray | ||
|
||
from .transform import NewDataField | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Interpolate: | ||
def __init__(self, grid, source): | ||
self.grid = list(grid) if isinstance(grid, tuple) else grid | ||
self.source = list(source) if isinstance(source, tuple) else source | ||
|
||
def __call__(self, ds): | ||
result = [] | ||
for f in ds: | ||
data = ekr.interpolate(f.to_numpy(), dict(grid=self.source), dict(grid=self.grid)) | ||
result.append(NewDataField(f, data)) | ||
return FieldArray(result) |
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,47 @@ | ||
# (C) Copyright 2024 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 | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class NewDataField: | ||
def __init__(self, field, data): | ||
self._field = field | ||
self._data = data | ||
|
||
def to_numpy(self, flatten=False, dtype=None, index=None): | ||
data = self._data | ||
if dtype is not None: | ||
data = data.astype(dtype) | ||
if flatten: | ||
data = data.flatten() | ||
return data | ||
|
||
def __getattr__(self, name): | ||
return getattr(self._field, name) | ||
|
||
def __repr__(self) -> str: | ||
return repr(self._field) | ||
|
||
|
||
class NewMetadataField: | ||
def __init__(self, field, **kwargs): | ||
self._field = field | ||
self._metadata = kwargs | ||
|
||
def __getattr__(self, name): | ||
return getattr(self._field, name) | ||
|
||
def __repr__(self) -> str: | ||
return repr(self._field) | ||
|
||
def metadata(self, name, **kwargs): | ||
if name in self._metadata: | ||
return self._metadata[name] | ||
return self._field.metadata(name, **kwargs) |