def convert_surface(self): if not self.oasys_data is None: try: if isinstance(self.oasys_data, OasysPreProcessorData): error_profile_data = self.oasys_data.error_profile_data surface_data = error_profile_data.surface_data error_profile_data_files = [] for xx, yy, zz, error_profile_data_file in zip(surface_data.xx, surface_data.yy, surface_data.zz, surface_data.surface_data_file): filename, file_extension = os.path.splitext(error_profile_data_file) if (file_extension==".hd5" or file_extension==".hdf5" or file_extension==".hdf"): error_profile_data_file = filename + "_srw.dat" SU.write_error_profile_file(zz, xx, yy, error_profile_data_file) error_profile_data_files.append(error_profile_data_file) self.send("PreProcessor_Data", SRWPreProcessorData(error_profile_data=SRWErrorProfileData(error_profile_data_file=error_profile_data_files, error_profile_x_dim=error_profile_data.error_profile_x_dim, error_profile_y_dim=error_profile_data.error_profile_y_dim))) self.send("Files", error_profile_data_files) except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def send_data(self, height_profile_file_names, dimension_x, dimension_y): self.send( "PreProcessor_Data", SRWPreProcessorData(error_profile_data=SRWErrorProfileData( error_profile_data_file=height_profile_file_names, error_profile_x_dim=dimension_x, error_profile_y_dim=dimension_y))) self.send("Files", height_profile_file_names)
def send_data(self, dimension_x, dimension_y): self.send("PreProcessor_Data", SRWPreProcessorData(error_profile_data=SRWErrorProfileData(error_profile_data_file=self.heigth_profile_file_name, error_profile_x_dim=dimension_x, error_profile_y_dim=dimension_y)))
def generate_reflectivity_file(self): file_name = congruence.checkFileName(self.data_file_name) output_data = SRWPreProcessorData( reflectivity_data=SRWReflectivityData( reflectivity_data_file=self.data_file_name)) data_txt = "" if not self.reflectivity_unpol_data is None: try: reflectivity_data = self.reflectivity_unpol_data.get_content( "data2D") energy = self.reflectivity_unpol_data.get_content("dataX") angle = self.reflectivity_unpol_data.get_content( "dataY") * 0.001 #to rad output_data.reflectivity_data.energies_number = len(energy) output_data.reflectivity_data.angles_number = len(angle) output_data.reflectivity_data.components_number = 1 output_data.reflectivity_data.energy_start = energy[0] output_data.reflectivity_data.energy_end = energy[-1] output_data.reflectivity_data.energy_scale_type = ScaleType.LINEAR output_data.reflectivity_data.angle_start = angle[0] output_data.reflectivity_data.angle_end = angle[-1] output_data.reflectivity_data.angle_scale_type = ScaleType.LINEAR data_txt = "" for i in range(0, len(angle)): for j in range(0, len(energy)): if not (i == 0 and j == 0): data_txt += "\n" data_txt += str(reflectivity_data[j, i]) + "\n0.0" except: try: reflectivity_data = self.reflectivity_unpol_data.get_content( "xoppy_data") labels = self.reflectivity_unpol_data.get_content("labels") x_col = int( self.reflectivity_unpol_data.get_content("plot_x_col")) y_col = int( self.reflectivity_unpol_data.get_content("plot_y_col")) if "Energy" in labels[0]: congruence.checkStrictlyPositiveNumber( self.angle_single_value, "Angle Single Value") output_data.reflectivity_data.energies_number = len( reflectivity_data) output_data.reflectivity_data.angles_number = 1 output_data.reflectivity_data.energy_start = reflectivity_data[ 0, x_col] output_data.reflectivity_data.energy_end = reflectivity_data[ -1, x_col] output_data.reflectivity_data.angle_start = self.angle_single_value output_data.reflectivity_data.angle_end = self.angle_single_value elif "Theta" in labels[0]: congruence.checkStrictlyPositiveNumber( self.energy_single_value, "Energy Single Value") output_data.reflectivity_data.energies_number = 1 output_data.reflectivity_data.angles_number = len( reflectivity_data) output_data.reflectivity_data.energy_start = self.energy_single_value output_data.reflectivity_data.energy_end = self.energy_single_value output_data.reflectivity_data.angle_start = reflectivity_data[ 0, x_col] * 0.001 #to rad output_data.reflectivity_data.angle_end = reflectivity_data[ -1, x_col] * 0.001 #to rad output_data.reflectivity_data.components_number = 1 output_data.reflectivity_data.energy_scale_type = ScaleType.LINEAR output_data.reflectivity_data.angle_scale_type = ScaleType.LINEAR for i in range(0, len(reflectivity_data)): if i != 0: data_txt += "\n" data_txt += str(reflectivity_data[i, y_col]) + "\n0.0" except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception return if not data_txt == "": file = open(file_name, "w") file.write(data_txt) file.flush() file.close() self.send("Reflectivity Data", output_data) elif not self.reflectivity_s_data is None and not self.reflectivity_p_data is None: try: reflectivity_s = self.reflectivity_s_data.get_content("data2D") energy_s = self.reflectivity_s_data.get_content("dataX") angle_s = self.reflectivity_s_data.get_content( "dataY") * 0.001 #to rad try: reflectivity_p = self.reflectivity_p_data.get_content( "data2D") energy_p = self.reflectivity_p_data.get_content("dataX") angle_p = self.reflectivity_p_data.get_content( "dataY") * 0.001 #to rad if (len(energy_s) != len(energy_p)) or \ (energy_p[0] != energy_s[0]) or \ (energy_p[-1] != energy_s[-1]) or \ (len(angle_s) != len(angle_p)) or \ (angle_p[0] != angle_s[0]) or \ (angle_p[-1] != angle_s[-1]): QMessageBox.critical( self, "Error", "Reflectivity data have different dimension or different range of Energy/Angle values", QMessageBox.Ok) return output_data.reflectivity_data.energies_number = len( energy_s) output_data.reflectivity_data.angles_number = len(angle_s) output_data.reflectivity_data.components_number = 2 output_data.reflectivity_data.energy_start = energy_s[0] output_data.reflectivity_data.energy_end = energy_s[-1] output_data.reflectivity_data.energy_scale_type = ScaleType.LINEAR output_data.reflectivity_data.angle_start = angle_s[0] output_data.reflectivity_data.angle_end = angle_s[-1] output_data.reflectivity_data.angle_scale_type = ScaleType.LINEAR data_txt = "" for i in range(0, len(angle_s)): for j in range(0, len(energy_s)): if not (i == 0 and j == 0): data_txt += "\n" data_txt += str(reflectivity_s[j, i]) + "\n0.0" for i in range(0, len(angle_p)): for j in range(0, len(energy_p)): data_txt += "\n" + str(reflectivity_p[j, i]) + "\n0.0" except: QMessageBox.critical( self, "Error", "Reflectivity data have different dimension", QMessageBox.Ok) return except: try: reflectivity_s = self.reflectivity_s_data.get_content( "xoppy_data") labels_s = self.reflectivity_s_data.get_content("labels") x_col = int( self.reflectivity_s_data.get_content("plot_x_col")) y_col = int( self.reflectivity_s_data.get_content("plot_y_col")) try: reflectivity_p = self.reflectivity_p_data.get_content( "xoppy_data") labels_p = self.reflectivity_p_data.get_content( "labels") if (len(reflectivity_p) != len(reflectivity_s)) or \ (reflectivity_s[0, x_col] != reflectivity_p[0, x_col]) or \ (reflectivity_s[-1, x_col] != reflectivity_p[-1, x_col]) or \ (labels_s[0] != labels_p[0]): QMessageBox.critical( self, "Error", "Reflectivity data have different dimension or different range of Energy/Angle values", QMessageBox.Ok) return try: if "Energy" in labels_s[0]: congruence.checkStrictlyPositiveNumber( self.angle_single_value, "Angle Single Value") output_data.reflectivity_data.energies_number = len( reflectivity_s) output_data.reflectivity_data.angles_number = 1 output_data.reflectivity_data.energy_start = reflectivity_s[ 0, x_col] output_data.reflectivity_data.energy_end = reflectivity_s[ -1, x_col] output_data.reflectivity_data.angle_start = self.angle_single_value output_data.reflectivity_data.angle_end = self.angle_single_value elif "Theta" in labels_s[0]: congruence.checkStrictlyPositiveNumber( self.energy_single_value, "Energy Single Value") output_data.reflectivity_data.energies_number = 1 output_data.reflectivity_data.angles_number = len( reflectivity_s) output_data.reflectivity_data.energy_start = self.energy_single_value output_data.reflectivity_data.energy_end = self.energy_single_value output_data.reflectivity_data.angle_start = reflectivity_s[ 0, x_col] * 0.001 #to rad output_data.reflectivity_data.angle_end = reflectivity_s[ -1, x_col] * 0.001 #to rad except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception return output_data.reflectivity_data.components_number = 2 output_data.reflectivity_data.energy_scale_type = ScaleType.LINEAR output_data.reflectivity_data.angle_scale_type = ScaleType.LINEAR for i in range(0, len(reflectivity_s)): if i != 0: data_txt += "\n" data_txt += str(reflectivity_s[i, y_col]) + "\n0.0" for i in range(0, len(reflectivity_p)): data_txt += "\n" + str( reflectivity_p[i, y_col]) + "\n0.0" except: QMessageBox.critical( self, "Error", "Reflectivity data have different dimension", QMessageBox.Ok) return except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception return if not data_txt == "": file = open(file_name, "w") file.write(data_txt) file.flush() file.close() self.send("Reflectivity Data", output_data) else: QMessageBox.critical( self, "Error", "Incomplete Data: connect Total Polarization Data or BOTH Polarizations Data", QMessageBox.Ok)