Detecting Heating Season
Finding Heating Season using Outside Temperature Time Series¶
The present notebook deduces heating season from outside temperature time series. This deduction is sensitive to the approach used and to the parameters choosen.
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.io as pio
# Needed for correct layout of the produced html
pio.renderers.default='notebook'
pd.options.plotting.backend = "plotly"
Imports of input data¶
In this Section, input data are loaded.
These input data are composed of a trajectory of external temperature and the dates of heating season. The heating season initially loaded will not be used. We will calculate new heating season.
from heatpro.external_factors import ExternalFactors, EXTERNAL_TEMPERATURE_NAME, non_heating_season_basic
#loading external temperature
df = pd.read_csv('../data/external_factors.csv',index_col=0,parse_dates=True)
Calculating Heating Season¶
The cell bellow calculate the heating season for two configurations of the basic
approach. The non_heating_season_basic
function will find the start and the end of the non-heating season of a year.
The non-heating season is defined as the larger periods where the share of hot days is above a hot days part threshold. Hot days are defined as day where the average day temperature is above a certain temperature threshold.
Hot day temperature threshold | Hot day share thresholde | |
---|---|---|
Configuration #1 | 16 °C | 85 % |
Configuration #2 | 17 °C | 90 % |
df["Heating season - config#1"] = True
for year in df.index.year.unique():
start_NHS, end_NHS = non_heating_season_basic(df.loc[str(year)][EXTERNAL_TEMPERATURE_NAME],16,0.85)
df.loc[start_NHS:end_NHS,"Heating season - config#1"] = False
df["Heating season - config#2"] = True
for year in df.index.year.unique():
start_NHS, end_NHS = non_heating_season_basic(df.loc[str(year)][EXTERNAL_TEMPERATURE_NAME],17,0.9)
df.loc[start_NHS:end_NHS,"Heating season - config#2"] = False
fig = go.Figure([
go.Scatter(
x = df.index,
y = df[EXTERNAL_TEMPERATURE_NAME],
name = 'Outside Temperature',
# marker_color="#5C5C5C ",
showlegend=True,
),
],
layout_title_text="External Factors",
layout_yaxis_title='<b>°C</b>',
layout_legend=dict(
orientation="h",
yanchor="top",
xanchor="left",
y=-0.1,
),
layout_hovermode='x unified',
)
changes = df["Heating season - config#1"].diff().astype(bool).fillna(False)
changing_date = changes[changes == True][1:]
for start, end in zip(changing_date[::2].index,changing_date[1::2].index):
fig.add_vline(
x=start,
line_color="red",
)
fig.add_vline(
x=end,
line_color="red",
)
fig.add_annotation(
text="Heating season - config#1",
x=start + (end-start)/2,
y=-2,
font = dict(size=10, color='red'),
showarrow=False,
xanchor="center",
)
changes = df["Heating season - config#2"].diff().astype(bool).fillna(False)
changing_date = changes[changes == True][1:]
for start, end in zip(changing_date[::2].index,changing_date[1::2].index):
fig.add_vline(x=start, line_color="green",)
fig.add_vline(x=end, line_color="green",)
fig.add_annotation(text="Heating season - config#2",x=start + (end-start)/2,y=5,font = dict(size=10, color='green'),showarrow=False,xanchor="center",)
fig.show()