conda-forge / rasterio-feedstock

A conda-smithy repository for rasterio.
BSD 3-Clause "New" or "Revised" License
42 stars 22 forks source link

Different results on reprojection on recent rasterio versions installed with conda #239

Open fmaussion opened 2 years ago

fmaussion commented 2 years ago

Solution to issue cannot be found in the documentation.

Issue

Here is a sample data file: hef_srtm.tif.zip (DEM data)

Here is a sample script:

import numpy as np
import rasterio
from rasterio.warp import reproject, Resampling

ds = rasterio.open('hef_srtm.tif')
dem_data = rasterio.band(ds, 1)

nodata = -9999
nx, ny = 159, 114
ulx, uly, dx, dx = -3542.1291222825153, 5186065.526772606, 50.0, 50.0
dst_transform = rasterio.transform.from_origin(ulx, uly, dx, dx)

dst_crs = '+proj=tmerc +lat_0=0 +lon_0=10.7584 +k=0.9996 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'

profile = ds.profile
profile.update({
    'crs': dst_crs,
    'transform': dst_transform,
    'width': nx,
    'height': ny,
    'nodata': nodata,
    'driver': 'GTiff'
})

with rasterio.open(f'outf_{rasterio.__version__}_conda.tif', 'w', **profile) as dest:
    dst_array = np.empty((ny, nx), dtype=ds.dtypes[0])
    reproject(
        source=dem_data,
        src_crs=ds.crs,
        src_transform=ds.transform,
        src_nodata=nodata,
        destination=dst_array,
        dst_transform=dst_transform,
        dst_crs=dst_crs,
        resampling=Resampling.cubic)
    dest.write(dst_array, 1)

ds.close()

Sorry I couldn't pin this down to a simpler snippet. This code resamples the data into a new map. It is taken out of the OGGM test suite ehich stated erroring on conda environments recently (date unknown).

The expected output is: outf_1.2.10_pip.tif.zip

When run on a fresh conda install in linux, the output is different (shifted with large absolute errors: +- 60 meters, tested on two different linux machines):

image

On conda, downgrading to rasterio 1.2.9 solves the problem. (but its hard to tell what the reason is, because this downgrades libgdal and proj as well.

cc @TimoRoth FYI

Installed packages

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
affine                    2.3.0                      py_0    conda-forge
alsa-lib                  1.2.3                h516909a_0    conda-forge
anyio                     3.5.0            py39hf3d152e_0    conda-forge
aom                       3.3.0                h27087fc_1    conda-forge
argon2-cffi               21.3.0             pyhd8ed1ab_0    conda-forge
argon2-cffi-bindings      21.2.0           py39h3811e60_1    conda-forge
asttokens                 2.0.5              pyhd8ed1ab_0    conda-forge
attrs                     21.4.0             pyhd8ed1ab_0    conda-forge
babel                     2.9.1              pyh44b312d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
beautifulsoup4            4.10.0             pyha770c72_0    conda-forge
bleach                    4.1.0              pyhd8ed1ab_0    conda-forge
blosc                     1.21.0               h9c3ff4c_0    conda-forge
bokeh                     2.4.2            py39hf3d152e_0    conda-forge
boost-cpp                 1.74.0               h6cacc03_7    conda-forge
bottleneck                1.3.4            py39hd257fcd_0    conda-forge
branca                    0.4.2              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h7f98852_6    conda-forge
brotli-bin                1.0.9                h7f98852_6    conda-forge
brotlipy                  0.7.0           py39h3811e60_1003    conda-forge
brunsli                   0.1                  h9c3ff4c_0    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.18.1               h7f98852_0    conda-forge
c-blosc2                  2.0.4                h5f21a17_1    conda-forge
ca-certificates           2021.10.8            ha878542_0    conda-forge
cairo                     1.16.0            ha12eb4b_1010    conda-forge
cartopy                   0.20.2           py39h0ddd56c_4    conda-forge
certifi                   2021.10.8        py39hf3d152e_1    conda-forge
cffi                      1.15.0           py39h4bc2ebd_0    conda-forge
cfitsio                   4.0.0                h9a35b8e_0    conda-forge
cftime                    1.6.0            py39hd257fcd_0    conda-forge
charls                    2.3.4                h9c3ff4c_0    conda-forge
charset-normalizer        2.0.12             pyhd8ed1ab_0    conda-forge
click                     8.0.4            py39hf3d152e_0    conda-forge
click-plugins             1.1.1                      py_0    conda-forge
cligj                     0.7.2              pyhd8ed1ab_1    conda-forge
cloudpickle               2.0.0              pyhd8ed1ab_0    conda-forge
configobj                 5.0.6                      py_0    conda-forge
cryptography              36.0.1           py39h95dcef6_0    conda-forge
curl                      7.82.0               h7bff187_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
cytoolz                   0.11.2           py39h3811e60_1    conda-forge
dask                      2022.3.0           pyhd8ed1ab_0    conda-forge
dask-core                 2022.3.0           pyhd8ed1ab_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
debugpy                   1.5.1            py39he80948d_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
distributed               2022.3.0           pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
executing                 0.8.3              pyhd8ed1ab_0    conda-forge
expat                     2.4.7                h27087fc_0    conda-forge
fiona                     1.8.21           py39hc5a795b_0    conda-forge
flit-core                 3.7.1              pyhd8ed1ab_0    conda-forge
folium                    0.12.1.post1       pyhd8ed1ab_1    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.13.96              h8e229c2_2    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.31.1           py39hb9d737c_0    conda-forge
freetype                  2.10.4               h0708190_1    conda-forge
freexl                    1.0.6                h7f98852_0    conda-forge
fsspec                    2022.2.0           pyhd8ed1ab_0    conda-forge
gdal                      3.4.2            py39hc691d54_0    conda-forge
geopandas                 0.10.2             pyhd8ed1ab_1    conda-forge
geopandas-base            0.10.2             pyha770c72_1    conda-forge
geos                      3.10.2               h9c3ff4c_0    conda-forge
geotiff                   1.7.1                h509b78c_0    conda-forge
gettext                   0.19.8.1          h73d1719_1008    conda-forge
giflib                    5.2.1                h36c2ea0_2    conda-forge
gst-plugins-base          1.18.5               hf529b03_3    conda-forge
gstreamer                 1.18.5               h9f60fe5_3    conda-forge
hdf4                      4.2.15               h10796ff_3    conda-forge
hdf5                      1.12.1          nompi_h2386368_104    conda-forge
heapdict                  1.0.1                      py_0    conda-forge
icu                       69.1                 h9c3ff4c_0    conda-forge
idna                      3.3                pyhd8ed1ab_0    conda-forge
imagecodecs               2022.2.22        py39hf577088_0    conda-forge
imageio                   2.16.1             pyhcf75d05_0    conda-forge
importlib-metadata        4.11.3           py39hf3d152e_0    conda-forge
importlib_metadata        4.11.3               hd8ed1ab_0    conda-forge
importlib_resources       5.4.0              pyhd8ed1ab_0    conda-forge
iniconfig                 1.1.1              pyh9f0ad1d_0    conda-forge
ipykernel                 6.9.2            py39hef51801_0    conda-forge
ipython                   8.1.1            py39hf3d152e_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.7.0              pyhd8ed1ab_0    conda-forge
jbig                      2.1               h7f98852_2003    conda-forge
jedi                      0.18.1           py39hf3d152e_0    conda-forge
jinja2                    3.0.3              pyhd8ed1ab_0    conda-forge
joblib                    1.1.0              pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h7f98852_0    conda-forge
json-c                    0.15                 h98cffda_0    conda-forge
json5                     0.9.5              pyh9f0ad1d_0    conda-forge
jsonschema                4.4.0              pyhd8ed1ab_0    conda-forge
jupyter                   1.0.0            py39hf3d152e_7    conda-forge
jupyter_client            7.1.2              pyhd8ed1ab_0    conda-forge
jupyter_console           6.4.3              pyhd8ed1ab_0    conda-forge
jupyter_core              4.9.2            py39hf3d152e_0    conda-forge
jupyter_server            1.15.6             pyhd8ed1ab_0    conda-forge
jupyterlab                3.3.2              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
jupyterlab_server         2.11.0             pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        1.1.0              pyhd8ed1ab_0    conda-forge
jxrlib                    1.1                  h7f98852_2    conda-forge
kealib                    1.4.14               h87e4c3c_3    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
kiwisolver                1.4.0            py39hf939315_0    conda-forge
krb5                      1.19.3               h3790be6_0    conda-forge
lcms2                     2.12                 hddcbb42_0    conda-forge
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
lerc                      3.0                  h9c3ff4c_0    conda-forge
libaec                    1.0.6                h9c3ff4c_0    conda-forge
libavif                   0.9.3                h166bdaf_1    conda-forge
libblas                   3.9.0           13_linux64_openblas    conda-forge
libbrotlicommon           1.0.9                h7f98852_6    conda-forge
libbrotlidec              1.0.9                h7f98852_6    conda-forge
libbrotlienc              1.0.9                h7f98852_6    conda-forge
libcblas                  3.9.0           13_linux64_openblas    conda-forge
libclang                  13.0.1          default_hc23dcda_0    conda-forge
libcurl                   7.82.0               h7bff187_0    conda-forge
libdap4                   3.20.6               hd7c4107_2    conda-forge
libdeflate                1.10                 h7f98852_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.10               h9b69904_4    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 11.2.0              h1d223b6_14    conda-forge
libgdal                   3.4.2                haa48f22_0    conda-forge
libgfortran-ng            11.2.0              h69a702a_14    conda-forge
libgfortran5              11.2.0              h5c6108e_14    conda-forge
libglib                   2.70.2               h174f98d_4    conda-forge
libgomp                   11.2.0              h1d223b6_14    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
libkml                    1.3.0             h238a007_1014    conda-forge
liblapack                 3.9.0           13_linux64_openblas    conda-forge
libllvm13                 13.0.1               hf817b99_2    conda-forge
libnetcdf                 4.8.1           nompi_hb3fd0d9_101    conda-forge
libnghttp2                1.47.0               h727a467_0    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopenblas               0.3.18          pthreads_h8fe5266_0    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libpq                     14.2                 hd57d9b9_0    conda-forge
librttopo                 1.1.0                hf69c175_9    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libspatialindex           1.9.3                h9c3ff4c_4    conda-forge
libspatialite             5.0.1               ha867d66_15    conda-forge
libssh2                   1.10.0               ha56f1ee_2    conda-forge
libstdcxx-ng              11.2.0              he4da1e4_14    conda-forge
libtiff                   4.3.0                h542a066_3    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libwebp                   1.2.2                h3452ae3_0    conda-forge
libwebp-base              1.2.2                h7f98852_1    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libxkbcommon              1.0.3                he3ba5ed_0    conda-forge
libxml2                   2.9.12               h885dcf4_1    conda-forge
libzip                    1.8.0                h4de3113_1    conda-forge
libzlib                   1.2.11            h36c2ea0_1013    conda-forge
libzopfli                 1.0.3                h9c3ff4c_0    conda-forge
locket                    0.2.0                      py_2    conda-forge
lz4-c                     1.9.3                h9c3ff4c_1    conda-forge
lzo                       2.10              h516909a_1000    conda-forge
mapclassify               2.4.3              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.1            py39hb9d737c_0    conda-forge
matplotlib                3.5.1            py39hf3d152e_0    conda-forge
matplotlib-base           3.5.1            py39h2fa2bec_0    conda-forge
matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge
mistune                   0.8.4           py39h3811e60_1005    conda-forge
motionless                1.3.3              pyhd8ed1ab_0    conda-forge
msgpack-python            1.0.3            py39h1a9c180_0    conda-forge
munch                     2.5.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mysql-common              8.0.28               ha770c72_0    conda-forge
mysql-libs                8.0.28               hfa10184_0    conda-forge
nbclassic                 0.3.7              pyhd8ed1ab_0    conda-forge
nbclient                  0.5.13             pyhd8ed1ab_0    conda-forge
nbconvert                 6.4.4            py39hf3d152e_0    conda-forge
nbformat                  5.2.0              pyhd8ed1ab_0    conda-forge
ncurses                   6.3                  h9c3ff4c_0    conda-forge
nest-asyncio              1.5.4              pyhd8ed1ab_0    conda-forge
netcdf4                   1.5.8           nompi_py39h64b754b_101    conda-forge
networkx                  2.7.1              pyhd8ed1ab_0    conda-forge
nomkl                     1.0                  h5ca1d4c_0    conda-forge
notebook                  6.4.10             pyha770c72_0    conda-forge
notebook-shim             0.1.0              pyhd8ed1ab_0    conda-forge
nspr                      4.32                 h9c3ff4c_1    conda-forge
nss                       3.74                 hb5efdd6_0    conda-forge
numexpr                   2.8.0           py39hbd72853_101    conda-forge
numpy                     1.22.3           py39h18676bf_0    conda-forge
oggm                      1.5.3.dev67+g08a1b1a.d20220320           dev_0    <develop>
openjpeg                  2.4.0                hb52868f_1    conda-forge
openssl                   1.1.1l               h7f98852_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandas                    1.4.1            py39hde0f152_0    conda-forge
pandoc                    2.17.1.1             ha770c72_0    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
partd                     1.2.0              pyhd8ed1ab_0    conda-forge
patsy                     0.5.2              pyhd8ed1ab_0    conda-forge
pcre                      8.45                 h9c3ff4c_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    9.0.1            py39hae2aec6_2    conda-forge
pip                       22.0.4             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               h36c2ea0_0    conda-forge
pluggy                    1.0.0            py39hf3d152e_2    conda-forge
poppler                   22.01.0              h1434ded_1    conda-forge
poppler-data              0.4.11               hd8ed1ab_0    conda-forge
postgresql                14.2                 h2510834_0    conda-forge
progressbar2              4.0.0                    pypi_0    pypi
proj                      9.0.0                h93bde94_1    conda-forge
prometheus_client         0.13.1             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.27             pyha770c72_0    conda-forge
prompt_toolkit            3.0.27               hd8ed1ab_0    conda-forge
psutil                    5.9.0            py39h3811e60_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
py                        1.11.0             pyh6c4a22f_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.11.2             pyhd8ed1ab_0    conda-forge
pyopenssl                 22.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.7              pyhd8ed1ab_0    conda-forge
pyproj                    3.3.0            py39hcadae2f_2    conda-forge
pyqt                      5.12.3           py39hf3d152e_8    conda-forge
pyqt-impl                 5.12.3           py39hde8b62d_8    conda-forge
pyqt5-sip                 4.19.18          py39he80948d_8    conda-forge
pyqtchart                 5.12             py39h0fcd23e_8    conda-forge
pyqtwebengine             5.12.1           py39h0fcd23e_8    conda-forge
pyrsistent                0.18.1           py39h3811e60_0    conda-forge
pyshp                     2.2.0              pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1            py39hf3d152e_4    conda-forge
pytables                  3.7.0            py39h2669a42_0    conda-forge
pytest                    7.1.1            py39hf3d152e_0    conda-forge
pytest-mpl                0.130                    pypi_0    pypi
python                    3.9.10          h85951f9_2_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-utils              3.1.0                    pypi_0    pypi
python_abi                3.9                      2_cp39    conda-forge
pytz                      2021.3             pyhd8ed1ab_0    conda-forge
pywavelets                1.3.0            py39hd257fcd_0    conda-forge
pyyaml                    6.0              py39h3811e60_3    conda-forge
pyzmq                     22.3.0           py39h37b5a0c_1    conda-forge
qt                        5.12.9               ha98a1a1_5    conda-forge
qtconsole                 5.2.2              pyhd8ed1ab_1    conda-forge
qtconsole-base            5.2.2              pyhd8ed1ab_1    conda-forge
qtpy                      2.0.1              pyhd8ed1ab_0    conda-forge
rasterio                  1.2.10           py39h2e4b6e6_5    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
requests                  2.27.1             pyhd8ed1ab_0    conda-forge
rioxarray                 0.10.2             pyhd8ed1ab_0    conda-forge
rtree                     0.9.7            py39hb102c33_3    conda-forge
salem                     0.3.7              pyhd8ed1ab_0    conda-forge
scikit-image              0.19.2           py39hde0f152_0    conda-forge
scikit-learn              1.0.2            py39h4dfa638_0    conda-forge
scipy                     1.8.0            py39hee8e79c_1    conda-forge
seaborn                   0.11.2               hd8ed1ab_0    conda-forge
seaborn-base              0.11.2             pyhd8ed1ab_0    conda-forge
send2trash                1.8.0              pyhd8ed1ab_0    conda-forge
setuptools                60.10.0          py39hf3d152e_0    conda-forge
shapely                   1.8.0            py39ha65c37e_5    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snappy                    1.1.8                he1b5a44_3    conda-forge
sniffio                   1.2.0            py39hf3d152e_2    conda-forge
snuggs                    1.4.7                      py_0    conda-forge
sortedcontainers          2.4.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3.1              pyhd8ed1ab_0    conda-forge
sqlite                    3.37.1               h4ff8645_0    conda-forge
stack_data                0.2.0              pyhd8ed1ab_0    conda-forge
statsmodels               0.13.2           py39hce5d2b2_0    conda-forge
tblib                     1.7.0              pyhd8ed1ab_0    conda-forge
terminado                 0.13.3           py39hf3d152e_0    conda-forge
testpath                  0.6.0              pyhd8ed1ab_0    conda-forge
threadpoolctl             3.1.0              pyh8a188c0_0    conda-forge
tifffile                  2022.3.16          pyhd8ed1ab_0    conda-forge
tiledb                    2.7.1                h1e4a385_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
toolz                     0.11.2             pyhd8ed1ab_0    conda-forge
tornado                   6.1              py39h3811e60_2    conda-forge
traitlets                 5.1.1              pyhd8ed1ab_0    conda-forge
typing_extensions         4.1.1              pyha770c72_0    conda-forge
tzcode                    2022a                h166bdaf_0    conda-forge
tzdata                    2022a                h191b570_0    conda-forge
unicodedata2              14.0.0           py39h3811e60_0    conda-forge
urllib3                   1.26.9             pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
websocket-client          1.3.1              pyhd8ed1ab_0    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
widgetsnbextension        3.6.0            py39hf3d152e_0    conda-forge
xarray                    2022.3.0           pyhd8ed1ab_0    conda-forge
xerces-c                  3.2.3                h8ce2273_4    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.0.10               h7f98852_0    conda-forge
xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
xorg-libx11               1.7.2                h7f98852_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h7f98852_1    conda-forge
xorg-libxrender           0.9.10            h7f98852_1003    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xyzservices               2022.3.0           pyhd8ed1ab_0    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
zeromq                    4.3.4                h9c3ff4c_1    conda-forge
zfp                       0.5.5                h9c3ff4c_8    conda-forge
zict                      2.1.0              pyhd8ed1ab_0    conda-forge
zipp                      3.7.0              pyhd8ed1ab_1    conda-forge
zlib                      1.2.11            h36c2ea0_1013    conda-forge
zstd                      1.5.2                ha95c52a_0    conda-forge

Environment info

active environment : oggm_env_formlist
    active env location : /home/mowglie/.miniconda3/envs/oggm_env_formlist
            shell level : 2
       user config file : /home/mowglie/.condarc
 populated config files : /home/mowglie/.condarc
          conda version : 4.12.0
    conda-build version : not installed
         python version : 3.8.12.final.0
       virtual packages : __linux=5.13.0=0
                          __glibc=2.31=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/mowglie/.miniconda3  (writable)
      conda av data dir : /home/mowglie/.miniconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/mowglie/.miniconda3/pkgs
                          /home/mowglie/.conda/pkgs
       envs directories : /home/mowglie/.miniconda3/envs
                          /home/mowglie/.conda/envs
               platform : linux-64
             user-agent : conda/4.12.0 requests/2.27.1 CPython/3.8.12 Linux/5.13.0-35-generic linuxmint/20.3 glibc/2.31
fmaussion commented 2 years ago

Additional info: the reason I'm reporting here and not on rasterio is that in our docker environments (built without wheels and with pip) everything works as expected.

Additional image where one can see that the output with conda is not OK, like rugged:

image

xylar commented 2 years ago

@fmaussion, thanks for reporting this and for the script to reproduce the problem. I will try to look into it this weekend.

If you want to try to narrow it down in the meantime, one option would be to install older builds of rasterio 1.2.10 (e.g. conda create -y -n test "rasterio=1.2.10=*_0" ...) and see when the problem emerges. This is what I will try first. You can look here: https://github.com/conda-forge/rasterio-feedstock/pulls?q=is%3Apr+is%3Aclosed to get a sense of what has changed in each build since the 1.2.10 release (you likely will need to look at the individual PRs to see which build number corresponds to which change).

If you don't have the time or expertise to do this, I'll see when I can get to it.

it seems unlikely that this is ultimately a conda-forge problem but we should be able to track down which dependency is causing trouble so you can pursue things further with them (or with rasterio).

fmaussion commented 2 years ago

@xylar thanks for having a look. I did check that downgrading to rasterio 1.2.9 solves the problem.

To simplify reproducing the problem I have created a est environment with two env.yml files and the reference data in it, you can download it here: rioproblem.zip (a few kb)

Here is are the outcome in a few commands:

$ mamba env create -f env_latest.yml
$ conda activate test_env_latest
$ python script.py
Traceback (most recent call last):
  File "/home/mowglie/tmp/rioproblem/script.py", line 44, in <module>
    np.testing.assert_allclose(ref, this, atol=1)
  File "/home/mowglie/.miniconda3/envs/test_env_latest/lib/python3.9/site-packages/numpy/testing/_private/utils.py", line 1530, in assert_allclose
    assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
  File "/home/mowglie/.miniconda3/envs/test_env_latest/lib/python3.9/site-packages/numpy/testing/_private/utils.py", line 844, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Not equal to tolerance rtol=1e-07, atol=1

Mismatched elements: 15466 / 18126 (85.3%)
Max absolute difference: 65
Max relative difference: 0.02263231
 x: array([[2596, 2595, 2610, ..., 2583, 2568, 2555],
       [2565, 2569, 2582, ..., 2565, 2548, 2531],
       [2539, 2547, 2557, ..., 2545, 2526, 2507],...
 y: array([[2598, 2597, 2615, ..., 2584, 2566, 2549],
       [2542, 2551, 2564, ..., 2550, 2526, 2502],
       [2542, 2551, 2564, ..., 2550, 2526, 2502],...
$ conda deactivate
$ mamba env create -f env_down.yml
$ conda activate test_env_down
$ python script.py
(all good here)

it seems unlikely that this is ultimately a conda-forge problem but we should be able to track down which dependency is causing trouble so you can pursue things further with them (or with rasterio).

Yes I understand - yet again with latest rasterio and pip I see no problem, but it could be GDAL or some other lib indeed...

xylar commented 2 years ago

@fmaussion, can you try the same tests but with other yaml files that select other recent builds? You can look at https://anaconda.org/conda-forge/rasterio/files to see what the hashes and build numbers are for recent builds (make sure to get the linux-64 version).

xylar commented 2 years ago

@fmaussion, in case you aren't familiar with the difference, there are several builds for each version number (e.g. 1.2.10) and each may have different dependencies (different versions of geos, proj, etc.).

TimoRoth commented 2 years ago

I've now tested this with all linux-64/rasterio-1.2.10_py39* versions that are on https://anaconda.org/conda-forge/rasterio/files. For all, the reproduction-script showed the assertion error. I then continued with all 1.2.9 versions, and they also all showed the error. But I'm pretty sure these have worked in the past, so maybe the issue is not directly caused by rasterio itself?

TimoRoth commented 2 years ago

Sorry, correction: The reference file we transferred via Slack got messed up in the process (No idea what Slack is doing, but it breaks geotiff files sent via it...).

With the correct reference in place now, I can confirm that the error happens with rasterio-1.2.10-py39h2e4b6e6_5. After the following downgrade, the error is gone:

The following packages will be DOWNGRADED:

  cfitsio                                  4.1.0-hd9d235c_0 --> 4.0.0-h9a35b8e_0
  geotiff                                  1.7.1-h509b78c_0 --> 1.7.0-h6593c0a_6
  libgdal                                  3.4.2-hdfc60d4_1 --> 3.4.1-hff5c5e8_5
  libspatialite                           5.0.1-ha867d66_15 --> 5.0.1-h0e567f8_14
  proj                                     9.0.0-h93bde94_1 --> 8.2.1-h277dcde_0
  rasterio                            1.2.10-py39h2e4b6e6_5 --> 1.2.10-py39h0401cea_4
xylar commented 2 years ago

Oh, boy, that's a lot of packages changed. In theory, you'd need to try upgrading each of those packages one at a time. Not sure if that's possible.

TimoRoth commented 2 years ago

My immediate suspicion is the major proj update. But it's not possible to do those updates individually, since there is no version of packages that's build against those combinations.

xylar commented 2 years ago

Okay, yeah, that's one of the difficulties with package management. A major update in proj often requires a version update in all of the packages that have it as a dependency.

xylar commented 2 years ago

I'm afraid I don't have a good way to help here. You've done the detective work I can think of within conda-forge.

TimoRoth commented 2 years ago

Some more detective work: I have just updated our entirely self compiled Docker-Image to the same proj and gdal versions (9.0.0 and 3.4.2 respectively) and everything works just fine there. That kinda only leaves the minor geotiff upgrade. In our case, we're using the internal bundled geotiff version that comes with gdal, which is version 1.7.0.

TimoRoth commented 2 years ago

I now also tried to manually build and use libgeotiff version 1.7.1, and everything works great. So I'm out of ideas which part of that upgrade broke it, but it doesn't seem like it's an upstream issue of any of the libraries, but something related to conda/conda-forge.

xylar commented 2 years ago

Presumably that leave compiler settings or other configuration of one or another package on conda-forge. But I can't think of an easy way to track that down. I can double check if we can downgrade proj < 9 and still make any of the other upgrades. Typically, packages should first be updated and then be rebuilt with the new proj, rather than doing that in one PR so I would expect that would be possible but I can't be sure.

Anyway, I still don't have time to investigate this but it's pretty intriguing...

xylar commented 2 years ago

@fmaussion and @TimoRoth, I believe I've narrowed this to being caused by the update from geotiff 1.7.0 to 1.7.1.

The following (using your test script) works fine:

mamba create -y -n test_rasterio python=3.9 rasterio=1.2.10 proj=9.0.0 cfitsio=4.1.0 geotiff=1.7.0 libgdal=3.4.2
conda activate test_rasterio
python script.py
conda deactivate

The following fails the test:

mamba create -y -n test_rasterio python=3.9 rasterio=1.2.10 proj=9.0.0 cfitsio=4.1.0 geotiff=1.7.1 libgdal=3.4.2
conda activate test_rasterio
python script.py
conda deactivate

@akrherz has been working hard on consistently pinning geotiff (perhaps related to investigating this issue?) and built gdal with geotiff=1.7.0 just a few hours ago. Before that, it seems that packages were getting 1.7.0 or 1.7.1 somewhat arbitrarily as a dependency. That seems to have made debugging this issue a bit more challenging.

I think the fact that you were able to use a different (non-conda-forge) build of geotiff 1.7.1 successfully suggests a problem with that build on conda-forge. Maybe open an issue in that feedstock but feel free to keep this one open until we figure this out.

akrherz commented 2 years ago

The pinning of geotiff is very tight, so I don't suspect the issue I am currently fixing there is related. You are right though, it makes debugging much more tricky as you get some strange combinations of builds due to which geotiff gets picked by conda at build time.

xylar commented 2 years ago

@akrherz, I agree. The problem is presumably with how 1.7.1 was built. If you happen to know anything about CMake and/or libgeotiff, maybe take a look at what changed in 1.7.1 and let us know if you have any suggestions for how to modify the build: https://github.com/OSGeo/libgeotiff/compare/1.7.0...1.7.1

I'm not very fluent in CMake but nothing jumps out at me.

xylar commented 2 years ago

I haven't made any headway on figuring this out. I'm not familiar enough with the reproject() function (or with rasterio in general) to try to come up with a sensible way to figure out where the problem might be cropping up.

I'm afraid I've done all I can unless we can narrow the problem down further.