plesty.pol_pl.rig
Instrument composite (rig) for the polarization-dependent PL experiment.
Wires the two remote device servers of the measurement into one
CompositeDevice:
hwp— Thorlabs K10CR1 rotation stage carrying the half-wave plate in the detection path, in front of a fixed polarizer (plesty-k10cr1),spec— Princeton Instruments LightField spectrometer (plesty-lightfield-spectrometer).
Everything the composite already does is used rather than repeated: the
resilient call (timeout → reconnect → retry) and one thread per sub-device.
What is left here is the rig’s own vocabulary: home the plate, move it, set up
an acquisition, acquire a spectrum. The experiment layer never issues a raw
device command.
The instruments and their operation budgets are declared in the packaged
config.yaml; the server addresses come from the environment. Neither is
written in this file.
Frame data never crosses the transport: the spectrometer writes each .spe
to the data path the run routed it to, and reports only the file path.
Attributes
Classes
Half-wave-plate rotation stage + spectrometer as one instrument. |
Functions
|
Return the signed shortest angular distance from target to reported. |
Module Contents
- plesty.pol_pl.rig._logger
- plesty.pol_pl.rig.DEVICES: dict[str, Any]
- plesty.pol_pl.rig._HWP
- plesty.pol_pl.rig._SPEC
- plesty.pol_pl.rig._STATIC_SPEC_SETTINGS: tuple[tuple[str, Any], ...] = (('CameraSettings.HardwareIOTriggerResponse', 'NoResponse'),...
- plesty.pol_pl.rig.angular_error_deg(reported_deg: float, target_deg: float) float
Return the signed shortest angular distance from target to reported.
- Parameters:
reported_deg (float)
target_deg (float)
- Return type:
float
- class plesty.pol_pl.rig.PolPlRig(devices: collections.abc.Mapping[str, Any] | None = None, env: plesty.lib.utils.settings.EnvSettings | None = None, env_prefix: str | None = None)
Bases:
plesty.lib.device.composite_device.CompositeDeviceHalf-wave-plate rotation stage + spectrometer as one instrument.
Connect the rig’s instruments, each on its own thread.
Addresses are not arguments: each is read from
<NAME>_ADDRESSin the environment (HWP_ADDRESS,SPEC_ADDRESS), so a deployment is configured by its.env.- Parameters:
devices (Optional[collections.abc.Mapping[str, Any]]) – Sub-device overrides in the form
CompositeDeviceaccepts; defaults to thedevicesblock of the packagedconfig.yaml.env (Optional[plesty.lib.utils.settings.EnvSettings]) – Environment source for the address lookups.
env_prefix (Optional[str]) – Deployment prefix for the derived variable names.
- Raises:
ValueError – If a sub-device’s address is neither configured nor in the environment.
RuntimeError – If a device server cannot be reached.
- init_state() None
Reset what this rig remembers about its instruments.
Per rig, not per process: a run builds its own rig, so a fresh run rewrites every setting and never inherits another run’s idea of them.
- Return type:
None
- home_hwp() bool
Home the rotation stage and return its homed status.
- Return type:
bool
- set_hwp(angle_deg: float) float
Move the half-wave plate to an absolute angle and return where it settled.
Small steps from a known position run under a short window; larger or first moves keep the full mechanical budget. The stage answers only once it has stopped, so the reported angle is the one the spectrum is measured at. It is checked against the target: on a mismatch beyond
position_tolerance_degthe move is issued once more, and a second mismatch raises, so the step is retried instead of recording a spectrum at the wrong angle.- Parameters:
angle_deg (float) – Target angle in degrees (applied modulo 360).
- Returns:
The stage-reported angle in degrees.
- Raises:
RuntimeError – If the stage settles away from the target twice.
- Return type:
float
- configure_spectrum(exposure_ms: float, frames: int, base_name: str) None
Push one acquisition’s settings to the spectrometer, writing only what changed.
The file name is part of the settings rather than of the acquire call: LightField generates it from the base name.
- Parameters:
exposure_ms (float) – Exposure time in milliseconds.
frames (int) – Frames stored in the one
.spefile.base_name (str) – File-name stem LightField generates from.
- Return type:
None
- center_wavelength_nm() float
Return the grating centre wavelength currently set on the spectrometer.
- Return type:
float
- acquire_spectrum(exposure_ms: float, frames: int) dict[str, Any]
Expose the spectrometer once and return the file it wrote.
The path is compared with the one reported before the exposure, because LightField answers with its most recent file whether or not this acquisition produced one.
- Parameters:
exposure_ms (float) – Exposure time in milliseconds (sizes the call window).
frames (int) – Frames stored by the acquisition.
- Returns:
{"data_file": str, "started_at": datetime, "ended_at": datetime}— the path as the spectrometer host sees it, and the UTC bounds of the exposure.- Raises:
RuntimeError – If the spectrometer reports no new file.
- Return type:
dict[str, Any]
- _write_spec(key: str, value: Any) None
Push one spectrometer setting under the configured write budget.
- Parameters:
key (str)
value (Any)
- Return type:
None