mirror of
https://github.com/lynchaos/ashvale-station.git
synced 2026-09-12 12:47:49 +00:00
Heated environment: a thermostat member in the forecast ensemble
A room held at a setpoint is a different process from one left to drift. It is
a closed loop, and persistence, the baseline everything here is scored against,
is the wrong statement about it: the truth is not that it stays where it is, it
is that it returns to the setpoint.
So site.heating adds a fourth ensemble member, first order because that is what
a controlled system is:
dT_set(h) = (T_set - T_now) * (1 - exp(-h / tau))
Humidity follows and is the part that is easy to get wrong. Heating adds no
moisture, so vapour pressure is conserved and not relative humidity:
RH(h) = RH_now * es(T_now) / es(T_now + dT_set(h))
Warm the air and RH falls although nothing was dried, which is why a heated
house in winter is dry. The test asserts the dew point is unchanged to 1e-6.
Pressure gets zero: a thermostat cannot move the synoptic field.
Offered, not imposed. Hedge scores this member on realised error like any
other, so a wrong tau or a stale setpoint costs accuracy and gets down-weighted
rather than quietly biasing every forecast. Verified: on history with no
heating the ensemble assigned it weight 0.000. With heating off it returns zero
and is identical to persistence.
Going from three members to four means old saved heads must migrate.
from_dict reinitialises weights and member_mae. I missed member_mae first time
and it did not fail on load, it failed later inside learn() on a broadcast
error, which is a much worse place to find out; the migration test now covers
both and calls learn() to prove it.
Settings tab gains the toggle, setpoint and time constant. Turning heating on
or off is treated as a regime change like a door: discontinuity marker plus a
queued retrain.
This commit is contained in:
+53
-2
@@ -34,6 +34,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import math
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
@@ -382,6 +383,55 @@ class Station:
|
||||
return {"rows": written, "seconds": round(secs, 2),
|
||||
"k": comp.k, "hum_offset": hcomp.offset}
|
||||
|
||||
def _setpoint_delta(self, target: str, horizon_s: int, anchor: float) -> float:
|
||||
"""Where a thermostatted room is heading, as a delta from now.
|
||||
|
||||
A controlled room is first order: the heating closes the gap to the
|
||||
setpoint exponentially, so after time h the remaining error is
|
||||
exp(-h/tau) of what it was. The expected change is therefore
|
||||
|
||||
dT(h) = (T_set - T_now) * (1 - exp(-h / tau))
|
||||
|
||||
which is zero at h=0 and asymptotes to the full correction. That is a
|
||||
much better statement about a heated room than persistence, which claims
|
||||
the room stays wherever it happens to be.
|
||||
|
||||
Humidity follows for free and is the part people get wrong. Heating adds
|
||||
no moisture, so vapour pressure is what is conserved, not relative
|
||||
humidity. Warm the air and RH falls even though nothing was dried:
|
||||
|
||||
RH(h) = RH_now * es(T_now) / es(T_now + dT(h))
|
||||
|
||||
This is why a heated house in winter is dry. Pressure is unaffected: a
|
||||
thermostat cannot move the synoptic field, so that member stays at zero
|
||||
and the ensemble will correctly ignore it.
|
||||
|
||||
Returns 0.0 when heating is off, which makes this member identical to
|
||||
persistence and therefore harmless.
|
||||
"""
|
||||
site = self.cfg.site
|
||||
if not site.heating:
|
||||
return 0.0
|
||||
tau_s = max(float(site.thermal_time_constant_h), 0.05) * 3600.0
|
||||
closed = 1.0 - math.exp(-float(horizon_s) / tau_s)
|
||||
|
||||
temp_now = self.live.get("temp_smooth")
|
||||
if temp_now is None:
|
||||
return 0.0
|
||||
d_temp = (float(site.heating_setpoint_c) - float(temp_now)) * closed
|
||||
|
||||
if target == "temperature":
|
||||
return d_temp
|
||||
if target == "humidity":
|
||||
# Constant vapour pressure, so RH moves only because es(T) moved.
|
||||
es_now = float(physics.saturation_vapour_pressure(temp_now))
|
||||
es_fut = float(physics.saturation_vapour_pressure(temp_now + d_temp))
|
||||
if es_fut <= 1e-9:
|
||||
return 0.0
|
||||
rh_now = float(anchor)
|
||||
return float(np.clip(rh_now * es_now / es_fut, 0.0, 100.0)) - rh_now
|
||||
return 0.0
|
||||
|
||||
def set_environment(self, environment: Optional[str] = None,
|
||||
enclosure: Optional[str] = None,
|
||||
note: str = "") -> Dict:
|
||||
@@ -467,7 +517,8 @@ class Station:
|
||||
grid_ts, cols, X, valid = built
|
||||
|
||||
clim_scores = self.climatology.fit(grid_ts, cols, valid)
|
||||
counts = self.nowcast.fit(X, valid, cols, self.climatology, grid_ts)
|
||||
counts = self.nowcast.fit(X, valid, cols, self.climatology, grid_ts,
|
||||
setpoint_fn=self._setpoint_delta)
|
||||
|
||||
self.last_train = time.time()
|
||||
self.monitor.clear_retrain_flag()
|
||||
@@ -503,7 +554,7 @@ class Station:
|
||||
"humidity": float(self.live.get("hum_smooth", cols["humidity"][-1])),
|
||||
"pressure": float(self.live.get("press_slp", cols["pressure"][-1])),
|
||||
}
|
||||
fc = self.nowcast.forecast(x_now, anchors, now, self.climatology)
|
||||
fc = self.nowcast.forecast(x_now, anchors, now, self.climatology, setpoint_fn=self._setpoint_delta)
|
||||
|
||||
bundle: Dict[str, Any] = {"issued_ts": now, "anchors": anchors, "targets": {}}
|
||||
for target, per_h in fc.items():
|
||||
|
||||
Reference in New Issue
Block a user