import numpy as np
[docs]
def defcolumn(transf, inout_datastore, ddi, mapper):
"""Interpolate 3-D fields to the surface and compute column-integrated quantities.
Prepends a synthetic surface level (index 0) to every 3-D field (pressure,
specific humidity, total condensed water, temperature, winds) by linear
extrapolation from the two lowest model levels, using the 2 m temperature for
the temperature extrapolation. All downstream diagmet steps operate on this
augmented column. See :doc:`/documentation/doc-models/chimere/diagmet`
(section 2) for the full derivation.
Args:
transf (Plugin): diagmet transform instance.
inout_datastore (dict): mutable datastore.
ddi (datetime): current sub-simulation date.
mapper (dict): transform mapper.
"""
# Inputs
temp = inout_datastore["inputs"][("meteo", "temp")][ddi]["spec"].values
temp2 = inout_datastore["inputs"][("meteo", "tem2")][ddi]["spec"].values
sphu = inout_datastore["inputs"][("meteo", "sphu")][ddi]["spec"].values
alti = inout_datastore["outputs"][("meteo", "alti")][ddi]["spec"].values
pres = transf.diag_misc["pres"]
winm = inout_datastore["inputs"][("meteo", "winm")][ddi]["spec"].values
winz = inout_datastore["inputs"][("meteo", "winz")][ddi]["spec"].values
cliq = inout_datastore["inputs"][("meteo", "clwc")][ddi]["spec"].values
water = cliq
if transf.cice and (
(transf.clol == 1) or (transf.clom == 1) or (transf.cloh == 1)
):
cice = inout_datastore["inputs"][("meteo", "cice")][ddi]["spec"]
water = water + cice
if transf.rain and (
(transf.clol == 1) or (transf.clom == 1) or (transf.cloh == 1)
):
rain = inout_datastore["inputs"][("meteo", "rain")][ddi]["spec"]
water = water + rain
# Interpolate variables to surface
alt_wgt = (alti[:, 0] / (alti[:, 1] - alti[:, 0]))[:, np.newaxis]
alti = np.concatenate([0 * alti[:, [0]], alti], axis=1)
winm = np.concatenate([0 * winm[:, [0]], winm], axis=1)
winz = np.concatenate([0 * winz[:, [0]], winz], axis=1)
pres = np.concatenate(
[pres[:, [0]] + (pres[:, [0]] - pres[:, [1]]) * alt_wgt, pres], axis=1)
sphu = np.concatenate(
[np.maximum(1e-10, sphu[:, [0]] + (sphu[:, [0]] - sphu[:, [1]]) * alt_wgt),
sphu], axis=1)
water = np.concatenate(
[np.maximum(1e-10, water[:, [0]] + (water[:, [0]] - water[:, [1]]) * alt_wgt),
water], axis=1)
temp = np.concatenate(
[temp2[:, [0]] - (temp[:, [0]] - temp2[:, [0]])
* 2 / (alti[:, [0]] - 2), temp],
axis=1)
# missing: op for optical thickness
# Save it for later
transf.diag_misc["alti"] = alti
transf.diag_misc["pres"] = pres
transf.diag_misc["sphu"] = sphu
transf.diag_misc["water"] = water
transf.diag_misc["temp"] = temp
transf.diag_misc["winz"] = winz
transf.diag_misc["winm"] = winm