Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Coordinate-aware ops

Part 4: Coordinate-Aware Analysis (Ops Using Coordinate Info)

This notebook demonstrates how to leverage physical coordinate values for selection, slicing, regridding, and interpolation.

4.1 Selecting Data for a Specific Location

Select by physical coordinate value rather than array index.

Temperature field: ('time', 'latitude', 'longitude'), shape: (12, 16, 32)

Find nearest coordinate index

Target: 47.6°N, -122.3°E
Nearest grid point: 42.00°N, -121.94°E
Time series: ('time',), shape: (12,)
Annual mean: 28.81 °C

Helper: coordinate-based location selection

Selected time series: ('time',), shape: (12,)

4.2 Slicing a Region of Interest

Extract a spatial subset using coordinate boundary values.

Regional temperature: ('time', 'latitude', 'longitude'), shape: (12, 1, 1)
Regional mean time series shape: (12,)

4.3 Regridding / Interpolation

Interpolate data from a coarse grid to a finer grid using coordinate values.

Coarse grid: (8, 16)
Target fine grid: (16, 32)

Simple nearest-neighbor interpolation (for demonstration)

Interpolated fine grid: (16, 32)

4.4 Sparse Weather Station Interpolation (Pattern)

Demonstrates the workflow for GP or nearest-neighbor interpolation from irregularly spaced station data to a regular grid.

Stations: 20, temp range: 21.4 — 36.0 °C
Interpolated grid: ('latitude', 'longitude'), shape: (8, 16)
Temperature range: 21.4 — 36.0 °C

Key Patterns Summary

  1. Coordinate-based selection — use axis.ticks + argmin to find nearest index
  2. Regional slicing — np.searchsorted on coordinate values to find slice bounds
  3. Regridding — interpolate .data then re-wrap with new coordinate axes
  4. Sparse-to-grid — nearest-neighbor or GP regression, then wrap result

For production interpolation, consider interpax (differentiable, JIT-compatible) or GPJax for probabilistic interpolation.