Module: calc#

Calculation support for diffractometers

default_decision_function(position, solutions)

The default decision function - returns the first solution.

UnreachableError(msg, pseudo, physical)

Position is unreachable.

CalcRecip(dtype[, engine, sample, lattice, ...])

Reciprocal space calculations

Specific Geometries

CalcE4CH(**kwargs)

Geometry: E4CH

CalcE4CV(**kwargs)

Geometry: E4CV

CalcE6C(**kwargs)

Geometry: E6C

CalcK4CV(**kwargs)

Geometry: K4CV

CalcK6C(**kwargs)

Geometry: K6C

CalcPetra3_p09_eh2(**kwargs)

Geometry: PETRA3 P09 EH2

CalcPetra3_p23_4c(**kwargs)

Geometry: PETRA3 P23 4C

CalcPetra3_p23_6c(**kwargs)

Geometry: PETRA3 P23 6C

CalcSoleilMars(**kwargs)

Geometry: SOLEIL MARS

CalcSoleilNanoscopiumRobot(**kwargs)

Geometry: SOLEIL NANOSCOPIUM ROBOT

CalcSoleilSiriusKappa(**kwargs)

Geometry: SOLEIL SIRIUS KAPPA

CalcSoleilSiriusTurret(**kwargs)

Geometry: SOLEIL SIRIUS TURRET

CalcSoleilSixsMed1p2(**kwargs)

Geometry: SOLEIL SIXS MED1+2

CalcSoleilSixsMed2p2(**kwargs)

Geometry: SOLEIL SIXS MED2+2

CalcSoleilSixsMed2p3(**kwargs)

Geometry: SOLEIL SIXS MED2+3

CalcSoleilSixsMed2p3v2(**kwargs)

Geometry: SOLEIL SIXS MED2+3 v2

CalcZaxis(**kwargs)

Geometry: ZAXIS

class hkl.calc.CalcE4CH(**kwargs)[source]#

Geometry: E4CH

class hkl.calc.CalcE4CV(**kwargs)[source]#

Geometry: E4CV

class hkl.calc.CalcE6C(**kwargs)[source]#

Geometry: E6C

class hkl.calc.CalcK4CV(**kwargs)[source]#

Geometry: K4CV

class hkl.calc.CalcK6C(**kwargs)[source]#

Geometry: K6C

class hkl.calc.CalcPetra3_p09_eh2(**kwargs)[source]#

Geometry: PETRA3 P09 EH2

class hkl.calc.CalcPetra3_p23_4c(**kwargs)[source]#

Geometry: PETRA3 P23 4C

class hkl.calc.CalcPetra3_p23_6c(**kwargs)[source]#

Geometry: PETRA3 P23 6C

class hkl.calc.CalcRecip(dtype, engine='hkl', sample='main', lattice=None, degrees=True, units='user', lock_engine=False, inverted_axes=None)[source]#

Reciprocal space calculations

add_sample(sample[, select])

Add an HklSample

calc_linear_path(start, end, n[, num_params])

Construct a trajectory from start to end with n steps (n+1 points).

energy

The energy associated with the geometry, in keV

engine

engine_locked

If set, do not allow the engine to be changed post-initialization

engines

forward(position[, engine])

Calculate real positions from pseudo positions.

forward_iter(start, end, max_iters, *[, ...])

Iteratively attempt to go from a pseudo start -> end position

geometry_name

Name of this geometry, as defined in libhkl.

geometry_table([rst])

Describe this geometry in a table.

get_path(start[, end, n, path_type])

inverse(real)

Calculate pseudo positions from real positions.

inverted_axes

The physical axis names to invert

new_sample(name[, select])

Convenience function to add a sample by name

parameters

physical_axes

Physical (real) motor positions as an OrderedDict

physical_axis_names

physical_positions

Physical (real) motor positions

Position

Dynamically-generated physical motor position class

pseudo_axes

Ordered dictionary of axis name to position

pseudo_axis_names

Pseudo axis names from the current engine

pseudo_positions

Pseudo axis positions/values from the current engine

sample

Currently selected sample.

sample_name

The name of the currently selected sample.

units

The units used for calculations

update()

Calculate the pseudo axis positions from the real axis positions

wavelength

The wavelength associated with the geometry, in angstrom

Parameters:
  • dtype (str) – Diffractometer type (usually specified by a subclass)

  • engine (str, optional) – ‘hkl’, for example

  • sample (str, optional) – Default sample name (default: ‘main’)

  • lattice (Lattice, optional) – Lattice to use with the default sample

  • degrees (bool, optional) – Use degrees instead of radians (default: True)

  • units ({'user', }) – The type of units to use internally

  • lock_engine (bool, optional) – Don’t allow the engine to be changed during the life of this object

  • inverted_axes (list, optional) – Names of axes to invert the sign

property Position#

Dynamically-generated physical motor position class

_canonical2user(canonical)[source]#

Convert canonical axis names to user (renames).

property _cfg_reciprocal#

Return reciprocal lattice to save as configuration.

_get_axis_by_name(name)[source]#

Given an axis name, return the HklParameter

Parameters:

name (str) – If a name map is specified, this is the mapped name.

_get_path_fcn(path_type)[source]#
_get_sample(name)[source]#
_invert_physical_positions(pos)[source]#

Invert the physical axis positions based on the settings

Parameters:

pos (OrderedDict) – NOTE: Modified in-place

_re_init()[source]#
_repr_info()[source]#
add_sample(sample, select=True)[source]#

Add an HklSample

Parameters:
  • sample (HklSample instance) – The sample name, or optionally an already-created HklSample instance

  • select (bool, optional) – Select the sample to focus calculations on

property axes_c#

User-defined real-space axes held constant during forward() calculation.

property axes_r#

User-defined real-space axes used for forward() calculation.

property axes_w#

User-defined real-space axes written by forward() calculation.

calc_linear_path(start, end, n, num_params=0, **kwargs)[source]#

Construct a trajectory from start to end with n steps (n+1 points).

Example (for hkl engine):

>>> e4cv.calc.calc_linear_path((1,1,0), (1,-1,0), 4, num_params=3)
[(1.0, 1.0, 0.0),
(1.0, 0.5, 0.0),
(1.0, 0.0, 0.0),
(1.0, -0.5, 0.0),
(1.0, -1.0, 0.0)]
property energy#

The energy associated with the geometry, in keV

property engine#
property engine_locked#

If set, do not allow the engine to be changed post-initialization

property engines#
forward(position, engine=None)[source]#

Calculate real positions from pseudo positions.

forward_iter(start, end, max_iters, *, threshold=0.99, decision_fcn=None)[source]#

Iteratively attempt to go from a pseudo start -> end position

For every solution failure, the position is moved back. For every success, the position is moved closer to the destination.

After up to max_iters, the position can be reached, the solutions will be returned. Otherwise, ValueError will be raised stating the last position that was reachable and the corresponding motor positions.

Parameters:
  • start (Position)

  • end (Position)

  • max_iters (int) – Maximum number of iterations

  • threshold (float, optional) – Normalized proximity to end position to stop iterating

  • decision_fcn (callable, optional) –

    Function to choose a solution from several. Defaults to picking the first solution. Here is the default decision_fcn():

    def decision(pseudo_position, solution_list):
        return solution_list[0]
    

Returns:

solutions

Return type:

list

Raises:

UnreachableError (ValueError) – Position cannot be reached The last valid HKL position and motor positions are accessible in this exception instance.

property geometry_name#

Name of this geometry, as defined in libhkl.

geometry_table(rst=False)[source]#

Describe this geometry in a table.

Parameters:

rst (bool) – When True, format using restructured text. Otherwise, use a simpler representation

get_path(start, end=None, n=100, path_type='linear', **kwargs)[source]#
inverse(real)[source]#

Calculate pseudo positions from real positions.

property inverted_axes#

The physical axis names to invert

new_sample(name, select=True, **kwargs)[source]#

Convenience function to add a sample by name

Keyword arguments are passed to the new HklSample initializer.

Parameters:
  • name (str) – The sample name

  • select (bool, optional) – Select the sample to focus calculations on

property parameters#
property physical_axes#

Physical (real) motor positions as an OrderedDict

property physical_axis_names#
property physical_positions#

Physical (real) motor positions

property pseudo_axes#

Ordered dictionary of axis name to position

property pseudo_axis_names#

Pseudo axis names from the current engine

property pseudo_positions#

Pseudo axis positions/values from the current engine

property sample#

Currently selected sample.

property sample_name#

The name of the currently selected sample.

property units#

The units used for calculations

update()[source]#

Calculate the pseudo axis positions from the real axis positions

property wavelength#

The wavelength associated with the geometry, in angstrom

class hkl.calc.CalcSoleilMars(**kwargs)[source]#

Geometry: SOLEIL MARS

class hkl.calc.CalcSoleilNanoscopiumRobot(**kwargs)[source]#

Geometry: SOLEIL NANOSCOPIUM ROBOT

class hkl.calc.CalcSoleilSiriusKappa(**kwargs)[source]#

Geometry: SOLEIL SIRIUS KAPPA

class hkl.calc.CalcSoleilSiriusTurret(**kwargs)[source]#

Geometry: SOLEIL SIRIUS TURRET

class hkl.calc.CalcSoleilSixsMed1p2(**kwargs)[source]#

Geometry: SOLEIL SIXS MED1+2

class hkl.calc.CalcSoleilSixsMed2p2(**kwargs)[source]#

Geometry: SOLEIL SIXS MED2+2

class hkl.calc.CalcSoleilSixsMed2p3(**kwargs)[source]#

Geometry: SOLEIL SIXS MED2+3

class hkl.calc.CalcZaxis(**kwargs)[source]#

Geometry: ZAXIS

exception hkl.calc.UnreachableError(msg, pseudo, physical)[source]#

Position is unreachable.

pseudo#

Last reachable pseudo position in the trajectory

Type:

sequence

physical#

Corresponding physical motor positions

Type:

sequence

hkl.calc.default_decision_function(position, solutions)[source]#

The default decision function - returns the first solution.