shadow4.sources package

Subpackages

Submodules

shadow4.sources.s4_electron_beam module

Defines the shadow4 electron beam.

class shadow4.sources.s4_electron_beam.S4ElectronBeam(energy_in_GeV=1.0, energy_spread=0.0, current=0.1, number_of_bunches=0, moment_xx=0.0, moment_xxp=0.0, moment_xpxp=0.0, moment_yy=0.0, moment_yyp=0.0, moment_ypyp=0.0, dispersion_x=0.0, dispersion_y=0.0, dispersionp_x=0.0, dispersionp_y=0.0)[source]

Bases: ElectronBeam

Defines an electron beam at a given point of the storage ring.

Parameters:
  • energy_in_GeV (float, optional) – The electron energy in GeV.

  • energy_spread (float, optional) – The electron energy spread (in a fraction of the energy_in_GeV).

  • current (float, optional) – The electron beam current intensity in A.

  • moment_xx (float, optional) – The <x^2> moment.

  • moment_xxp (float, optional) – The <x x’> moment.

  • moment_xpxp (float, optional) – The <x’^2> moment.

  • moment_yy (float, optional) – The <y^2> moment.

  • moment_yyp (float, optional) – The <y y’> moment.

  • moment_ypyp (float, optional) – The <y’^2> moment.

  • dispersion_x (float, optional) – The eta_x parameter, spatial dispersion

  • dispersion_y (float, optional) – The eta_y parameter, spatial dispersion

  • dispersionp_x (float, optional) – The eta’_x parameter, angular dispersion

  • dispersionp_y (float, optional) – The eta’_y parameter, angular dispersion

to_python_code()[source]

Returns the python code to create the electron beam.

Returns:

The python code.

Return type:

str

shadow4.sources.s4_light_source module

Defines the shadow4 synchrotron LightSource (the base class of beanding magnet, wiggler and undulator lightsources).

It contains an electron beam and a magnetic structure and some parameters like nrays and seed.

class shadow4.sources.s4_light_source.S4LightSource(name='Undefined', electron_beam=None, magnetic_structure=None, nrays=5000, seed=12345)[source]

Bases: LightSource

Constructor

Parameters:
  • name (str) – A name.

  • electron_beam (instance of S4ElectronBeam) – The electron beam.

  • magnetic_structure (instance of a class derived from SYNED MagneticStructre.) – The magnetic structure (bending magnet, wiggler or undulator).

  • nrays (int) – The number of rays.

  • seed (int) – The seed.

calculate_spectrum(**params)[source]

To be implemented in a derived class.

Raises:

NotImplementedError()

get_beam(**params)[source]

To be implemented in a derived class.

Raises:

NotImplementedError()

get_info()[source]

Returns specific information.

Return type:

str

get_nrays()[source]

Returns the stored number of rays.

Returns:

The number of rays.

Return type:

int

get_seed()[source]

Returns the stored seed.

Returns:

The seed.

Return type:

int

set_nrays(nrays)[source]

Defines the number of rays to be used.

Parameters:

nrays (int) – The number of rays.

set_seed(seed)[source]

Defines the Monte Carlo seed.

Parameters:

seed (int) – The seed.

to_python_code(**kwargs)[source]

Returns the python code to create the light source. To be fully defined in the derived classes.

Parameters:

**kwargs – Passed arguments

Returns:

The python code.

Return type:

str

shadow4.sources.s4_light_source_base module

Defines the a Base LightSource to support non-synchrotron sources.

class shadow4.sources.s4_light_source_base.S4LightSourceBase(name='Undefined', nrays=5000, seed=1234567)[source]

Bases: EmptyLightSource

Abstract class to support non-synchrotron light sources (e.g. geometrical source)

Parameters:
  • name (str) – A name.

  • nrays (int) – The number of rays.

  • seed (int) – The Monte Carlo seed.

calculate_spectrum(**params)[source]

To be implemented in a derived class.

Raises:

NotImplementedError()

get_beam(**params)[source]
get_info()[source]

Returns specific information.

Return type:

str

get_nrays()[source]

Returns the stored number of rays.

Returns:

The number of rays.

Return type:

int

get_seed()[source]

Returns the stored seed.

Returns:

The seed.

Return type:

int

set_nrays(nrays)[source]

Defines the number of rays to be used.

Parameters:

nrays (int) – The number of rays.

set_seed(seed)[source]

Defines the Monte Carlo seed.

Parameters:

seed (int) – The seed.

to_python_code(**kwargs)[source]

To be implemented in a derived class.

Raises:

NotImplementedError()

shadow4.sources.s4_light_source_from_beamlines module

Defines the a LightSource merging several beamlines.

class shadow4.sources.s4_light_source_from_beamlines.S4LightSourceFromBeamlines(name='Undefined', beamlines=None, ids=None, weights=None)[source]

Bases: EmptyLightSource

Class to create a light source from a S4Beam in an H5 file.

Parameters:
  • name (str, optional) – A name.

  • beamlines (list, optiona) – A list with the beamlines (instances of S4Beamline).

  • ids (list, optional) – A list with the ids or names (str).

  • weights (list, optional) – A list with the weights (float).

append_beamline(beamline, id='appended beamline', weight=1.0)[source]

Appends a beamline

Parameters:
  • beamline (instance of S4Beamline) – the beamline to be appended.

  • id (str, optional) – the beamline id.

  • weight (float, optional) – the intensity weigh for the beamline.

calculate_spectrum(**params)[source]

To be implemented in a derived class.

Raises:

NotImplementedError()

get_beam()[source]

Retirns the S4 beam.

Parameters:

copy (int) – Returns the beam stored in the class (0) or a copy of it (1).

Returns:

  • S4Beam instance

  • The S4 beam.

get_info()[source]

Returns specific information.

Return type:

str

number_of_beamlines()[source]

returns the number of beamlines.

Returns:

The number of stored beamlines.

Return type:

int

to_python_code(**kwargs)[source]

Returns the python code.

Returns:

The python code.

Return type:

str

shadow4.sources.s4_light_source_from_file module

Defines the a LightSource with a beam defined in a HDF5 file.

class shadow4.sources.s4_light_source_from_file.S4LightSourceFromFile(name='Undefined', file_name='', simulation_name='run001', beam_name='begin')[source]

Bases: EmptyLightSource

Class to create a light source from a S4Beam in an H5 file.

Parameters:
  • name (str, optional) – A name.

  • file_name (str, optional) – The name of the H5 file.

  • simulation_name (str, optional) – A name or key to define the simulation within the H5 file.

  • beam_name (str, optional) – A name or key to define the name of the beam with the simulation.

calculate_spectrum(**params)[source]

To be implemented in a derived class.

Raises:

NotImplementedError()

get_beam(copy=0)[source]

Retirns the S4 beam.

Parameters:

copy (int) – Returns the beam stored in the class (0) or a copy of it (1).

Returns:

  • S4Beam instance

  • The S4 beam.

get_info()[source]

Returns specific information.

Return type:

str

to_python_code(**kwargs)[source]

Returns the python code for calculating the geometrical source.

Returns:

The python code.

Return type:

str

Module contents