Loading...
Loading...
Spatial data gridding and interpolation with a machine-learning style API. Process geographic and Cartesian point data onto regular grids. Use when Claude needs to: (1) Grid scattered spatial data onto regular grids, (2) Interpolate point data using splines, linear, or cubic methods, (3) Process geographic coordinates with projections, (4) Reduce large datasets using block averaging, (5) Remove polynomial trends from spatial data, (6) Cross-validate gridding parameters, (7) Create processing pipelines with Chain, (8) Grid vector data like GPS velocities.
npx skill4agent add steadfastasart/geoscience-skills verdeimport verde as vd
# Basic gridding
spline = vd.Spline()
spline.fit(coordinates, values) # coordinates = (lon, lat) tuple
grid = spline.grid(spacing=0.1) # Returns xarray Dataset
# Access result
elevation = grid.elevation.values
# Save output
grid.to_netcdf('output.nc')| Class | Purpose |
|---|---|
| Bi-harmonic spline interpolation (smooth, good extrapolation) |
| Delaunay triangulation (fast, no extrapolation) |
| Cubic interpolation (medium smoothness) |
| Pipeline of processing steps |
| Decimate data to block means/medians |
| Polynomial trend fitting and removal |
| Grid 2-component vector data |
coordinates = (longitude, latitude) # Tuple of 1D arrays
values = elevation # 1D array
spline = vd.Spline()
spline.fit(coordinates, values)
grid = spline.grid(spacing=0.1, data_names=['elevation'])import pyproj
projection = pyproj.Proj(proj='merc', lat_ts=data_lat.mean())
proj_coords = projection(longitude, latitude)
spline = vd.Spline()
spline.fit(proj_coords, values)
grid = spline.grid(spacing=1000) # 1000m spacingimport numpy as np
reducer = vd.BlockReduce(reduction=np.median, spacing=0.1)
coords_reduced, values_reduced = reducer.filter(coordinates, values)trend = vd.Trend(degree=2) # Quadratic
trend.fit(coordinates, values)
residuals = values - trend.predict(coordinates)
# Grid residuals, then add trend backchain = vd.Chain([
('trend', vd.Trend(degree=1)),
('reduce', vd.BlockReduce(np.median, spacing=0.05)),
('spline', vd.Spline())
])
chain.fit(coordinates, values)
grid = chain.grid(spacing=0.01)spline = vd.Spline()
scores = vd.cross_val_score(spline, coordinates, values, cv=5)
print(f"Mean R2: {scores.mean():.3f}")grid = spline.grid(spacing=0.1)
mask = vd.distance_mask(coordinates, maxdist=0.2, grid=grid)
grid_masked = grid.where(mask)| Parameter | Description |
|---|---|
| Grid cell size (same units as coordinates) |
| (west, east, south, north) bounds |
| (n_north, n_east) grid dimensions |
| 'spacing' or 'region' - which to adjust for exact fit |
| Gridder | Speed | Smoothness | Extrapolation |
|---|---|---|---|
| Medium | High | Good |
| Fast | Low | None |
| Fast | Medium | None |
| Use Case | Tool | Why |
|---|---|---|
| General spatial gridding | Verde | ML-style API, pipelines, cross-validation |
| Basic 1D/2D interpolation | scipy.interpolate | Simpler API, no spatial focus |
| Potential field gridding | Harmonica | Equivalent sources designed for gravity/magnetics |
| Command-line batch gridding | GMT | Powerful CLI, good for automation scripts |
| Geostatistical interpolation | scikit-gstat / pykrige | Variogram-based with uncertainty |
| Very large datasets (10M+ pts) | GMT / GDAL | Better memory handling at scale |
| Vector data (GPS velocities) | Verde ( | Built-in 2-component vector gridding |
| Trend removal + gridding | Verde ( | Pipeline combines steps cleanly |
surfacenearneighborBlockReduceTrend(degree=1)Trend(degree=2)cross_val_score()Spline(damping=...)Spline(mindist=...).grid()distance_mask()grid.elevation.plot()grid.to_netcdf()| Issue | Solution |
|---|---|
| Poor extrapolation | Use |
| Slow with large data | Use |
| Regional trends | Remove with |
| Wrong spacing | Check coordinate units (degrees vs meters) |