示例#1
0
def residual_cubic(param):
    '''Function which computes the residual (as sum of squares) comparing the
    ratio of expt to theoretical intensity ratio to the sensitivity  profile
    modelled as  a line, ( 1+ c1*x + c2*x**2 + c3*x**3 )

    param : T, c1, c2, c3

    '''
    TK = 298

    sosD2 = bp.sumofstate_D2(TK)
    sosHD = bp.sumofstate_HD(TK)

    computed_D2 = compute_series_para.spectra_D2(TK, OJ_D2, QJ_D2,
                                                 SJ_D2, sosD2)
    computed_HD = compute_series_para.spectra_HD(TK, OJ_HD, QJ_HD,
                                                 SJ_HD, sosHD)

    # ------ D2 ------
    trueR_D2 = gen_intensity_mat(computed_D2, 2)
    expt_D2 = gen_intensity_mat(dataD2, 0)
    I_D2 = np.divide(expt_D2, trueR_D2)
    #I_D2 = clean_mat(I_D2)
    # ----------------

    # ------ HD ------
    trueR_HD = gen_intensity_mat(computed_HD, 2)
    expt_HD = gen_intensity_mat(dataHD, 0)
    I_HD = np.divide(expt_HD, trueR_HD)
    #I_HD = clean_mat(I_HD)
    # ----------------

    # I_HD = clean_and_scale_elements(I_HD, index_HD, 2)
    # I_D2 = clean_and_scale_elements(I_D2, index_D2, 2)

    # generate the RHS : sensitivity factor
    sD2 = gen_s_cubic(computed_D2, param)
    sHD = gen_s_cubic(computed_HD, param)

    # residual matrix
    eD2 = I_D2 - sD2
    eHD = I_HD - sHD

    eD2 = np.multiply(wMat_D2, eD2)
    eHD = np.multiply(wMat_HD, eHD)

    eD2 = clean_mat(eD2)
    eHD = clean_mat(eHD)

    # E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))

    eD2[indexD2] = 0
    eHD[indexHD] = 0

    #E = np.sum(np.abs(eD2)) + np.sum(np.abs(eHD))
    E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))

    return(E)
示例#2
0
def T_independent_D2_set_nan(array):
    '''
    elements in 'array' which correspond to frequencies not
    analyzed are set to nan, for D2
    '''
    TK = 298  #  --------------------------------
    sosD2 = bp.sumofstate_D2(TK)

    computed_D2 = compute_series_para.spectra_D2( TK, OJ_D2, QJ_D2,
                                                 SJ_D2, sosD2)
    calc_298_D2 = gen_intensity_mat(computed_D2, 2)

    TK = 1000  #  -------------------------------
    sosD2 = bp.sumofstate_D2(TK)
    computed_D2 = compute_series_para.spectra_D2( TK, OJ_D2, QJ_D2,
                                                 SJ_D2, sosD2)
    calc_600_D2=gen_intensity_mat (computed_D2, 2)

    diff_D2 = calc_298_D2 - calc_600_D2
    cr_D2 = clean_mat(diff_D2)

    return set_nan_if_foundzero(cr_D2, array)
示例#3
0
def T_independent_index():

    TK = 298  #  --------------------------------
    sosD2 = bp.sumofstate_D2(TK)
    sosHD = bp.sumofstate_HD(TK)

    computed_D2 = compute_series_para.spectra_D2( TK, OJ_D2, QJ_D2,
                                                 SJ_D2, sosD2)
    computed_HD = compute_series_para.spectra_HD( TK, OJ_HD, QJ_HD,
                                                 SJ_HD, sosHD)

    calc_298_D2 = gen_intensity_mat(computed_D2, 2)
    calc_298_HD = gen_intensity_mat(computed_HD, 2)

    TK = 1000  #  -------------------------------
    sosD2 = bp.sumofstate_D2(TK)
    sosHD = bp.sumofstate_HD(TK)

    computed_D2 = compute_series_para.spectra_D2( TK, OJ_D2, QJ_D2,
                                                 SJ_D2, sosD2)
    computed_HD = compute_series_para.spectra_HD( TK, OJ_HD, QJ_HD,
                                                 SJ_HD, sosHD)

    calc_600_D2=gen_intensity_mat (computed_D2, 2)
    calc_600_HD=gen_intensity_mat (computed_HD, 2)

    diff_D2 = calc_298_D2 - calc_600_D2
    diff_HD = calc_298_HD - calc_600_HD

    cr_D2 = clean_mat(diff_D2)
    cr_HD = clean_mat(diff_HD)

    index_D2 = np.nonzero(np.abs(cr_D2) >1e-10)
    index_HD = np.nonzero(np.abs(cr_HD) >1e-10)

    return index_D2, index_HD
示例#4
0
def spectra_D2(T, Js, Jas):
    """Compute in intensities and position for rotational Raman bands of D2 """

    #--- nuclear spin statistics ------------
    g_even = 6  # deuterium
    g_odd = 3
    # ---------------------------------------

    sos = bp.sumofstate_D2(T)

    # define arrays for intensity, position and J_{i}
    specD2 = np.zeros(shape=(Js + Jas, 4))
    posnD2 = np.zeros(shape=(Js + Jas, 1))
    spectraD2 = np.zeros(shape=(Js + Jas, 1))

    # Stokes lines
    for i in range(0, Js + 1):
        E = eJD2v0[i]
        energy = (-1 * E * H * C)
        popn = (2 * i + 1) * math.exp(energy / (K * T))
        bj = (3 * (i + 1) * (i + 2)) / (2 * (2 * i + 1) * (2 * i + 3))
        position = (eJD2v0[i + 2] - eJD2v0[i])
        gamma = ME_D2_532[i + 1][2]

        if i % 2 == 0:
            factor = popn * g_even * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos
        else:
            factor = popn * g_odd * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos

        specD2[(Jas - 1) + i][0] = i
        specD2[(Jas - 1) + i][1] = position
        specD2[(Jas - 1) +
               i][2] = factor  # unnormalized intensity, arbitrary unit
        specD2[(Jas - 1) + i][3] = omega - position
        posnD2[(Jas - 1) + i] = position
        spectraD2[(Jas - 1) + i] = factor

    # Anti-Stokes lines
    i = Jas
    for i in range(Jas, 1, -1):
        E = eJD2v0[i]
        energy = (-1 * E * H * C)
        popn = (2 * i + 1) * math.exp(energy / (K * T))
        bj = (3 * (i) * (i - 1)) / (2 * (2 * i - 1) * (2 * i + 1))
        position = -1 * (eJD2v0[i] - eJD2v0[i - 2])
        gamma = ME_D2_532[i - 1][2]

        if i % 2 == 0:
            factor = popn * g_even * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos
        else:
            factor = popn * g_odd * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos

        specD2[Jas - i][0] = i
        specD2[Jas - i][1] = position
        specD2[Jas - i][2] = factor  # unnormalized intensity, arbitrary unit
        specD2[Jas - i][3] = omega - position
        posnD2[Jas - i] = position
        spectraD2[Jas - i] = factor

#   return the output
    normalize1d(spectraD2)
    specD2[:, 2] = spectraD2[:, 0]  # assign normalized intensity
    return specD2
示例#5
0
def residual_linear(param):
    '''Function which computes the residual (as sum of squares) comparing the
    ratio of expt to theoretical intensity ratio to the sensitivity  profile
    modelled as  a line, ( 1+ c1*x )

    param : T, c1

    '''

    TK = 298

    sosD2 = bp.sumofstate_D2(TK)
    sosHD = bp.sumofstate_HD(TK)

    computed_D2 = compute_series_para.spectra_D2(TK, OJ_D2, QJ_D2,
                                                 SJ_D2, sosD2)
    computed_HD = compute_series_para.spectra_HD(TK, OJ_HD, QJ_HD,
                                                 SJ_HD, sosHD)

    # ------ D2 ------
    trueR_D2 = gen_intensity_mat(computed_D2, 2)
    expt_D2 = gen_intensity_mat(dataD2, 0)
    I_D2 = np.divide(expt_D2, trueR_D2)
    #I_D2 = clean_mat(I_D2)
    # ----------------

    # ------ HD ------
    trueR_HD = gen_intensity_mat(computed_HD, 2)
    expt_HD = gen_intensity_mat(dataHD, 0)
    I_HD = np.divide(expt_HD, trueR_HD)
    #I_HD = clean_mat(I_HD)
    # ----------------

    #I_D2[indexD2] = 0
    #I_HD[indexHD] = 0

    # generate the RHS : sensitivity factor
    sD2 = gen_s_linear(computed_D2, param)
    sHD = gen_s_linear(computed_HD, param)

    # weight
    #errD2 = gen_weight(expt_D2)
    #errHD = gen_weight(expt_HD)
    #errD2 = clean_mat(errD2)
    #errD2[indexD2] = 0
    #np.savetxt("error_test", errD2, fmt='%3.3f')

    # residual matrix
    eD2 = I_D2 - sD2
    eHD = I_HD - sHD

    eD2 = np.multiply(wMat_D2, eD2)
    eHD = np.multiply(wMat_HD, eHD)

    eD2 = clean_mat(eD2)
    eHD = clean_mat(eHD)

    # E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))

    eD2[indexD2] = 0
    eHD[indexHD] = 0
    np.savetxt("errD2_test", eD2, fmt='%3.3f')
    np.savetxt("errHD_test", eHD, fmt='%3.3f')

    #E = np.sum(np.abs(eD2)) + np.sum(np.abs(eHD))
    E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))

    return(E)
示例#6
0
# ******************** CHECKS FOR INPUTS ************************
# ***************************************************************


# ------------------------------------------------

wMat_D2 = 1
wMat_HD = 1.2
wMat_H2 = 1

# checks for input done here

# generate calculated data for the entered J values
TK=299
sosD2 = bp.sumofstate_D2(TK)
sosHD = bp.sumofstate_HD(TK)
sosH2 = bp.sumofstate_H2(TK)

computed_D2 = compute_series_para.spectra_D2(TK, OJ_D2, QJ_D2, SJ_D2, sosD2)
computed_HD = compute_series_para.spectra_HD(TK, OJ_HD, QJ_HD, SJ_HD, sosHD)
computed_H2 = compute_series_para.spectra_H2_c(TK, OJ_H2, QJ_H2, sosH2)

# checks for dimension match done here
if (computed_D2.shape[0] != dataD2.shape[0]):
    print('D2 : Dimension of input data does not match with the calculated\
           spectra. Check input expt data or the J-indices entered.')
    sys.exit("\tError: Quitting.")

if (computed_HD.shape[0] != dataHD.shape[0]):
    print('H2 : Dimension of input data does not match with the calculated\
def spectra_D2(T, Js, Jas):
    """Compute in intensities and position for rotational Raman bands of D2 """

    #--- nuclear spin statistics ------------
    g_even = 6  # deuterium
    g_odd = 3
    # ---------------------------------------

    sos = bp.sumofstate_D2(T)

    # define arrays for intensity, position and J_{i}
    specD2 = np.zeros(shape=(Js + Jas, 4))
    posnD2 = np.zeros(shape=(Js + Jas, 1))
    spectraD2 = np.zeros(shape=(Js + Jas, 1))

    # Stokes lines
    for i in range(0, Js + 1):
        E = eJD2v0[i]
        energy = (-1 * E * H * C)
        popn = (2 * i + 1) * math.exp(energy / (K * T))
        bj = (3 * (i + 1) * (i + 2)) / (2 * (2 * i + 1) * (2 * i + 3))
        position = (eJD2v0[i + 2] - eJD2v0[i])
        gamma = ME_D2_532[i + 1][2]

        if i % 2 == 0:
            factor = popn * g_even * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos
        else:
            factor = popn * g_odd * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos

        specD2[(Jas - 1) + i][0] = i
        specD2[(Jas - 1) + i][1] = position
        specD2[(Jas - 1) +
               i][2] = factor  # unnormalized intensity, arbitrary unit
        specD2[(Jas - 1) + i][3] = omega - position
        posnD2[(Jas - 1) + i] = position
        spectraD2[(Jas - 1) + i] = factor

    # Anti-Stokes lines
    i = Jas
    for i in range(Jas, 1, -1):
        E = eJD2v0[i]
        energy = (-1 * E * H * C)
        popn = (2 * i + 1) * math.exp(energy / (K * T))
        bj = (3 * (i) * (i - 1)) / (2 * (2 * i - 1) * (2 * i + 1))
        position = -1 * (eJD2v0[i] - eJD2v0[i - 2])
        gamma = ME_D2_532[i - 1][2]

        if i % 2 == 0:
            factor = popn * g_even * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos
        else:
            factor = popn * g_odd * bj * omega_sc * (
                (omega_sc - position / 1e4)**3) * (gamma**2) / sos

        specD2[Jas - i][0] = i
        specD2[Jas - i][1] = position
        specD2[Jas - i][2] = factor  # unnormalized intensity, arbitrary unit
        specD2[Jas - i][3] = omega - position
        posnD2[Jas - i] = position
        spectraD2[Jas - i] = factor

#   return the output
    normalize1d(spectraD2)
    specD2[:, 2] = spectraD2[:, 0]  # assign normalized intensity
    return specD2
    #print("Normalized spectra D2 :\n", spectraD2)

    #np.savetxt('posnD2.txt', posnD2, fmt='%+6.6f') #save the band position.
    #np.savetxt('spectraD2.txt', spectraD2, fmt='%+5.11f') #save the band intensity
    #np.savetxt('specD2.txt', (specD2), fmt='%+5.12f') #save the 2D array which has data on
    #  initial J number, band position, band intensity and the position in abs. wavenumbers


#********************************************************************
#********************************************************************
#********************************************************************

#print(" Sum of state for  H2 at 333 K : ", bp.sumofstate_H2(333))

#print(" Sum of state for  HD at 375 K : ", bp.sumofstate_HD(375))

#print(" Sum of state for  D2 at 298 K : ", bp.sumofstate_D2(298))

#********************************************************************
#print ("\n")
#spectra_H2(298, 6, 6)
#print ("\n")
#spectra_HD(298, 7, 7)
#print ("\n")
#spectra_D2(298, 6, 8)

#  Spectra can  be plotted using matplotlib simply using the band posn and the spectra

#********************************************************************