Aggregation Guide¶
CUSP contains many observations that are densely sampled in some places and much sparser elsewhere. Aggregation can be useful when a model assumes more independent observations, when you want to reduce the influence of dense local sampling, or when you plan to join CUSP to environmental layers that are much coarser than individual field points.
The CUSP aggregation tool assigns observations to generated square cells or
to cells in a user-supplied polygon layer, then links dates within each cell
and calendar year. The default settings are
30 m cells and a maximum 31-day gap between consecutive observations, but
you can choose values appropriate for your analysis.
What Aggregation Does¶
The aggregation workflow:
- starts from a CUSP observation table
- groups observations that fall in the same projected grid cell
- starts a new temporal group whenever the gap between consecutive dates is greater than the linkage threshold
- keeps annual separation so records from different years are not grouped together
- allows grouping across sources
- preserves provenance through a membership table
- sets aggregated
pf_observedto the mean of member0/1values - sets aggregated
methodtomixedwhen multiple methods are present - carries forward the union of member
quality_flags
Important default settings:
| Setting | Default | Meaning |
|---|---|---|
| Distance threshold | 30 m |
Observations are grouped within projected 30 m grid cells unless you pass a different --distance-m value. |
| Temporal linkage | 31 days |
Within the same year and grid cell, consecutive observations remain linked when their date gap is no more than 31 days. |
| Total group span | not fixed | The rule is single-linkage: a chain of qualifying date gaps can produce a group spanning more than 31 or 62 days. |
| Annual separation | preserved | Observations from different calendar years are not grouped together. |
| Grouping projection | EPSG:3413 |
Spatial grouping is computed in a projected Arctic coordinate system. |
| Output coordinates | EPSG:4326 |
Aggregated latitude and longitude are exported in WGS84. |
Southern Hemisphere observations
Beginning with v1.2, CUSP includes Southern Hemisphere sites. The default aggregation projection,
EPSG:3413, is designed for the Arctic: a 30 m projected cell does not have
the intended ground scale at these sites. Use the canonical observations
and a suitable local or Southern Hemisphere projection for their spatial
analysis. Passing --distance-m alone does not change the projection.
Run The Default Aggregation¶
From a CUSP repository checkout, run the default workflow from the repository
root. It reads data/cusp_observations.csv and writes the aggregation bundle to
data/:
python -m cusp.aggregate
python -m cusp.qc validate-aggregated
The defaults are relative to your current working directory, not to the Python
installation directory. If you installed the tools and downloaded a versioned
release CSV, run the following from the directory containing
cusp_v1.3.csv:
python -m cusp.aggregate \
--input cusp_v1.3.csv \
--data-dir cusp_aggregation
python -m cusp.qc validate-aggregated \
--input cusp_aggregation/aggregated_30m.csv \
--membership cusp_aggregation/aggregated_30m_membership.csv
Explicit input or output paths override the corresponding path derived from
--data-dir.
Important Options¶
See all options with:
python -m cusp.aggregate --help
Common options:
| Option | What it controls |
|---|---|
--data-dir |
Directory used for default input and output paths. The default is ./data. |
--input |
Observation-level table to aggregate. |
--output |
Aggregated CSV to write. |
--membership-output |
Table linking each original cusp_obs_id to an aggregated group. |
--flags-output |
QC flags for mixed sources, mixed methods, mixed permafrost labels, and similar checks. |
--excluded-output |
Rows skipped by the aggregation workflow. |
--gpkg-output |
GeoPackage export of aggregated points. |
--manifest-output |
Parameters, row counts, hashes, and run metadata. |
--distance-m |
Projected square cell side length in meters. The default is 30. |
--grid |
Polygon grid file with a declared CRS and unique cell IDs. |
--grid-layer |
Layer to read from a multilayer vector file. |
--grid-id-column |
Cell ID attribute in the supplied grid. The default is grid_id. |
--temporal-link-days |
Temporal linkage threshold in days. The default is 31. |
The output date is the latest member date in each group. Because grouping is
based on consecutive date gaps, --temporal-link-days is not a symmetric
window around that output date and does not impose a hard maximum group span.
Example: Custom Aggregation¶
python -m cusp.aggregate \
--input exports/latest/cusp_v1.3.csv \
--output runs/examples/aggregated_100m_example.csv \
--membership-output runs/examples/aggregated_100m_example_membership.csv \
--flags-output runs/examples/aggregated_100m_example_qc_flags.csv \
--excluded-output runs/examples/aggregated_100m_example_excluded_rows.csv \
--gpkg-output runs/examples/aggregated_100m_example.gpkg \
--manifest-output runs/examples/aggregated_100m_example_manifest.json \
--distance-m 100 \
--temporal-link-days 14
If you publish or share a custom aggregation, name it clearly so other users can distinguish it from the original CUSP release table.
Aggregate Within A Supplied Grid¶
Prepare a GeoPackage, GeoJSON, or Shapefile containing Polygon or MultiPolygon
features with a defined CRS and a unique string or integer ID for each cell.
String identifiers retain leading zeros. Supply Shapefile companion files
together with the .shp file. Use --grid-layer when the file has multiple
spatial layers. The default ID attribute is grid_id; select a different
attribute with --grid-id-column.
From a repository checkout, this example uses the small irregular MPAS mesh fixture provided for issue #49. Replace the grid path and ID attribute with your own layer for analysis.
python -m cusp.aggregate \
--input exports/latest/cusp_v1.3.csv \
--grid tests/fixtures/grids/mpas_arctic_subset.geojson \
--grid-id-column cell_id \
--data-dir runs/examples/custom-grid
python -m cusp.qc validate-aggregated \
--input runs/examples/custom-grid/aggregated_custom_grid.csv \
--membership runs/examples/custom-grid/aggregated_custom_grid_membership.csv
CUSP transforms observation points into the grid CRS before assigning them
to polygons. Supplied cells define the spatial grouping, so --grid and an
explicit --distance-m are mutually exclusive. Each cell then uses the same
calendar-year separation, consecutive-date linkage, field summaries, source
attribution, and quality-flag union described above. One cell can produce
several aggregate rows across years or separated date groups.
The assignment rules are deterministic.
| Location | Behavior |
|---|---|
| Covered by one polygon | Assign to that cell, including its outer boundary. |
| Strictly inside one polygon and on another's boundary | Assign to the polygon containing the point's interior location. |
| On a shared boundary with zero interior matches | Assign to the smallest cell ID in lexicographic string order. For example, "10" sorts before "2". |
| Strictly inside multiple polygons | Stop with observation IDs and candidate cell IDs. |
| Outside all cells, including uncovered polygon holes | Record once in the exclusions CSV with exclusion_reason = outside_grid. |
Invalid geometry and missing or duplicate cell IDs produce errors with diagnostic identifiers. Overlap checks apply at observation locations. Grid geometry follows the planar coordinates encoded in its CRS. Prepare cells crossing the antimeridian or projection seams as correctly split polygons or multipart features in an appropriate CRS before aggregation.
Custom outputs use the aggregated_custom_grid stem. The point table contains
cusp_agg_id and the supplied cell identifier as grid_id. Join it back to
the polygon layer using grid_id. The membership table links cusp_obs_id
to cusp_agg_id; the flags table uses the same aggregate ID. Custom IDs depend
on the cell ID and the sorted member observation IDs. Cell and observation
row ordering have no effect on output membership or IDs.
The exported WGS84 coordinates identify the observed member nearest to the
group's mean location in grid coordinates, breaking ties by observation ID.
This representative location lies inside or on the assigned cell, including
concave and multipart polygons. Subsequent feature sampling evaluates this
point location. Polygon-wide environmental summaries can be computed
separately using the supplied polygons and grid_id.
The manifest records grid and observation input checksums, layer selection, CRS, matching rules, row accounting, boundary-tie counts, and artifact hashes. Zero-coverage runs write empty aggregate tables and an empty point layer with every input observation accounted for in the exclusions table. Outputs are staged before publication, and the manifest is published last. A failed publication can be retried using the same output paths.
For Python use, pass a GeoDataFrame through grid and its identifier through
grid_id_column to build_aggregation_tables. The existing
temporal_link_days argument applies to both spatial assignment methods.
When To Use Custom Aggregation¶
Custom aggregation runs are useful for:
- sensitivity analysis
- testing alternate model input density
- evaluating different spatial thinning choices
- matching the approximate scale of environmental covariates
- comparing how temporal linkage changes grouped records
They are user-created derivatives unless they are explicitly published as CUSP release files.
Check A Custom Run¶
For non-default outputs, inspect at least:
- row count
n_grouped- fraction of mixed-method groups
- fraction of mixed-source groups
- whether grouped points look spatially reasonable
You may also want to re-sample environmental features for the aggregated table. See GEE feature sampling.