Skip to main content

Processing component

Running Python code from processing component:

  • Build the container in project root: docker compose build processing
  • Run code: docker compose run --rm processing python -m pinta_processing.main or docker compose run --rm processing python src/pinta_processing/main.py

The release workflow builds the prod image from the published pinta-processing wheel and its bundled constraints. Versioned releases are published as both processing:<version> and pinta-processing:<version> images.

Table of contents

Parallel raster ingestion and staging tables

Note: This section describes behaviour that spans the processing, db, and dags components. The raster writer lives here in processing, but the staging-table lifecycle (creation, merge, constraints) lives in the db utilities and is orchestrated by the load_dem and calculate_reference_dem DAGs. It is documented here for now because the processing pipeline is the natural entry point; it may move to the db or dags component later.

Overview

Loading a DEM is parallel at the file level: each input file (a .zip raster for load_dem, or a LAS/LAZ tile rasterised with las2dem for calculate_reference_dem) is handled by its own pipeline, and many pipelines run at the same time. Each pipeline reads its input, tiles the raster onto a fixed global grid, and writes those tiles to PostGIS raster storage.

Having every pipeline write directly into one shared raster table does not scale: concurrent writers serialise on shared, table-level resources (see below). Instead, each logical table (dem and its overviews) is backed by a number of short-lived staging tables. The parallel pipelines spread their tiles across the staging tables, and once they all finish, a single step merges the staging tables into the main table:

Staging table flow: one pipeline per input file writes tiles in parallel across the staging tables, routing each tile by hash of its grid cell; a single merge step then fuses the staging tables into the main table and drops them

Why staging tables? PostgreSQL pages, TOAST and write contention

PostgreSQL stores table data in fixed 8 KB pages, and a row must fit on a single page. When a value is larger than about a quarter of a page (~2 KB), PostgreSQL stores it out-of-line using TOAST: the value is sliced into chunks held in a separate, table-private TOAST relation, and the row keeps only a pointer to them.

A raster tile is far larger than a page — a 256×256 float32 block is 256 KB — so the raster column is always TOASTed. Writing a single tile therefore touches several physical structures at once: the table's own heap, its TOAST relation, and that relation's index.

When many pipelines write into the same table concurrently, they contend on those shared structures. The dominant cost is the relation-extension lock: only one backend at a time may append new pages to a given relation, and continuously growing both a table and its TOAST relation makes concurrent writers queue behind one another. A shared spatial index or uniqueness constraint on the raster column would serialise them further still.

Writing to several separate staging tables avoids this. Each staging table is its own relation with its own heap, TOAST relation, and extension lock, so spreading tiles across them splits the contention. Each tile is routed to a staging table by hashing its position on the global grid, which spreads tiles evenly.

The global tile grid and file-edge duplicates

The writer does not store inputs as-is; it re-tiles every input onto a single global grid that is the same for all files, using a fixed tile size. For each grid cell an input overlaps, it produces one full tile, pre-filled with nodata, and copies in whatever part of the input falls inside that cell.

Snapping every file to the same global grid is what makes parallel ingestion mergeable: a given location always yields a tile with the exact same extent, no matter which file produced it.

At the edges of an input file, a grid cell is only partly covered. The tile for that cell holds real data over the covered part and nodata everywhere else. The neighbouring file covers the other part of the same cell and produces a tile at the identical extent — again nodata where it has no data. So along every shared border you get two overlapping duplicate tiles (and up to four at grid corners): same extent, complementary real data, nodata filling the gaps.

Merging staging tables

Once every pipeline has finished writing, the staging tables are combined into the main table in a single step. All staging tiles are gathered together and grouped by their grid cell. Cells that occur only once are inserted directly. Cells that occur more than once (the duplicate edge tiles described above) are fused with PostGIS ST_Union: where one copy has nodata and another has real data, the real data wins. The complementary halves of each border tile are merged back into a single, gap-free, continuous tile, leaving exactly one tile per grid cell in the main table.

Edge tile merge: two input files re-tiled onto the global grid produce two duplicate tiles at a border cell, each with nodata where its file has no data; ST_Union fuses them into one gap-free tile per grid cell

With the data in place and every grid cell now unique, the spatial index and the raster constraints are added and the staging tables are dropped. Overviews of the DEM and are merged in the same way.

The merge itself is implemented in the db component.

Dissolving update areas into the preview DEM

Note: Like raster ingestion above, this behaviour spans components: the pipeline and its stages live here in processing, while orchestration lives in the dissolve_update_areas DAG.

What dissolving means

An update area is a polygon, digitized by the users themselves, inside which the newly calculated reference DEM should replace the primary DEM. Dissolving is the step that blends the two into the DEM preview (dem_preview): inside the update area the reference DEM is authoritative, outside it the primary DEM is kept, and the seam between them is smoothed by interpolation so the preview does not show a visible elevation step along the polygon border.

Dissolve zones: the update area covered by the reference DEM, the interpolation zone ring around it, and the surrounding primary DEM read extent

The dissolve pipeline

pipelines.dissolve_update_area builds the following chain for one update area polygon:

read primary DEM            read reference DEM
(around the update area)    (update area)
        │                        │
        └────────── Zip ─────────┘
                     │
                RasterUnion         (reference DEM wins inside the update area)
                     │
              RasterInterpolate     (smooth the seam)
                     │
      write dem_preview + overviews (merge into existing tiles)

The primary DEM is read as a ring around the update area so there is data around the seam to interpolate from, while the reference DEM is clipped to the update area itself. The update area interior is clipped out of the primary read: inside the area the reference DEM wins the union, and the seam interpolation samples its inner known points from the reference data, so primary data there would only be read to be overwritten. The ring width is derived from what the seam interpolation actually needs: the interpolation ring plus the known-point sampling band, plus a safety margin. RasterUnion lays both rasters onto a single grid, the reference DEM winning inside the update area, and RasterInterpolate smooths the seam between the two surfaces (see below).

The blended patch and its downsampled overviews are then merged into dem_preview, re-tiled onto the same global grid used for ingestion: where a tile already exists its pixels are overwritten by the patch (existing values are kept where the patch has nodata). Overviews are visualization-only and downsampled from the blended patch alone, so concurrent dissolve tasks may leave a shared overview tile slightly stale, dem_preview itself stays consistent.

Seam interpolation

After the union, the raster has an abrupt transition at the update area border: reference-DEM values inside meet primary-DEM values outside. To hide this step, the pipeline interpolates a donut-shaped zone outside of the polygon. The ring lies on the primary-DEM side because inside the area the reference DEM is authoritative and must not be altered.

Elevation profile across the update area border: before interpolation the primary and reference DEM meet in an abrupt step; after interpolation a smooth ramp spans the interpolation zone, anchored to values sampled from both DEMs on either side of the zone

The interpolated values are calculated by RasterInterpolate as follows:

  1. Target pixels. The ring polygon is rasterized onto the raster grid; every pixel whose centre falls inside the polygon becomes a target. These pixels' current values are discarded and recomputed.
  2. Known points. The target mask is dilated by a few pixels in every direction (8-connected binary dilation). Pixels in this band that are not targets themselves and hold valid (non-nodata) data become the known points. This samples a narrow band of reference-DEM data on the inner side of the ring and primary-DEM data on the outer side, so the interpolation is anchored to both surfaces.
  3. Cubic interpolation. The known points are fed to SciPy's griddata with method="cubic", using pixel row/column indices as coordinates and elevations as values. SciPy triangulates the known points (Delaunay) and fits a piecewise-cubic Clough–Tocher surface over the triangulation. The gradients used by the cubic patches are estimated so that the surface is C1 continuous — both the elevation and its slope vary smoothly across patch boundaries. Each target pixel's new value is this surface evaluated at the pixel's coordinates. The effect is a smooth ramp from the primary surface to the reference surface across the ring, with no kink at either edge.
  4. Write-back. The interpolated values replace the target pixels; any remaining NaNs map back to nodata.

Pipelines

The processing component provides a pipeline architecture for chaining raster and vector data processing operations together.

Core Concepts

Pipeline: A chain of processing stages that execute sequentially. Each stage processes raster or vector data and passes the result to the next stage or returns the data as pipeline output.

Stage: A processing operation that implements the process(data) method. Stages receive a RasterDataset or VectorDataset (or None), perform an operation, and return the result.

RasterDataset: A container for raster data consisting of:

  • array: NumPy array containing the raster values
  • transform: Affine transformation for georeferencing
  • crs: Coordinate Reference System
  • nodata: Nodata value

Creating Pipelines

Pipelines are created using the pipe operator (|) to chain stages together:

from pinta_processing import reader, writer, filters

# Simple read-transform-write pipeline
pipeline = reader.RasterioReader("input.tif") \
    | filters.MultiplyValues(factor=2.0) \
    | writer.GeotiffWriter("output.tif")

# Execute pipeline (read-only stages like reader return data)
pipeline.execute()

Example of pipeline returning raster data:

from pinta_processing import reader, writer, filters

# Simple read-transform-write pipeline
pipeline = reader.RasterioReader("input.tif") \
    | filter.MultiplyValues(factor=2.0)

# Execute pipeline (read-only stages like reader return data)
result = pipeline.execute()
# Get raster pixels as np array
result.array

Pipeline Modules

Reader

The reader module handles loading raster or vector data for various sources.

PostgisReader clips a raster table with a WKT geometry. The intersecting tiles are clipped and streamed out of the database one row at a time and mosaicked client-side. The backend never materializes the full clipped raster. Unioning the tiles server-side instead would build the whole clipped raster in backend memory as a single value, which for large clip geometries leads to backend out-of-memory failures.

Filter

The filters module contains data transformation stages that modify data while preserving metadata.

Writer

The writer module handles saving data to various medias. All writer stages behave as sinks; no data is returned from a writer, and the pipeline branch does not continue after a writer stage.

Tee

The Tee stage branches a pipeline into multiple parallel paths without affecting the main data stream:

from pinta_processing import core, reader, filters, writer

# Create a branching pipeline where data goes to multiple writers
pipeline = (
    reader.RasterioReader("dem.asc")
    | core.Tee(
        filters.MultiplyValues(2.0)
        | writer.GeotiffWriter("dem_multiplied.tif")
    )
    | writer.GeotiffWriter("dem.tif")
)

pipeline.execute()

Each branch receives an independent copy of the data, allowing simultaneous write operations without interference. The main data stream continues unchanged after the Tee.

Zip

The Zip stage is the inverse of Tee: instead of fanning one stream out to several branches, it gathers several streams back into one. It runs one or more independent branches and combines their outputs with the main data stream into a single tuple, which is passed to the next stage. This lets a downstream stage work on several inputs at once — for example, differencing two rasters.

The main stream value, if present, becomes the first element of the tuple, followed by each branch result in order. Each branch is independent and is typically a self-contained sub-pipeline that starts with its own reader.

from pinta_processing import core, reader, filters, writer

# Compute the elevation change between two DEMs.
# The main stream reads the newer DEM, Zip pulls in the older one, and
# RasterDiff receives the (newer, older) tuple and subtracts the second
# from the first.
pipeline = (
    reader.RasterioReader("dem_2026.tif")
    | core.Zip(reader.RasterioReader("dem_2020.tif"))
    | filters.RasterDiff()
    | writer.GeotiffWriter("dem_change.tif")
)

pipeline.execute()

Zip accepts multiple branches, producing a longer tuple. It can also be used as the first stage of a pipeline (with no main stream), in which case the tuple contains only the branch results:

from pinta_processing import core, reader, filters, writer

# Zip as the first stage: the tuple holds only the branch outputs.
pipeline = (
    core.Zip(
        reader.RasterioReader("dem_2026.tif"),
        reader.RasterioReader("dem_2020.tif"),
    )
    | filters.RasterDiff()
    | writer.GeotiffWriter("dem_change.tif")
)

pipeline.execute()

Consumers such as RasterDiff require the zipped rasters to share an identical shape, CRS, and transform.

LAZ processing with LAStools

Point cloud (LAS/LAZ) tiles are rasterised into a DEM with LAStools. Las2DemReader runs the tool as a subprocess, writes a temporary GeoTIFF and hands it back into the pipeline as a normal RasterDataset, so LAStools appears as an ordinary reader stage.

The binaries are not baked into the processing image. The image build only verifies that the shared libraries LAStools needs are present. At run time the binaries come from a bind mount, so the container expects to find lastools executables from configured path.

Setting up LAStools on a server, with a license

  1. Unpack the LAStools distribution somewhere on the Docker host, so that <dir>/bin/las2dem_new64 exists.
  2. Set the Airflow Variable pinta_lastools_path to that host directory. It is bind-mounted read-only into every container task at /lastools (see config.py).
  3. Make the license file reachable, in one of two ways:
    • Place lastoolslicense.txt inside the LAStools directory. The default LAStoolsLicenseFile=/lastools/lastoolslicense.txt then finds it with no further configuration.
    • Or set the Airflow Variable pinta_lastools_license_path to the host path of the license file. It is mounted at /lastoolslicense.txt and LAStoolsLicenseFile is repointed there.

Demo mode for local development

Without a license the binaries only run when invoked with -demo flag. When LASTOOLS_DEMO_MODE environment variable is truthy lastools will run in demo mode.

Locally the flag comes from the Airflow Variable pinta_lastools_demo_mode, which is templated into the task container's environment. In the dev stack it is wired through AIRFLOW_VAR_PINTA_LASTOOLS_DEMO_MODE in docker-compose.yml and defaults to false, so set it in your .env to run unlicensed. Leave it off on a licensed server — the restricted output is only acceptable for development and tests.

Metadata

Release files for pinta-processing 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pinta-processing 0.1.0
File Size Uploaded Provenance Actions
pinta_processing-0.1.0.tar.gz 39.1 kB Without provenance Details for pinta_processing-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pinta-processing 0.1.0
File Interpreter ABI Platform Actions
pinta_processing-0.1.0-py3-none-any.whl Python 3 none any Details for pinta_processing-0.1.0-py3-none-any.whl

Total release size: 92.3 kB

Release files / pinta_processing-0.1.0.tar.gz

Download URL pinta_processing-0.1.0.tar.gz
Size 39.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1d4b0c14dc6f04648127899cc989c840ce8af179308bfb706d1f1b1d652bf27f
BLAKE2b-256 checksum
How to use checksums
dabc0bef6b531f57f8be5629d2b164241f09071e098d6616d8bf8617e1696a32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pinta_processing-0.1.0-py3-none-any.whl

Download URL pinta_processing-0.1.0-py3-none-any.whl
Size 53.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7b63aaae33027aa387fcc57dea1c7841eb3b3fcfdf366d12cbf7ac6eb4c3114
BLAKE2b-256 checksum
How to use checksums
66277f096fc26d607a15f579d8e68ed9483edd5ff302c49fbef29e52dbc858d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pinta-processing 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page