Skip to main content

CanyonbPy: CANYON-B Python

DOI

A Python implementation of CANYON-B (CArbonate system and Nutrients concentration from hYdrological properties and Oxygen using Neural networks) based on Bittig et al., 2018. It was developped from the MATLAB CANYON-B v1.0.

Features

Calculate macronutrients and carbonate system variables using CANYON-B neural network.

Installation

You can install canyonbpy using pip:

pip install canyonbpy

Usage

Here's a simple example of how to use canyonbpy with numpy:

from datetime import datetime
from canyonbpy import canyonb


# Prepare your data
data = {
    'gtime': [datetime(2024, 1, 1)],  # Date/time 
    'lat': [45.0],          # Latitude (-90 to 90)
    'lon': [-20.0],         # Longitude (-180 to 180)
    'pres': [100.0],        # Pressure (dbar)
    'temp': [15.0],         # Temperature (°C)
    'psal': [35.0],         # Salinity
    'doxy': [250.0]         # Dissolved oxygen (µmol/kg)
}

# Make predictions
results = canyonb(**data)

# Access results
ph = results['pH']           # pH prediction
ph_error = results['pH_ci']  # pH uncertainty

And now directly with xarray:

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

# ds must contain: time, latitude, longitude, pressure, temperature, salinity, doxy
ds = xr.Dataset(
    {
        "temperature": (("time", "pressure", "latitude", "longitude"), 16.0 * np.ones((2, 3, 3, 4))), 
        "salinity": (("time", "pressure", "latitude", "longitude"), 36.1 * np.ones((2, 3, 3, 4))),
        "doxy": (("time", "pressure", "latitude", "longitude"), 104 * np.ones((2, 3, 3, 4))),
    },
    coords={
        "time": ("time", [datetime(2014, 12, 9, 8, 45), datetime(2020, 12, 10, 8, 45)]),
        "pressure": ("pressure", np.array([180, 181, 182])),
        "latitude": ("latitude", np.array([17.6, 17.6, 17.6])),
        "longitude": ("longitude", np.array([-24.3, -24.3, -24.3, -24.3])),
    },
)

# Predict with CANYON-B
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])

Available parameters for prediction:

  • AT: Total Alkalinity
  • CT: Total Dissolved Inorganic Carbon
  • pH: pH
  • pCO2: Partial pressure of CO2
  • NO3: Nitrate
  • PO4: Phosphate
  • SiOH4: Silicate

Documentation

Documentation is available here.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this package in your research, please cite both the original CANYON-B paper and this implementation with the corresponding version for bug tracking (the example here shows all versions):

@article{bittig2018canyon,
  title={An alternative to static climatologies: Robust estimation of open ocean CO2 variables and nutrient concentrations from T, S, and O2 data using Bayesian neural networks},
  author={Bittig, Henry C and Steinhoff, Tobias and Claustre, Hervé and Körtzinger, Arne and others},
  journal={Frontiers in Marine Science},
  volume={5},
  pages={328},
  year={2018},
  publisher={Frontiers}, 
  doi={10.3389/fmars.2018.00328},
}

@software{bajon_canyonbpy,
  author    = {Bajon, Raphaël},
  title     = {canyonbpy: A Python implementation of CANYON-B},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.14765787},
  url       = {https://doi.org/10.5281/zenodo.14765787}
}

Metadata

Release files for canyonbpy 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for canyonbpy 0.4.0
File Size Uploaded Provenance Actions
canyonbpy-0.4.0.tar.gz 719.5 kB Without provenance Details for canyonbpy-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for canyonbpy 0.4.0
File Interpreter ABI Platform Actions
canyonbpy-0.4.0-py3-none-any.whl Python 3 none any Details for canyonbpy-0.4.0-py3-none-any.whl

Total release size: 1.5 MB

Release files / canyonbpy-0.4.0.tar.gz

Download URL canyonbpy-0.4.0.tar.gz
Size 719.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c457d3924411a45b4d15df3bce4db447d3c735ccf18987b94cf9145b938954cc
BLAKE2b-256 checksum
How to use checksums
3399039d8cf38555d74b6a790337d1a6edd3b7ddf5e24ece3aad53091bc8600e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / canyonbpy-0.4.0-py3-none-any.whl

Download URL canyonbpy-0.4.0-py3-none-any.whl
Size 732.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b439568309d27c44c39ba8fca6e1066aedaa33d6fae4ed6fc406ae24371e8761
BLAKE2b-256 checksum
How to use checksums
9095c8a371750589213e6a7adecd2f0bce7149bf2d3c81d62a9dcfe3a2e72fa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for canyonbpy 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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