None
Note
This tutorial was generated from an IPython notebook that can be downloaded here.
Usage example
import focal_stats
import rasterio as rio
import matplotlib.pyplot as plt
import numpy as np
import os
Matplotlib is building the font cache; this may take a moment.
os.chdir("../../../")
Loading raster (containing water table depth (Fan et al., 2017)).
with rio.open("data/wtd.tif") as f:
a = f.read(1).astype(np.float64)
a[a == -999.9] = np.nan
Inspecting the data
plt.imshow(a, cmap='Blues', vmax=100)
plt.title("Water table depth")
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7ff3c4aec550>
Focal statistics
Calculation of the focal mean:
plt.imshow(focal_stats.focal_mean(a, window_size=15), vmax=100, cmap="Blues")
<matplotlib.image.AxesImage at 0x7ff3c4184b50>
This looks quite similar to the input raster, but with smoothing applied. Let’s try a higher window_size, which should increase the smoothing
plt.imshow(focal_stats.focal_mean(a, window_size=101), vmax=100, cmap="Blues")
<matplotlib.image.AxesImage at 0x7ff3c4112c90>
This same functionality can be used to reduce the shape of the raster based on this window_size.
x = focal_stats.focal_mean(a, window_size=108, reduce=True)
plt.imshow(x, vmax=100, cmap="Blues")
<matplotlib.image.AxesImage at 0x7ff3c4084b90>
The shape of this new raster is exactly 108 times smaller than the input raster. Note that for this to work both x and y-axes need to be divisible by the window size.