Skip to main content

Ocean-DIVA

CI DOI

Open the interactive HTML guide for an explorable land-mask example.

Ocean-DIVA performs Data-Interpolating Variational Analysis on scattered spatial observations. It produces a gridded analysis and relative posterior error while respecting coastlines, islands, and disconnected basins.

This implementation has a NumPy-first Python API and a focused Rust engine for coastline-aware shortest paths. Published wheels require no Fortran compiler, Julia installation, or system NetCDF library.

Installation

python -m pip install ocean-diva

Optional integrations are available as extras:

python -m pip install "ocean-diva[accessors]"  # pandas and xarray
python -m pip install "ocean-diva[plot]"       # example plots

The distribution is named ocean-diva; the Python package remains diva.

Python API

A grid is inferred from the finite observation extent when one is not supplied. The inferred grid preserves the aspect ratio, adds a 5% buffer, and uses about 50 cells along its longest axis.

from diva import analyze

result = analyze(
    x=[0.3, 0.55, 0.85],
    y=[0.3, 0.9, 0.1],
    values=[1.0, -1.0, 0.2],
    correlation_length=0.2,
    signal_to_noise=1.0,
)

result.save("results.npz")

Use grid_resolution and grid_buffer to customize an inferred grid:

result = analyze(
    x,
    y,
    values,
    correlation_length=0.2,
    grid_resolution=100,
    grid_buffer=(0.5, 0.25),
)

Pass an explicit Grid when exact coordinates are required:

import numpy as np
from diva import Grid, analyze

grid = Grid(np.linspace(0, 1, 101), np.linspace(0, 1, 101))
result = analyze(x, y, values, grid, correlation_length=0.2)

Pandas and xarray

Importing diva registers a .diva accessor when pandas or xarray is installed.

# Returns a tidy DataFrame indexed by (latitude, longitude).
result_df = observations.diva.analyze(
    x="longitude",
    y="latitude",
    values="temperature",
    correlation_length=0.2,
)

# Returns a Dataset containing analysis, error, and water.
result_ds = temperature.diva.analyze(
    x="longitude",
    y="latitude",
    correlation_length=0.2,
)

Both accessors accept the same solver and automatic-grid options as diva.analyze. The xarray accessor also accepts a coordinate-aware land_mask, using 1 for land and 0 for ocean.

For example, an xarray analysis can include an island that observations on opposite sides must be interpolated around:

import numpy as np
import xarray as xr

temperature = xr.DataArray(
    [12.0, 10.0, 20.0, 18.0],
    dims="observation",
    coords={
        "longitude": ("observation", [0.2, 0.3, 0.7, 0.8]),
        "latitude": ("observation", [0.25, 0.75, 0.75, 0.25]),
    },
    name="temperature",
    attrs={"units": "degree_Celsius"},
)

longitude = np.linspace(0, 1, 51)
latitude = np.linspace(0, 1, 51)
land = xr.DataArray(
    (
        (latitude[:, None] >= 0.20)
        & (latitude[:, None] <= 0.80)
        & (longitude[None, :] >= 0.42)
        & (longitude[None, :] <= 0.58)
    ).astype(np.uint8),
    dims=("latitude", "longitude"),
    coords={"longitude": longitude, "latitude": latitude},
    name="land",
)

result = temperature.diva.analyze(
    x="longitude",
    y="latitude",
    correlation_length=0.2,
    land_mask=land,
)

# `water` is false on the island; mask land before plotting or exporting.
water_temperature = result["analysis"].where(result["water"])

The mask coordinates define the output grid when no Grid is supplied. They must match an explicit grid when one is supplied. A land mask also enables shortest-water-path distances, so covariance does not pass straight through the island.

Command line

The CLI reads portable DIVA observation, contour, and parameter files:

diva analyze input/data.dat \
  --contours input/coast.cont \
  --params input/param.par \
  --output results.npz

Capabilities

  • whitespace- or comma-delimited x y value [weight] observations;
  • ODV spreadsheet layer extraction;
  • legacy coast.cont and param.par readers;
  • zero, mean, and planar background fields;
  • relative posterior error estimates;
  • even-odd coastline masks with islands and holes;
  • shortest-water-path covariance around land barriers;
  • compressed NumPy and long-form CSV output.

The solver uses a normalized Matérn field rather than being a line-for-line port of the historical finite-element implementation. Advanced historical workflows such as 3-D/4-D climatology, advection constraints, generalized cross-validation, and NetCDF output are outside its current scope.

Examples

python examples/python_basic.py
python examples/black_sea_surface.py
python benchmarks/benchmark_core.py

The Black Sea example uses the bundled ODV sample in data/ and writes its .npz and .png outputs beside the script.

Development

The package is built with maturin and PyO3:

python -m pip install ".[accessors,plot]"
python -m unittest discover -s tests -v

Running from an unbuilt source checkout falls back to the equivalent Python shortest-path implementation.

References

  • Troupin, C. et al. (2012), “Generation of analysis and consistent error fields using Data Interpolating Variational Analysis (Diva),” Ocean Modelling, 52–53, 90–101. doi:10.1016/j.ocemod.2012.05.002
  • Barth, A. et al. (2014), “divand-1.0: n-dimensional variational data analysis for ocean observations,” Geoscientific Model Development, 7, 225–241. doi:10.5194/gmd-7-225-2014
  • DIVAnd.jl, the actively maintained N-dimensional generalization of DIVA.

License

GPL-3.0-or-later. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ocean_diva-0.1.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ocean_diva-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (307.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

File details

Details for the file ocean_diva-0.1.0.tar.gz.

File metadata

  • Download URL: ocean_diva-0.1.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ocean_diva-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1c25a2a256393aeda078641deee0c553eb2dcf378c2c6a71fb2f5c98078bf8ae
MD5 f43c3a754f55e5a391ea4c9760bce651
BLAKE2b-256 778be0c229a8f0699a93e20dbf64fa871586ba88312aacf067dab36f96d4b100

See more details on using hashes here.

File details

Details for the file ocean_diva-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ocean_diva-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 307.8 kB
  • Tags: CPython 3.14, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ocean_diva-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d95efde65af793b2773ed2e4f3800e293aebee879127d2f2dc50f3acb982afba
MD5 ed9a3c99bafaa271fc39875c84239567
BLAKE2b-256 6ccbbe956b2a4ac225757a21cb5d1f76697f7baaf336bcd5f1758b3a364e936c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page