In [1]:
"""
Example 6

- scan a parameter and visualize the result as an animation in the post-processor
- variation of the spatial profile as the change of the photon energy
"""

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("far", "spatial", "fdensa", "meshxy")

# define the photon energy by the normalized value (by e1st)
spectra.Set("config", "normenergy", True) 

# expand the observation range
spectra.Set("config", "xrange", [-1.5, 1.5]) 
spectra.Set("config", "yrange", [-1.5, 1.5]) 

# scan the photon energy to observe
spectra.Scan("config", "nefix", 0.9, 1.05, 21, folder="./output", prefix="sample6", serial=-1)

# visualize the results
if isjupyter:
    from IPython.display import display, HTML
    display(HTML("<h2>Animation to show how the spatial profile changes"))
    spectra.ConfigurePlot(normalize="For Each", type2d="Surface (Color Map)")
    spectra.PostProcessCLI.Plot()
else:
    spectra.PostProcess.SurfacePlot()
    spectra.PostProcess.NormalizePlot(True)
    spectra.PostProcess.StartAnimation()

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

Animation to show how the spatial profile changes

In [ ]: