|
| 1 | +import sys, os |
| 2 | +sys.path.append('../../../') |
| 3 | + |
| 4 | + |
| 5 | +import numpy as np |
| 6 | +import matplotlib.pyplot as plt |
| 7 | +from matplotlib.ticker import MaxNLocator |
| 8 | + |
| 9 | +import PyPARIS.myfilemanager as mfm |
| 10 | + |
| 11 | +import mystyle as ms |
| 12 | + |
| 13 | +tag = 'noecloud' |
| 14 | + |
| 15 | +flag_check_damp_time = False |
| 16 | +tau_damp_x = 50. |
| 17 | +tau_damp_y = 100. |
| 18 | + |
| 19 | +flag_check_Qs = True |
| 20 | +Q_s = np.nan |
| 21 | + |
| 22 | +#ob = mfm.monitorh5_to_obj('bunch_evolution_00.h5') |
| 23 | +ob = mfm.monitorh5list_to_obj( |
| 24 | + ['bunch_evolution_%02d.h5'%ii for ii in range(3)]) |
| 25 | + |
| 26 | + |
| 27 | +plt.close('all') |
| 28 | + |
| 29 | +# Plot transverse positions |
| 30 | +fig1 = plt.figure(1, figsize=(8,6*1.2)) |
| 31 | +fig1.set_facecolor('w') |
| 32 | +ms.mystyle_arial(fontsz=16) |
| 33 | + |
| 34 | +axx = fig1.add_subplot(2,1,1) |
| 35 | +axy = fig1.add_subplot(2,1,2, sharex=axx) |
| 36 | + |
| 37 | +axx.plot(ob.mean_x) |
| 38 | +axy.plot(ob.mean_y) |
| 39 | + |
| 40 | +if flag_check_damp_time: |
| 41 | + turn_num = np.arange(0, len(ob.mean_x), dtype=np.float) |
| 42 | + ix_max = np.argmax(ob.mean_x) |
| 43 | + iy_max = np.argmax(ob.mean_y) |
| 44 | + |
| 45 | + axx.plot(ob.mean_x[ix_max]*np.exp(-(turn_num-ix_max)/tau_damp_x), |
| 46 | + linewidth=2, color='red', linestyle='--', |
| 47 | + label=r'Damping time = %.0f turns'%tau_damp_x) |
| 48 | + axy.plot(ob.mean_y[iy_max]*np.exp(-(turn_num-iy_max)/tau_damp_y), |
| 49 | + linewidth=2, color='red', linestyle='--', |
| 50 | + label=r'Damping time = %.0f turns'%tau_damp_y) |
| 51 | + |
| 52 | +axx.legend(prop={'size':14}).draggable() |
| 53 | +axy.legend(prop={'size':14}).draggable() |
| 54 | + |
| 55 | +axx.set_ylabel('x [m]') |
| 56 | +axy.set_ylabel('y [m]') |
| 57 | +axy.set_xlabel('Turn') |
| 58 | + |
| 59 | +# Plot transverse spectra |
| 60 | +fig2 = plt.figure(2, figsize=(8,6*1.2)) |
| 61 | +fig2.set_facecolor('w') |
| 62 | + |
| 63 | +axfx = fig2.add_subplot(2,1,1) |
| 64 | +axfy = fig2.add_subplot(2,1,2, sharex=axfx) |
| 65 | + |
| 66 | +spectx = np.abs(np.fft.rfft(ob.mean_x)) |
| 67 | +specty = np.abs(np.fft.rfft(ob.mean_y)) |
| 68 | +freq = np.fft.rfftfreq(len(ob.mean_x)) |
| 69 | + |
| 70 | +axfx.plot(freq, spectx) |
| 71 | +axfy.plot(freq, specty) |
| 72 | + |
| 73 | +# Check longitudinal plane |
| 74 | +fig3 = plt.figure(3, figsize=(8,6*1.2)) |
| 75 | +fig3.set_facecolor('w') |
| 76 | +axz = fig3.add_subplot(2,1,1, sharex=axx) |
| 77 | +axfz = fig3.add_subplot(2,1,2) |
| 78 | + |
| 79 | +axz.plot(ob.mean_z[:-10]) |
| 80 | +spectz = np.abs(np.fft.rfft(ob.mean_z[:-10])) |
| 81 | +spectz[0] = 0. # I am non interested in the average |
| 82 | +freqz = np.fft.rfftfreq(len(ob.mean_x[:-10])) |
| 83 | +axfz.plot(freqz, spectz) |
| 84 | +axfz.axvline(x=Q_s) |
| 85 | + |
| 86 | +for ax in [axx, axy, axfx, axfy, axz, axfz]: |
| 87 | + ax.ticklabel_format(style='sci', scilimits=(0,0),axis='y') |
| 88 | + |
| 89 | +for ax in [axx, axy, axfx, axfy, axz, axfz]: |
| 90 | + ax.yaxis.set_major_locator(MaxNLocator(5)) |
| 91 | + |
| 92 | +for ax in [axx, axy, axfx, axfy, axz, axfz]: |
| 93 | + ax.grid(True) |
| 94 | + |
| 95 | +for fig in [fig1, fig2, fig3]: |
| 96 | + fig.suptitle('Bunch') |
| 97 | + fig.subplots_adjust( |
| 98 | + top=0.885, |
| 99 | + bottom=0.1, |
| 100 | + left=0.125, |
| 101 | + right=0.9, |
| 102 | + hspace=0.345, |
| 103 | + wspace=0.2) |
| 104 | + |
| 105 | +plt.show() |
0 commit comments