limiter
- class climlab.process.limiter.Limiter(bounds={}, **kwargs)[source]
Bases:
TimeDependentProcess
A process that implements strict bounds on the allowable range of values of state variables. Values outside the given bounds are adjusted back to the bounding value at each timestep.
Bounding values are stored in a dictionary
.bounds
which has identical keys to.state
Each item in the
.bounds
dict is another dict containing the keys'minimum'
and'maximum'
. By default these are initialized toNone
andnp.inf
respectively, which means the process produces zero adjustment.The user needs to specify desired minimum and/or maximum values for each state variable. These can be specified at process creation time using the keyword argument
bounds
, or modified in-place (see example below).For diagnostic purposes, we can always access the adjustments (in state variable units) and the tendencies (in state variable units per second) produced by the Limiter just like any other process (see example below)
Example use: an EBM with surface temperature limited to <= 25 degrees C:
import climlab ebm = climlab.EBM() # Create the Limiter process, and make sure it has a matching timestep mylimiter = climlab.process.Limiter(state=ebm.state, timestep=ebm.timestep) # Now set our desired upper bound on the temperature mylimiter.bounds['Ts']['maximum'] = 25. # And couple it to the rest of the model ebm.add_subprocess('TempLimiter', mylimiter) # Take a step forward and verify that surface temperatures do not exceed 25 degrees C ebm.step_forward() assert np.all(ebm.Ts<=25) # Examine the tendencies (in degrees C / second) produced by the Limiter: # They should be zero everywhere the temperaure is less than 25 degrees: print(ebm.subprocess['TempLimiter'].tendencies)
- Attributes:
depth
Depth at grid centers (m)
depth_bounds
Depth at grid interfaces (m)
diagnostics
Dictionary access to all diagnostic variables
input
Dictionary access to all input variables
lat
Latitude of grid centers (degrees North)
lat_bounds
Latitude of grid interfaces (degrees North)
lev
Pressure levels at grid centers (hPa or mb)
lev_bounds
Pressure levels at grid interfaces (hPa or mb)
lon
Longitude of grid centers (degrees)
lon_bounds
Longitude of grid interfaces (degrees)
timestep
The amount of time over which
step_forward()
is integrating in unit seconds.
Methods
add_diagnostic
(name[, value])Create a new diagnostic variable called
name
for this process and initialize it with the givenvalue
.add_input
(name[, value])Create a new input variable called
name
for this process and initialize it with the givenvalue
.add_subprocess
(name, proc)Adds a single subprocess to this process.
add_subprocesses
(procdict)Adds a dictionary of subproceses to this process.
compute
()Computes the tendencies for all state variables given current state and specified input.
compute_diagnostics
([num_iter])Compute all tendencies and diagnostics, but don't update model state.
declare_diagnostics
(diaglist)Add the variable names in
inputlist
to the list of diagnostics.declare_input
(inputlist)Add the variable names in
inputlist
to the list of necessary inputs.integrate_converge
([crit, verbose])Integrates the model until model states are converging.
integrate_days
([days, verbose])Integrates the model forward for a specified number of days.
integrate_years
([years, verbose])Integrates the model by a given number of years.
remove_diagnostic
(name)Removes a diagnostic from the
process.diagnostic
dictionary and also delete the associated process attribute.remove_subprocess
(name[, verbose])Removes a single subprocess from this process.
set_state
(name, value)Sets the variable
name
to a new statevalue
.set_timestep
([timestep, num_steps_per_year])Calculates the timestep in unit seconds and calls the setter function of
timestep()
step_forward
()Updates state variables with computed tendencies.
to_xarray
([diagnostics, timeave])Convert process variables to
xarray.Dataset
format.