In [3]:
"""
Example 8
- calculate a Wigner function on the vertical (y,'y) phase space
- load the Wigner function and perform CMD (coherent mode decomposition)
"""
import sys
isjupyter = "ipykernel" in sys.modules
import spectra
if isjupyter:
spectra.Start(mode="c")
import plotly.io as pio
pio.renderers.default = "notebook"
else:
spectra.Start(src="l")
spectra.Open("sample.json")
spectra.SelectBL("X-ray-BL")
# flux spatial profile
spectra.SelectCalculation("srcpoint", "wigner", "phasespace", "YYpprj")
# transverse range auto configuration
spectra.Set("config", "autot", True)
# compute the Wigner function
spectra.StartCalculation(folder="./output", prefix="sample8", serial=1)
# load the Wigner function for CMD
spectra.LoadWigner4CMD("./output/sample8-1.json")
# export the modal profile with finer grid and wider range
spectra.Set("config", "CMDfld", "JSON")
spectra.Set("config", "fieldrangey", 0.05)
spectra.Set("config", "fieldgridy", 0.0005)
# perform CMD
spectra.StartCalculation(prefix="sample8", serial=2)
# check modal intensity
if isjupyter:
from IPython.display import display, HTML
display(HTML("<h2>CMD result: integrated modal flux"))
spectra.PostProcessCLI.Plot(data="sample8-2", item="Integrated Modal Flux")
else:
spectra.ShowPostProcessor()
spectra.PostProcess.Plot("Integrated Modal Flux")
spectra.PostProcess.DuplicatePlot("Integrated Modal Flux")
# check modal intensity
if isjupyter:
display(HTML("<h2>CMD result: spatial profile of each mode"))
spectra.PostProcessCLI.Plot(type="Modal Profile", item="Modal Amplitude Real")
else:
spectra.PostProcess.SetDataType("Modal Profile")
spectra.PostProcess.Plot("Modal Amplitude Real")
if not isjupyter:
input("Completed. Press enter to exit. ")
spectra.Exit()
Calculation failed or output file is invalid.
CMD result: integrated modal flux
Data sample8-2 not found in the stored list
CMD result: spatial profile of each mode
Invalid name "Modal Amplitude Real". Should be one of ['Prj. Brilliance']
In [ ]: