
Collapse duplicate communities in an Output Biomass Community snapshot
dedup_community_snapshot.RdBiomass Succession writes its Output Biomass Community state with one map
code per pixel: succession is evaluated per cell, so the writer emits a
distinct MapCode for every active cell and never re-collapses cells whose
cohort lists ended up identical. On a large landscape almost all of those map
codes are duplicates of one another, and the redundancy is carried entirely by
the CSV.
Arguments
- csv
Path to the snapshot CSV (
community-input-file-<t>.csv), with aMapCodecolumn plus the cohort columns (typicallySpeciesName,CohortAge,CohortBiomass).- tif
Path to the matching map-code raster (
output-community-<t>.tif).- out_csv, out_tif
Output paths. Default to overwriting
csv/tif.- quiet
Suppress the summary message.
A snapshot can also contain empty communities: active cells whose map code has no CSV rows at all (no cohorts – recently disturbed, or active but unforested). Biomass Succession emits these itself. They are active landscape, so they are collapsed to one shared code and left active rather than zeroed; the active-cell count is asserted unchanged before anything is written.
The rewritten raster is written with the smallest pixel type LANDIS-II accepts that holds the largest new code:
INT1U(GDALByte),INT2S(Int16) orINT4S(Int32). Its GDAL reader takes only byte, short, int, float and double, so the unsigned 16- and 32-bit types are rejected – as isINT1S, which GDAL 3.7+ writes asInt8. The type is pinned rather than inferred.
Value
Invisibly, a list with csv, tif, map_codes_before,
map_codes_after, rows_before, rows_after, empty_code (the shared
empty-community code, NA if there were none), empty_cells and
datatype.
Details
That matters because LANDIS-II reads initial communities back through
Landis.Library.InitialCommunities.Universal.DatasetParser, which builds a
System.Dynamic.ExpandoObject per row. The parser's memory cost is a large
multiple of the file size, so a snapshot that is mostly duplicate rows can
exhaust a container's --memory and abort the run with
System.OutOfMemoryException inside ReadCSVInputFile, before the simulation
starts. Measured on a 2.98M-active-cell landscape: 2,684,154 map codes
carrying only 4,153 distinct communities – a 1,472 MB CSV that deduplicates
to roughly 2 MB.
This rewrites the pair so that one map code represents each distinct community and the raster points every pixel at its community's new code. The simulated state is unchanged: every pixel still maps to exactly the cohort list it had before.
Two communities are the same when their cohort sets are identical, compared
on every non-MapCode column after ordering rows canonically within a map
code. Biomass is compared exactly – no rounding – so this never merges
cells that differ, only cells that are already identical.
See also
Other Dynamic Fire calibration helpers:
apply_calibrated_damage_age(),
apply_calibrated_hi_prop(),
apply_calibrated_ignprob(),
apply_calibrated_num_fires(),
bc_fuel_code_to_base(),
build_calibration_scenario_template(),
build_calibration_spinup_scenario(),
calibrate_dynamic_fire(),
calibration_par_names(),
default_severity_prior_sturtevant2009(),
landis_overstory_mortality_share(),
loss_from_stats(),
observed_fire_sizes(),
parse_dynamic_fire_logs(),
patch_fire_config(),
run_calibration_spinup(),
run_calibration_validation(),
save_observed_fire_targets(),
sim_landis(),
sim_mock(),
sim_r_reimpl()