import numpy as np from scipy.fftpack import fft, ifft, fftshift, ifftshift, fftfreq import matplotlib import matplotlib.pyplot as plt from matplotlib import cm
global pi; pi=np.pi
def plotFirstAndLastPulse(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int,**kwargs): t=sim.t[int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]*1e12 plt.figure() plt.title("Initial pulse and final pulse") plt.plot(t,getPower(matrix[0,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]),label="Initial Pulse") plt.plot(t,getPower(matrix[-1,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]),label="Final Pulse") plt.xlabel("Time [ps]") plt.ylabel("Power [W]") plt.legend() saveplot('first_and_last_pulse',**kwargs) plt.show() def plotPulseMatrix2D(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int, dB_cutoff,**kwargs): fig, ax = plt.subplots() ax.set_title('Pulse Evolution (dB scale)') t = sim.t[int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]*1e12 z = fiber.zlocs T, Z = np.meshgrid(t, z) P=getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)] )/np.max(getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)])) P[P<1e-100]=1e-100 P = 10*np.log10(P) P[P<dB_cutoff]=dB_cutoff surf=ax.contourf(T, Z, P,levels=40) ax.set_xlabel('Time [ps]') ax.set_ylabel('Distance [m]') cbar=fig.colorbar(surf, ax=ax) saveplot('pulse_evo_2D',**kwargs) plt.show()
def plotPulseMatrix3D(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int, dB_cutoff,**kwargs): fig, ax = plt.subplots(1,1, figsize=(10,7),subplot_kw={"projection": "3d"}) plt.title("Pulse Evolution (dB scale)")
t = sim.t[int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]*1e12 z = fiber.zlocs T_surf, Z_surf = np.meshgrid(t, z) P_surf=getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)] )/np.max(getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)])) P_surf[P_surf<1e-100]=1e-100 P_surf = 10*np.log10(P_surf) P_surf[P_surf<dB_cutoff]=dB_cutoff surf = ax.plot_surface(T_surf, Z_surf, P_surf, cmap=cm.viridis, linewidth=0, antialiased=False) ax.set_xlabel('Time [ps]') ax.set_ylabel('Distance [m]') fig.colorbar(surf, shrink=0.5, aspect=5) saveplot('pulse_evo_3D',**kwargs) plt.show()
def plotPulseChirp2D(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int,**kwargs): fig, ax = plt.subplots() ax.set_title('Pulse Chirp Evolution') t = sim.t[int(sim_config.number_of_points/2-nrange):int(sim_config.number_of_points/2+nrange)]*1e12 z = fiber.zlocs T, Z = np.meshgrid(t, z)
Cmatrix=np.ones( (len(z),len(t)) )*1.0
for i in range(fiber.ntraces): Cmatrix[i,:]=getChirp(t/1e12,matrix[i,int(sim_config.number_of_points/2-nrange):int(sim_config.number_of_points/2+nrange)])/1e9
for kw, value in kwargs.items(): if kw.lower()=='chirpplotrange' and type(value)==tuple: Cmatrix[Cmatrix<value[0]]=value[0] Cmatrix[Cmatrix>value[1]]=value[1]
surf=ax.contourf(T, Z, Cmatrix,levels=40,cmap='RdBu')
ax.set_xlabel('Time [ps]') ax.set_ylabel('Distance [m]') cbar=fig.colorbar(surf, ax=ax) cbar.set_label('Chirp [GHz]') saveplot('chirp_evo_2D',**kwargs) plt.show()
def plotEverythingAboutPulses(pulseMatrix,fiber:Fiber_config, sim:SIM_config, nrange:int, dB_cutoff, **kwargs):
print(' ') plotFirstAndLastPulse(pulseMatrix,fiber,sim, nrange,**kwargs) plotPulseMatrix2D(pulseMatrix,fiber,sim,nrange,dB_cutoff,**kwargs) plotPulseChirp2D(pulseMatrix,fiber,sim,nrange,**kwargs) plotPulseMatrix3D(pulseMatrix,fiber,sim,nrange,dB_cutoff,**kwargs)
print(' ')
def plotFirstAndLastSpectrum(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int,**kwargs): f=sim.f[int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]/1e9 plt.figure() plt.title("Initial spectrum and final spectrum") plt.plot(f,getPower(matrix[0,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)])*1e9,label="Initial Spectrum") plt.plot(f,getPower(matrix[-1,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)])*1e9,label="Final Spectrum") plt.xlabel("Freq. [GHz]") plt.ylabel("PSD [W/GHz]") plt.legend() saveplot('first_and_last_spectrum',**kwargs) plt.show()
def plotSpectrumMatrix2D(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int, dB_cutoff,**kwargs): fig, ax = plt.subplots() ax.set_title('Spectrum Evolution (dB scale)') f = sim.f[int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]/1e9 z = fiber.zlocs F, Z = np.meshgrid(f, z) Pf=getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)] )/np.max(getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)])) Pf[Pf<1e-100]=1e-100 Pf = 10*np.log10(Pf) Pf[Pf<dB_cutoff]=dB_cutoff surf=ax.contourf(F, Z, Pf,levels=40) ax.set_xlabel('Freq. [GHz]') ax.set_ylabel('Distance [m]') cbar=fig.colorbar(surf, ax=ax) saveplot('spectrum_evo_2D',**kwargs) plt.show()
def plotSpectrumMatrix3D(matrix,fiber:Fiber_config,sim:SIM_config, nrange:int, dB_cutoff,**kwargs): fig, ax = plt.subplots(1,1, figsize=(10,7),subplot_kw={"projection": "3d"}) plt.title("Spectrum Evolution (dB scale)")
f = sim.f[int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)]/1e9 z = fiber.zlocs F_surf, Z_surf = np.meshgrid(f, z) P_surf=getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)] )/np.max(getPower(matrix[:,int(sim.number_of_points/2-nrange):int(sim.number_of_points/2+nrange)])) P_surf[P_surf<1e-100]=1e-100 P_surf = 10*np.log10(P_surf) P_surf[P_surf<dB_cutoff]=dB_cutoff surf = ax.plot_surface(F_surf, Z_surf, P_surf, cmap=cm.viridis, linewidth=0, antialiased=False) ax.set_xlabel('Freq. [GHz]') ax.set_ylabel('Distance [m]') fig.colorbar(surf, shrink=0.5, aspect=5) saveplot('spectrum_evo_3D',**kwargs) plt.show()
def plotEverythingAboutSpectra(spectrumMatrix, fiber:Fiber_config, sim:SIM_config, nrange:int, dB_cutoff, **kwargs):
print(' ') plotFirstAndLastSpectrum(spectrumMatrix,fiber,sim, nrange,**kwargs) plotSpectrumMatrix2D(spectrumMatrix,fiber,sim,nrange,dB_cutoff,**kwargs) plotSpectrumMatrix3D(spectrumMatrix,fiber,sim,nrange,dB_cutoff,**kwargs)
print(' ')
nrange=600 cutoff=-30
plotEverythingAboutPulses(pulseMatrix,fiber,sim_config,nrange,cutoff,savename='gaussian',chirpPlotRange=(-40,40))
nrange=400 cutoff=-30 plotEverythingAboutSpectra(spectrumMatrix,fiber,sim_config,nrange,cutoff,savename='gaussian')
|