I have global net radiation data but I want to extract for my country. I've loaded the NetCDF but I don't know how to proceed further. The following is a similar question (Extract data from netcdf using a shapefile polygon in python) but the answer talks about running from command line but I'm using Spyder.

If someone could help me with the code, I know that I need to use some command like clip or extract but I'm not sure how to.


You can use rioxarray. Here is an example: https://corteva.github.io/rioxarray/stable/examples/clip_geom.html

import rioxarray
import geopandas

geodf = geopandas.read_file(...)
xds = rioxarray.open_rasterio(...)
clipped = xds.rio.clip(geodf.geometry.apply(mapping), geodf.crs)
  • I checked it with a Tiff file and it worked. However, when I checked it with netcdf, I have difficulty with write_crs method to set a proper crs for it.
    – Muser
    Jul 15 '20 at 14:44
  • What errors do you have? Can you open up a new question with the rioxarray tag and the dataset you are using?
    – snowman2
    Jul 15 '20 at 15:12
  • Sure. Thank you.
    – Muser
    Jul 16 '20 at 4:28
  • I have written a more detailed answer that deals with my problem (write_crs). I think it can be useful for those who have the same problem. How can I post it here as a second answer? Its seems that the question is closed
    – Muser
    Jul 16 '20 at 6:33
  • Here is the answer that I was talking about with a new quesion related to it: gis.stackexchange.com/questions/367890/…
    – Muser
    Jul 16 '20 at 7:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.