Reading rasters

Reading files

from girs.rast.raster import Raster
r = RasterReader('D:/tmp/chirps/chirps-v2.0.2016.01.10.tif')
r = RasterReader(filename='D:/tmp/chirps/chirps-v2.0.2016.01.10.tif')
print r.get_filename()

Outputs:

D:/tmp/chirps/chirps-v2.0.2016.01.10.tif

Reading compressed files

ZIP files

The zip-file chirps-v2.0.2016.01.10.tif.zip has only one member chirps-v2.0.2016.01.10.tif.

from girs.rast.raster import Raster
r = RasterReader('D:/tmp/chirps/chirps-v2.0.2016.01.10.tif.zip')
print r.get_filename()
print r.get_rastername()
print r.is_compressed()

Outputs:

D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.10.tif.zip
chirps-v2.0.2016.01.10.tif
True

The zip-file chirps-v2.0.2016.Jan.10th.zip has also only one member chirps-v2.0.2016.01.10.tif. Filename and member name must not be the same.

from girs.rast.raster import Raster
r = RasterReader('D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.Jan.10th.zip')
print r.get_filename()
print r.get_rastername()

Outputs:

D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.Jan.10th.zip
chirps-v2.0.2016.01.10.tif

The zip-file chirps-v2.0.2016.01.zip has two members: chirps-v2.0.2016.01.10.tif and chirps-v2.0.2016.01.10.tif. The member name must be given in this case.

from girs.rast.raster import RasterReader
r = RasterReader('D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.zip',
                  member='chirps-v2.0.2016.01.10.tif')
print r.get_filename()
print r.get_rastername()
r = RasterReader('D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.zip',
                  member='chirps-v2.0.2016.01.11.tif')
print r.get_filename()
print r.get_rastername()

Outputs:

D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.zip
chirps-v2.0.2016.01.10.tif
D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.zip
chirps-v2.0.2016.01.11.tif

GZIP files

Gzip files have only one member, which has the same name as the compressed file. If the compressed file is renamed, the uncompressed file will have the new name without the suffix .gz

from girs.rast.raster import RasterReader
r = RasterReader('D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.10.tif.gz')
print r.get_filename()
print r.get_rastername()

Outputs:

D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.10.tif.gz
D:/tmp/girs/chirps_basin/compressed/chirps-v2.0.2016.01.10.tif