In [3]:
"""
Example 4

- shot-to-shot fluctuation of SASE FEL simulated by varying the seed number for the random number
- compare the gain curve and spectral/temporal profiles
"""

import sys
isjupyter = "ipykernel" in sys.modules

import simplex 

if isjupyter:
    simplex.Start(mode="c") 
    import plotly.io as pio
    pio.renderers.default = "notebook" # to enable exporting as an HTML file
    from IPython.display import display, HTML
else:
    simplex.Start() 

# open "sample.json" in the current directory
simplex.Open("sample_sase.json")

# export the temporal and spectral proiles
simplex.Set("datadump", "temporal", True)
simplex.Set("datadump", "spectral", True)

# number of shots
Nshots = 5

# scan the random number seed to simulate the shot-to-shot fluctuation
simplex.Scan("condition", "randseed", 1, Nshots, interval=1, folder="./output", prefix="sample4", iniSN=1)

# data names 
datanames = []
for n in range(Nshots):
    datanames.append("sample4"+"_"+str(n+1))

if isjupyter:
    display(HTML("<h2>Gain Curve of SASE FEL"))
    simplex.PostProcessCLI.Plot(data=datanames, item="Pulse Energy", config={"yscale":"Logarithmic"})
    display(HTML("<h2>Temporal Profiles"))
    simplex.PostProcessCLI.Plot(data=datanames, item="Temporal Profile")
    display(HTML("<h2>Spectral Profiles"))
    simplex.PostProcessCLI.Plot(data=datanames, item="Temporal Profile")
else:
    simplex.PostProcess.SelectData("sample4_1")
    # gain curves
    simplex.PostProcess.Plot("Pulse Energy")
    simplex.PostProcess.ComparativePlot(*datanames)
    simplex.PostProcess.PlotScale(y="log")
    simplex.PostProcess.DuplicatePlot("Shot-to-shot fluctuation of the gain curve")
    # temporal profiles
    simplex.PostProcess.Plot("Temporal Profile")
    simplex.PostProcess.ComparativePlot(*datanames)
    simplex.PostProcess.SetSlide(-1)
    simplex.PostProcess.DuplicatePlot("Shot-to-shot fluctuation of the temporal profile")
    # temporal profiles
    simplex.PostProcess.Plot("Spectral Profile")
    simplex.PostProcess.ComparativePlot(*datanames)
    simplex.PostProcess.SetSlide(-1)
    simplex.PostProcess.DuplicatePlot("Shot-to-shot fluctuation of the spectral profile")

if not isjupyter:
    input("Completed. Press enter to exit. ")
    simplex.Exit()
                                                  

Gain Curve of SASE FEL

Temporal Profiles

Spectral Profiles

In [ ]: