shadow4.beamline package

Subpackages

Submodules

shadow4.beamline.s4_beamline module

Defines the S4 beamline.

As a reminder, and following the SYNED philosophy, the S4 beamline is a container of the S4 light source and a list of S4 beamline elements.

class shadow4.beamline.s4_beamline.S4Beamline(light_source=None, beamline_elements_list=None)[source]

Bases: Beamline

Constructor.

Parameters:
  • light_source (instance of LightSource) – The light source

  • beamline_elements_list (list) – The beamline elements (each one an instance of S4BeamlineElement).

append_beamline_element(beamline_element: S4BeamlineElement)[source]

Appends a S4 beamline element.

Parameters:

beamline_element (instance of S4BeamlineElement.) – The beamline element to append.

distances_summary(file='')[source]

Returns a summary of the real distances, focal distances and orientation angles.

Return type:

str

duplicate()[source]

Returns a copy of the S4 beamline instance.

Returns:

A copy of the object instance.

Return type:

S4BeamlineElement instance

oeinfo(oe_index=None)[source]

Returns the optical element(s) information (oeinfo or mirinfo in shadow3).

Return type:

str

run_beamline(**params)[source]

Runs (performs the ray tracing) of the full beamline.

Parameters:

**params – Passed params.

Returns:

(output_beam, output_mirr) the traced beam and footprint (after the last beamline element).

Return type:

tuple

sourcinfo()[source]

Returns the source information (sourcinfo in shadow3).

Return type:

str

sysinfo(title='', comment='')[source]

Returns the system information (sysinfo in shadow3).

Return type:

str

syspositions()[source]

Returns a dictionary with the positions of the source, o.e. and images.

Returns:

dict[“source”] numpy array (icoor) with the three coordinates of source dict[“source”] numpy array (n_oe,icoor) with the three coordinates of optical elements for all elements dict[“source”] numpy array (n_oe,icoor) with the three coordinates of image positions for all elements dict[“optical_axis_x”] numpy array with the x coordinates of the optical axis dict[“optical_axis_y”] numpy array with the y coordinates of the optical axis dict[“optical_axis_z”] numpy array with the z coordinates of the optical axis

Return type:

dict

to_python_code(**kwargs)[source]

Returns the python code to create the beamline.

Parameters:
  • partial_code (int) – set to 0: returns full beamline (default), 1: returns only source, 2: returns only beamline elements.

  • **kwargs – Passed arguments.

Returns:

The python code.

Return type:

str

shadow4.beamline.s4_beamline_element module

Defines the S4 beamline element.

The S4 beamline element is a container with: - The (SYNED) optical element (OpticalElement) - The (SYNED) element coordinates (ElementCoordinates) - The S4 element movements (S4BeamlineElementMovements) - The S4 beam to be received by te element (S4Beam)

class shadow4.beamline.s4_beamline_element.S4BeamlineElement(optical_element: OpticalElement = None, coordinates: ElementCoordinates = None, movements: S4BeamlineElementMovements = None, input_beam: S4Beam = None)[source]

Bases: BeamlineElement

Constructor.

Parameters:
  • optical_element (instance of OpticalElement, optional) – The syned optical element.

  • coordinates (instance of ElementCoordinates, optional) – The syned element coordinates.

  • movements (instance of S4BeamlineElementMovements, optional) – The S4 element movements.

  • input_beam (instance of S4Beam, optional) – The S4 incident beam.

get_input_beam()[source]

Returns the input beam.

Return type:

instance of S4Beam

get_movements()[source]

Returns the element movements.

Return type:

instance of S4BeamlineElementMovements

info()[source]

Gets the information text (syned doc).

Returns:

A info text for the S4 beamline element.

Return type:

str

set_input_beam(input_beam)[source]

Sets the input beam. :param input_beam: The input beam. :type input_beam: instance of S4Beam

set_movements(movements)[source]

Sets the element movements.

Parameters:

movements (instance of S4BeamlineElementMovements) – The descriptod of the movements.

to_python_code(**kwargs)[source]

Returns the python code to describe and run th eelement. To be implemented in the derived classes.

Parameters:

**kwargs – The arguments to pass.

Raises:

NotImplementedError

to_python_code_coordinates()[source]

Returns a code block to implement the element coordinates (to be used by the upper classes).

Returns:

A code block.

Return type:

str

to_python_code_movements()[source]

Returns a code block to implement the element movements (to be used by the upper classes).

Returns:

A code block.

Return type:

str

trace_beam(**params)[source]

Performs the ray tracing (trace). To be implemented in the derived classes.

Parameters:

**params

Raises:

NotImplementedError

shadow4.beamline.s4_beamline_element_movements module

Container for the variables describing the movements of a S4 beamline element.

class shadow4.beamline.s4_beamline_element_movements.S4BeamlineElementMovements(f_move=0, offset_x=0.0, offset_y=0.0, offset_z=0.0, rotation_x=0.0, rotation_y=0.0, rotation_z=0.0)[source]

Bases: object

Constructor.

Parameters:
  • f_move (int, optional) – flag to apply movements: 0=No, 1=yes.

  • offset_x (float, optional) – The offset in X direction in m.

  • offset_y (float, optional) – The offset in Y direction in m.

  • offset_z (float, optional) – The offset in Z direction in m.

  • rotation_x (float, optional) – The rotation angle around the X axis in rad.

  • rotation_y (float, optional) – The rotation angle around the Y axis in rad.

  • rotation_z (float, optional) – The rotation angle around the Z axis in rad.

get_offsets()[source]

Returns the offsets.

Returns:

(offset_x, offset_y, offset_z) the offsets along X, Y, and Z.

Return type:

tuple

get_rotations()[source]

Returns the rotation angles.

Returns:

(rotation_x, rotation_y, rotation_z) the rotations around X, Y, and Z axes.

Return type:

tuple

shadow4.beamline.s4_optical_element_decorators module

Defines the functionality for shadow4 optical elements.

Map:

S4OpticalElementDecorator—–

|—–S4PlaneOpticalElementDecorator |—–S4CurvedOpticalElementDecorator—

|—– S4SphereOpticalElementDecorator |—– S4EllipsoidOpticalElementDecorator |—– S4HyperboloidOpticalElementDecorator |—– S4ToroidOpticalElementDecorator |—– S4ParaboloidOpticalElementDecorator |—– S4ConicOpticalElementDecorator |—– S4NumericalMeshOpticalElementDecorator |—– S4RefractiveLensOpticalElementDecorator

Basically it adds some methods:

  • get_info: to be overloaded with specific info for a particular optical element.

  • to_python_code: to be overloaded to create the python code for the specifoc optical element.

  • get_surface_shape_instance: returns the SYNED shape instance.

  • get_optical_surface_instance: returns the S4 optical surface instance.

class shadow4.beamline.s4_optical_element_decorators.S4ConicOpticalElementDecorator(conic_coefficients=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0])[source]

Bases: S4CurvedOpticalElementDecorator

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Conic

class shadow4.beamline.s4_optical_element_decorators.S4CurvedOpticalElementDecorator(surface_calculation=0, is_cylinder=False, curved_surface_shape=None)[source]

Bases: S4OpticalElementDecorator

Creates the shadow4 optical element decorator for a curved surface.

Parameters:
  • surface_calculation (int, optional) –

    flag:
    • 0 = SurfaceCalculation.INTERNAL,

    • 1 = SurfaceCalculation.EXTERNAL.

  • is_cylinder (int, optional) –

    flag:
    • 0=No (there is revolution symmetry along Y)

    • 1=Yes (flat surface along X or Y).

  • curved_surface_shape (syned shape instance, optional) –

get_surface_shape_instance()[source]

Returns the SYNED instance of type Shape.

Return type:

instance of shape class.

class shadow4.beamline.s4_optical_element_decorators.S4EllipsoidOpticalElementDecorator(surface_calculation=0, is_cylinder=False, cylinder_direction=0, convexity=0, min_axis=0.0, maj_axis=0.0, pole_to_focus=0.0, p_focus=0.0, q_focus=0.0, grazing_angle=0.0)[source]

Bases: S4CurvedOpticalElementDecorator

Creates the shadow4 optical element decorator for an Ellipsoid surface.

Parameters:
  • surface_calculation (int, optional) –

    flag:

    0 = SurfaceCalculation.INTERNAL, 1 = SurfaceCalculation.EXTERNAL.

  • is_cylinder (int, optional) –

    flag:

    0=No (there is revolution symmetry along Y) 1=Yes (flat surface along X or Y).

  • cylinder_direction (int (as defined by Direction), optional) – TANGENTIAL = 0, SAGITTAL = 1.

  • convexity (int (as defined by Convexity), optional) – NONE = -1, UPWARD = 0, DOWNWARD = 1.

  • min_axis (float, optional) – For surface_calculation=0, The minor axis of the ellipsoid (2a).

  • maj_axis (float, optional) – For surface_calculation=0, The major axis of the ellipsoid (2b)

  • pole_to_focus (float, optional) – For surface_calculation=0, the p or q distance (from focus to center of the optical element).

  • p_focus (float, optional) – For surface_calculation=1,2, the p distance (from source plane to center of the optical element).

  • q_focus (float, optional) – For surface_calculation=1, the q distance (from the center of the optical element to the image plane).

  • grazing_angle (float, optional) – For surface_calculation=1, the grazing angle in rad.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Conic

class shadow4.beamline.s4_optical_element_decorators.S4HyperboloidOpticalElementDecorator(surface_calculation=0, is_cylinder=False, cylinder_direction=0, convexity=0, min_axis=0.0, maj_axis=0.0, pole_to_focus=0.0, p_focus=0.0, q_focus=0.0, grazing_angle=0.0)[source]

Bases: S4CurvedOpticalElementDecorator

Creates the shadow4 optical element decorator for an Hyperboloid surface.

Parameters:
  • surface_calculation (int, optional) –

    flag:

    0 = SurfaceCalculation.INTERNAL, 1 = SurfaceCalculation.EXTERNAL.

  • is_cylinder (int, optional) –

    flag:

    0=No (there is revolution symmetry along Y) 1=Yes (flat surface along X or Y).

  • cylinder_direction (int (as defined by Direction), optional) – NONE = -1, UPWARD = 0, DOWNWARD = 1.

  • convexity (int (as defined by Convexity), optional) – NONE = -1, UPWARD = 0, DOWNWARD = 1.

  • min_axis (float, optional) – For surface_calculation=0, The minor axis of the ellipsoid (2a).

  • maj_axis (float, optional) – For surface_calculation=0, The major axis of the ellipsoid (2b)

  • pole_to_focus (float, optional) – For surface_calculation=0, the p or q distance (from focus to center of the optical element).

  • p_focus (float, optional) – For surface_calculation=1,2, the p distance (from source plane to center of the optical element).

  • q_focus (float, optional) – For surface_calculation=1, the q distance (from the center of the optical element to the image plane).

  • grazing_angle (float, optional) – For surface_calculation=1, the grazing angle in rad.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Conic

class shadow4.beamline.s4_optical_element_decorators.S4NumericalMeshOpticalElementDecorator(xx=None, yy=None, zz=None, surface_data_file=None)[source]

Bases: S4CurvedOpticalElementDecorator

Creates the shadow4 optical element decorator for a Mesh surface.

Parameters:
  • xx (ndarray, optional) – the 1D array with the X points.

  • yy (ndarray, optional) – the 1D array with the Y points.

  • zz (ndarray, optional) – the 2D [shape Nx,Ny] array with the Z points.

  • surface_data_file (str, optional) – the name of the h5 file with the mesh.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Mesh

class shadow4.beamline.s4_optical_element_decorators.S4OpticalElementDecorator[source]

Bases: object

Base abstract class.

get_info()[source]

Returns string containing some specific information of the shadow4 optical element.

Return type:

str

get_optical_surface_instance()[source]

Returns a object of type S4OpticalSurface.

Raises:

NotImplementedError.

get_surface_shape_instance()[source]

Returns a SYNED object of type Shape.

Raises:

NotImplementedError.

interthickness()[source]

Returns the interthickness of the beamline element, which is the distance covered by the element along the optical axis. Elements with a single optical surface (mirrors, crystals, etc.) have interthickness zero. This is the value returned here. Elements like lenses, CRL, transfocators, etc. have interthickness > 0. They have to redefine this method. Note that the interthickness is the projection along the (image) optical axis.

Return type:

float

to_python_code(**kwargs)[source]

Returns string containing python code to create shadow4 optical element.

Raises:

NotImplementedError.

class shadow4.beamline.s4_optical_element_decorators.S4ParaboloidOpticalElementDecorator(surface_calculation=0, is_cylinder=False, cylinder_direction=0, convexity=0, parabola_parameter=0.0, at_infinity=0, pole_to_focus=0.0, p_focus=0.0, q_focus=0.0, grazing_angle=0.0)[source]

Bases: S4CurvedOpticalElementDecorator

Creates the shadow4 optical element decorator for an Paraboloid surface.

Parameters:
  • surface_calculation (int, optional) –

    flag:

    0 = SurfaceCalculation.INTERNAL, 1 = SurfaceCalculation.EXTERNAL.

  • is_cylinder (int, optional) –

    flag:

    0=No (there is revolution symmetry along Y) 1=Yes (flat surface along X or Y).

  • cylinder_direction (int (as defined by Direction), optional) – NONE = -1, UPWARD = 0, DOWNWARD = 1.

  • convexity (int (as defined by Convexity), optional) – NONE = -1, UPWARD = 0, DOWNWARD = 1.

  • parabola_parameter (float, optional) – For surface_calculation=0, The parabola parameter PARAM (y^2 = 2 PARAM z)

  • at_infinity (int, optional) –

    For surface_calculation=0, flag to indicate that

    0: the source is at infinity (focusing paraboloid) = Side.SOURCE. 1: the image is at infinity (collimating paraboloid) = Side.IMAGE.

  • pole_to_focus (float, optional) – For surface_calculation=0, the p or q distance (from focus to center of the optical element).

  • p_focus (float, optional) – For surface_calculation=1, the q distance (from source plane to the center of the optical element).

  • q_focus (float, optional) – For surface_calculation=1, the q distance (from the center of the optical element to the image plane).

  • grazing_angle (float, optional) – For surface_calculation=1, the grazing angle in rad.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Conic

class shadow4.beamline.s4_optical_element_decorators.S4PlaneOpticalElementDecorator[source]

Bases: S4OpticalElementDecorator

Creates the shadow4 optical element decorator for a plane surface.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Conic

get_surface_shape_instance()[source]

Returns the SYNED instance of type Shape.

Return type:

instance of syned.beamline.shape.Plane

class shadow4.beamline.s4_optical_element_decorators.S4RefractiveLensOpticalElementDecorator(surface_shape=1, convex_to_the_beam=1, cylinder_angle=0, ri_calculation_mode=0, prerefl_file=None, refraction_index=1.0, attenuation_coefficient=0.0, density=1.0, dabax=None, radius=0.0005, conic_coefficients1=None, conic_coefficients2=None)[source]

Bases: S4CurvedOpticalElementDecorator

Creates the shadow4 optical element decorator for a Refractive lens.

Parameters:
  • surface_shape (int, optional) – Flag for the single lens surface shape: 0=plane, 1=sphere, 2=parabola, 3=conic coefficients

  • convex_to_the_beam (int, optional) – Flag for convexity of the first interface exposed to the beam For surface_shape (1,2): 0=No, 1=Yes, or in other words 0=Concave, 1=Convex

  • cylinder_angle (int, optional) – Flag for cylindrical symmetry. For surface_shape (1,2): 0=not cylindricaL, 1=meridional 2=sagittal

  • ri_calculation_mode (int, optional) –

    Flag for the used source of refraction indices and absorption coefficients:

    0=User 1=prerefl file 2=direct calculation using xraylib 3=direct calculation using dabax

  • prerefl_file (str, optional) – For ri_calculation_mode=0: file name (from prerefl) to get the refraction index.

  • refraction_index (float, optional) – For ri_calculation_mode=1: the real part of the refraction coefficient Real[n].

  • attenuation_coefficient (float, optional) – For ri_calculation_mode=1: the linear absorption coefficient, in cm^-1 (real)..=

  • dabax (None or instance of DabaxXraylib,) – The pointer to the dabax library (used for f_r_ind > 6).

  • radius (float, optional) – For surface_shape=(1,2): lens radius [m] (for spherical, or radius at the tip for paraboloid).

  • conic_coefficients1 (list or ndarray, optional) – For surface_shape = 3: the 10 conic coefficients of the first refractive interface.

  • conic_coefficients2 (list or ndarray, optional) – For surface_shape = 3: the 10 conic coefficients of the second refractive interface.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Returns:

instances of shadow4.s4_optical_surfaces.s4_conic.S4Conic

Return type:

list

class shadow4.beamline.s4_optical_element_decorators.S4SphereOpticalElementDecorator(surface_calculation=0, is_cylinder=False, cylinder_direction=0, convexity=0, radius=0.0, p_focus=0.0, q_focus=0.0, grazing_angle=0.0)[source]

Bases: S4CurvedOpticalElementDecorator

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Conic

class shadow4.beamline.s4_optical_element_decorators.S4ToroidOpticalElementDecorator(surface_calculation=0, min_radius=0.0, maj_radius=0.0, f_torus=0, p_focus=0.0, q_focus=0.0, grazing_angle=0.0)[source]

Bases: S4CurvedOpticalElementDecorator

Creates the shadow4 optical element decorator for an Toroid surface.

Parameters:
  • surface_calculation (int, optional) –

    flag:

    0 = SurfaceCalculation.INTERNAL, 1 = SurfaceCalculation.EXTERNAL.

  • min_radius (float, optional) – The minor axis of the toroid in m.

  • maj_radius (float, optional) – The surface major radius in m. Note that this is the radius of the optical surface (it is not the radius of the toroid).

  • f_torus (int, optional) –

  • p_focus (float, optional) – For surface_calculation=1, the p distance (from source plane to center of the optical element).

  • q_focus (float, optional) – For surface_calculation=1, the q distance (from the center of the optical element to the image plane).

  • grazing_angle (float, optional) – For surface_calculation=1, the grazing angle in rad.

get_optical_surface_instance()[source]

Returns a shadow4 optical element object of type optical surface.

Return type:

instance of shadow4.s4_optical_surfaces.s4_conic.S4Toroid

class shadow4.beamline.s4_optical_element_decorators.SurfaceCalculation[source]

Bases: object

class supporting the flag for external or internal calculation:

  • INTERNAL = 0

  • EXTERNAL = 1

EXTERNAL = 1
INTERNAL = 0

Module contents