process

digraph inheritanceb5682a5d9a { bgcolor=transparent; rankdir=LR; ratio=expand; size=""; "Process" [URL="#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."]; }
class climlab.process.process.Process(name='Untitled', state=None, domains=None, subprocess=None, lat=None, lev=None, num_lat=None, num_levels=None, input=None, verbose=True, **kwargs)[source]

Bases: object

A generic parent class for all climlab process objects. Every process object has a set of state variables on a spatial grid.

For more general information about Processes and their role in climlab, see Process section climlab-architecture.

Initialization parameters

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

Parameters:
  • state (Field) – spatial state variable for the process. Set to None if not specified.

  • domains (_Domain or dict of _Domain) – domain(s) for the process

  • subprocess (Process or dict of Process) – subprocess(es) of the process

  • lat (array) – latitudinal points (optional)

  • lev – altitudinal points (optional)

  • num_lat (int) – number of latitudional points (optional)

  • num_levels (int) – number of altitudinal points (optional)

  • input (dict) – collection of input quantities

  • verbose (bool) – Flag to control text output during instantiation of the Process [default: True]

Object attributes

Additional to the parent class Process following object attributes are generated during initialization:

Variables:
  • domains (dict) – dictionary of process _Domain

  • state (dict) – dictionary of process states (of type Field)

  • param (dict) – dictionary of model parameters which are given through **kwargs

  • diagnostics (dict) – a dictionary with all diagnostic variables

  • _input_vars (dict) – collection of input quantities like boundary conditions and other gridded quantities

  • creation_date (str) – date and time when process was created

  • subprocess (dict of Process) – dictionary of suprocesses of the process

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)

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.

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.

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.

to_xarray([diagnostics])

Convert process variables to xarray.Dataset format.

add_diagnostic(name, value=None)[source]

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

Quantity is accessible in two ways:

  • as a process attribute, i.e. proc.name

  • as a member of the diagnostics dictionary, i.e. proc.diagnostics['name']

Use attribute method to set values, e.g. `proc.name = value `

Parameters:
  • name (str) – name of diagnostic quantity to be initialized

  • value (array) – initial value for quantity [default: None]

Example:

Add a diagnostic CO2 variable to an energy balance model:

>>> import climlab
>>> model = climlab.EBM()

>>> # initialize CO2 variable with value 280 ppm
>>> model.add_diagnostic('CO2',280.)

>>> # access variable directly or through diagnostic dictionary
>>> model.CO2
280
>>> model.diagnostics.keys()
['ASR', 'CO2', 'net_radiation', 'icelat', 'OLR', 'albedo']
add_input(name, value=None)[source]

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

Quantity is accessible in two ways:

  • as a process attribute, i.e. proc.name

  • as a member of the input dictionary, i.e. proc.input['name']

Use attribute method to set values, e.g. `proc.name = value `

Parameters:
  • name (str) – name of diagnostic quantity to be initialized

  • value (array) – initial value for quantity [default: None]

add_subprocess(name, proc)[source]

Adds a single subprocess to this process.

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

  • proc (Process) – a Process object

Raises:

ValueError if proc is not a process

Example:

Replacing an albedo subprocess through adding a subprocess with same name:

>>> from climlab.model.ebm import EBM_seasonal
>>> from climlab.surface.albedo import StepFunctionAlbedo

>>> # creating EBM model
>>> ebm_s = EBM_seasonal()

>>> print ebm_s
climlab Process of type <class 'climlab.model.ebm.EBM_seasonal'>.
State variables and domain shapes:
  Ts: (90, 1)
The subprocess tree:
top: <class 'climlab.model.ebm.EBM_seasonal'>
   diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
   LW: <class 'climlab.radiation.AplusBT.AplusBT'>
   albedo: <class 'climlab.surface.albedo.P2Albedo'>
   insolation: <class 'climlab.radiation.insolation.DailyInsolation'>
>>> #  creating and adding albedo feedback subprocess
>>> step_albedo = StepFunctionAlbedo(state=ebm_s.state, **ebm_s.param)
>>> ebm_s.add_subprocess('albedo', step_albedo)
>>>
>>> print ebm_s
climlab Process of type <class 'climlab.model.ebm.EBM_seasonal'>.
State variables and domain shapes:
  Ts: (90, 1)
The subprocess tree:
top: <class 'climlab.model.ebm.EBM_seasonal'>
   diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
   LW: <class 'climlab.radiation.AplusBT.AplusBT'>
   albedo: <class 'climlab.surface.albedo.StepFunctionAlbedo'>
      iceline: <class 'climlab.surface.albedo.Iceline'>
      cold_albedo: <class 'climlab.surface.albedo.ConstantAlbedo'>
      warm_albedo: <class 'climlab.surface.albedo.P2Albedo'>
   insolation: <class 'climlab.radiation.insolation.DailyInsolation'>
add_subprocesses(procdict)[source]

Adds a dictionary of subproceses to this process.

Calls add_subprocess() for every process given in the input-dictionary. It can also pass a single process, which will be given the name default.

Parameters:

procdict (dict) – a dictionary with process names as keys

declare_diagnostics(diaglist)[source]

Add the variable names in inputlist to the list of diagnostics.

declare_input(inputlist)[source]

Add the variable names in inputlist to the list of necessary inputs.

property depth

Depth at grid centers (m)

Getter:

Returns the points of axis 'depth' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'depth' axis can be found.

property depth_bounds

Depth at grid interfaces (m)

Getter:

Returns the bounds of axis 'depth' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'depth' axis can be found.

property diagnostics

Dictionary access to all diagnostic variables

Type:

dict

property input

Dictionary access to all input variables

That can be boundary conditions and other gridded quantities independent of the process

Type:

dict

property lat

Latitude of grid centers (degrees North)

Getter:

Returns the points of axis 'lat' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'lat' axis can be found.

property lat_bounds

Latitude of grid interfaces (degrees North)

Getter:

Returns the bounds of axis 'lat' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'lat' axis can be found.

property lev

Pressure levels at grid centers (hPa or mb)

Getter:

Returns the points of axis 'lev' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'lev' axis can be found.

property lev_bounds

Pressure levels at grid interfaces (hPa or mb)

Getter:

Returns the bounds of axis 'lev' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'lev' axis can be found.

property lon

Longitude of grid centers (degrees)

Getter:

Returns the points of axis 'lon' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'lon' axis can be found.

property lon_bounds

Longitude of grid interfaces (degrees)

Getter:

Returns the bounds of axis 'lon' if availible in the process’s domains.

Type:

array

Raises:

ValueError if no 'lon' axis can be found.

remove_diagnostic(name)[source]

Removes a diagnostic from the process.diagnostic dictionary and also delete the associated process attribute.

Parameters:

name (str) – name of diagnostic quantity to be removed

Example:

Remove diagnostic variable ‘icelat’ from energy balance model:

>>> import climlab
>>> model = climlab.EBM()

>>> # display all diagnostic variables
>>> model.diagnostics.keys()
['ASR', 'OLR', 'net_radiation', 'albedo', 'icelat']

>>> model.remove_diagnostic('icelat')
>>> model.diagnostics.keys()
['ASR', 'OLR', 'net_radiation', 'albedo']

>>> # Watch out for subprocesses that may still want
>>>  # to access the diagnostic 'icelat' variable !!!
remove_subprocess(name, verbose=True)[source]

Removes a single subprocess from this process.

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

  • verbose (bool) – information whether warning message should be printed [default: True]

Example:

Remove albedo subprocess from energy balance model:

>>> import climlab
>>> model = climlab.EBM()

>>> print model
climlab Process of type <class 'climlab.model.ebm.EBM'>.
State variables and domain shapes:
  Ts: (90, 1)
The subprocess tree:
top: <class 'climlab.model.ebm.EBM'>
   diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
   LW: <class 'climlab.radiation.AplusBT.AplusBT'>
   albedo: <class 'climlab.surface.albedo.StepFunctionAlbedo'>
      iceline: <class 'climlab.surface.albedo.Iceline'>
      cold_albedo: <class 'climlab.surface.albedo.ConstantAlbedo'>
      warm_albedo: <class 'climlab.surface.albedo.P2Albedo'>
   insolation: <class 'climlab.radiation.insolation.P2Insolation'>

>>> model.remove_subprocess('albedo')

>>> print model
climlab Process of type <class 'climlab.model.ebm.EBM'>.
State variables and domain shapes:
  Ts: (90, 1)
The subprocess tree:
top: <class 'climlab.model.ebm.EBM'>
   diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
   LW: <class 'climlab.radiation.AplusBT.AplusBT'>
   insolation: <class 'climlab.radiation.insolation.P2Insolation'>
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.])
to_xarray(diagnostics=False)[source]

Convert process variables to xarray.Dataset format.

With diagnostics=True, both state and diagnostic variables are included.

Otherwise just the state variables are included.

Returns an xarray.Dataset object with all spatial axes, including ‘bounds’ axes indicating cell boundaries in each spatial dimension.

Example:

Create a single column radiation model and view as xarray object:

>>> import climlab
>>> state = climlab.column_state(num_lev=20)
>>> model = climlab.radiation.RRTMG(state=state)

>>> # display model state as xarray:
>>> model.to_xarray()
<xarray.Dataset>
Dimensions:       (depth: 1, depth_bounds: 2, lev: 20, lev_bounds: 21)
Coordinates:
  * depth         (depth) float64 0.5
  * depth_bounds  (depth_bounds) float64 0.0 1.0
  * lev           (lev) float64 25.0 75.0 125.0 175.0 225.0 275.0 325.0 ...
  * lev_bounds    (lev_bounds) float64 0.0 50.0 100.0 150.0 200.0 250.0 ...
Data variables:
    Ts            (depth) float64 288.0
    Tatm          (lev) float64 200.0 204.1 208.2 212.3 216.4 220.5 224.6 ...

>>> # take a single timestep to populate the diagnostic variables
>>> model.step_forward()
>>> # Now look at the full output in xarray format
>>> model.to_xarray(diagnostics=True)
<xarray.Dataset>
Dimensions:           (depth: 1, depth_bounds: 2, lev: 20, lev_bounds: 21)
Coordinates:
  * depth             (depth) float64 0.5
  * depth_bounds      (depth_bounds) float64 0.0 1.0
  * lev               (lev) float64 25.0 75.0 125.0 175.0 225.0 275.0 325.0 ...
  * lev_bounds        (lev_bounds) float64 0.0 50.0 100.0 150.0 200.0 250.0 ...
Data variables:
    Ts                (depth) float64 288.7
    Tatm              (lev) float64 201.3 204.0 208.0 212.0 216.1 220.2 ...
    ASR               (depth) float64 240.0
    ASRcld            (depth) float64 0.0
    ASRclr            (depth) float64 240.0
    LW_flux_down      (lev_bounds) float64 0.0 12.63 19.47 26.07 32.92 40.1 ...
    LW_flux_down_clr  (lev_bounds) float64 0.0 12.63 19.47 26.07 32.92 40.1 ...
    LW_flux_net       (lev_bounds) float64 240.1 231.2 227.6 224.1 220.5 ...
    LW_flux_net_clr   (lev_bounds) float64 240.1 231.2 227.6 224.1 220.5 ...
    LW_flux_up        (lev_bounds) float64 240.1 243.9 247.1 250.2 253.4 ...
    LW_flux_up_clr    (lev_bounds) float64 240.1 243.9 247.1 250.2 253.4 ...
    LW_sfc            (depth) float64 128.9
    LW_sfc_clr        (depth) float64 128.9
    OLR               (depth) float64 240.1
    OLRcld            (depth) float64 0.0
    OLRclr            (depth) float64 240.1
    SW_flux_down      (lev_bounds) float64 341.3 323.1 318.0 313.5 309.5 ...
    SW_flux_down_clr  (lev_bounds) float64 341.3 323.1 318.0 313.5 309.5 ...
    SW_flux_net       (lev_bounds) float64 240.0 223.3 220.2 217.9 215.9 ...
    SW_flux_net_clr   (lev_bounds) float64 240.0 223.3 220.2 217.9 215.9 ...
    SW_flux_up        (lev_bounds) float64 101.3 99.88 97.77 95.64 93.57 ...
    SW_flux_up_clr    (lev_bounds) float64 101.3 99.88 97.77 95.64 93.57 ...
    SW_sfc            (depth) float64 163.8
    SW_sfc_clr        (depth) float64 163.8
    TdotLW            (lev) float64 -1.502 -0.6148 -0.5813 -0.6173 -0.6426 ...
    TdotLW_clr        (lev) float64 -1.502 -0.6148 -0.5813 -0.6173 -0.6426 ...
    TdotSW            (lev) float64 2.821 0.5123 0.3936 0.3368 0.3174 0.3299 ...
    TdotSW_clr        (lev) float64 2.821 0.5123 0.3936 0.3368 0.3174 0.3299 ...
climlab.process.process.get_axes(process_or_domain)[source]

Returns a dictionary of all Axis in a domain or dictionary of domains.

Parameters:

process_or_domain (Process or _Domain) – a process or a domain object

Raises:
exc:

TypeError if input is not or not having a domain

Returns:

dictionary of input’s Axis

Return type:

dict

Example:
>>> import climlab
>>> from climlab.process.process import get_axes

>>> model = climlab.EBM()

>>> get_axes(model)
{'lat': <climlab.domain.axis.Axis object at 0x7ff13b9dd2d0>,
 'depth': <climlab.domain.axis.Axis object at 0x7ff13b9dd310>}
climlab.process.process.process_like(proc)[source]

Make an exact clone of a process, including state and all subprocesses.

The creation date is updated.

Parameters:

proc (Process) – process

Returns:

new process identical to the given process

Return type:

Process

Example:
>>> import climlab
>>> from climlab.process.process import process_like

>>> model = climlab.EBM()
>>> model.subprocess.keys()
['diffusion', 'LW', 'albedo', 'insolation']

>>> albedo = model.subprocess['albedo']
>>> albedo_copy = process_like(albedo)

>>> albedo.creation_date
'Thu, 24 Mar 2016 01:32:25 +0000'

>>> albedo_copy.creation_date
'Thu, 24 Mar 2016 01:33:29 +0000'