Skip to content

Commit

Permalink
Merge pull request #342 from roocs/regrid_masks_and_fixes
Browse files Browse the repository at this point in the history
Regridding masks, robustness of dataset_utils functions and bug fixes
  • Loading branch information
Zeitsperre authored Nov 4, 2024
2 parents 20d6403 + 293bde5 commit 60892b8
Show file tree
Hide file tree
Showing 23 changed files with 3,449 additions and 1,472 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ concurrency:

env:
ESGF_TEST_DATA_VERSION: v1
XCLIM_TEST_DATA_VERSION: v2024.8.23

permissions:
contents: read
Expand Down Expand Up @@ -50,7 +51,7 @@ jobs:
name: Python${{ matrix.python-version }} (PyPI + Tox)
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 30
strategy:
matrix:
include:
Expand Down Expand Up @@ -94,7 +95,7 @@ jobs:
name: Python${{ matrix.python-version }} (Anaconda, upstream=${{ matrix.upstream }})
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -140,9 +141,10 @@ jobs:
run: |
micromamba list
python -m pip check || true
pip install pytest-timeout
- name: Test with conda
run: |
python -m pytest --numprocesses=logical --durations=10 --cov=clisops --cov-report=term-missing
python -m pytest -m "not slow" --timeout=180 --durations=10 --cov=clisops --cov-report=term-missing
finish:
needs:
Expand Down
41 changes: 41 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
Version History
===============

v0.14.1 (unreleased)
--------------------

New Features
^^^^^^^^^^^^
* Added new methods to `clisops.core.regrid.Grid`
* Added possibility to apply land or ocean mask if present in the file
* Adapted method from ESMF to detect smashed cells
* Masking degenerate (i.e. collapsed and smashed) cells
* Dropping lat/lon bounds if an integrity check fails
* Added a few attributes to the `Grid` object
* `clisops.ops.regrid`: added option to request a land/sea mask for the output grid
* `clisops.utils.dataset_utils`
* Added function `determine_lon_lat_range` to determine the min. and max. lat and lon values
* Added function `fix_unmasked_missing_values_lon_lat` to identify and mask yet unmasked missing values in lat and lon arrays
* Added `force` parameter to `cf_convert_between_lon_frames`

Bug Fixes
^^^^^^^^^
* `clisops.utils.dataset_utils`
* Fixed issue in `cf_convert_between_lon_frames` causing the longitude frame to not be adjusted in case of NaNs in the longitude array
* Addressed issues in `generate_bounds_curvilinear`
* latitudes are now clipped above 90 or below -90 degrees north
* longitudes are converted to longitude frame -180, 180
* longitude bounds are adjusted at the Greenwich meridian or anti meridian to avoid grid cells wrapping once or more times around the globe
* Bounds are generated significantly faster due to making use of index slicing and `numpy.vectorize`

Breaking Changes
^^^^^^^^^^^^^^^^
* Adapted functions from `roocs_utils.xarray_utils.xarray_utils` into `clisops.utils.dataset_utils`
* `get_coord_by_type` now returns the name of the coordinate variable and not the coordinate variable
* `get_coord_by_type` optionally returns a list with further matches for the coordinate variable
* `get_coord_by_type` does no longer raise an exception when more than one coordinate variable matches the requested type
* `get_coord_by_type` raises `ValueError` instead of `Exception` when the coordinate type is unknown
* `detect_coordinate` raises `KeyError` instead of `AttributeError` if no coordinate could be detected
* `detect_gridtype` raises `ValueError` for unsupported grid types rather than `InvalidParameterValue` and `Exception`
* `clisops.core.regrid`
* `Grid.detect_coordinate`: raises `KeyError` instead of `AttributeError` if no coordinate could be detected
* `clisops.ops.regrid`
* `Regrid._calculate`: issues `UserWarning` instead of letting `clisops.core.Weights.__init__` raise an `Exception` when input and output grid are alike

v0.14.0 (2024-10-03)
--------------------

Expand Down
37 changes: 0 additions & 37 deletions binder/environment.yml

This file was deleted.

1 change: 1 addition & 0 deletions binder/environment.yml
18 changes: 7 additions & 11 deletions clisops/core/average.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import numpy as np
import xarray as xr
from roocs_utils.exceptions import InvalidParameterValue
from roocs_utils.xarray_utils.xarray_utils import (

from clisops.core.regrid import XESMF_MINIMUM_VERSION
from clisops.core.subset import shape_bbox_indexer
from clisops.utils.dataset_utils import (
get_coord_by_type,
get_coord_type,
known_coord_types,
)

from clisops.core.regrid import XESMF_MINIMUM_VERSION
from clisops.core.subset import shape_bbox_indexer
from clisops.utils.time_utils import create_time_bounds

__all__ = ["average_over_dims", "average_shape", "average_time"]

# see https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects
freqs = {"day": "1D", "month": "1MS", "year": "1AS"}
freqs = {"day": "1D", "month": "1MS", "year": "1YS"}


def average_shape(
Expand Down Expand Up @@ -281,15 +281,11 @@ def average_time(
)

# check time coordinate exists and get name
# For roocs_utils 0.5.0
t = get_coord_by_type(ds, "time", ignore_aux_coords=False)
if t is None:
raise Exception("Time dimension could not be found")
# For latest roocs_utils (master)
# try:
# t = get_coord_by_type(ds, "time", ignore_aux_coords=False)
# except KeyError:
# raise Exception("Time dimension could not be found")
else:
t = ds[t]

# resample and average over time
ds_t_avg = ds.resample(indexer={t.name: freqs[freq]}).mean(
Expand Down
Loading

0 comments on commit 60892b8

Please sign in to comment.