|
| 1 | +import at |
| 2 | +import at.plot |
| 3 | +import numpy as np |
| 4 | +import matplotlib.pyplot as plt |
| 5 | + |
| 6 | + |
| 7 | +file_path = 'dba.mat' |
| 8 | +# Load lattice file (can be .mat or .lat) |
| 9 | +lattice = at.load_mat(file_path, mat_key='RING') |
| 10 | +plt.rcParams["figure.figsize"] = [10, 6] |
| 11 | +plt.rcParams["figure.dpi"] = 600 |
| 12 | +plt.rcParams['lines.linewidth'] = 6 |
| 13 | + |
| 14 | +plt.rcParams["xtick.direction"] = 'inout' |
| 15 | +plt.rcParams["ytick.direction"] = 'inout' |
| 16 | +plt.rcParams["xtick.minor.visible"] = True |
| 17 | +plt.rcParams["ytick.minor.visible"] = True |
| 18 | + |
| 19 | +plt.rcParams['xtick.major.size'] = 10 |
| 20 | +plt.rcParams['ytick.major.size'] = 10 |
| 21 | + |
| 22 | +plt.rcParams['xtick.minor.size'] = 5 |
| 23 | +plt.rcParams['xtick.labelsize'] = 24 |
| 24 | +plt.rcParams['ytick.labelsize'] = 24 |
| 25 | +plt.rcParams['xtick.top'] = True |
| 26 | +plt.rcParams['ytick.right'] = True |
| 27 | +plt.rcParams['axes.titlesize'] = 26 |
| 28 | +plt.rcParams['font.size'] =20 |
| 29 | +plt.rcParams['lines.linewidth'] = 2.3 |
| 30 | +plt.rcParams['font.family']= 'Times New Roman' |
| 31 | +plt.rcParams['legend.loc']= 'upper right' |
| 32 | +plt.rcParams['legend.fontsize']= 'small' |
| 33 | +plt.rcParams['xtick.major.width']=1 |
| 34 | +plt.rcParams['ytick.major.width']=1 |
| 35 | +plt.rcParams['axes.grid'] = False |
| 36 | +plt.rcParams['axes.grid.which'] = 'major' |
| 37 | +custom_colors = ['blue', 'red', 'green'] |
| 38 | + |
| 39 | +# Set the custom color cycle |
| 40 | +plt.rcParams['axes.prop_cycle'] = plt.cycler(color=custom_colors) |
| 41 | + |
| 42 | + |
| 43 | +# Plot beta functions |
| 44 | +lattice.plot_beta(s_range=[0,24]) |
| 45 | + |
| 46 | + |
| 47 | +# Track the particles through the lattice |
| 48 | +#tracked_particles = at.track(lattice, r_in0, 1000, 0) |
| 49 | +quad_positions = [] |
| 50 | +quad_lengths = [] |
| 51 | +quad_strengths = [] |
| 52 | +position = 0.0 |
| 53 | +for elem in range(len(lattice)//12): |
| 54 | + position += lattice[elem].Length |
| 55 | + if isinstance(lattice[elem], at.Quadrupole): |
| 56 | + print(lattice[elem].FamName, lattice[elem].K,' ', lattice[elem].Length) |
| 57 | + quad_positions.append(position- lattice[elem].Length/2) |
| 58 | + quad_lengths.append(lattice[elem].Length) |
| 59 | + quad_strengths.append(lattice[elem].K) |
| 60 | +# Plot the quadrupole strengths as vertical lines |
| 61 | +plt.plot( figsize=(14, 12)) |
| 62 | +for pos, length, strength in zip(quad_positions, quad_lengths, quad_strengths): |
| 63 | + plt.plot([pos, pos], [0, strength], color="k", label="Quadrupole Strength" if pos == quad_positions[0] else "") |
| 64 | + #plt.plot([pos - length / 2, pos + length / 2], [strength, strength], color="red", linestyle="--", label="Length of Quadrupole" if pos == quad_positions[0] else "") |
| 65 | + plt.axhline(0, color="black", linestyle=":", linewidth=1) |
| 66 | + |
| 67 | +# Add labels and legend |
| 68 | +plt.xlabel("s position [m]") |
| 69 | +plt.ylabel("Quadrupole Strength (K)") |
| 70 | +plt.title("Quadrupole Strengths and Lengths Along the Lattice") |
| 71 | +plt.legend() |
| 72 | +# Plot beta functions |
| 73 | +plt.plot(figsize=(10, 15)) |
| 74 | +lattice.plot_beta(s_range=[0,len(lattice)//12]) |
| 75 | +#plt.grid(True) |
0 commit comments