How to mask out the CONUS from a netcdf file and write it again into netcdf?


Is there any efficient way to mask the Xarray’s datasets for a specific country and save that output for further analyses?

GeoCAT suggested two ways “cover” or “clip”. But the output is not suitable to save it as a netcdf file “.to_netcdf”. It happens as the output is kind of raster.

Alternatives are suggested like : Geopandas.clip, rioxarray, salem, regionmask.

Here we need to install different packages which take lots of time. I would appreciate any idea/link/example on more direct solution.

Here I found the answer; one fantastic example using rioxarray which worked wonderfully!

1 Like