예제 #1
0
    def test_rh_spec_humidity(self):
        """Tests specific humidity -> RH calculation
        
        Starting from an RH, an atmospheric pressure and temperature,
        calculate specific humidity. Then check to see if the tested code
        can reproduce the RH we started with. 
        """
        rh = 25 * u.pct
        p = 1 * u.bar
        t = 25 * u.deg_C

        e_sat = vp.calc_vp(t)
        w_sat = m.mixing_ratio(e_sat, p)

        w = rh * w_sat  # get vapor pressure from definition of RH
        e = p * w / (m.EPSILON + w)  # mixing ratio solved for e

        # calculate specific humidity using eq 2.19
        q = m.EPSILON * (e / (p - (1 - m.EPSILON) * e))

        rh_test = m.calc_rh_spec_humidity(q, p, t)

        self.assertTrue(np.abs(rh - rh_test) < 0.1 * u.pct,
                        msg="test RH: {:3.1} ; calculated RH: {:3.1}".format(
                            rh, rh_test))
예제 #2
0
def calc_vpd(Tday, vp_act):
    """Calculate vapor pressure deficit given the measured temperature and 
    actual (modeled) vapor pressure. Returns the VPD in Pa, limited to the 
    range [0-9000Pa]."""

    vp_sat = vp.calc_vp(Tday)
    vpd = vp_sat - vp_act
    np.clip(vpd, 0 * u.Pa, 9000 * u.Pa)
    return vpd
예제 #3
0
def calc_vpd(Tday, vp_act):
    """Calculate vapor pressure deficit given the measured temperature and 
    actual (modeled) vapor pressure. Returns the VPD in Pa, limited to the 
    range [0-9000Pa]."""

    vp_sat = vp.calc_vp(Tday)
    vpd = vp_sat - vp_act
    np.clip(vpd, 0 * u.Pa, 9000 * u.Pa)
    return vpd
예제 #4
0
def calc_rh_spec_humidity(q, p, t):
    """RH is needed for the various NFDRS fuel moistures.
    
    Implements equation 2.20 (p. 17) of [1].
    
    Returns a relative humidity as a fraction 0..1, not as a percent 0..100.
    
    [1] Rogers, R. R. A Short Course in Cloud Physics, Third Edition. 
        3 edition. Oxford ; New York: Pergamon, 1989.    
    """
    e = calc_vp_spec_humidity(q, p)
    w = mixing_ratio(e, p)

    e_sat = vp.calc_vp(t)
    w_sat = mixing_ratio(e_sat, p)

    return (w / w_sat).to(u.pct)
예제 #5
0
def calc_rh_spec_humidity(q, p, t):
    """RH is needed for the various NFDRS fuel moistures.
    
    Implements equation 2.20 (p. 17) of [1].
    
    Returns a relative humidity as a fraction 0..1, not as a percent 0..100.
    
    [1] Rogers, R. R. A Short Course in Cloud Physics, Third Edition. 
        3 edition. Oxford ; New York: Pergamon, 1989.    
    """
    e = calc_vp_spec_humidity(q, p)
    w = mixing_ratio(e, p)

    e_sat = vp.calc_vp(t)
    w_sat = mixing_ratio(e_sat, p)

    return (w / w_sat).to(u.pct)
예제 #6
0
    def test_rh_spec_humidity(self) : 
        """Tests specific humidity -> RH calculation
        
        Starting from an RH, an atmospheric pressure and temperature,
        calculate specific humidity. Then check to see if the tested code
        can reproduce the RH we started with. 
        """
        rh = 25 * u.pct
        p =  1 * u.bar
        t =  25 * u.deg_C
        
        e_sat = vp.calc_vp(t)
        w_sat = m.mixing_ratio(e_sat, p)
        
        w = rh * w_sat          # get vapor pressure from definition of RH
        e = p*w/(m.EPSILON + w) # mixing ratio solved for e
        
        # calculate specific humidity using eq 2.19
        q = m.EPSILON * (e/(p-(1-m.EPSILON)*e))

        rh_test = m.calc_rh_spec_humidity(q, p, t)
        
        self.assertTrue(np.abs(rh-rh_test) < 0.1 * u.pct,
          msg="test RH: {:3.1} ; calculated RH: {:3.1}".format(rh, rh_test))