LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
figures Namespace Reference

Functions

 build_parent_map (root=xmlparameters)
 
 find_species (root, mnemonic)
 
 _get_from_default (root, name_lower)
 
 get_par (name, species_mnemonic, root=xmlparameters, parent_map=parent_map)
 
 get_par (_name, _type='mean')
 Helpers.
 
 weibull (_x, _p1, _p2, _p3=1.0)
 Response functions.
 
 temp (_x, _p1, _p2)
 
 get_par_range (_name)
 
 plot_response_row (_ax, _func, _x, _names, _xlabel, _ylabel, _xlim=None, _ylim=None, _legend=False)
 
 plot_response (_filename, _func, _x, _names, _xlabel, _ylabel, _xlim=None, _ylim=None, _legend=False, _adjust=None)
 
 plot_single (_filename, _func, _x, _xlabel, _ylabel, _xlim=None, _ylim=None)
 
 t_kernel (_x, _t_opt, _gauss_exp, _e0, _q10)
 
 t_microbial_e0 (_x, _gauss_exp, _t_opt, _e0)
 
 t_microbial_q10 (_x, _gauss_exp, _t_opt, _q10)
 
 ph_logistic (_x, _ph_50, _width)
 
 ph_bell (_x, _half_width, _exponent, _ph_opt)
 
 ph_cutoff (_fact)
 
 t_logistic (_x, _t_50, _width)
 
 aged_cn (_cn, _cn_undamped, _exponent)
 
 depth_logistic (_z, _z_50, _steepness)
 
 get_par (_name, _xml)
 Helpers.
 

Variables

 fig = plt.figure( figsize=(7, 4))
 zs = np.array([temp(x, t1, t2) * weibull(y, w1, w2, w3) for x,y in zip(np.ravel(X), np.ravel(Y))]) zs = np.array([2.0 / (1.0/temp(x, t1, t2) + 1.0/weibull(y, w1, w2, w3)) for x,y in zip(np.ravel(X), np.ravel(Y))]) Z = zs.reshape(X.shape)
 
 temp = np.arange(30, 50, 0.1)
 
 _xlim
 Microbial processes.
 
 _ylim
 Nitrification.
 
 p1 = get_par('METRX_F_CHEMODENIT_T_1')
 Decomposition and humification.
 
 p_mix = get_par('METRX_F_PERTUBATION_MIX')
 Bioturbation (D_eff_dailyturbation_sl) response factors (constants are hard-coded in soilchemistry-metrx-physics-chemistry.cpp)
 

Detailed Description

Response functions of MeTrX plotted for the doxygen documentation.

Parameter values (mean, min, max) are read from resources/parameters-site.xml,
figures are written to ../figures/.

Function Documentation

◆ _get_from_default()

figures._get_from_default ( root,
name_lower )
protected
Fallback: get parameter from species mnemonic='none'.
28def _get_from_default(root, name_lower):
29 """Fallback: get parameter from species mnemonic='none'."""
30 default_species = find_species(root, 'none')
31 if default_species is None:
32 return None # or raise
33
34 for elem in default_species.findall('par'):
35 if elem.attrib.get('name', '').lower() == name_lower:
36 return float(elem.attrib['value'])
37 return None
38

References find_species().

Referenced by get_par().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ aged_cn()

figures.aged_cn ( _cn,
_cn_undamped,
_exponent )
C:N modifier of the aged pool turnover (site parameters _CN_1, _CN_2).

MeTrX_decomposition: min(1, (CN_1 / (C:N))^CN_2), i.e. undamped up to a C:N of CN_1 and
increasingly damped above it.
229def aged_cn(_cn, _cn_undamped, _exponent):
230 """C:N modifier of the aged pool turnover (site parameters _CN_1, _CN_2).
231
232 MeTrX_decomposition: min(1, (CN_1 / (C:N))^CN_2), i.e. undamped up to a C:N of CN_1 and
233 increasingly damped above it.
234 """
235 return min(1.0, (_cn_undamped / _cn)**_exponent)
236

References get_par(), plot_response(), plot_response_row(), and plot_single().

Here is the call graph for this function:

◆ build_parent_map()

figures.build_parent_map ( root = xmlparameters)
Build a dict: child_element -> parent_element.
16def build_parent_map(root=xmlparameters):
17 """Build a dict: child_element -> parent_element."""
18 return {child: parent for parent in root.iter() for child in parent}

References build_parent_map().

Referenced by build_parent_map(), and get_par().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ depth_logistic()

figures.depth_logistic ( _z,
_z_50,
_steepness )
Depth damping of methane production (site parameters _DEPTH_1 = 50 % depth, _DEPTH_2).
303def depth_logistic(_z, _z_50, _steepness):
304 """Depth damping of methane production (site parameters _DEPTH_1 = 50 % depth, _DEPTH_2)."""
305 return 1.0 / (1.0 + math.exp(_steepness * (_z - _z_50)))
306

References plot_response().

Here is the call graph for this function:

◆ find_species()

figures.find_species ( root,
mnemonic )
Return the first <species> element with the given mnemonic.
21def find_species(root, mnemonic):
22 """Return the first <species> element with the given mnemonic."""
23 for node in root.iter('species'):
24 if node.attrib.get('mnemonic') == mnemonic:
25 return node
26 return None
27

Referenced by _get_from_default(), and get_par().

Here is the caller graph for this function:

◆ get_par() [1/3]

figures.get_par ( _name ,
_type = 'mean' )

Helpers.

Return value ('mean'), 'min' or 'max' of a site parameter.
18def get_par( _name, _xml) :
19 for elem in _xml :
20 if elem.attrib.get( 'name').lower() == _name.lower() :
21 return float(elem.attrib.get( 'value', ''))
22 return None
23

◆ get_par() [2/3]

figures.get_par ( _name,
_type = 'mean' )

Helpers.

Return value ('mean'), 'min' or 'max' of a site parameter.
18def get_par( _name, _xml) :
19 for elem in _xml :
20 if elem.attrib.get( 'name').lower() == _name.lower() :
21 return float(elem.attrib.get( 'value', ''))
22 return None
23

References get_par(), and weibull().

Here is the call graph for this function:

◆ get_par() [3/3]

figures.get_par ( name,
species_mnemonic,
root = xmlparameters,
parent_map = parent_map )
name: parameter name (string), e.g. 'aejm'
species_mnemonic: e.g. ':corns:' or ':poaceae:'
root: root <speciesparameters> element
parent_map: optional precomputed parent map (for efficiency)
39def get_par(name, species_mnemonic, root=xmlparameters, parent_map=parent_map):
40 """
41 name: parameter name (string), e.g. 'aejm'
42 species_mnemonic: e.g. ':corns:' or ':poaceae:'
43 root: root <speciesparameters> element
44 parent_map: optional precomputed parent map (for efficiency)
45 """
46 if parent_map is None:
47 parent_map = build_parent_map(root)
48
49 name_lower = name.lower()
50
51 # 1. Find requested species node
52 species_node = find_species(root, species_mnemonic)
53 if species_node is None:
54 # if the species doesn't exist at all, skip to default
55 return _get_from_default(root, name_lower)
56
57 # 2. Walk up the hierarchy: species -> parent species -> ...
58 current = species_node
59 while current is not None and current.tag == 'species':
60 for elem in current.findall('par'):
61 if elem.attrib.get('name', '').lower() == name_lower:
62 return float(elem.attrib['value'])
63 current = parent_map.get(current)
64
65 # 3. If not found, try the default species mnemonic="none"
66 return _get_from_default(root, name_lower)
67
68

References _get_from_default(), build_parent_map(), find_species(), and get_par().

Referenced by aged_cn(), get_par(), get_par(), and get_par_range().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_par_range()

figures.get_par_range ( _name)
Return dictionary with mean, min and max of a site parameter.
33def get_par_range(_name):
34 """Return dictionary with mean, min and max of a site parameter."""
35 return {t: get_par(_name, t) for t in ('mean', 'min', 'max')}
36

References get_par().

Referenced by plot_response_row().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ph_bell()

figures.ph_bell ( _x,
_half_width,
_exponent,
_ph_opt )
MeTrX_get_fact_ph_bell (arguments in order of site parameters _1, _2, _3).
134def ph_bell(_x, _half_width, _exponent, _ph_opt):
135 """MeTrX_get_fact_ph_bell (arguments in order of site parameters _1, _2, _3)."""
136 return 1.0 / (1.0 + (abs(_x - _ph_opt) / _half_width)**_exponent)

◆ ph_cutoff()

figures.ph_cutoff ( _fact)
Processes with pH response below FACT_PH_MIN are not calculated (SoilChemistryMeTrX::FACT_PH_MIN).
138def ph_cutoff(_fact):
139 """Processes with pH response below FACT_PH_MIN are not calculated (SoilChemistryMeTrX::FACT_PH_MIN)."""
140 return _fact if _fact >= FACT_PH_MIN else 0.0

References plot_response().

Referenced by t_logistic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ph_logistic()

figures.ph_logistic ( _x,
_ph_50,
_width )
MeTrX_get_fact_ph_logistic: increasing with pH for _width > 0, decreasing for _width < 0.
131def ph_logistic(_x, _ph_50, _width):
132 """MeTrX_get_fact_ph_logistic: increasing with pH for _width > 0, decreasing for _width < 0."""
133 return 1.0 / (1.0 + math.exp(-(_x - _ph_50) / _width))

Referenced by t_logistic().

Here is the caller graph for this function:

◆ plot_response()

figures.plot_response ( _filename,
_func,
_x,
_names,
_xlabel,
_ylabel,
_xlim = None,
_ylim = None,
_legend = False,
_adjust = None )
Plot response with sensitivity to each parameter (see plot_response_row) and save figure.
78 _xlim=None, _ylim=None, _legend=False, _adjust=None):
79 """Plot response with sensitivity to each parameter (see plot_response_row) and save figure."""
80 n = len(_names) + 1
81 fig, ax = plt.subplots(1, n, figsize=(5*n, 4))
82 plot_response_row(ax, _func, _x, _names, _xlabel, _ylabel, _xlim, _ylim, _legend)
83 if _adjust is not None:
84 plt.subplots_adjust(**_adjust)
85 save(_filename)
86

References plot_response_row().

Referenced by aged_cn(), depth_logistic(), ph_cutoff(), and t_logistic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plot_response_row()

figures.plot_response_row ( _ax,
_func,
_x,
_names,
_xlabel,
_ylabel,
_xlim = None,
_ylim = None,
_legend = False )
Plot _func(x, *parameters) on a row of axes.

The first panel shows the response with all parameters at their mean value.
Each further panel varies one parameter between min (blue), mean (black) and
max (red) while the other parameters are kept at their mean value.
49def plot_response_row(_ax, _func, _x, _names, _xlabel, _ylabel, _xlim=None, _ylim=None, _legend=False):
50 """Plot _func(x, *parameters) on a row of axes.
51
52 The first panel shows the response with all parameters at their mean value.
53 Each further panel varies one parameter between min (blue), mean (black) and
54 max (red) while the other parameters are kept at their mean value.
55 """
56 pars = [get_par_range(name) for name in _names]
57 means = [p['mean'] for p in pars]
58
59 _ax[0].plot(_x, [_func(x, *means) for x in _x], colors['mean'])
60 _ax[0].set_title('\n'.join(f"{n}: {p['mean']}" for n, p in zip(_names, pars)), fontsize=8)
61
62 for k, par in enumerate(pars):
63 ax = _ax[k+1]
64 for t in ('mean', 'min', 'max'):
65 values = list(means)
66 values[k] = par[t]
67 ax.plot(_x, [_func(x, *values) for x in _x], colors[t],
68 label=None if t == 'mean' else str(par[t]))
69 ax.set_title('\n'.join(f"{n}: [{p['min']}, {p['max']}]" if i == k else f"{n}: {p['mean']}"
70 for i, (n, p) in enumerate(zip(_names, pars))), fontsize=8)
71 if _legend:
72 ax.legend()
73
74 for ax in _ax:
75 format_axes(ax, _xlabel, _ylabel, _xlim, _ylim)
76

References get_par_range().

Referenced by aged_cn(), and plot_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plot_single()

figures.plot_single ( _filename,
_func,
_x,
_xlabel,
_ylabel,
_xlim = None,
_ylim = None )
Plot response without parameter variation and save figure.
87def plot_single(_filename, _func, _x, _xlabel, _ylabel, _xlim=None, _ylim=None):
88 """Plot response without parameter variation and save figure."""
89 fig, ax = plt.subplots(1, 1, figsize=(5, 4))
90 ax.plot(_x, [_func(x) for x in _x])
91 format_axes(ax, _xlabel, _ylabel, _xlim, _ylim)
92 save(_filename)
93
94

Referenced by aged_cn().

Here is the caller graph for this function:

◆ t_kernel()

figures.t_kernel ( _x,
_t_opt,
_gauss_exp,
_e0,
_q10 )
MeTrX_get_fact_t_microbial, the temperature response shared by all rate processes.

Below the optimum a Q10 (_q10 > 0) or a Lloyd & Taylor form (_e0 > 0) applies, above it
and otherwise a gaussian. Arguments in the order of the C++ function.
107def t_kernel(_x, _t_opt, _gauss_exp, _e0, _q10):
108 """MeTrX_get_fact_t_microbial, the temperature response shared by all rate processes.
109
110 Below the optimum a Q10 (_q10 > 0) or a Lloyd & Taylor form (_e0 > 0) applies, above it
111 and otherwise a gaussian. Arguments in the order of the C++ function.
112 """
113 if _x <= _t_opt:
114 if _q10 > 0.0:
115 return _q10 ** ((_x - _t_opt) / 10.0)
116 if _e0 > 0.0:
117 if _x <= T_ZERO_MICROBIAL + 1.0:
118 return 0.0
119 return math.exp(_e0 * (1.0 / (_t_opt - T_ZERO_MICROBIAL) - 1.0 / (_x - T_ZERO_MICROBIAL)))
120 return temp(_x, _gauss_exp, _t_opt)
121

References temp.

Referenced by t_microbial_e0(), and t_microbial_q10().

Here is the caller graph for this function:

◆ t_logistic()

figures.t_logistic ( _x,
_t_50,
_width )
Temperature inhibition of nosZ (site parameters _T_1 = half response, _T_2 = width).
194def t_logistic(_x, _t_50, _width):
195 """Temperature inhibition of nosZ (site parameters _T_1 = half response, _T_2 = width)."""
196 return 1.0 / (1.0 + math.exp(-(_x - _t_50) / _width))
197

References ph_cutoff(), ph_logistic(), and plot_response().

Here is the call graph for this function:

◆ t_microbial_e0()

figures.t_microbial_e0 ( _x,
_gauss_exp,
_t_opt,
_e0 )
Kernel with Lloyd & Taylor below the optimum (site parameters _T_EXP_1, _T_EXP_2, _T_E0).
122def t_microbial_e0(_x, _gauss_exp, _t_opt, _e0):
123 """Kernel with Lloyd & Taylor below the optimum (site parameters _T_EXP_1, _T_EXP_2, _T_E0)."""
124 return t_kernel(_x, _t_opt, _gauss_exp, _e0, 0.0)
125

References t_kernel().

Here is the call graph for this function:

◆ t_microbial_q10()

figures.t_microbial_q10 ( _x,
_gauss_exp,
_t_opt,
_q10 )
Kernel with a Q10 below the optimum (site parameters _T_EXP_1, _T_EXP_2, _Q10).
126def t_microbial_q10(_x, _gauss_exp, _t_opt, _q10):
127 """Kernel with a Q10 below the optimum (site parameters _T_EXP_1, _T_EXP_2, _Q10)."""
128 return t_kernel(_x, _t_opt, _gauss_exp, 0.0, _q10)

References t_kernel().

Here is the call graph for this function:

◆ temp()

figures.temp ( _x ,
_p1 ,
_p2  )
Gaussian around the optimum _p2 with width _p1, used above the optimum by the kernel.
26def temp( _x, _p1, _p2) :
27 return math.exp(-_p1 * (1.0 - _x / _p2)**2.0)

Variable Documentation

◆ _xlim

figures._xlim
protected

Microbial processes.

Methane production and oxidation.

Denitrification.

◆ _ylim

figures._ylim
protected

Nitrification.

Anaerobic volume fraction and pore connectivity.

◆ fig

figures.fig = plt.figure( figsize=(7, 4))

zs = np.array([temp(x, t1, t2) * weibull(y, w1, w2, w3) for x,y in zip(np.ravel(X), np.ravel(Y))]) zs = np.array([2.0 / (1.0/temp(x, t1, t2) + 1.0/weibull(y, w1, w2, w3)) for x,y in zip(np.ravel(X), np.ravel(Y))]) Z = zs.reshape(X.shape)

ax.plot_surface(X, Y, Z, cmap="winter", rstride=1, cstride=1) ax.set_title('Temperature-moisture factor') ax.set_xlabel('T [oC]') ax.set_ylabel('wfps [-]') ax.set_zlabel('response [-]') plt.savefig(script_dir+"/../figures/temp_moist.png")

◆ temp

figures.temp = np.arange(30, 50, 0.1)
Gaussian around the optimum _p2 with width _p1, used above the optimum by the kernel.

Referenced by t_kernel().