def generate_heigth_profile_file(self, not_interactive_mode=False): if not self.zz is None and not self.yy is None and not self.xx is None: try: congruence.checkDir(self.heigth_profile_file_name) sys.stdout = EmittingStream(textWritten=self.writeStdOut) ST.write_shadow_surface(self.zz, self.xx, self.yy, outFile=congruence.checkFileName(self.heigth_profile_file_name)) if not not_interactive_mode: QMessageBox.information(self, "QMessageBox.information()", "Height Profile file " + self.heigth_profile_file_name + " written on disk", QMessageBox.Ok) if self.modify_y == 0: dimension_y = self.si_to_user_units * (self.server.y[-1] - self.server.y[0]) if self.modify_y == 1: dimension_y = self.si_to_user_units * (self.server.y[-1] - self.server.y[0]) * self.scale_factor_y elif self.modify_y == 2: dimension_y = self.new_length self.send("PreProcessor_Data", ShadowPreProcessorData(error_profile_data_file=self.heigth_profile_file_name, error_profile_x_dim=self.dimension_x, error_profile_y_dim=dimension_y)) except Exception as exception: QMessageBox.critical(self, "Error", exception.args[0], QMessageBox.Ok)
def generate_waviness_file(self, not_interactive_mode=False): if not self.zz is None and not self.yy is None and not self.xx is None: try: congruence.checkDir(self.waviness_file_name) sys.stdout = EmittingStream(textWritten=self.writeStdOut) ST.write_shadow_surface(self.zz.T, self.xx, self.yy, outFile=congruence.checkFileName( self.waviness_file_name)) if not not_interactive_mode: QMessageBox.information( self, "QMessageBox.information()", "Waviness file " + self.waviness_file_name + " written on disk", QMessageBox.Ok) self.send( "PreProcessor_Data", ShadowPreProcessorData( error_profile_data_file=self.waviness_file_name, error_profile_x_dim=self.dimension_x, error_profile_y_dim=self.dimension_y)) except Exception as exception: QMessageBox.critical(self, "Error", exception.args[0], QMessageBox.Ok)
def create_surface_file(ftype="toroid", p=18.8, q=8.075, theta=2e-3, ratio=1.0): from Shadow import ShadowTools as ST from orangecontrib.syned.als.widgets.tools.ow_als_diaboloid import ken_diaboloid_segment_to_point from orangecontrib.syned.als.widgets.tools.ow_als_diaboloid import valeriy_diaboloid_exact_segment_to_point from orangecontrib.syned.als.widgets.tools.ow_als_diaboloid import valeriy_parabolic_cone_segment_to_point from orangecontrib.syned.als.widgets.tools.ow_als_diaboloid import toroid_segment_to_point Rs = 2.0 * numpy.sin(theta) / (1 / p + 1 / q) * ratio Y = numpy.linspace(-0.8, 0.8, 1001) X = numpy.linspace(-Rs, Rs, 101) if ftype == "toroid": Z = toroid_segment_to_point(p=p, q=q, theta=theta, x=X, y=Y) elif ftype == "diaboloid": Z, XX, YY = valeriy_diaboloid_exact_segment_to_point(p=p, q=q, theta=theta, x=X, y=Y) elif ftype == "parabolic-cone": Z, XX, YY = valeriy_parabolic_cone_segment_to_point(p=p, q=q, theta=theta, x=X, y=Y) # print(Z.shape, X.shape, Y.shape) ST.write_shadow_surface(Z.T, X, Y, "diaboloid_shadow.dat") return Rs
def write_shadow_and_hybrid_files(self, error_profile_data_files, index, xx, yy, zz): zz = zz / self.workspace_units_to_m xx = numpy.round(xx / self.workspace_units_to_m, 6) yy = numpy.round(yy / self.workspace_units_to_m, 6) filename, _ = os.path.splitext(os.path.basename(self.surface_file_names[index])) error_profile_data_file = filename + "_shadow.dat" hybrid_error_profile_data_file = filename + "_hybrid.h5" ST.write_shadow_surface(zz, xx, yy, error_profile_data_file) OU.write_surface_file(zz, xx, yy, hybrid_error_profile_data_file) error_profile_data_files.append([error_profile_data_file, hybrid_error_profile_data_file])
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_file = 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" or file_extension==".h5"): error_profile_data_file = filename + "_shadow.dat" ST.write_shadow_surface(surface_data.zz/self.workspace_units_to_m, numpy.round(surface_data.xx/self.workspace_units_to_m, 6), numpy.round(surface_data.yy/self.workspace_units_to_m, 6), error_profile_data_file) self.send("PreProcessor_Data", ShadowPreProcessorData(error_profile_data_file=error_profile_data_file, error_profile_x_dim=error_profile_data.error_profile_x_dim/self.workspace_units_to_m, error_profile_y_dim=error_profile_data.error_profile_y_dim/self.workspace_units_to_m)) elif isinstance(self.oasys_data, OasysSurfaceData): surface_data_file = self.oasys_data.surface_data_file filename, file_extension = os.path.splitext(surface_data_file) if (file_extension==".hd5" or file_extension==".hdf5" or file_extension==".hdf" or file_extension==".h5"): surface_data_file = filename + "_shadow.dat" ST.write_shadow_surface(self.oasys_data.zz/self.workspace_units_to_m, numpy.round(self.oasys_data.xx/self.workspace_units_to_m, 9), numpy.round(self.oasys_data.yy/self.workspace_units_to_m, 9), surface_data_file) error_profile_x_dim = abs(self.oasys_data.xx[-1] - self.oasys_data.xx[0])/self.workspace_units_to_m error_profile_y_dim = abs(self.oasys_data.yy[-1] - self.oasys_data.yy[0])/self.workspace_units_to_m self.send("PreProcessor_Data", ShadowPreProcessorData(error_profile_data_file=surface_data_file, error_profile_x_dim=error_profile_x_dim, error_profile_y_dim=error_profile_y_dim)) except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def generate_waviness_file(self): if not self.zz is None and not self.yy is None and not self.xx is None: if not self.waviness_file_name is None: self.waviness_file_name = self.waviness_file_name.strip() if self.waviness_file_name == "": raise Exception("Output File Name missing") else: raise Exception("Output File Name missing") sys.stdout = EmittingStream(textWritten=self.writeStdOut) ST.write_shadow_surface(self.zz.T, self.xx, self.yy, outFile=self.waviness_file_name) QMessageBox.information(self, "QMessageBox.information()", "Waviness file " + self.waviness_file_name + " written on disk", QMessageBox.Ok) self.send("PreProcessor_Data", ShadowPreProcessorData(waviness_data_file=self.waviness_file_name))
def convert_surfaces(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 + "_shadow.dat" ST.write_shadow_surface( zz / self.workspace_units_to_m, numpy.round(xx / self.workspace_units_to_m, 6), numpy.round(yy / self.workspace_units_to_m, 6), error_profile_data_file) error_profile_data_files.append( error_profile_data_file) self.send( "PreProcessor_Data", ShadowPreProcessorData( error_profile_data_file=error_profile_data_files, error_profile_x_dim=error_profile_data. error_profile_x_dim / self.workspace_units_to_m, error_profile_y_dim=error_profile_data. error_profile_y_dim / self.workspace_units_to_m)) 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 generate_waviness_file(self, not_interactive_mode=False): if not self.zz is None and not self.yy is None and not self.xx is None: try: congruence.checkDir(self.waviness_file_name) sys.stdout = EmittingStream(textWritten=self.writeStdOut) ST.write_shadow_surface(self.zz.T, self.xx, self.yy, outFile=congruence.checkFileName(self.waviness_file_name)) if not not_interactive_mode: QMessageBox.information(self, "QMessageBox.information()", "Waviness file " + self.waviness_file_name + " written on disk", QMessageBox.Ok) self.send("PreProcessor_Data", ShadowPreProcessorData(error_profile_data_file=self.waviness_file_name, error_profile_x_dim=self.dimension_x, error_profile_y_dim=self.dimension_y)) except Exception as exception: QMessageBox.critical(self, "Error", exception.args[0], QMessageBox.Ok)
def write_error_profile_file(self): ST.write_shadow_surface(self.zz, self.xx, self.yy, self.heigth_profile_file_name)
def write_error_profile_file(self, zz, xx, yy, outFile): ST.write_shadow_surface(zz, xx, yy, outFile)
def completeOperations(self, shadow_oe): shadow_oe_temp = shadow_oe.duplicate() input_beam_temp = self.input_beam.duplicate(history=False) self.manage_acceptance_slits(shadow_oe_temp) ShadowBeam.traceFromOE(input_beam_temp, shadow_oe_temp, write_start_file=0, write_end_file=0, widget_class_name=type(self).__name__) x, y, z = self.calculate_ideal_surface(shadow_oe_temp) bender_parameter, z_bender_correction = self.calculate_bender_correction( y, z, self.kind_of_bender, self.shape) self.M1_out = round(bender_parameter[0], int(6 * self.workspace_units_to_mm)) if self.shape == TRAPEZIUM: self.e_out = round(bender_parameter[1], 5) if self.kind_of_bender == DOUBLE_MOMENTUM: self.ratio_out = round(bender_parameter[2], 5) elif self.shape == RECTANGLE: if self.kind_of_bender == DOUBLE_MOMENTUM: self.ratio_out = round(bender_parameter[1], 5) self.plot3D(x, y, z_bender_correction, 2, "Ideal - Bender Surfaces") if self.modified_surface > 0: x_e, y_e, z_e = ShadowPreProcessor.read_surface_error_file( self.ms_defect_file_name) if len(x) == len(x_e) and len(y) == len(y_e) and \ x[0] == x_e[0] and x[-1] == x_e[-1] and \ y[0] == y_e[0] and y[-1] == y_e[-1]: z_figure_error = z_e else: z_figure_error = interp2d(y_e, x_e, z_e, kind='cubic')(y, x) z_bender_correction += z_figure_error self.plot3D(x, y, z_figure_error, 3, "Figure Error Surface") self.plot3D(x, y, z_bender_correction, 4, "Ideal - Bender + Figure Error Surfaces") ST.write_shadow_surface(z_bender_correction.T, numpy.round(x, 6), numpy.round(y, 6), self.output_file_name_full) # Add new surface as figure error shadow_oe._oe.F_RIPPLE = 1 shadow_oe._oe.F_G_S = 2 shadow_oe._oe.FILE_RIP = bytes(self.output_file_name_full, 'utf-8') # Redo Raytracing with the new file super().completeOperations(shadow_oe) self.send( "PreProcessor_Data", ShadowPreProcessorData( error_profile_data_file=self.output_file_name, error_profile_x_dim=self.dim_x_plus + self.dim_x_minus, error_profile_y_dim=self.dim_y_plus + self.dim_y_minus))