corteva / rioxarray

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

merge_arrays - mirrowed y value #564

Closed sehHeiden closed 1 year ago

sehHeiden commented 2 years ago

Code Sample, a copy-pastable example if possible

A set of arrays are merged and than saved (the later for finding the errors). The array are from an DGM in south Germany. The example contains 4 raster files. Two files north of other files. I cannot share the files, for legal reasons.

rasters = [open_rasterio(_x) for _x in kwargs.values() if _x.exists()]
full = merge_arrays(rasters, method='last')

Problem description

Two things happen. After saving the megered raster I can see, that the southern 2 raster are turned upside down (north is south). The Northern two raster are correctly north of the first two raster, but also upside down.

The second problem. When trying the bounds parameter I get the error:

  File "...\rioxarray\merge.py", line 169, in merge_arrays
    merged_data, merged_transform = _rio_merge(
  File "...\rasterio\merge.py", line 262, in merge
    dest = np.zeros((output_count, output_height, output_width), dtype=dt)
ValueError: negative dimensions are not allowed
python-BaseException

Expected Output

Environment Information

rioxarray (0.11.1) deps:
  rasterio: 1.2.1
    xarray: 2022.3.0
      GDAL: 3.1.4
      GEOS: None
      PROJ: None
 PROJ DATA: None
 GDAL DATA: None

Other python deps:
     scipy: 1.8.1
    pyproj: 3.0.1

System:
    python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)]
executable: C:\Users\remote\anaconda3\envs\OBAL\python.exe
   machine: Windows-10-10.0.19043-SP0

Installation method

Conda environment information (if you installed with conda):

Environment (conda list):

Name                    Version                   Build  Channel
affine                    2.3.1              pyhd8ed1ab_0    conda-forge
alabaster                 0.7.12                     py_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
astral                    2.2                pyhd8ed1ab_1    conda-forge
attrs                     21.4.0             pyhd8ed1ab_0    conda-forge
babel                     2.10.3             pyhd8ed1ab_0    conda-forge
boost-cpp                 1.74.0               h9f4b32c_8    conda-forge
branca                    0.5.0              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h8ffe710_7    conda-forge
brotli-bin                1.0.9                h8ffe710_7    conda-forge
brotlipy                  0.7.0           py39hb82d6ee_1004    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2022.6.15            h5b45459_0    conda-forge
cachetools                5.0.0              pyhd8ed1ab_0    conda-forge
cairo                     1.16.0            hb19e0ff_1008    conda-forge
certifi                   2022.6.15        py39hcbf5309_0    conda-forge
cffi                      1.15.1           py39h0878f49_0    conda-forge
cfitsio                   3.470                h0af3d06_7    conda-forge
charset-normalizer        2.1.0              pyhd8ed1ab_0    conda-forge
click                     7.1.2              pyh9f0ad1d_0    conda-forge
click-plugins             1.1.1                      py_0    conda-forge
cligj                     0.7.2              pyhd8ed1ab_1    conda-forge
colorama                  0.4.5              pyhd8ed1ab_0    conda-forge
conda                     4.13.0           py39hcbf5309_1    conda-forge
conda-package-handling    1.8.1            py39hb3671d1_1    conda-forge
cryptography              37.0.4           py39h7bc7c5c_0    conda-forge
curl                      7.83.1               h789b8ee_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
dataclasses               0.8                pyhc8e2a94_3    conda-forge
docutils                  0.18.1           py39hcbf5309_1    conda-forge
expat                     2.4.8                h39d44d4_0    conda-forge
fiona                     1.8.18           py39he2373ac_0    conda-forge
folium                    0.12.1.post1       pyhd8ed1ab_1    conda-forge
fontconfig                2.14.0               hce3cb01_0    conda-forge
fonttools                 4.34.4           py39hb82d6ee_0    conda-forge
freetype                  2.10.4               h546665d_1    conda-forge
freexl                    1.0.6                ha8e266a_0    conda-forge
gdal                      3.1.4           py39haafd053_15    conda-forge
geocube                   0.3.2              pyhd8ed1ab_0    conda-forge
geopandas                 0.11.0             pyhd8ed1ab_0    conda-forge
geopandas-base            0.11.0             pyha770c72_0    conda-forge
geos                      3.9.1                h39d44d4_2    conda-forge
geotiff                   1.6.0                h8e90983_5    conda-forge
gettext                   0.19.8.1          ha2e2712_1008    conda-forge
hdf4                      4.2.15               h0e5069d_3    conda-forge
hdf5                      1.10.6          nompi_h5268f04_1114    conda-forge
icu                       68.2                 h0e60522_0    conda-forge
idna                      3.3                pyhd8ed1ab_0    conda-forge
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
importlib-metadata        4.11.4           py39hcbf5309_0    conda-forge
importlib_metadata        4.11.4               hd8ed1ab_0    conda-forge
intel-openmp              2022.1.0          h57928b3_3787    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
joblib                    1.1.0              pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h8ffe710_2    conda-forge
kealib                    1.4.14               h96bfa42_2    conda-forge
kiwisolver                1.4.3            py39h2e07f2f_0    conda-forge
krb5                      1.19.3               h1176d77_0    conda-forge
lcms2                     2.12                 h2a16943_0    conda-forge
lerc                      3.0                  h0e60522_0    conda-forge
libarchive                3.5.2                hb45042f_3    conda-forge
libblas                   3.9.0              15_win64_mkl    conda-forge
libbrotlicommon           1.0.9                h8ffe710_7    conda-forge
libbrotlidec              1.0.9                h8ffe710_7    conda-forge
libbrotlienc              1.0.9                h8ffe710_7    conda-forge
libcblas                  3.9.0              15_win64_mkl    conda-forge
libcurl                   7.83.1               h789b8ee_0    conda-forge
libdeflate                1.12                 h8ffe710_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libgdal                   3.1.4               h966def8_15    conda-forge
libglib                   2.72.1               h3be07f2_0    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
libkml                    1.3.0             h9859afa_1014    conda-forge
liblapack                 3.9.0              15_win64_mkl    conda-forge
libmamba                  0.24.0               h81a967f_1    conda-forge
libmambapy                0.24.0           py39h4126fcf_1    conda-forge
libnetcdf                 4.8.0           nompi_hf689e7d_103    conda-forge
libpng                    1.6.37               h1d00b33_3    conda-forge
libpq                     13.5                 hfcc5ef8_1    conda-forge
librttopo                 1.1.0                hb340de5_6    conda-forge
libsolv                   0.7.22               h7755175_0    conda-forge
libspatialindex           1.9.3                h39d44d4_4    conda-forge
libspatialite             5.0.1                h6b539a6_4    conda-forge
libssh2                   1.10.0               h680486a_2    conda-forge
libtiff                   4.4.0                h2ed3b44_1    conda-forge
libwebp                   1.2.2                h57928b3_0    conda-forge
libwebp-base              1.2.2                h8ffe710_1    conda-forge
libxcb                    1.13              hcd874cb_1004    conda-forge
libxml2                   2.9.14               hf5bbc77_3    conda-forge
libzip                    1.9.2                hfed4ece_0    conda-forge
libzlib                   1.2.12               h8ffe710_1    conda-forge
llvmlite                  0.38.1           py39ha0cd8c8_0    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
lzo                       2.10              he774522_1000    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
mamba                     0.24.0           py39hb3d9227_1    conda-forge
mapclassify               2.4.3              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.1            py39hb82d6ee_1    conda-forge
matplotlib-base           3.5.2            py39h581301d_0    conda-forge
menuinst                  1.4.18           py39hcbf5309_1    conda-forge
mkl                       2022.1.0           h6a75c08_874    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
munch                     2.5.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
networkx                  2.8.4              pyhd8ed1ab_0    conda-forge
numba                     0.55.2           py39hb8cd55e_0    conda-forge
numpy                     1.22.4           py39h0948cea_0    conda-forge
odc-geo                   0.2.1              pyhd8ed1ab_0    conda-forge
openjpeg                  2.4.0                hb211442_1    conda-forge
openssl                   1.1.1q               h8ffe710_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandas                    1.4.3            py39h2e25243_0    conda-forge
pcre                      8.45                 h0e60522_0    conda-forge
pillow                    9.2.0            py39ha53f419_0    conda-forge
pip                       22.1.2             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               h8ffe710_0    conda-forge
poppler                   21.03.0              h9ff6ed8_0    conda-forge
poppler-data              0.4.11               hd8ed1ab_0    conda-forge
postgresql                13.5                 h1c22c4f_1    conda-forge
proj                      8.0.0                h1cfcee9_0    conda-forge
pthread-stubs             0.4               hcd874cb_1001    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycosat                   0.6.3           py39hb82d6ee_1010    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.12.0             pyhd8ed1ab_0    conda-forge
pyopenssl                 22.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyproj                    3.0.1            py39h1007a03_1    conda-forge
pysocks                   1.7.1            py39hcbf5309_5    conda-forge
python                    3.9.13          h9a09f29_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.9                      2_cp39    conda-forge
pytz                      2022.1             pyhd8ed1ab_0    conda-forge
pywin32                   303              py39hb82d6ee_0    conda-forge
rasterio                  1.2.1            py39hfec4536_0    conda-forge
rasterstats               0.16.0             pyhd8ed1ab_0    conda-forge
reproc                    14.2.3               h8ffe710_0    conda-forge
reproc-cpp                14.2.3               h0e60522_0    conda-forge
requests                  2.28.1             pyhd8ed1ab_0    conda-forge
rioxarray                 0.11.1             pyhd8ed1ab_0    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0            py39hcbf5309_4    conda-forge
xarray                    2022.3.0           pyhd8ed1ab_0    conda-forge
xerces-c                  3.2.3                h0e60522_5    conda-forge
xorg-libxau               1.0.9                hcd874cb_0    conda-forge
xorg-libxdmcp             1.1.3                hcd874cb_0    conda-forge
xyzservices               2022.6.0           pyhd8ed1ab_0    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
yaml                      0.2.5                h8ffe710_2    conda-forge
yaml-cpp                  0.7.0                h0e60522_1    conda-forge
zipp                      3.8.0              pyhd8ed1ab_0    conda-forge
zlib                      1.2.12               h8ffe710_1    conda-forge
zstd                      1.5.2                h6255e5f_2    conda-forge
snowman2 commented 2 years ago

This sounds like something worth looking into. However, we need a reproducible example. Are you able to provide a simple code snipped with example rasters that re-produce this issue?

snowman2 commented 2 years ago

Can you try with the latest rioxarray (0.12.0)?

sehHeiden commented 2 years ago

I tired the version 0.12.0 error is the same.

I fixed the first problem of turning the rows upsidedown with: raster.rio.reproject(raster.rio.crs).

original transform: Affine(5.0, 0.0, 588802.5, 0.0, 5.0, 5235857.5), changed: Affine(5.0, 0.0, 588802.5, 0.0, -5.0, 5235997.5)

I cannot share the data, because of legal reasons.

snowman2 commented 2 years ago

The latest rasterio is 1.3.2. I would recommend upgrading that as well and seeing if it helps.

scottyhq commented 2 years ago

I cannot share the data, because of legal reasons.

@Meresmata check out https://github.com/cogeotiff/rio-faux

snowman2 commented 1 year ago

Unfortunately there isn't much we can do here with the current information.