Classification API Reference¶
This page documents the land-system classification API, the top-level
savana.* modules. For precipitation product assessment, see the separate
Precipitation Assessment API Reference, which documents
the savana.rainfall.* modules.
Same names, different modules
A few module names appear in both packages: config, thresholds,
and viz. On this page they always mean the classification versions
(savana.config, savana.thresholds, savana.viz). Their rainfall
namesakes (savana.rainfall.config, etc.) are entirely separate and
documented on the rainfall API page.
High-level entry point¶
savana.pipeline
¶
High-level orchestration: the "few lines of code" entry point.
Mirrors the workflow in mainrun.js step for step, but wrapped as a
single Python object so a Jupyter user can go from an AOI to a
validated, multi-epoch classified savanna land-system map in a handful
of calls instead of hand-assembling every module.
Example¶
import savana clf = savana.SavanaClassifier( ... aoi="projects/ee-desmond/assets/NewParkMerged", ... name_filter="Kogyae", ... park_name="Kogyae", ... epochs=[2017, 2019, 2021, 2024], ... ) clf.run() clf.maps[2024] # ee.Image, classified 2024 land systems clf.accuracy_summary() # pandas.DataFrame, one row per model clf.show(2024) # interactive geemap.Map in the notebook
SavanaClassifier
¶
End-to-end adaptive savanna land-system classifier for one AOI.
All parameters have sane defaults matching the original manuscript methodology; override any of them for a different landscape, class scheme, or sensor configuration.
Source code in savana/pipeline.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
accuracy_summary()
¶
One row per model (A/B/C/D) with overall accuracy, kappa, PA/UA.
Source code in savana/pipeline.py
185 186 187 188 189 190 191 192 193 194 195 | |
analyse_change()
¶
Run conservative + RUE-validated change detection across epochs.
Source code in savana/pipeline.py
165 166 167 168 169 170 171 | |
answer(question)
¶
Answer a question about your results using only computed facts.
Simple keyword matching, not an LLM — it can only ever report numbers the pipeline actually produced, so it can't hallucinate. Try asking about a class's area, the dominant class, accuracy, or change between years.
clf.answer("how much core woodland is there in 2024?") clf.answer("what changed between the years?") clf.answer("how accurate is the model?")
Source code in savana/pipeline.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
build_features()
¶
Build composites, indices, RUE, thresholds, and masks for the reference year.
Source code in savana/pipeline.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
class_areas()
¶
Per-epoch class area statistics (km2) as a pandas DataFrame.
Source code in savana/pipeline.py
209 210 211 212 213 214 | |
classify()
¶
Classify every requested epoch year.
Source code in savana/pipeline.py
152 153 154 155 156 157 158 159 160 161 162 163 | |
compare(left=2024, right='SATELLITE', m=None)
¶
Side-by-side swipe comparison between two years, or a year vs. a basemap.
left/right each accept either an epoch year (int, must be
in self.maps) or a basemap name string (e.g. "SATELLITE",
"HYBRID", "ROADMAP", "Esri.WorldImagery"). Drag the
handle in the middle of the resulting map to swipe.
clf.compare(2019, 2024) # two classified years clf.compare(2024, "SATELLITE") # classified year vs. basemap
Source code in savana/pipeline.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
confusion_matrices()
¶
Full per-class confusion matrix table across all 4 models.
Source code in savana/pipeline.py
197 198 199 200 201 202 203 204 205 206 207 | |
export(drive_folder=None, asset_folder=None)
¶
Export classified maps (+ change products, if computed) to Drive/Assets.
Source code in savana/pipeline.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
facts()
¶
Compute the grounded facts dict — real numbers from your actual results.
This is the single source of truth for .summarize() and .answer(); call it directly if you want the raw structured data instead of text.
Source code in savana/pipeline.py
346 347 348 349 350 351 352 353 354 | |
run()
¶
Run the full pipeline: features -> sampling -> training -> classification -> change.
Source code in savana/pipeline.py
173 174 175 176 177 178 179 180 181 | |
sample_training_points()
¶
Unsupervised clustering + rule-based labelling + class balancing.
Source code in savana/pipeline.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
show(year=None, m=None)
¶
Display a classified epoch (default: reference year) on an interactive map.
Source code in savana/pipeline.py
240 241 242 243 244 245 | |
show_change(m=None)
¶
Display change-detection layers on an interactive map.
Source code in savana/pipeline.py
338 339 340 341 342 343 344 | |
show_gcps(with_background=True, m=None)
¶
Display the ground control points on the map, colored by class.
A sanity check on the sampling/labelling step — where the training points actually landed and whether their classes look spatially sensible — before trusting the classifier they train. Requires .sample_training_points() (or .run()) to have completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
with_background
|
bool
|
If True (default), shows the reference year's classified map underneath the points, dimmed, so you can visually compare point placement against the result. If False, points are shown alone. |
True
|
Source code in savana/pipeline.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
show_geolibre(year=None, m=None)
¶
Display a classified epoch inside the GeoLibre Jupyter widget.
Alternative to .show() — same idea, different map backend. Requires: pip install "savana[geolibre]" (Python >= 3.11).
Source code in savana/pipeline.py
288 289 290 291 292 293 294 295 296 297 298 299 | |
show_years(years=None, m=None)
¶
Display several classified epochs as toggleable layers on one map.
Uses geemap's layer panel — check/uncheck each year's checkbox to flip between them. Defaults to all epochs the classifier ran.
clf.show_years() # all epochs clf.show_years([2019, 2024]) # just these two
Source code in savana/pipeline.py
275 276 277 278 279 280 281 282 283 284 285 286 | |
show_years_geolibre(years=None, m=None)
¶
Display several classified epochs as toggleable layers in GeoLibre.
Alternative to .show_years() — same idea, different map backend. Requires: pip install "savana[geolibre]" (Python >= 3.11).
Source code in savana/pipeline.py
301 302 303 304 305 306 307 308 309 310 311 | |
summarize()
¶
Plain-English report generated entirely from real computed results.
No AI, no invented numbers — every figure here traces back to .class_areas() / .accuracy_summary() / the change-detection stats.
Source code in savana/pipeline.py
356 357 358 359 360 361 362 363 364 | |
train()
¶
Train the 4-model ablation + master classifiers.
Source code in savana/pipeline.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
classify_landscape(aoi, epochs=None, park_name='AOI', **kwargs)
¶
One-call convenience wrapper: build, run, and return a fitted classifier.
clf = savana.classify_landscape( ... "path/to/my_park.geojson", epochs=[2020, 2024], park_name="My Park" ... ) clf.show()
Source code in savana/pipeline.py
383 384 385 386 387 388 389 390 391 392 393 394 395 | |
Feature engineering¶
savana.composites
¶
Sentinel-2, seasonal, percentile, and AlphaEarth embedding composites.
Ported from kogyae.js Phase 2 (Sentinel-2 reference imagery) and
Phase 3 (AlphaEarth embeddings), and from the year-loop composite logic
in Phase 8, the standalone composites.js module you use in
mainrun.js was empty, so this reconstructs it from the working
monolithic script with the exact same signatures mainrun.js expects
(getSentinel2Annual, getSeasonalComposite, getPercentileComposites,
getEmbeddingImage), plus a graceful fallback for seasons/years with
sparse Cloud Score+ coverage.
embedding_image(year, region)
¶
Annual AlphaEarth satellite embedding image (64 bands: A01..A64).
Equivalent to getEmbeddingImage / C.getEmbeddingImage.
Source code in savana/composites.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
percentile_composites(year, region, percentiles=(10, 90), cloud_score_threshold=0.65)
¶
Per-band percentile composites (default p10/p90) for a calendar year.
Used to build the seasonal-amplitude / stability indices.
Equivalent to C.getPercentileComposites, returns a dict keyed
"p{percentile}" (e.g. {"p10": image, "p90": image}).
Source code in savana/composites.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
seasonal_composite(start_date, end_date, region, cloud_score_threshold=0.55, cloud_pct_fallback=50)
¶
Cloud-masked median Sentinel-2 composite for an arbitrary date range.
Falls back to a simple CLOUDY_PIXEL_PERCENTAGE filter if Cloud
Score+ has no coverage for the window, and to a zero-filled image
if there are no scenes at all (keeps downstream band math from
failing on sparse early-record years). Equivalent to
getSeasonalComposite / C.getSeasonalComposite.
Source code in savana/composites.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
sentinel2_annual(year, region, cloud_score_threshold=0.65)
¶
Cloud-masked median Sentinel-2 SR composite for a calendar year.
Equivalent to getSentinel2Composite / C.getSentinel2Annual.
Source code in savana/composites.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
savana.indices
¶
Spectral index computation and the 14-band phenological stack.
Direct port of indices.js.
build_pheno_stack(idx, rue_img)
¶
Build the 14-band phenological stack used in Model D training.
rue_img must be a single band named 'RUE'.
Source code in savana/indices.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
compute(s2_annual, s2_dry, s2_wet, p10, p90)
¶
Compute all spectral indices from seasonal/percentile composites.
Returns a dict, access as idx["ndvi"], idx["ndvi_dry"], etc.
Source code in savana/indices.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
savana.rue
¶
Rain Use Efficiency (RUE): integrated NDVI normalised by rainfall.
Tile-boundary bias is removed by normalising integrated NDVI by the
count of valid (cloud-free) months before dividing by annual rainfall.
Direct port of rue.js.
compute_annual(year, region, cloud_score_threshold=0.65)
¶
Full integrated-NDVI / CHIRPS RUE for a training year.
Returns {"chirps": image, "indvi": image, "rue": image} where
rue is a single band named 'RUE' (used as training feature #14).
Source code in savana/rue.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
epoch_rue(year, region, cloud_score_threshold=0.65)
¶
RUE for a specific epoch year. Returns a single band named RUE_{year}.
Source code in savana/rue.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
savana.thresholds
¶
Adaptive percentile-based threshold derivation.
All thresholds are derived from this AOI's own index distribution,
nothing is hardcoded, so the same code transfers to any savanna
landscape automatically. Direct port of thresholds.js.
compute(idx, region)
¶
Compute all classification thresholds from index percentiles.
Returns a dict of ee.Number, access as T["CORE_NDVI_DRY"] etc.
Source code in savana/thresholds.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
savana.masks
¶
Mutually exclusive land system masks.
Priority order: Anthropogenic -> Riparian -> Core -> Grassland ->
Shrub-Transition -> Open Woodland. Each mask explicitly excludes all
higher-priority classes. Direct port of masks.js.
add_layers(masks, m=None, class_info=None)
¶
Add each mask as a layer to a geemap/folium Map (or ee.Map in Code Editor context).
m should be a geemap.Map instance in a notebook. If omitted,
a new one is created and returned.
Source code in savana/masks.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
compute(idx, T)
¶
Compute all 6 land system masks from indices and thresholds.
Returns {"anthro", "riparian", "core", "grass", "shrub", "open"}.
Source code in savana/masks.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
coverage(masks, region)
¶
Fraction of AOI covered by each mask (target range ~0.05-0.30 each).
Source code in savana/masks.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
Training and classification¶
savana.sampling
¶
GCP (ground control point) generation.
Unsupervised clustering -> cluster-stratified candidate sampling ->
rule-based provisional labelling with a confidence-margin filter ->
class balancing -> embedding extraction. Direct port of sampling.js
(and the equivalent Phase 4 logic in kogyae.js).
assign_labels(candidates, T, confidence_margin=config.DEFAULT_CONFIDENCE_MARGIN, class_property=config.CLASS_PROPERTY)
¶
Assign rule-based provisional labels; filter out low-confidence and invalid points.
Returns the filtered, valid-labelled ee.FeatureCollection.
Source code in savana/sampling.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 | |
build_gcps(embedding, idx, clusters, T, region, n_classes=6, points_per_class=config.DEFAULT_POINTS_PER_CLASS, scale=config.DEFAULT_EXPORT_SCALE, class_property=config.CLASS_PROPERTY, n_clusters=config.DEFAULT_N_CLUSTERS, candidates_per_cluster=config.DEFAULT_CANDIDATES_PER_CLUSTER, confidence_margin=config.DEFAULT_CONFIDENCE_MARGIN)
¶
End-to-end: sample candidates -> label -> balance -> extract embeddings.
Returns the final ee.FeatureCollection of ground control points
with embedding bands attached, ready for classifier training.
Source code in savana/sampling.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
cluster_embedding(embedding, region, n_clusters=config.DEFAULT_N_CLUSTERS, seed=config.DEFAULT_RANDOM_SEED)
¶
Unsupervised k-means clustering in AlphaEarth embedding space.
Returns {"clusters": image, "samples": feature_collection}.
Source code in savana/sampling.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
sample_candidates(idx, clusters, region, n_clusters=config.DEFAULT_N_CLUSTERS, candidates_per_cluster=config.DEFAULT_CANDIDATES_PER_CLUSTER, scale=config.DEFAULT_EXPORT_SCALE)
¶
Cluster-stratified candidate point sampling.
Source code in savana/sampling.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
savana.classifiers
¶
Four-model ablation training and multi-epoch classification.
Ported from kogyae.js Phase 5 (training), Phase 7 (accuracy split),
and Phase 8 (multi-epoch classification), the standalone
classifers.js module referenced by mainrun.js was empty, so this
reconstructs it with the exact signatures mainrun.js expects
(trainAllModels, classifyAllEpochs).
Models
A: KNN (k=3) | AlphaEarth embeddings only [baseline] B: Random Forest | AlphaEarth embeddings only C: Random Forest | Phenology indices only [CIRCULAR, ablation only, not used operationally, since labels were derived from the same indices] D: Random Forest | Embeddings + Phenology [PRIMARY, used for mapping]
classify_all_epochs(epochs, models, region, park_name='AOI', embedding_current_year=None, embedding_current_image=None, phenology_min_year=config.DEFAULT_PHENOLOGY_MIN_YEAR, smooth_radius_px=1)
¶
Classify every epoch year with the appropriate master classifier.
Years >= phenology_min_year use Model D (embeddings + phenology,
recomputed for that specific year). Earlier years, where seasonal
Sentinel-2 coverage is typically too sparse for reliable phenology
, fall back to Model B (embeddings only). This generalises the
hardcoded "if year === 2017" special case in the original script.
embedding_current_year/embedding_current_image: if one of
the epochs is the same year the embedding used for training was
already computed for, pass it in to avoid recomputing it.
Returns {year: classified_image}.
Source code in savana/classifiers.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
train_all_models(gcps, embedding, idx, rue_img, region, class_property=config.CLASS_PROPERTY, n_trees=150, split_fraction=0.7, seed=config.DEFAULT_RANDOM_SEED, class_order=None)
¶
Train the 4-model ablation and the two "master" classifiers used for mapping (Model B for years without reliable phenology, Model D for all other years).
Returns a dict with the trained classifiers, error matrices, and the exact band lists each classifier expects (so downstream classification always matches training feature order).
Source code in savana/classifiers.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 | |
savana.change
¶
Conservative change detection + Rain-Use-Efficiency inter-annual variability.
Direct port of change.js. Distinguishes genuine structural change
from rainfall-driven apparent change (a common false-positive source in
savanna change detection) using RUE coefficient-of-variation as a filter.
analyse(classified_maps, epochs, region, park_name='AOI', rue_cv_threshold=0.15)
¶
Run conservative change detection across all epochs.
Requires exactly the epochs present as keys in classified_maps;
the "conservative" and RUE checks specifically use the first and
last epoch, plus stability through any provided middle epochs.
Returns a dict with the change stack, conservative/genuine/variable
change masks, transition codes, RUE-CV image, and per-epoch RUE
images (keyed rue_{year}).
Source code in savana/change.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
class_area_stats(classified_maps, epochs, region, scale)
¶
Per-epoch class area statistics (km2), grouped by class code.
Source code in savana/change.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
Accuracy and export¶
savana.accuracy
¶
Confusion matrix and accuracy summary reporting.
Ports the CSV structure from accuracy.js (24-row full confusion
matrix across 4 models x 6 classes, plus a 4-row per-model summary),
but returns pandas.DataFrame directly for notebook use, Drive/CSV
export is available separately via :mod:savana.exports.
confusion_matrix_dataframe(matrices, park_name='AOI', class_info=None)
¶
Build the full 24-row (4 models x N classes) confusion matrix table.
matrices maps model key ("a","b","c","d") to an ee.ConfusionMatrix.
Source code in savana/accuracy.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
print_summary(matrices, park_name='AOI')
¶
Console summary mirroring the ablation-comparison prints in kogyai.js.
Source code in savana/accuracy.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
summary_dataframe(matrices, park_name='AOI', class_info=None)
¶
One row per model with overall accuracy, kappa, and per-class PA/UA.
Source code in savana/accuracy.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
savana.exports
¶
Export helpers: Google Drive, Earth Engine Assets, and local CSV/GeoTIFF.
Ports the export logic in exports.js, generalised so the
folder/asset path, CRS, and scale are all parameters instead of
hardcoded to one researcher's Drive folder and asset project.
class_areas_dataframe(classified_maps, epochs, region, scale)
¶
Client-side (getInfo) per-epoch class area table as a pandas DataFrame.
Source code in savana/exports.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
export_change_products(chg, region, park_name='AOI', drive_folder=None, asset_folder=None, scale=config.DEFAULT_EXPORT_SCALE, crs=config.DEFAULT_CRS, start=True)
¶
Export change-detection and RUE products to Drive and/or Assets.
Source code in savana/exports.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
export_classified_maps(classified_maps, epochs, region, park_name='AOI', drive_folder=None, asset_folder=None, scale=config.DEFAULT_EXPORT_SCALE, crs=config.DEFAULT_CRS, start=True)
¶
Export each epoch's classified map to Drive and/or an EE Asset folder.
At least one of drive_folder / asset_folder should be given,
or nothing will be exported. Returns the list of started EE tasks.
Source code in savana/exports.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
Insights and visualisation¶
savana.insights
¶
Grounded analytical insights: knowledge derived only from real results.
The design principle here is deliberate: every number in summarize()
and answer() traces back to something actually computed by the
pipeline (class_areas(), accuracy_summary(), the change-detection
stats), never invented, interpolated, or guessed. compute_facts()
is the single source of truth; both text-producing functions only ever
read from it. This keeps savana's reporting honest even as it grows,
if a future version adds LLM-phrased summaries, that layer should sit
on top of these same facts, never replace them.
answer(facts, question)
¶
Answer a natural-language question using only precomputed facts.
This is deliberately simple keyword matching, not an LLM, it can
only ever report numbers that are actually in facts, so it
cannot hallucinate a result the pipeline didn't produce. Questions
it doesn't recognise get an honest "don't know" rather than a guess.
Source code in savana/insights.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
compute_facts(clf)
¶
Extract a structured dict of real, computed facts from a fitted classifier.
Requires clf.run() (or at least .classify()) to have completed.
This is the "knowledge base", everything else in this module reads
from its output, never from the raw ee.Image objects directly.
Each section (area, accuracy, change) is computed independently and
guarded against Earth Engine timeouts, a slow/large AOI causing one
section to time out will not prevent the others from returning. Any
section that fails is set to None and noted in facts["warnings"]
rather than raising, since a partial, honest answer is better than a
hard crash on results that mostly did compute successfully.
Source code in savana/insights.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
summarize(facts)
¶
Turn a facts dict into a plain-English narrative report.
Source code in savana/insights.py
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 | |
savana.viz
¶
Interactive visualization helpers built on geemap/leafmap for Jupyter.
add_legend(m, class_info=None, title='Land System Classes')
¶
Add a class legend to a geemap.Map.
Source code in savana/viz.py
81 82 83 84 85 86 | |
compare_split_map(left, right, left_label='Left', right_label='Right', region=None, class_info=None, m=None, zoom=12)
¶
Side-by-side swipe comparison between two layers.
Each of left/right can be either:
- an ee.Image (e.g. a classified year, or clf.maps[2019]),
rendered with the land-system palette/legend
- a basemap name string (e.g. "SATELLITE", "HYBRID",
"ROADMAP", "Esri.WorldImagery"), passed straight to geemap
Drag the handle in the middle of the map to swipe between them, this also works for "classified year vs. underlying satellite imagery" by passing a basemap name string as one side.
Source code in savana/viz.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 | |
show_change_map(chg, region=None, m=None, zoom=12)
¶
Display conservative/genuine/variable change layers on a geemap.Map.
Source code in savana/viz.py
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 | |
show_classified_map(classified_image, region=None, class_info=None, m=None, zoom=12)
¶
Display a classified land-system image on an interactive geemap.Map.
Source code in savana/viz.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
show_gcps(gcps, region=None, class_info=None, class_property=config.CLASS_PROPERTY, background=None, m=None, zoom=12, point_size=5)
¶
Display ground control points on a map, colored by assigned class.
Lets you visually sanity-check the sampling/labelling step, where the training points actually landed, and whether their classes look spatially sensible, before trusting the classifier trained on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gcps
|
The |
required | |
region
|
AOI to center the map on (e.g. |
None
|
|
class_info
|
dict | None
|
Class scheme (defaults to the standard 6-class one). |
None
|
class_property
|
str
|
Property name holding the class code on each
point (defaults to savana's standard |
CLASS_PROPERTY
|
background
|
Optional ee.Image to show underneath the points (e.g. a classified year, or a Sentinel-2 composite), makes it easier to judge whether points look correctly placed. |
None
|
|
m
|
Existing geemap.Map to add to, or a new one is created. |
None
|
|
point_size
|
int
|
Marker size in pixels. |
5
|
Source code in savana/viz.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
show_multi_year_map(classified_maps, years=None, region=None, class_info=None, m=None, zoom=12)
¶
Add every requested epoch as its own toggleable layer on one map.
Uses geemap's built-in layer panel, each year gets its own checkbox, so you can flip between them (or view several at once with opacity sliders) without re-running anything.
Source code in savana/viz.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
savana.viz_geolibre
¶
Display savana classification results inside the GeoLibre Jupyter widget.
GeoLibre (https://geolibre.app, MIT-licensed, by the same author as geoai)
ships a Jupyter-native Python package with a leafmap-style API. This module
is a thin adapter: it converts savana's ee.Image outputs into XYZ tile
URLs (via Earth Engine's own tile server) that GeoLibre's
add_tile_layer() can display, the same way you'd add any other raster
tile source.
This is intentionally a lightweight integration, it depends only on the
public geolibre PyPI package, versioned and released the same way as
every other savana dependency. It is not a GeoLibre plugin (that would be
TypeScript code living inside GeoLibre's own repo/build system); see the
project roadmap for that as a possible future, separate effort.
Requires: pip install "savana[geolibre]" (needs Python >= 3.11, since
that is GeoLibre's own minimum, this is stricter than savana's core
Python >= 3.10 requirement).
Known limitation: GeoLibre's swipe/compare tool is currently a UI-only
plugin (Plugins menu > Swipe) with no scriptable Python entry point yet.
Once GeoLibre exposes one, a compare_geolibre() will be added here to
match savana.viz.compare_split_map().
show_classified_map(classified_image, region=None, class_info=None, m=None, zoom=10, layout='embed')
¶
Display one classified land-system image inside the GeoLibre widget.
Returns a geolibre.Map, display it in a notebook cell by putting
it as the last expression, same as any other Jupyter widget.
Source code in savana/viz_geolibre.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
show_multi_year_map(classified_maps, years=None, region=None, class_info=None, m=None, zoom=10, layout='embed')
¶
Add every requested epoch as its own toggleable tile layer in GeoLibre.
Each year appears as its own entry in GeoLibre's Layers panel, with its own visibility checkbox and opacity slider (the same panel you already saw in the app), no extra code needed on your end to toggle between them once this cell has run.
Source code in savana/viz_geolibre.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Natural-language agent¶
savana.agents
¶
SavanaGeoAgent: the one agent class for savana - grounded Q&A, map control, and a chat UI, all in one place.
This is built directly ON TOP of geoai's own agent infrastructure
(geoai.agents) rather than a parallel reimplementation: the map is a
real geoai.Map (leafmap/MapLibre-based, the same class geoai's own
demos use), map control comes from geoai's real, full-featured
MapTools (fly_to, add_basemap, add_vector, add_raster, add_cog_layer,
remove_layer, and more), and model creation reuses geoai's own
create_anthropic_model/create_openai_model/create_gemini_model.
savana adds its own grounded Q&A tools (summarize, class_area, accuracy,
change, etc.) alongside geoai's map tools on one combined Strands agent.
from savana.agents import SavanaGeoAgent
agent = SavanaGeoAgent(clf, model="anthropic")
agent.ask("How much core woodland is there in 2024?") # savana Q&A
agent.ask("Fly to the study area and add a satellite basemap") # geoai map tools
agent.show_ui() # chat UI + live map, inline
Requires: pip install "savana[agents]" (installs geoai-py[agents],
which brings in strands-agents, leafmap, and the LLM provider
SDKs).
SavanaGeoAgent
¶
The one agent class for savana: grounded Q&A + full map control + chat UI.
Built on geoai's real Map/MapTools/model-factory infrastructure
(see module docstring), savana adds its own grounded query tools
alongside geoai's map-control tools on one combined agent.
Deliberately one class, not two, pass clf, rainfall, or
both. Whichever you pass determines which grounded tool set(s) get
loaded, so someone working on both a land-system classification and
a rainfall assessment for the same study area gets one agent and
one ask(), not two agents to keep track of.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clf
|
A |
None
|
|
rainfall
|
A |
None
|
|
model
|
str
|
Either a provider name ( |
'anthropic'
|
model_id
|
Optional[str]
|
Optional explicit model id, used only when |
None
|
map_instance
|
Optional existing |
None
|
|
max_tokens
|
int
|
Explicit max output tokens for the Anthropic provider
specifically, always set explicitly here (not left to
provider defaults), since omitting it is what causes a bare
|
4096
|
**model_kwargs
|
Any
|
Passed through to geoai's model factory. |
{}
|
Source code in savana/agents.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
map
property
¶
The live geoai.Map (leafmap/MapLibre) this agent controls.
__call__(prompt)
¶
Full Strands result object (same as calling the agent directly).
Source code in savana/agents.py
527 528 529 | |
ask(prompt)
¶
Send a single-turn question, get a plain-text answer back.
If show_ui() is currently displayed, this also updates it, asking from a plain cell and typing into the UI box both write to the same visible chat log.
Source code in savana/agents.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
show_ui(height=600)
¶
Display the live geoai map + a chat box side by side, inline.
Calling agent.ask(...) in a separate cell also updates this
panel, if it's currently displayed, they share the same chat log.
Requires: ipywidgets (installed with the agents extra).
Source code in savana/agents.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
Configuration and Earth Engine¶
savana.config
¶
Default configuration for savanna landscape classification.
Everything here is a default, every public function in the package accepts overrides, so a user classifying a different savanna system with a different class scheme is not locked into these values.
class_palette(class_info=None)
¶
Ordered hex palette (by ascending class code) for map visualisation.
Source code in savana/config.py
46 47 48 49 | |
class_vis_params(class_info=None)
¶
Earth Engine visualization params for a classified land-system image.
Source code in savana/config.py
52 53 54 55 56 | |
savana.ee_init
¶
Earth Engine session setup and flexible AOI (area-of-interest) loading.
The original GEE script hardcoded a single park asset
(projects/ee-desmond/assets/NewParkMerged) and filtered it by name.
This module generalises that so any user can classify their study
area, supplied as an Earth Engine asset ID, a GeoJSON/Shapefile path,
a geopandas.GeoDataFrame, or an ee.Geometry/ee.FeatureCollection
directly.
initialize(project=None, force=False)
¶
Initialize the Earth Engine Python API (auth if needed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str | None
|
Google Cloud project registered for Earth Engine use.
If omitted, uses whatever is already configured for the
environment ( |
None
|
force
|
bool
|
Re-initialize even if already initialized this session. |
False
|
Source code in savana/ee_init.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
load_aoi(source, name_filter=None)
¶
Resolve any of several AOI input types into a single ee.Geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
One of:
- |
required |
name_filter
|
str | None
|
If |
None
|
Returns:
| Type | Description |
|---|---|
Geometry
|
ee.Geometry: a single (possibly multi-part) dissolved geometry. |
Source code in savana/ee_init.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |