def plot_cylindrical(output_dir, opal_run_dir, step_list_of_lists): field_plot = plot_dump_fields.PlotDumpFields( opal_run_dir + "FieldMapRPHI.dat", True) field_plot.load_dump_fields() try: canvas_1d, hist, graph = field_plot.plot_1d({"r": 4.}, "phi", "bz") for format in ["png"]: canvas_1d.Print(output_dir + "bz_1d." + format) Colors.reset() except Exception: sys.excepthook(*sys.exc_info()) canvas_bz_offset = field_plot.plot_dump_fields("phi", "r", "bz") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bz_offset) for format in ["png"]: canvas_bz_offset.Print(output_dir + "closed_orbit_cylindrical_bz." + format) Colors.reset() canvas_br_offset = field_plot.plot_dump_fields("phi", "r", "br") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_br_offset) for format in ["png"]: canvas_br_offset.Print(output_dir + "closed_orbit_cylindrical_br." + format) Colors.reset() canvas_bphi_offset = field_plot.plot_dump_fields("phi", "r", "bphi") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bphi_offset) for format in ["png"]: canvas_bphi_offset.Print(output_dir + "closed_orbit_cylindrical_bphi." + format) Colors.reset() canvas_bphi_offset = field_plot.plot_dump_fields("phi", "r", "bx") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bphi_offset) for format in ["png"]: canvas_bphi_offset.Print(output_dir + "closed_orbit_cylindrical_bx." + format) Colors.reset() canvas_bphi_offset = field_plot.plot_dump_fields("phi", "r", "by") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bphi_offset) for format in ["png"]: canvas_bphi_offset.Print(output_dir + "closed_orbit_cylindrical_by." + format) Colors.reset() for step_list in step_list_of_lists: canvas, axes, graph = plot_x_z_projection(step_list) #plot_elements_xz(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir + "closed_orbit_elevation." + format) Colors.reset()
def plot_cylindrical(output_dir, opal_run_dir, step_list_of_lists): field_plot = plot_dump_fields.PlotDumpFields(opal_run_dir+"FieldMapRPHI.dat", True) field_plot.load_dump_fields() canvas_bz_offset = field_plot.plot_dump_fields("phi", "r", "bz") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bz_offset) for format in ["png"]: canvas_bz_offset.Print(output_dir+"closed_orbit_cylindrical_bz."+format) Colors.reset() return canvas_br_offset = field_plot.plot_dump_fields("phi", "r", "br") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_br_offset) for format in ["png"]: canvas_br_offset.Print(output_dir+"closed_orbit_cylindrical_br."+format) Colors.reset() canvas_bphi_offset = field_plot.plot_dump_fields("phi", "r", "bphi") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bphi_offset) for format in ["png"]: canvas_bphi_offset.Print(output_dir+"closed_orbit_cylindrical_bphi."+format) Colors.reset() canvas_bphi_offset = field_plot.plot_dump_fields("phi", "r", "bx") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bphi_offset) for format in ["png"]: canvas_bphi_offset.Print(output_dir+"closed_orbit_cylindrical_bx."+format) Colors.reset() canvas_bphi_offset = field_plot.plot_dump_fields("phi", "r", "by") for step_list in step_list_of_lists: plot_r_phi_projection(step_list, canvas_bphi_offset) for format in ["png"]: canvas_bphi_offset.Print(output_dir+"closed_orbit_cylindrical_by."+format) Colors.reset() try: canvas_1d = None for field, color in ("bz", 1), ("bphi", 2), ("br", 4): canvas_1d, graph = field_plot.plot_1d({"r":4.}, "phi", field, canvas_1d, (0., 36.), color) for format in ["png"]: canvas_1d.Print(output_dir+"bfield_1d_a."+format) canvas_1d = None for field, color in ("bz", 1), ("bphi", 2), ("br", 4): canvas_1d, graph = field_plot.plot_1d({"r":4.}, "phi", field, canvas_1d, (108., 144.), color) for format in ["png"]: canvas_1d.Print(output_dir+"bfield_1d_b."+format) Colors.reset() except Exception: sys.excepthook(*sys.exc_info())
def plot_zoom(output_dir, opal_run_dir, step_list_of_lists): field_plot = plot_dump_fields.PlotDumpFields(opal_run_dir+"FieldMapXY-zoom.dat") field_plot.load_dump_fields() canvas = field_plot.plot_dump_fields("x", "y", "bz") for step_list in step_list_of_lists: canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(2.7, 3.7, 2, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_plan-zoom."+format)
def plot_cartesian(output_dir, opal_run_dir, step_list): field_plot = plot_dump_fields.PlotDumpFields(opal_run_dir + "FieldMapXY.dat") field_plot.load_dump_fields() inner_radius, outer_radius, ncells = 3., 5., 60 canvas = field_plot.plot_dump_fields("x", "y", "bz") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir + "closed_orbit_plan_bz." + format) return canvas = field_plot.plot_dump_fields("x", "y", "bx") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir + "closed_orbit_cartesian_bx." + format) canvas = field_plot.plot_dump_fields("x", "y", "by") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir + "closed_orbit_cartesian_by." + format) canvas = field_plot.plot_dump_fields("x", "y", "br") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir + "closed_orbit_cartesian_br." + format) canvas = field_plot.plot_dump_fields("x", "y", "bphi") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir + "closed_orbit_cartesian_bphi." + format)
def plot_test_field(output_dir, opal_run_dir): field_plot = plot_dump_fields.PlotDumpFields(opal_run_dir+"FieldMapTest.dat") field_plot.load_dump_fields() canvas_1d = None for field, color in ("bx", 4), ("bz", 1), ("by", 2): canvas_1d, graph = field_plot.plot_1d({}, "y", field, canvas_1d, (-2, 2), color) if field == "bz": for delta in -1.5, +1.5: eqn = "0.5*[0]*(tanh((x-0.5*[1]-[3])/[2])-tanh((x+0.5*[1]-[3])/[2]))" fit = ROOT.TF1("fa1", eqn, delta-0.5, delta+0.5) fit.SetParameter(0, 0.25) fit.SetParameter(1, 0.125) fit.SetParameter(2, 0.1) fit.SetParameter(3, delta) fit.SetLineColor(ROOT.kGreen) fit.SetLineStyle(3) print("Fitting", eqn) graph.Fit(fit) fit.Draw("SAME") RootObjects.other.append(fit) canvas_1d.Print(output_dir+"test_field.png")
def plot_cartesian(output_dir, opal_run_dir, step_list, file_type): field_plot = plot_dump_fields.PlotDumpFields(opal_run_dir+"FieldMapXY.dat", file_type) #"em_cartesian") field_plot.load_dump_fields() probe_cuts = [lambda item: item["id"] == 0] # cut if any of probe_cuts is true probe_data = load_probes(opal_run_dir+"*PROBE*.h5", probe_cuts) #inner_radius, axis_radius, outer_radius, ncells = 12.5, 14.350, 16.0, 30 #inner_radius_a, axis_radius_a, outer_radius_a, ncells_a = 11.5, 14.350, 16.0, 15 #z_min, z_max = 0.05, 0.2 inner_radius, axis_radius, outer_radius, ncells = 3.5, 3.995, 4.5, 20 inner_radius_a, axis_radius_a, outer_radius_a, ncells_a = 3.4, 3.995, 4.5, 10 z_min, z_max, phi_min, phi_max = -0.3, 0.1, 0, 252 field_dict = {"MAGNETD":ROOT.kBlue, "MAGNETF":ROOT.kBlue} for i in range(1, 6): field_dict["H_BUMP_"+str(i)+" "] = ROOT.kMagenta field_dict["V_BUMP_"+str(i)+" "] = ROOT.kMagenta log_plot = plot_dump_fields.LogFileStripper(opal_run_dir+"log", field_dict) Colors.reset() canvas = field_plot.plot_dump_fields("x", "y", "bz") log_plot.plot_log_file(canvas, 0, 1) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) plot_beam_pipe(inner_radius_a, outer_radius_a, ncells_a, canvas) plot_axis(axis_radius, ncells, canvas) plot_probes(canvas, probe_data, "x", "y") canvas, axes, graph = plot_x_y_projection(step_list, canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_plan_bz."+format) return Colors.reset() canvas = None canvas, graph = plot_x_z_projection(step_list, phi_min, phi_max, z_min, z_max, canvas) plot_probes(canvas, probe_data, "phi", "z") plot_phi_pipe(ncells+1, 0, 360, -2.0, 2.0, ROOT.kGray, canvas) plot_phi_pipe(ncells_a+1, 0, 360, -2.0, 2.0, 1, canvas) #plot_phi_pipe(2, 72-36*0.07, 72+36*0.07, 0.05, 0.08, ROOT.kGray, canvas) #plot_phi_pipe(2, 0, 360, 0.0878, -0.05, ROOT.kGray, canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_elevation."+format) Colors.reset() Colors.reset() canvas = field_plot.plot_dump_fields("x", "y", "br") log_plot.plot_log_file(canvas, 0, 1) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) plot_beam_pipe(inner_radius_a, outer_radius_a, ncells_a, canvas) plot_axis(axis_radius, ncells, canvas) plot_probes(canvas, probe_data, "x", "y") canvas, axes, graph = plot_x_y_projection(step_list, canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_plan_br."+format) Colors.reset() canvas = field_plot.plot_dump_fields("x", "y", "bphi") plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) plot_beam_pipe(inner_radius_a, outer_radius_a, ncells_a, canvas) plot_axis(axis_radius, ncells, canvas) plot_probes(canvas, probe_data, "x", "y") canvas, axes, graph = plot_x_y_projection(step_list, canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_plan_bphi."+format) #return Colors.reset() canvas = field_plot.plot_dump_fields("x", "y", "btot") plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) plot_beam_pipe(inner_radius_a, outer_radius_a, ncells_a, canvas) plot_axis(axis_radius, ncells, canvas) plot_probes(canvas, probe_data, "x", "y") canvas, axes, graph = plot_x_y_projection(step_list, canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_plan_btot."+format) return canvas = field_plot.plot_dump_fields("x", "y", "bx") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_cartesian_bx."+format) canvas = field_plot.plot_dump_fields("x", "y", "by") canvas, axes, graph = plot_x_y_projection(step_list, canvas) plot_beam_pipe(inner_radius, outer_radius, ncells, canvas) #plot_elements_xy(opal_run_dir+"log", canvas) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_cartesian_by."+format) canvas, graph = plot_x_z_projection(step_list) for format in ["png"]: canvas.Print(output_dir+"closed_orbit_cartesian_vertical."+format)