コード例 #1
0
ファイル: lapserate.py プロジェクト: olemke/konrad
    def __call__(self, atmosphere):
        if self._lapse_cache is not None:
            return self._lapse_cache

        T = atmosphere['T'][0, :]
        p = atmosphere['plev'][:]
        phlev = atmosphere['phlev'][:]

        # Use short formula symbols for physical constants.
        g = constants.earth_standard_gravity
        L = constants.heat_of_vaporization
        Rd = constants.specific_gas_constant_dry_air
        Rv = constants.specific_gas_constant_water_vapor
        Cp = constants.isobaric_mass_heat_capacity_dry_air

        gamma_d = g / Cp  # dry lapse rate

        w_saturated = vmr2mixing_ratio(saturation_pressure(T) / p)

        gamma_m = (gamma_d * ((1 + (L * w_saturated) / (Rd * T)) /
                              (1 + (L**2 * w_saturated) / (Cp * Rv * T**2))
                              )
                   )
        lapse = interp1d(np.log(p), gamma_m, fill_value='extrapolate')(
            np.log(phlev[:-1]))

        if self.fixed:
            self._lapse_cache = lapse

        return lapse
コード例 #2
0
ファイル: lapserate.py プロジェクト: stella-bourdin/konrad
    def calc_lapse_rate(self, p, T):
        # Use short formula symbols for physical constants.
        g = constants.earth_standard_gravity
        L = constants.heat_of_vaporization
        Rd = constants.specific_gas_constant_dry_air
        Rv = constants.specific_gas_constant_water_vapor
        Cp = constants.isobaric_mass_heat_capacity_dry_air

        gamma_d = g / Cp  # dry lapse rate

        w_saturated = vmr2mixing_ratio(saturation_pressure(T) / p)

        gamma_m = gamma_d * ((1 + (L * w_saturated) / (Rd * T)) /
                             (1 + (L**2 * w_saturated) / (Cp * Rv * T**2)))

        return _to_p_coordinates(gamma_m, p, T)
コード例 #3
0
ファイル: entrainment.py プロジェクト: lkluft/konrad
    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