def T_independent_index(): ''' Getting indices for the t-independent terms in the matrix for all three gases, index output are for the terms which do not change with temperature ''' TK = 298 # -------------------------------- sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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 ) calc_298_D2 = gen_intensity_mat(computed_D2, 2) calc_298_HD = gen_intensity_mat(computed_HD, 2) calc_298_H2 = gen_intensity_mat(computed_H2, 2) TK = 1000 # ------------------------------- sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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 ) calc_600_D2 = gen_intensity_mat (computed_D2, 2) calc_600_HD = gen_intensity_mat (computed_HD, 2) calc_600_H2 = gen_intensity_mat(computed_H2, 2) # ------------------------------------------- diff_D2 = calc_298_D2 - calc_600_D2 diff_HD = calc_298_HD - calc_600_HD diff_H2 = calc_298_H2 - calc_600_H2 cr_D2 = clean_mat(diff_D2) cr_HD = clean_mat(diff_HD) cr_H2 = clean_mat(diff_H2) # terms which are t-independet are selected here index_D2 = np.nonzero(np.abs(cr_D2) < 1e-10) index_HD = np.nonzero(np.abs(cr_HD) < 1e-10) index_H2 = np.nonzero(np.abs(cr_H2) < 1e-10) # index for t-independent terms return index_D2, index_HD , index_H2
def residual_O2S0_D2(param): '''Function which computes the residual (as sum of squares) comparing the ratio of expt with the corresponding calculated ratios. The calculated ratios are computed for given T. Param : T ''' TK = param sosD2 = compute_series_para.sumofstate_D2(TK) O1 = compute_series_para.D2_O1(TK, 2, sosD2) S1 = compute_series_para.D2_S1(TK, 0, sosD2) #print(O1,"\n",S1) O1calc = O1[0][2] S1calc = S1[0][2] r_calc = (O1calc/ S1calc) r_expt = (dataD2OS[0]/dataD2OS[1]) #print(r_calc, r_expt) diff = r_expt - r_calc return diff**2
def residual_Q_D2_234(param): '''Function which computes the residual (as sum of squares) comparing the ratio of expt with the corresponding calculated ratios. The calculated ratios are computed for given T. Param : T ''' TK = param sosD2 = compute_series_para.sumofstate_D2(TK) QJ_D2 = 4 # max J value of analyzed Q-bands computed_D2 = compute_series_para.D2_Q1(TK, QJ_D2, sosD2) # ------ D2 ------ #print(computed_D2) computed_D2=computed_D2[:-2, :] #print(computed_D2) dataD2Q = dataD2Q4[:-2, :] print(computed_D2.shape, dataD2Q.shape) trueR_D2 = gen_intensity_mat(computed_D2, 2) expt_D2 = gen_intensity_mat(dataD2Q, 0) errD2_output = gen_weight(dataD2Q) errorP = errD2_output #np.savetxt("exptD2",clean_mat(expt_D2),fmt='%2.4f') #np.savetxt("errD2",clean_mat(errorP),fmt='%2.4f') calc_D2 = clean_mat(trueR_D2) expt_D2 = clean_mat(expt_D2) errorP = clean_mat(errorP) # ---------------- diffD2 = expt_D2 - calc_D2 # scale by weights #diffD2 = (np.multiply(errorP , diffD2)) # remove redundant terms diffD2 = clean_mat(diffD2) np.savetxt("diff_D2", diffD2,fmt='%2.4f') # return the residual E=np.sum(np.square(diffD2)) return E
def residual_quintuple(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 + c4*x**4 ) param : T, c1, c2, c3, c4 ''' TK = param[0] sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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) # ------ 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) # ---------------- # ------ H2 ------ trueR_H2 = gen_intensity_mat(computed_H2, 2) expt_H2 = gen_intensity_mat(dataH2, 0) I_H2 = np.divide(expt_H2, trueR_H2) I_H2 = clean_mat(I_H2) # ---------------- # generate the RHS : sensitivity factor sD2 = gen_s_quintuple(computed_D2, param) sHD = gen_s_quintuple(computed_HD, param) sH2 = gen_s_quintuple(computed_H2, param) # residual matrix eD2 = I_D2 - sD2 eHD = I_HD - sHD eH2 = I_H2 - sH2 eD2 = np.multiply(wMat_D2, eD2) eHD = np.multiply(wMat_HD, eHD) eH2 = np.multiply(wMat_H2, eH2) eD2 = clean_mat(eD2) eHD = clean_mat(eHD) eH2 = clean_mat(eH2) # set specific rows/cols to 0 eH2[:, 1] = 0 eH2[1, :] = 0 eHD[:, 6] = 0 eHD[6, :] = 0 #E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))\ # + np.sum(np.square(eH2)) E = np.sum(np.abs(eD2)) + np.sum(np.abs(eHD)) +\ np.sum(np.abs(eH2)) #np.savetxt("errorD2_5.txt", np.abs(eD2), fmt="%4.4f", delimiter='\t') #np.savetxt("errorHD_5.txt", np.abs(eHD), fmt="%4.4f", delimiter='\t') #np.savetxt("errorH2_5.txt", np.abs(eH2), fmt="%4.4f", delimiter='\t') #E = np.sum(np.abs(eD2)) + np.sum(np.abs(eHD)) +\ # np.sum(np.abs(eH2)) return E
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 = param[0] sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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) # ------ 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) # ---------------- # ------ H2 ------ trueR_H2 = gen_intensity_mat(computed_H2, 2) expt_H2 = gen_intensity_mat(dataH2, 0) I_H2 = np.divide(expt_H2, trueR_H2) I_H2 = clean_mat(I_H2) # ---------------- # generate the RHS : sensitivity factor sD2 = gen_s_linear(computed_D2, param) sHD = gen_s_linear(computed_HD, param) sH2 = gen_s_linear(computed_H2, param) # residual matrix eD2 = I_D2 - sD2 eHD = I_HD - sHD eH2 = I_H2 - sH2 eD2 = np.multiply(wMat_D2, eD2) eHD = np.multiply(wMat_HD, eHD) eH2 = np.multiply(wMat_H2, eH2) eD2 = clean_mat(eD2) eHD = clean_mat(eHD) eH2 = clean_mat(eH2) # set specific rows/cols to 0 eH2[:, 1] = 0 eH2[1, :] = 0 eHD[:, 6] = 0 eHD[6, :] = 0 #E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))\ # + np.sum(np.square(eH2)) E = np.sum(np.abs(eD2)) + np.sum(np.abs(eHD)) +\ np.sum(np.abs(eH2)) return E
# *************************************************************** # ******************** CHECKS FOR INPUTS ************************ # *************************************************************** wMat_D2 = 1 wMat_HD = 1 wMat_H2 = 1 # checks for input done here # generate calculated data for the entered J values TK = 299 sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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 (len(computed_D2) != 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 (len(computed_HD) != dataHD.shape[0]): print('H2 : Dimension of input data does not match with the calculated\
def residual_quintuple(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 + c4*x**4 ) param : T, c1, c2, c3, c4 ''' TK = param[0] sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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) # ------ 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) # ---------------- # ------ H2 ------ trueR_H2 = gen_intensity_mat(computed_H2, 2) expt_H2 = gen_intensity_mat(dataH2, 0) I_H2 = np.divide(expt_H2, trueR_H2) I_H2 = clean_mat(I_H2) # ---------------- # generate the RHS : sensitivity factor sD2 = gen_s_quintuple(computed_D2, param) sHD = gen_s_quintuple(computed_HD, param) sH2 = gen_s_quintuple(computed_H2, param) # residual matrix eD2 = I_D2 - sD2 eHD = I_HD - sHD eH2 = I_H2 - sH2 eD2 = np.multiply(wMat_D2, eD2) eHD = np.multiply(wMat_HD, eHD) eH2 = np.multiply(wMat_H2, eH2) eD2 = clean_mat(eD2) eHD = clean_mat(eHD) eH2 = clean_mat(eH2) # E = np.sum(np.square(eD2)) + np.sum(np.square(eHD))\ # + np.sum(np.square(eH2)) index = T_independent_index() factor = 5 eD2[index[0]] = eD2[index[0]] * factor eHD[index[1]] = eHD[index[1]] * factor eH2[index[2]] = eH2[index[2]] * factor E = np.sum(np.abs(eD2)) + np.sum(np.abs(eHD)) +\ np.sum(np.abs(eH2)) return E
def residual_quartic(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 + c4*x**4 ) param : T, c1, c2, c3, c4 ''' TK = param[0] sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.sumofstate_H2(TK) computed_D2_o1s1 = compute_series_para.spectra_D2_o1s1( TK, OJ_D2, SJ_D2, sosD2) computed_D2_q1 = compute_series_para.D2_Q1(TK, QJ_D2, sosD2) computed_HD_o1s1 = compute_series_para.spectra_HD_o1s1( TK, OJ_HD, SJ_HD, sosHD) computed_HD_q1 = compute_series_para.HD_Q1(TK, QJ_HD, sosHD) computed_H2_o1 = compute_series_para.H2_O1(TK, OJ_H2, sosH2) computed_H2_q1 = compute_series_para.H2_Q1(TK, QJ_H2, sosH2) # -------------------------------------------------- # generate the matrix of ratios trueR_D2_o1s1 = gen_intensity_mat(computed_D2_o1s1, 2) expt_D2_o1s1 = gen_intensity_mat(dataD2_o1s1, 0) trueR_D2_q1 = gen_intensity_mat(computed_D2_q1, 2) expt_D2_q1 = gen_intensity_mat(dataD2_q1, 0) # -------------------------------------------------- trueR_HD_o1s1 = gen_intensity_mat(computed_HD_o1s1, 2) expt_HD_o1s1 = gen_intensity_mat(dataHD_o1s1, 0) trueR_HD_q1 = gen_intensity_mat(computed_HD_q1, 2) expt_HD_q1 = gen_intensity_mat(dataHD_q1, 0) # -------------------------------------------------- trueR_H2_o1 = gen_intensity_mat(computed_H2_o1, 2) expt_H2_o1 = gen_intensity_mat(dataH2_o1, 0) trueR_H2_q1 = gen_intensity_mat(computed_H2_q1, 2) expt_H2_q1 = gen_intensity_mat(dataH2_q1, 0) # -------------------------------------------------- # take ratio of expt to calculated I_D2_q1 = np.divide(expt_D2_q1, trueR_D2_q1) I_D2_o1s1 = np.divide(expt_D2_o1s1, trueR_D2_o1s1) I_HD_q1 = np.divide(expt_HD_q1, trueR_HD_q1) I_HD_o1s1 = np.divide(expt_HD_o1s1, trueR_HD_o1s1) I_H2_q1 = np.divide(expt_H2_q1, trueR_H2_q1) I_H2_o1 = np.divide(expt_H2_o1, trueR_H2_o1) # remove redundant elements I_D2_q1 = clean_mat(I_D2_q1) I_HD_q1 = clean_mat(I_HD_q1) I_H2_q1 = clean_mat(I_H2_q1) I_D2_o1s1 = clean_mat(I_D2_o1s1) I_HD_o1s1 = clean_mat(I_HD_o1s1) I_H2_o1 = clean_mat(I_H2_o1) # -------------------------------------------------- # generate sensitivity matrix using true data sD2_q1 = gen_s_quartic(computed_D2_q1, param) sHD_q1 = gen_s_quartic(computed_HD_q1, param) sH2_q1 = gen_s_quartic(computed_H2_q1, param) sD2_o1s1 = gen_s_quartic(computed_D2_o1s1, param) sHD_o1s1 = gen_s_quartic(computed_HD_o1s1, param) sH2_o1 = gen_s_quartic(computed_H2_o1, param) # -------------------------------------------------- eD2_q1 = (np.multiply(1, I_D2_q1) - sD2_q1) eHD_q1 = (np.multiply(1, I_HD_q1) - sHD_q1) eH2_q1 = (np.multiply(1, I_H2_q1) - sH2_q1) eD2_o1s1 = (np.multiply(weight, I_D2_o1s1) - sD2_o1s1) eHD_o1s1 = (np.multiply(weight, I_HD_o1s1) - sHD_o1s1) eH2_o1 = (np.multiply(1, I_H2_o1) - sH2_o1) # -------------------------------------------------- eD2_o1s1 = clean_mat(eD2_o1s1) eD2_q1 = clean_mat(eD2_q1) eHD_o1s1 = clean_mat(eHD_o1s1) eHD_q1 = clean_mat(eHD_q1) eH2_q1 = clean_mat(eH2_q1) eH2_o1 = clean_mat(eH2_o1) # -------------------------------------------------- E = np.sum(np.abs(eD2_q1)) + np.sum(np.abs(eHD_q1)) \ + np.sum(np.abs(eH2_q1)) + np.sum(np.abs(eD2_o1s1)) \ + np.sum(np.abs(eHD_o1s1)) + + np.sum(np.abs(eH2_o1)) return (E)
def residual_quartic_TF(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 = 299.6 sosD2 = compute_series_para.sumofstate_D2(TK) sosHD = compute_series_para.sumofstate_HD(TK) sosH2 = compute_series_para.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) # ------ 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) # ---------------- # ------ H2 ------ trueR_H2 = gen_intensity_mat(computed_H2, 2) expt_H2 = gen_intensity_mat(dataH2, 0) I_H2 = np.divide(expt_H2, trueR_H2) I_H2 = clean_mat(I_H2) # ---------------- # generate the RHS : sensitivity factor sD2 = gen_s_quartic(computed_D2, param) sHD = gen_s_quartic(computed_HD, param) sH2 = gen_s_quartic(computed_H2, param) # residual matrix eD2 = (np.multiply(wMat_D2, I_D2)) - sD2 eHD = (np.multiply(wMat_HD, I_HD)) - sHD eH2 = (np.multiply(wMat_H2, I_H2)) - sH2 # residual matrix eD2 = I_D2 - sD2 eHD = I_HD - sHD eH2 = I_H2 - sH2 eD2 = np.multiply(wMat_D2, eD2) eHD = np.multiply(wMat_HD, eHD) eH2 = np.multiply(wMat_H2, eH2) eD2 = clean_mat(eD2) eHD = clean_mat(eHD) eH2 = clean_mat(eH2) E=np.sum(np.abs(eD2)) + np.sum(np.abs(eHD)) +\ np.sum(np.abs(eH2)) return (E)