Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid bounds returned by .rio.bounds() #645

Closed
vincentsarago opened this issue Mar 9, 2023 · 4 comments
Closed

Invalid bounds returned by .rio.bounds() #645

vincentsarago opened this issue Mar 9, 2023 · 4 comments
Labels
question Further information is requested

Comments

@vincentsarago
Copy link

👋 I've looked at all issues mentioning bounds but I don't think I found one similar to the one I have (I'm sorry if there is)

When using ds.rio.bounds() for this dataset s3://power-analysis-ready-datastore/power_901_annual_meteorology_utc.zarr, I'm getting values that exceed the values in the array itself 👇

ds = xarray.open_dataset("s3://power-analysis-ready-datastore/power_901_annual_meteorology_utc.zarr", engine="zarr", decode_coords="all") 

ds.rio._obj.coords
>> 
Coordinates:
  * lat      (lat) float64 -90.0 -89.5 -89.0 -88.5 -88.0 ... 88.5 89.0 89.5 90.0
  * lon      (lon) float64 -180.0 -179.4 -178.8 -178.1 ... 178.1 178.8 179.4
  * time     (time) datetime64[ns] 1981-12-31 1982-12-31 ... 2021-12-31


# Print XMIN, YMIN, XMAX, YMAX
bounds = list(map(float, [ds["lon"].min(), ds["lat"].min(), ds["lon"].max(), ds["lat"].max()]))
print(bounds)
>> [-180.0, -90.0, 179.375, 90.0]

# Print Bounds from rioxarray
print(ds.rio.bounds())
>> (-180.3125, -90.25, 179.6875, 90.25)

print(ds.rio.bounds(recalc=True))
>> (-180.3125, -90.25, 179.6875, 90.25)

print(ds.rio.transform())
>> Affine(0.625, 0.0, -180.3125, 0.0, 0.5, -90.25)

print(ds.rio._internal_bounds())
>> (-180.0, 90.0, 179.375, -90.0)

print(ds.rio._unordered_bounds())
>> (-180.3125, 90.25, 179.6875, -90.25)

print(ds.rio.resolution())
>> (0.625, 0.5)

Environment Information

python -c "import rioxarray; rioxarray.show_versions()"
rioxarray (0.12.2) deps:
  rasterio: 1.4.dev0
    xarray: 2022.6.0
      GDAL: 3.5.0
      GEOS: 3.10.3
      PROJ: 9.0.0
 PROJ DATA: /opt/homebrew/share/proj
 GDAL DATA: /opt/homebrew/share/gdal

Other python deps:
     scipy: 1.9.1
    pyproj: 3.4.0

System:
    python: 3.9.13 (main, May 24 2022, 21:13:51)  [Clang 13.1.6 (clang-1316.0.21.2)]
executable: /Users/vincentsarago/Dev/venv/py39/bin/python
   machine: macOS-13.2-arm64-arm-64bit
@vincentsarago vincentsarago added the bug Something isn't working label Mar 9, 2023
@snowman2
Copy link
Member

snowman2 commented Mar 9, 2023

Welcome!

The coordinates of the grid cell represent the centroid of the grid cell. To get the boundary of the raster, you have to take into account the resolution of the grid cell and add/subtract from the bounding centroid coordinates.

@snowman2 snowman2 added question Further information is requested and removed bug Something isn't working labels Mar 9, 2023
@vincentsarago
Copy link
Author

@snowman2 so I'm right to assume that the coordinates from the zarr file are incorrect because they represent UpperLeff corner of the grid instead of the centroid?

It's unlikely that a user will want the bounds of it's data to overflow the valid bounds for epsg:4326 (-180.0, 90.0, 179.375, -90.0)

@snowman2
Copy link
Member

snowman2 commented Mar 9, 2023

I'm right to assume that the coordinates from the zarr file are incorrect because they represent UpperLeff corner of the grid instead of the centroid?

I have only encountered files with the coordinates representing the centroid. It is likely incorrect or at least non-standard

@vincentsarago
Copy link
Author

thank you @snowman2 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants