-
Hi All, My end goal is to read a grib2 file using rioxarray and clip it with a polygon. I'm running into issues with the grib2 projection definition. I'm fairly new to grib2 file formats, any help is appreciated.
I run into this error:
Next, I define the grib2 projection using the WKT projection string found when I open the file in QGIS:
Then I run into a KeyError using the projection:
As the error is a KeyError, I try to define the projection using a proj4string instead:
And then I run into an error stating that no data found in bounds. I have confirmed that data is within the bounds using QGIS.
I'm fairly stumped. Any help is greatly appreciated. Please find the grib2 file attached. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Your latitude and longitude coordinates are 2D. rioxarray only works with 1D coordinates. Here are issues for reference for how to deal with this: |
Beta Was this translation helpful? Give feedback.
-
Found a simpler solution. The issue you are encountering is occurring when the CRS is exporting to CF. import rioxarray
clip_geom = [
{
"type":"Polygon",
"coordinates":[[
[-20.053465032,4.855709248],
[-19.468843208,4.521462474],
[-20.068351733,3.435063352],
[-20.705115362,3.786607157],
[-20.053465032,4.855709248]
]]
}
]
with rioxarray.set_options(export_grid_mapping=False):
rds = rioxarray.open_rasterio(
"grib2_file/CMC_hrdps_west_PRATE_SFC_0_rotated_latlon0.009x0.009_20221018T00Z_P005-00.grib2"
)
clipped = rds.rio.clip(clip_geom) Side note: This will no longer be an issue with the next release of pyproj (pyproj4/pyproj#1167). |
Beta Was this translation helpful? Give feedback.
Your latitude and longitude coordinates are 2D. rioxarray only works with 1D coordinates.
Here are issues for reference for how to deal with this: