urbanflow.utils.courtyard_utils¶
courtyard_utils.py
Utilities for loading and generating courtyard files
Functions
|
Automatically label enclosed empty cells as courtyards. |
- urbanflow.utils.courtyard_utils.add_auto_courtyards(grid, *, empty_code=0, courtyard_code=4, structure=None)¶
Automatically label enclosed empty cells as courtyards.
Any cell in
grid
with valueempty_code
that is not 8-connected to the raster border is reclassified ascourtyard_code
. The operation is performed in-place using fast morphological propagation.- Parameters:
grid (ndarray of int) – 2D raster array representing land-use classes or categories. Modified in-place.
empty_code (int, optional) – Value used to indicate empty cells, by default
0
.courtyard_code (int, optional) – Value used to indicate courtyard cells, by default
4
.structure (ndarray of bool, optional) – Structuring element defining connectivity for propagation. Defaults to a 3×3 matrix of ones (8-connectivity).
- Returns:
grid – Same array as input, with enclosed empty cells relabeled as courtyards.
- Return type:
ndarray of int
Notes
Connectivity is determined using
scipy.ndimage.binary_propagation
.Empty cells connected to the border remain unchanged.
Empty cells fully enclosed by structures are converted into courtyards.
Examples
>>> import numpy as np >>> from urbanflow.utils.courtyard_utils import add_auto_courtyards >>> grid = np.array([ ... [0,0,0,0], ... [0,2,2,0], ... [0,2,0,0], ... [0,0,0,0], ... ], dtype=np.uint8) >>> add_auto_courtyards(grid, empty_code=0, courtyard_code=4) array([[0, 0, 0, 0], [0, 2, 2, 0], [0, 2, 4, 0], [0, 0, 0, 0]], dtype=uint8)