0

I'm opening this grib file using rioxarray and reprojecting to WGS84 in the following manner with the goal of grabbing pixel values by coordinates.

import rioxarray 

url = 'https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr.20220511/conus/hrrr.t00z.wrfsubhf01.grib2'

src = rioxarray.open_rasterio(url)
reproj = src.rio.reproject("EPSG:4326")

This reprojectoin takes a little while, so I've pivoted to converting lat,lon coordinates to LCC2SP using this method

from pyproj import Transformer

x, y = -99, 43
transformer = Transformer.from_crs("EPSG:4326", src.rio.crs.to_proj4(), always_xy=True)
xm, ym = transformer.transform(x, y)

now when I select the the data using the two respective coordinate systems, I get two different values.

lcc_val = src.sel(x=xm, y=ym, method='nearest')[13]  # note: I use the original projection 'src' dataset here
coord_val = reproj.sel(x=x, y=y, method='nearest')[13]  # note: I use the new reprojected dataset here

the values are

lcc_val = array(22.60875854)
coord_val = array(20.73375854)

Can anyone see why this is happening?

EDIT: On testing the edges of the grid, the values being returned are the same. It's near the center where there are slight differences. I'm guessing it's some sort of reprojection error?

1 Answer 1

2

https://rasterio.readthedocs.io/en/stable/topics/reproject.html

Rasterio can map the pixels of a destination raster with an associated coordinate reference system and transform to the pixels of a source image with a different coordinate reference system and transform. This process is known as reprojection.

When re-projecting using rioxarray, you are creating equally spaced grids in the new projection. Then, you map the data from the original grid to the new grid.

If you only reproject the coordinates, as you were doing with pyproj, the spacing between the adjacent cells are often not equal due to distortion between projections. This means that you won't have an equally spaced grid in the new projection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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