Skip to content

New parameter seedVegInit: repeatable vegetation in the fit - #105

Merged
eliotmcintire merged 4 commits into
developmentfrom
veg-init-seed
Nov 16, 2026
Merged

eliotmcintire merged 4 commits into
developmentfrom
veg-init-seed

Conversation

@eliotmcintire

@eliotmcintire eliotmcintire commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

The vegetation the fit rebuilds from satellite data involves random in-filling of missing values, so the same area gave different vegetation on different machines. This adds a seed (default fixed) so results are repeatable, and it can be switched off or changed to see how much the in-filling matters.

Affects: the vegetation of every fit is drawn once with the new default seed, so the nested run re-runs once and results can differ from earlier runs; after that they are the same on every machine. seedVegInit = NA gives the old unseeded behaviour.

Depends-on: PredictiveEcology/Biomass_borealDataPrep#156

Technical details

Defect: the nested simInitAndSpades() in runBorealDP_forCohortData() (fireSense_dataPrepFit.R:~1724) passes no seed. LandR::subsetDT (cohorts.R:1638) draws the age-model subset (cohorts.R:1495, from Biomass_borealDataPrep.R:834) and the biomass-model subset (Biomass_borealDataPrep.R:1147), and convertUnwantedLCC draws too.

Fix: new parameter seedVegInit (numeric, default 1, NA = none) passed as the nested module's .seed = list(init = seedVegInit). All the draws run in the init event (.inputObjects has only randomStudyArea(seed = 1234)), and SpaDES.core reads .seed at simulation-spades.R:255, and at :277-284 saves .Random.seed, calls set.seed() for the event and restores the session stream in on.exit. The outer Cache() of the nested simInitAndSpades() (fireSense_dataPrepFit.R:~1738) digests its call arguments, including params = parms, and omits only paths; so .seed is in its key (checked by a toy test that uses the same call shape: a second seed adds a cache entry, a repeat adds none). It is also in the key of the init event. The inner Cache() calls of the nested module (age-model subset, replacement land cover, biomass model) did not key on it, which is fixed in Biomass_borealDataPrep#156. Users' own .seed entries for other events are kept; NA leaves the module's .seed untouched.

Reuses: SpaDES.core's .seed parameter, utils::modifyList, the existing parms list of the nested call; new: nestedVegSeed() (builds the .seed list; nothing existing does that, and as a function it can be tested). The tests' moduleParams() (copied in two test files) moved to helper-moduleCode.R as moduleParamTable() (the old name was shadowed by SpaDES.core::moduleParams).

Tests: test-seedVegInit.R (nestedVegSeed() cases; the parameter default; a toy module whose init calls LandR::subsetDT with .seed: same seed gives the same subset, even in a fresh cache; another seed gives another; no seed varies). On base it fails (4 failures/errors, no nestedVegSeed). The full nested Biomass_borealDataPrep run was too heavy, so cohortData identity is covered by the toy plus the module-side test in #156. Full suite (convertToPackage() + test_local(), SpaDES.core 3.2.1.9069, fireSenseUtils 0.2.3.9172): branch 145 blocks, 526 passed, 0 failed, 0 errors, 1 skip; base (development) 141 blocks, 514 passed, 0 failed, 0 errors, same 1 skip (DPF_EQUIVALENCE_FIXTURE not set).

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

…s_borealDataPrep

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
@eliotmcintire eliotmcintire added enhancement New feature or request backwards compatible Existing code and results keep working unchanged labels Nov 16, 2026
eliotmcintire and others added 2 commits November 16, 2026 12:31
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
…phabetically among the parameters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
@eliotmcintire eliotmcintire changed the title New parameter vegInitSeed: repeatable vegetation in the fit New parameter seedVegInit: repeatable vegetation in the fit Nov 16, 2026
…eeping both bullets

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
@eliotmcintire
eliotmcintire merged commit 17986d0 into development Nov 16, 2026
9 checks passed
@eliotmcintire
eliotmcintire deleted the veg-init-seed branch November 16, 2026 23:04
eliotmcintire added a commit that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
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