samstars.features.cost_surface¶
samstars.features.cost_surface
¶
CostSurfaceWeights
dataclass
¶
Weights for height edges, NDVI gaps, image texture, and experimental SLIC edges.
Weights must be nonnegative and sum to one. Terms without a supplied NIR band or SLIC layer are omitted and the remaining weights are rescaled.
Source code in samstars/features/cost_surface.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
__post_init__()
¶
Validate and normalize configuration after initialization.
Source code in samstars/features/cost_surface.py
123 124 125 126 127 128 129 130 | |
build_cost_surface(*, img_path=None, chm_path, rgb_bands=None, nir_band=None, texture_band=None, wv3_path=None, slic_path=None, weights=(0.4, 0.3, 0.3, 0), nodata_value=-9999.0)
¶
Build a 0–1 crown-boundary cost raster from aligned imagery and canopy height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_path
|
str | Path | None
|
Three-band RGB or multiband imagery raster. |
None
|
chm_path
|
str | Path
|
Single-band canopy heights in meters, on the imagery grid. |
required |
rgb_bands
|
tuple[int, int, int] | None
|
One-based red, green, blue indices. Defaults to |
None
|
nir_band
|
int | None
|
Optional near-infrared band for the NDVI gap term. With no NIR band, the cost uses height edges and image texture only. |
None
|
texture_band
|
int | None
|
Optional image band for texture. Defaults to the mean of the selected RGB channels. |
None
|
wv3_path
|
str | Path | None
|
Legacy alias for |
None
|
slic_path
|
str | Path | None
|
Experimental SLIC labels on the imagery grid. |
None
|
weights
|
tuple[float, float, float, float]
|
Height-edge, NDVI-gap, texture, and SLIC weights. Unavailable terms are omitted and the remaining weights are rescaled to sum to one. |
(0.4, 0.3, 0.3, 0)
|
nodata_value
|
float
|
Output value at pixels with missing input data. |
-9999.0
|
Returns:
| Name | Type | Description |
|---|---|---|
cost |
ndarray
|
Float32 array of boundary costs. Higher values indicate stronger cues. |
profile |
dict
|
Rasterio profile for the single-band output. |
Source code in samstars/features/cost_surface.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
write_cost_surface(cost, profile, out_path, *, exist_ok=True)
¶
Write a cost array and Rasterio profile to a single-band GeoTIFF.
The parent directory is created when needed. Set exist_ok=False to
reject an existing output file. Returns the output path.
Source code in samstars/features/cost_surface.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |