|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +from math import pi |
| 4 | +import at |
| 5 | +import at.plot |
| 6 | + |
| 7 | + |
| 8 | +#this function can plot pretty xy phase space with certain initial cond. |
| 9 | +def lat_pas(SR,nturns, ref, save = False): |
| 10 | + |
| 11 | + #global SR |
| 12 | + plt.rcParams["figure.figsize"] = [2*3.75, 3.75] |
| 13 | + plt.rcParams['xtick.major.size'] = 5 |
| 14 | + plt.rcParams['xtick.labelsize'] = 18 |
| 15 | + plt.rcParams['ytick.labelsize'] = 18 |
| 16 | + plt.rcParams['xtick.top'] = True |
| 17 | + plt.rcParams['ytick.right'] = True |
| 18 | + plt.rcParams['axes.titlesize'] = 20 |
| 19 | + plt.rcParams['legend.loc'] ='upper right' |
| 20 | + font = {'family':'Times New Roman', |
| 21 | + 'weight' : 'normal', |
| 22 | + 'size' : 18 } |
| 23 | + plt.rc('font',**font) |
| 24 | + plt.rcParams['lines.linewidth'] = 2 |
| 25 | + Z01 = np.array([10e-5, 0, 5e-6, 0, 0, 0]) |
| 26 | + Z02 = np.array([5e-5, 0, 0, 0, 0, 0]) |
| 27 | + Z03 = np.array([3e-5, 0, 10e-6, 0, 0, 0]) |
| 28 | + |
| 29 | + Z1=at.lattice_pass(SR, Z01, nturns, refpts=ref) |
| 30 | + Z2=at.lattice_pass(SR, Z02, nturns, refpts=ref) |
| 31 | + Z3=at.lattice_pass(SR, Z03, nturns, refpts=ref) |
| 32 | + |
| 33 | + fig, ax1 = plt.subplots() |
| 34 | + ax1.plot(Z1[0, 0, 0, :]*1e6, Z1[1, 0, 0, :]*1e6,'b.') |
| 35 | + #ax1.plot(Z2[0, 0, 0, :]*1e6, Z2[1, 0, 0, :]*1e6,'b.') |
| 36 | + #ax1.plot(Z3[0, 0, 0, :]*1e6, Z3[1, 0, 0, :]*1e6,'g.') |
| 37 | + ax1.set_title("Phase space at index number %g" %ref) |
| 38 | + ax1.minorticks_on() |
| 39 | + ax1.tick_params(axis='both',which='minor',width=1, length=6, top='True', right='True', direction='in') |
| 40 | + ax1.tick_params(which='both', width=1) |
| 41 | + ax1.tick_params(which='major', length=7, top='True', right='True', direction='inout') |
| 42 | + ax1.tick_params(axis='both',which='minor',width=1, length=6, top='True', right='True', direction='in') |
| 43 | +# Create the contour plot |
| 44 | + ax1.set_ylabel("X' [$\mu$rad]") |
| 45 | + ax1.set_xlabel("X [$\mu$m]") |
| 46 | + |
| 47 | + ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis |
| 48 | + ax2.minorticks_on() |
| 49 | + ax2.plot(Z1[2, 0, 0, :]*1e6, Z1[3, 0, 0, :]*1e6,'r.',ls='none', markersize=2, alpha =0.25) |
| 50 | + #ax2.plot(Z2[2, 0, 0, :]*1e6, Z2[3, 0, 0, :]*1e6,'b.', alpha =0.25) |
| 51 | + #ax2.plot(Z3[2, 0, 0, :]*1e6, Z3[3, 0, 0, :]*1e6,'g.', alpha =0.25) |
| 52 | + ax2.set_ylabel("Y' [$\mu$rad]", color='r') |
| 53 | + ax2.set_ylim(-10,10) |
| 54 | + print(SR[ref]) |
| 55 | + if save == True: |
| 56 | + ax1.savefig('PhaseSpace_%g'%ref+'.png', dpi = 600, bbox_inches=None, pad_inches=0.5) |
| 57 | + ax1.savefig('PhaseSpace_%g'%ref+'.eps', dpi = 300, bbox_inches=None, pad_inches=0.5) |
| 58 | + plt.show() |
| 59 | + |
| 60 | +#plots horizontal x orbit vs spos |
| 61 | +def plot_bpm_x(SR, nturns, ref_point , tune, save): |
| 62 | + #nturns=500 |
| 63 | + ref = SR[ref_point] |
| 64 | + time = nturns*1.7e-6 #second |
| 65 | + damp = 0.01717785 #s at.radiation_parameters(StorageR).Tau[0]# |
| 66 | + tune = 0.22#tune#at.radiation_parameters(SR).tunes[0] |
| 67 | + tt = np.linspace(0,time, nturns) |
| 68 | + Z03 = np.array([3e-6, 0, 10e-6, 0, 0, 0]) |
| 69 | + Z3=at.lattice_pass(SR,Z03,nturns, refpts=ref) |
| 70 | + plt.rcParams['axes.titlesize'] = 20 |
| 71 | + plt.rcParams['ytick.right'] = True |
| 72 | + plt.rcParams["figure.figsize"] = [3*3.75, 3.75] |
| 73 | + plt.rcParams['xtick.major.size'] = 5 |
| 74 | + plt.rcParams['xtick.labelsize'] = 18 |
| 75 | + plt.rcParams['ytick.labelsize'] = 18 |
| 76 | + plt.rcParams['xtick.top'] = True |
| 77 | + plt.rcParams['legend.loc'] ='upper right' |
| 78 | + plt.rcParams['lines.linewidth'] = 2 |
| 79 | + font = {'family':'Times New Roman', |
| 80 | + 'weight' : 'normal', |
| 81 | + 'size' : 18 } |
| 82 | + plt.rc('font',**font) |
| 83 | + plt.minorticks_on() |
| 84 | + plt.tick_params(axis='both',which='minor',width=1, length=6, top='True', right='True', direction='in') |
| 85 | + plt.tick_params(which='both', width=1) |
| 86 | + plt.tick_params(which='major', length=7, top='True', right='True', direction='inout') |
| 87 | + plt.tick_params(axis='both',which='minor',width=1, length=6, top='True', right='True', direction='in') |
| 88 | +# Create the contour plot |
| 89 | + #plt.title('Horizontal position for turns: %d at ref. point %d, damping %.4e s' %(nturns, ref_point, damp) ) |
| 90 | + |
| 91 | + |
| 92 | + plt.plot( tt*1000, 1000*Z3[0, 0, 0, :]*np.exp(-2*tt/damp),'.',c='b', label='Tune: %0.3f' %tune)# %tune) |
| 93 | + #plt.plot( tt*1000, 1000*Z3[2, 0, 0, :]*np.exp(-2*tt/0.0400897),'.',c='b', label='Tune: %0.3f' %tune)# %tune) |
| 94 | + plt.ylabel("X [mm]") |
| 95 | + plt.xlabel("Time [ms]") |
| 96 | + plt.legend() |
| 97 | + print(ref, damp) |
| 98 | + if save == True: |
| 99 | + plt.savefig('bpm'+str(tune)+'_hor.png', dpi =600) |
| 100 | + plt.savefig('bpm'+str(tune)+'_hor.eps', dpi =300) |
| 101 | + return damp, 1000*Z3[0, 0, 0, :]*np.exp(-2*tt/damp) |
| 102 | +##time, xx = plot_bpm_x(5000, 101, 0.27, False) |
| 103 | + |
| 104 | +#same as plot_bpm_x without plotting it |
| 105 | +def orbit_x(SR, nturns, ref_point , tune, save): |
| 106 | + #nturns=500 |
| 107 | + ref = SR[ref_point] |
| 108 | + time = nturns*1.7e-6 #second |
| 109 | + damp = 6.54e-06 #s |
| 110 | + tune = tune#at.radiation_parameters(SR).tunes[0] |
| 111 | + tt = np.linspace(0,time, nturns) |
| 112 | + Z03 = np.array([10e-6, 0, 10e-6, 0, 0, 0]) |
| 113 | + Z3=at.lattice_pass(SR,Z03,nturns, refpts=ref) |
| 114 | + return damp, 1000*Z3[0, 0, 0, :]*np.exp(-2*tt/damp), 1000*Z3[1, 0, 0, :]*np.exp(-2*tt/damp) |
0 commit comments