Skip to content

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

Open
eliotmcintire wants to merge 2 commits into
developmentfrom
climateSplit
Open

eliotmcintire wants to merge 2 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.

Merge order with the interaction PRs (PredictiveEcology/fireSenseUtils#242, PredictiveEcology/fireSense_dataPrepFit#107, PredictiveEcology/fireSense_spreadFit#131, #43), whichever merges first: interaction terms must use fireSenseUtils::climateSplitCols(spreadVars), so CMD_yr:fuel and CMD_dev:fuel; and in fireSense_spreadPredict the interaction PR's needed <- spreadSourceCols(fitted) must come after the split block of spreadProbOneELF(), which makes CMD_yr and CMD_dev from CMD.

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, 5 tests; the new one: a non-flammable row with an extreme value in the covariate table does not move the median): a split row predicts the logistic of the hand-computed linear predictor (median over the burnable pixels, deviation per pixel); 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. Full suite on the branch: 0 failures, 0 errors, 0 skips, 358 passed. On base (origin/development with the new file copied in): 0 failures, 4 errors (the new tests), 0 skips, 352 passed. Ran against the fireSenseUtils branch loaded with pkgload::load_all(), in a SpaDES.core::convertToPackage() copy.

No version bump. The reqdPkgs floor on fireSenseUtils is set after #244 merges and its version is bumped.

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

… 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

This branch has not been deployed

No deployments
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