Beispiel #1
0
def alpha(freq,
          T,
          P,
          X,
          X_dict,
          otherPar,
          units='dBperkm',
          path='./',
          verbose=False):
    """Piece-wise quadratic frequency interpolation and extrapolation to orton_H2.tables.
       Interpolation in T is interptype ('cubic')
       Extrapolation in T is based on:
           down = nexp (=4) extrapolation in Temperature
           up = h2_jj matched at the nearest tabulated point.
               freq is a list of frequencies (must be a list)
               T and P are scalars in K and bars
               X is a list of the mixing ratios constituents at X_dict
               otherPar['h2state'] = 'e' or 'n' (h2states)
               Units either 'dBperkm' or 'invcm'
               Need to have otherPar['newset']=True whenever the frequencies change"""

    newset = otherPar['h2newset']
    h2state = otherPar['h2state']
    interpType = 'cubic'

    if len(Ttab) == 0 or newset:
        readInputFiles(freq, path, verbose)

    h2state = h2state.lower()
    P_h2 = P * X[X_dict['H2']]
    P_he = P * X[X_dict['HE']]
    try:
        P_ch4 = P * X[X_dict['CH4']]
    except keyError:
        P_ch4 = 0.0

    alpha_h2 = []
    if T < Ttab[0]:  ### extrapolate down in T with quartic
        nearest = 0
        nexp = 4.0
        indi = [nearest, nearest + 1]
        X1 = Ttab[indi[0]]
        X21n = Ttab[indi[1]]**nexp - Ttab[indi[0]]**nexp
        for ii in range(len(freq)):
            v = []
            for jj in indi:
                Tjj = Ttab[jj]
                #h2-h2
                xx = h2tableList['eh2h2'] + h2stateList[h2state]
                ah2near = h2vab[xx, ii, jj]
                #h2-he
                xx = h2tableList['eh2he'] + h2stateList[h2state]
                ahenear = h2vab[xx, ii, jj]
                #h2-ch4
                xx = h2tableList['eh2ch4'] + h2stateList[h2state]
                ach4near = h2vab[xx, ii, jj]
                #total
                a = (P_h2 / atm2bar) * (
                    ah2near * P_h2 / atm2bar + ahenear * P_he / atm2bar +
                    ach4near * P_ch4 / atm2bar) * (T0 / Tjj)**2
                v.append(a)
            Y1 = v[indi[0]]
            Y21 = v[indi[1]] - v[indi[0]]
            AQ = -1.0 * Y21 / X21n
            CQ = Y1 + AQ * (X1**nexp)
            a = CQ - AQ * (T**nexp)
            alpha_h2.append(a)
    elif T > Ttab[-1]:  ### extrapolate up in T using Joiner
        nearest = -1
        Tnear = Ttab[nearest]
        jjnear = h2_jj.alpha(freq, Tnear, P, X, X_dict, otherPar)
        jj = h2_jj.alpha(freq, T, P, X, X_dict, otherPar)
        for ii in range(len(freq)):
            #h2-h2
            xx = h2tableList['eh2h2'] + h2stateList[h2state]
            ah2near = h2vab[xx, ii, nearest]
            #h2-he
            xx = h2tableList['eh2he'] + h2stateList[h2state]
            ahenear = h2vab[xx, ii, nearest]
            #h2-ch4
            xx = h2tableList['eh2ch4'] + h2stateList[h2state]
            ach4near = h2vab[xx, ii, nearest]
            #total
            anear = (P_h2 / atm2bar) * (
                ah2near * P_h2 / atm2bar + ahenear * P_he / atm2bar +
                ach4near * P_ch4 / atm2bar) * (T0 / Tnear)**2
            a = jj[ii] * (anear / jjnear[ii])
            alpha_h2.append(a)
    else:  ### within range of Orton's tables
        for ii in range(len(freq)):
            #h2-h2
            xx = h2tableList['eh2h2'] + h2stateList[h2state]
            fv = interp1d(Ttab, h2vab[xx, ii], kind=interpType)
            ah2 = fv(T)
            #h2-he
            xx = h2tableList['eh2he'] + h2stateList[h2state]
            fv = interp1d(Ttab, h2vab[xx, ii], kind=interpType)
            ahe = fv(T)
            #h2-ch4
            xx = h2tableList['eh2ch4'] + h2stateList[h2state]
            fv = interp1d(Ttab, h2vab[xx, ii], kind=interpType)
            ach4 = fv(T)
            #total
            a = (P_h2 / atm2bar) * (ah2 * P_h2 / atm2bar + ahe * P_he / atm2bar
                                    + ach4 * P_ch4 / atm2bar) * (T0 / T)**2
            alpha_h2.append(a)

    if units == 'dBperkm':
        for ii, a in enumerate(alpha_h2):
            alpha_h2[ii] = a * 434294.5
    elif units != 'invcm':
        print 'Assuming units are in invcm...not ' + units

    return alpha_h2
Beispiel #2
0
def alpha(freq,T,P,X,X_dict,otherPar,units='dBperkm',path='./',verbose=False):
    """Piece-wise quadratic frequency interpolation and extrapolation to orton_H2.tables.
       Interpolation in T is interptype ('cubic')
       Extrapolation in T is based on:
           down = nexp (=4) extrapolation in Temperature
           up = h2_jj matched at the nearest tabulated point.
               freq is a list of frequencies (must be a list)
               T and P are scalars in K and bars
               X is a list of the mixing ratios constituents at X_dict
               otherPar['h2state'] = 'e' or 'n' (h2states)
               Units either 'dBperkm' or 'invcm'
               Need to have otherPar['newset']=True whenever the frequencies change"""

    newset = otherPar['h2newset']
    h2state = otherPar['h2state']
    interpType = 'cubic'
    
    if len(Ttab)==0 or newset:
        readInputFiles(freq,path,verbose)

    h2state = h2state.lower()
    P_h2 = P*X[X_dict['H2']]
    P_he = P*X[X_dict['HE']]
    try:
        P_ch4 = P*X[X_dict['CH4']]
    except keyError:
        P_ch4 = 0.0

    alpha_h2 = []
    if T < Ttab[0]:        ### extrapolate down in T with quartic
        nearest = 0
        nexp = 4.0
        indi = [nearest,nearest+1]
        X1  = Ttab[indi[0]]
        X21n= Ttab[indi[1]]**nexp - Ttab[indi[0]]**nexp
        for ii in range(len(freq)):
            v = []
            for jj in indi:
                Tjj = Ttab[jj]
                #h2-h2
                xx = h2tableList['eh2h2'] + h2stateList[h2state]
                ah2near = h2vab[xx,ii,jj]
                #h2-he
                xx = h2tableList['eh2he'] + h2stateList[h2state]
                ahenear = h2vab[xx,ii,jj]
                #h2-ch4
                xx = h2tableList['eh2ch4'] + h2stateList[h2state]
                ach4near = h2vab[xx,ii,jj]
                #total
                a = (P_h2/atm2bar)*(ah2near*P_h2/atm2bar + ahenear*P_he/atm2bar + ach4near*P_ch4/atm2bar)*(T0/Tjj)**2
                v.append(a)
            Y1  = v[indi[0]]
            Y21 = v[indi[1]] - v[indi[0]]
            AQ = -1.0*Y21/X21n
            CQ = Y1 + AQ*(X1**nexp)
            a = CQ - AQ*(T**nexp)
            alpha_h2.append(a)   
    elif T > Ttab[-1]:     ### extrapolate up in T using Joiner
        nearest = -1
        Tnear = Ttab[nearest]
        jjnear = h2_jj.alpha(freq,Tnear,P,X,X_dict)
        jj = h2_jj.alpha(freq,T,P,X,X_dict)
        for ii in range(len(freq)):
            #h2-h2
            xx = h2tableList['eh2h2'] + h2stateList[h2state]
            ah2near = h2vab[xx,ii,nearest]
            #h2-he
            xx = h2tableList['eh2he'] + h2stateList[h2state]
            ahenear = h2vab[xx,ii,nearest]
            #h2-ch4
            xx = h2tableList['eh2ch4'] + h2stateList[h2state]
            ach4near = h2vab[xx,ii,nearest]
            #total
            anear = (P_h2/atm2bar)*(ah2near*P_h2/atm2bar + ahenear*P_he/atm2bar + ach4near*P_ch4/atm2bar)*(T0/Tnear)**2
            a = jj[ii]*(anear/jjnear[ii])
            alpha_h2.append(a)
    else:                     ### within range of Orton's tables
        for ii in range(len(freq)):
            #h2-h2
            xx = h2tableList['eh2h2'] + h2stateList[h2state]
            fv = interp1d(Ttab,h2vab[xx,ii],kind=interpType)
            ah2 = fv(T)
            #h2-he
            xx = h2tableList['eh2he'] + h2stateList[h2state]
            fv = interp1d(Ttab,h2vab[xx,ii],kind=interpType)
            ahe = fv(T)
            #h2-ch4
            xx = h2tableList['eh2ch4'] + h2stateList[h2state]
            fv = interp1d(Ttab,h2vab[xx,ii],kind=interpType)
            ach4 = fv(T)
            #total
            a = (P_h2/atm2bar)*(ah2*P_h2/atm2bar + ahe*P_he/atm2bar + ach4*P_ch4/atm2bar)*(T0/T)**2
            alpha_h2.append(a)
            
    if units=='dBperkm':
        for ii,a in enumerate(alpha_h2):
            alpha_h2[ii] = a*434294.5
    elif units != 'invcm':
        print 'Assuming units are in invcm...not '+units

        
    return alpha_h2
Beispiel #3
0
JJCMP = True
if JJCMP:
    plt.figure(100)
    f = []
    for i in range(300):
        f.append(float(i)/3.0+0.1)
    P = 10.0
    X_ch4 = 3.3E-5
    X_he = 0.1
    X_h2 = 1.0 - (X_ch4+X_he)
    X_dict={'H2':0,'HE':1,'CH4':2}
    X=[X_h2,X_he,X_ch4]

    Tease = [30.0,100.0,300.0,600.0]
    for T in Tease:
        a = h2_jj.alpha(f,T,P,X,X_dict)
        s = 'joiner %.0f K' % (T)
        plt.semilogy(f,a,'--',label=s)
        if T==Tease[0]:
            otherPar['newset'] = True
        else:
            otherPar['newset'] = False
        a = h2_orton.alpha(f,T,P,X,X_dict,otherPar,verbose=verbosity)
        s = 'orton (e) %.0f K' % (T)
        plt.semilogy(f,a,label=s)
        a = h2_orton.alpha(f,T,P,X,X_dict,otherPar,verbose=verbosity)
        s = 'orton (n) %.0f K' % (T)
        plt.semilogy(f,a)

    ##import h2_orton_linear
    ##a = h2_orton_linear.alpha(f,T,P,X,X_dict,h2_state='e',newset=True,verbose=verbosity)