3

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.

1

1 Answer 1

2

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)
7
  • 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
    Commented Jul 15, 2020 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
    Commented Jul 15, 2020 at 15:12
  • Sure. Thank you.
    – Muser
    Commented Jul 16, 2020 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
    Commented Jul 16, 2020 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
    Commented Jul 16, 2020 at 7:02

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