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_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] computed_D2 = compute_series_para.spectra_D2(TK, OJ_D2, QJ_D2, SJ_D2) computed_HD = compute_series_para.spectra_HD(TK, OJ_HD, QJ_HD, SJ_HD) computed_H2 = compute_series_para.spectra_H2_c(TK, OJ_H2, QJ_H2) # ------ 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) # ---------------- #I_H2 = clean_and_scale_elements(I_H2, index_H2, 2) #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_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 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)) E=np.sum(np.abs(eD2)) + np.sum(np.abs(eHD)) +\ np.sum(np.abs(eH2)) 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
# *************************************************************** 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\ spectra. Check input expt data or the J-indices entered.') sys.exit("\tError: Quitting.") if (len(computed_H2) != dataH2.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
# ******************** 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 computed_D2 = compute_series_para.spectra_D2(299, OJ_D2, QJ_D2, SJ_D2) computed_HD = compute_series_para.spectra_HD(299, OJ_HD, QJ_HD, SJ_HD) computed_H2 = compute_series_para.spectra_H2_c(299, OJ_H2, QJ_H2) # 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.') sys.exit("\tError: Quitting.") if (computed_H2.shape[0] != dataH2.shape[0]): print('H2 : Dimension of input data does not match with the calculated\
def residual_cubic_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_cubic(computed_D2, param) sHD = gen_s_cubic(computed_HD, param) sH2 = gen_s_cubic(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.abs(eD2)) + np.sum(np.abs(eHD)) +\ np.sum(np.abs(eH2)) return (E)