Along this vignette, the classification of load curves is presented. Data from a single building in biggr dataset is used as sample case. Daily load classification is done after clustering data considering both absolute consumption and temperature

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Load the needed libraries

library(data.table)
library(ggplot2)
library(gridExtra)
library(plotly)
library(padr)
library(htmlwidgets)
library(carrier)
library(biggr)

Load an example dataset

The biggr package has internally preloaded six datasets containing hourly electricity consumption and weather data from six different buildings.

data(biggr)
df <- electricity3 %>% calendar_components(localTimeZone = "Europe/Madrid")
df <- cbind(df, do.call(cbind,oce::sunAngle(df$time,latitude=41.5,longitude=1))[,c("azimuth","altitude")])
df <- df %>% filter(!duplicated(df$time))
# Time series plots
ts_p <- ggplot(
    reshape2::melt( df %>% select(time, Qe, temperature, windSpeed, GHI) %>% pad(), 
                    "time")
  ) + 
  geom_line(
    aes(time,value)
  ) + 
  facet_wrap(~variable, scales = "free_y", ncol=1) +
  theme_bw()
ts_p <- ggplotly(ts_p)
ts_p
# Scatter plots of the electricity consumption and outdoor temperature
grid.arrange(
  ggplot(aggregate(df[,c("temperature","Qe")],by=list("date"=as.Date(df$localtime)),FUN=mean)) + 
      geom_point(
        aes(temperature, Qe),
        size=0.05
    )
)
# All daily load curves at once
ggplot(df) + 
  geom_line(
    aes(hour, Qe, group=date),
    alpha=0.05
  ) + xlab("hour of the day")
# All weekly load curves at once
ggplot(df) + 
  geom_line(
    aes(weekhour, Qe, group=paste(strftime(localtime,"%Y"),strftime(localtime,"%U"))),
    alpha=0.1
  ) + xlab("hour of the week")

Clustering the daily load curves

clust <- clustering_dlc(
  data = df,
  consumptionFeature = "Qe", 
  outdoorTemperatureFeature = "temperature", 
  localTimeZone = "Europe/Madrid", 
  kMax = 4, 
  inputVars = c("loadCurves","dailyConsumption"),
  loadCurveTransformation = "absolute",
  nDayParts = 24
)
if("s" %in% colnames(df))
  df <- df %>% select(-s) 
df <- df %>% left_join(clust$dailyClassification)
df <- df[!is.na(df$s),] # Once the classification procedure works, no need for this.
# All daily load curves depending the patterns detected
p <- ggplotly(
  ggplot(df) + 
    geom_line(
      aes(hour, Qe, group=date, col=s),
      alpha=0.05
    ) + 
    xlab("hour of the day") + 
    facet_wrap(~s) +
    theme_bw()
  )
saveWidget(p, "classification_clustering_dlc.html", selfcontained = T)
p

Classification of daily curves

Classify data using previous obtained clusters and "absoluteLoadCurvesCentroids" method

df$s <- NULL
tmp <- classification_dlc(data=df,
  consumptionFeature="Qe",
  outdoorTemperatureFeature="temperature",
  localTimeZone="Europe/Madrid",
  clustering=clust,
  methodPriority="absoluteLoadCurvesCentroids")
# All daily load curves depending the patterns detected
p <- ggplotly(
  ggplot(tmp) + 
    geom_line(
      aes(hour, consumption, group=date, col=s),
      alpha=0.05
    ) + 
    xlab("hour of the day") + 
    facet_wrap(~s) +
    theme_bw()
  )
saveWidget(p, "classification_dlc.html", selfcontained = T)
p


biggproject/biggr documentation built on Oct. 2, 2024, 11:13 p.m.