Changes for page Partial Coherence Simulation
Last modified by rangeadm on 2025/04/23 16:13
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -4,74 +4,9 @@ 4 4 5 5 Here you can find a small python script (by (% class="twikiNewLink" %)MartinB(%%)) implementing the partial coherence methode as described in Thomas Pfeifer et al. //Partial-coherence method to model experimental free-electron laser pulse statistics,// Opt. Lett. 35, 3441-3443 (2010); [[link to the paper>>url:http://dx.doi.org/10.1364/OL.35.003441||shape="rect"]] 6 6 7 -The pulse shapes in time AND corresponding spectral dstribution can be easily created with: 7 +The pulse shapes in time AND corresponding spectral dstribution can be easily created with the Jupyter Notebook**[[attach:SASEPulseGenV2.ipynb]]** 8 8 9 -* ((( 10 -a python script 11 11 12 -{{expand}} 13 -import numpy as np 14 -import matplotlib.pyplot as plt 15 - 16 -def GetSASE(CentralEnergy, dE_FWHM, dt_FWHM, samples=0, Axis=True): 17 -h=4.135667662 #in eV*fs 18 -dE=dE_FWHM/2.355 #in eV, converts to sigma 19 -dt=dt_FWHM/2.355 #in fs, converts to sigma 20 -if samples == 0: 21 -samples=int(400.*dt*CentralEnergy/h) 22 -else: 23 -if (samples < 400.*dt*CentralEnergy/h): 24 -print("Number of samples is a little small, proceeding anyway. Got", samples, "prefer more than",400.*dt*CentralEnergy/h) 25 - 26 -EnAxis=np.linspace(0.,20.*CentralEnergy,num=samples) 27 -EnInput=np.zeros(samples, dtype=np.complex64) 28 -#for i in range(samples): 29 -EnInput=np.exp(-(EnAxis-CentralEnergy)~*~*2/2./dE~*~*2+2*np.pi*1j*np.random.random(size=samples)) 30 -En_FFT=np.fft.fft(EnInput) 31 -TAxis=np.fft.fftfreq(samples,d=(20.*CentralEnergy)/samples)*h 32 -TOutput=np.exp(-TAxis~*~*2/2./dt~*~*2)*En_FFT 33 -EnOutput=np.fft.ifft(TOutput) 34 -if (Axis): 35 -return EnAxis, EnOutput, TAxis, TOutput 36 -else: 37 -return EnOutput, TOutput 38 - 39 -\\ 40 - 41 -# set the main parameters here: 42 -CentralEnergy=80. # in eV 43 -bandwidth=0.5 # bandwidth in % 44 -dt_FWHM=30. # FWHM of the temporal duration on average 45 - 46 -dE_FWHM=CentralEnergy/100 *bandwidth # calculate bandwidth of the spectrum in eV 47 - 48 -# calculate 3 SASE pulses 49 -EnAxis, EnOutput, TAxis, TOutput = GetSASE(CentralEnergy=CentralEnergy, dE_FWHM=dE_FWHM, dt_FWHM=dt_FWHM) 50 -EnAxis2, EnOutput2, TAxis2, TOutput2 = GetSASE(CentralEnergy=CentralEnergy, dE_FWHM=dE_FWHM, dt_FWHM=dt_FWHM) 51 -EnAxis3, EnOutput3, TAxis3, TOutput3 = GetSASE(CentralEnergy=CentralEnergy, dE_FWHM=dE_FWHM, dt_FWHM=dt_FWHM) 52 - 53 - 54 -# plot spectrum 55 -ax1 = plt.subplot(1, 2, 1) 56 -plt.plot(EnAxis,np.absolute(EnOutput),EnAxis2,np.absolute(EnOutput2),EnAxis3,np.absolute(EnOutput3) ) 57 -plt.xlim(CentralEnergy-2.*dE_FWHM,CentralEnergy+2.*dE_FWHM) 58 -plt.title('Average pulse duration: %.1f fs' % dt_FWHM ) 59 -ax1.set_xlabel('Photon energy in eV') 60 -ax1.set_ylabel('spectral intensity') 61 - 62 -# plot time structure 63 -ax1 =plt.subplot(1, 2, 2) 64 -plt.plot(TAxis,np.absolute(TOutput),TAxis2,np.absolute(TOutput2), TAxis3,np.absolute(TOutput3)) 65 -plt.xlim(-2.*dt_FWHM,+2.*dt_FWHM) 66 -ax1.set_xlabel('time in fs') 67 -ax1.set_ylabel('pulse amplitude') 68 - 69 -plt.show() 70 -{{/expand}} 71 -))) 72 -* the Jupyter Notebook**[[attach:SASEPulseGenV4.ipynb]]** 73 - 74 - 75 75 Some examples of results: 76 76 77 77 \\