standard_knowledge
Programmatically augmenting CF Standards with IOOS operational knowledge.
# uv run python
# in py
=
# Load all CF standards
# Apply community knowledge to the standards
# Get a standard by name or alias
=
# Xarray compatible attributes for a standard
=
# find standards by variable names
=
# Notice the `.filter()`? It returns a StandardsFilter object,
# so you can chain multiple filters together.
# by_ioos_category, by_unit, has_qartod_tests
# Search for standards across multiple fields (name, aliases, common variable names, related standards)
=
Or in Javascript (preview here!)
import init from "./pkg/standard_knowledge_js.js"
await
let library =
library.
library.
library.
let standard = library.
let attrs = standard.
let standards = library..
let underPressure = library..
A CLI can also be installed for interacting with the standards.
cargo install --path cli or ./noxfile.py -s install_cli from the repo, or cargo install standard_knowledge_cli for the published version.
)
{
}
)
The CLI can also load other sources of knowledge with --knowledge/-k. Knowledge can be loaded from local paths, including directories, as well as URLs.
Once -k is specified the default knowledge loading is skipped, unless -k lib is included.
Goals
Provide a cross language way (by packaging Rust into Python, Javascript, and other languages) of sharing learnings from users of CF Standards.
- Translations from CF-ese
- Common column/variable names
Contributing Knowledge
The core of the library isn't the code, but the knowledge that we have gained as a community in implementing the CF Standards in our work.
The knowledge is stored as YAML files in core/standards/ by <standard_name>.yaml.
# core/standards/air_pressure_at_mean_sea_level.yaml
ioos_category: Meteorology
long_name: Atmospheric Pressure at Sea Level
common_variable_names:
- pressure
- atmospheric_pressure
- sea_level_pressure
related_standards:
- air_pressure
sibling_standards:
- air_temperature
extra_attrs:
coverage_content_type: physicalMeasurement
ncei_name: PRESSURE - BAROMETRIC
standard_name_url: https://vocab.nerc.ac.uk/collection/P07/current/CFSN0015
other_units:
- kPa
- bar
comments: |
Raw pressure sensor values on buoys may need to be adjusted based on sensor tower height.
Knowledge keys:
ioos_category- Category of measurement for the Integrated Ocean Observing Systemlong_name- A more human readable name for the standardcommon_variable_names- When the standard name isn't used for a column or variable, what might commonly get used instead.related_standards- Standards that measure generally similar things, but differ in specifics that are worth investigating.sibling_standards- Standards that are usually used together.extra_attrs- Dictionary of extra attributes to be applied to Xarray or ERDDAP.other_units- Other units that may be used rather than the one defined in the standard.comments- What others may need to know about a standard. How is the standard used, rather than the CF description of how it is defined. Notes about implementation.
[!NOTE]
- IOOS categories are not (currently) validated, but the set of known values (derived from ERDDAP's internal list) is in core/src/ioos_categories.rs.
Contributing Code
Cargo as manages the Rust components of the project, while Maturin and uv help keep things inline when working from the Python side of things.
Releasing
Use ./noxfile.py -s release -- <patch|minor|major> to bump the version.
Preferbly in a PR with the changes from the last release included.
Rust Testing
cargo test will run tests in all the workspaces.
As the CLI changes, it's tests should be updated with TRYCMD=overwrite cargo test or ./noxfile.py -s update_rust_tests.
For new CLI tests, it's easiest to copy one of the files in cli/tests/cmd, and tweak the args to match the new command, then run TRYCMD=overwrite cargo test to replace the status code, stdout and stderr.
Can be run with ./noxfile.py -s test_rust
Python testing
From py, uv run pytest will run tests.
It will also pick up changes in Rust, both for the Python bindings and changes in the core library as well.
uv run python will open a shell with the library rebuilt for interactive tinkering.
Can be run with ./noxfile -s test_python.
Javascript testing
Best run with ./noxfile -s test_js, but individual tests are listed in the Javascript readme.
Utils
utils/update_standards.py- Run withuv run --script utils/update_standards.pyto update the standard names and alias files from CF Conventions that are imported into the Rust library.
Nox
./noxfile.py has helpers for testing, bumping versions, updating standards, and other things that are easy to forget how to do.
Unless a session is specified, Nox will run all but update_standards, install_cli, release, and test_wasm_env sessions.
Sessions (use -s):
update_standards- Updates the CF standards.install_cli- Install the Rust CLI.release-- <patch|minor|major> - Bumps the version of the all the packages for a release.py_test-<version>- Test a Python version as specified in the Github actions matrix.py_wheel- Build Linux wheels for currently supported Python versions.py_wheel_wasm- Build 3.14 WASM wheel.py_test_wasm- Create a Pyodide venv, install the wheel, and then probably confuse VS Code as it will try to automatically update the terminal environment. Useful for manually testing the Pyodide environment.rust_test- Runcargo testagainst all the Rust crates.rust_update_tests- Update the rust test fixtures.js_test- Run the full Javascript test suite.js_build- Build the Javascript package.js_dev- Run the Javascript development server.