Skip to content

fork default: LCCClassesToReplaceNNMethod = 'nearestWeighted'; require LandR (>= 1.2.0.9005) - #1

Merged
achubaty merged 1 commit into
mainfrom
convertUnwantedLCC-method
Aug 5, 2026
Merged

fork default: LCCClassesToReplaceNNMethod = 'nearestWeighted'; require LandR (>= 1.2.0.9005)#1
achubaty merged 1 commit into
mainfrom
convertUnwantedLCC-method

Conversation

@achubaty

@achubaty achubaty commented Aug 5, 2026

Copy link
Copy Markdown

Fork-side counterpart of PredictiveEcology#102, which adds the LCCClassesToReplaceNNMethod parameter upstream.

Depends on PredictiveEcology/LandR#197 — merge that first.

Deliberate divergence from upstream

Same parameter, different default:

default why
upstream (PredictiveEcology#102) "nearestRandom" preserves the stochastic allocation the module has always had
this fork "nearestWeighted" the projects consuming this fork (LandWeb et al.) want reproducibility without seed management, and want a cropped development subset to agree with the full-extent run

"nearestWeighted" keys the draw on the pixel's ground position rather than the RNG. It is deterministic, needs no set.seed(), is stable under Cache(), and — because the key is the cell centre rather than the cell index — a grid-aligned crop of the study area gives the same answer as the full extent. The abundance weighting is identical to "nearestRandom"; only the source of the draw differs.

Setting it as the fork default rather than in each project's parameter config means projects get the intended behaviour without having to remember to pass it.

Also here, and not upstream

The reqdPkgs floor moves to LandR (>= 1.2.0.9005) for a second reason that only applies to this fork: LandR 1.2.0.9004 dropped the newPossLCC column that this fork's write-back block uses.

if (!is.null(newLCCClasses$newPossLCC)) {
  rstLCCAdj[newLCCClasses$pixelIndex] <- newLCCClasses$newPossLCC
}

That is.null() guard silently stopped firing under 1.2.0.9004, leaving rstLCCAdj — and therefore ecoregionMap — showing the un-replaced classes. LandR#197 restores the column; the comment now records the gap so the floor isn't lowered later without noticing. Upstream doesn't carry this block, so PredictiveEcology#102 doesn't need the note.

Testing

  • Module metadata parses; SpaDES.core::moduleParams() registers the parameter, moduleMetadata() reports the bumped floor and version = 1.5.13.
  • Not yet run end-to-end: LandWeb's renv still pins LandR 1.2.0.9004, so the lockfile needs updating once LandR#197 merges before a dataPrep run will exercise this.

Related

🤖 Generated with Claude Code

Exposes LandR::convertUnwantedLCC()'s new `method` argument, added in
PredictiveEcology/LandR#197, as a module parameter. Both options allocate each
LCCClassesToReplaceNN pixel a neighbouring class drawn in proportion to that class's
local abundance, and differ only in reproducibility:

  nearestWeighted (default) -- keyed on the pixel's ground position: deterministic,
    needs no seed, stable under Cache(), and a grid-aligned crop of the study area
    gives the same answer as the full extent (so a small dev subset agrees with the
    scaled-up run).
  nearestRandom -- draws from the RNG, for when replicates should differ.

The LandR floor moves to 1.2.0.9005 for two reasons. `method` does not exist before
it, so an older LandR fails with an unused-argument error rather than silently doing
something else. And 1.2.0.9004 had dropped the `newPossLCC` column that the block
below uses to write replacement classes back into rstLCCAdj -- the is.null() guard
there silently stopped firing, leaving rstLCCAdj, and hence ecoregionMap, showing the
un-replaced classes. 1.2.0.9005 restores it; the comment now records the gap.

Not yet exercised end-to-end: LandWeb's renv still pins LandR 1.2.0.9004, so the
lockfile needs updating once LandR#197 merges before a dataPrep run will work.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@achubaty achubaty changed the title new parameter LCCClassesToReplaceNNMethod; require LandR (>= 1.2.0.9005) fork default: LCCClassesToReplaceNNMethod = 'nearestWeighted'; require LandR (>= 1.2.0.9005) Aug 5, 2026
@achubaty
achubaty merged commit 991ea52 into main Aug 5, 2026
@achubaty
achubaty deleted the convertUnwantedLCC-method branch August 5, 2026 16:10
achubaty added a commit to PredictiveEcology/LandWeb that referenced this pull request Aug 5, 2026
…lDataPrep

Bumps the Biomass_borealDataPrep submodule to FOR-CAST main, which merges the new
`LCCClassesToReplaceNNMethod` parameter (FOR-CAST/Biomass_borealDataPrep#1), and sets it
explicitly in both parameter configs.

The fork already defaults to "nearestWeighted", so setting it here is belt-and-braces --
it keeps the intent visible next to LCCClassesToReplaceNN, and pins the behaviour if this
project ever tracks upstream, whose default is "nearestRandom"
(PredictiveEcology/Biomass_borealDataPrep#102).

"nearestWeighted" allocates each replaced pixel a neighbouring class drawn in proportion
to that class's local abundance, keyed on the pixel's ground position rather than the RNG:
deterministic without a seed, stable under Cache(), and a grid-aligned crop of a study
area gives the same answer as the full extent -- so a small development subset agrees with
the scaled-up run.

NOT yet runnable: renv still pins LandR 1.2.0.9004, which has no `method` argument. Once
PredictiveEcology/LandR#197 merges, update the lockfile via
`renv::install("PredictiveEcology/LandR@development", lock = TRUE)` (never snapshot()).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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