Processing extension contract#

SAFE ingestion belongs to raster core in every build. The optional Sentinel-2 processing extension owns surface reflectance, atmospheric lookup/correction, and processing-specific geometry, QA and visibility. The common C ABI exposes its Rust implementation to thin C++ and Python bindings. Applications can also compose public raster operations without registration.

extension-sentinel2 selects the processing implementation under extensions/sentinel2/. It does not select SAFE I/O or physical-model availability. The ownership inventory locates each source and public surface; the capability matrix describes execution support. Inclusion establishes no qualification claim.

One distribution and one native owner#

cugeo-raster has one distribution and coordinated release. Standard artifacts include the delivered first-party processing extensions. Inclusion neither invokes a processor nor downloads its dependencies or data. Python extras add optional dependencies; they do not select Python files or compiled extensions. Redistribution clearance remains a separate requirement.

Processing extensions link into libcugeo_raster.so, selected by Cargo features. They use the same core instance, native handle owners and resource accounting. There is no generic plugin registry, callback registration or plugin loader. The physical Sentinel model has a separately built optional native-artifact boundary to isolate its ERFA 2.0.1 dependency. Its installed Rust, C, C++ and Python interfaces expose explicit preparation and CUDA direct grids independently of processing selection. Linked execution requires separate qualification. Explicit physical preparation is the activation boundary for that artifact, its astronomical preparation and caller-supplied physical resources. Core imports, ordinary opening, catalog access and capability inspection remain independent of those resources. This exception adds no generic plugin registry or separate distribution.

An application can build a consumer library against the installed public C ABI. The processing author guide and its executed host example show this composition. That application artifact remains outside the cugeo-raster distribution and registers no first-party extension.

Dependencies follow this direction:

Rust extension API     C ABI -> C++ and Python bindings
          \             /
           product and sensor policy
                    |
          core I/O, grids, sampling,
          terrain, memory and completion
                    |
          codec/CUDA leaves and cugeo-proj

Core owns reusable raster operations, generic TIFF/JPEG2000, RPC polynomial evaluation and transformation, registered geolocation arrays and their inverse, and sensor-independent geometry. cugeo-proj owns terrestrial and vertical coordinate transformations. Astronomical preparation for the optional physical model belongs to that artifact and its prepared owner, using ERFA 2.0.1. An extension consumes these facilities; it does not copy a CUDA inverse, projection engine, allocator, decoder pool or completion owner.

Source layout and public names#

The required extension identifier is lower snake case, such as sentinel2. Cargo uses extension-<identifier>, with underscores changed to hyphens in the feature name. The Sentinel extension uses extension-sentinel2.

The source and installed interfaces use these locations:

Surface

Location and interface

Rust

extensions/mod.rs and extensions/sentinel2/mod.rs; public namespace cugeo_raster::extensions::sentinel2; only surface_reflectance requires extension-sentinel2

Core SAFE implementation

src/sentinel2.rs and src/sentinel2/{assets,subdatasets}.rs; Sentinel2* types are crate-root exports in every build

Core SAFE C adapters

src/ffi/sentinel2.rs and src/ffi/sentinel2/subdatasets.rs; existing cugeo_raster_sentinel2_product_*, *_reader_* and *_subdataset_* symbols

Radiometry

extensions/sentinel2/surface_reflectance.rs and its same-named directory; Rust namespace extensions::sentinel2::surface_reflectance

Radiometry C adapters

extensions/sentinel2/ffi/ with surface_reflectance.rs, surface_geometry.rs, surface_lut.rs and surface_source.rs

Specialized kernels

extensions/sentinel2/kernels/surface_reflectance.cu

C declarations

The single installed cugeo/raster/raster.h, with core and processing records/functions present in every build

Core C++ SAFE catalog

cugeo/raster/jpeg2000.hpp; namespace cugeo::raster::io::sentinel2, including product, asset, band, reader and subdataset interfaces

C++ radiometry

cugeo/raster/extensions/sentinel2/surface_reflectance.hpp; namespace cugeo::raster::extensions::sentinel2::surface_reflectance

Core Python SAFE catalog

cugeo.raster.io.sentinel2; existing types are also exposed by cugeo.raster.io, with the ordinary six catalog types exposed by cugeo.raster

Core Python group reader

cugeo.raster.io._safe_subdataset; ordinary open dispatches paths and typed group names

Python processing

extensions/sentinel2/python/{surface_reflectance,_surface_geometry,_surface_lut,_availability}.py, installed under cugeo.raster.extensions.sentinel2

The Rust crate exposes the external source directory through one explicit #[path = "../extensions/mod.rs"] pub mod extensions; declaration in src/lib.rs. The surface_reflectance module in extensions/sentinel2/mod.rs has #[cfg(feature = "extension-sentinel2")]; its CUDA-only items additionally require cuda. Omitted processing Rust APIs compile out. The physical module remains available in every selection. Physical preparation reports typed missing-artifact errors, and device preparation also requires core CUDA and a CUDA physical artifact. The API inspector and snapshots retain each item’s availability conditions. The inspector must follow the explicit source path within the packaged crate and retain fail-closed resolution. Complete source archives contain this directory, including excluded implementations; compiled artifacts contain only their selected implementation. Python package mappings install the extension-owned sources into the namespace above; package selection does not remove their thin declarations. Core SAFE types retain their existing ordinary and I/O facade exports.

The core SAFE implementation has one owner across all facades. No extension catalog aliases or forwarding namespaces are installed. C names retain their sole spelling, and every selection shares one header and ABI snapshot.

Ordinary SAFE opening#

cugeo.raster.open(path) opens admitted SAFE products and granules through the core catalog. Typed subdataset names reopen their selected group through the core group reader. Discovery preserves identity, ordering, XML metadata and selected-source ownership. product.open_band(...) returns an ordinary DatasetReader backed by the shared JPEG2000 source; asset and grouped readers retain their native-grid/raw-sample contracts.

Catalog parsing and metadata discovery require no processing code, physical module, atmospheric resources, CUDA or codec activation. Device pixel execution requires its independently selected JPEG2000 backend and retains ordinary backend/error admission. Core-only SAFE opening uses the same validation and errors as standard opening. Discovery and import never download resources. See the SAFE contract for admitted profiles, groups, metadata and raw reads.

Build selection and availability#

Select extensions independently of backend features:

Selection

Cargo features

Source-wheel setting

Standard

default = ["extensions-all"]; extensions-all = ["extension-sentinel2"]

Unset CUGEO_RASTER_BUILD_EXTENSIONS, or all

Core-only

--no-default-features

CUGEO_RASTER_BUILD_EXTENSIONS=none

Selected

--no-default-features --features extension-sentinel2

CUGEO_RASTER_BUILD_EXTENSIONS=sentinel2

The wheel setting accepts all, none or a comma-separated list of known extension identifiers. Empty or unknown identifiers, duplicates, and lists that mix all or none with identifiers or with each other fail the build. It controls Cargo selection through config/production-build.txt, the existing build/package authority. Selecting an extension cannot silently drop it. Selecting a backend with missing build inputs also fails explicitly. The supported initial matrix is standard-complete and core-only, with focused selection/omission checks; it promises no exhaustive combination matrix.

Extension selection is independent of backend selection. Catalog parsing needs neither CUDA nor a codec. Sentinel device reads need the existing cuda and nvjpeg2k features and admitted inputs; radiometry CUDA primitives need cuda. extensions-all does not enable NVIDIA backends. Core-only may still enable a backend for generic raster operations and raw SAFE reads. cugeo-proj remains a base dependency.

Wheel/sdist generation, Cargo packaging and CMake installation use the selected library and package the complete headers and thin bindings. For omitted extensions, the common C ABI retains callable stubs and installed Python/C++ declarations remain thin adapters to that ABI. Rust extension APIs compile out under their documented feature conditions. Omitted implementations, specialized kernels and extension-only runtime artifacts are excluded. Reusing a package directory must not leak a prior build’s artifacts. CMake installs the supplied Cargo artifact; it does not make a second extension selection. A prebuilt wheel input must report the requested extension set and backend selection.

The cugeo_raster_capabilities JSON reports the object "extensions":{"sentinel2":true} in a standard build and false in a core-only build. Every known extension has an explicit boolean. This reports processing inclusion only. It does not describe core SAFE I/O, physical-model availability, runtime readiness, schema admission or qualification. The existing Python cugeo.raster.diagnostics.capabilities() exposes the same fact. Unknown or missing required capability fields fail validation.

An extension needing an external runtime checks or loads it only on explicit use of the operation that requires it. Import, capability queries, core loading and unrelated operations must remain usable without that runtime. Catalog opening activates only catalog work. No current inventoried Sentinel component requires an external Sen2Cor or Sen2VM runtime. An external XDR table is data, not a dependency on the program that produced it. Lazy-runtime isolation is a contract requirement without a current extension-runtime execution result.

Errors and omitted interfaces#

Use the existing native Rust Error enum, C cugeo_raster_error_code and error record, C++ typed errors and Python exceptions. There is no separate raster ErrorKind or extension status namespace. Classify by codes, never message text.

Cause

Native Rust error

C status

Python through the common result adapter

Omitted extension; unavailable optional runtime or backend; unsupported meaning

Error::Unsupported

CUGEO_RASTER_UNSUPPORTED (2)

UnsupportedError, .code == 2

Malformed admitted arguments or metadata

Error::InvalidArgument

CUGEO_RASTER_INVALID_ARGUMENT (1)

CugeoRasterError with code 1; existing operation-specific refinements remain

Short caller storage

Error::Buffer

CUGEO_RASTER_BUFFER_ERROR (3)

CugeoRasterError, code 3

Missing/unreadable explicitly named data file, corrupt admitted source

Error::Io

CUGEO_RASTER_IO_ERROR (4)

CugeoRasterError, code 4, or the existing I/O refinement

CUDA unavailable

Error::CudaUnavailable

CUGEO_RASTER_CUDA_UNAVAILABLE (5)

Common adapter: CugeoRasterError; CUDA adapter: UnsupportedError, retaining code 5

CUDA execution failure

Error::Cuda

CUGEO_RASTER_CUDA_ERROR (6)

CugeoRasterError, code 6

Capacity retained by pending work

Error::WouldBlock

CUGEO_RASTER_WOULD_BLOCK (7)

Existing busy/result handling, retaining code 7

Resource exhaustion or insufficient declared budget

Error::ResourceLimit

CUGEO_RASTER_RESOURCE_LIMIT (8)

ResourceLimitError, code 8

Missing optional resources discovered by cugeo-proj preserve its established translation: cugeo-proj missing-resource code 10 becomes raster unsupported code 2. A selected missing local asset uses I/O code 4. Neither condition uses buffer code 3 as a general resource code. Pixel-level coordinate, terrain and sensor failures retain pixel statuses 3, 4 and 5, distinct from these call-level statuses.

Rust processing APIs compile out when their feature conditions are false. The omitted C implementation uses Error::Unsupported internally; it does not create a public Rust stub surface. C declarations, value records and exports remain available, as do the installed Python/C++ thin declarations:

Interface shape

Required omitted behavior

Rust processing items

Require extension-sentinel2; CUDA-only members also require cuda. Omitted items are unavailable at compile time, with conditions retained in the API inventory. Physical preparation remains declared and reports missing capabilities at its explicit activation boundary.

Python/C++ construction or execution

Imports and thin declarations remain available; omitted operations call the common C ABI and report typed unsupported code 2.

C processing create/open or returned processing handle

Validate required output slots, clear writable handle outputs to null, then return 2 without opening files or loading runtimes.

C versioned record output

Apply the existing size/flags/reserved-field checks. An invalid header returns 1 without overrunning the caller record; a valid record is initialized through the shared helper, then returns 2.

C string/count query

Initialize writable counts to zero and a writable nonempty string to an empty NUL-terminated string; validate required control pointers and null-buffer/capacity pairs, then return 2. No omitted query reports successful empty discovery.

C close_v1(T **slot, error)

Shared unavailable_owned_ffi_slot policy: null slot returns 1; a nonnull slot containing null succeeds; a nonnull object returns 2 and retains the slot without dereferencing that object. Error/owner alias checks remain authoritative.

C void release(T *object)

Null is a no-op. An omitted implementation has no valid live object to release; its disabled release follows the existing no-op stub convention, has no status and does not dereference the pointer. Handles from another library instance or artifact are outside the contract.

Required pointer, size, alignment, accessible-extent and control-alias policies remain owned by the existing FFI boundary. Disabled processing operations do not inspect product payloads or manufacture successful handles. There is no promise of diagnosing arbitrary invalid foreign pointers. Python closed-object and argument-shape errors keep their existing ValueError/TypeError behavior.

Memory, streams and receipts#

The array contract, pixel execution contract and memory-resource contract remain authoritative. Extensions use existing raster views, native descriptors, memory resources, admissions, source handles and completion chains. No adapter introduces another memory owner or interprets a handle from a different core.

Caller output retains its identity, dtype, residency and admitted strides. Python imagery follows scalar HW/sequence CHW and batch NCHW rules. Writable samples and forbidden input/output aliases remain caller non-overlap obligations; extensions do not add runtime pixel-alias validation. Pointer extent, context and control-record safety checks remain in force.

Host execution is synchronous. Ordinary GPU reads retain selected-stream ordering and their documented error-observation waits. Python CUDA calls use the shared current-CuPy-stream selection on omission, explicit overrides and prepared/session inheritance as specified by their interfaces. Native calls receive the resolved stream, including default streams. Surface-reflectance calls currently synchronize their caller stream; moving them does not turn them into asynchronous operations. Retain arrays, backing allocations, streams, decoders, prepared state and auxiliary resources through completion and failure draining. A failed fallible close preserves its owner for retry under the existing context-restoration policy. A band source and copied metadata survive catalog closure.

Budgets count whole retained allocations and overlapping live work, including staging, scratch, prepared tables and outputs according to their existing owners. A view does not shrink its backing charge. Capacity held by pending work remains distinct from exhaustion. Use existing operation receipts for backend, transfers, allocations, waits, fallback and unknown foreign costs; do not fabricate zero costs. Composition adds no rollback, per-query attribution, isolation or run-to-run determinism guarantee.

Metadata and independent references#

An extension’s reference description must identify the following facts. Keep source metadata, effective operation configuration and execution evidence distinct. These requirements do not introduce a metadata registry or persisted format. Existing source catalogs describe source facts; typed operation inputs and receipts describe processing. Unavailable facts remain unavailable.

Required fact

Representation and interpretation

Identity

Stable extension identifier (sentinel2), cugeo-raster version/ABI, native artifact identity in qualification evidence, named algorithm and its reference revision

Configuration

Effective typed plan parameters, backend choice, interpolation/correction mode, band selection and explicitly supplied defaults; record them with the result evidence rather than reconstructing them from message text

Inputs

Ordered physical band IDs and stored representations, dtype/precision, raw DN or physical units, scale/offset source state, source identity and admitted level/schema/profile

Outputs

Ordered bands and their units/dtype, explicit conversion/calibration, grid shape/transform/CRS and pixel registration; distinguish a physical result from encoded DN

Validity and QA

Nodata, saturation and masks with independent availability and units; named QA bit/category meanings and resampling rules; pixel status is not a QA class

Auxiliary resources

Explicit caller-supplied paths/bytes, content identities, provenance/licence, reference/configuration revision, applicability and coverage for LUTs, DEMs, geoids, calibration, orbit/attitude and Earth-orientation inputs

Comparison

Independent reference/build/configuration and resource identities, complete nonempty comparison population, exactness or justified tolerances with units, and separate input, encoding, interpolation and model errors

Reuse MetadataCatalog, MetadataValue, native band records, GeoGrid, georeference/geolocation descriptors and existing receipts where applicable. Do not relabel generated processing facts as MetadataOrigin::SafeProduct or infer a value from numeric convenience defaults. Persist raster data and metadata through the supported raster/Arrow/GeoArrow/Parquet/WKB representations; there is no custom extension file format. Resources are explicitly acquired; neither a missing table nor a missing geoid authorizes a download.

For the existing Sentinel catalog, the algorithm is native SAFE catalog and raw band access. Sentinel2BandMetadata and Python Sentinel2Radiometry preserve the difference between absent, numeric and not-applicable source offsets and optional conversion. Reads do not apply reflectance calibration. Stored resolution, JPEG2000 discard level and output sampling are separate choices. L1B source footprint/angles are descriptive text, with no invented map affine, CRS or physical sensor accuracy. Stored TCI, classification, probability, AOT and WVP planes remain core raw assets/groups; their presence is separate from computed processing QA.

GDAL 3.8.4 defines raster metadata and raw-pixel comparisons; the pinned Rasterio reference defines the applicable Python presentation. Neither is a runtime fallback or an oracle for physical sensor location. Sen2Cor-compatible table parsing and individual radiometry primitives do not establish a complete Sen2Cor processor or equivalence campaign. A physical Sentinel implementation requires its independent sensor reference, approved frame/terrain/resource envelope and justified numerical acceptance. Existing offline Sen2VM direct-node evidence does not by itself qualify a native installed physical model, every spacecraft or absolute accuracy.