Skip to content

vulcan.climate

climate


Interface between VULCAN and a climate model that updates the temperature and the eddy diffusion profile during an integration.

A climate hook is any callable hook(pco, Tco, species, ymix) that returns a ClimateUpdate. VULCAN passes its layer-centre pressures pco [dyn cm-2] from the bottom of the column up, its temperature Tco [K] on those layers, the list of species names and their volume mixing ratios ymix, shape (nz, ni). The hook returns the new temperature profile, and optionally a new eddy diffusion profile, on its own pressure grid; VULCAN maps them onto its grid with regrid_temperature and regrid_kzz. vulcan.agni.AgniClimate is the hook for AGNI; a coupled framework can pass its own hook to vulcan.run_vulcan.

All quantities are in cgs units, as everywhere in VULCAN.

ClimateUpdate(p, tmp, p_kzz=None, kzz=None) dataclass

Profiles returned by a climate hook, each on the hook's own pressure grid.

The arrays are copied, so they do not change with the hook's own arrays.

Attributes:

Name Type Description
p ndarray

Pressures of tmp [dyn cm-2], in any order.

tmp ndarray

Temperature [K].

p_kzz ndarray or None

Pressures of kzz [dyn cm-2], in any order. None when kzz is None.

kzz ndarray or None

Eddy diffusion coefficient [cm2 s-1], or None to leave VULCAN's profile unchanged.

kzz = None class-attribute instance-attribute

p instance-attribute

p_kzz = None class-attribute instance-attribute

tmp instance-attribute

interp_logp(p_src, val_src, p_tgt)

Interpolate linearly in log pressure; outside the source range the end values hold.

Parameters:

Name Type Description Default
p_src array_like

Source pressures, in any order and in any one pressure unit shared with p_tgt; must be positive.

required
val_src array_like

Values on p_src, same shape.

required
p_tgt array_like

Target pressures, in the unit of p_src.

required

Returns:

Type Description
ndarray

Values on p_tgt, same shape as p_tgt.

Source code in src/vulcan/climate.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def interp_logp(p_src, val_src, p_tgt) -> np.ndarray:
    """
    Interpolate linearly in log pressure; outside the source range the end values hold.

    Parameters
    ----------
    p_src : array_like
        Source pressures, in any order and in any one pressure unit shared with `p_tgt`;
        must be positive.
    val_src : array_like
        Values on `p_src`, same shape.
    p_tgt : array_like
        Target pressures, in the unit of `p_src`.

    Returns
    -------
    np.ndarray
        Values on `p_tgt`, same shape as `p_tgt`.
    """
    p_src = np.asarray(p_src, dtype=float)
    val_src = np.asarray(val_src, dtype=float)
    order = np.argsort(p_src)
    return np.interp(
        np.log(np.asarray(p_tgt, dtype=float)), np.log(p_src[order]), val_src[order]
    )

map_composition(p_src, species, ymix, p_tgt, current)

Map VULCAN mixing ratios onto the gases and pressures of a climate model.

A gas of the climate model that VULCAN also has takes VULCAN's profile, interpolated linearly in log pressure (end values hold outside VULCAN's grid). A gas that VULCAN does not have keeps its profile from current. The mixing ratios are then divided by their sum on each level, so that they sum to 1 again: VULCAN species absent from the climate model, such as radicals and condensates, are left out of that sum.

Parameters:

Name Type Description Default
p_src ndarray

VULCAN pressures of ymix [any unit, the same as p_tgt].

required
species list of str

VULCAN species names, the columns of ymix.

required
ymix ndarray

VULCAN volume mixing ratios [dimensionless], shape (nz, ni).

required
p_tgt ndarray

Pressures of the climate model's layers, in the same unit as p_src.

required
current dict

The climate model's present mixing ratio profile of each of its gases, on p_tgt.

required

Returns:

Type Description
dict

The new mixing ratio profile of each gas of the climate model, on p_tgt.

Source code in src/vulcan/climate.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def map_composition(
    p_src: np.ndarray,
    species: list[str],
    ymix: np.ndarray,
    p_tgt: np.ndarray,
    current: dict[str, np.ndarray],
) -> dict[str, np.ndarray]:
    """Map VULCAN mixing ratios onto the gases and pressures of a climate model.

    A gas of the climate model that VULCAN also has takes VULCAN's profile, interpolated
    linearly in log pressure (end values hold outside VULCAN's grid). A gas that VULCAN does
    not have keeps its profile from `current`. The mixing ratios are then divided by their
    sum on each level, so that they sum to 1 again: VULCAN species absent from the climate
    model, such as radicals and condensates, are left out of that sum.

    Parameters
    ----------
    p_src : np.ndarray
        VULCAN pressures of `ymix` [any unit, the same as `p_tgt`].
    species : list of str
        VULCAN species names, the columns of `ymix`.
    ymix : np.ndarray
        VULCAN volume mixing ratios [dimensionless], shape (nz, ni).
    p_tgt : np.ndarray
        Pressures of the climate model's layers, in the same unit as `p_src`.
    current : dict
        The climate model's present mixing ratio profile of each of its gases, on `p_tgt`.

    Returns
    -------
    dict
        The new mixing ratio profile of each gas of the climate model, on `p_tgt`.
    """
    p_src = np.asarray(p_src, dtype=float)
    p_tgt = np.asarray(p_tgt, dtype=float)
    ymix = np.asarray(ymix, dtype=float)
    out = {}
    for gas, prof in current.items():
        if gas in species:
            col = np.clip(ymix[:, species.index(gas)], 0.0, None)
            out[gas] = interp_logp(p_src, col, p_tgt)
        else:
            out[gas] = np.asarray(prof, dtype=float).copy()
    total = np.sum(list(out.values()), axis=0)
    if not np.all(total > 0):
        raise ValueError('The mapped composition is empty on at least one level')
    return {gas: prof / total for gas, prof in out.items()}

max_relative_change(t_old, t_new)

Largest relative temperature change over the layers, max |T_new - T_old| / T_old.

Parameters:

Name Type Description Default
t_old ndarray

Temperature before the update [K], shape (nz,); must be positive.

required
t_new ndarray

Temperature after the update [K], same shape.

required

Returns:

Type Description
float

The largest relative change [dimensionless].

Source code in src/vulcan/climate.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
def max_relative_change(t_old: np.ndarray, t_new: np.ndarray) -> float:
    """
    Largest relative temperature change over the layers, max |T_new - T_old| / T_old.

    Parameters
    ----------
    t_old : np.ndarray
        Temperature before the update [K], shape (nz,); must be positive.
    t_new : np.ndarray
        Temperature after the update [K], same shape.

    Returns
    -------
    float
        The largest relative change [dimensionless].
    """
    t_old = np.asarray(t_old, dtype=float)
    return float(np.max(np.abs(np.asarray(t_new, dtype=float) - t_old) / t_old))

regrid_kzz(update, pico_inner)

Eddy diffusion of a climate update on VULCAN's inner interfaces pico[1:-1].

Linear in log pressure of log Kzz when Kzz is positive everywhere, which reproduces a power law in pressure exactly; linear in Kzz otherwise. The end values hold outside the climate grid.

Parameters:

Name Type Description Default
update ClimateUpdate

Climate result; p_kzz [dyn cm-2] and kzz [cm2 s-1] are used.

required
pico_inner ndarray

VULCAN interface pressures without the top and bottom ones, pico[1:-1] [dyn cm-2], shape (nz - 1,).

required

Returns:

Type Description
ndarray

Kzz on pico_inner [cm2 s-1], shape (nz - 1,).

Raises:

Type Description
ValueError

If the update has no Kzz profile.

Source code in src/vulcan/climate.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def regrid_kzz(update: ClimateUpdate, pico_inner: np.ndarray) -> np.ndarray:
    """
    Eddy diffusion of a climate update on VULCAN's inner interfaces `pico[1:-1]`.

    Linear in log pressure of log Kzz when Kzz is positive everywhere, which reproduces a
    power law in pressure exactly; linear in Kzz otherwise. The end values hold outside the
    climate grid.

    Parameters
    ----------
    update : ClimateUpdate
        Climate result; `p_kzz` [dyn cm-2] and `kzz` [cm2 s-1] are used.
    pico_inner : np.ndarray
        VULCAN interface pressures without the top and bottom ones, `pico[1:-1]`
        [dyn cm-2], shape (nz - 1,).

    Returns
    -------
    np.ndarray
        Kzz on `pico_inner` [cm2 s-1], shape (nz - 1,).

    Raises
    ------
    ValueError
        If the update has no Kzz profile.
    """
    if update.kzz is None:
        raise ValueError('The climate update carries no kzz profile')
    p_tgt = np.asarray(pico_inner, dtype=float)
    if np.all(update.kzz > 0):
        return np.exp(interp_logp(update.p_kzz, np.log(update.kzz), p_tgt))
    return interp_logp(update.p_kzz, update.kzz, p_tgt)

regrid_temperature(update, pco)

Temperature of a climate update on VULCAN's layer-centre pressures.

Linear in log pressure. Above or below the climate grid the temperature of its top or bottom layer holds, so no value is extrapolated.

Parameters:

Name Type Description Default
update ClimateUpdate

Climate result; p [dyn cm-2] and tmp [K] are used.

required
pco ndarray

VULCAN layer-centre pressures [dyn cm-2], shape (nz,).

required

Returns:

Type Description
ndarray

Temperature on pco [K], shape (nz,).

Source code in src/vulcan/climate.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def regrid_temperature(update: ClimateUpdate, pco: np.ndarray) -> np.ndarray:
    """
    Temperature of a climate update on VULCAN's layer-centre pressures.

    Linear in log pressure. Above or below the climate grid the temperature of its top or
    bottom layer holds, so no value is extrapolated.

    Parameters
    ----------
    update : ClimateUpdate
        Climate result; `p` [dyn cm-2] and `tmp` [K] are used.
    pco : np.ndarray
        VULCAN layer-centre pressures [dyn cm-2], shape (nz,).

    Returns
    -------
    np.ndarray
        Temperature on `pco` [K], shape (nz,).
    """
    return interp_logp(update.p, update.tmp, np.asarray(pco, dtype=float))