Closed feefladder closed 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...
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.
@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.
@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.
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
@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
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.
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.
Environment (
conda list
):Details about
conda
and system (conda info
):