In [1]:
"""
Example 1
- calculate spectra of undulator radiation with three different observation positions
- compare the three in the post-processor and export an ASCII file
"""
import sys
isjupyter = "ipykernel" in sys.modules
import spectra
if isjupyter:
# start with CLI mode
spectra.Start(mode="c")
import plotly.io as pio
pio.renderers.default = "notebook" # to enable exporting as an HTML file
else:
# start with default settings
# Mode = interactive, Browser = Chrome, Source Files = remote
spectra.Start()
# open "sample.json" in the current directory
spectra.Open("sample.json")
if isjupyter:
# display the parameters
from IPython.display import display, HTML
display(HTML("<h2> Parameters and configurations"))
spectra.DisplayParameters(fontfamily="arial", fontsize="10px")
# select calculation: "Far Field & Ideal Condition::Energy Dependence::Angular Flux Density"
spectra.SelectCalculation("far", "energy", "fdensa")
# start calculation with an output file of "./output/sample1-1.json"
spectra.StartCalculation(folder="./output", prefix="sample1", serial=1)
# check the result; plot the spectrum of angular flux density
if isjupyter:
display(HTML("<h2> Example of undulator-radiation spectrum"))
spectra.PostProcessCLI.Plot(item="Flux Density")
else:
spectra.ShowPostProcessor()
# change the paramter, vertical position shifted to y=1mm
spectra.Set("config", "xyfix", [0, 1])
# start calculation with an output file of "sample1-2.json"
# same folder and prefix
# serial number automatically incremented
spectra.StartCalculation()
# horizontal position shifted to x=1mm; output file "sample1-3.json"
spectra.Set("config", "xyfix", [1, 0])
spectra.StartCalculation()
# check the result; compare with the former result
if isjupyter:
display(HTML("<h2> Comparison between three different observation positions"))
spectra.PostProcessCLI.Plot(data=["sample1-1", "sample1-2", "sample1-3"], item="Flux Density")
spectra.PostProcessCLI.Plot(data=["sample1-1", "sample1-2", "sample1-3"], item="Flux Density", xrange=[5000,6500])
else:
spectra.PostProcess.SelectData("sample1-1")
spectra.PostProcess.ComparativePlot("sample1-2", "sample1-3")
spectra.PostProcess.DuplicatePlot()
# export the comparative plot as an ASCII file
spectra.PostProcess.Export("./output/comparative.txt")
# expand the fundamental radiation
spectra.PostProcess.PlotRange(x=[5000,6500])
if not isjupyter:
# wait for the user's response
input("Completed. Press enter to exit. ")
# exit
spectra.Exit()
Parameters and configurations
Accelerator
Type
Storage Ring
Energy (GeV)
8
Current (mA)
100
Circumference (m)
1436
Bunches
203
σz (mm)
3.9
Nat. Emittance (m.rad)
2.4e-09
Coupling Constant
0.002
Energy Spread
0.0011
βx,y (m)
31.2, 5
αx,y
0, 0
ηx,y (m)
0.146, 0
η'x,y
0, 0
Peak Current (A)
72.358
εx,y (m.rad)
2.3952e-09, 4.7904e-12
σx,y (mm)
0.31705, 0.0048941
σ'x,y (mrad)
0.0087618, 0.00097882
γ-1 (mrad)
0.063875
Zero Emittance
False
Zero Energy Spread
False
Light Source
Type
Linear Undulator
Gap (mm)
10.737
B (T)
0.66936
λu (mm)
32
Device Length (m)
4.564
Reg. Magnet Length (m)
4.48
# of Reg. Periods
140
K value
2
ε1st (eV)
6330.9
λ1st (nm)
0.19584
σr,r' (mm,mrad)
0.0033335, 0.0046752
Σx,x' (mm,mrad)
0.31707, 0.0099311
Σy,y' (mm,mrad)
0.0059215, 0.0047765
Flux1st
8.7202e+14
Brilliance1st
2.4801e+20
Peak Brilliance
1.7946e+23
Bose Degeneracy
0.56202
Total Power (kW)
8.1277
Gap-Field Relation
Import Table
Gap vs. Field
End Correction Magnet
True
Segmentation
None
Configurations
Distance from the Source (m)
30
Target Energy (eV)
6330.9
Auto Config. for Transverse Range
False
x Range (mm)
-1, 1
Points (x)
41
y Range (mm)
-0.5, 0.5
Points (y)
51
Σx,y@ε1st (mm)
0.43508, 0.14342
Define Obs. Point in
Position
Normalize Photon Energy
False
Accuracy
Default
Example of undulator-radiation spectrum
Comparison between three different observation positions
In [ ]: