Case study 02 / 04

Forest Growth & Yield Analytics

A full-stack platform that fits, benchmarks, and serves basal-area growth models for 13 species and forest-unit groups, built for scientists at Ontario's Ministry of Natural Resources and Forestry.

Position
Software developer, industry partner project; MNRF forestry scientists as clients
Period
September 2025 to April 2026; public edition October 2026
Stack
  • Python 3.11
  • FastAPI
  • SQLAlchemy 2.0
  • Alembic
  • scikit-learn
  • XGBoost
  • LightGBM
  • statsmodels
  • React 19
  • TypeScript
  • Vite
  • PostgreSQL
  • SQL Server
  • SQLite
  • Playwright
  • GitHub Actions
Status
Delivered to MNRF; public edition runs on synthetic data only
Repo
github.com/TirthPatel6104/BA-growth-tool-public
Datasheet 02 of 04
Forest Growth & Yield Analytics2025-26

The question

Foresters planning a harvest need to know how much a stand will grow over the next 5 to 25 years. MNRF has decades of plot remeasurements and an established growth equation. Most growth tools stop at applying that equation. This one also asks: is the production equation actually the best model for this data?

The production model

The engine fits the relative growth rate of stand basal area with a fixed-form linear regression:

RGR = β₀ + β₁·BA + β₂·BA² + β₃·AGSfrac + β₄·TCR + β₅·DQ + β₆·q + β₇·Cut
TermMeaningUnitsExpected sign
BAInitial stand basal aream²/hanegative
BA²Density saturation(m²/ha)²
AGS_fracShare of acceptable growing stock0 to 1positive
TCRTimber capability rating of the site1 to 7positive
DQQuadratic mean diameter at breast heightcmnegative
qDiameter-distribution quotientnonepositive
CutPartial harvest flag0 or 1negative

Projection iterates once a year: BAt+1 = BAt + RGR · BAt. Models are fit for 13 groups (eight species and five forest units). Every fitted coefficient is checked against its expected biological sign, and a fit that gets a sign wrong is flagged before anyone reads a projection from it.

Projection. Drag the sliders; the curve is the model equation with example coefficients.
18.726.634.442.350.1012.525 yrBA m²/ha43.6 m²/ha
22 m²/ha
25 years
RGR = 0.0277 per year for this stand (AGS 0.72, TCR 3, DQ 20 cm, q 1.3, cut 0). Coefficients are from the public demo fit on synthetic data (n=1633), not the production model.

The benchmark

Remeasured plots are the trap. The same plot shows up at several dates, so a random train and test split puts its future in the training set and its past in the test set, and every model looks better than it is.

  • 17 algorithms. OLS, ridge, lasso, elastic net, Huber, Bayesian ridge, polynomial ridge, spline GAM, SVR, k-NN, random forest, extra trees, histogram GBM, XGBoost, LightGBM, MLP, and a mixed-effects model.
  • Three splits. Plot-grouped cross-validation (no plot on both sides), temporal, and naive k-fold. The naive score is printed next to the grouped one, so the leakage is a number on the page.
  • Against the incumbent. Each challenger gets a paired t-test against the production equation. A model that wins by noise does not win.
  • Honest intervals. Split-conformal prediction intervals with measured coverage, plus permutation_importance per model.
  • Output. A JSON and Markdown leaderboard across all 13 groups, from the UI, the API, or the command line.
The Model Benchmarks tab: summary tiles for best model, RMSE gain versus OLS, R² on unseen plots, 90% interval coverage, and R² inflation from leakage, above a 17-row leaderboard ranked by RMSE with paired t-test p-values against OLS.
The Model Benchmarks tab in the public edition, on synthetic data. On this group the top model beats OLS by 2.4% RMSE with p = 0.476, so the page reports it as noise. Naive k-fold inflates R² by 0.049 over plot-grouped CV.

The platform around it

  • API. FastAPI with 25 REST endpoints for per-plot predictions, 5 to 25 year projections, coefficients, and benchmark runs. Training and benchmark jobs return 202 Accepted and a job id, so a long fit never blocks a request.
  • Data layer. SQLAlchemy 2.0 behind one Alembic migration chain that runs on SQLite, PostgreSQL, and SQL Server.
  • Front end. React 19 and TypeScript. Bilingual (English and French), light and dark themes, usable at phone width.
  • CI gates. 89 pytest tests with coverage, flake8 and mypy, ESLint and a TypeScript build, Playwright end-to-end tests with axe accessibility scans, a migration sanity check, and a benchmark smoke test.
  • Docs. C4 system design, benchmarking method, and a security disclosure policy, written for the scientists who keep the system.
The Basal Area Growth Rate Tool web app, showing the Data Entry tab with a Connect to Database button and tabs for Calculations, Model Coefficients, Visualization, and Reports.
The entry screen of the public edition. Database connection first, then data entry, calculations, coefficients, benchmarks, charts, and reports.

What is public

The MNRF data is not. The public edition runs on a dataset generated from a fixed random seed, and its README lists exactly what was removed: real plots, coordinates, fitted coefficients, benchmark results, and the agency’s stored procedures. The contract those procedures have to meet is documented so the code still makes sense without them.

More work