Now in 2017, I use rasterio.mask.mask
and fiona
to rasterize the shape file and then apply that to the netCDF dataset using xarray
.
EDIT: Now in 2019, there is https://github.com/corteva/rioxarray to ease the integration of rasterio
and xarray
. Clipping a dataset (e.g. from NetCDF) with a geometry is listed as example here: https://corteva.github.io/rioxarray/stable/examples/clip_geom.html