Skip to content

SyncroSim v3.1 updates#1

Open
sarah-chisholm wants to merge 2 commits into
mainfrom
sc-syncrosim-3.1-update
Open

SyncroSim v3.1 updates#1
sarah-chisholm wants to merge 2 commits into
mainfrom
sc-syncrosim-3.1-update

Conversation

@sarah-chisholm
Copy link
Copy Markdown
Member

@sarah-chisholm sarah-chisholm commented May 6, 2026

The stsimNestweb package was updated from the SyncroSim v2 package format to v3, which required significant restructuring of the package.xml: wrapper elements were removed, datasheet definitions were moved to the top level, transformer I/O declarations were simplified, and layout name attributes were replaced with type. Additional v3.1-specific fields were added including minSyncroSimVersion, condaEnvVersion, isStochasticTime, and updateProvider. Column naming convention was also updated from ID to Id suffix throughout the XML and R scripts.

The conda environment was modernized by removing the deprecated r-rgdal package, updating Python from 3.6 to 3.11, pinning r-rsyncrosim>=2.1.9, and adding missing direct dependencies (r-terra, r-lme4, r-glmmtmb). In the R scripts, all calls to the deprecated datasheetSpatRaster() function were replaced with the v3-compatible datasheet() %>% filter() %>% pull() %>% rast() pattern.

Summary by CodeRabbit

  • Documentation

    • Added comprehensive README with installation steps, workflow overview, input/output specs, GLMM requirements and contact info.
  • New Features

    • Added package definition with datasheets, transformers, layouts and output specifications.
    • Added Conda environment file with pinned R package dependencies.
  • Refactor

    • Updated habitat modelling and summarization scripts for consistent ID naming and revised raster loading/handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1b3c67dd-c7fd-460a-8a7d-48acc8ff065b

📥 Commits

Reviewing files that changed from the base of the PR and between 2e73d58 and 284314d.

📒 Files selected for processing (1)
  • src/stsimnestweb.yml
✅ Files skipped from review due to trivial changes (1)
  • src/stsimnestweb.yml

Walkthrough

Adds a complete SyncroSim add-on (stsimNestweb): package manifest and metadata, a pinned Conda environment, R transformers (modelHabitat.R, summarizeHabitat.R) updated to use explicit datasheet→FileName→rast() loading and consistent *Id naming, multiple output datasheets/layouts, and an expanded README.

Changes

stsimNestweb package + tooling

Layer / File(s) Summary
Package Metadata / Data Shape
src/package.xml, src/.metadata
Introduces stsimNestweb package manifest (version 1.0.0), declares project/scenario datasheets (SiteType, Species, HabitatModel, SiteValue, InvalidHabitat, OutputOptions) and multiple output datasheets for habitat amounts and spatial products; adds XML package header with builtForSyncroSimVersion.
Transformer Declarations / Pipeline Wiring
src/package.xml
Declares runnable transformers modelHabitat (RScript, remote) and summarizeHabitat (RScript, local) and wires them into a Primary pipeline transformer; registers layouts (Project, Scenario, Chart, Map) and an XML update provider.
Conda Environment
src/stsimnestweb.yml
Adds stsimnestweb_env Conda environment YAML pinned to r-base=4.1.3 and a list of specific R package versions with conda-forge channel.
Core Implementation — modelHabitat
src/modelHabitat.R
Renames/normalizes identifier columns to *Id (e.g., StratumId, SecondaryStratumId), rebuilds invalidHabitatLookup construction, changes raster-loading to datasheet(...) %>% pull(Filename) %>% rast(), computes edge-distance from stateClass raster, and updates tabular grouping and ID→name lookups to use *Id fields.
Core Implementation — summarizeHabitat
src/summarizeHabitat.R
Replaces datasheetSpatRaster() with datasheet query → pull(FileName)rast() for habitat suitability and optional change rasters; preserves timestep/species iteration, mean layer aggregation, and GeoTIFF export behavior.
Documentation
README.md
Replaces minimal header with full package documentation: overview, installation, workflow, input/output specifications, pipeline and transformer description, GLMM covariate requirements, and contact information.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'SyncroSim v3.1 updates' is vague and generic, using non-descriptive phrasing that doesn't convey the scope or primary nature of the substantial changes made throughout the codebase. Consider a more specific title that highlights the main change, such as 'Migrate stsimNestweb package to SyncroSim v3.1 format and update dependencies' or 'Update package structure and R scripts for SyncroSim v3.1 compatibility'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sc-syncrosim-3.1-update

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/modelHabitat.R (2)

116-116: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Hardcoded absolute path will break portability.

Same issue as line 80—"D:/nestweb/Model-Inputs/Spatial/mean-decay.tif" is machine-specific and will fail in remote execution or on other systems.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modelHabitat.R` at line 116, Replace the hardcoded absolute path in the
meanDecay assignment (the rast(...) call that creates variable meanDecay) with a
portable construction: read the base inputs directory from a configuration
variable or environment variable (e.g., inputs_dir or
Sys.getenv("MODEL_INPUTS_DIR")) or build a project-relative path using
file.path() or here::here(), then pass that constructed path to rast(); update
the meanDecay assignment to use that config/env or relative path so the code
works on other machines and in remote execution.

137-137: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Hardcoded absolute path will break portability.

Third instance of the hardcoded "D:/nestweb/" path. All three occurrences (lines 80, 116, 137) should be refactored to use configurable or relative paths.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modelHabitat.R` at line 137, The code uses a hardcoded absolute path
"D:/nestweb/" in read_csv when building rawNestwebData (and two other
occurrences at the same file), which breaks portability; replace the literal
with a single configurable variable or a relative path helper (e.g., define
nestweb_dir at top of script or use here::here()/file.path(getwd(), ...) and
then call read_csv(file.path(nestweb_dir, tabularDataDir, "Habitat selection -
full dataset (30.03.2022).csv"), show_col_types = FALSE) %>%); update all three
occurrences (around the rawNestwebData/read_csv uses) to reference that
variable/helper so the path is centralized and portable.
🧹 Nitpick comments (1)
src/modelHabitat.R (1)

83-105: 💤 Low value

Complex lookup construction—consider adding clarifying comments.

The invalidHabitatLookup construction involves multiple left joins with self-generated expansion tables and an anti-join pattern. While functionally correct for expanding wildcard rows to explicit combinations, the logic is dense.

Consider adding a brief comment explaining the intent: expanding partial/wildcard InvalidHabitat entries to explicit species–stratum–state class combinations for raster masking.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modelHabitat.R` around lines 83 - 105, The invalidHabitatLookup pipeline
is dense and should get a short clarifying comment: above the chain that starts
with InvalidHabitat and builds invalidHabitatLookup, add a one- or two-sentence
comment stating that the code expands wildcard/partial InvalidHabitat rows into
explicit Species–StateClass–Stratum combinations (by joining replicated name
vectors from Stratum, StateClass and names(SpeciesID), using anti_join against
the full expand_grid of Species/StateClassId/StratumId, then mapping names to
IDs via lookup and computing StateClassStratumId) so readers understand why
left_join, expand_grid, anti_join, lookup and the final bind_rows/unique steps
are used.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modelHabitat.R`:
- Line 80: The read_csv call that assigns speciesCodes uses a hardcoded absolute
path "D:/nestweb", which breaks portability; update the call that constructs the
filepath (the speciesCodes <- read_csv(...) invocation that references
tabularDataDir) to build the path from a portable source instead (e.g., the
scenario/data directory, an environment variable, or a relative path helper) so
the code works across machines and remote runs—replace the absolute "D:/nestweb"
with a reference to a configurable base path (env var or scenario data folder)
and ensure tabularDataDir is appended via file.path.
- Around line 47-48: The variable assignment uses inconsistent column casing: in
modelHabitat.R the pipeline pulls "SpeciesId" into SpeciesID while elsewhere
(summarizeHabitat.R) code expects "SpeciesID"; confirm the actual column name
returned by datasheet(myScenario, "stsimNestweb_Species", includeKey = TRUE) and
make both callers use the same exact column name, updating the pull(...) call in
the SpeciesID assignment and the corresponding pull in summarizeHabitat.R so
they reference the identical column string (e.g., "SpeciesID" or "SpeciesId")
and keep the exported variable name SpeciesID consistent.

---

Outside diff comments:
In `@src/modelHabitat.R`:
- Line 116: Replace the hardcoded absolute path in the meanDecay assignment (the
rast(...) call that creates variable meanDecay) with a portable construction:
read the base inputs directory from a configuration variable or environment
variable (e.g., inputs_dir or Sys.getenv("MODEL_INPUTS_DIR")) or build a
project-relative path using file.path() or here::here(), then pass that
constructed path to rast(); update the meanDecay assignment to use that
config/env or relative path so the code works on other machines and in remote
execution.
- Line 137: The code uses a hardcoded absolute path "D:/nestweb/" in read_csv
when building rawNestwebData (and two other occurrences at the same file), which
breaks portability; replace the literal with a single configurable variable or a
relative path helper (e.g., define nestweb_dir at top of script or use
here::here()/file.path(getwd(), ...) and then call
read_csv(file.path(nestweb_dir, tabularDataDir, "Habitat selection - full
dataset (30.03.2022).csv"), show_col_types = FALSE) %>%); update all three
occurrences (around the rawNestwebData/read_csv uses) to reference that
variable/helper so the path is centralized and portable.

---

Nitpick comments:
In `@src/modelHabitat.R`:
- Around line 83-105: The invalidHabitatLookup pipeline is dense and should get
a short clarifying comment: above the chain that starts with InvalidHabitat and
builds invalidHabitatLookup, add a one- or two-sentence comment stating that the
code expands wildcard/partial InvalidHabitat rows into explicit
Species–StateClass–Stratum combinations (by joining replicated name vectors from
Stratum, StateClass and names(SpeciesID), using anti_join against the full
expand_grid of Species/StateClassId/StratumId, then mapping names to IDs via
lookup and computing StateClassStratumId) so readers understand why left_join,
expand_grid, anti_join, lookup and the final bind_rows/unique steps are used.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed4f7f6a-4247-44f8-b85d-a58b5e653879

📥 Commits

Reviewing files that changed from the base of the PR and between 44c5024 and 2e73d58.

📒 Files selected for processing (8)
  • README.md
  • package.xml
  • src/.metadata
  • src/modelHabitat.R
  • src/package.xml
  • src/stsimnestweb.yml
  • src/summarizeHabitat.R
  • stsimnestweb.yml
💤 Files with no reviewable changes (1)
  • package.xml

Comment thread src/modelHabitat.R
Comment on lines +47 to +48
SpeciesID <- datasheet(myScenario, "stsimNestweb_Species", includeKey = TRUE) %>%
pull(SpeciesId, name = Name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Compare SpeciesId vs SpeciesID usage across both R scripts
echo "=== modelHabitat.R ==="
rg -n 'SpeciesI[Dd]' src/modelHabitat.R
echo ""
echo "=== summarizeHabitat.R ==="
rg -n 'SpeciesI[Dd]' src/summarizeHabitat.R

Repository: ApexRMS/stsimNestweb

Length of output: 1917


🏁 Script executed:

#!/bin/bash
# Search for schema definitions or documentation files that might define the Species datasheet structure
echo "=== Looking for schema files ==="
fd -e "json" -e "csv" -e "yaml" -e "yml" | grep -i "species\|schema" | head -20

echo ""
echo "=== Looking for test files that might use this datasheet ==="
fd -e "R" -e "r" | xargs rg -l "stsimNestweb_Species" | head -10

echo ""
echo "=== Check if there are any example data or vignettes ==="
find . -type f \( -name "*species*" -o -name "*example*" -o -name "*vignette*" \) | head -20

Repository: ApexRMS/stsimNestweb

Length of output: 259


🏁 Script executed:

#!/bin/bash
# Search for any references to the column name in comments or documentation
echo "=== Looking for column name documentation ==="
rg -A 2 -B 2 "SpeciesId|SpeciesID" . --type r | grep -i "column\|field\|datasheet" -A 2 -B 2 | head -30

echo ""
echo "=== Check the datasheet call in both files for any hints ==="
rg -A 5 "datasheet.*stsimNestweb_Species" src/

Repository: ApexRMS/stsimNestweb

Length of output: 1889


Fix naming inconsistency: SpeciesId vs SpeciesID column name mismatch.

modelHabitat.R (line 48) pulls SpeciesId (lowercase 'd'), while summarizeHabitat.R (line 28) pulls SpeciesID (uppercase 'D'). Both call the same datasheet, so one of these will fail at runtime. Verify the actual column name returned by datasheet(..., "stsimNestweb_Species", includeKey = TRUE) and update both files to use the correct name consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modelHabitat.R` around lines 47 - 48, The variable assignment uses
inconsistent column casing: in modelHabitat.R the pipeline pulls "SpeciesId"
into SpeciesID while elsewhere (summarizeHabitat.R) code expects "SpeciesID";
confirm the actual column name returned by datasheet(myScenario,
"stsimNestweb_Species", includeKey = TRUE) and make both callers use the same
exact column name, updating the pull(...) call in the SpeciesID assignment and
the corresponding pull in summarizeHabitat.R so they reference the identical
column string (e.g., "SpeciesID" or "SpeciesId") and keep the exported variable
name SpeciesID consistent.

Comment thread src/modelHabitat.R
@@ -80,29 +80,29 @@ species <- HabitatModel$Name
speciesCodes <- read_csv(file.path("D:/nestweb", tabularDataDir, "species-codes.csv"), show_col_types = FALSE)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Hardcoded absolute path will break portability.

"D:/nestweb" is a machine-specific absolute path. This will fail on any other system or when deployed to remote execution environments (the transformer is configured with runContext="AllowRemote").

Consider using relative paths from the scenario's data folder, environment variables, or scenario-level configuration to specify data locations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modelHabitat.R` at line 80, The read_csv call that assigns speciesCodes
uses a hardcoded absolute path "D:/nestweb", which breaks portability; update
the call that constructs the filepath (the speciesCodes <- read_csv(...)
invocation that references tabularDataDir) to build the path from a portable
source instead (e.g., the scenario/data directory, an environment variable, or a
relative path helper) so the code works across machines and remote runs—replace
the absolute "D:/nestweb" with a reference to a configurable base path (env var
or scenario data folder) and ensure tabularDataDir is appended via file.path.

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