示例#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_HD_set_nan( array):
    '''
    elements in 'array' which correspond to frequencies not
    analyzed are set to nan, for HD
    '''
    TK = 298  #  --------------------------------

    sosHD = bp.sumofstate_HD(TK)
    computed_HD = compute_series_para.spectra_HD( TK, OJ_HD, QJ_HD,
                                                 SJ_HD, sosHD)

    calc_298_HD = gen_intensity_mat(computed_HD, 2)
    TK = 1000  #  -------------------------------
    sosHD = bp.sumofstate_HD(TK)
    computed_HD = compute_series_para.spectra_HD( TK, OJ_HD, QJ_HD,
                                                 SJ_HD, sosHD)

    calc_600_HD=gen_intensity_mat (computed_HD, 2)
    diff_HD = calc_298_HD - calc_600_HD
    cr_HD = clean_mat(diff_HD)

    return set_nan_if_foundzero(cr_HD, 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_HD(T, Js, Jas):
    """Compute in intensities and position for rotational Raman bands of HD """

    #--- nuclear spin statistics ------------
    g_even = 1  # hydrogen deuteride
    g_odd = 1
    # ---------------------------------------

    sos = bp.sumofstate_HD(T)

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

    # Stokes lines
    for i in range(0, Js + 1):
        E = eJHDv0[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 = (eJHDv0[i + 2] - eJHDv0[i])
        gamma = ME_HD_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

        specHD[(Jas - 1) + i][0] = i
        specHD[(Jas - 1) + i][1] = position
        specHD[(Jas - 1) +
               i][2] = factor  # unnormalized intensity, arbitrary unit
        specHD[(Jas - 1) + i][3] = omega - position
        posnHD[(Jas - 1) + i] = position
        spectraHD[(Jas - 1) + i] = factor

    # Anti-Stokes lines
    i = Jas
    for i in range(Jas, 1, -1):
        E = eJHDv0[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 * (eJHDv0[i] - eJHDv0[i - 2])
        gamma = ME_HD_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

        specHD[Jas - i][0] = i
        specHD[Jas - i][1] = position
        specHD[Jas - i][2] = factor  # unnormalized intensity, arbitrary unit
        specHD[Jas - i][3] = omega - position
        posnHD[Jas - i] = position
        spectraHD[Jas - i] = factor

#   return the output
    normalize1d(spectraHD)
    specHD[:, 2] = spectraHD[:, 0]  # assign normalized intensity
    #print("Normalized spectra HD: \n", spectraHD)
    return specHD
示例#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\
           spectra. Check input expt data or the J-indices entered.')