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
1 Answer 1
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
lang-py