Quickstart

Map turns raw field measurements into a validated map in one step. Pass it x, y, z, and the desired resolution: it runs the whole pipeline, from filtering to the final interpolation, and keeps the interpolation method with the lower leave-one-out cross-validation (LOO-CV) RMSE. Map and grid generation lists every stage, input, and result field.

Inputs

x, y : array_like : Source coordinates. Projected coordinates are used as-is. Geographic longitude/latitude is detected and converted internally to metric coordinates before distance calculations; the result is returned in the original coordinates.

z : array_like : Source value for each coordinate pair. x, y, and z must be one-dimensional and have the same length.

resolution : float : Required output grid spacing. For projected input, use the coordinate unit. For longitude/latitude input, use meters.

bounds : geometry, str, bytes, optional : Interpolation domain. Accepts a Shapely geometry, WKT, or WKB in the same coordinate system as the original input. If omitted, APbase infers a boundary from the filtered source points.

In Rust, x, y, and z can be slices, Vecs, arrays, or ndarray arrays of any numeric type. resolution is the argument of MapOptions::new, and bounds is an optional MapOptions field holding WKT, WKB bytes, or a geos::Geometry.

Run the pipeline

import numpy as np

import apbase
from apbase import Map

apbase.config["n_threads"] = 4

# Synthetic source data: 500 points with spatially correlated values plus noise.
rng = np.random.default_rng(0)
x = rng.uniform(0, 1000, 500)
y = rng.uniform(0, 1000, 500)
z = np.sin(x / 150) * np.cos(y / 150) * 10 + rng.uniform(-0.5, 0.5, 500)

# One call: filter -> grid -> variogram -> CV -> best model.
mapper = Map(resolution=10.0)
result = mapper(x, y, z)

Tip

apbase.config["n_threads"] in Python and apbase::config.set("n_threads", n)? in Rust are process-wide OpenMP configuration, not a Map argument. Set it once before building any instance, not per call.

What you get back

result.method                  # "idw" or "kriging", whichever has the lower LOO-CV RMSE
result.x, result.y, result.z   # grid points inside the boundary
X, Y, Z = result.to_raster()   # optional (ny, nx) arrays, NaN outside boundary

result.x, result.y, and result.z hold only the grid points inside the boundary, with no NaN padding. Call to_raster() only when you need a full (ny, nx) raster.

To audit what the pipeline did, inspect result.cross_validation, result.filter_statistics, and result.n_source_points.

The functional shortcut

create_map (apbase.create_map in Python, apbase::create_map in Rust) wraps the same pipeline without instantiating Map explicitly:

result = apbase.create_map(x, y, z, resolution=10.0)

Advanced manual control

For most applications, Map and create_map are all you need. Use the lower-level modules to inspect intermediate results, force a specific interpolation method, or build an advanced workflow such as cokriging; see User guide. Methodology covers the mathematics behind the automatic model choice.