0

I am trying to mask a NetCDF file with an shapefile. Here is my shapefile:

Africa_Shape = geopandas.read_file('/content/gdrive/MyDrive/HighresMIP/control_1950/iho/iho.shp', crs="epsg:4326")

And here is my NetCDF file (MSWEP_monthly) structure and the procedure that I am following to clip the original dataset enter image description here

And my results are all the values nan.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Aug 17, 2021 at 18:13

1 Answer 1

0

https://github.com/corteva/rioxarray/issues/202

Simplest method:

min_x, min_y, max_x, max_y = Africa_Shape.total_bounds
xds_clipped = xds.where((xds.lon<=max_x) & (xds.lon>=min_x) & (xds.lat<=max_y) & (xds.lat>=min_y), drop=True)

But, I would recommend looking into xoak

answered Aug 18, 2021 at 12:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.