Beispiel #1
0
def invert_Se(Se, z, r):
    # Given Moist Static Energy Se [J], mixing ratio r and height z [m],
    # return Temperature T [K]
    T0 = (Se - Lv0*r - g*z)/Cpd
    def Tfind_Se(T, Se, z, r): return Se - Se_r(T, z, r)
    T = rootfinder.fzero(Tfind_Se, T0, Se, z, r)
    return T
Beispiel #2
0
def invert_theta_l(theta_l, rt, p):
    T = thermo.theta_to_T(theta_l, p)
    r_star = thermo.r_star(p, T)
    if r_star < rt:
        T0 = numpy.array([233.15, theta_l])
        T = rootfinder.fzero(Tfind, T0, p, theta_l, rt)
    return T
Beispiel #3
0
def find_Tmoist(thetaE0, press):
    """
    Calculates the temperatures along a moist adiabat.
    
    Parameters
    ----------

    thetaE0 : float
        Initial equivalent potential temperature (K).
    press : float or array_like
        Pressure (Pa).

    Returns
    -------
    Temp : float or array_like
        Temperature (K) of thetaE0 adiabat at 'press'.

    Examples
    --------
    >>> np.array([find_Tmoist(300., 8.e4)])
    array([ 271.0638])
    >>> find_Tmoist(330., 8.e4)
    283.7226584032411
    """
    Tstart = c.Tc
    try:
        brackets = rf.find_interval(thetaes_diff, Tstart, thetaE0, press)
        Temp = rf.fzero(thetaes_diff, brackets, thetaE0, press)
    except BracketError as e:
        print("couldn't find bracket: debug info: ", e.extra_info)
        Temp = np.nan
    return Temp
Beispiel #4
0
def findLCL0(wv, press0, temp0):
    """
    
    findLCL0(wv, press0, temp0)
   
    Finds the temperature and pressure at the lifting condensation
    level (LCL) of an air parcel (using a rootfinder).

    Parameters
    - - - - - -
    wv : float
         Mixing ratio (K).
    temp0 : float
           Temperature (K).
    press0: float
            pressure (Pa)

    Returns
    - - - - -
    plcl : float
        Pressure at the LCL (Pa).
    Tlcl : float
        Temperature at the LCL (K).
    
    Raises
    - - - -
    NameError
        If the air is saturated at a given wv, temp0 and press0 (i.e. Tdew(wv, press0) >= temp0)
        
    Tests
    - - - - -
    >>> Td = Tdfind(5., 9.e4)
    >>> Td > 280.
    True
    >>> findLCL0(5., 9.e4, 280.)
    Traceback (most recent call last):
        ...
    NameError: parcel is saturated at this pressure
    >>> p1, T1 =  findLCL0(0.001, 9.e4, 280.)
    >>> print T1, p1
    250.226034799 60692.0428535
    
    """
    
    
    Td = Tdfind(wv, press0)
    
    if (Td >= temp0):
        raise NameError('parcel is saturated at this pressure')
    
    theta0 = theta(temp0, press0, wv)
   
    #evalzero = lambda pguess: lclzero(pguess, wv, theta0)
    
    #will return plcl, Tlcl when Tchange returns approx. 0 
    #(i.e. when the parcel temperature = Td)
    plcl = fzero(Tchange, [1000*100, 200*100], (wv, theta0))
    Tlcl = invtheta(theta0, plcl, wv)
    
    return plcl, Tlcl
Beispiel #5
0
def invert_theta_l(theta_l, rt, p):
    T = thermo.theta_to_T(theta_l, p)
    r_star = thermo.r_star(p, T)
    if r_star < rt:
        T0 = numpy.array([233.15, theta_l])
        T = rootfinder.fzero(Tfind, T0, p, theta_l, rt)
    return T
Beispiel #6
0
def findLCL0(wv, press0, temp0):
    """
    
    findLCL0(wv, press0, temp0)
   
    Finds the temperature and pressure at the lifting condensation
    level (LCL) of an air parcel (using a rootfinder).

    Parameters
    - - - - - -
    wv : float
         Mixing ratio (K).
    temp0 : float
           Temperature (K).
    press0: float
            pressure (Pa)

    Returns
    - - - - -
    plcl : float
        Pressure at the LCL (Pa).
    Tlcl : float
        Temperature at the LCL (K).
    
    Raises
    - - - -
    NameError
        If the air is saturated at a given wv, temp0 and press0 (i.e. Tdew(wv, press0) >= temp0)
        
    Tests
    - - - - -
    >>> Td = Tdfind(5., 9.e4)
    >>> Td > 280.
    True
    >>> findLCL0(5., 9.e4, 280.)
    Traceback (most recent call last):
        ...
    NameError: parcel is saturated at this pressure
    >>> p1, T1 =  findLCL0(0.001, 9.e4, 280.)
    >>> print T1, p1
    250.226034799 60692.0428535
    
    """

    Td = Tdfind(wv, press0)

    if (Td >= temp0):
        #raise NameError('parcel is saturated at this pressure')
        return press0, temp0

    theta0 = theta(temp0, press0, wv)

    #evalzero = lambda pguess: lclzero(pguess, wv, theta0)

    #will return plcl, Tlcl when Tchange returns approx. 0
    #(i.e. when the parcel temperature = Td)
    plcl = fzero(Tchange, [1000 * 100, 200 * 100], (wv, theta0))
    Tlcl = invtheta(theta0, plcl, wv)

    return plcl, Tlcl
Beispiel #7
0
def invert_theta_l(thetal, p, rt):
    # Given Liquid Water Potential Temperature thetal [K],
    # pressure p [Pa] and total mixing ratio rt,
    # return Temperature T [K]
    T = theta_to_T(thetal, p)
    rstar = r_star(p, T)
    if r_star < rt:
        T0 = array([230., thetal])
        T = rootfinder.fzero(Tfind_thetal, p, T0, thetal, rt)
    return T
Beispiel #8
0
def tinvert_thetae(thetaeVal, rT, press):
    """
    temp,rv,rl=tinvert_thetae(thetaeVal, rT, press)

    Uses a rootfinder to determine the temperature for which the
    pseudo equivilant potential temperature (thetaepress) is equal to the
    equivilant potential temperature (thetae) of the parcel.

    Parameters
    ----------
    thetaeVal : float
        Thetae of parcel (K).
    rT : float
        Total water mixing ratio (kg/kg).
    press : float
        Pressure of parcel in (Pa).

    Returns
    -------

    theTemp : float
        Temperature for which thetaep equals the parcel thetae (K).
    rv : float
        Vapor mixing ratio of the parcel (kg/kg).
    rl : float
        liquid water mixing ratio of the parcel (kg/kg) at 'press'.

    Raises
    ------
    IOError
        If 'press' is larger than 100000 Pa.

    Examples
    --------

    >>> tinvert_thetae(300., 0.001, 8.e4)
    (278.683729619619, 0.001, 0)
    """
    if press > 1.e5:
        raise IOError('expecting pressure level less than 100000 Pa')
    # The temperature has to be somewhere between thetae
    # (T at surface) and -40 deg. C (no ice).
    Tstart = c.Tc
    brackets = rf.find_interval(find_resid_thetae, Tstart, thetaeVal, rT,
                                press)
    theTemp = rf.fzero(find_resid_thetae, brackets, thetaeVal, rT, press)
    rv, rl = find_rvrl(theTemp, rT, press)
    return theTemp, rv, rl
Beispiel #9
0
def tinvert_rsat(Tstart, rsat, press):
    """
    rootfind the temp that produces rsat at press.

    Parameters
    ----------

    temp : float
           temperature (K)

    rsat : float
           saturation mixing ratio (kg/kg)

    press : float 
            pressure (hPa)

    Returns
    -------

    Tdew : temperature (K) at with air is saaturated
    """
    brackets = rf.find_interval(find_resid_rsat, Tstart, rsat, press)
    temp = rf.fzero(find_resid_rsat, brackets, rsat, press)
    return temp