In [1]:
"""
Example 4

- examine how to improve the numerical accuracy
"""

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")
spectra.SelectCalculation("near", "energy", "pflux", "slitrect")
if not isjupyter:
    spectra.FitWindow()
spectra.Set("src", "e1st", 10000)
spectra.Set("config", "erange", [9000, 11000])

# modify aperture conditions
spectra.Set("config", "slit_dist", 5)
spectra.Set("config", "slitapt", [0.4, 0.4])

spectra.StartCalculation(folder="./output", prefix="sample4", serial=1)

# try to improve the numerical accuracy
spectra.Set("config", "accuracy", "Custom")
# "accinobs" = Integration Step in Transverse Grid (default = 1)
spectra.SetAccuracy("accinobs", 2)
# "acclimobs" = Integration Range in Transverse Grid (default = 1)
spectra.SetAccuracy("acclimobs", 2)
spectra.StartCalculation() # needs a bit more CPU time

# compare the result
if isjupyter:
    from IPython.display import display, HTML
    display(HTML("<h2>Example to improve the calculation accuracy"))
    spectra.PostProcessCLI.Plot(data=["sample4-1", "sample4-2"])
else:
    spectra.ShowPostProcessor()
    spectra.PostProcess.SelectData("sample4-1")
    spectra.PostProcess.ComparativePlot("sample4-2")

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

Example to improve the calculation accuracy

In [ ]: