def test_id16(filename_ebs_np,filename_hb_np,plot_spectrum=True,plot_mode=False): if plot_spectrum: af_hb = CompactAFReader.initialize_from_file(filename_hb_np) x_hb = np.arange(af_hb.number_modes()) y_hb = np.cumsum(np.abs(af_hb.occupation_array())) plt.plot(x_hb,y_hb,label="High Beta") af_ebs = CompactAFReader.initialize_from_file(filename_ebs_np) x_ebs = np.arange(af_ebs.number_modes()) y_ebs = np.cumsum(np.abs(af_ebs.occupation_array())) # y_fit_coeff = np.polyfit(x_ebs, np.log(y_ebs), 1, w=np.sqrt(y_ebs)) # print(y_fit_coeff) # y_fit = np.exp(y_fit_coeff[1]) * np.exp(y_fit_coeff[0] * x_ebs) plt.plot(x_ebs,y_ebs,label="EBS") plt.xlabel("Mode index") plt.ylabel("Cumulated occupation") ax = plt.subplot(111) ax.legend(bbox_to_anchor=None) plt.show() if plot_mode: af_hb = CompactAFReader.initialize_from_file(filename_hb_h5) plot_image(np.abs(af_hb.mode(10)),title=filename_hb_h5)
def test_compare_h5_np(filename_h5,filename_np,do_plot_CSD=False): af1 = CompactAFReader.initialize_from_file(filename_h5) # # af2 = CompactAFReader.initialize_from_file(filename_np) test_equal(af1,af2) tic() for i in range(af1.number_modes()): print(i,af1.mode(i).sum()) toc() print(af1.info()) tic() for i in range(af2.number_modes()): print(i,af2.mode(i).sum()) toc() # Cross spectral density Wx1x2,Wy1y2 = af2.CSD_in_one_dimension(mode_index_max=None) if do_plot_CSD: plot_image(np.abs(Wx1x2),1e6*af2.x_coordinates(),1e6*af2.x_coordinates(),show=False,title="Wx1x2") plot_image(np.abs(Wy1y2),1e6*af2.y_coordinates(),1e6*af2.y_coordinates(),show=True,title="Wy1y2")
def test_compare_h5_np(filename_h5, filename_np, do_plot_CSD=False): af1 = CompactAFReader.initialize_from_file(filename_h5) # # af2 = CompactAFReader.initialize_from_file(filename_np) test_equal(af1, af2) tic() for i in range(af1.number_modes()): print(i, af1.mode(i).sum()) toc() print(af1.info()) tic() for i in range(af2.number_modes()): print(i, af2.mode(i).sum()) toc() # Cross spectral density Wx1x2, Wy1y2 = af2.CSD_in_one_dimension(mode_index_max=None) if do_plot_CSD: plot_image(np.abs(Wx1x2), 1e6 * af2.x_coordinates(), 1e6 * af2.x_coordinates(), show=False, title="Wx1x2") plot_image(np.abs(Wy1y2), 1e6 * af2.y_coordinates(), 1e6 * af2.y_coordinates(), show=True, title="Wy1y2")
def test_id16(filename_ebs_np, filename_hb_np, plot_spectrum=True, plot_mode=False): if plot_spectrum: af_hb = CompactAFReader.initialize_from_file(filename_hb_np) x_hb = np.arange(af_hb.number_modes()) y_hb = np.cumsum(np.abs(af_hb.occupation_array())) plt.plot(x_hb, y_hb, label="High Beta") af_ebs = CompactAFReader.initialize_from_file(filename_ebs_np) x_ebs = np.arange(af_ebs.number_modes()) y_ebs = np.cumsum(np.abs(af_ebs.occupation_array())) # y_fit_coeff = np.polyfit(x_ebs, np.log(y_ebs), 1, w=np.sqrt(y_ebs)) # print(y_fit_coeff) # y_fit = np.exp(y_fit_coeff[1]) * np.exp(y_fit_coeff[0] * x_ebs) plt.plot(x_ebs, y_ebs, label="EBS") plt.xlabel("Mode index") plt.ylabel("Cumulated occupation") ax = plt.subplot(111) ax.legend(bbox_to_anchor=None) plt.show() if plot_mode: af_hb = CompactAFReader.initialize_from_file(filename_hb_h5) plot_image(np.abs(af_hb.mode(10)), title=filename_hb_h5)
def up_to_mode(files,titles,thresholds=[0.95,0.75,0.50]): for i,file in enumerate(files): af = CompactAFReader.initialize_from_file(file) x_ebs = np.arange(af.number_modes()) y_ebs = np.cumsum(np.abs(af.occupation_array())) print("\n>>>>>>>>>>>>>>>>: ",titles[i]) for threshold in thresholds: # threshold = 0.95O i_good = np.where(y_ebs > threshold) print(">>>>>>>>>>>>>>>> mode up to %d percent: %d"%(threshold*100, x_ebs[i_good[0][0]])) plt.plot(x_ebs,y_ebs,label=titles[i]) filename = "cumulated_occupation_%s.dat"%(titles[i]) f = open(filename,'w') for j,x in enumerate(x_ebs): f.write("%g %g\n"%(x,y_ebs[j])) f.close() print("File written to disk: %s"%filename) ax = plt.subplot(111) ax.legend(bbox_to_anchor=None) plt.ylabel("Cumulated occupation") plt.xlabel("Mode index") plt.savefig("cumulated_occupation.eps") plt.show()
def read_file(self): self.setStatusMessage("") filename = self.le_beam_file_name.text() try: if congruence.checkFileName(filename): # # just in case old file is open # try: # self.af.close_h5_file() # except: # pass try: self.af = CompactAFReader.initialize_from_file(filename) self._input_available = True self.write_std_out(self.af.info(list_modes=False)) self.main_tabs.setCurrentIndex(1) self.initialize_tabs() self.send("COMSYL modes", self.af) except: raise FileExistsError( "Error loading COMSYL modes from file: %s" % filename) except: raise Exception("Failed to read file %s" % filename)
def read_file(self): self.setStatusMessage("") filename = self.le_beam_file_name.text() if not os.path.exists(filename): raise Exception("File not found %s" % filename) try: if congruence.checkFileName(filename): try: self.af = CompactAFReader.initialize_from_file(filename) except: raise FileExistsError( "Error loading COMSYL modes from file: %s" % filename) except: raise Exception("Failed to read file %s" % filename) self.send("COMSYL modes", self.af)
def find_ebs_file_among_all_u18_2m(): path = "/scisoft/users/glass/Documents/sources/Orange-SRW/comsyl/calculations/" list = [ "cd_01_u18_2m_s1.4.npy", "cd_01_u18_2m_s2.0.npy", "cd_01_u18_2m_s2.5.npy", "cd_01_u18_2m_s3.0.npy", "cd_01_u18_2m_s3.5.npy", "cd_05_u18_2m_s2.0.npy", "cd_05_u18_2m_s2.5.npy", "cd_05_u18_2m_s3.0.npy", "cd_05_u18_2m_s3.5.npy", "cd_12_u18_2m_s2.0.npy", "cd_12_u18_2m_s2.5.npy", "cd_12_u18_2m_s3.0.npy", "cd_12_u18_2m_s3.5.npy", "cd_16_u18_2m_s2.0.npy", "cd_16_u18_2m_s2.5.npy", "cd_16_u18_2m_s3.0.npy", "cd_16_u18_2m_s3.5.npy", "cd_1_u18_2m_s2.0.npy", "cd_1_u18_2m_s2.5.npy", "cd_1_u18_2m_s3.0.npy", "cd_1_u18_2m_s3.5.npy", "cd_20_u18_2m_s2.0.npy", "cd_20_u18_2m_s2.5.npy", "cd_20_u18_2m_s3.0.npy", "cd_20_u18_2m_s3.5.npy", "cd_24_u18_2m_s2.0.npy", "cd_24_u18_2m_s2.5.npy", "cd_24_u18_2m_s3.0.npy", "cd_24_u18_2m_s3.5.npy", "cd_28_u18_2m_s2.0.npy", "cd_28_u18_2m_s2.5.npy", "cd_28_u18_2m_s3.0.npy", "cd_28_u18_2m_s3.5.npy", "cd_4_u18_2m_s2.0.npy", "cd_4_u18_2m_s2.5.npy", "cd_4_u18_2m_s3.0.npy", "cd_4_u18_2m_s3.5.npy", "cd_8_u18_2m_s2.0.npy", "cd_8_u18_2m_s2.5.npy", "cd_8_u18_2m_s3.0.npy", "cd_8_u18_2m_s3.5.npy", "cdt_01_u18_2m_s2.0.npy", "cdt_01_u18_2m_s2.5.npy", "cdt_01_u18_2m_s3.0.npy", "cdt_01_u18_2m_s3.5.npy", "cdt_05_u18_2m_s2.0.npy", "cdt_05_u18_2m_s2.5.npy", "cdt_05_u18_2m_s3.0.npy", "cdt_05_u18_2m_s3.5.npy", "cdt_12_u18_2m_s2.0.npy", "cdt_12_u18_2m_s2.5.npy", "cdt_12_u18_2m_s3.0.npy", "cdt_12_u18_2m_s3.5.npy", "cdt_16_u18_2m_s2.0.npy", "cdt_16_u18_2m_s2.5.npy", "cdt_16_u18_2m_s3.0.npy", "cdt_16_u18_2m_s3.5.npy", "cdt_1_u18_2m_s2.0.npy", "cdt_1_u18_2m_s2.5.npy", "cdt_1_u18_2m_s3.0.npy", "cdt_1_u18_2m_s3.5.npy", "cdt_20_u18_2m_s2.0.npy", "cdt_20_u18_2m_s2.5.npy", "cdt_20_u18_2m_s3.0.npy", "cdt_20_u18_2m_s3.5.npy", "cdt_24_u18_2m_s2.0.npy", "cdt_24_u18_2m_s2.5.npy", "cdt_24_u18_2m_s3.0.npy", "cdt_24_u18_2m_s3.5.npy", "cdt_28_u18_2m_s2.0.npy", "cdt_28_u18_2m_s2.5.npy", "cdt_28_u18_2m_s3.0.npy", "cdt_28_u18_2m_s3.5.npy", "cdt_4_u18_2m_s2.0.npy", "cdt_4_u18_2m_s2.5.npy", "cdt_4_u18_2m_s3.0.npy", "cdt_4_u18_2m_s3.5.npy", "cdt_8_u18_2m_s2.0.npy", "cdt_8_u18_2m_s2.5.npy", "cdt_8_u18_2m_s3.0.npy", "cdt_8_u18_2m_s3.5.npy", "cl_high_beta_u18_2m_1h_s1.4.npy", "cl_high_beta_u18_2m_1h_s1.5.npy", "cl_high_beta_u18_2m_1h_s1.6.npy", "cl_high_beta_u18_2m_1h_s1.7.npy", "cl_high_beta_u18_2m_1h_s1.8.npy", "cl_high_beta_u18_2m_1h_s1.9.npy", "cl_high_beta_u18_2m_1h_s2.0.npy", "cl_low_beta_u18_2m_1h_s6.5.npy", "cm_delta_u18_2m_1h_matrix_s0.5.npy", "cm_delta_u18_2m_1h_matrix_s1.0.npy", "cm_delta_u18_2m_1h_matrix_s1.5.npy", "cm_delta_u18_2m_1h_matrix_s2.0.npy", "cm_delta_u18_2m_1h_tsnc_s1.0.npy", "cm_delta_u18_2m_1h_tsnc_s2.0.npy", "cm_delta_u18_2m_1h_tsnc_s3.0.npy", "cm_delta_u18_2m_1h_tsnc_s4.0.npy", "cm_delta_u18_2m_1h_ts_s1.0.npy", "cm_delta_u18_2m_1h_ts_s2.0.npy", "cm_delta_u18_2m_1h_ts_s3.0.npy", "cm_delta_u18_2m_1h_ts_s4.0.npy", "cm_delta_u18_2m_1h_ts_s5.0.npy", "cm_delta_u18_2m_1h_ts_s6.0.npy", "cm_delta_u18_2m_1h_ts_s7.0.npy", "cm_delta_u18_2m_1h_ts_s8.0.npy", "cm_new_alpha_u18_2m_1h_matrix_s1.5.npy", "cm_new_alpha_u18_2m_1h_tsnc_s1.5.npy", "cm_new_alpha_u18_2m_1h_tsnc_s2.5.npy", "cm_new_res_u18_2m_1h_matrix_s2.5.npy", "cm_new_res_u18_2m_1h_tsnc_s2.5.npy", "cm_new_res_u18_2m_1h_ts_s2.5.npy", "cm_new_u18_2m_1h_matrix_s2.5.npy", "cm_new_u18_2m_1h_ts_s2.5.npy", "cp_new_u18_2m_1h_ts_s2.5.npy", "cs_new_alpha_u18_2m_1h_s1.8.npy", "cs_new_u18_2m_1h_s2.5.npy", "cu_new_u18_2m_1h_s1.0.npy", "cu_new_u18_2m_1h_s1.5.npy", "cu_new_u18_2m_1h_s2.0.npy", "cu_new_u18_2m_1h_s2.5.npy", "cu_new_u18_2m_1h_s3.0.npy", "cu_new_u18_2m_1h_s3.5.npy", "cu_new_u18_2m_1h_s4.0.npy", "cu_new_u18_2m_3h_s1.0.npy", "cu_new_u18_2m_3h_s1.5.npy", "cu_new_u18_2m_3h_s2.0.npy", "cu_new_u18_2m_3h_s2.5.npy", "cu_new_u18_2m_3h_s3.0.npy", "cu_new_u18_2m_3h_s3.5.npy", "cu_new_u18_2m_3h_s4.0.npy", "cu_new_u18_2m_5h_s0.2.npy", "cu_new_u18_2m_5h_s0.4.npy", "cu_new_u18_2m_5h_s0.6.npy", "cu_new_u18_2m_5h_s0.8.npy", "cu_new_u18_2m_5h_s1.0.npy", "cu_new_u18_2m_5h_s1.2.npy", "cu_new_u18_2m_5h_s1.4.npy", "cu_new_u18_2m_5h_s1.6.npy", "delta_u18_2m_1h_s1.0.npy", "delta_u18_2m_1h_s2.0.npy", "delta_u18_2m_1h_s3.0.npy", "delta_u18_2m_1h_s4.0.npy", "delta_u18_2m_1h_s5.0.npy", "gel_01_u18_2m_s2.5.npy", "gel_05_u18_2m_s2.5.npy", "gel_12_u18_2m_s2.5.npy", "gel_16_u18_2m_s2.5.npy", "gel_1_u18_2m_s2.5.npy", "gel_20_u18_2m_s2.5.npy", "gel_4_u18_2m_s2.5.npy", "gel_8_u18_2m_s2.5.npy", "gel_big2_u18_2m_s1.0.npy", "gel_big_u18_2m_s1.0.npy", "hf_new_u18_2m_1h_s0.5.npy", "hf_new_u18_2m_1h_s1.0.npy", "hf_new_u18_2m_1h_s1.5.npy", "hf_new_u18_2m_1h_s2.0.npy", "hf_new_u18_2m_1h_s2.5.npy", "hf_new_u18_2m_1h_s3.0.npy", "hf_new_u18_2m_1h_s3.5.npy", "hf_new_u18_2m_1h_s4.0.npy", "hf_new_u18_2m_3h_s1.0.npy", "hf_new_u18_2m_3h_s1.5.npy", "hf_new_u18_2m_3h_s2.0.npy", "hf_new_u18_2m_3h_s2.5.npy", "hf_new_u18_2m_3h_s3.0.npy", "hf_new_u18_2m_3h_s3.5.npy", "hf_new_u18_2m_3h_s4.0.npy", "low_beta_res_u18_2m_1h_ts_s4.5.npy", "low_beta_res_u18_2m_1h_ts_s5.0.npy", "low_beta_res_u18_2m_1h_ts_s5.1.npy", "low_beta_res_u18_2m_1h_ts_s6.0.npy", "low_beta_res_u18_2m_1h_ts_s6.5.npy", "low_beta_res_u18_2m_1h_ts_s8.0.npy", "new_res_u18_2m_1h_matrix_s2.0.npy", "new_res_u18_2m_1h_matrix_s2.5.npy", "new_res_u18_2m_1h_tsnc_s2.0.npy", "new_res_u18_2m_1h_ts_s2.0.npy", "new_res_u18_2m_1h_ts_s2.5.npy", "new_u18_2m_1h_matrix_s2.0.npy", "new_u18_2m_1h_s0.1.npy", "new_u18_2m_1h_s1.0.npy", "new_u18_2m_1h_ts_s2.0.npy", "ns_cl_high_beta_u18_2m_1h_s1.6.npy", "test_cm_new_u18_2m_1h_ts_s2.5.npy",] for file in list: print("%s"%file) af = CompactAFReader.initialize_from_file(path+"/"+file) y_ebs = np.cumsum(np.abs(af.occupation_array())) if np.abs(y_ebs[0]-7.015756401120343266e-02) < 1e-4: print(">>>>>>>>>>>>>>>>>>found: %s"%file)
def load_comsyl_file(self): self.af_oasys = CompactAFReader.initialize_from_file(self.filename)
intensity=True, phase=True, overwrite=overwrite) path, file_name = os.path.split(file_name) self.setStatusMessage("File Out: " + file_name) # path, file_name = os.path.split(self.file_name) # self.setStatusMessage("File Out: " + file_name) else: QMessageBox.critical(self, "Error", "COMSYL modes not present", QMessageBox.Ok) except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if __name__ == "__main__": from PyQt5.QtWidgets import QApplication import sys a = QApplication(sys.argv) ow = OWModesFileWriter() ow.file_name = "tmp.h5" filename = "/users/srio/COMSYLD/comsyl/comsyl/calculations/septest_cm_new_u18_2m_1h_s2.5.npy" af = CompactAFReader.initialize_from_file(filename) ow.af = af ow.show() a.exec_()