import xarray as xr
from .utils.uv_rotation import uv_rotation
from .utils.altipres import altipres
from .utils.checkcfl import checkcfl
from .utils.vertical_turbulent_diffusivity import vertical_turbulent_diffusivity
from .utils.convection import convection
from .utils.boundary_layer_height import boundary_layer_height
from .utils.mean_z0_shf_extra_urban_temp import mean_z0_shf_extra_urban_temp
from .utils.friction_velocity import friction_velocity
from .utils.sv_heat_flux import sv_heat_flux
from .utils.obukov_length import obukov_length
from .utils.low_cloud_top import low_cloud_top
from .utils.defcolumn import defcolumn
from .utils.precipitations import precipitations
from .utils.cloud_optical_thickness import cloud_optical_thickness
[docs]
def forward(
transf,
inout_datastore,
controlvect,
obsvect,
mapper,
di,
df,
mode,
runsubdir,
workdir,
onlyinit=False,
**kwargs
):
"""Run the full DIAGMET meteorological processing pipeline.
Executes the following steps in order, each implemented in a dedicated
utility module under ``utils/``:
1. **altipres** — pressure at level mid-points, altitudes, air density.
2. **defcolumn** — interpolation of 3-D fields to the surface level.
3. **uv_rotation** — rotation of u/v wind components to the model grid.
4. **mean_z0_shf_extra_urban_temp** — urban heat island correction to
roughness length and sensible heat flux.
5. **sv_heat_flux** — sensible and virtual heat fluxes.
6. **friction_velocity** — friction velocity :math:`u^*` (Ustar).
7. **boundary_layer_height** — PBL height.
8. **checkcfl** — CFL condition check and wind-speed limiting.
9. **low_cloud_top** — low cloud top pressure.
10. **obukov_length** — Obukhov length :math:`L`.
11. **vertical_turbulent_diffusivity** — turbulent diffusion coefficient
:math:`K_{zz}` at CHIMERE layer tops.
12. **convection** — convective mass fluxes.
13. **precipitations** — total precipitation (convective + large-scale).
14. **cloud_optical_thickness** — cloud optical depth.
A temporary ``transf.diag_misc`` dict is created at entry and deleted
at exit to allow intermediate fields to be passed between steps.
Args:
transf (Plugin): diagmet transform instance.
inout_datastore (dict): mutable datastore; ``'inputs'`` provides the
raw ECMWF fields; ``'outputs'`` receives the derived CHIMERE
meteorological fields.
controlvect: unused.
obsvect: unused.
mapper (dict): transform mapper.
di (datetime): sub-simulation start date.
df (datetime): sub-simulation end date.
mode (str): ``'fwd'`` (adjoint is a no-op for diagmet).
runsubdir (str): unused.
workdir (str): unused.
onlyinit (bool): unused.
**kwargs: forwarded to each utility function.
"""
ddi = min(di, df)
# Initialize diag_misc to allow propagation of temporary variables
# from one function to the other
transf.diag_misc = {}
# Directly transfer variables if output in input
for trid in mapper["outputs"]:
if trid in inout_datastore["inputs"]:
inout_datastore["outputs"][trid][ddi] = \
inout_datastore["inputs"][trid][ddi]
# Compute pressure, altitudes
altipres(transf, inout_datastore, ddi, mapper)
# Interpolate variables to surface
defcolumn(transf, inout_datastore, ddi, mapper)
# Do u/v rotation
uv_rotation(transf, inout_datastore, ddi, mapper)
# Correction by urban heat
mean_z0_shf_extra_urban_temp(transf, inout_datastore, ddi, mapper)
# SV heat flux
sv_heat_flux(transf, inout_datastore, ddi, mapper)
# Compute ustar
friction_velocity(transf, inout_datastore, ddi, mapper)
# Boundary layer height
boundary_layer_height(transf, inout_datastore, ddi, mapper)
# Check CFL conditions
checkcfl(transf, inout_datastore, ddi, mapper)
# Low cloud top
low_cloud_top(transf, inout_datastore, ddi, mapper)
# Obukov length
obukov_length(transf, inout_datastore, ddi, mapper)
# Vertical turbulent diffusivity at top CHIMERE layers
vertical_turbulent_diffusivity(transf, inout_datastore, ddi, mapper)
# Convection
convection(transf, inout_datastore, ddi, mapper)
# Precipatation
precipitations(transf, inout_datastore, ddi, mapper)
# Cloud optical thickness
cloud_optical_thickness(transf, inout_datastore, ddi, mapper)
# Remove diag_misc from memory
del transf.diag_misc