Quick Start
This page walks through a complete end-to-end example in about 15 lines of code. We’ll build a Lorenz 63 system, integrate it, and export the result to Pyleoclim for a quick spectral analysis.
1. Create a model
Every ClimateCritters model takes a forcing argument. For the Lorenz 63 system the forcing adds an optional perturbation to the x-equation; here we set it to zero.
import climatecritters as cc
from climatecritters.model_critters import Lorenz63
forcing = cc.Forcing(lambda t: 0.0)
model = Lorenz63(forcing=forcing, sigma=10.0, rho=28.0, beta=8/3)2. Integrate
Call integrate() with an integration window, initial conditions, and a solver method. It returns a CCOutput object containing the full trajectory.
output = model.integrate(
t_span=(0, 50),
y0=[1.0, 1.0, 1.0],
method='RK45',
)3. Inspect the output
print(output.state_variables.dtype.names) # ('x', 'y', 'z')
print(output.time[:5]) # first five time points4. Export to Pyleoclim
to_pyleo() converts any state variable into a Pyleoclim Series (or MultipleSeries for a list of names), enabling the full suite of Pyleoclim analysis and plotting tools.
ts_x = output.to_pyleo(var_names='x')
ts_x.plot()For a dashboard with spectral analysis:
ts_x.dashboard()5. Try a time-varying parameter
Any parameter can be replaced with a callable at construction time. The callable must have signature (t), (t, state), or (t, state, model).
# rho increases linearly from 20 to 40 over the integration window
model_tv = Lorenz63(
forcing=forcing,
sigma=10.0,
rho=lambda t: 20.0 + (20.0 / 50.0) * t,
beta=8/3,
)
output_tv = model_tv.integrate(t_span=(0, 50), y0=[1, 1, 1], method='RK45')