Overview: the chain layer and its relation to the core API
GridR exposes two layers for grid resampling:
Core layer –
array_grid_resampling(and the standalone preprocessing helper) works on in-memory NumPy arrays. The caller owns the buffers and pays the cost of holding everything in RAM.Chain layer –
basic_grid_resampling_chainworks on rasterio datasets opened from disk. It iterates over output strips and tiles, reading and writing only what is needed at each step.
This notebook clarifies which core features are also available through the chain layer, how the chain reuses core code internally, and how to map each core argument to its chain counterpart.
What you’ll learn
The conceptual difference between core and chain layers
Why
standalonedoes not exist in the chain layerHow masking strategies are shared between the two layers
A complete
core kwarg ↔ chain kwargcorrespondence table
The chain layer wraps the core layer
basic_grid_resampling_chain does not reimplement resampling. For each tile of its output strip loop, it eventually calls array_grid_resampling with the relevant slice of input data and the relevant slice of the grid. The chain layer is responsible for:
Splitting the output into strips and tiles (
io_strip_size,tile_shape).Computing the minimal source-raster read window for each tile (
array_compute_resampling_grid_geometries).Reading the input raster, grid and masks from disk through rasterio.
Merging the source raster mask with the rasterized geometry masks into a single validity mask suitable for the core layer.
Forwarding all interpolation-related parameters (
interp,nodata_out,boundary_condition,trust_padding, …) directly to the core call.Writing the resampled output (and optional mask) back to disk.
Note – The masking strategy code is shared between the two> layers. Whether you call
array_grid_resamplingin standalone mode> orbasic_grid_resampling_chain, the same module decides how each> mask propagates through the interpolator and to the output mask;> only the application context differs (a single in-memory call vs.> a per-tile chain call). Consequently, every masking feature> documented in the core tutorials (input mask, grid mask, output> mask) behaves identically through the chain.
Why standalone is not a chain argument
At the core layer, standalone=True instructs array_grid_resampling to perform on-the-fly preprocessing (boundary extension, padding for the interpolator support, mask consolidation) before resampling. standalone=False skips this step and expects the caller to have provided a pre-padded source array.
The chain layer’s whole purpose is to provide a turnkey, file-to-file resampling: it always perform the preprocessing itself and calls the underlying core with standalone mode turned off. There is therefore no standalone argument on the chain side.
Core ↔ Chain argument correspondence
The table below maps every relevant core argument to its chain counterpart. Arguments marked forwarded are passed verbatim from the chain to the core layer for each tile call. Arguments marked chain-only govern the chain’s I/O loop and have no equivalent in the core API.
Resampling parameters
Core kwarg |
Chain kwarg |
Notes |
|---|---|---|
|
|
Chain always initialize the interpolator object. |
|
|
Forwarded as-is. |
|
|
Forwarded as-is. |
|
|
Forwarded as-is. |
|
|
Forwarded as-is. |
|
(none) |
Chain always behaves as standalone; see above. |
|
(none, managed internally) |
Set per tile by the chain to account for the tile’s origin within the source raster. |
|
|
Forwarded as-is; expressed in full-resolution output coordinates. |
|
|
Chain-only; offset applied to grid coordinates before any geometry computation. |
Input source data
Core kwarg |
Chain kwarg |
Notes |
|---|---|---|
|
|
The chain reads the relevant tile from disk and forwards it. |
|
|
Same idea; the chain reads the grid coordinates from disk. |
Masks
Core kwarg |
Chain kwarg |
Notes |
|---|---|---|
|
|
Source raster mask; the chain reads the relevant tile of the mask and forwards it. |
(N/A) |
|
Chain-only; rasterized at tile level and merged with the source raster mask before forwarding to the core. |
|
|
Grid validity mask; forwarded after rebinarisation to the GridR |
Outputs
Core kwarg |
Chain kwarg |
Notes |
|---|---|---|
return: |
|
The chain writes each tile back to disk in place of allocating a return buffer. |
return: |
|
Optional. Same per-tile write pattern. |
Chain-only: I/O loop
Chain kwarg |
Purpose |
|---|---|
|
Maximum strip height (in output rows by default). |
|
Whether |
|
Sub-divide each strip into |
|
Optional |
What this means in practice
If you have already mastered the core tutorial series, switching to the chain layer for a production-scale, file-oriented workflow only requires:
Replacing NumPy buffer arguments by their rasterio dataset equivalents (per the table above).
Adding the chain-only I/O parameters that match your memory budget (
io_strip_size,tile_shape).Optionally taking advantage of chain-only conveniences such as geometry masks and
grid_shift.
Every other parameter you know from the core API still applies, with the same meaning and the same defaults.