def test_2d_normalize_to_slope_error(self,combination="FF"): mirrorLength = 200.1 # cm Step = 1.0 RandomSeed = 8788 RMS = 0.2e-6 # 2.0e-6 # rad mirrorWidth = 40.0 StepW = 1.0 RandomSeedW = 8788 RMSW = 0.5e-6 # 1.0e-6 if combination == "EE": # TODO: not yet tested input_file = package_dirname("srxraylib.metrology") + "/mirror_1d.txt" values = numpy.loadtxt(input_file) x_l = values[:, 0] y_l = values[:, 1] x_w = values[:, 0] y_w = values[:, 1] print("File loaded: %s, Length:%f, StDev: %g"%(input_file,x_l[-1]-x_l[0],y_l.std())) x,y,z = simulate_profile_2D(random_seed_l=RandomSeed, error_type_l=SLOPE_ERROR, rms_l=RMS, correlation_length_l=30.0,power_law_exponent_beta_l=1.5, random_seed_w=RandomSeedW, error_type_w=SLOPE_ERROR, rms_w=RMSW, correlation_length_w=30.0,power_law_exponent_beta_w=1.5, x_l=x_l,y_l=y_l,x_w=x_w,y_w=y_w, combination=combination) else: x,y,z = simulate_profile_2D(mirror_length=mirrorLength, step_l=Step, random_seed_l=RandomSeed, error_type_l=SLOPE_ERROR, rms_l=RMS, correlation_length_l=30.0,power_law_exponent_beta_l=1.5, mirror_width=mirrorWidth, step_w=StepW, random_seed_w=RandomSeedW, error_type_w=SLOPE_ERROR, rms_w=RMSW, correlation_length_w=30.0,power_law_exponent_beta_w=1.5, combination=combination) tmp1 = slopes(z.T,x,y,return_only_rms=1) print(" target SLOPE error in WIDTH: %g rad"%(RMSW)) print(" target SLOPE error in LENGTH: %g rad"%(RMS)) print(" obtained HEIGHT error (in LENGTH and WIDTH): %g"%(z.std())) print(" obtained SLOPE error in WIDTH: %g"%(tmp1[0])) print(" obtained SLOPE error in LENGTH: %g"%(tmp1[1])) print(" shape x,y,z:",x.shape,y.shape,z.shape) # the LENGTH direction must match!! assert numpy.abs( RMS - tmp1[1] ) < 0.01 * numpy.abs(RMS) if do_plot: from srxraylib.plot.gol import plot_surface plot_surface(z.T*1e7,x,y,xtitle="X [cm]",ytitle="Y [cm",ztitle="Z [nm]",title="test_2d_normalize_to_slope_error")
def test_2d_normalize_to_slope_error(self, combination="FF"): mirrorLength = 200.1 # cm Step = 1.0 RandomSeed = 8788 RMS = 0.2e-6 # 2.0e-6 # rad mirrorWidth = 40.0 StepW = 1.0 RandomSeedW = 8788 RMSW = 0.5e-6 # 1.0e-6 if combination == "EE": # TODO: not yet tested input_file = package_dirname( "srxraylib.metrology") + "/mirror_1d.txt" values = numpy.loadtxt(input_file) x_l = values[:, 0] y_l = values[:, 1] x_w = values[:, 0] y_w = values[:, 1] print("File loaded: %s, Length:%f, StDev: %g" % (input_file, x_l[-1] - x_l[0], y_l.std())) x, y, z = simulate_profile_2D(random_seed_l=RandomSeed, error_type_l=SLOPE_ERROR, rms_l=RMS, correlation_length_l=30.0, power_law_exponent_beta_l=1.5, random_seed_w=RandomSeedW, error_type_w=SLOPE_ERROR, rms_w=RMSW, correlation_length_w=30.0, power_law_exponent_beta_w=1.5, x_l=x_l, y_l=y_l, x_w=x_w, y_w=y_w, combination=combination) else: x, y, z = simulate_profile_2D(mirror_length=mirrorLength, step_l=Step, random_seed_l=RandomSeed, error_type_l=SLOPE_ERROR, rms_l=RMS, correlation_length_l=30.0, power_law_exponent_beta_l=1.5, mirror_width=mirrorWidth, step_w=StepW, random_seed_w=RandomSeedW, error_type_w=SLOPE_ERROR, rms_w=RMSW, correlation_length_w=30.0, power_law_exponent_beta_w=1.5, combination=combination) tmp1 = slopes(z.T, x, y, return_only_rms=1) print(" target SLOPE error in WIDTH: %g rad" % (RMSW)) print(" target SLOPE error in LENGTH: %g rad" % (RMS)) print(" obtained HEIGHT error (in LENGTH and WIDTH): %g" % (z.std())) print(" obtained SLOPE error in WIDTH: %g" % (tmp1[0])) print(" obtained SLOPE error in LENGTH: %g" % (tmp1[1])) print(" shape x,y,z:", x.shape, y.shape, z.shape) # the LENGTH direction must match!! assert numpy.abs(RMS - tmp1[1]) < 0.01 * numpy.abs(RMS) if do_plot: from srxraylib.plot.gol import plot_surface plot_surface(z.T * 1e7, x, y, xtitle="X [cm]", ytitle="Y [cm", ztitle="Z [nm]", title="test_2d_normalize_to_slope_error")
v_slit_points=50, distance=10.0, wavefront_precision_parameters=WavefrontPrecisionParameters( sr_method=2, relative_precision=0.01, number_of_points_for_trajectory_calculation=20000, sampling_factor_for_adjusting_nx_ny=-1)) e, h, v, i = wiggler.get_intensity(source_wavefront_parameters=wf_parameters, multi_electron=False) plot_contour(i[int(int(e.size / 2))], h * 1e3, v * 1e3, title="%s SRW; E=%g eV" % ("XRD1", e[int(e.size / 2)]), xtitle="H [mm]", ytitle="V [mm]", plot_points=0, contour_levels=numpy.linspace(0, i.max(), 20), cmap=None, cbar=1, cbar_title="Flux ", show=1) plot_surface(i[int(e.size / 2)], h * 1e3, v * 1e3, title="%s SRW; E=%g eV" % ("XRD1", e[int(e.size / 2)]), xtitle="H [mm]", ytitle="V [mm]", show=1)
def do_plot(self, exchange_data): print(">>plot_data_exchange: data received") plot_type = None try: data = exchange_data.get_content("xoppy_data").T plot_type = "1D" except: pass try: data = exchange_data.get_content("data2D") plot_type = "2D" except: pass if plot_type == None: print(">>plot_data_exchange: Nothing to plot") return if plot_type == "1D": print(">>plot_data_exchange: plotting 1D") try: xcol = exchange_data.get_content("plot_x_col") except: xcol = 0 try: ycol = exchange_data.get_content("plot_y_col") except: ycol = 1 x = data[xcol, :] y = data[ycol, :] x.shape = -1 y.shape = -1 fig = plt.figure() plt.plot(x, y, linewidth=1.0, figure=fig) try: plt.title(exchange_data.get_content("name")) except: pass try: plt.xlabel(exchange_data.get_content("labels")[xcol]) except: pass try: plt.ylabel(exchange_data.get_content("labels")[ycol]) except: pass plt.grid(True) if plot_type == "2D": print(">>plot_data_exchange: plotting 2D") try: x = exchange_data.get_content("dataX") except: x = numpy.arange(data.shape[0]) try: y = exchange_data.get_content("dataY") except: y = numpy.arange(data.shape[0]) from srxraylib.plot.gol import plot_surface fig = plot_surface(data, x, y, show=0) if self.figure_canvas is not None: self.mainArea.layout().removeWidget(self.figure_canvas) self.figure_canvas = FigureCanvas(fig) #plt.figure()) self.mainArea.layout().addWidget(self.figure_canvas)
def do_plot(self, exchange_data): print(">>plot_data_exchange: data received") plot_type = None try: data = exchange_data.get_content("xoppy_data").T plot_type = "1D" except: pass try: data = exchange_data.get_content("data2D") plot_type = "2D" except: pass if plot_type == None: print(">>plot_data_exchange: Nothing to plot") return if plot_type == "1D": print(">>plot_data_exchange: plotting 1D") try: xcol = exchange_data.get_content("plot_x_col") except: xcol = 0 try: ycol = exchange_data.get_content("plot_y_col") except: ycol = 1 x = data[xcol,:] y = data[ycol,:] x.shape = -1 y.shape = -1 fig = plt.figure() plt.plot(x,y,linewidth=1.0, figure=fig) try: plt.title(exchange_data.get_content("name")) except: pass try: plt.xlabel(exchange_data.get_content("labels")[xcol]) except: pass try: plt.ylabel(exchange_data.get_content("labels")[ycol]) except: pass plt.grid(True) if plot_type == "2D": print(">>plot_data_exchange: plotting 2D") try: x = exchange_data.get_content("dataX") except: x = numpy.arange(data.shape[0]) try: y = exchange_data.get_content("dataY") except: y = numpy.arange(data.shape[0]) from srxraylib.plot.gol import plot_surface fig = plot_surface(data,x,y,show=0) if self.figure_canvas is not None: self.mainArea.layout().removeWidget(self.figure_canvas) self.figure_canvas = FigureCanvas(fig) #plt.figure()) self.mainArea.layout().addWidget(self.figure_canvas)
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.")
newbeam.set_column(1, x2[0]) newbeam.set_column(2, x2[1]) newbeam.set_column(3, x2[2]) newbeam.set_column(4, v2[0]) newbeam.set_column(5, v2[1]) newbeam.set_column(6, v2[2]) newbeam.set_column(10, flag) newbeam.set_column(13, optical_path + t) return newbeam, normal if __name__ == "__main__": t = S4Toroid() t.set_from_focal_distances(30.0, 10.0, 0.003) print(t.info()) print("Rmaj, Rmin", t.get_toroid_radii()) print("Rtan, Rsag", t.get_tangential_and_sagittal_radii()) from srxraylib.plot.gol import plot_surface x = numpy.linspace(-0.01, 0.01, 100) y = numpy.linspace(-0.03, 0.03, 200) X = numpy.outer(x, numpy.ones_like(y)) Y = numpy.outer(numpy.ones_like(x), y) Z = t.surface_height(X, Y) plot_surface(Z, x, y, xtitle="x")
t = numpy.linspace(0, y.max() - y.min(), 100) xx = x0[0] + v0[0] * t yy = x0[1] + v0[1] * t zz = x0[2] + v0[2] * t plot_surface_and_line(Z, x, y, zz, xx, yy) # # mesh object # mm = S4Mesh() mm.set_ray(x0, v0) mm.set_surface(sphere) zz = mm.surface_height(X, Y) plot_surface(zz, x, y, xtitle="X") # # intercept # x_start = 0 t_solution = mm.solve(x_start) print("t_solution: ", t_solution) print("line: ", mm.line(t_solution)) print("surface: ", mm.surface_vs_t(t_solution)) # # now real surface from file #
wf_parameters = SourceWavefrontParameters(photon_energy_min = resonance_energy*harmonic, photon_energy_max = resonance_energy*harmonic, photon_energy_points=1, h_slit_gap = 0.005, v_slit_gap = 0.005, h_slit_points=51, v_slit_points=51, distance = 10.0) e, h, v, i = undulator.get_intensity(source_wavefront_parameters=wf_parameters) plot_contour(i[int(e.size/2)],h*1e3,v*1e3,title="%s SRW; E=%g eV"%("MicroXRD",e[int(e.size/2)]),xtitle="H [mm]",ytitle="V [mm]",plot_points=0, contour_levels=numpy.linspace(0, i.max(), 20), cmap=None, cbar=1, cbar_title="Intensity [ph/s/.1%bw/mm^2]",show=1) plot_surface(i[int(e.size/2)],h*1e3,v*1e3,title="%s SRW; E=%g eV"%("MicroXRD",e[int(e.size/2)]),xtitle="H [mm]",ytitle="V [mm]", show=1) # ------------------------------------------ ''' wf_parameters = SourceWavefrontParameters(photon_energy_min = 1, photon_energy_max = 12001, photon_energy_points=12000, h_slit_gap = 0.001, v_slit_gap = 0.001, h_slit_points=10, v_slit_points=50, distance = 10.0) e, i = undulator.get_spectral_flux(source_wavefront_parameters=wf_parameters, multi_electron=True) plot(e, i, show=1, title="Flux for MicroXRD", xtitle="Energy [eV]", ytitle="Flux [ph/s/.1%bw]")