roocs / clisops

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

`subset_shape` fails if dataset and shape have no CRS #95

Closed huard closed 3 years ago

huard commented 3 years ago

Description

subset_shape fails at shape_crs = CRS(poly.crs) if poly.crs is None, which is the case if shape is a simple geometry with no CRS information attached.

Zeitsperre commented 3 years ago

I can look into this. All the parts are there. It can probably be fixed with a try-except catch.

huard commented 3 years ago

Ok thanks,

I'd like a simple test like this to work:

from shapely.geometry import Polygon
# Create dummy Dataset
dims = ("lon", "lat")
n = {"lon": 5, "lat": 6}
ds = xr.Dataset(data_vars={"foo": (dims, np.ones(shape=list(n.values())))},
                coords={"lon": ("lon", np.arange(n["lon"])),
                        "lat": ("lat", np.arange(n["lat"]))}
                )
poly = Polygon([[0.5, 0], [2.5, 0], [2.5, 2.5], [0.5, 2.5]])
shape = gpd.GeoDataFrame(geometry=[poly])
subset.subset_shape(ds, shape=shape)

with output lat being [0, 1, 2] and output lon [1,2]

Zeitsperre commented 3 years ago

fixed with #96