Skip to content

Remove dead code, document functions, correct Rmd - #12

Merged
eliotmcintire merged 4 commits into
developmentfrom
chore/dead-code-and-docs
Sep 21, 2026
Merged

eliotmcintire merged 4 commits into
developmentfrom
chore/dead-code-and-docs

Conversation

@eliotmcintire

@eliotmcintire eliotmcintire commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Removes the commented-out code and an if (FALSE) {...} block in prepare_IgnitionAndEscapePredict(), adds short roxygen docs to every function, corrects the parameter/input/output desc strings, and fills in the Rmd (summary, events, links), which was still the template. Behaviour is unchanged: with comments ignored, every function parses identical to development except for the deleted if (FALSE) block, and parameter names, classes and defaults and input/output names and classes are identical. One metadata change to note: 12 inputs had their description passed positionally into sourceURL, leaving desc as NA; the text is now in desc and sourceURL is NA. tests/testthat passes. The .md/.html are left for the render workflow.

Removed functions: none (the only dead one, getRequiredFuelClasses, was already commented out).

Possibly unused, kept:

  • parameters .plotInitialTime, .plotInterval, .saveInitialTime, .saveInterval, .useCache: never read.
  • input fireSense_IgnitionFitted: only checked in .inputObjects, and only if whichModulesToPrepare has fireSense_IgnitionFit.
  • input climateYear: only read in a check whose result (time) is never used; the layer taken is always year<time(sim)>.
  • input propFlammable: set in .inputObjects, never read.
  • argument timeStep of ageNonForest(): not used; TSD always increases by 1.

Seen, not changed:

  • whichModulesToPrepare defaults to fireSense_EscapeFit, but the code tests for fireSense_EscapePredict.
  • .inputObjects calls defineFlammable(rstLCC, ...); rstLCC does not exist when rstLCCs is supplied, and is a list otherwise.
  • P(sim)$.studyAreaName, sim$studyArea and sim$rstLCCs are used but not declared in the metadata.

🤖 Generated with Claude Code


Tests (added in 3927403)

A testthat suite on a 4x4 toy landscape where every covariate is hand-computable. The toy climate encodes both the year and the cell in its values (year<Y> MDC cell n = (Y-2000)*100 + n, Tmax its negative), so asserting a value proves which layer of which variable was taken.

99 assertions, 0 failures, 0 skips. Verified to pass identically on origin/development and on this branch, run the way CI runs them (convertToPackage() + pkgload::load_all() + test_local()). Every substantive test was mutation-checked by breaking the module source and confirming the test fails: 14 mutations, 14 detected.

file covers
test-metadata.R exact input/output/parameter name+class contract
test-ageNonForest.R ageing, burn reset, NA=0, timeStep ignored
test-getCurrentClimate.R layer selection by year and variable, both compareGeom guards, supplied-raster passthrough, reuse message
test-init.R declared outputs produced, climateVariablesForFire expansion, landcoverDT construction, event scheduling per whichModulesToPrepare
test-inputObjects.R default climateVariablesForFire; two defects below
test-covariates.R row set, column order, climate layer/year, non-forest columns, youngAge, igAggFactor aggregation and igAggFactor = 1, missingLCCgroup, fuel-class pins

Defects recorded, not blessed

Each states the intended assertion wrapped in expect_failure() -- so fixing the defect trips the test and forces the assertion to be unwrapped -- plus an assertion pinning the current state. No test asserts that buggy behaviour is correct.

  1. .inputObjects leaves rstLCC_RTM NULL. The suppliedElsewhere("rstLCCs", sim) branch (l.509-510) does tail(sim$rstLCCs, 1)[[1]], but rstLCCs is not a declared input, so it is absent from the simList and the result is NULL. A rstLCC_RTM passed to simInit() is overwritten by this. Init() (l.241) then errors subscript out of bounds on .compareRas(rtm, NULL) -- the module cannot complete init as shipped. The test helper restores rstLCC_RTM after simInit() so the rest of the suite can exercise the code past this point.
  2. .inputObjects cannot build flammableRTM (l.546): defineFlammable(rstLCC, ...) uses a local created only in the other branch, and the function is not imported.
  3. Covariate tables do not advance with simulation time. getCurrentClimate() (l.296) only builds currentClimateRasters when it is.null(). The event reschedules annually, but from year two the object is populated and the build is skipped, so climate is frozen at start(sim) -- while the year column does track time(sim). Running 2001->2003 yields a table labelled 2003 carrying 2001 climate.
  4. climateYear does not override time(sim). The inner lapply formal currentYear = time(sim) (l.322) shadows the outer currentYear (l.309-313). climateYear only reaches the "beyond the projection" message.
  5. lightningDays is NaN in the ignition table. The layer is selected correctly (sim$lightningMaps["lightningDays"], l.416, returns the right values -- checked directly); the loss is inside fireSenseUtils::mergePreparedCovs(). Not diagnosed further.
  6. Init() destroys categorical landcover on realignment. l.241-245 uses postProcess(..., to = rasterToMatch), which defaults to bilinear resampling; averaging class codes 19/16/210/20 gives values like 186.125 and 43.91, which match no class, so makeLandcoverDT() returns an all-NA landcoverDT -- silently, with the right rows and column names. Fix is method = "near".

Also confirmed: with the shipped whichModulesToPrepare default (fireSense_EscapeFit), only getClimateRasters and ageNonForest are scheduled and no covariate table is produced at all.

Honest labelling

The fuel-class magnitudes in test-covariates.R are a regression pin on fireSenseUtils internals, labelled as such -- not hand-derived. (The previous draft claimed they were "pinned from origin/development"; that claim was false and has been removed. They are in fact identical on both branches, verified by running the suite against each.)


Update (cbace6d)

This replaces "Possibly unused, kept" and the whichModulesToPrepare note above.

Removed; stop setting these:

  • parameters .plotInitialTime, .plotInterval, .saveInitialTime, .saveInterval
  • input fireSense_IgnitionFitted

Kept: .useCache (SpaDES.core reads it), climateYear (#13 makes it work), propFlammable (its only line is inside the block #13 rewrites; remove it after #13).

whichModulesToPrepare now defaults to fireSense_SpreadPredict, fireSense_IgnitionPredict and fireSense_EscapePredict. These are the three names doEvent tests for.

The save event now emits a message and does nothing else. The module never schedules it.

The version is not bumped here because #13 changes the same line.

eliotmcintire and others added 3 commits September 20, 2026 09:44
No behaviour change: only commented-out code, an if (FALSE) block, comments,
desc strings and Rmd text are touched. Several input descs had been passed
positionally into sourceURL; they are now in desc.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Adds tests for `ageNonForest()`, `getCurrentClimate()`, `Init()`/`init`,
`.inputObjects()` and the two covariate-assembly events, on a 4x4 toy
landscape whose every covariate can be worked out by hand. The toy climate
encodes both the year and the cell in its values, so an assertion on a value
proves which layer of which variable was taken.

99 assertions, no skips. Verified to pass identically on `origin/development`
and on this branch, run the way CI runs them (convertToPackage + test_local).
Every substantive test was mutation-checked: 14 mutations of the module
source, 14 detected.

Five defects are recorded, none of them blessed as correct: each states the
INTENDED assertion wrapped in `expect_failure()` so that fixing the defect
trips the test, plus an assertion pinning the current state.

- `.inputObjects` leaves `rstLCC_RTM` NULL: the `suppliedElsewhere("rstLCCs")`
  branch does `tail(sim$rstLCCs, 1)[[1]]`, but `rstLCCs` is not a declared
  input and so is absent. `Init()` then errors on `.compareRas(rtm, NULL)`,
  which makes the module unusable as shipped.
- `.inputObjects` cannot build `flammableRTM`: `defineFlammable(rstLCC, ...)`
  uses a local from the other branch and a function the module does not import.
- The covariate tables do not advance with simulation time: `getCurrentClimate()`
  only builds `currentClimateRasters` when it is NULL, so from year two on the
  climate is frozen at `start(sim)` while the `year` column still tracks
  `time(sim)` -- the table claims 2003 and carries 2001 climate.
- `climateYear` does not override `time(sim)`: the inner lapply's formal
  `currentYear = time(sim)` shadows the outer `currentYear`.
- `lightningDays` is NaN in the ignition table.
- `Init()` realigns landcover with bilinear `postProcess()`, averaging
  categorical class codes into non-classes and silently yielding an all-NA
  landcoverDT.
They are pinned observations of fireSenseUtils internals, identical on
origin/development and on this branch, not hand-derived truths.
…; add empty save event

Removed, never read: parameters .plotInitialTime, .plotInterval,
.saveInitialTime, .saveInterval; input fireSense_IgnitionFitted and its
check in .inputObjects, which only ran for a Fit module name.

whichModulesToPrepare now defaults to the three Predict modules that
doEvent tests for. It named fireSense_EscapeFit, which nothing tests for.

The save event emits a message and does nothing else.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B4sgRg9EwyHaAQdDzUaQW
eliotmcintire added a commit that referenced this pull request Sep 21, 2026
…Rasters alone

Merge #12 first; this branch now contains it.

Conflicts and how each was resolved:
- inputs metadata: #12's text and removals, with #13's climateYear class
  ("numeric") and the new rstLCCs input.
- getCurrentClimate() guard: #13's code. The two dead comments #12 removed
  stay removed.
- getCurrentClimate() assignment: #13's mod$currentClimateYear line, without
  the dead trailing comment.
- .inputObjects rstLCC block, both ends: #13's
  if (!suppliedElsewhere("rstLCC_RTM", sim)) wrapper.
- tests/testthat/test-getCurrentClimate.R: every test from both sides. #12's
  climateYear expect_failure pin is replaced by #13's test of the fix.

Correction to #13's stale-climate fix: the guard was keyed on the year alone,
so it rebuilt currentClimateRasters from projectedClimateRasters even when
another module had supplied it. In the project the climateYear module supplies
it every year, preferring historical rasters. Now a supplied object is left
alone, and only an object this module built is rebuilt when the year changes
(mod$builtCurrentClimate). New test: supplied every year, left untouched, and
the covariate tables carry the supplied values. It fails on #13 as pushed.

#12's expect_failure pins for the defects fixed here are now ordinary
expectations: rstLCC_RTM from rstLCCs, flammableRTM in .inputObjects,
nearest-neighbour landcover, covariates advancing each year. The toy helper's
rstLCC_RTM workaround is gone. The lightningDays pin stays; it is not fixed.

"the climate rasters are rebuilt when the year changes" now runs through
spades(), because mod only persists there.

Removed propFlammable (input and assignment): nothing reads it.
Version 1.0.4.9000.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B4sgRg9EwyHaAQdDzUaQW
@eliotmcintire
eliotmcintire merged commit a64003b into development Sep 21, 2026
6 checks passed
@eliotmcintire
eliotmcintire deleted the chore/dead-code-and-docs branch September 21, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant