Page 1 of 1

add_coastlines.sh: cannot identify input image file

Posted: Wed Sep 21, 2022 12:09 am
by rrabin
Hello,

I get the following error when executing the command:

add_coastlines.sh output3.tif --add-coastlines --add-borders --borders-resolution=h --add-grid --grid-D 1.0 1.0
PIL.UnidentifiedImageError: cannot identify image file 'output3.tif'

The file output3.tif was created with the following command:
rio warp image.tif -o output3.tif --bounds -80 29 -60 49 --res 0.02 –dst-crs ‘+proj=longlat +ellps=WGS84’

image.tif was created from geo2grid.sh

I have placed image.tif, output3.tif in ftp://pub/incoming

Thanks! -Bob

Re: add_coastlines.sh: cannot identify input image file

Posted: Wed Sep 21, 2022 10:24 am
by davidh
Hi Bob,

If you run the output tif through gdalinfo you'll see this at the bottom:

Band 1 Block=256x256 Type=Byte, ColorInterp=Gray
Band 2 Block=256x256 Type=Byte, ColorInterp=Undefined

It seems like rasterio (rio) is losing the alpha definition of the second band for some reason. I would consider this a bug that you should file with rasterio. My guess is it will happen with any LA (Luminance Alpha) geotiff being processed with GDAL warp. That said, a quick fix is to add:

Code: Select all

--co ALPHA=YES
Let me know how it goes.

Dave

Re: add_coastlines.sh: cannot identify input image file

Posted: Wed Sep 21, 2022 12:30 pm
by rrabin
Hi Dave,

Thank you! The quick fix works! I'll report the bug to rastario.

Best wishes,
-Bob

Re: add_coastlines.sh: cannot identify input image file

Posted: Wed Sep 21, 2022 2:14 pm
by rrabin
Hi Dave,

I updated the Python environment to 3.8 (from 3.7). The error doesn't occur with version 3.8.

Thanks!

-Bob

Re: add_coastlines.sh: cannot identify input image file

Posted: Wed Sep 21, 2022 2:22 pm
by rrabin
Correction: the error still occurs with version 3.8

Re: add_coastlines.sh: cannot identify input image file

Posted: Thu Sep 22, 2022 10:33 am
by davidh
Bob,

The bug is not in Python or in Polar2Grid/Geo2Grid, it is specifically in the rasterio python package or the GDAL C++ library that rasterio uses underneath. You can see what version of rasterio is available here:

https://pypi.org/project/rasterio/

But know that I was using the latest version when I tested your example and got the same result so it is not a bug that is fixed. If you'd like to file a bug report for the rasterio project then you can do so here:

https://github.com/rasterio/rasterio/issues

You may want to search through the existing issues to see if someone else has run into the same issue.

Dave