terraflow.stats¶
The stats module exposes the Pydantic summary models that back report.json plus helper functions for raster and climate statistics.
Public surface¶
RasterSummary,ClimateSummary,RunReport— Pydantic v2 models.summarize_raster,summarize_raster_file,compare_rasters,batch_summarize— helper functions.
API Reference¶
stats
¶
ClimateSummary
¶
Bases: BaseModel
Simple summary describing climate inputs used for a pipeline run.
RasterSummary
¶
Bases: BaseModel
Summary statistics for a single-band raster (or ROI subset).
This model is Pydantic-based so it can be safely serialized to JSON/YAML and used in downstream reporting or auditing.
from_array(arr)
classmethod
¶
Build a RasterSummary from a masked array. Entirely masked arrays yield count=0 and all other fields None.
Source code in terraflow/stats.py
RunReport
¶
Bases: BaseModel
Lightweight, serializable report of a TerraFlow run.
This is intentionally generic: it does not depend on the internal dataframe schema, only on aggregated summaries.
is_empty_roi
property
¶
Convenience flag: True if the ROI resulted in no valid cells.
batch_summarize(raster_paths, roi=None, roi_crs=None)
¶
Summarize a collection of rasters and return a mapping from file stem to RasterSummary instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_paths
|
Iterable[str | Path]
|
Iterable of paths to raster files. |
required |
roi
|
Optional[Dict[str, float]]
|
Optional ROI dict; see :func: |
None
|
roi_crs
|
Optional[str]
|
CRS of the ROI coordinates; see :func: |
None
|
Source code in terraflow/stats.py
compare_rasters(raster_a, raster_b, roi=None, roi_crs=None, mode='difference')
¶
Compare two rasters over an optional ROI and return the resulting array plus summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_a
|
DatasetReader
|
Open rasterio datasets with the same shape/transform. |
required |
raster_b
|
DatasetReader
|
Open rasterio datasets with the same shape/transform. |
required |
roi
|
Optional[Dict[str, float]]
|
Optional ROI dict with keys xmin, ymin, xmax, ymax. Coordinates must be in the CRS given by roi_crs. |
None
|
roi_crs
|
Optional[str]
|
CRS of the ROI coordinates. When |
None
|
mode
|
Literal['difference', 'ratio']
|
|
'difference'
|
Source code in terraflow/stats.py
summarize_raster(raster, roi=None, roi_crs=None)
¶
Compute summary statistics for band 1 of a raster, optionally clipped to an ROI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
DatasetReader
|
Open rasterio dataset. |
required |
roi
|
Optional[Dict[str, float]]
|
Optional dict with keys xmin, ymin, xmax, ymax. Coordinates must be
in the CRS given by roi_crs. When roi_crs is |
None
|
roi_crs
|
Optional[str]
|
EPSG code or WKT string for the CRS of the ROI coordinates. When
|
None
|
Source code in terraflow/stats.py
summarize_raster_file(raster_path, roi=None, roi_crs=None)
¶
Convenience wrapper: open a raster, summarize it, and close it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_path
|
str | Path
|
Path to the raster file. |
required |
roi
|
Optional[Dict[str, float]]
|
Optional ROI dict; see :func: |
None
|
roi_crs
|
Optional[str]
|
CRS of the ROI coordinates; see :func: |
None
|