stoner_measurement.instruments.temperature_controller.TemperatureController

class stoner_measurement.instruments.temperature_controller.TemperatureController(transport: BaseTransport, protocol: BaseProtocol)[source]

Bases: BaseInstrument

Abstract base class for temperature controller instruments.

Provides a uniform interface for reading temperatures, managing setpoints, and controlling heater output across a range of cryogenic and laboratory temperature controllers including the Lakeshore 335, 336, 340 and 350, the Oxford Instruments ITC503, and the Oxford Instruments Mercury iTC. All temperature values are in Kelvin unless otherwise stated.

Subclasses must implement the seventeen core abstract methods. Optional capability methods raise NotImplementedError by default; drivers override only those methods that their hardware supports. Callers should consult get_capabilities() to determine which optional features are available before invoking them.

Variables:

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.protocol import LakeshoreProtocol
>>> from stoner_measurement.instruments.temperature_controller import (
...     TemperatureController, ControlMode, SensorStatus,
...     ControllerCapabilities, PIDParameters,
... )
>>> class _TC(TemperatureController):
...     def get_temperature(self, channel): return 300.0
...     def get_sensor_status(self, channel): return SensorStatus.OK
...     def get_input_channel(self, loop): return "A"
...     def set_input_channel(self, loop, channel): pass
...     def get_setpoint(self, loop): return 300.0
...     def set_setpoint(self, loop, value): pass
...     def get_loop_mode(self, loop): return ControlMode.CLOSED_LOOP
...     def set_loop_mode(self, loop, mode): pass
...     def get_heater_output(self, loop): return 50.0
...     def set_heater_range(self, loop, range_): pass
...     def get_pid(self, loop): return PIDParameters(50.0, 1.0, 0.0)
...     def set_pid(self, loop, p, i, d): pass
...     def get_ramp_rate(self, loop): return 5.0
...     def set_ramp_rate(self, loop, rate): pass
...     def get_ramp_enabled(self, loop): return False
...     def set_ramp_enabled(self, loop, enabled): pass
...     def get_capabilities(self):
...         return ControllerCapabilities(
...             num_inputs=2, num_loops=1,
...             input_channels=("A", "B"), loop_numbers=(1,),
...         )
>>> tc = _TC(NullTransport(), LakeshoreProtocol())
>>> tc.get_temperature("A")
300.0
>>> tc.get_capabilities().num_loops
1
connect() → None[source]

Open the connection and verify the controller identity.

get_alarm_limits(channel: str) → tuple[float, float][source]

Return the (low, high) alarm limits for sensor channel in Kelvin.

Parameters:

channel (str) – Sensor channel identifier.

Returns:

(low_limit, high_limit) in Kelvin.

Return type:

(tuple[float, float])

Raises:
get_alarm_state(channel: str) → AlarmState[source]

Return the current alarm state for sensor channel.

Parameters:

channel (str) – Sensor channel identifier.

Returns:

Current alarm condition.

Return type:

(AlarmState)

Raises:
get_autotune_status(loop: int) → str[source]

Return the current autotune status for loop as a string.

The returned string is instrument-specific; typical values include "idle", "running", "complete", and "failed".

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Human-readable autotune status.

Return type:

(str)

Raises:
get_calibration_curve_names() → dict[int, str][source]

Return available calibration-curve names keyed by curve number.

Controllers that can provide curve metadata should override this method and return a mapping of curve number to a human-readable name or description. Controllers that do not expose curve names should return an empty mapping.

Returns:

Mapping from calibration curve number to display name.

Return type:

(dict[int, str])

abstractmethod get_capabilities() → ControllerCapabilities[source]

Return the static capability descriptor for this controller driver.

Returns:

Descriptor advertising the number of inputs, loops, and which optional feature groups are supported.

Return type:

(ControllerCapabilities)

Examples

>>> caps = tc.get_capabilities()
>>> caps.num_loops
1
>>> caps.has_ramp
True
get_controller_status() → TemperatureStatus[source]

Return a full snapshot of all channels and loops.

Uses get_capabilities() to discover channels and loops, then assembles a TemperatureStatus from get_temperature_reading() and get_loop_status().

Returns:

Snapshot of all sensor readings and control-loop states.

Return type:

(TemperatureStatus)

Raises:

ConnectionError – If the transport is not open.

get_excitation(channel: str) → float[source]

Return the excitation level applied to sensor channel.

The excitation value and its units (voltage, current, or power) are instrument-specific. Common examples: Lakeshore resistive-excitation in μV, or Oxford Mercury excitation in μA.

Parameters:

channel (str) – Sensor channel identifier.

Returns:

Excitation level in instrument-native units.

Return type:

(float)

Raises:
get_filter(channel: str) → dict[str, object][source]

Return the digital filter settings for sensor channel.

The returned dictionary contains at minimum the keys "enabled" (bool), "points" (int, number of readings averaged), and "window" (float, percentage window for filter reset).

Parameters:

channel (str) – Sensor channel identifier.

Returns:

Filter settings keyed by name.

Return type:

(dict[str, object])

Raises:
get_gas_auto() → bool[source]

Return True if the gas/needle-valve is in automatic control mode.

In automatic mode the controller determines the gas-flow position itself; in manual mode the operator-set position is used directly.

Drivers that support querying the gas auto mode should override this method. The default implementation raises NotImplementedError.

Returns:

True when the gas flow is under automatic control.

Return type:

(bool)

Raises:

Examples

>>> tc.get_gas_auto()
False
get_gas_flow() → float[source]

Return the cryogen gas-flow valve position as a percentage.

Returns:

Gas-flow valve opening as a percentage (0–100 %).

Return type:

(float)

Raises:
abstractmethod get_heater_output(loop: int) → float[source]

Return the heater output percentage for control loop.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Heater output as a percentage (0–100 %).

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_heater_output(1)
50.0
get_heater_range(loop: int) → int[source]

Return the current heater range index for control loop.

The meaning of the returned index is instrument-specific. A value of 0 conventionally means “heater off”.

Drivers that support reading the heater range should override this method. The default implementation raises NotImplementedError.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Current heater range index.

Return type:

(int)

Raises:

Examples

>>> tc.get_heater_range(1)
0
abstractmethod get_input_channel(loop: int) → str[source]

Return the sensor channel currently assigned to control loop.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Channel identifier of the sensor driving this loop.

Return type:

(str)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_input_channel(1)
'A'
get_input_channel_settings(channel: str) → InputChannelSettings[source]

Return the configuration settings for sensor input channel.

Reads the sensor type, range, filter, and calibration-curve assignment for the specified input channel. The returned InputChannelSettings instance may contain None for fields that the driver does not support.

Parameters:

channel (str) – Sensor channel identifier.

Returns:

Current configuration of the input channel.

Return type:

(InputChannelSettings)

Raises:

Examples

>>> # ctrl.get_input_channel_settings("A")  # requires live instrument
get_loop_input_channels(loop: int) → tuple[str, ...][source]

Return native inputs assignable to a loop; override for restricted hardware.

Parameters:

loop (int) – Advertised local loop number.

Returns:

Supported native channel identifiers.

Return type:

(tuple[str, …])

Raises:

ValueError – If the loop is not advertised by this instrument.

abstractmethod get_loop_mode(loop: int) → ControlMode[source]

Return the active control mode for loop.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Current control mode of the loop.

Return type:

(ControlMode)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_loop_mode(1)
<ControlMode.CLOSED_LOOP: 'closed_loop'>
get_loop_status(loop: int) → LoopStatus[source]

Return a comprehensive status snapshot for control loop.

Calls all relevant core abstract methods and assembles a LoopStatus dataclass. Drivers that can retrieve all loop data in a single instrument query should override this method.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Complete current state of the control loop.

Return type:

(LoopStatus)

Raises:

ConnectionError – If the transport is not open.

get_needle_valve() → float[source]

Return the needle-valve (gas-flow restrictor) position as a percentage.

Returns:

Needle-valve position as a percentage (0 = fully closed, 100 = fully open).

Return type:

(float)

Raises:
get_num_zones(loop: int) → int[source]

Return the number of configured zones for loop.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Number of zones configured in the zone table.

Return type:

(int)

Raises:
abstractmethod get_pid(loop: int) → PIDParameters[source]

Return the PID parameters for control loop.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Current proportional, integral and derivative gain values.

Return type:

(PIDParameters)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_pid(1)
PIDParameters(p=50.0, i=1.0, d=0.0)
abstractmethod get_ramp_enabled(loop: int) → bool[source]

Return True if setpoint ramping is enabled for loop.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

True when the ramp function is active.

Return type:

(bool)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_ramp_enabled(1)
False
abstractmethod get_ramp_rate(loop: int) → float[source]

Return the setpoint ramp rate for loop in Kelvin per minute.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Ramp rate in Kelvin per minute.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_ramp_rate(1)
5.0
get_ramp_state(loop: int) → RampState[source]

Return the current ramp state for loop.

The default implementation infers the state from get_ramp_enabled(); override in subclasses that can query the actual hardware ramp state directly.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

RAMPING when the ramp function is active, IDLE otherwise.

Return type:

(RampState)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_ramp_state(1)
<RampState.IDLE: 'idle'>
get_sensor_curve(channel: str) → int[source]

Return the calibration curve number assigned to sensor channel.

Parameters:

channel (str) – Sensor channel identifier.

Returns:

Curve number (instrument-specific; 0 typically means no curve assigned).

Return type:

(int)

Raises:
abstractmethod get_sensor_status(channel: str) → SensorStatus[source]

Return the validity/range status of the sensor on channel.

Parameters:

channel (str) – Sensor channel identifier (instrument-specific, e.g. "A").

Returns:

Current validity and range status of the sensor reading.

Return type:

(SensorStatus)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_sensor_status("A")
<SensorStatus.OK: 'ok'>
abstractmethod get_setpoint(loop: int) → float[source]

Return the current setpoint for control loop in Kelvin.

Parameters:

loop (int) – Control loop number (1-based).

Returns:

Setpoint temperature in Kelvin.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_setpoint(1)
300.0
abstractmethod get_temperature(channel: str) → float[source]

Return the current temperature for channel in Kelvin.

Parameters:

channel (str) – Sensor channel identifier (instrument-specific, e.g. "A").

Returns:

Current temperature in Kelvin.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> tc.get_temperature("A")
300.0
get_temperature_reading(channel: str) → TemperatureReading[source]

Return a combined temperature value and sensor status for channel.

Calls get_temperature() and get_sensor_status() and packages the results into a TemperatureReading. Drivers that can fetch both in a single query should override this method.

Parameters:

channel (str) – Sensor channel identifier.

Returns:

Current temperature in Kelvin with validity status.

Return type:

(TemperatureReading)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> reading = tc.get_temperature_reading("A")
>>> reading.value
300.0
>>> reading.status
<SensorStatus.OK: 'ok'>
get_zone(loop: int, zone_index: int) → ZoneEntry | None[source]

Return the parameters of zone entry zone_index for loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • zone_index (int) – Zone entry index (1-based).

Returns:

Zone parameters including PID gains, ramp rate, heater range and heater output power for this table entry. None marks the end of the populated table for drivers with unused rows.

Return type:

(ZoneEntry | None)

Raises:
ramp_to_setpoint(loop: int, target: float, *, rate: float | None = None) → None[source]

Set a new target setpoint for loop, optionally configuring the ramp rate.

This convenience method performs the typical “ramp to a new temperature” sequence:

  1. If rate is given, set the ramp rate via set_ramp_rate().

  2. Enable ramping via set_ramp_enabled() (only when the driver advertises has_ramp).

  3. Write the new setpoint via set_setpoint().

Callers that need to wait for the temperature to arrive should follow this call with wait_for_setpoint().

Parameters:
  • loop (int) – Control loop number (1-based).

  • target (float) – Desired setpoint in Kelvin.

Keyword Parameters:

rate (float | None) – Ramp rate in Kelvin per minute. When provided, the rate is written to the instrument before the setpoint is updated. When None the currently programmed ramp rate is unchanged. Ignored if the driver does not advertise has_ramp.

Raises:
  • ConnectionError – If the transport is not open.

  • ValueError – If target or rate are outside the instrument’s valid range.

Examples

>>> tc.ramp_to_setpoint(1, 150.0, rate=5.0)
set_alarm_enabled(channel: str, enabled: bool) → None[source]

Enable or disable the alarm for sensor channel.

Parameters:
  • channel (str) – Sensor channel identifier.

  • enabled (bool) – True to activate alarm checking, False to disable it.

Raises:
set_alarm_limits(channel: str, low: float, high: float) → None[source]

Set the low and high alarm thresholds for sensor channel.

Parameters:
  • channel (str) – Sensor channel identifier.

  • low (float) – Low-alarm temperature threshold in Kelvin.

  • high (float) – High-alarm temperature threshold in Kelvin.

Raises:
set_excitation(channel: str, value: float) → None[source]

Set the excitation level for sensor channel.

Parameters:
  • channel (str) – Sensor channel identifier.

  • value (float) – Excitation level in instrument-native units.

Raises:
set_filter(channel: str, *, enabled: bool, points: int, window: float) → None[source]

Configure the digital filter for sensor channel.

Parameters:

channel (str) – Sensor channel identifier.

Keyword Parameters:
  • enabled (bool) – True to activate the filter, False to disable it.

  • points (int) – Number of readings to average (1 effectively disables averaging).

  • window (float) – Percentage deviation window that triggers a filter reset (0 disables window filtering).

Raises:
set_gas_auto(auto: bool) → None[source]

Enable or disable automatic gas/needle-valve control.

Parameters:

auto (bool) – True to engage automatic gas-flow control; False to switch to manual control.

Raises:
set_gas_flow(percent: float) → None[source]

Set the cryogen gas-flow valve to percent open.

Parameters:

percent (float) – Desired valve opening as a percentage (0–100 %).

Raises:
abstractmethod set_heater_range(loop: int, range_: int) → None[source]

Set the heater range for control loop.

The meaning of range_ is instrument-specific. A value of 0 conventionally means “heater off”.

Parameters:
  • loop (int) – Control loop number (1-based).

  • range (int) – Heater range index (instrument-specific).

Raises:

ConnectionError – If the transport is not open.

abstractmethod set_input_channel(loop: int, channel: str) → None[source]

Assign sensor channel as the input for control loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • channel (str) – Sensor channel identifier to assign.

Raises:
  • ConnectionError – If the transport is not open.

  • ValueError – If channel is not a valid sensor input for this instrument.

set_input_channel_settings(channel: str, settings: InputChannelSettings) → None[source]

Apply configuration settings to sensor input channel.

Writes the sensor type, range, filter, and calibration-curve assignment from settings to the instrument. Fields that are None in settings are not changed on the instrument.

Parameters:
  • channel (str) – Sensor channel identifier.

  • settings (InputChannelSettings) – Configuration to apply. None fields are ignored.

Raises:

Examples

>>> from stoner_measurement.instruments.temperature_controller import InputChannelSettings
>>> s = InputChannelSettings(filter_enabled=True, filter_points=10, filter_window=2.0)
>>> # ctrl.set_input_channel_settings("A", s)  # requires live instrument
abstractmethod set_loop_mode(loop: int, mode: ControlMode) → None[source]

Set the control mode for loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • mode (ControlMode) – Desired control mode.

Raises:
set_manual_heater_output(loop: int, output: float) → None[source]

Set the manual (open-loop) heater output percentage for loop.

Used when the loop is in OPEN_LOOP mode to drive the heater to a fixed percentage without PID feedback.

The default implementation raises NotImplementedError. Drivers that support open-loop heater output should override this method and set ControllerCapabilities.has_manual_heater_output to True in their capabilities descriptor.

Parameters:
  • loop (int) – Control loop number (1-based).

  • output (float) – Desired heater output as a percentage (0–100 %).

Raises:

Examples

>>> tc.set_manual_heater_output(1, 25.0)
set_needle_valve(position: float) → None[source]

Set the needle-valve position.

Parameters:

position (float) – Desired position as a percentage (0 = fully closed, 100 = fully open).

Raises:
abstractmethod set_pid(loop: int, p: float, i: float, d: float) → None[source]

Set the PID parameters for control loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • p (float) – Proportional gain.

  • i (float) – Integral gain (reset).

  • d (float) – Derivative gain (rate).

Raises:
  • ConnectionError – If the transport is not open.

  • ValueError – If any gain value is outside the instrument’s valid range.

abstractmethod set_ramp_enabled(loop: int, enabled: bool) → None[source]

Enable or disable setpoint ramping for loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • enabled (bool) – True to activate the ramp function, False to disable it.

Raises:

ConnectionError – If the transport is not open.

abstractmethod set_ramp_rate(loop: int, rate: float) → None[source]

Set the setpoint ramp rate for loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • rate (float) – Ramp rate in Kelvin per minute. A value of 0 typically disables ramping or sets an unlimited rate (instrument-specific).

Raises:
  • ConnectionError – If the transport is not open.

  • ValueError – If rate is negative or exceeds the instrument’s maximum.

set_sensor_curve(channel: str, curve_num: int) → None[source]

Assign calibration curve curve_num to sensor channel.

Parameters:
  • channel (str) – Sensor channel identifier.

  • curve_num (int) – Curve number to assign (instrument-specific).

Raises:
abstractmethod set_setpoint(loop: int, value: float) → None[source]

Set the target temperature for control loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • value (float) – Desired setpoint in Kelvin.

Raises:
set_zone(loop: int, zone_index: int, entry: ZoneEntry) → None[source]

Write a zone table entry for loop.

Parameters:
  • loop (int) – Control loop number (1-based).

  • zone_index (int) – Zone entry index (1-based).

  • entry (ZoneEntry) – Zone parameters to write, including PID gains, ramp rate, heater range and heater output power.

Raises:
start_autotune(loop: int, mode: int = 0) → None[source]

Start the PID autotuning sequence for loop.

Parameters:

loop (int) – Control loop number (1-based).

Keyword Parameters:

mode (int) – Autotune mode (instrument-specific; commonly 0 = P only, 1 = P+I, 2 = P+I+D). Defaults to 0.

Raises:
wait_for_setpoint(loop: int, channel: str, *, tolerance: float = 0.5, timeout: float = 300.0, poll_period: float = 1.0) → None[source]

Block until the temperature on channel is within tolerance of the setpoint.

Polls get_temperature() and get_setpoint() at intervals of poll_period seconds until the absolute deviation falls within tolerance, or until timeout seconds have elapsed.

Parameters:
  • loop (int) – Control loop whose setpoint is used as the target.

  • channel (str) – Sensor channel to monitor.

Keyword Parameters:
  • tolerance (float) – Acceptable deviation from the setpoint in Kelvin. Defaults to 0.5.

  • timeout (float) – Maximum time to wait in seconds. Defaults to 300.0.

  • poll_period (float) – Interval between temperature polls in seconds. Defaults to 1.0.

Raises:
  • TimeoutError – If the temperature does not reach the setpoint within timeout seconds.

  • ConnectionError – If the transport is not open.