Miscellaneous Support#

Source Code Documentation#

Miscellaneous Support.

check_value_in_list(title, value, examples)

Raise ValueError exception if value is not in the list of examples.

compare_float_dicts(a1, a2[, tol])

Compare two dictionaries.

dict_device_factory(data, **kwargs)

Create a DictionaryDevice class using the supplied dictionary.

flatten_lists(xs)

Convert nested lists into single list.

get_solver(solver_name)

Load a Solver class from a named entry point.

load_yaml(text)

Load YAML from text.

load_yaml_file(file)

Return contents of a YAML file as a Python object.

roundoff(value[, digits])

Round a number to specified precision.

solver_factory(solver_name, geometry, **kwargs)

Create a Solver object with geometry and axes.

solvers()

Dictionary of available Solver classes, mapped by entry point name.

unique_name([prefix, length])

Short, unique name, first 7 (at most) characters of a unique, random uuid.

IDENTITY_MATRIX_3X3

Identity matrix, 2-D, 3 rows, 3 columns.

SOLVER_ENTRYPOINT_GROUP

Name by which hklpy2 backend Solver classes are grouped.

ConfigurationRunWrapper(*devices[, knowns])

Write configuration of supported device(s) to a bluesky run.

ConfigurationError

Custom exceptions from hklpy2.operations.configure.

ConstraintsError

Custom exceptions from hklpy2.operations.constraints.

DiffractometerError

Custom exceptions from DiffractometerBase.

LatticeError

Custom exceptions from hklpy2.operations.lattice.

OperationsError

Custom exceptions from Operations.

ReflectionError

Custom exceptions from hklpy2.operations.reflection.

SampleError

Custom exceptions from hklpy2.operations.sample.

SolverError

Custom exceptions from a Solver.

WavelengthError

Custom exceptions from hklpy2.wavelength_support.

exception hklpy2.operations.misc.ConfigurationError[source]#

Bases: Hklpy2Error

Custom exceptions from hklpy2.operations.configure.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class hklpy2.operations.misc.ConfigurationRunWrapper(*devices, knowns=None)[source]#

Bases: object

Write configuration of supported device(s) to a bluesky run.

EXAMPLE:

crw = ConfigurationRunWrapper(sim4c2)
RE.preprocessors.append(crw.wrapper)
RE(bp.rel_scan([noisy], m1, -1.2, 1.2, 11))

Disable the preprocessor:

crw.enable = False  # 'True' to enable

Remove the last preprocessor:

RE.preprocessors.pop()

Add another diffractometer:

crw.devices.append(e4cv)

device_names

Return list of configured device names.

devices

List of devices to be reported.

enable

Is it permitted to write device configuration?

known_bases

Known device base classes.

start_key

Top-level key in run's metadata dictionary.

validate(devices)

Verify all are recognized objects.

wrapper(plan)

Bluesky plan wrapper (preprocessor).

property device_names: [<class 'str'>]#

Return list of configured device names.

devices = []#

List of devices to be reported.

property enable: bool#

Is it permitted to write device configuration?

known_bases = []#

Known device base classes.

Any device (base class) that reports its configuration dictionary in the .read_configuration() method can be added to this tuple.

start_key = 'diffractometers'#

Top-level key in run’s metadata dictionary.

validate(devices) None[source]#

Verify all are recognized objects.

wrapper(plan)[source]#

Bluesky plan wrapper (preprocessor).

Writes device(s) configuration to start document metadata.

Example:

crw = ConfigurationRunWrapper(e4cv)
RE.preprocessors.append(crw.wrapper)
exception hklpy2.operations.misc.ConstraintsError[source]#

Bases: Hklpy2Error

Custom exceptions from hklpy2.operations.constraints.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception hklpy2.operations.misc.DiffractometerError[source]#

Bases: Hklpy2Error

Custom exceptions from DiffractometerBase.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

hklpy2.operations.misc.IDENTITY_MATRIX_3X3 = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]#

Identity matrix, 2-D, 3 rows, 3 columns.

exception hklpy2.operations.misc.LatticeError[source]#

Bases: Hklpy2Error

Custom exceptions from hklpy2.operations.lattice.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception hklpy2.operations.misc.OperationsError[source]#

Bases: Hklpy2Error

Custom exceptions from Operations.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception hklpy2.operations.misc.ReflectionError[source]#

Bases: Hklpy2Error

Custom exceptions from hklpy2.operations.reflection.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

hklpy2.operations.misc.SOLVER_ENTRYPOINT_GROUP = 'hklpy2.solver'#

Name by which hklpy2 backend Solver classes are grouped.

exception hklpy2.operations.misc.SampleError[source]#

Bases: Hklpy2Error

Custom exceptions from hklpy2.operations.sample.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception hklpy2.operations.misc.SolverError[source]#

Bases: Hklpy2Error

Custom exceptions from a Solver.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception hklpy2.operations.misc.WavelengthError[source]#

Bases: Hklpy2Error

Custom exceptions from hklpy2.wavelength_support.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

hklpy2.operations.misc.check_value_in_list(title, value, examples, blank_ok=False)[source]#

Raise ValueError exception if value is not in the list of examples.

hklpy2.operations.misc.compare_float_dicts(a1, a2, tol=0.0001)[source]#

Compare two dictionaries. Values are all floats.

hklpy2.operations.misc.dict_device_factory(data: dict, **kwargs)[source]#

Create a DictionaryDevice class using the supplied dictionary.

hklpy2.operations.misc.flatten_lists(xs)[source]#

Convert nested lists into single list.

https://stackoverflow.com/questions/2158395

hklpy2.operations.misc.get_solver(solver_name)[source]#

Load a Solver class from a named entry point.

import hklpy2
SolverClass = hklpy2.get_solver("hkl_soleil")
libhkl_solver = SolverClass()
hklpy2.operations.misc.load_yaml(text: str)[source]#

Load YAML from text.

hklpy2.operations.misc.load_yaml_file(file)[source]#

Return contents of a YAML file as a Python object.

hklpy2.operations.misc.roundoff(value, digits=4)[source]#

Round a number to specified precision.

hklpy2.operations.misc.solver_factory(solver_name: str, geometry: str, **kwargs)[source]#

Create a Solver object with geometry and axes.

hklpy2.operations.misc.solvers()[source]#

Dictionary of available Solver classes, mapped by entry point name.

import hklpy2
print(hklpy2.solvers())
hklpy2.operations.misc.unique_name(prefix='', length=7)[source]#

Short, unique name, first 7 (at most) characters of a unique, random uuid.