Source code for pycif.plugins.transforms.complex.diagmet.utils.convection

import numpy as np


[docs] def convection(transf, inout_datastore, ddi, mapper): """Compute convective mass fluxes (up-draught and down-draught) for CHIMERE. Converts the ECMWF updraught/downdraught detrainment rates (kg/m3/s) to detrainment fluxes per layer (``dpdu``, ``dpdd``, kg/m2/s, clipped to non-negative values) by multiplying them by the layer thickness derived from ``alti``, and recovers the corresponding entrainment profiles (``dpeu``, ``dped``) as the level-to-level convergence of the mass flux plus the detrainment term. All four outputs are zero when ``deep_convection`` is disabled. See :doc:`/documentation/doc-models/chimere/diagmet` (section 12) 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. """ # Compute convection if transf.deep_convection: upfl = inout_datastore["inputs"][("meteo", "mumf")][ddi]["spec"] dpdu = inout_datastore["inputs"][("meteo", "mudr")][ddi]["spec"] dwfl = inout_datastore["inputs"][("meteo", "mdmf")][ddi]["spec"] dpdd = inout_datastore["inputs"][("meteo", "mddr")][ddi]["spec"] else: upfl = 0. * inout_datastore["inputs"][("meteo", "temp")][ddi]["spec"] dpdu = 0. * inout_datastore["inputs"][("meteo", "temp")][ddi]["spec"] dwfl = 0. * inout_datastore["inputs"][("meteo", "temp")][ddi]["spec"] dpdd = 0. * inout_datastore["inputs"][("meteo", "temp")][ddi]["spec"] # Convert detrainment rates from kg/m3/s to kg/m2/s # alti is the altitude above ground of the top of each layer alti = transf.diag_misc["alti"] thickness = np.diff(alti, axis=1) dpdu = dpdu * thickness dpdd = dpdd * thickness dpeu = np.concatenate([ upfl[:, [0]] + dpdu[:, [0]], upfl[:, 1:] - upfl[:, :-1] + dpdu[:, 1:], ], axis=1) dped = np.concatenate([ dwfl[:, 1:] - dwfl[:, :-1] + dpdd[:, :-1], -dwfl[:, [-1]] + dpdd[:, [-1]] ], axis=1) # Put back to datastore inout_datastore["outputs"][("meteo", "dpdu")][ddi]["spec"] = \ 0. * upfl + np.maximum(0, dpdu) inout_datastore["outputs"][("meteo", "dpdd")][ddi]["spec"] = \ 0. * upfl + np.maximum(0, dpdd) inout_datastore["outputs"][("meteo", "dpeu")][ddi]["spec"] = \ 0. * upfl + np.maximum(0, dpeu) inout_datastore["outputs"][("meteo", "dped")][ddi]["spec"] = \ 0. * upfl + np.maximum(0, dped)