time_dependent_process

digraph inheritanceccd21e700c { bgcolor=transparent; rankdir=LR; ratio=expand; size=""; "Process" [URL="climlab.process.process.html#climlab.process.process.Process",dirType=back,fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=14,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A generic parent class for all climlab process objects."]; "TimeDependentProcess" [URL="#climlab.process.time_dependent_process.TimeDependentProcess",dirType=back,fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=14,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A generic parent class for all time-dependent processes."]; "Process" -> "TimeDependentProcess" [arrowsize=0.5,dirType=back,style="setlinewidth(0.5)"]; }
class climlab.process.time_dependent_process.TimeDependentProcess(time_type='explicit', timestep=None, topdown=True, **kwargs)[source]

Bases: Process

A generic parent class for all time-dependent processes.

TimeDependentProcess is a child of the Process class and therefore inherits all those attributes.

Initialization parameters

An instance of TimeDependentProcess is initialized with the following arguments (for detailed information see Object attributes below):

Parameters:
  • timestep (float) – specifies the timestep of the object (optional)

  • time_type (str) – how time-dependent-process should be computed [default: ‘explicit’]

  • topdown (bool) – whether geneterate process_types in regular or in reverse order [default: True]

Object attributes

Additional to the parent class Process following 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': see initialization parameter

    • 'num_steps_per_year': see set_timestep() and timestep() for details

    • 'day_of_year_index': counter how many steps have been integrated in current year

    • 'steps': counter how many steps have been integrated in total

    • 'days_elapsed': time counter for days

    • 'years_elapsed': time counter for years

    • 'days_of_year': array which holds the number of numerical steps per year, expressed in days

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 given value.

add_input(name[, value])

Create a new input variable called name for this process and initialize it with the given value.

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 state value.

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])

Convert process variables to xarray.Dataset format.

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 the compute() 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.

integrate_converge(crit=0.0001, verbose=True)[source]

Integrates the model until model states are converging.

Parameters:
  • crit (float) – exit criteria for difference of iterated solutions [default: 0.0001]

  • verbose (bool) – information whether total elapsed time should be printed [default: True]

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:
  • days (float) – integration time for the model in days [default: 1.0]

  • verbose (bool) – information whether model time details should be printed [default: True]

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:
  • years (float) – integration time for the model in years [default: 1.0]

  • verbose (bool) – information whether model time details should be printed [default: True]

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 name to a new state value.

Parameters:
  • name (string) – name of the state

  • value (Field or array) – state variable

Raises:

ValueError if state variable value is not having a domain.

Raises:

ValueError if 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.])
set_timestep(timestep=86400.0, num_steps_per_year=None)[source]

Calculates the timestep in unit seconds and calls the setter function of timestep()

Parameters:
  • timestep (float) – the amount of time over which step_forward() is integrating in unit seconds [default: 24*60*60]

  • num_steps_per_year (float) – a number of steps per calendar year (optional)

If the parameter num_steps_per_year is specified and not None, the timestep is calculated accordingly and therefore the given input parameter timestep is ignored.

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.param['timestep'].

Setter:

Sets the timestep to the given input. See also set_timestep().

Type:

float

climlab.process.time_dependent_process.couple(proclist, name='Parent')[source]