import gdal
from tqdm import tqdm_notebook as tqdm
# NOAA GFS gribfile
ingrb = r'D:\Data\GFS_grib\gfs.t00z.pgrb2.0p25.f015'
ds = gdal.Open(ingrb)
b1 = ds.GetRasterBand(1)
# Raster dimensions
xs, ys = b1.XSize, b1.YSize
xs, ys
(1440, 721)
# Blocksize of the file
xbs, ybs = b1.GetBlockSize() # striped file layout, "row-wise"
xbs, ybs
(1440, 1)
gdal.SetCacheMax(0) # Dont cache in order to force disk I/O (not a realistic scenario)
%%timeit
# read column by column
for colnum in range(xs):
data = b1.ReadAsArray(xoff=colnum, yoff=0, win_xsize=1, win_ysize=ys)
1 loop, best of 3: 1.39 s per loop
%%timeit
# read row by row
for rownum in range(ys):
data = b1.ReadAsArray(xoff=0, yoff=rownum, win_xsize=xs, win_ysize=1)
100 loops, best of 3: 10.8 ms per loop
ds = None # close the file