40def draw(axes, rng, field, label, aperture):
41 xs, ys, zs = rng.axis_values()
42 centre = np.abs(zs).argmin()
43 i0, j0 = np.abs(xs).argmin(), np.abs(ys).argmin()
45 slice_xy = field[:, :, centre, 0].T
46 limit = np.abs(slice_xy).max()
47 mesh = axes[0].pcolormesh(xs, ys, slice_xy, cmap=
"RdBu_r", vmin=-limit, vmax=limit)
48 axes[0].figure.colorbar(mesh, ax=axes[0], label=
"$B_x$ [T]")
52 (-aperture[0], -aperture[1]),
60 axes[0].set(xlabel=
"x [cm]", ylabel=
"y [cm]", title=f
"{label}: $B_x$ at z = {zs[centre]:.0f} cm")
61 axes[0].set_aspect(
"equal")
63 axes[1].plot(xs, field[:, j0, centre, 0], label=
"along x, y = 0")
64 axes[1].plot(ys, field[i0, :, centre, 0], label=
"along y, x = 0")
67 on_axis = abs(field[i0, j0, centre, 0])
68 axes[1].set_ylim(-1.5 * on_axis, 1.5 * on_axis)
69 axes[1].axhline(0.0, color=
"k", linewidth=0.5)
71 axes[1].grid(alpha=0.3)
72 axes[1].set(xlabel=
"x or y [cm]", ylabel=
"$B_x$ [T]", title=f
"{label}: transverse profiles")
75 limit = np.abs(integral).max()
76 mesh = axes[2].pcolormesh(xs, ys, integral, cmap=
"RdBu_r", vmin=-limit, vmax=limit)
77 axes[2].figure.colorbar(mesh, ax=axes[2], label=
r"$\int B_x \mathrm{d}z$ [T cm]")
78 axes[2].set(xlabel=
"x [cm]", ylabel=
"y [cm]", title=f
"{label}: bending power")
79 axes[2].set_aspect(
"equal")
81 axes[3].plot(zs, field[i0, j0, :, 0], label=
"$B_x$")
82 axes[3].plot(zs, field[i0, j0, :, 1], label=
"$B_y$")
83 axes[3].plot(zs, field[i0, j0, :, 2], label=
"$B_z$")
85 axes[3].grid(alpha=0.3)
86 axes[3].set(xlabel=
"z [cm]", ylabel=
"B [T]", title=f
"{label}: on the beam axis")
90 parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
91 parser.add_argument(
"input", help=
"field map to plot")
92 parser.add_argument(
"-o",
"--output", default=
"fieldMap.pdf", help=
"file to write")
97 help=
"how to unroll the entries; xslow is what ShipBFieldMap assumes",
102 help=
"draw both unrollings side by side",
107 help=
"leave out the nominal spectrometer aperture outline",
115 help=
"also print the bending power at this (x, y), repeatable",
117 args = parser.parse_args()
119 rng = fmt.read_range(args.input)
120 field = fmt.read_field(args.input, order=args.data_order, rng=rng)
121 aperture =
None if args.no_aperture
else APERTURE
123 readings = [(args.data_order, field)]
124 if args.compare_orders:
125 other =
"yslow" if args.data_order ==
"xslow" else "xslow"
126 readings.append((other, fmt.transpose_xy(field)))
128 figure, grid = plt.subplots(4, len(readings), figsize=(7 * len(readings), 20), squeeze=
False, layout=
"constrained")
129 for column, (label, values)
in enumerate(readings):
130 draw([grid[row][column]
for row
in range(4)], rng, values, label, aperture)
131 figure.suptitle(args.input)
132 figure.savefig(args.output)
133 print(f
"Wrote {args.output}")
136 xs, ys, _ = rng.axis_values()
137 for label, values
in readings:
139 for x, y
in args.probe:
140 i, j = np.abs(xs - x).argmin(), np.abs(ys - y).argmin()
141 print(f
" {label}: int Bx dz at ({xs[i]:.0f}, {ys[j]:.0f}) cm = {integral[i, j]:.3f} T cm")