python – Solving Rasterio IO Error and GDAL VRT_SHARED_SOURCE Issues

gdalpythonrasteriovrt

I trying to follow some code on git which uses sentinel hub images code

I'm stuck with one part of the code which opens and reads a grayscale tif image which for some reason returns a rasterio IOerror.

with rasterio.open(img_path) as src:
    gamma0 = src.read(1)

The error message is as follows:

rasterio.errors.RasterioIOError: Read or write failed. /home/vulcanadmin/landstat-sentinel-fusion-installation/landsat-sentinel-fusion/data/processed/sentinel-1/antananarivo/vv-gamma0.tif, band 1: IReadBlock failed at X offset 0, Y offset 0: TIFFReadEncodedStrip() failed.

I checked the image. It isn't corrupt, no issues opening it with gdal.

Read that it has do with setting a GDAL variable, VRT_SHARED_SOURCE=0. I'm trying to figure out how this variable should be set or if anyone has encountered a similar issue and found a resolution. I'm using a linux system so tried setting it as an environment variable export $VRT_SHARED_SOURCE=0 but that didn't work. Neither did it work with the following,

with rasterio.Env(VRT_SHARED_SOURCE=0):
    with rasterio.open('vv-gamma0.tif') as src:
        gamma0 = src.read(1)

Would appreciate any help. Thanks.

Best Answer

Managed to figure out the what was causing the issue after some troubleshooting. I'm using the gdal package from SNAP (Sentinel Application Platform) to run this code. There was a problem with the images i was saving through SNAP's graph processing tool. There was no error message generated but rasterio had trouble opening it. I'd missed the warning messages on the image.

Note the warning message through gdalinfo

Warning 1: TIFFReadDirectory:Bogus "StripByteCounts" field, ignoring and calculating from imagelength

Driver: GTiff/GeoTIFF

Files: vv-gamma0.tif

Size is 4284, 4077

Coordinate System is:

GEOGCRS["WGS 84",

    DATUM["World Geodetic System 1984",

        ELLIPSOID["WGS 84",6378137,298.257223563,

            LENGTHUNIT["metre",1]]],

    PRIMEM["Greenwich",0,

        ANGLEUNIT["degree",0.0174532925199433]],

    CS[ellipsoidal,2],

        AXIS["geodetic latitude (Lat)",north,

            ORDER[1],

            ANGLEUNIT["degree",0.0174532925199433]],

        AXIS["geodetic longitude (Lon)",east,

            ORDER[2],

            ANGLEUNIT["degree",0.0174532925199433]],

    USAGE[

        SCOPE["unknown"],

        AREA["World"],

        BBOX[-90,-180,90,180]],

    ID["EPSG",4326]]

Data axis to CRS axis mapping: 2,1

Origin = (47.326717760975129,-18.718723510025118)

Pixel Size = (0.000089859555849,-0.000089859555849)

Metadata:

  AREA_OR_POINT=Area

  TIFFTAG_IMAGEDESCRIPTION=vv-gamma0

  TIFFTAG_RESOLUTIONUNIT=1 (unitless)

  TIFFTAG_XRESOLUTION=1

  TIFFTAG_YRESOLUTION=1

Image Structure Metadata:

  INTERLEAVE=BAND

Corner Coordinates:

Upper Left  (  47.3267178, -18.7187235) ( 47d19'36.18"E, 18d43' 7.40"S)

Lower Left  (  47.3267178, -19.0850809) ( 47d19'36.18"E, 19d 5' 6.29"S)

Upper Right (  47.7116761, -18.7187235) ( 47d42'42.03"E, 18d43' 7.40"S)

Lower Right (  47.7116761, -19.0850809) ( 47d42'42.03"E, 19d 5' 6.29"S)

Center      (  47.5191969, -18.9019022) ( 47d31' 9.11"E, 18d54' 6.85"S)

Band 1 Block=4284x4077 Type=Float32, ColorInterp=Gray

I had missed setting the Linux shared environment variable after restarting the system. This resolved the error on my part.

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/admin/snap/bin

Related Question