reflection#

Import: ad_hoc_diffractometer.reflection

A Reflection stores the Miller indices (hkl), the diffractometer motor angles at which the reflection was observed, the wavelength used, and the name of the geometry on which it was recorded.

A ReflectionList owns an ordered dict of named Reflection objects and manages the primary (or1) and secondary (or2) orienting designations. It is held as AdHocDiffractometer.reflections.

Typical usage:

g = psic()
rl = g.reflections                          # ReflectionList
r1 = rl.add("r1", hkl=(1, 0, 0),
             angles={"mu": 0, "eta": 20, ...},
             valid_stages=set(g._stages))
r2 = rl.add("r2", hkl=(0, 1, 0), ...)
rl.setor0("r1")
rl.setor1("r2")
rl.orienting_reflections   # -> [r1, r2]
rl["r1"]                   # -> r1
del rl["r1"]
rl.clear()

Classes#

Reflection

One observed reflection used for diffractometer orientation.

ReflectionList

Ordered, named collection of Reflection objects with or1/or2 management.

Module Contents#

class ad_hoc_diffractometer.reflection.Reflection[source]#

Import: ad_hoc_diffractometer.reflection.Reflection

One observed reflection used for diffractometer orientation.

Parameters:
  • name (str) – User-supplied label (e.g. "r1", "Si_111"). Set by ReflectionList.add().

  • hkl (tuple of float) – Miller indices (h, k, l). Need not be integers.

  • angles (dict[str, float]) – Motor angles (degrees) keyed by stage name. Keys are specific to the geometry named in geometry_name and are validated by ReflectionList.add() before the reflection is stored.

  • wavelength (float or None) – Wavelength in Å. If None the geometry’s wavelength is assumed.

  • geometry_name (str or None) – Name of the geometry on which this reflection was recorded. Angle keys are only meaningful for that geometry.

Notes

Reflections are geometry-specific: angle keys from a psic geometry cannot be applied to kappa6c because the stage names differ. ReflectionList.add() validates keys and records geometry_name so cross-geometry misuse can be detected.

angles: dict[str, float]#
classmethod from_dict(d: dict) Reflection[source]#

Reconstruct a Reflection from a dict produced by to_dict().

Parameters:

d (dict) – Must contain "name", "hkl", "angles". "wavelength" and "geometry_name" are optional (default None).

Return type:

Reflection

geometry_name: str | None = None#
hkl: tuple[float, float, float]#
name: str#
to_dict() dict[source]#

Return a JSON-serialisable dict representing this reflection.

Returns:

Keys: "name" (str), "hkl" (list of 3 float), "angles" (dict str→float), "wavelength" (float or None), "geometry_name" (str or None).

Return type:

dict

wavelength: float | None = None#
class ad_hoc_diffractometer.reflection.ReflectionList(geometry_name: str, valid_stages: set[str])[source]#

Import: ad_hoc_diffractometer.reflection.ReflectionList

Ordered, named collection of Reflection objects with or1/or2 management.

Held as AdHocDiffractometer.reflections. All mutation methods validate that angle keys belong to the owning geometry.

Parameters:
  • geometry_name (str) – Name of the owning AdHocDiffractometer. Stored on every reflection added through this list.

  • valid_stages (set of str) – Stage names of the owning geometry. Used to validate angle keys.

Examples

>>> rl = ReflectionList(geometry_name="psic",
...                     valid_stages={"mu", "eta", "chi", "phi",
...                                   "nu", "delta"})
>>> r = rl.add("r1", hkl=(1, 0, 0), angles={"mu": 0, "eta": 20})
>>> rl.setor0("r1")
>>> rl.orienting_reflections
[Reflection(name='r1', ...)]
_resolve(reflection: str | Reflection) str[source]#

Return the name of a reflection given a name or object.

add(name: str, hkl: tuple[float, float, float], angles: dict[str, float], wavelength: float | None = None) Reflection[source]#

Add a named reflection, validate angle keys, and return it.

Parameters:
  • name (str) – Unique label.

  • hkl (tuple of float) – Miller indices.

  • angles (dict[str, float]) – Motor angles; keys must be stage names of this geometry.

  • wavelength (float or None) – Wavelength in Å; stored as-is (caller supplies the geometry’s current wavelength if desired).

Raises:

ValueError – If name already exists or any angle key is not a valid stage.

clear() None[source]#

Remove all reflections and clear or1/or2 designations.

classmethod from_dict(d: dict) ReflectionList[source]#

Reconstruct a ReflectionList from a dict produced by to_dict().

Parameters:

d (dict) – Must contain "reflections" (list of reflection dicts). "geometry_name", "or1", and "or2" are optional.

Return type:

ReflectionList

geometry_name#
items()[source]#
keys()[source]#
property orienting_reflections: list[Reflection]#

Ordered list of designated orienting reflections.

Returns [], [or1], or [or1, or2]. A secondary without a primary is returned as a single-element list containing the secondary.

remove(name: str) None[source]#

Remove the named reflection and clear any or1/or2 designation it held.

Raises:

KeyError – If no reflection with that name exists.

setor0(reflection: str | Reflection) None[source]#

Designate a reflection as primary (or1 slot, SPEC setor0).

If it was previously the secondary (or2), that designation is cleared. The previous or1 remains in the list without any designation.

setor1(reflection: str | Reflection) None[source]#

Designate a reflection as secondary (or2 slot, SPEC setor1).

If it was previously the primary (or1), that designation is cleared. The previous or2 remains in the list without any designation.

to_dict() dict[source]#

Return a JSON-serialisable dict representing this reflection list.

Returns:

Keys: "geometry_name" (str or None), "reflections" (list of reflection dicts in insertion order), "or1" (name str or None), "or2" (name str or None).

Return type:

dict

valid_stages#
values()[source]#