Esempio n. 1
0
 def __call__(self, atmosphere, **kwargs):
     if self._rh_profile is None:
         self._rh_profile = vmr2relative_humidity(
             vmr=atmosphere['H2O'][-1],
             pressure=atmosphere['plev'],
             temperature=atmosphere['T'][-1])
     return self._rh_profile
Esempio n. 2
0
 def __call__(self, atmosphere, **kwargs):
     if self._rh_profile is None:
         self._rh_profile = vmr2relative_humidity(
             vmr=atmosphere["H2O"][-1],
             pressure=atmosphere["plev"],
             temperature=atmosphere["T"][-1],
         )
     return self._rh_profile
Esempio n. 3
0
    def adjust_humidity(self, atmosphere, **kwargs):
        """Determine the humidity profile based on atmospheric state.

        Parameters:
            TODO: Write docstring.

        Returns:
            ndarray: Water vapor profile [VMR].
        """
        if self._rh_func is not None:
            rh_profile = self._rh_func(atmosphere, **kwargs)
        else:
            if self._rh_profile is None:
                self._rh_profile = vmr2relative_humidity(
                    vmr=atmosphere['H2O'][-1],
                    pressure=atmosphere['plev'],
                    temperature=atmosphere['T'][-1])
            rh_profile = self._rh_profile

        atmosphere['H2O'][-1, :] = relative_humidity2vmr(
            relative_humidity=rh_profile,
            pressure=atmosphere['plev'],
            temperature=atmosphere['T'][-1])
        self._stratosphere_coupling.adjust_stratospheric_vmr(atmosphere)
Esempio n. 4
0
    def entrain(self, T_con_adiabat, atmosphere):
        # Physical constants.
        L = constants.heat_of_vaporization
        Rv = constants.specific_gas_constant_water_vapor
        Cp = constants.isobaric_mass_heat_capacity_dry_air

        # Abbreviated variables references.
        T_rad = atmosphere["T"][0, :]
        p = atmosphere["plev"][:]
        phlev = atmosphere["phlev"][:]

        # Zero-buoyancy plume entrainment.
        k_ttl = np.max(np.where(T_con_adiabat >= T_rad))
        r_saturated = np.ones_like(p) * 0.0
        r_saturated[: k_ttl + 1] = vmr2mixing_ratio(
            saturation_pressure(T_con_adiabat[: k_ttl + 1]) / p[: k_ttl + 1]
        )
        q_saturated = r_saturated / (1 + r_saturated)
        q_saturated_hlev = interp1d(np.log(p), q_saturated, fill_value="extrapolate")(
            np.log(phlev[:-1])
        )

        z = atmosphere["z"][0, :]
        zhlev = interp1d(np.log(p), z, fill_value="extrapolate")(np.log(phlev[:-1]))
        dz_lapse = np.hstack((np.array([z[0] - zhlev[0]]), np.diff(z)))

        RH = vmr2relative_humidity(atmosphere["H2O"][0, :], p, atmosphere["T"][0, :])
        RH = np.where(RH > 1, 1, RH)

        RH_hlev = interp1d(np.log(p), RH, fill_value="extrapolate")(np.log(phlev[:-1]))

        entr = self.entr
        deltaT = np.ones_like(p) * 0.0
        k_cb = np.max(np.where(p >= 96000.0))

        # First calculate temperature deviation based on Eq. (4) in Singh&O'Gorman (2013)
        deltaT[k_cb:] = (
            1
            / (1 + L / (Rv * T_con_adiabat[k_cb:] ** 2) * L * q_saturated[k_cb:] / Cp)
            * np.cumsum(
                entr
                / zhlev[k_cb:]
                * (1 - RH_hlev[k_cb:])
                * L
                / Cp
                * q_saturated_hlev[k_cb:]
                * dz_lapse[k_cb:]
            )
        )
        # Second weight deltaT obtained from above by a height-dependent coefficient,
        # as described in Eq. (4) in Bao et al. (submitted).
        if np.any(T_con_adiabat > T_rad):
            k_ttl = np.max(np.where(T_con_adiabat > T_rad))
            z_ttl = z[k_ttl]
            z_cb = z[k_cb]

            f = lambda x: x ** (2.0 / 3.0)
            weight = f((z[k_cb : k_ttl + 1] - z_ttl) / (z_cb - z_ttl))
            deltaT[k_cb : k_ttl + 1] = deltaT[k_cb : k_ttl + 1] * weight
            deltaT[k_ttl + 1 :] = 0

        self.create_variable(
            name="entrainment_cooling",
            dims=("time", "plev"),
            data=deltaT.reshape(1, -1),
        )

        return T_con_adiabat - deltaT