roocs / clisops

Climate Simulation Operations
https://clisops.readthedocs.io/en/latest/
Other
21 stars 9 forks source link

subset_bbox_indexer broken with latest xarray #250

Closed aulemahal closed 1 year ago

aulemahal commented 1 year ago

Description

I'm sorry @Zeitsperre , it seems your fix in #241 is not working. I'm not sure what happened, but maybe you tested it out on a xarray commit from before the release and they changed it in between? What is certain, though, is that clisops would benefit from having a test build using xarray@master, to detect these before release.

What I Did

from clisops.core.subset import shape_bbox_indexer
import geopandas as gpd
import xarray as xr

# I am taking a polygon and a dataset from PAVICS for the example
poly = gpd.read_file('https://pavics.ouranos.ca/geoserver/public/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=public%3Aquebec_admin_boundaries&maxFeatures=1&outputFormat=application%2Fjson')
ds = xr.open_dataset('https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmin/nrcan_canada_daily_tasmin_2017.nc')

shape_bbox_indexer(ds, poly)

Fails with:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [30], line 1
----> 1 shape_bbox_indexer(ds, poly)

File ~/mambaforge/envs/finch/lib/python3.10/site-packages/clisops/core/subset.py:806, in shape_bbox_indexer(ds, poly)
    800         native_ind, _ = xarray.core.coordinates.remap_label_indexers(
    801             ds, ind, method="nearest"
    802         )
    803     else:
    804         native_ind = xarray.core.indexing.map_index_queries(
    805             ds, ind, method="nearest"
--> 806         ).indexers
    807 else:
    808     # For curvilinear grids, finding the closest points require a bit more work.
    809     # Note that this code is not exercised for now.
    810     from scipy.spatial import cKDTree

AttributeError: 'IndexSelResult' object has no attribute 'indexers'

Which is because the attribute name indeed is dim_indexers.

Zeitsperre commented 1 year ago

Looking into this, it seems as though the necessary tests are not run to check for these changes. The summary of issues here are as follows:

I'm going to look into fixing all these in an upcoming patch PR, today or tomorrow.

Zeitsperre commented 1 year ago

fixed with #251