Tree Metrics¶
Compute TPA-weighted descriptive statistics at the condition or group level.
Overview¶
The tree_metrics() function calculates sample-level tree metrics such as quadratic mean diameter (QMD), mean height, and species composition. Unlike population-level estimators (volume(), tpa(), etc.), these are descriptive statistics that do not use expansion factors or variance estimation.
This is useful for characterizing stand structure, linking plot-level attributes to external models, or computing derived metrics not available in the standard FIA tables.
import pyfia
db = pyfia.FIA("georgia.duckdb")
db.clip_by_state("GA")
# QMD and mean height by forest type
result = pyfia.tree_metrics(db, metrics=["qmd", "mean_height"], grp_by="FORTYPCD")
Function Reference¶
tree_metrics
¶
tree_metrics(db: 'FIA', metrics: list[str], grp_by: str | list[str] | None = None, land_type: str = 'forest', tree_type: str = 'live', tree_domain: str | None = None, area_domain: str | None = None, sawtimber_threshold: float = 9.0, include_cond_attrs: list[str] | None = None) -> DataFrame
Compute TPA-weighted tree metrics from FIA data.
Calculates derived per-condition or per-group tree metrics such as quadratic mean diameter (QMD), mean height, and species composition. These are sample-level descriptive statistics, not population-level estimates -- they do not use expansion factors or variance estimation.
| PARAMETER | DESCRIPTION |
|---|---|
db
|
FIA database connection with EVALID set.
TYPE:
|
metrics
|
Metrics to compute. Valid options:
TYPE:
|
grp_by
|
Grouping columns. Supports standard FIA columns (FORTYPCD, STDAGE, etc.) and plot-condition level grouping (PLT_CN, CONDID).
TYPE:
|
land_type
|
Land type filter: "forest", "timber", or "all".
TYPE:
|
tree_type
|
Tree status filter: "live", "dead", or "gs" (growing stock).
TYPE:
|
tree_domain
|
SQL-like tree filter (e.g.,
TYPE:
|
area_domain
|
SQL-like condition filter (e.g.,
TYPE:
|
sawtimber_threshold
|
Diameter threshold for sawtimber_prop metric.
TYPE:
|
include_cond_attrs
|
COND table columns to pass through in the output (e.g.,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Metrics with one row per group. Columns include the requested metrics plus N_PLOTS and N_TREES counts. |
Examples:
QMD and mean height by forest type:
Condition-level metrics for timber valuation:
>>> result = tree_metrics(
... db,
... metrics=["qmd", "mean_height", "softwood_prop", "sawtimber_prop"],
... grp_by=["PLT_CN", "CONDID", "STDAGE", "FORTYPCD"],
... land_type="timber",
... tree_domain="DIA >= 1.0",
... include_cond_attrs=["SLOPE", "SICOND"],
... )
Source code in src/pyfia/estimation/estimators/tree_metrics.py
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 | |
Available Metrics¶
| Metric | Output Column | Description |
|---|---|---|
"qmd" |
QMD |
Quadratic mean diameter (TPA-weighted) |
"mean_dia" |
MEAN_DIA |
Arithmetic mean diameter (TPA-weighted) |
"mean_height" |
MEAN_HT |
Mean tree height (TPA-weighted, nulls excluded) |
"softwood_prop" |
SOFTWOOD_PROP |
Softwood proportion of bole biomass (SPCD < 300) |
"sawtimber_prop" |
SAWTIMBER_PROP |
Proportion of TPA above sawtimber diameter threshold |
"max_dia" |
MAX_DIA |
Maximum tree diameter in group |
"stocking" |
STOCKING |
Rough stocking index |
All results also include N_PLOTS and N_TREES diagnostic counts.
Examples¶
QMD by Forest Type¶
result = pyfia.tree_metrics(db, metrics=["qmd"], grp_by="FORTYPCD")
result = pyfia.join_forest_type_names(result, db)
print(result.sort("QMD", descending=True).head(10))
Stand Structure Profile¶
Compute multiple metrics at once for a comprehensive stand description:
result = pyfia.tree_metrics(
db,
metrics=["qmd", "mean_height", "softwood_prop", "sawtimber_prop", "stocking"],
grp_by="FORTYPCD",
)
Condition-Level Metrics for External Models¶
Get per-plot-condition metrics with additional COND attributes passed through:
result = pyfia.tree_metrics(
db,
metrics=["qmd", "mean_height", "softwood_prop", "sawtimber_prop"],
grp_by=["PLT_CN", "CONDID", "STDAGE", "FORTYPCD"],
land_type="timber",
tree_domain="DIA >= 1.0",
include_cond_attrs=["SLOPE", "SICOND"],
)
Each row represents a single plot-condition, useful for linking to harvest probability models or growth simulators.
Large Trees Only¶
result = pyfia.tree_metrics(
db,
metrics=["qmd", "mean_dia", "max_dia"],
tree_domain="DIA >= 12.0",
grp_by="FORTYPCD",
)
Sawtimber with Custom Threshold¶
The default sawtimber threshold is 9.0 inches. Override it for hardwood-specific analysis:
result = pyfia.tree_metrics(
db,
metrics=["sawtimber_prop"],
sawtimber_threshold=11.0,
grp_by="FORTYPCD",
)
Comparison with Other Estimators¶
| Feature | tree_metrics() |
tpa(), volume(), etc. |
|---|---|---|
| Estimate type | Sample-level descriptive | Population-level statistical |
| Expansion factors | No | Yes |
| Variance / SE | No | Yes |
| Confidence intervals | No | Yes |
| Use case | Stand characterization, model inputs | Area/volume/biomass totals and per-acre rates |