conda-forge / rasterio-feedstock

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

Rasterio open .png files: resample crashes the kernel, show() shows only 1 band #180

Closed feefladder closed 3 years ago

feefladder commented 3 years ago

Issue:

I think this is a rasterio issue, but their page said I had to post it here. Opening .png file with rasterio and writing it to the georeference of a .tif file. From this thread: resampling crashes the kernel, unless saved and loaded again, then everything is fine.

import rasterio as rio
from rasterio.enums import Resampling
from rasterio.plot import show

#Input png image, to convert as geotiff
img = rio.open('/path/to.png')

#this crashes the kernel:
read(out_shape=(3,img.shape[0]/4,img.shape[1]*4), resampling=Resampling.nearest)

#fine from here:
img = img.read([1,2,3])
img = img.astype('uint16')
show(img) #shows true color

#write the png to a referenced .tif
with rio.open('/path/to/reference.tif') as naip:
    #open georeferenced.tif for writing
    with rio.open(
        'georeferenced.tif',
        'w',
        driver='GTiff',
        count=img.shape[0],
        height=img.shape[1],
        width=img.shape[2],
        dtype=img.dtype,
        crs=naip.crs,
        transform=naip.transform,
        ) as dst:
            dst.write(img)

with rio.open('georeferenced.tif') as limg:
        show(limg) #1 band only shows
        show(limg.read([1,2,3])) #shows true color
        #resample so pixels overlap with reference
        limg = limg.read(out_shape=(3,naip.shape[0],naip.shape[1]),
                         resampling=Resampling.nearest) # no error
        with rio.open('resampled.tif','w', 
                     driver='GTiff',
                     count=limg.shape[0],
                     height=limg.shape[1],
                     width=limg.shape[2],
                     dtype=limg.dtype,
                     crs=naip.crs,
                     transform=naip.transform,
                     ) as dst:
            dst.write(limg)


Environment (conda list):

``` # packages in environment at /home/joempie/miniconda3/envs/LDD: # # 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 alabaster 0.7.12 py_0 conda-forge amqp 5.0.2 pyhd8ed1ab_0 conda-forge appdirs 1.4.4 pyh9f0ad1d_0 conda-forge argh 0.26.2 pyh9f0ad1d_1002 conda-forge astroid 2.4.2 py38h32f6830_1 conda-forge async_generator 1.10 py_0 conda-forge atomicwrites 1.4.0 pyh9f0ad1d_0 conda-forge attrs 20.3.0 pyhd3deb0d_0 conda-forge autopep8 1.5.4 pyh9f0ad1d_0 conda-forge babel 2.9.0 pyhd3deb0d_0 conda-forge backcall 0.2.0 pyh9f0ad1d_0 conda-forge backports 1.0 py_2 conda-forge backports.functools_lru_cache 1.6.1 py_0 conda-forge bcrypt 3.2.0 py38h1e0a361_1 conda-forge billiard 3.6.3.0 py38h1e0a361_2 conda-forge black 20.8b1 py_1 conda-forge bleach 3.2.1 pyh9f0ad1d_0 conda-forge bokeh 2.2.3 py38h32f6830_0 conda-forge boost-cpp 1.74.0 h9359b55_0 conda-forge brotlipy 0.7.0 py38h8df0ef7_1001 conda-forge bzip2 1.0.8 h516909a_3 conda-forge c-ares 1.16.1 h516909a_3 conda-forge ca-certificates 2020.11.8 ha878542_0 conda-forge cachetools 4.1.1 py_0 conda-forge cairo 1.16.0 h9f066cc_1006 conda-forge celery 5.0.2 pyhd8ed1ab_0 conda-forge certifi 2020.11.8 py38h578d9bd_0 conda-forge cffi 1.14.3 py38h1bdcb99_1 conda-forge cfitsio 3.470 hb418390_7 conda-forge cftime 1.2.1 py38hab2c0dc_1 conda-forge chardet 3.0.4 py38h924ce5b_1008 conda-forge click 7.1.2 pyh9f0ad1d_0 conda-forge click-didyoumean 0.0.3 pyh8c360ce_0 conda-forge click-plugins 1.1.1 py_0 conda-forge click-repl 0.1.6 py_0 conda-forge cligj 0.7.0 py_0 conda-forge cloudpickle 1.6.0 py_0 conda-forge cryptography 3.2.1 py38h7699a38_0 conda-forge curl 7.71.1 he644dc0_8 conda-forge cycler 0.10.0 py_2 conda-forge cytoolz 0.11.0 py38h1e0a361_1 conda-forge dask 2.30.0 py_0 conda-forge dask-core 2.30.0 py_0 conda-forge dataclasses 0.7 pyhb2cacf7_7 conda-forge datacube 1.8.3 py_1 conda-forge dbus 1.13.6 hfdff14a_1 conda-forge decorator 4.4.2 py_0 conda-forge defusedxml 0.6.0 py_0 conda-forge descartes 1.1.0 py_4 conda-forge diff-match-patch 20200713 pyh9f0ad1d_0 conda-forge distributed 2.30.1 py38h578d9bd_0 conda-forge docutils 0.16 py38h924ce5b_2 conda-forge entrypoints 0.3 pyhd8ed1ab_1003 conda-forge expat 2.2.9 he1b5a44_2 conda-forge fiona 1.8.17 py38h676c6b2_1 conda-forge flake8 3.8.4 py_0 conda-forge fontconfig 2.13.1 h7e3eb15_1002 conda-forge freetype 2.10.4 h7ca028e_0 conda-forge freexl 1.0.5 h516909a_1002 conda-forge fsspec 0.8.4 py_0 conda-forge future 0.18.2 py38h578d9bd_2 conda-forge gdal 3.1.4 py38h9edfc58_0 conda-forge geocube 0.0.14 pyhd8ed1ab_1 conda-forge geopandas 0.8.1 py_0 conda-forge geos 3.8.1 he1b5a44_0 conda-forge geotiff 1.6.0 h5d11630_3 conda-forge gettext 0.19.8.1 hf34092f_1004 conda-forge giflib 5.2.1 h36c2ea0_2 conda-forge glib 2.66.2 h58526e2_0 conda-forge gst-plugins-base 1.14.5 h0935bb2_2 conda-forge gstreamer 1.14.5 h36ae1b5_2 conda-forge hdf4 4.2.13 hf30be14_1003 conda-forge hdf5 1.10.6 nompi_h1022a3e_1110 conda-forge heapdict 1.0.1 py_0 conda-forge helpdev 0.7.1 pyhd8ed1ab_0 conda-forge icu 67.1 he1b5a44_0 conda-forge idna 2.10 pyh9f0ad1d_0 conda-forge imagesize 1.2.0 py_0 conda-forge importlib-metadata 2.0.0 py_1 conda-forge importlib_metadata 2.0.0 1 conda-forge intervaltree 3.0.2 py_0 conda-forge ipykernel 5.3.4 py38h1cdfbd6_1 conda-forge ipython 7.19.0 py38h81c977d_0 conda-forge ipython_genutils 0.2.0 py_1 conda-forge isort 5.6.4 py_0 conda-forge jedi 0.17.2 py38h578d9bd_1 conda-forge jeepney 0.5.0 pyhd8ed1ab_0 conda-forge jinja2 2.11.2 pyh9f0ad1d_0 conda-forge jpeg 9d h36c2ea0_0 conda-forge json-c 0.13.1 hbfbb72e_1002 conda-forge jsonschema 3.2.0 py_2 conda-forge jupyter_client 6.1.7 py_0 conda-forge jupyter_core 4.6.3 py38h578d9bd_2 conda-forge jupyterlab_pygments 0.1.2 pyh9f0ad1d_0 conda-forge kealib 1.4.13 h33137a7_1 conda-forge keyring 21.5.0 py38h578d9bd_0 conda-forge kiwisolver 1.3.1 py38h82cb98a_0 conda-forge kombu 5.0.2 py38h578d9bd_1 conda-forge krb5 1.17.1 hfafb76e_3 conda-forge lark-parser 0.10.0 pyh9f0ad1d_0 conda-forge lazy-object-proxy 1.4.3 py38h1e0a361_2 conda-forge lcms2 2.11 hcbb858e_1 conda-forge ld_impl_linux-64 2.35.1 hed1e6ac_0 conda-forge libblas 3.9.0 2_openblas conda-forge libcblas 3.9.0 2_openblas conda-forge libclang 10.0.1 default_hde54327_1 conda-forge libcurl 7.71.1 hcdd3856_8 conda-forge libdap4 3.20.6 h1d1bd15_1 conda-forge libedit 3.1.20191231 he28a2e2_2 conda-forge libev 4.33 h516909a_1 conda-forge libevent 2.1.10 hcdb4288_3 conda-forge libffi 3.2.1 he1b5a44_1007 conda-forge libgcc-ng 9.3.0 h5dbcf3e_17 conda-forge libgdal 3.1.4 h670eac6_0 conda-forge libgfortran-ng 9.3.0 he4bcb1c_17 conda-forge libgfortran5 9.3.0 he4bcb1c_17 conda-forge libglib 2.66.2 hbe7bbb4_0 conda-forge libgomp 9.3.0 h5dbcf3e_17 conda-forge libiconv 1.16 h516909a_0 conda-forge libkml 1.3.0 h74f7ee3_1012 conda-forge liblapack 3.9.0 2_openblas conda-forge libllvm10 10.0.1 he513fc3_3 conda-forge libnetcdf 4.7.4 nompi_hefab0ff_106 conda-forge libnghttp2 1.41.0 h8cfc5f6_2 conda-forge libopenblas 0.3.12 pthreads_h4812303_1 conda-forge libpng 1.6.37 h21135ba_2 conda-forge libpq 12.3 h5513abc_2 conda-forge libsodium 1.0.18 h36c2ea0_1 conda-forge libspatialindex 1.9.3 he1b5a44_3 conda-forge libspatialite 5.0.0 h4dde289_0 conda-forge libssh2 1.9.0 hab1572f_5 conda-forge libstdcxx-ng 9.3.0 h2ae2ef3_17 conda-forge libtiff 4.1.0 h4f3a223_6 conda-forge libuuid 2.32.1 h14c3975_1000 conda-forge libwebp-base 1.1.0 h36c2ea0_3 conda-forge libxcb 1.13 h14c3975_1002 conda-forge libxkbcommon 0.10.0 he1b5a44_0 conda-forge libxml2 2.9.10 h68273f3_2 conda-forge locket 0.2.0 py_2 conda-forge lz4-c 1.9.2 he1b5a44_3 conda-forge markupsafe 1.1.1 py38h8df0ef7_2 conda-forge matplotlib 3.3.3 py38h578d9bd_0 conda-forge matplotlib-base 3.3.3 py38h5c7f4ab_0 conda-forge mccabe 0.6.1 py_1 conda-forge mistune 0.8.4 py38h25fe258_1002 conda-forge msgpack-python 1.0.0 py38hbf85e49_2 conda-forge munch 2.5.0 py_0 conda-forge mypy_extensions 0.4.3 py38h32f6830_2 conda-forge mysql-common 8.0.21 2 conda-forge mysql-libs 8.0.21 hf3661c5_2 conda-forge nbclient 0.5.1 py_0 conda-forge nbconvert 6.0.7 py38h32f6830_2 conda-forge nbformat 5.0.8 py_0 conda-forge ncurses 6.2 h58526e2_3 conda-forge nest-asyncio 1.4.3 pyhd8ed1ab_0 conda-forge netcdf4 1.5.4 nompi_py38hec8b9af_103 conda-forge nspr 4.29 he1b5a44_1 conda-forge nss 3.58 h27285de_1 conda-forge numpy 1.19.4 py38hf0fd68c_1 conda-forge numpydoc 1.1.0 py_1 conda-forge olefile 0.46 pyh9f0ad1d_1 conda-forge openjpeg 2.3.1 h981e76c_3 conda-forge openssl 1.1.1h h516909a_0 conda-forge packaging 20.4 pyh9f0ad1d_0 conda-forge pandas 1.1.4 py38h0ef3d22_0 conda-forge pandoc 2.11.1.1 h36c2ea0_0 conda-forge pandocfilters 1.4.2 py_1 conda-forge paramiko 2.7.2 pyh9f0ad1d_0 conda-forge parso 0.7.0 pyh9f0ad1d_0 conda-forge partd 1.1.0 py_0 conda-forge pathspec 0.8.1 pyhd3deb0d_0 conda-forge pathtools 0.1.2 py_1 conda-forge pcre 8.44 he1b5a44_0 conda-forge pexpect 4.8.0 pyh9f0ad1d_2 conda-forge pickleshare 0.7.5 py_1003 conda-forge pillow 8.0.1 py38h70fbd49_0 conda-forge pip 20.2.4 py_0 conda-forge pixman 0.40.0 h36c2ea0_0 conda-forge pluggy 0.13.1 py38h924ce5b_3 conda-forge poppler 0.89.0 h4190859_1 conda-forge poppler-data 0.4.10 0 conda-forge postgresql 12.3 h8573dbc_2 conda-forge proj 7.1.1 h966b41f_3 conda-forge prompt-toolkit 3.0.8 pyha770c72_0 conda-forge prompt_toolkit 3.0.8 hd8ed1ab_0 conda-forge psutil 5.7.3 py38h8df0ef7_0 conda-forge psycopg2 2.8.6 py38h766eaa4_1 conda-forge pthread-stubs 0.4 h14c3975_1001 conda-forge ptyprocess 0.6.0 py_1001 conda-forge pycodestyle 2.6.0 pyh9f0ad1d_0 conda-forge pycparser 2.20 pyh9f0ad1d_2 conda-forge pydocstyle 5.1.1 py_0 conda-forge pyflakes 2.2.0 pyh9f0ad1d_0 conda-forge pygments 2.7.2 py_0 conda-forge pylint 2.6.0 py38h32f6830_1 conda-forge pyls-black 0.4.6 pyh9f0ad1d_0 conda-forge pyls-spyder 0.1.1 pyhd3deb0d_0 conda-forge pynacl 1.4.0 py38h1e0a361_2 conda-forge pyopenssl 19.1.0 py_1 conda-forge pyparsing 2.4.7 pyh9f0ad1d_0 conda-forge pyproj 2.6.1.post1 py38h56787f0_3 conda-forge pyqt 5.12.3 py38ha8c2ead_4 conda-forge pyqt5-sip 4.19.18 pypi_0 pypi pyqtchart 5.12 pypi_0 pypi pyqtwebengine 5.12.1 pypi_0 pypi pyrsistent 0.17.3 py38h25fe258_1 conda-forge pysocks 1.7.1 py38h924ce5b_2 conda-forge python 3.8.6 h852b56e_0_cpython conda-forge python-dateutil 2.8.1 py_0 conda-forge python-jsonrpc-server 0.4.0 pyh9f0ad1d_0 conda-forge python-language-server 0.36.1 pyhd8ed1ab_1 conda-forge python_abi 3.8 1_cp38 conda-forge pytz 2020.4 pyhd8ed1ab_0 conda-forge pyxdg 0.26 py_0 conda-forge pyyaml 5.3.1 py38h8df0ef7_1 conda-forge pyzmq 20.0.0 py38h1d1b12f_1 conda-forge qdarkstyle 2.8.1 pyhd8ed1ab_2 conda-forge qt 5.12.9 h1f2b2cb_0 conda-forge qtawesome 1.0.1 pyh9f0ad1d_0 conda-forge qtconsole 4.7.7 pyh9f0ad1d_0 conda-forge qtpy 1.9.0 py_0 conda-forge rasterio 1.1.8 py38h37fbd03_0 conda-forge readline 8.0 he28a2e2_2 conda-forge redis-py 3.5.3 pyh9f0ad1d_0 conda-forge regex 2020.11.13 py38h25fe258_0 conda-forge requests 2.25.0 pyhd3deb0d_0 conda-forge richdem 0.3.4 py38hb3f55d8_0 conda-forge rioxarray 0.1.1 pyhd8ed1ab_0 conda-forge rope 0.18.0 pyh9f0ad1d_0 conda-forge rtree 0.9.4 py38h02d302b_2 conda-forge scipy 1.5.3 py38hb2138dd_0 conda-forge secretstorage 3.2.0 py38h578d9bd_0 conda-forge setuptools 49.6.0 py38h924ce5b_2 conda-forge shapely 1.7.1 py38hc7361b7_1 conda-forge six 1.15.0 pyh9f0ad1d_0 conda-forge snowballstemmer 2.0.0 py_0 conda-forge snuggs 1.4.7 py_0 conda-forge sortedcontainers 2.3.0 pyhd8ed1ab_0 conda-forge sphinx 3.3.1 pyhd8ed1ab_0 conda-forge sphinxcontrib-applehelp 1.0.2 py_0 conda-forge sphinxcontrib-devhelp 1.0.2 py_0 conda-forge sphinxcontrib-htmlhelp 1.0.3 py_0 conda-forge sphinxcontrib-jsmath 1.0.1 py_0 conda-forge sphinxcontrib-qthelp 1.0.3 py_0 conda-forge sphinxcontrib-serializinghtml 1.1.4 py_0 conda-forge spyder 4.2.0 py38h578d9bd_0 conda-forge spyder-kernels 1.10.0 py38h578d9bd_0 conda-forge sqlalchemy 1.3.20 py38h1e0a361_0 conda-forge sqlite 3.33.0 h4cf870e_1 conda-forge sshtunnel 0.2.1 py_0 conda-forge tblib 1.6.0 py_0 conda-forge testpath 0.4.4 py_0 conda-forge three-merge 0.1.1 pyh9f0ad1d_0 conda-forge tiledb 2.1.2 h17508cd_1 conda-forge tk 8.6.10 hed695b0_1 conda-forge toml 0.10.2 pyhd8ed1ab_0 conda-forge toolz 0.11.1 py_0 conda-forge tornado 6.1 py38h25fe258_0 conda-forge tqdm 4.51.0 pyh9f0ad1d_0 conda-forge traitlets 5.0.5 py_0 conda-forge typed-ast 1.4.1 py38h25fe258_1 conda-forge typing_extensions 3.7.4.3 py_0 conda-forge tzcode 2020a h516909a_0 conda-forge ujson 4.0.1 py38h950e882_1 conda-forge urllib3 1.25.11 py_0 conda-forge vine 5.0.0 pyhd8ed1ab_1 conda-forge watchdog 0.10.3 py38h32f6830_2 conda-forge wcwidth 0.2.5 pyh9f0ad1d_2 conda-forge webencodings 0.5.1 py_1 conda-forge wheel 0.35.1 pyh9f0ad1d_0 conda-forge wrapt 1.11.2 py38h1e0a361_1 conda-forge wurlitzer 2.0.0 py38h32f6830_2 conda-forge xarray 0.16.1 py_0 conda-forge xerces-c 3.2.3 hfe33f54_1 conda-forge xlrd 1.2.0 pyh9f0ad1d_1 conda-forge xorg-kbproto 1.0.7 h14c3975_1002 conda-forge xorg-libice 1.0.10 h516909a_0 conda-forge xorg-libsm 1.2.3 h84519dc_1000 conda-forge xorg-libx11 1.6.12 h516909a_0 conda-forge xorg-libxau 1.0.9 h14c3975_0 conda-forge xorg-libxdmcp 1.1.3 h516909a_0 conda-forge xorg-libxext 1.3.4 h516909a_0 conda-forge xorg-libxrender 0.9.10 h516909a_1002 conda-forge xorg-renderproto 0.11.1 h14c3975_1002 conda-forge xorg-xextproto 7.3.0 h14c3975_1002 conda-forge xorg-xproto 7.0.31 h14c3975_1007 conda-forge xz 5.2.5 h516909a_1 conda-forge yaml 0.2.5 h516909a_0 conda-forge yapf 0.30.0 pyh9f0ad1d_0 conda-forge zeromq 4.3.3 h58526e2_2 conda-forge zict 2.0.0 py_0 conda-forge zipp 3.4.0 py_0 conda-forge zlib 1.2.11 h516909a_1010 conda-forge zstd 1.4.5 h6597ccf_2 conda-forge ```


Details about conda and system ( conda info ):

``` active environment : LDD active env location : /home/joempie/miniconda3/envs/LDD shell level : 2 user config file : /home/joempie/.condarc populated config files : /home/joempie/.condarc conda version : 4.9.2 conda-build version : not installed python version : 3.8.3.final.0 virtual packages : __cuda=11.0=0 __glibc=2.27=0 __unix=0=0 __archspec=1=x86_64 base environment : /home/joempie/miniconda3 (writable) 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/joempie/miniconda3/pkgs /home/joempie/.conda/pkgs envs directories : /home/joempie/miniconda3/envs /home/joempie/.conda/envs platform : linux-64 user-agent : conda/4.9.2 requests/2.25.0 CPython/3.8.3 Linux/4.15.0-88-generic ubuntu/18.04.5 glibc/2.27 UID:GID : 1000:1000 netrc file : None offline mode : False ```
xylar commented 3 years ago

Unless this is something specifically wrong with the conda-forge recipe for rasterio, and not rasterio itself, I agree that this is an issue for "upstream" (the rasterio repo itself). I also noticed that their issue template points people here for anything to do with the conda-forge package, but that is not fair to us. I guess they just don't want to support conda-forge installations so you might get more attention from them if you are able to reproduce your problem with a whole environment (including rasterio) from pypi.

Anyway, I don't think we'll be much help here...

sgillies commented 3 years ago

this crashes the kernel:

read(out_shape=(3,img.shape[0]/4,img.shape[1]*4), resampling=Resampling.nearest)

@Joeperdefloep I cannot reproduce this with any file that I have. Can you provide a PNG that will crash?

@xylar there was a time where most of the issues reported to the rasterio issue tracker by conda users were entirely explained by incrementally updated and inconsistent conda environments where the solution was to delete them and recreate them from scratch. That's why the rasterio project points conda users here.

Here's my assumption in all things open source: errors multiply downstream. If a user has a problem with a distro package, the cause is most likely in the distro package, not the upstream software. If you've reproduced the user's environment and found the error in rasterio, please do bring it upstream.

xylar commented 3 years ago

@Joeperdefloep, I think there were a few issues with the example you posted. First, I think you want img.read() instead of just read(), right? Second, you need to be doing integer division by 4 to get an integer shape.

I'm able to reproduce a seg fault with just this code:

#!/usr/bin/env python

import rasterio as rio
from rasterio.enums import Resampling
from rasterio.plot import show

#Input png image, to convert as geotiff
img = rio.open('test.png')

#this crashes the kernel:
img = img.read(out_shape=(3, img.shape[0]//4,img.shape[1]*4), resampling=Resampling.nearest)

Based on this example in the documentation: https://rasterio.readthedocs.io/en/latest/topics/resampling.html#up-and-downsampling, it looks like the first element in the out_shape tuple needs to be the number of color channels, given by img.count. For me, print(img.count) gives 4, so that seems likely to be the source of the problem. For example, the following worked find for me.

#!/usr/bin/env python

import rasterio as rio
from rasterio.enums import Resampling
from rasterio.plot import show

#Input png image, to convert as geotiff
img = rio.open('test.png')

print(img.count)
# works fine:
img = img.read(out_shape=(img.count, img.shape[0]//4,img.shape[1]*4), 
               resampling=Resampling.nearest)

As @sgillies, said, it would be helpful to have an example image you're using to be able to reproduce the problem.

xylar commented 3 years ago

@sgillies

there was a time where most of the issues reported to the rasterio issue tracker by conda users were entirely explained by incrementally updated and inconsistent conda environments where the solution was to delete them and recreate them from scratch. That's why the rasterio project points conda users here.

Here's my assumption in all things open source: errors multiply downstream. If a user has a problem with a distro package, the cause is most likely in the distro package, not the upstream software. If you've reproduced the user's environment and found the error in rasterio, please do bring it upstream.

I'm sympathetic to this. It is, indeed, common for users to mix and match conda package from different channels and distributions in ways that cause problems. In this particular case, though, it seems very unlikely that this has anything to do with conda-forge and indeed it seems likely that @Joeperdefloep just needs a little help following the documentation. To me, it seems incorrect to point users straight to conda-forge if they are using the conda-forge package because this means that we may get flooded with questions that are completely unrelated to the distro, as this one was. It seems like you are tacitly assuming our time is less valuable than yours in terms of who has to decide whether a given issue is more likely to be a distro issue vs. a package issue or a user error.

feefladder commented 3 years ago

index Hadocha_DEM.tif.zip OK. I added some files. thank you for pointing out the problems in my code and the quick responses!. I actually opened this issue because show() only shows one band, and then in debugging I ran into a ?segfault?. This seems now only a minor issue, but it appears to be because of a type conversion. so:

import rasterio as rio
from rasterio.enums import Resampling
from rasterio.plot import show
#Input png image, to convert as geotiff
img = rio.open('index.png')
with rio.open('Hadocha_DEM.tif') as ref:
    #will only show one band:
    fimg = img.read().astype('uint16')
    with rio.open(
        'uint16.tif',
        'w',
        driver='GTiff',
        count=fimg.shape[0],
        height=fimg.shape[1],
        width=fimg.shape[2],
        dtype=fimg.dtype,
        crs=ref.crs,
        transform=ref.transform
        ) as dst:
            dst.write(fimg)
    #will work fine:
    img = img.read()
    with rio.open(
        'uint8.tif',
        'w',
        driver='GTiff',
        count=img.shape[0],
        height=img.shape[1],
        width=img.shape[2],
        dtype=img.dtype,
        crs=ref.crs,
        transform=ref.transform
        ) as dst:
            dst.write(img)
#one band:
show(rio.open('uint16.tif'))
#full color:
show(rio.open('uint8.tif'))
show(rio.open('uint16.tif').read())

where the problem is that it only shows one band

xylar commented 3 years ago

@Joeperdefloep, I'm happy to play around with your example but this issue definitely doesn't sound to me like anything conda-forge related and instead like something to report to: https://github.com/mapbox/rasterio/issues

sgillies commented 3 years ago

I agree with @xylar but this looks like a usage question. Can you bring it to https://rasterio.groups.io/g/main/topics @Joeperdefloep? Also provide more details about index.png please or better yet, the file itself.