Gradients#

Heating and cooling gradients (rate of change per hour) of a temperature series, classified by direction and season.

All plots are interactive — hover to see exact values.

import plotly.io as pio
pio.renderers.default = "notebook_connected"

Load sample data#

The bundled flat_temp.csv contains hourly indoor temperature readings.

import pandas as pd
from importlib import resources

data_path = resources.files("pyedautils") / "data" / "flat_temp.csv"
temp = pd.read_csv(data_path, sep=";", index_col="timestamp", parse_dates=True)
temp.columns = ["temperature"]
temp.head()
temperature
timestamp
2018-10-03 00:00:00 24.43
2018-10-03 01:00:00 24.40
2018-10-03 02:00:00 24.40
2018-10-03 03:00:00 24.40
2018-10-03 04:00:00 24.40

Compute gradients#

compute_gradients resamples to hourly means, takes the step-to-step difference and keeps only steps above the magnitude threshold. The sign decides the direction (heating vs cooling).

from pyedautils.data_prep.gradients import compute_gradients

grad = compute_gradients(temp["temperature"], threshold=0.3)
grad.head()
timestamp gradient direction season
0 2018-10-04 09:00:00 -0.33 cooling Fall
1 2018-10-04 11:00:00 0.52 heating Fall
2 2018-10-10 06:00:00 -0.33 cooling Fall
3 2018-10-10 07:00:00 -0.65 cooling Fall
4 2018-10-10 08:00:00 -0.58 cooling Fall

Summary per direction#

summarize_gradients gives mean / min / max and the count per direction.

from pyedautils.data_prep.gradients import summarize_gradients

summarize_gradients(grad)
direction mean min max n
0 heating 0.45 0.3 1.8 554
1 cooling -0.53 -2.1 -0.3 688

Boxplots by season#

plot_gradient_boxplots compares the heating and cooling spread per group (season, quarter, month, weekday or hour).

from pyedautils.plots import plot_gradient_boxplots

fig = plot_gradient_boxplots(grad, groupby="season")
fig.show()