stoner_measurement.instruments.temperature_controller.TemperatureController¶
- class stoner_measurement.instruments.temperature_controller.TemperatureController(transport: BaseTransport, protocol: BaseProtocol)[source]¶
Bases:
BaseInstrumentAbstract 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
NotImplementedErrorby default; drivers override only those methods that their hardware supports. Callers should consultget_capabilities()to determine which optional features are available before invoking them.- Variables:
transport (BaseTransport) – Transport layer instance.
protocol (BaseProtocol) – Protocol instance.
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
- 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:
- Raises:
NotImplementedError – If the driver does not support alarm limits. Check
ControllerCapabilities.has_alarmbefore calling.ConnectionError – If the transport is not open.
- 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:
- Raises:
NotImplementedError – If the driver does not support alarm monitoring. Check
ControllerCapabilities.has_alarmbefore calling.ConnectionError – If the transport is not open.
- 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:
NotImplementedError – If the driver does not support autotuning. Check
ControllerCapabilities.has_autotunebefore calling.ConnectionError – If the transport is not open.
- 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.
- 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:
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 aTemperatureStatusfromget_temperature_reading()andget_loop_status().- Returns:
Snapshot of all sensor readings and control-loop states.
- Return type:
- 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:
NotImplementedError – If the driver does not support excitation configuration. Check
ControllerCapabilities.has_sensor_excitationbefore calling.ConnectionError – If the transport is not open.
- 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:
- Raises:
NotImplementedError – If the driver does not support filter configuration. Check
ControllerCapabilities.has_sensor_excitationbefore calling.ConnectionError – If the transport is not open.
- get_gas_auto() bool[source]¶
Return
Trueif 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:
Truewhen the gas flow is under automatic control.- Return type:
(bool)
- Raises:
NotImplementedError – If the driver does not support gas auto mode. Check
ControllerCapabilities.has_gas_auto_modebefore calling.ConnectionError – If the transport is not open.
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:
NotImplementedError – If the driver does not support cryogen flow control. Check
ControllerCapabilities.has_cryogen_controlbefore calling.ConnectionError – If the transport is not open.
- 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
0conventionally 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:
NotImplementedError – If the driver does not support reading the heater range.
ConnectionError – If the transport is not open.
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
InputChannelSettingsinstance may containNonefor fields that the driver does not support.- Parameters:
channel (str) – Sensor channel identifier.
- Returns:
Current configuration of the input channel.
- Return type:
- Raises:
NotImplementedError – If the driver does not support input channel configuration. Check
ControllerCapabilities.has_input_settingsbefore calling.ConnectionError – If the transport is not open.
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:
- 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:
- 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
LoopStatusdataclass. 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:
- 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:
NotImplementedError – If the driver does not support needle-valve control. Check
ControllerCapabilities.has_cryogen_controlbefore calling.ConnectionError – If the transport is not open.
- 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:
NotImplementedError – If the driver does not support zone control. Check
ControllerCapabilities.has_zonebefore calling.ConnectionError – If the transport is not open.
- 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:
- 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
Trueif setpoint ramping is enabled for loop.- Parameters:
loop (int) – Control loop number (1-based).
- Returns:
Truewhen 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:
- Return type:
- 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;
0typically means no curve assigned).- Return type:
(int)
- Raises:
NotImplementedError – If the driver does not support user calibration curves. Check
ControllerCapabilities.has_user_curvesbefore calling.ConnectionError – If the transport is not open.
- 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:
- 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()andget_sensor_status()and packages the results into aTemperatureReading. 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:
- 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:
- Returns:
Zone parameters including PID gains, ramp rate, heater range and heater output power for this table entry.
Nonemarks the end of the populated table for drivers with unused rows.- Return type:
(ZoneEntry | None)
- Raises:
NotImplementedError – If the driver does not support zone control. Check
ControllerCapabilities.has_zonebefore calling.ConnectionError – If the transport is not open.
- 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:
If rate is given, set the ramp rate via
set_ramp_rate().Enable ramping via
set_ramp_enabled()(only when the driver advertiseshas_ramp).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:
- 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
Nonethe currently programmed ramp rate is unchanged. Ignored if the driver does not advertisehas_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:
- Raises:
NotImplementedError – If the driver does not support alarms. Check
ControllerCapabilities.has_alarmbefore calling.ConnectionError – If the transport is not open.
- set_alarm_limits(channel: str, low: float, high: float) None[source]¶
Set the low and high alarm thresholds for sensor channel.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support alarm limits. Check
ControllerCapabilities.has_alarmbefore calling.ConnectionError – If the transport is not open.
- set_excitation(channel: str, value: float) None[source]¶
Set the excitation level for sensor channel.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support excitation configuration. Check
ControllerCapabilities.has_sensor_excitationbefore calling.ConnectionError – If the transport is not open.
- 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) –
Trueto activate the filter,Falseto 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:
NotImplementedError – If the driver does not support filter configuration. Check
ControllerCapabilities.has_sensor_excitationbefore calling.ConnectionError – If the transport is not open.
- set_gas_auto(auto: bool) None[source]¶
Enable or disable automatic gas/needle-valve control.
- Parameters:
auto (bool) –
Trueto engage automatic gas-flow control;Falseto switch to manual control.- Raises:
NotImplementedError – If the driver does not support gas auto mode. Check
ControllerCapabilities.has_gas_auto_modebefore calling.ConnectionError – If the transport is not open.
- 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:
NotImplementedError – If the driver does not support cryogen flow control. Check
ControllerCapabilities.has_cryogen_controlbefore calling.ConnectionError – If the transport is not open.
- 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
0conventionally means “heater off”.- Parameters:
- 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:
- 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
Nonein settings are not changed on the instrument.- Parameters:
channel (str) – Sensor channel identifier.
settings (InputChannelSettings) – Configuration to apply.
Nonefields are ignored.
- Raises:
NotImplementedError – If the driver does not support input channel configuration. Check
ControllerCapabilities.has_input_settingsbefore calling.ConnectionError – If the transport is not open.
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:
ConnectionError – If the transport is not open.
ValueError – If mode is not supported by this loop on this instrument.
- 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_LOOPmode 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 setControllerCapabilities.has_manual_heater_outputtoTruein their capabilities descriptor.- Parameters:
- Raises:
NotImplementedError – If the driver does not support manual heater output control. Check
ControllerCapabilities.has_manual_heater_outputbefore calling.ConnectionError – If the transport is not open.
ValueError – If output is outside 0–100 %.
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:
NotImplementedError – If the driver does not support needle-valve control. Check
ControllerCapabilities.has_cryogen_controlbefore calling.ConnectionError – If the transport is not open.
- abstractmethod set_pid(loop: int, p: float, i: float, d: float) None[source]¶
Set the PID parameters for control loop.
- Parameters:
- 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:
- 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:
- 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:
- Raises:
NotImplementedError – If the driver does not support user calibration curves. Check
ControllerCapabilities.has_user_curvesbefore calling.ConnectionError – If the transport is not open.
- abstractmethod set_setpoint(loop: int, value: float) None[source]¶
Set the target temperature for control loop.
- Parameters:
- Raises:
ConnectionError – If the transport is not open.
ValueError – If value is outside the instrument’s valid range.
- set_zone(loop: int, zone_index: int, entry: ZoneEntry) None[source]¶
Write a zone table entry for loop.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support zone control. Check
ControllerCapabilities.has_zonebefore calling.ConnectionError – If the transport is not open.
- 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 to0.- Raises:
NotImplementedError – If the driver does not support autotuning. Check
ControllerCapabilities.has_autotunebefore calling.ConnectionError – If the transport is not open.
- 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()andget_setpoint()at intervals of poll_period seconds until the absolute deviation falls within tolerance, or until timeout seconds have elapsed.- Parameters:
- 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.