time_dependent_process

- class climlab.process.time_dependent_process.TimeDependentProcess(time_type='explicit', timestep=86400, initial_time=np.datetime64('1970-01-01T00:00'), topdown=True, **kwargs)[source]
Bases:
ProcessA generic parent class for all time-dependent processes.
TimeDependentProcessis a child of theProcessclass and therefore inherits all those attributes.Initialization parameters
An instance of
TimeDependentProcessis initialized with the following arguments (for detailed information see Object attributes below):- Parameters:
Object attributes
Additional to the parent class
Processfollowing object attributes are generated during initialization:- Variables:
has_process_type_list (bool) – information whether attribute process_types (which is needed for
compute()and build in_build_process_type_list()) exists or not. Attribute is set to'False'during initialization.topdown (bool) – information whether the list process_types (which contains all processes and sub-processes) should be generated in regular or in reverse order. See
_build_process_type_list().timeave (dict) – a time averaged collection of all states and diagnostic processes over the timeperiod that
integrate_years()has been called for last.tendencies (dict) – computed difference in a timestep for each state. See
compute()for details.time_type (str) – how time-dependent-process should be computed. Possible values are:
'explicit','implicit','diagnostic','adjustment'.time (dict) –
- a collection of all time-related attributes of the process.
The dictionary contains following items:
'timestep': The model timestep as np.timedelta64 object'steps': counter how many steps have been integrated in total'initial_time': The initial time when the Process is first created as np.datetime64 object [default: Jan. 1 1970]'current_time': The current model time as np.datetime64 object (should be equal to initial_time + steps*timestep)'active_now': Boolean that indicates whether the Process is currently active (used for asynchronous coupling)
- Attributes:
- current_time
depthDepth at grid centers (m)
depth_boundsDepth at grid interfaces (m)
diagnosticsDictionary access to all diagnostic variables
- elapsed_time
inputDictionary access to all input variables
latLatitude of grid centers (degrees North)
lat_boundsLatitude of grid interfaces (degrees North)
levPressure levels at grid centers (hPa or mb)
lev_boundsPressure levels at grid interfaces (hPa or mb)
lonLongitude of grid centers (degrees)
lon_boundsLongitude of grid interfaces (degrees)
timestepThe amount of time over which
step_forward()is integrating in unit seconds.timestep_in_secondsReturn a float value representing the timestep in units of seconds
Methods
add_diagnostic(name[, value])Create a new diagnostic variable called
namefor this process and initialize it with the givenvalue.add_input(name[, value])Create a new input variable called
namefor this process and initialize it with the givenvalue.add_subprocess(name, proc[, verbose])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
inputlistto the list of diagnostics.declare_input(inputlist)Add the variable names in
inputlistto 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.diagnosticdictionary 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
nameto a new statevalue.Updates state variables with computed tendencies.
to_xarray([diagnostics, timeave])Convert process variables to
xarray.Datasetformat.- compute()[source]
Computes the tendencies for all state variables given current state and specified input.
The function first computes all diagnostic processes. They don’t produce any tendencies directly but they may affect the other processes (such as change in solar distribution). Subsequently, all tendencies and diagnostics for all explicit processes are computed.
Tendencies due to implicit and adjustment processes need to be calculated from a state that is already adjusted after explicit alteration. For that reason the explicit tendencies are applied to the states temporarily. Now all tendencies from implicit processes are calculated by matrix inversions and similar to the explicit tendencies, the implicit ones are applied to the states temporarily. Subsequently, all instantaneous adjustments are computed.
Then the changes that were made to the states from explicit and implicit processes are removed again as this
compute()function is supposed to calculate only tendencies and not apply them to the states.Finally, all calculated tendencies from all processes are collected for each state, summed up and stored in the dictionary
self.tendencies, which is an attribute of the time-dependent-process object, for which thecompute()method has been called.Object attributes
During method execution following object attributes are modified:
- Variables:
tendencies (dict) – dictionary that holds tendencies for all states is calculated for current timestep through adding up tendencies from explicit, implicit and adjustment processes.
diagnostics (dict) – process diagnostic dictionary is updated by diagnostic dictionaries of subprocesses after computation of tendencies.
- compute_diagnostics(num_iter=3)[source]
Compute all tendencies and diagnostics, but don’t update model state. By default it will call compute() 3 times to make sure all subprocess coupling is accounted for. The number of iterations can be changed with the input argument.
- property current_time
- property elapsed_time
- integrate_converge(crit=0.0001, verbose=True)[source]
Integrates the model until model states are converging.
- Parameters:
- Example:
>>> import climlab >>> model = climlab.EBM() >>> model.global_mean_temperature() Field(11.997968598413685) >>> model.integrate_converge() Total elapsed time is 10.0 years. >>> model.global_mean_temperature() Field(14.288155406577301)
- integrate_days(days=1.0, verbose=True)[source]
Integrates the model forward for a specified number of days.
It convertes the given number of days into years and calls
integrate_years().- Parameters:
- Example:
>>> import climlab >>> model = climlab.EBM() >>> model.global_mean_temperature() Field(11.997968598413685) >>> model.integrate_days(80.) Integrating for 19 steps, 80.0 days, or 0.219032740466 years. Total elapsed time is 0.211111111111 years. >>> model.global_mean_temperature() Field(11.873680783355553)
- integrate_years(years=1.0, verbose=True)[source]
Integrates the model by a given number of years.
- Parameters:
It calls
step_forward()repetitively and calculates a time averaged value over the integrated period for every model state and all diagnostics processes.- Example:
>>> import climlab >>> model = climlab.EBM() >>> model.global_mean_temperature() Field(11.997968598413685) >>> model.integrate_years(2.) Integrating for 180 steps, 730.4844 days, or 2.0 years. Total elapsed time is 2.0 years. >>> model.global_mean_temperature() Field(13.531055349437258)
- set_state(name, value)[source]
Sets the variable
nameto a new statevalue.- Parameters:
name (string) – name of the state
value (
Fieldor array) – state variable
- Raises:
ValueErrorif state variablevalueis not having a domain.- Raises:
ValueErrorif shape mismatch between existing domain and new state variable.- Example:
Resetting the surface temperature of an EBM to \(-5 ^{\circ} \textrm{C}\) on all latitues:
>>> import climlab >>> from climlab import Field >>> import numpy as np >>> # setup model >>> model = climlab.EBM(num_lat=36) >>> # create new temperature distribution >>> initial = -5 * ones(size(model.lat)) >>> model.set_state('Ts', Field(initial, domain=model.domains['Ts'])) >>> np.squeeze(model.Ts) Field([-5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5., -5.])
- step_forward()[source]
Updates state variables with computed tendencies.
Calls the
compute()method to get current tendencies for all process states. Multiplied with the timestep and added up to the state variables is updating all model states.- Example:
>>> import climlab >>> model = climlab.EBM() >>> # checking time step counter >>> model.time['steps'] 0 >>> # stepping the model forward >>> model.step_forward() >>> # step counter increased >>> model.time['steps'] 1
- property timestep
The amount of time over which
step_forward()is integrating in unit seconds.- Getter:
Returns the object timestep which is stored in
self.time['timestep'].- Setter:
Sets the timestep to the given input.
- Type:
- property timestep_in_seconds
Return a float value representing the timestep in units of seconds