/usr/lib/python2.7/dist-packages/rasterio/windows.py is in python-rasterio 0.36.0-2build5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | """Windows and related functions."""
import functools
import collections
def iter_args(function):
"""Decorator to allow function to take either *args or
a single iterable which gets expanded to *args.
"""
@functools.wraps(function)
def wrapper(*args, **kwargs):
if len(args) == 1 and isinstance(args[0], collections.Iterable):
return function(*args[0])
else:
return function(*args)
return wrapper
def get_data_window(arr, nodata=None):
"""Return a window for the non-nodata pixels within the input array.
Parameters
----------
arr: numpy ndarray, <= 3 dimensions
nodata: number
If None, will either return a full window if arr is not a masked
array, or will use the mask to determine non-nodata pixels.
If provided, it must be a number within the valid range of the dtype
of the input array.
Returns
-------
((row_start, row_stop), (col_start, col_stop))
"""
from rasterio._io import get_data_window
return get_data_window(arr, nodata)
@iter_args
def union(*windows):
"""Union windows and return the outermost extent they cover.
Parameters
----------
windows: list-like of window objects
((row_start, row_stop), (col_start, col_stop))
Returns
-------
((row_start, row_stop), (col_start, col_stop))
"""
from rasterio._io import window_union
return window_union(windows)
@iter_args
def intersection(*windows):
"""Intersect windows and return the innermost extent they cover.
Will raise ValueError if windows do not intersect.
Parameters
----------
windows: list-like of window objects
((row_start, row_stop), (col_start, col_stop))
Returns
-------
((row_start, row_stop), (col_start, col_stop))
"""
from rasterio._io import window_intersection
return window_intersection(windows)
@iter_args
def intersect(*windows):
"""Test if windows intersect.
Parameters
----------
windows: list-like of window objects
((row_start, row_stop), (col_start, col_stop))
Returns
-------
boolean:
True if all windows intersect.
"""
from rasterio._io import windows_intersect
return windows_intersect(windows)
|