Source code for pycif.plugins.transforms.complex.diagmet.utils.mean_z0_shf_extra_urban_temp
import pandas as pd
import numpy as np
from ......utils.check.errclass import CifError
[docs]
def mean_z0_shf_extra_urban_temp(transf, inout_datastore, ddi, mapper):
"""Apply urban heat island corrections to roughness length, sensible heat flux, and 2-m temperature.
Combines the ``LANDUSE`` land-cover fractions and the monthly ``LANDPAR``
roughness lengths into four grid-cell diagnostics — urban wind-reduction
factor ``awf``, area-weighted roughness length ``az0``, additional urban
heat-flux fraction ``auf``, and urban-corrected minimum PBL height ``pm`` —
stored in ``transf.diag_misc`` for use by later steps, and applies ``awf``
to the lowest-level winds. See
:doc:`/documentation/doc-models/chimere/diagmet` (section 4) 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.
"""
# Read LANDUSE
domain = mapper["inputs"][("meteo", "winz")]["domain"]
nlat, nlon = domain.zlat.shape
landuse = pd.read_csv(
transf.file_landuse, header=None, sep=r"\s+"
).values
if landuse.size != nlat * nlon * 9:
raise CifError(f"Warning: The landuse file in file {transf.file_landuse} has not the expected shape ({nlat}/{nlon}). Make sure the LANDUSE file matches the domain")
fland = np.transpose(landuse.reshape((nlat, nlon, 9)), axes=(2, 0, 1))
# Read LANDPAR
zom = pd.read_csv(transf.file_landpar, sep=r"\s+", index_col=0)
# Parameter
pblmin = transf.pblmin
# Urban corrections for wind, fluxes
uwinfac = int(not transf.uwinfac)
uflxadd = int(transf.uflxadd)
upblmin = int(transf.upblmin)
# Compute awf, az0, auf, pm
awf = fland[np.arange(9) != 4].sum(axis=0) + uwinfac * fland[4]
az0 = (fland * zom.loc[ddi.month].values[:, np.newaxis, np.newaxis]).sum(axis=0)
auf = uflxadd * fland[4]
pm = pblmin * fland[np.arange(9) != 4].sum(axis=0) + max(upblmin, pblmin) * fland[4]
# Save variables to diag_misc for use by other functions
transf.diag_misc.update({"awf": awf, "az0": az0, "auf": auf, "pm": pm})
# Correction of wind speeds
inout_datastore["outputs"][("meteo", "winm")][ddi]["spec"][:, 0] *= awf
inout_datastore["outputs"][("meteo", "winz")][ddi]["spec"][:, 0] *= awf