This is an implementation of the Chemistry Land-surface Atmosphere Soil Slab (CLASS) model that runs entirely in the browser or any Javascript runtime like NodeJS.
For more information on CLASS, see https://classmodel.github.io/.
The CLASS web application that uses this package is available at https://classmodel.github.io/class-web.
The class model can be run from the command line.
# Generate config file with default values
pnpx @classmodel/class generate -o config.json
# Or download one of the presets from
# https://github.com/classmodel/class-web/tree/main/apps/class-solid/src/lib/presets
# Edit the config file
# Run the model
pnpx @classmodel/class run config.json
# Outputs h variable for each timestep in JSON format
# To output csv use
pnpx @classmodel/class run --output output.csv --format csv config.json
# To read from stdin use
cat config.json | pnpx @classmodel/class -
If you do not have pnpx
installed you can use npx
instead.
In development use pnpx tsx src/cli.ts ./config.json
.
To use the reference configuration of a experiment downloaded from the web application extract it with jq using
jq .reference < ~/Downloads/class-MyExperiment.json > config.json
Install with
pnpm install @classmodel/class
Run model with default config use
import { runClass } from "@classmodel/class/runner";
const config = {}
const output = runClass(config)
console.log(output)
This package is part of a monorepo with other packages and applications.
The Class model uses a JSON schema to validate the input configuration. The schema is defined in the @classmodel/class
package and can be found at src/config.json (in repo). The schema is used to validate the input configuration and to generate a form to input the configuration.
The src/config.ts
file contains the embedded JSON schema and its Typescript type definition.
At the moment you manually have to keep the src/config.ts
file in sync with the src/config.json
file. By copying the content over and updating the TypeScript Config type.
See the form package for additional keywords in the JSON schema.
To allow for some properties to be only defined and required when another property is true.
We use the if/then/else
syntax. The if
block should refer to a property in the main properties object.
The then
block can define additional properties that are required when the if
property is true.
See existing Config type in src/config.ts
file on how to define the TypeScript type of a new if/then/else
block.
To check types, you can run the pnpm typecheck
command as other commands ignore types.
The unit tests are written with node:test and node:assert.
The unit tests can be run with the following command:
pnpm test
To get test coverage
# Does not work via pnpm script so need to call node directly
node --import tsx --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info src/*.test.ts
# To generate a html report use genhtml which is part of lcov OS package
genhtml lcov.info --output-directory coverage
The API documention of the package can be generated with
pnpm run docs
Which will write HTML files to docs/
directory.
The documentation of the latest release is published at https://classmodel.github.io/class-web/docs/.
This project includes code that was generated with the assistance of a language model (LLM). All code generated by the LLM has been reviewed by the development team.