Last active
March 14, 2020 07:17
-
-
Save underchemist/6c5f521d155d3dc1460201feba8251fd to your computer and use it in GitHub Desktop.
rasterio inspired block_windows implementation using itertools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import product, chain | |
def block_windows(src, xsize, ysize): | |
height, width = src.shape | |
nrows, rmod = divmod(height, ysize) | |
ncols, cmod = divmod(width, xsize) | |
offsets = product(range(0, width, xsize), range(0, height, ysize)) | |
sizes = product(chain([xsize]*ncols, [cmod]), chain([ysize]*nrows, [rmod])) | |
for (xoff, yoff), (xsize, ysize) in zip(offsets, sizes): | |
yield xoff, yoff, xsize, ysize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment