lmweather authoring skill
Guidance for authoring, running, and verifying rotating shallow-water weather and climate dynamics programs on the lmweather host.
Purpose
Help write deterministic lmscript programs for lmweather that simulate idealized atmospheric and oceanic dynamics on a rotating sphere (spectral transform method, Williamson test cases) or on a beta-plane channel (staggered C-grid finite differences).
When to use it
Use lmweather when a task needs spherical shallow-water integrations, Williamson benchmark cases (TC1 cosine-bell advection, TC2 steady geostrophic flow, TC5 mountain wave train, TC6 Rossby-Haurwitz wave), passive tracer transport, barotropic jet instability, or beta-plane Rossby, Kelvin, and gravity wave adjustments exported for plotting.
Install
Install the lmctl CLI toolchain with npm i -g @lmctl-ai/lmctl or download a release binary from GitHub Releases. Linux binaries require dynamic glibc 2.35 or newer (Ubuntu 22.04+) with C++ runtimes linked statically and zero external library dependencies. Bind install="github:lmctl-ai/lmweather@latest" on the _lmcode_ block so run_lmcode resolves or downloads the binary automatically.
Commands
lmscript rh.lms
lmweather --version
lmweather --notices
lmweather --lmcode-schema
lmweather --lmcode-schema --json
lmweather --lmcode-signatures
lmweather --dry-run --lmcode build/rh.dslb
lmweather --lmcode build/rh.dslb
Inputs and outputs
- Inputs are lmscript _lmcode_ blocks compiled against the embedded lmweather.dsl.json schema, using context object wx of type Wx to create Sphere and Plane models.
- Initial conditions, orography, and passive tracers are specified as mathematical expression strings (in radians using lon, lat on the sphere or meters using x, y on the plane) or built-in Williamson and spherical-harmonic presets.
- Outputs include point diagnostics, spectral and harmonic energy metrics, and space-separated gnuplot pm3d tables written via save_csv, save_zonal_mean, save_spectrum, save_row,save_column, or wx.save_text.
- Stdout carries only the single SDK JSON terminal result frame; wx.print(msg) writes diagnostics to stderr.
Safety rules
- Keep explicit RK4 time steps within the gravity-wave CFL stability limit: query model.stable_dt() or choose dt below 2 * sqrt(2) / omega_max on the sphere; lmweather rejects unstable steps before integrating and re-checks stability every 64 steps.
- Respect unit and angle conventions: SI units everywhere; point query latitudes/longitudes (height_at, u_at, v_at, vorticity_at, tracer_at, wave_crest) and CSV columns use degrees, while tilt(alpha), williamson1(alpha), williamson2(alpha), and expression variables lon, lat use radians.
- On a Plane model, call depth(H) before calling fields, perturb, or run; changing resting depth after initializing fields is rejected. Note that the h expression in Plane.fields(h_anom, u, v) is the height anomaly added to H.
- Initialize a tracer with sphere.tracer(expr) or sphere.williamson1(alpha) before calling sphere.advect_only() or querying tracer_* methods.
- Keep triangular truncation T in [4, 170] and total memory within the default 4096 MiB ceiling (configurable via LMWEATHER_MAX_MEMORY_MB).
Worked examples
p = _lmcode_ cli="lmweather" install="github:lmctl-ai/lmweather@latest";
let s = wx.sphere(42).williamson6();
let m0 = s.mean_height();
let e0 = s.energy();
s.run_dt(7.0 * 86400.0, 900.0);
wx.print("crest of wave 4 at 45N: " + str(s.wave_crest(4, 45.0)) + " deg");
wx.assert_close(s.mean_height(), m0, 0.000000001);
wx.assert_close(s.energy() / e0, 1.0, 0.0001);
s.save_csv("rh_day7.csv");
let ch = wx.plane(128, 64, 6400000.0, 3200000.0)
.depth(1000.0)
.coriolis(0.0001, 1.6e-11)
.linear()
.fields("10.0 * exp(-((x - 0.5*lx)*(x - 0.5*lx) + (y - 0.5*ly)*(y - 0.5*ly)) / (300000.0*300000.0))", "0", "0");
ch.run(86400.0);
wx.assert_close(ch.mean_depth(), 1000.0, 0.0001);
ch.save_row(32, "ridge_midline.dat");
end _lmcode_
r = run_lmcode(p);
require(r.ok, "lmweather simulation failed");
Errors and exit codes
Exit 0 indicates that all bytecode slots loaded and completed. Exit 2 reports invalid command-line syntax, contradictory --dry-run flags, or an invalid LMWEATHER_MAX_MEMORY_MB setting. Exit 3 reports bytecode load or schema errors, expression syntax failures, RK4 CFL stability limit violations, non-finite divergence during integration, invalid method ordering (such as calling Plane.depth after Plane.fields or querying tracer metrics without a tracer), failed assertions, or memory budget exhaustion. Exit 4 reports application failures tagged APP_FAIL.
How to verify
- Run lmweather --version and lmweather --lmcode-schema --json to verify the binary version and embedded schema contract.
- Validate compiled bytecode without running time integrations by passing --dry-run --lmcode.
- Check mass conservation with wx.assert_close(s.mean_height(), m0, 1e-9) on the sphere or wx.assert_close(p.mean_depth(), H0, 1e-9) on the plane.
- Check energy conservation (s.energy() / e0 near 1.0), normalized Williamson errors (s.error_l2(), s.error_linf()), or linear potential vorticity conservation (p.pv_anomaly_rms()).