Skip to content

Predict a fit with split climate terms from the year's climate - #44

Merged
eliotmcintire merged 6 commits into
developmentfrom
climateSplit
Nov 21, 2026
Merged

eliotmcintire merged 6 commits into
developmentfrom
climateSplit

Conversation

@eliotmcintire

@eliotmcintire eliotmcintire commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

A spread model fitted with the climate split into a between-year and a within-year term needs those two terms rebuilt when it predicts. This makes the predictions do that, from the year's climate, the same way the fit did.

Affects: nothing changes for existing fits. A prediction from a fit with the two climate terms now works and uses the year's regional median of climate, computed over the region's own burnable pixels.

Depends-on: PredictiveEcology/fireSenseUtils#244

Technical details

Part of one change with PredictiveEcology/fireSenseUtils#244, fireSense_dataPrepFit and fireSense_spreadFit. Without this, spreadProbOneELF() (fireSense_spreadPredict.R) stops for a row with CMD_yr/CMD_dev parameters: the prediction covariates have CMD, not those two, so "the fitted coefficients ... have no covariate".

Fix: spreadProbOneELF() finds the split terms among the fitted names (isClimateSplitCol(), climateSplitBase()) and calls fireSenseUtils::splitSpreadClimate() on its copy of the covariates, as the fit does. The median is over the ELF's flammable pixels, chosen with fireSenseUtils::climateSplitRefPixels(covs$pixelID, flammableRTM, elfPixels), the function the fit uses. The new argument elfPixels: every row of covs with one fitted ELF; with several, the cells of rasterToMatchLargeELF labelled with that ELF (not the blend zone, which would shift the median), found with ELFcellLabels(), the label step of ELFblendWeights() moved into a function so both use it. One fitted ELF: the table is that ELF's landcoverDT rows (fuelClassPrep.R:786 in fireSenseUtils joins to landcoverDT; makeLandcoverDT.R:34-41 keeps flammable cells with land cover not 0; useOwnELFRows() drops other ELFs), so it already is the fit's burnable pixel set, and flammableRTM is a guard. Several ELFs: the merged table holds every ELF's rows, so elfPixels selects the ELF's own cells. A row without split terms takes none of these paths.

fireSense_dataPrepPredict needs no change: its covariate table has the base climate variable, and the ledger row's names carry the rest (fireSenseUtils::spreadFitLedgerInputs() now finds CMD from CMD_yr/CMD_dev, so the climate layer is still requested).

Overlap with the spreadInteractions work: that one also builds columns in spreadProbOneELF(). This diff adds one block before the "every fitted coefficient needs a covariate" check and one argument.

The interaction work (fuel x climate terms) is now on development. fireSense_dataPrepFit stops when spreadInteractions and spreadClimateSplit = TRUE are combined; fireSense_spreadPredict builds the split terms for a coefficient such as CMD_yr:fuel too, so a ledger row with one predicts.

Climate in the ceiling and activation (spreadClimate, now on development): the climate columns of climateRef are every annual covariate that is not a 0/1 indicator (fireSenseUtils::spreadClimateCols()), so C_yr and C_dev are both climate columns, each with its own reference, and both move the ceiling (or are the linear predictor in activation). Nothing to change here; a new test checks it.

Interaction with a split term (2026-11-20): a split fit whose fuel is in the linear range (every real fit) did not predict at all. spreadProbOneELF() turned the logged fuel to linear with covs[[cn]] <- (fireSense_spreadPredict.R:572), which copies the table, so splitSpreadClimate() could no longer add CMD_yr/CMD_dev by reference and the prediction stopped with "have no covariate". The earlier split tests had no linear fuel, so they passed. It now uses data.table::set(). New test: a row with an intercept, centres, youngAge and CMD_yr:fuelA gives the logistic of the hand-computed linear predictor (product of the centred terms, 0 where youngAge cleared the fuel). On the base this test errors; full suite branch 0 failures, 0 errors, 0 skips, 426 passed (base 425). Combined with fireSense_dataPrepFit's spreadInteractions, which now builds CMD_yr:fuel.

Reuses: fireSenseUtils::splitSpreadClimate(), climateSplitBase(), isClimateSplitCol(), climateSplitRefPixels() and elfCellLabels() (the label code of ELFblendWeights(), moved to fireSenseUtils); new: nothing in this module.

Tests (new test-climateSplit.R, 7 tests): a split row predicts the logistic of the hand-computed linear predictor (median over the burnable pixels, deviation per pixel); a non-flammable row with an extreme value does not move the median; with only the between term, every pixel gets the same value; with two ELFs each uses the median of its own pixels; a row without split terms is unchanged; a split fit with climate in the ceiling (spreadClimate = "ceiling" row) moves pc with both terms and x holds the fuels only; a coefficient CMD_yr:fuel is built from the split term. Full suite (convertToPackage() copy, fireSenseUtils with the branch installed in a scratch library): base (development 1.2.0.9017) 0 failures, 0 errors, 0 skips, 414 passed; branch 0 failures, 0 errors, 0 skips, 425 passed. On base the new file errors (the functions do not exist).

No version bump. The reqdPkgs floor on fireSenseUtils is 0.2.3.9186, the version fireSenseUtils#244 will have once it merges (development is at 9184; if another fireSenseUtils PR merges first, the floor is raised to match). Until then CI installs 9184, so the Depends-on line is what holds this PR back.

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

eliotmcintire and others added 2 commits November 20, 2026 16:38
… over the ELF's own burnable pixels

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
…me from fireSenseUtils::climateSplitRefPixels(); cell labels from elfCellLabels()

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
eliotmcintire and others added 4 commits November 20, 2026 17:10
… an interaction is split too; tests: split with climate in the ceiling, split in an interaction

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh
…itSpreadClimate() can add its columns; test of a CMD_yr:fuel interaction

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh
@eliotmcintire
eliotmcintire merged commit 00da8ea into development Nov 21, 2026
13 of 15 checks passed
@eliotmcintire
eliotmcintire deleted the climateSplit branch November 21, 2026 14:25
eliotmcintire added a commit that referenced this pull request Nov 21, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards compatible Existing code and results keep working unchanged enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant