diff --git a/CHANGELOG.md b/CHANGELOG.md index 5224c332e..892a094e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ Entries for 2.6.0 to 2.14.0 were generated from commit subjects. Older entries w ## [Unreleased] +### Changed + +- The warm-up progress line on close shows the sensor temperature and power the last step was planned with, + instead of reading them again after the step. The done line says why the warm-up ended (setpoint reached, or + cooler idle, with the readings). `RampStep` has a new field `idle`. + ## [2.29.1] - 2026-11-25 ### Changed diff --git a/pyobs/mixins/coolingramp.py b/pyobs/mixins/coolingramp.py index 4e719c321..a613ae7a9 100644 --- a/pyobs/mixins/coolingramp.py +++ b/pyobs/mixins/coolingramp.py @@ -86,6 +86,9 @@ def __init__( self._cooling_commanded: float | None = None self._cooling_event = asyncio.Event() self._cooling_failures = 0 + # sensor temperature and power the last warm-up step was planned with, and how the last ramp ended + self._cooling_reading: tuple[float | None, int | None] = (None, None) + self._cooling_end: str | None = None self._cooling_task = self.add_background_task(self._cooling_ramp_loop, True) # type: ignore[attr-defined] @@ -197,6 +200,7 @@ async def _cooling_warm_up(self, timeout: float) -> None: """Runs the warm-up ramp to its end. Logs when it starts, about every _WARMUP_LOG_INTERVAL seconds while it runs, and when it is done, so the log shows why the module takes long to stop.""" start = time.monotonic() + self._cooling_reading, self._cooling_end = (None, None), None delay = await self._cooling_tick() if self._cooling_target is None: return # cooler was off already, or switched off in the first step @@ -213,25 +217,19 @@ async def _cooling_warm_up(self, timeout: float) -> None: delay = await self._cooling_tick() now = time.monotonic() if self._cooling_target is not None and now >= next_log: - await self._cooling_log_warm_up(start + timeout - now) + self._cooling_log_warm_up(start + timeout - now) next_log = now + _WARMUP_LOG_INTERVAL - log.info("Warm-up done after %s, cooling is off.", _duration(time.monotonic() - start)) + end = f", {self._cooling_end}" if self._cooling_end else "" + log.info("Warm-up done after %s%s, cooling is off.", _duration(time.monotonic() - start), end) - async def _cooling_log_warm_up(self, left: float) -> None: - # only for the log, the next tick reports a real problem - try: - sensor = await self._get_sensor_temperature() - except Exception: - sensor = None - try: - _, _, power = await self._get_cooling_hardware() - except Exception: - power = None + def _cooling_log_warm_up(self, left: float) -> None: + """Logs the progress, with the readings the last step was planned with.""" + sensor, power = self._cooling_reading log.info( "Warming up: setpoint %s, sensor %s, power %s, up to %s left.", _temperature(self._cooling_commanded), _temperature(sensor), - "unknown" if power is None else f"{power} %", + _power(power), _duration(max(0.0, left)), ) @@ -303,6 +301,15 @@ async def _cooling_tick(self) -> float | None: sensor = await self._get_sensor_temperature() _, _, power = await self._get_cooling_hardware() step = self._cooling_ramp.next_step(commanded, enabled, setpoint, sensor, power) + if not enabled: + self._cooling_reading = (sensor, power) + if step.done: + self._cooling_end = ( + f"cooler idle at setpoint {_temperature(commanded)}, sensor {_temperature(sensor)}, " + f"power {_power(power)}" + if step.idle + else f"setpoint at {_temperature(commanded)}" + ) if step.write: await self._set_cooling_hardware(step.enabled, step.setpoint) self._cooling_commanded = step.setpoint @@ -321,6 +328,10 @@ def _temperature(value: float | None) -> str: return "unknown" if value is None else f"{value:.1f} °C" +def _power(value: int | None) -> str: + return "unknown" if value is None else f"{value} %" + + def _duration(seconds: float) -> str: return f"{seconds:.0f} s" if seconds < 90 else f"{seconds / 60:.0f} min" diff --git a/pyobs/utils/coolingramp.py b/pyobs/utils/coolingramp.py index 6b5b0d28d..71db8d3f5 100644 --- a/pyobs/utils/coolingramp.py +++ b/pyobs/utils/coolingramp.py @@ -29,6 +29,7 @@ class RampStep: setpoint: Setpoint to write, None if the cooler is to be switched off. done: Whether the ramp has reached its target after this step. delay: Seconds to wait before asking for the next step (0 if done). + idle: Whether a warm-up stopped early because the cooler was idle. """ write: bool @@ -36,6 +37,7 @@ class RampStep: setpoint: float | None done: bool delay: float + idle: bool = False class CoolingRamp: @@ -148,9 +150,10 @@ def next_step( if not enabled: idle = sensor is not None and commanded >= sensor + IDLE_MARGIN and (power is None or power == 0) self._idle_count = self._idle_count + 1 if idle else 0 - if self._idle_count >= self.idle_steps or commanded >= goal or self.rate_warm is None: + stop_idle = self._idle_count >= self.idle_steps and commanded < goal + if stop_idle or commanded >= goal or self.rate_warm is None: self._idle_count = 0 - return RampStep(write=True, enabled=False, setpoint=None, done=True, delay=0.0) + return RampStep(write=True, enabled=False, setpoint=None, done=True, delay=0.0, idle=stop_idle) else: self._idle_count = 0 if commanded == goal: diff --git a/tests/mixins/test_coolingramp.py b/tests/mixins/test_coolingramp.py index 08e887ccd..8c4aa5c1f 100644 --- a/tests/mixins/test_coolingramp.py +++ b/tests/mixins/test_coolingramp.py @@ -313,8 +313,10 @@ async def test_close_with_warmup_logs_start_progress_and_end( await camera.close() lines = [r.getMessage() for r in caplog.records if r.name == "pyobs.mixins.coolingramp"] assert lines[0] == "Warming up from -9.0 °C towards -8.0 °C before closing, may take up to 30 s." - assert lines[1] == "Warming up: setpoint -8.0 °C, sensor -8.5 °C, power 80 %, up to 30 s left." - assert lines[-1].startswith("Warm-up done after ") and lines[-1].endswith("cooling is off.") + # sensor and power are the ones the step was planned with, read before the setpoint went to -8 + assert lines[1] == "Warming up: setpoint -8.0 °C, sensor -9.5 °C, power 80 %, up to 30 s left." + assert lines[-1].startswith("Warm-up done after ") + assert lines[-1].endswith(", setpoint at -8.0 °C, cooling is off.") assert len(lines) == 3 @@ -328,13 +330,23 @@ async def test_close_with_cooler_already_off_logs_no_warmup(caplog: pytest.LogCa @pytest.mark.asyncio -async def test_warmup_progress_survives_failing_reads(caplog: pytest.LogCaptureFixture) -> None: +async def test_close_with_idle_cooler_logs_why_it_stopped_early(caplog: pytest.LogCaptureFixture) -> None: + camera = make_camera(cooling_rate_warm=600.0, cooling_close_timeout=30.0) + camera._cooling = camera._cooling._replace(temperatures={"CCD": -8.0, "Back": 3.0}, power=0) # setpoint -10 + with caplog.at_level("INFO", logger="pyobs.mixins.coolingramp"): + await camera.close() + lines = [r.getMessage() for r in caplog.records if r.name == "pyobs.mixins.coolingramp"] + # idle from -7 (sensor + 1) on, off after the third idle reading at -5 + assert lines[-1].endswith(", cooler idle at setpoint -5.0 °C, sensor -8.0 °C, power 0 %, cooling is off."), lines[ + -1 + ] + + +def test_warmup_progress_without_readings_says_unknown(caplog: pytest.LogCaptureFixture) -> None: camera = make_camera() camera._cooling_commanded = -12.0 - camera._get_sensor_temperature = AsyncMock(side_effect=RuntimeError("SDK error")) # type: ignore[method-assign] - camera._get_cooling_hardware = AsyncMock(side_effect=RuntimeError("SDK error")) # type: ignore[method-assign] with caplog.at_level("INFO", logger="pyobs.mixins.coolingramp"): - await camera._cooling_log_warm_up(840.0) + camera._cooling_log_warm_up(840.0) msg = "Warming up: setpoint -12.0 °C, sensor unknown, power unknown, up to 14 min left." assert caplog.records[-1].getMessage() == msg diff --git a/tests/utils/test_coolingramp.py b/tests/utils/test_coolingramp.py index a4f9a7bc2..1bbc6f54f 100644 --- a/tests/utils/test_coolingramp.py +++ b/tests/utils/test_coolingramp.py @@ -71,7 +71,13 @@ def test_disable_stops_early_when_sensor_stops_following() -> None: assert ramp.next_step(6.0, False, None, sensor=5.0, power=0).setpoint == 7.0 assert ramp.next_step(7.0, False, None, sensor=5.0, power=0).setpoint == 8.0 step = ramp.next_step(8.0, False, None, sensor=5.0, power=0) - assert step.done and step.enabled is False and step.setpoint is None + assert step.done and step.enabled is False and step.setpoint is None and step.idle + + +def test_disable_at_the_end_point_is_not_an_idle_stop() -> None: + ramp = CoolingRamp(rate_warm=1.0, off_temperature=20.0, idle_steps=1) + step = ramp.next_step(20.0, False, None, sensor=5.0, power=0) + assert step.done and step.enabled is False and not step.idle def test_disable_needs_idle_readings_in_a_row() -> None: