Skip to content

Commit

Permalink
Updated to sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Manning committed Nov 28, 2023
2 parents 5618cfe + 3a2c1fe commit dc5017d
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 33 deletions.
39 changes: 24 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,46 @@ on: [ push, pull_request ]
jobs:
build:

name: Conda Build with Python${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
run: |
sudo apt-get -y install pandoc
if: matrix.python-version == 3.8
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
if: matrix.python-version == 3.9
- name: Setup Conda (Micromamba) with Python${{ matrix.python-version }}
uses: mamba-org/setup-micromamba@v1
with:
python-version: ${{ matrix.python-version }}
cache-downloads: true
cache-environment: true
environment-file: environment.yml
create-args: >-
conda
python=${{ matrix.python-version }}
- name: Conda and Mamba versions
run: |
conda --version
echo "micromamba: $(micromamba --version)"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# pip install flake8 black pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install --no-user --editable "."
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
# pip install the package, command-line unit tests work
pip install --no-deps -e .
- name: Lint with flake8
run: make lint
if: matrix.python-version == 3.8
if: matrix.python-version == 3.9
# - name: Check formatting with black
# run: black --check --target-version py38 daops tests
# if: matrix.python-version == 3.8
# run: black --check --target-version py39 daops tests
# if: matrix.python-version == 3.9
- name: Test with pytest
run: |
python -m pytest -v tests
- name: Build docs 🏗️
run: make docs
if: matrix.python-version == 3.8
if: matrix.python-version == 3.9
13 changes: 13 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Version History
===============

v0.10.0 (2023-11-27)
-------------------

Breaking Changes
^^^^^^^^^^^^^^^^
* ``clisops``>=0.12.0 required.

New Features
^^^^^^^^^^^^

* Added regridding operator (#111)


v0.9.0 (2023-11-17)
-------------------

Expand Down
3 changes: 1 addition & 2 deletions daops/__init__.py
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

Expand Down
80 changes: 80 additions & 0 deletions daops/ops/regrid.py
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
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# daops documentation build configuration file, created by
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
Expand Down Expand Up @@ -74,7 +73,7 @@
# the built documents.
#
# The short X.Y version.
version = "0.9.0"
version = "0.10.0"
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
19 changes: 10 additions & 9 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ channels:
- defaults
dependencies:
- pip
- numpy>=1.16
- xarray>=2023.7.0
- numpy >=1.16
- xarray >=0.21,<2023.3.0 # https://github.com/pydata/xarray/issues/7794
- dask
- netcdf4
- clisops>=0.10.0
- clisops >=0.12.0
- roocs-grids >=0.1.2
- xesmf >=0.8.2
- elasticsearch>=7.9.1
# - roocs-utils>=0.6.2
- roocs-utils>=0.6.2
# logging
- loguru>=0.5.3
- loguru >=0.5.3
# catalog
- intake
# to support kerchunk
- fsspec==2022.11.0
- fsspec
- aiohttp
- zstd
- pip:
- git+https://github.com/roocs/roocs-utils.git@i106-enable-read-kerchunk#egg=roocs_utils
- zarr==2.13.3
- zstandard
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ dask[complete]
cftime
netcdf4
elasticsearch>=8.0.1
clisops>=0.10.0
roocs-utils>=0.6.2
clisops>=0.12.0
## clisops @ git+https://github.com/roocs/clisops.git@master#egg=clisops
roocs-utils>=0.6.4
roocs_grids>=0.1.2
# logging
loguru>=0.5.3
# catalog
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
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

Expand Down
3 changes: 1 addition & 2 deletions setup.py
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
Expand Down
36 changes: 36 additions & 0 deletions tests/test_operations/test_regrid.py
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

0 comments on commit dc5017d

Please sign in to comment.