I have some NetCDF files (sea level anomaly) and I can open them in Python, but how can I extract pixel values of a specific region (square shape) and save the pixel values as CSV file?
the details of files are like this one, sorry for picture bad quality.
and this is one of the files.(Both links are for the same file)
1 Answer 1
You can try using rioxarray & xarray:
- Clip: https://corteva.github.io/rioxarray/stable/examples/clip_geom.html
- Clip Box: https://corteva.github.io/rioxarray/stable/examples/clip_box.html
- NetCDF to CSV: https://gis.stackexchange.com/a/358057/144357
If you are able to provide a file, a more targeted example could be given.
EDIT: In case you have lon 0-360, these links should help:
- https://github.com/corteva/rioxarray/issues/58#issuecomment-612062722
- https://gis.stackexchange.com/a/357810/144357
Based on this comment from the moderators:
Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that.
Mind attempting to come up with a solution based on the links referenced here and adding code you have attempted and any errors you have run into to the question?
-
thanks for answering. i add a link to the question.Kourosh Shahryari– Kourosh Shahryari2020年07月30日 12:20:09 +00:00Commented Jul 30, 2020 at 12:20
-
Mind attempting to come up with a solution based on the links referenced here and adding code you have attempted and any errors you have run into to the question?snowman2– snowman22020年07月30日 13:13:46 +00:00Commented Jul 30, 2020 at 13:13
gdal_translate
~ gdal.org/programs/gdal_translate.html#gdal-translatexarray
, you may find the example presented in this question useful: stackoverflow.com/questions/58992490/…. Once you have extracted a value at a given geocoordinate, you can simply export the dataset to Pandas dataframe then use their.to_csv()
method.