process

- 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:
objectA 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
Processis initialized with the following arguments (for detailed information see Object attributes below):- Parameters:
state (Field) – spatial state variable for the process. Set to
Noneif not specified.domains (
_Domainor dict of_Domain) – domain(s) for the processsubprocess (
Processor dict ofProcess) – subprocess(es) of the processlat (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
Processfollowing object attributes are generated during initialization:- Variables:
param (dict) – dictionary of model parameters which are given through
**kwargsdiagnostics (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:
depthDepth at grid centers (m)
depth_boundsDepth at grid interfaces (m)
diagnosticsDictionary access to all diagnostic variables
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)
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.
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.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.to_xarray([diagnostics, timeave])Convert process variables to
xarray.Datasetformat.- add_diagnostic(name, value=None)[source]
Create a new diagnostic variable called
namefor this process and initialize it with the givenvalue.Quantity is accessible in two ways:
as a process attribute, i.e.
proc.nameas 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
namefor this process and initialize it with the givenvalue.Quantity is accessible in two ways:
as a process attribute, i.e.
proc.nameas 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, verbose=True)[source]
Adds a single subprocess to this process.
- Parameters:
name (string) – name of the subprocess
proc (
Process) – a Process object
- Raises:
ValueErrorifprocis 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
inputlistto the list of diagnostics.
- declare_input(inputlist)[source]
Add the variable names in
inputlistto 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:
ValueErrorif 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:
ValueErrorif no'depth'axis can be found.
- property input
Dictionary access to all input variables
That can be boundary conditions and other gridded quantities independent of the process
- Type:
- 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:
ValueErrorif 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:
ValueErrorif 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:
ValueErrorif 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:
ValueErrorif 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:
ValueErrorif 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:
ValueErrorif no'lon'axis can be found.
- remove_diagnostic(name)[source]
Removes a diagnostic from the
process.diagnosticdictionary 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
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.])
- to_xarray(diagnostics=False, timeave=False)[source]
Convert process variables to
xarray.Datasetformat.With
diagnostics=True, both state and diagnostic variables are included.Otherwise just the state variables are included.
Returns an
xarray.Datasetobject with all spatial axes, including ‘bounds’ axes indicating cell boundaries in each spatial dimension.- Example:
Create a single column radiation model and view as
xarrayobject:>>> 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 (
Processor_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:
- 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:
- 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'