-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16-explore.Rmd
More file actions
171 lines (142 loc) · 4.73 KB
/
16-explore.Rmd
File metadata and controls
171 lines (142 loc) · 4.73 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Model Exploration {#explore}
```{r, include=FALSE}
source("_common.R", local = knitr::knit_global())
```
## Prerequisites
In this chapter we will explore the model to uncover energy characteristics and
create an overview of general trends. We will use eplusr to run the EnergyPlus
simulation and extract relevant model inputs/outputs, `{tidyverse}` for data
transformation, and `{ggplot2}` to visualize the extracted and subsequently
transformed data.
```{r, message=FALSE}
library(eplusr)
library(tidyverse)
library(lubridate)
library(ggplot2)
library(here)
```
We will be working with the IDF and EPW file that pertains to the U.S.
Department of Energy (DOE) Commercial Reference Building and Chicago's TMY3
respectively.
```{r, message=FALSE}
path_idf <- here("data", "idf", "RefBldgMediumOfficeNew2004_Chicago.idf")
model <- read_idf(path_idf)
path_epw <- here("data", "epw", "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")
epw <- read_epw(path_epw)
```
## Extracting
Before carrying out any model exploration, you need to first specify the outputs
of interest. The code below preprocesses the model by adding the list of output
meters and variables to the model (See Chapter \@ref(output) for details).
```{r}
preprocess_idf <- function(idf, meters, variables) {
# make sure weather file input is respected
idf$SimulationControl$Run_Simulation_for_Weather_File_Run_Periods <- "Yes"
# make sure simulation is not run for sizing periods
idf$SimulationControl$Run_Simulation_for_Sizing_Periods <- "No"
# make sure energy consumption is presented in kWh
if (is.null(idf$OutputControl_Table_Style)) {
idf$add(OutputControl_Table_Style = list("HTML", "JtoKWH"))
} else {
idf$OutputControl_Table_Style$Unit_Conversion <- "JtoKWH"
}
# remove all existing meter and variable outputs
if (!is.null(idf$`Output:Meter`)) {
idf$Output_Meter <- NULL
}
# remove all existing meter and variable outputs
if (!is.null(idf$`Output:Table:Monthly`)) {
idf$`Output:Table:Monthly` <- NULL
}
if (!is.null(idf$`Output:Variable`)) {
idf$Output_Variable <- NULL
}
# add meter outputs to get hourly time-series energy consumption
idf$add(Output_Meter := meters)
# add variable outputs to get hourly zone air temperature
idf$add(Output_Variable := variables)
# make sure the modified model is returned
return(idf)
}
meters <- list(
key_name = c(
"Cooling:Electricity",
"Heating:NaturalGas",
"Heating:Electricity",
"InteriorLights:Electricity",
"ExteriorLights:Electricity",
"InteriorEquipment:Electricity",
"Fans:Electricity",
"Pumps:Electricity",
"WaterSystems:NaturalGas"
),
Reporting_Frequency = "Hourly"
)
variables <- list(
key_value = "*",
Variable_Name = c(
"Site Outdoor Air Drybulb Temperature",
"Site Outdoor Air Relative Humidity"
),
Reporting_Frequency = "Hourly"
)
model <- preprocess_idf(model, meters, variables)
```
You can then run the simulation and it will be possible to extract the output of
interest from the model.
```{r, out.lines = 15}
model$save(here("data", "idf", "model_preprocessed.idf"), overwrite = TRUE)
job <- model$run(epw, dir = tempdir())
```
## Energy signature
```{r}
pt_of_interest <- c(
"Site Outdoor Air Drybulb Temperature",
"Cooling:Electricity",
"Heating:NaturalGas"
)
report <- job$report_data(
name = pt_of_interest, environment_name = "annual",
all = TRUE, wide = TRUE
) %>%
select(datetime, month, day, hour, day_type, contains(pt_of_interest)) %>%
rename_with(~pt_of_interest, .cols = contains(pt_of_interest)) %>%
pivot_longer(
cols = c("Cooling:Electricity", "Heating:NaturalGas"),
names_to = "type", values_to = "value"
) %>%
mutate(
value = value * 1e-6, # convert J to MJ
month = ordered(month.abb[month], month.abb) # replace month index with month name
)
```
```{r}
ggplot(report, aes(
x = `Site Outdoor Air Drybulb Temperature`,
y = value,
color = type
)) +
geom_point(shape = 1, alpha = 0.7) +
facet_grid(rows = vars(type)) +
scale_color_brewer(palette = "Set2") +
xlab(expression("Outdoor drybulb temperature" ~ (degree * C))) +
ylab("Energy consumption (MJ)") +
theme(legend.position = "none")
```
```{r}
report_heating <- report %>%
filter(type == "Heating:NaturalGas")
ggplot(report_heating, aes(
x = day, y = hour,
fill = value
)) +
geom_tile() +
scale_fill_viridis_c(
name = "Heating\nEnergy (MJ)",
option = "plasma"
) +
facet_grid(cols = vars(month)) +
ylab("Hour of the day") +
xlab("Day of the week") +
theme(legend.position = "bottom")
```