Undulator Spectrum

This is a simple example of how to calculate a spectrum from an undulator.

In [1]:
# Plots inline for notebook
%matplotlib inline

# Import the OSCARS SR module
import oscars.sr
OSCARS v2.1.8 - Open Source Code for Advanced Radiation Simulation
Brookhaven National Laboratory, Upton NY, USA
http://oscars.bnl.gov
oscars@bnl.gov
In [2]:
# Create a new OSCARS object.  Default to 8 threads and always use the GPU if available
osr = oscars.sr.sr(nthreads=8, gpu=1)

Undulator Field

Create a simple undulator field

In [3]:
# Clear all existing fields and create an undulator field
osr.clear_bfields()
osr.add_bfield_undulator(bfield=[0, 1, 0], period=[0, 0, 0.050], nperiods=31)

Particle Beam and Trajectory

Define a particle beam, in this case a 3 [GeV] electron beam. You must also define the start and stop times for the calculation.

In [4]:
# Define simple electron beam
osr.set_particle_beam(energy_GeV=3, x0=[0, 0, -1], current=0.5)

# Define the start and stop times for the calculation
osr.set_ctstartstop(0, 2)

Calculate Spectrum

Calculate the spectrum 30 [m] downstream from the center of the device

In [5]:
# Calculate spectrum at 30 [m]
spectrum = osr.calculate_spectrum(obs=[0, 0, 30], energy_range_eV=[100, 2000])

Plot Spectrum

With the oscars.plots_mpl module you can plot the spectrum (and many other things)

In [6]:
# Optionally import the plotting tools (matplotlib)
from oscars.plots_mpl import *

# Plot spectrum
plot_spectrum(spectrum)