-
Notifications
You must be signed in to change notification settings - Fork 7
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
10 changed files
with
171 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Top-level package for daops. | ||
daops - Dataset-Aware Operations""" | ||
|
||
__author__ = """Elle Smith""" | ||
__contact__ = "[email protected]" | ||
__copyright__ = "Copyright 2018 United Kingdom Research and Innovation" | ||
__license__ = "BSD" | ||
__version__ = "0.9.0" | ||
__version__ = "0.10.0" | ||
|
||
from loguru import logger | ||
|
||
|
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,80 @@ | ||
from clisops.ops.regrid import regrid as clisops_regrid | ||
from roocs_utils.parameter import collection_parameter | ||
from roocs_utils.parameter import dimension_parameter | ||
|
||
from daops.ops.base import Operation | ||
|
||
__all__ = [ | ||
"regrid", | ||
] | ||
|
||
|
||
class Regrid(Operation): | ||
def _resolve_params(self, collection, **params): | ||
""" | ||
Resolve the input parameters to `self.params` and parameterise | ||
collection parameter and set to `self.collection`. | ||
""" | ||
# need to verify method, grid and adaptive masking threshold are correct format - parameters? | ||
collection = collection_parameter.CollectionParameter(collection) | ||
|
||
self.collection = collection | ||
self.params = { | ||
"method": params.get("method"), | ||
"adaptive_masking_threshold": params.get("adaptive_masking_threshold"), | ||
"grid": params.get("grid"), | ||
} | ||
|
||
def get_operation_callable(self): | ||
return clisops_regrid | ||
|
||
|
||
def regrid( | ||
collection, | ||
method="nn", | ||
adaptive_masking_threshold=0.5, | ||
grid="1deg", | ||
output_dir=None, | ||
output_type="netcdf", | ||
split_method="time:auto", | ||
file_namer="standard", | ||
apply_fixes=True, | ||
): | ||
""" | ||
Regrid input dataset according to specified method and output grid. | ||
The adaptive masking threshold can also be specified. | ||
Parameters | ||
---------- | ||
collection: Collection of datasets to process, sequence or string of comma separated dataset identifiers. | ||
method: The method by which to regrid. | ||
adaptive_masking_threshold: | ||
grid: The desired output grid. | ||
output_dir: str or path like object describing output directory for output files. | ||
output_type: {"netcdf", "nc", "zarr", "xarray"} | ||
split_method: {"time:auto"} | ||
file_namer: {"standard", "simple"} | ||
apply_fixes: Boolean. If True fixes will be applied to datasets if needed. Default is True. | ||
Returns | ||
------- | ||
List of outputs in the selected type: a list of xarray Datasets or file paths. | ||
Examples | ||
-------- | ||
| collection: ("cmip6.ukesm1.r1.gn.tasmax.v20200101",) | ||
| method: "nn" | ||
| adaptive_masking_threshold: 0.5 | ||
| grid: "1deg" | ||
| output_type: "netcdf" | ||
| output_dir: "/cache/wps/procs/req0111" | ||
| split_method: "time:auto" | ||
| file_namer: "standard" | ||
| apply_fixes: True | ||
""" | ||
|
||
result_set = Regrid(**locals()).calculate() | ||
|
||
return result_set |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.9.0 | ||
current_version = 0.10.0 | ||
commit = True | ||
tag = True | ||
|
||
|
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
"""The setup script.""" | ||
|
||
__author__ = """Elle Smith""" | ||
__contact__ = "[email protected]" | ||
__copyright__ = "Copyright 2018 United Kingdom Research and Innovation" | ||
__license__ = "BSD" | ||
__version__ = "0.9.0" | ||
__version__ = "0.10.0" | ||
|
||
import os | ||
from setuptools import setup, find_packages | ||
|
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,36 @@ | ||
import os | ||
|
||
import pytest | ||
import xarray as xr | ||
|
||
|
||
# from daops.ops.regrid import regrid | ||
|
||
# TODO: remove when upgraded to new clisops version | ||
# pytestmark = pytest.mark.xfail(reason="needs clisops>=0.12 with regrid operator") | ||
|
||
CMIP6_IDS = ["CMIP6.CMIP.MPI-M.MPI-ESM1-2-HR.historical.r1i1p1f1.Omon.tos.gn.v20190710"] | ||
|
||
|
||
def _check_output_nc(result, fname="output_001.nc"): | ||
assert fname in [os.path.basename(_) for _ in result.file_uris] | ||
|
||
|
||
@pytest.mark.online | ||
def test_regrid(tmpdir, load_esgf_test_data): | ||
from daops.ops.regrid import regrid | ||
|
||
result = regrid( | ||
CMIP6_IDS[0], | ||
method="conservative", | ||
adaptive_masking_threshold=0.5, | ||
grid="1deg", | ||
output_dir=tmpdir, | ||
file_namer="simple", | ||
apply_fixes=False, | ||
) | ||
|
||
_check_output_nc(result) | ||
ds = xr.open_dataset(result.file_uris[0], use_cftime=True) | ||
assert "time" in ds.dims | ||
assert "tos" in ds |