rio_terrain Package¶
terrain
Module¶
-
rio_terrain.core.terrain.
aspect
(arr, res=(1, 1), pcs='compass', neighbors=4)¶ Calculates aspect.
Parameters: - arr (ndarray) – 2D numpy array
- res (tuple) – tuple of raster cell width and height
- north (str, optional) – choice of polar coordinate system
Returns: 2D numpy array representing slope aspect
Return type: aspect (ndarray)
-
rio_terrain.core.terrain.
curvature
(arr, res=(1, 1), neighbors=4)¶ Calculates curvature.
Parameters: - arr (ndarray) – 2D numpy array
- res (tuple) – tuple of raster cell width and height
Returns: 2D numpy array representing surface curvature
Return type: curvature (ndarray)
-
rio_terrain.core.terrain.
slope
(arr, res=(1, 1), units='grade', neighbors=4)¶ Calculates slope.
Parameters: - arr (ndarray) – 2D numpy array
- res (tuple) – tuple of raster cell width and height
- units (str, optional) – choice of grade or degrees
- neighbors (int, optional) – use four or eight neighbors in calculation
Returns: 2D numpy array representing slope
Return type: slope (ndarray)
windowing
Module¶
-
rio_terrain.core.windowing.
block_count
(shape, block_shapes, band=1)¶ Determine the number of blocks in a band
Parameters: - shape (tuple) – tuple containing raster height and width in cells
- block_shapes (tuple) – block shapes for a rasterio read source
- band (int) – raster band to count on
Returns: number of blocks in the raster
Return type: result (int)
-
rio_terrain.core.windowing.
bounds_window
(bounds, affine, constrain=True)¶ Create a full cover rasterio-style window
Parameters: - bounds (tuple) –
- affine (Affine) –
Returns: row_slice (tuple) col_slice (tuple)
-
rio_terrain.core.windowing.
chunk_dim
(dim, chunk_size, min_size=None)¶ Chunk a 1D array
-
rio_terrain.core.windowing.
chunk_dims
(shape, chunk_shape, min_size=None)¶ Chunk a 2D array
-
rio_terrain.core.windowing.
expand_window
(window, src_shape, margin=10)¶ Expand a window by a margin
Parameters: - window (Window) –
- src_shape (tuple) –
- margin (int) –
Returns: result (Window)
-
rio_terrain.core.windowing.
intersect_bounds
(bbox0, bbox1)¶ Get the intersection in w s e n
Parameters: - bbox0 (tuple) –
- bbox1 (tuple) –
Returns: coordinate bounds (w, s, e, n)
Return type: bounds (tuple)
-
rio_terrain.core.windowing.
is_raster_aligned
(src0, src1)¶ Check two rasters for cell alignment
Parameters: - src0 – rasterio read source
- src1 – rasterio read source
Returns: True if the raster source cells align
Return type: result (bool)
-
rio_terrain.core.windowing.
is_raster_congruent
(src0, src1, band=1)¶ Tests two rasters for coincident bounds.
Parameters: - src0 – rasterio read source
- src1 – rasterio read source
Returns: True if the rasters are coincident
Return type: result (bool)
-
rio_terrain.core.windowing.
is_raster_intersecting
(src0, src1)¶ Test two rasters for overlap
-
rio_terrain.core.windowing.
margins
(window0, window1)¶ Size of collar between a pair of windows
Here, window0 is a read window and window1 is a write window
-
rio_terrain.core.windowing.
slices_to_window
(rows, cols)¶
-
rio_terrain.core.windowing.
subsample
(blocks, probability=1.0)¶ Subsample an iterable at a given probability
Parameters: - blocks (iterable) – an iterable of rasterio windows
- probability (float) – fraction of blocks to sample
Yields: block (window) – yield a rasterio window if sampled
-
rio_terrain.core.windowing.
tile_dim
(dim, tile_size, min_size=None)¶ Chunk a range using a minimum chunk size
-
rio_terrain.core.windowing.
tile_dims
(shape, tile_shape, min_size=None)¶ Chunk a 2D array
-
rio_terrain.core.windowing.
tile_grid
(ncols, nrows, blockxsize, blockysize, col_offset=0, row_offset=0, overlap=0)¶ Return a generator containing read and write windows with a specified dimensions and overlap
mgrid returns not as expected so used broadcast_arrays instead base_rows, base_cols = np.mgrid[0:h:blockysize, 0:w:blockxsize]
Parameters: - ncols (int) – raster width in columns
- nrows (int) – raster height in rows
- blockxsize (int) – block width in rows
- blockysize (int) – block height in rows
- col_offset (int) – columns to offset the grid
- row_offset (int) – rows to offset the grid
- overlap (int) – overlap between windows
Yields: window (Window) – tiled windows over a region
-
rio_terrain.core.windowing.
tile_grid_intersection
(src0, src1, blockxsize=None, blockysize=None)¶ Generate tiled windows for the intersection between two grids.
Given two rasters having different dimensions calculate read-window generators for each and a write-window generator for the intersecion.
Parameters: - src0 – rasterio read source
- src1 – rasterio read source
- blockxsize (int) – write-window width
- blockysize (int) – write-window height
Returns: read windows for src0 src1_blocks : read windows for src1 write_blocks : write windows for the intersection affine (Affine) : write raster Affine ncols (int) : write raster width in columns nrows (int) : write raster height in rows
Return type: src0_blocks
-
rio_terrain.core.windowing.
trim
(arr, margins)¶ Trim a 2D array by a set of margins
-
rio_terrain.core.windowing.
window_bounds
(window, affine, offset='center')¶ Create bounds coordinates from a rasterio window
Parameters: - window (Window) –
- affine (Affine) –
- offset (str) –
Returns: coordinate bounds (w, s, e, n)
Return type: bounds (tuple)
statistics
Module¶
-
rio_terrain.core.statistics.
mean
(src, windows, njobs)¶ Calculates the mean of a rasterio source
Parameters: - src – rasterio source
- windows – iterable of read and write windows
- njobs (integer) – number of processing jobs
Returns: mean value
Return type: mean (float)
mean = 140.043719088 ArcGIS = 140.04371922353
-
rio_terrain.core.statistics.
minmax
(src, windows, njobs)¶ Calculates the minimum and maximum values in a rasterio source.
Parameters: - src – rasterio source
- windows – iterable of read and write windows
- njobs (integer) – number of processing jobs
Returns: minimum value src_max (float) : maximum value
Return type: src_min (float)
ArcGIS min = 77.278923034668 ArcGIS max = 218.81454467773
-
rio_terrain.core.statistics.
stddev
(src, mean, windows, njobs)¶ Calculates the standard deviation of a rasterio source
Parameters: - src – rasterio source
- mean – mean value
- windows – iterable of read and write windows
- njobs (integer) – number of processing jobs
Returns: standard deviation
Return type: stddev (float)
stddev = 23.5554506735 ArcGIS = 23.555450665488
focalstatistics
Module¶
-
rio_terrain.core.focalstatistics.
mad
(arr, size=(3, 3))¶ Calculates the median absolute deviation (MAD) for an array
-
rio_terrain.core.focalstatistics.
std
(arr, size=(3, 3))¶ Calculates the standard deviation for a neighborhood
-
rio_terrain.core.focalstatistics.
std_ndimage
(arr, size=(3, 3))¶ Calculates the standard deviation for a neighborhood