mirror of
https://github.com/rasterio/rasterio.git
synced 2026-02-01 14:34:43 +00:00
parent
824a8dc40d
commit
34c4f3d2b9
@ -160,7 +160,10 @@ def get_data_window(arr, nodata=None):
|
||||
# Otherwise retrieve mask from array (if it is masked)
|
||||
# Finally try returning a full window (nodata=None and nothing in arr is masked)
|
||||
if nodata is not None:
|
||||
arr_mask = arr != nodata
|
||||
if np.isnan(nodata):
|
||||
arr_mask = ~np.isnan(arr)
|
||||
else:
|
||||
arr_mask = arr != nodata
|
||||
elif np.ma.is_masked(arr):
|
||||
arr_mask = ~np.ma.getmask(arr)
|
||||
else:
|
||||
@ -180,10 +183,10 @@ def get_data_window(arr, nodata=None):
|
||||
v.append((nz.min(), nz.max() + 1))
|
||||
else:
|
||||
v.append((0, 0))
|
||||
|
||||
|
||||
if arr_mask.ndim == 1:
|
||||
v.append((0, 0))
|
||||
|
||||
|
||||
return Window.from_slices(*v)
|
||||
|
||||
|
||||
|
||||
@ -508,6 +508,14 @@ def test_data_window_nodata():
|
||||
assert window == Window.from_slices((1, 3), (0, 3))
|
||||
|
||||
|
||||
def test_data_window_nodata_nan():
|
||||
"""Get window of arr with nodata."""
|
||||
arr = np.ones((3, 3))
|
||||
arr[0, :] = np.nan
|
||||
window = get_data_window(arr, nodata=np.nan)
|
||||
assert window == Window.from_slices((1, 3), (0, 3))
|
||||
|
||||
|
||||
def test_data_window_novalid():
|
||||
"""Get window of arr with nodata."""
|
||||
arr = np.ones((3, 3))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user