def ken_diaboloid_point_to_segment(p=29.3, q=19.53, theta=4.5e-3, x=numpy.linspace(-0.01, 0.01, 101), y=numpy.linspace(-0.1, 0.1, 1001), detrend=0, filename_shadow="", filename_h5=""): X = numpy.outer(x, numpy.ones_like(y)) Y = numpy.outer(numpy.ones_like(x), y) s = p * numpy.cos(2 * theta) z0 = p * numpy.sin(2 * theta) c = p + q print("s: %f, z0: %f, c: %f" % (s, z0, c)) Z = -numpy.sqrt(c**2 + q**2 - s**2 - 2 * Y * (s + q) - 2 * c * numpy.sqrt(X**2 + (q - Y)**2)) Z += z0 print(Z.shape, Z.min(), Z.max()) if detrend == 0: zfit = 0 elif detrend == 1: zfit = -theta * y # -numpy.tan(theta) * y elif detrend == 2: zcentral = Z[Z.shape[0] // 2, :] zcoeff = numpy.polyfit(y[(y.size // 2 - 10):(y.size // 2 + 10)], zcentral[(y.size // 2 - 10):(y.size // 2 + 10)], 1) zfit = zcoeff[1] + y * zcoeff[0] # print(zcoeff) # from srxraylib.plot.gol import plot # plot(y,zcentral,y,zfit) for i in range(Z.shape[0]): Z[i, :] = Z[i, :] - zfit # write_surface_file(Z.T, x, y, "C:\\Users\\manuel\\Oasys\\ken_method.h5", overwrite=True) if filename_shadow != "": write_shadow_surface(Z, x, y, filename=filename_shadow) print("SHADOW file %s written to disk." % filename_shadow) if filename_h5 != "": write_surface_file(Z.T, x, y, filename_h5, overwrite=True) print("HDF5 file %s written to disk." % filename_h5) return Z, X, Y
def write_thickness_files(self, error_profile_data_files, index, xx, yy, zz): zz = numpy.round(zz, 12) xx = numpy.round(xx, 12) yy = numpy.round(yy, 12) filename, _ = os.path.splitext( os.path.basename(self.surface_file_names[index])) thickness_profile_data_file = filename + ".h5" OU.write_surface_file(zz, xx, yy, thickness_profile_data_file) error_profile_data_files.append(thickness_profile_data_file)
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_thickness_error_files(self, thickness_error_profile_data_files): self.crl_error_profiles = [] for thickness_error_file in thickness_error_profile_data_files: xx, yy, zz = OU.read_surface_file(thickness_error_file) xx /= self.workspace_units_to_m yy /= self.workspace_units_to_m zz /= self.workspace_units_to_m filename, _ = os.path.splitext(os.path.basename(thickness_error_file)) thickness_error_file = filename + "_hybrid.h5" OU.write_surface_file(zz, xx, yy, thickness_error_file) self.crl_error_profiles.append(thickness_error_file)
def write_error_profile_file(self, zz, xx, yy, outFile): OU.write_surface_file(zz, xx, yy, outFile)
1e9 * z_x, 1e3 * y, 1e9 * z_y, legend=["z vs x", "z vs y"], xtitle="x or y coordinate [mm]", ytitle="Height [nm]") # Z = numpy.outer(z_x,z_y) Z = numpy.zeros((x.size, y.size)) for i in range(x.size): for j in range(y.size): Z[i, j] = z_x[i] + z_y[j] plot_surface(1e9 * Z, 1e3 * x, 1e3 * y, xtitle="Shadow X [mm]", ytitle="Shadow Y [mm]", ztitle="Height Z [nm]", title="") # OasysSurfaceData(xx=x, # yy=y, # zz=Z, # surface_data_file="BL822_crystal_error.h5") write_surface_file(Z.T, x, y, "BL822_crystal_error.h5", overwrite=True) print("write_h5_surface: File for OASYS " + "BL822_crystal_error.h5" + " written to disk.")
def compute(self, plot_data=False): try: if not self.xx_1 is None and not self.xx_2 is None: xx_1 = self.xx_1 yy_1 = self.yy_1 zz_1 = self.zz_1 xx_2 = self.xx_2 yy_2 = self.yy_2 zz_2 = self.zz_2 if not (len(xx_1) == len(xx_2) and len(yy_1) == len(yy_1) and round(xx_1[0], 6) == round(xx_2[0], 6) and round(xx_1[-1], 6) == round(xx_2[-1], 6) and round(yy_1[0], 6) == round(yy_2[0], 6) and round(yy_1[-1], 6) == round(yy_2[-1], 6)): raise ValueError( "The two surfaces cannot be merged: dimensions or binning incompatible" ) xx = xx_2 yy = yy_2 zz = zz_2 + zz_1 self.axis.clear() x_to_plot, y_to_plot = numpy.meshgrid(xx, yy) if plot_data: self.axis.plot_surface(x_to_plot, y_to_plot, zz, rstride=1, cstride=1, cmap=cm.autumn, linewidth=0.5, antialiased=True) self.axis.set_xlabel("X [m]") self.axis.set_ylabel("Y [m]") self.axis.set_zlabel("Z [m]") self.axis.mouse_init() self.figure_canvas.draw() if not (self.surface_file_name.endswith("hd5") or self.surface_file_name.endswith("hdf5") or self.surface_file_name.endswith("hdf")): self.surface_file_name += ".hdf5" OU.write_surface_file(zz, xx, yy, self.surface_file_name) error_profile_x_dim = abs(xx[-1] - xx[0]) error_profile_y_dim = abs(yy[-1] - yy[0]) self.send( "PreProcessor_Data", OasysPreProcessorData( error_profile_data=OasysErrorProfileData( surface_data=OasysSurfaceData( xx=xx, yy=yy, zz=zz, surface_data_file=self.surface_file_name), error_profile_x_dim=error_profile_x_dim, error_profile_y_dim=error_profile_y_dim))) self.send( "Surface_Data", OasysSurfaceData(xx=xx, yy=yy, zz=zz, surface_data_file=self.surface_file_name)) except Exception as exception: QMessageBox.critical(self, "Error", exception.args[0], QMessageBox.Ok) if self.IS_DEVELOP: raise exception