1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
# Benchmark for read of raster data to ndarray
import timeit
# GDAL
s = """
src = gdal.Open('tests/data/RGB.byte.tif')
arr = src.GetRasterBand(1).ReadAsArray()
src = None
"""
n = 1000
t = timeit.timeit(s, setup='from osgeo import gdal', number=n)
print("GDAL:")
print("%f usec\n" % (1000*t/n))
# Rasterio
s = """
with rasterio.open('tests/data/RGB.byte.tif') as src:
arr = src.read(1, masked=False)
"""
t = timeit.timeit(s, setup='import rasterio', number=n)
print("Rasterio:")
print("%f usec\n" % (1000*t/n))
# GDAL Extras
s = """
src = gdal.Open('tests/data/RGB.byte.tif')
transform = src.GetGeoTransform()
srs = osr.SpatialReference()
srs.ImportFromWkt(src.GetProjectionRef())
wkt = srs.ExportToWkt()
proj = srs.ExportToProj4()
arr = src.GetRasterBand(1).ReadAsArray()
src = None
"""
n = 1000
t = timeit.timeit(s, setup='from osgeo import gdal; from osgeo import osr', number=n)
print("GDAL + Extras:\n")
print("%f usec\n" % (1000*t/n))
# Rasterio
s = """
with rasterio.open('tests/data/RGB.byte.tif') as src:
transform = src.transform
proj = src.crs
wkt = src.crs_wkt
arr = src.read(1, masked=False)
"""
t = timeit.timeit(s, setup='import rasterio', number=n)
print("Rasterio:\n")
print("%f usec\n" % (1000*t/n))
|