Verde provides classes and functions for processing spatial data, like bathymetry, GPS, temperature, gravity, or anything else that is measured along a surface. The main focus is on methods for gridding such data (interpolating on a regular grid). You’ll also find other analysis methods that are often used in combination with gridding, like trend removal and blocked operations.
Before we get started, here are a few of the conventions we use across Verde:
Coordinates can be Cartesian or Geographic. We generally make no assumptions about which one you’re using.
All functions and classes expect coordinates in the order: West-East and South-North. This applies to the actual coordinate values, bounding regions, grid spacing, etc. Exceptions to this rule are the
We don’t use names like “x” and “y” to avoid ambiguity. Cartesian coordinates are “easting” and “northing” and Geographic coordinates are “longitude” and “latitude”.
The term “region” means the bounding box of the data. It is ordered west, east, south, north.
Most classes and functions are available through the
verde top level
package. The only exception is the
verde.synthetic module that has
functionality for generating synthetic data. Throughout the documentation we’ll
vd as the alias for
import matplotlib.pyplot as plt import verde as vd
The gridder interface#
All gridding and trend estimation classes in Verde share the same interface
(they all inherit from
verde.base.BaseGridder). Since most gridders
in Verde are linear models, we based our gridder interface on the
scikit-learn estimator interface: they all
fit method that estimates the
model parameters based on data and a
method that calculates new data based on the estimated parameters.
Unlike scikit-learn, our data model is not a feature matrix and a target
est.fit(X, y)) but a tuple of coordinate arrays and a data
grd.fit((easting, northing), data)). This makes more sense
for spatial data and is common to all classes and functions in Verde.
As an example, let’s generate some synthetic data using
northing easting scalars 0 -3448.095870 2744.067520 -417.745960 1 -3134.825681 3575.946832 -10.460197 2 -2375.147789 3013.816880 914.277006 3 -1247.024885 2724.415915 -534.571829 4 -3332.462671 2118.273997 407.865799
The data are random points taken from a checkerboard function and returned to
us in a
Before we can use the spline, we need to fit it to our synthetic data. After that, we can use the spline to predict values anywhere:
spline.fit((data.easting, data.northing), data.scalars) # Generate coordinates for a regular grid with 100 m grid spacing (assuming # coordinates are in meters). grid_coords = vd.grid_coordinates(region=(0, 5000, -5000, 0), spacing=100) gridded_scalars = spline.predict(grid_coords) plt.figure() plt.pcolormesh(grid_coords, grid_coords, gridded_scalars, cmap="RdBu_r") plt.colorbar() plt.show()
/home/runner/work/verde/verde/doc/tutorials_src/overview.py:115: FutureWarning: The default scoring will change from R² to negative root mean squared error (RMSE) in Verde 2.0.0. This may change model selection results slightly. print(spline.score(grid_coords, true_values)) 0.9950450863038701
Generating grids and profiles#
<xarray.Dataset> Dimensions: (northing: 168, easting: 167) Coordinates: * easting (easting) float64 23.48 53.42 83.37 ... 4.964e+03 4.994e+03 * northing (northing) float64 -4.997e+03 -4.967e+03 ... -30.88 -0.9571 Data variables: scalars (northing, easting) float64 495.6 521.3 549.0 ... -184.7 -139.6 Attributes: metadata: Generated by Spline(mindist=0)
grid uses default names for the coordinates
(“easting” and “northing”) and data variables (“scalars”). You can overwrite
these names by setting the
<xarray.Dataset> Dimensions: (latitude: 168, longitude: 167) Coordinates: * longitude (longitude) float64 23.48 53.42 83.37 ... 4.964e+03 4.994e+03 * latitude (latitude) float64 -4.997e+03 -4.967e+03 ... -30.88 -0.9571 Data variables: gravity (latitude, longitude) float64 495.6 521.3 549.0 ... -184.7 -139.6 Attributes: metadata: Generated by Spline(mindist=0)
northing easting distance scalars 0 0.000000 0.000000 0.000000 66.785386 1 -25.125628 25.125628 35.533004 92.895119 2 -50.251256 50.251256 71.066008 124.644015 3 -75.376884 75.376884 106.599012 163.870393 4 -100.502513 100.502513 142.132016 209.836541
This covers the basics of using Verde. Most use cases and examples in the documentation will involve some variation of the following workflow:
Load data (coordinates and data values)
Create a gridder
Fit the gridder to the data
Total running time of the script: ( 0 minutes 1.007 seconds)