corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
518 stars 82 forks source link

"incorrect" bounds (clip_box, pad_box) #545

Closed bertcoerver closed 2 years ago

bertcoerver commented 2 years ago

Code Sample

ds = xr.Dataset(None, {"x": range(5), "y": range(5)})
ds.rio.bounds()

This returns (-0.5, 4.5, 4.5, -0.5), where the values represent xmin, ymin, xmax, ymax I believe. As you can see, ymin > ymax. I can solve this by assuring that the y coordinates are descending instead of ascending:

ds = xr.Dataset(None, {"x": range(5), "y": range(5)})
ds = ds.sortby(ds.y, ascending=False)
ds.rio.bounds()

Gives (-0.5, -0.5, 4.5, 4.5).

Problem description

I'm trying to use rio.clip_box and then rio.pad_box on a dataset, but I'm running into errors which are solved when making sure that ymin is smaller than ymax.

Shouldn't rio.bounds check what is the actual minimum value in ds.y (e.g. doing somethings like ds.y.min()), instead of doing something like ds.y.isel(y = 0)?

Environment Information

rioxarray (0.11.1) deps:
  rasterio: 1.2.10
    xarray: 2022.3.0
      GDAL: 3.3.2
      GEOS: None
      PROJ: None
 PROJ DATA: None
 GDAL DATA: None

Other python deps:
     scipy: 1.8.0
    pyproj: 3.3.0

System:
    python: 3.8.12 | packaged by conda-forge | (default, Jan 30 2022, 23:33:09)  [Clang 11.1.0 ]
executable: /Users/hmcoerver/miniconda3/envs/pywapor/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Conda environment information (if you installed with conda):


Environment (conda list):

``` gdal 3.4.2 py38h0b97839_0 conda-forge libgdal 3.4.2 h52a0caa_0 conda-forge rasterio 1.2.10 pypi_0 pypi rioxarray 0.11.1 pypi_0 pypi xarray 2022.3.0 pypi_0 pypi ```


Details about conda and system ( conda info ):

``` active environment : pywapor active env location : /Users/hmcoerver/miniconda3/envs/pywapor shell level : 2 user config file : /Users/hmcoerver/.condarc populated config files : conda version : 4.11.0 conda-build version : 3.21.4 python version : 3.8.12.final.0 virtual packages : __osx=10.16=0 __unix=0=0 __archspec=1=x86_64 base environment : /Users/hmcoerver/miniconda3 (writable) conda av data dir : /Users/hmcoerver/miniconda3/etc/conda conda av metadata url : None channel URLs : https://repo.anaconda.com/pkgs/main/osx-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/osx-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /Users/hmcoerver/miniconda3/pkgs /Users/hmcoerver/.conda/pkgs envs directories : /Users/hmcoerver/miniconda3/envs /Users/hmcoerver/.conda/envs platform : osx-64 user-agent : conda/4.11.0 requests/2.27.1 CPython/3.8.12 Darwin/20.6.0 OSX/10.16 UID:GID : 501:20 netrc file : None offline mode : False ```