Skip to contents

Biomass 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.

Usage

dedup_community_snapshot(csv, tif, out_csv = csv, out_tif = tif, quiet = FALSE)

Arguments

csv

Path to the snapshot CSV (community-input-file-<t>.csv), with a MapCode column plus the cohort columns (typically SpeciesName, 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 (GDAL Byte), INT2S (Int16) or INT4S (Int32). Its GDAL reader takes only byte, short, int, float and double, so the unsigned 16- and 32-bit types are rejected – as is INT1S, which GDAL 3.7+ writes as Int8. 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.