Skip to content

Welcome to CanyonbPy

CanyonbPy is a Python package implementing the CANYON-B neural network for predicting ocean nutrients and carbonate system variables, just from temperature, salinity and dissolved oxygen.

Matlab version: CANYON-B v1.0

This package has been developped using the CANYON-B v1.0 Matlab version of the code.

Python version: PyCO2SYS v1.8.0+

The calculations from canyonbpy could require PyCO2SYS Python package. Here, we used PyCO2SYS v1.8.0.

Features

Predict ocean parameters using CANYON-B neural network models

  • Multi-parameters prediction
    • Total Alkalinity (AT) in μmol·kg−1
    • Dissolved Inorganic Carbon (CT) in μmol·kg−1
    • pH
    • pCO2 in μatm
    • Nitrate (NO3) in μmol·kg−1
    • Phosphate (PO4) in μmol·kg−1
    • Silicate (SiOH4) in μmol·kg−1
  • Handle various input formats including datetime and decimal years
  • Automatic Arctic latitude adjustments
  • Uncertainty estimates for all predictions
  • numpy integration for multi-dimensional data variables

Installation

pip install canyonbpy

For more detailed installation instructions, see the Installation page.

Main commands

canyonbpy main function

canyonb - performs the CANYON-B calculation.

Quick Start

In your Python environment with numpy, datetime and canyonbpy libraries:

import numpy as np
from datetime import datetime
from canyonbpy import canyonb

# Sample data
data = {
    'gtime': [datetime(2024, 1, 1)],
    'lat': np.array([45.0]),
    'lon': np.array([-20.0]),
    'pres': np.array([100.0]),
    'temp': np.array([15.0]),
    'psal': np.array([35.0]),
    'doxy': np.array([250.0])
}

# Get predictions
results = canyonb(**data)

Even easier now:

import xarray as xr
import canyonbpy  # accessor ds.canyonb is registered here

# ds must contain: time, latitude, longitude, pressure, temperature, salinity, doxy
results = ds.canyonb.predict()

# CONTENT
results_content = ds.canyonb.content()

# results is an xr.Dataset with the same dims/coords as ds
print(results["pH"])       # xr.DataArray
print(results["pH_ci"])    # total uncertainty

# Merge predictions back into the source dataset
ds_enriched = xr.merge([ds, results])