Skip to main content

Python Codes for UNCertainty EStimation Library

Project description

NBS UncLEs

Motivation

Fully surveying the seafloor at the resolution required for all navigational and scientific needs is often prohibitively costly. In practice, bathymetric surveys collect direct depth measurements along sparse survey lines and use interpolation to represent the seafloor between them. Like all scientific measurements, these depths require an associated uncertainty estimate — but for interpolated regions, that uncertainty must account for how much the true seafloor may depart from the interpolated value.

The core challenge is that we have no direct measurements in the very regions we are trying to characterize. This library addresses that challenge by exploiting the spatial structure of nearby known bathymetry. Under an assumption of spatial isotropy — that the statistical character of the seafloor is consistent regardless of direction — the variance observed in sampled survey lines can be used to estimate the likely variance at different spatial scales across the interpolated gaps.

What interpolation_uncertainty does

NBS_UncLEs implements and compares two families of methods for making this estimate:

Spectral methods analyze the power spectral density (PSD) of the seafloor along known survey lines. By cumulatively summing variance across spatial frequency bins — starting from the highest frequency and working toward scales matching the distance from a known measurement — these methods estimate the likely interpolation error at any given location. Spatial methods use sliding-window statistics (standard deviation, min/max envelopes, Gaussian smoothing) computed directly from the depth field to characterize local variability. To evaluate and develop these methods, the library simulates sparse surveying on full-coverage raster datasets: it subsamples every N-th column as a synthetic survey line, linearly interpolates across the gaps, and computes the true residual between the interpolated and actual seafloor. This residual serves as ground truth for validating each uncertainty estimate across different seafloor types (flat, rough, sloped).

Installation

Quick install (pip)

If you just want to use the library without modifying it:

pip install git+https://github.com/franciscorpuz/nbs_uncles.git

Note: This project depends on GDAL, which can be difficult to install via pip alone. If you run into issues, use the conda workflow below instead.

For conda users / collaborators

This is the recommended approach — it handles GDAL and other geospatial C dependencies reliably via conda-forge.

git clone https://github.com/franciscorpuz/nbs_uncles
cd nbs_uncles
conda env create -f environment.yml
conda activate nbs_uncles

The environment includes an editable install (pip install -e .) of the package itself, so any changes you make to src/ are immediately available.

To update your environment after a git pull:

conda env update -f environment.yml --prune

Getting started

See the notebooks in notebooks/ for usage examples. The primary working notebook is uncertainty_sim_nbs_dataset.ipynb.

from nbs_uncles import (
    read_file, show_depth,
    build_coverage_mask,
    compute_dominant_angle_radon_transform, compute_local_orientation,
    detect_trackline_positions, assign_depths_to_lines,
    build_uncertainty_raster, undo_rotation,
)
from skimage.morphology import opening, thin, disk

# 1. Load bathymetric raster
bathy_data = read_file("data/raster/H13060_MB_4m_MLLW_3of3.bag", verbose=True)
show_depth(bathy_data, cmap='viridis')

# 2. Build binary coverage mask
bathy_binary = build_coverage_mask(bathy_data)

# 3-4. Morphological filtering + skeletonisation to isolate tracklines
bathy_lines = bathy_binary & ~opening(bathy_binary, disk(5))
bathy_thin = thin(bathy_lines) > 0

# 5. Radon transform to find dominant line orientations
dominant = compute_dominant_angle_radon_transform(bathy_thin, circle=False)

# 6. PCA-based local angle estimation
local_orientations = compute_local_orientation(bathy_thin, line_length=50, num_neighbors=20)

# 7-14. For each dominant angle: detect lines, assign depths, compute uncertainty
for angle in dominant['peaks']:
    # Extract pixels near this angle
    low, high = (angle - 5) % 180, (angle + 5) % 180
    if low < high:
        angle_mask = (local_orientations >= low) & (local_orientations < high)
    else:
        angle_mask = (local_orientations >= low) | (local_orientations < high)

    # Detect trackline positions and assign depth values
    peaks, restored_mask, angle_to_rotate = detect_trackline_positions(
        angle_mask, bathy_binary, angle,
    )
    depth_raster = assign_depths_to_lines(
        restored_mask, bathy_binary, bathy_data, angle_to_rotate,
    )

    # Compute spectral uncertainty and rotate back to original orientation
    uncertainty = build_uncertainty_raster(
        peaks, restored_mask, depth_raster, bathy_data['metadata']['resolution'],
    )
    result = undo_rotation(uncertainty, angle_to_rotate, bathy_binary.shape)

Package structure

nbs_ucnles
├── io              — read_file (GDAL-backed raster/BAG I/O)
├── visualization   — show_depth (plotting)
├── preprocessing
│   ├── morphology  — build_coverage_mask, morphological filters
│   ├── orientation — Radon transform, PCA-based local angles
│   └── geometry    — point rotation, undo_rotation
├── methods         — compute_uncertainty (FFT/PSD spectral energy)
└── pipeline        — detect_trackline_positions, assign_depths_to_lines,
                      process_line_pair, build_uncertainty_raster

How to cite nbs_uncles

NOAA - NOS National Bathymetric Source Project Link: https://nauticalcharts.noaa.gov/learn/nbs.html

Project details


Download files

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

Source Distribution

nbs_uncles-0.0.1.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

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

nbs_uncles-0.0.1-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file nbs_uncles-0.0.1.tar.gz.

File metadata

  • Download URL: nbs_uncles-0.0.1.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nbs_uncles-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9abcf524be773317f897c72bbb6545d74bd151e1d7311ee55558d2f0c003230a
MD5 7745434b7bcad01c1e64ffb63799d7a2
BLAKE2b-256 8ce43f79635be82c7261b23e4e81cea2f68f613db56534c27ad2c38c6e27f17d

See more details on using hashes here.

File details

Details for the file nbs_uncles-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: nbs_uncles-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nbs_uncles-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f17178c732ef52b7e5d9b9ced8903b5473353aafbdcde4ef643fd2221039f43e
MD5 f3ee1c6ac52f562f53ddbd245182e64d
BLAKE2b-256 b7582d7bdd5b3c3e5f430281eb813cec13a03ff2dabe2ebbc06b44d2d0233a60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page