File size: 2,744 Bytes
1baf215 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """Controlled, stable vocabulary; bounds describe sensors, never instance capacities."""
from dataclasses import dataclass
import numpy as np
DT_MINUTES = 15
HORIZONS = (1, 2, 4, 8)
GENERATOR_VERSION = "0.1.2"
@dataclass(frozen=True)
class FieldSpec:
name: str
unit: str
role: str
minimum: float
maximum: float
type: str = "continuous"
FIELD_SPECS = [
FieldSpec("indoor_temp", "degC", "state", -30, 70),
FieldSpec("mass_temp", "degC", "state", -30, 70),
FieldSpec("energy_kwh", "kWh", "state", 0, 1e6),
FieldSpec("water_level", "m3", "state", 0, 50),
FieldSpec("water_temp", "degC", "state", -5, 80),
FieldSpec("flow", "m3/h", "state", 0, 20),
FieldSpec("pressure", "kPa", "state", 0, 300),
FieldSpec("state_of_charge", "fraction", "state", 0, 1),
FieldSpec("battery_temp", "degC", "state", -30, 80),
FieldSpec("terminal_voltage", "V", "state", 10, 70),
FieldSpec("hvac_power", "kW", "action", -15, 15),
FieldSpec("valve_position", "fraction", "action", 0, 1),
FieldSpec("pump_output", "fraction", "action", 0, 1),
FieldSpec("battery_power", "kW", "action", -20, 20),
FieldSpec("outdoor_temp", "degC", "exogenous", -30, 60),
FieldSpec("solar_gain", "kW", "exogenous", 0, 5),
FieldSpec("occupancy_gain", "kW", "exogenous", 0, 3),
FieldSpec("demand", "m3/h", "exogenous", 0, 10),
FieldSpec("inlet_temp", "degC", "exogenous", -5, 60),
FieldSpec("ambient_temp", "degC", "exogenous", -30, 60),
]
FIELD_INDEX = {spec.name: i for i, spec in enumerate(FIELD_SPECS)}
NUM_FIELDS = len(FIELD_SPECS)
UNIT_NAMES = tuple(dict.fromkeys(spec.unit for spec in FIELD_SPECS))
ROLE_NAMES = ("state", "action", "exogenous")
UNIT_IDS = np.array([UNIT_NAMES.index(spec.unit) for spec in FIELD_SPECS], dtype=np.int64)
ROLE_IDS = np.array([ROLE_NAMES.index(spec.role) for spec in FIELD_SPECS], dtype=np.int64)
SCHEMAS = {
"thermal": [
"indoor_temp",
"mass_temp",
"energy_kwh",
"hvac_power",
"outdoor_temp",
"solar_gain",
"occupancy_gain",
],
"tank": [
"water_level",
"water_temp",
"flow",
"pressure",
"valve_position",
"pump_output",
"demand",
"inlet_temp",
],
"battery": ["state_of_charge", "battery_temp", "terminal_voltage", "battery_power", "ambient_temp"],
}
MAX_STATE_FIELDS = max(sum(FIELD_SPECS[FIELD_INDEX[n]].role == "state" for n in s) for s in SCHEMAS.values())
def role_fields(schema, role):
return [n for n in schema if FIELD_SPECS[FIELD_INDEX[n]].role == role]
def field_mask(schema):
mask = np.zeros(NUM_FIELDS, dtype=bool)
mask[[FIELD_INDEX[n] for n in schema]] = True
return mask
|