forked from CommerceDataService/NZERTF
-
Notifications
You must be signed in to change notification settings - Fork 1
/
learn.html
424 lines (349 loc) · 21.9 KB
/
learn.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>NIST Net-Zero Learn Page</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<title>NIST Net-Zero - Learn More</title>
<meta name="description" content="NIST Net-Zero learn page to get tutorials on data usage">
<link href="css/nzertf.css" rel="stylesheet">
<link href="css/cursor.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Coda:400,800' rel='stylesheet' type='text/css'>
<!--Dropdowns-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/nzertf.js"></script>
<!-- Syntax Highlighting -->
<!-- Support for the following languages: -->
<!-- Apache, Bash, C#, C++, CSS, CoffeeScript, Device Tree, Diff, HTML, XML, HTTP, Ini, JSON, Java, JavaScript, Makefile, Markdown, Nginx, Objective-C, PHP, Perl, Python, Ruby, SQL, Fortran, Julia, Lisp, Lua, Mathematica, Matlab, Python-Profile, R, Scilab, Scala, Stata, Swift -->
<link rel="stylesheet" type="text/css" href="css/mono-blue.css"><!-- Style for highlighting Code: Default to Github -->
<script src="js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script><!-- Activate Code Highlighting -->
</head>
<body data-spy="scroll" data-target="#side-nav">
<header>
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><img src="img/nist.png" alt="NIST logo" height="25">Engineering Laboratory</a>
</div>
<div class="collapse navbar-collapse parentMenu">
<ul class="nav navbar-nav">
<li class="dropdown"><a class="dropbtn" href="research.html">Research <span class="caret"></span></a>
<div class="dropdown-content">
<a href="research.html#ongoing_research">Ongoing Research at NIST</a>
<a href="research.html#external_research">External Research Efforts</a>
<a href="research.html#potential_research">Potential Research Avenues</a>
</div>
</li>
<li class="dropdown"><a class="dropbtn" href="data.html">Data <span class="caret"></span></a>
<div class="dropdown-content">
<a href="data.html#data_dictionary">Data Dictionary</a>
<a href="data.html#log_revisions">Known Data Gaps and Issues</a>
<a href="data.html#download_data">Download Data</a>
<a href="data.html#data_faq">FAQ</a>
<a href="data.html#data_citation">Citation</a>
</div>
</li>
<li class="dropdown"><a class="dropbtn" href="learn.html">Learn <span class="caret"></span></a>
<div class="dropdown-content">
<a href="learn.html#Data-From-Subsystem">Work with Data from a Subsystem</a>
<a href="learn.html#Data-By-Timestamp">Extract Data by Timestamp</a>
<a href="learn.html#Analyze-Aggregate-Readings">Analyzing Aggregated Readings</a>
<a href="learn.html#csv_to_json">Convert CSV to JSON</a>
</div>
</li>
<li><a href="https://www.nist.gov/el" target="_blank">About EL</a></li>
</ul>
</div>
<!-- /.nav-collapse -->
</div>
</div>
</header>
<div class="container">
<div class="row content-row row-offcanvas row-offcanvas-left">
<!-- SIDE NAVBAR -->
<nav class="col-xs-6 col-sm-3 sidebar-offcanvas sidenav-padding" id="side-nav">
<ul id="sidebar" class="nav nav-stacked fixed">
<li><a href="#Data-From-Subsystem">Work with data from a subsystem</a>
<ul class="nav nav-stacked sub-section">
<li><a href="#Data-From-Subsystem-A">Get the Data</a></li>
<li><a href="#Data-From-Subsystem-B">Work with the Data</a></li>
</ul>
</li>
<li><a href="#Data-By-Timestamp">Extract data by timestamp</a>
<ul class="nav nav-stacked sub-section">
<li><a href="#Data-By-Timestamp-A">Get the Data</a></li>
<li><a href="#Data-By-Timestamp-B">Work with the Data</a></li>
</ul>
</li>
<li><a href="#Analyze-Aggregate-Readings">Analyzing Aggregated Readings</a>
<ul class="nav nav-stacked sub-section">
<li><a href="#Analyze-Aggregate-Readings-A">Get the Data</a></li>
<li><a href="#Analyze-Aggregate-Readings-B">Work with the Data</a></li>
</ul>
</li>
<li><a href="#csv_to_json">Convert CSV to JSON</a>
</li>
</ul>
</nav>
<!--CONTENT SECTION-->
<div class="col-xs-12 col-sm-9 content_stuff">
<section id="Data-From-Subsystem" class="group">
<h1>Work with data from a subsystem</h1>
<p>Data from the net-zero house includes 400+ variables that include readings from instrumentation around the house in one minute increments. Each of these variables, also called channels in NIST documentation, provides the readings from one instrument, and the instruments are grouped into subsystems:
<br>
<ul>
<li>DHW - Domestic Hot Water</li>
<li>SHW - Solar Hot Water</li>
<li>Load - Electrical and Thermal Loads by equipment and people</li>
<li>HVAC - Heating and Cooling System</li>
<li>IndEnv - Indoor Environment</li>
<li>PV - Photovoltaic</li>
<li>OutEnv - Outdoor Environment</li>
<li>Vent - Ventilation</li>
<li>Elec - Electrical</li>
</ul>
</p>
<br>
<p>This tutorial walks through loading data from a particular subsystem.</p>
<div id="Data-From-Subsystem-A" class="subgroup">
<h3>Get the data you need</h3>
<p>If you want to analyze net-zero data for specific subsystems, rather than data for the whole house, you can download the data from the net-zero website and import it into R, or you can use the download link directly.</p>
<p>For example, if you wanted to analyze the channels (like the heat pump air flow rate or the total power used by the heat pump) in the HVAC subsystem, you could pull data for that subsystem:</p>
<pre><code class="r">
# load libraries
library(ggplot2) # plotting library
# get data
hvac <- read.csv("https://s3.amazonaws.com/nist-netzero/2015-data-files/HVAC-minute.csv", header=TRUE, na.strings=c("NA", "NULL", "", " "))
</code></pre>
<p>Here are the variables included in the HVAC subsystem data. The nomenclature includes the name of the subsystem and the name of the channel as SubSystem_Channel.</p>
<pre><code>
names(hvac)
</code></pre>
<pre><code>
## [1] "Timestamp"
## [2] "TimeStamp_Count"
## [3] "TimeStamp_SchedulerTime"
## [4] "TimeStamp_SystemTime"
## [5] "DayOfWeek"
## [6] "HVAC_HVACDeltaPPressureDiffacrossIndoorUnit"
## [7] "HVAC_HVACDewpointReturnAir"
## [8] "HVAC_HVACDewpointSupplyAir"
## [9] "HVAC_HVACTempReturnAir"
## [10] "HVAC_HVACTempSupplyAir"
## [11] "HVAC_HeatPumpIndoorEnergyTotal"
## [12] "HVAC_HeatPumpIndoorPowerTotal"
## [13] "HVAC_HeatPumpOutdoorEnergyTotal"
## [14] "HVAC_HeatPumpOutdoorPowerTotal"
## [15] "HVAC_HeatPumpEnergyIndoorunit"
## [16] "HVAC_HeatPumpEnergyOutdoorUnit"
## [17] "HVAC_X1421IDUnitPowerDemandW"
## [18] "HVAC_X1422ODUnitPowerDemandW"
## [19] "HVAC_X1423UltraAire70HPowerW"
## [20] "HVAC_UltraAire70HInletAirAvgTempF"
## [21] "HVAC_UltraAire70HExitAirAvgTempF"
## [22] "HVAC_UltraAire70HAirflowCFM"
</code></pre>
</div>
<div id="Data-From-Subsystem-B" class="subgroup">
<h3>Working with the Data</h3>
<p>Once you have your data, you can visualize the Supply and Return air temperatures by season.</p>
<p>First, convert <i>Timestamp</i> into a date/time format using strptime():</p>
<pre><code>
# converts Timestamp variable into date/time format (POSIXlt)
hvac$Timestamp <- strptime(hvac$Timestamp, "%Y-%m-%d %H:%M:%S")
# quick check of the values in the Timestamp variable
hvac$Timestamp[1:10]
</code></pre>
<pre><code>
## [1] "2015-02-01 00:00:00 EST" "2015-02-01 00:01:00 EST"
## [3] "2015-02-01 00:02:00 EST" "2015-02-01 00:03:00 EST"
## [5] "2015-02-01 00:04:00 EST" "2015-02-01 00:05:00 EST"
## [7] "2015-02-01 00:06:00 EST" "2015-02-01 00:07:00 EST"
## [9] "2015-02-01 00:08:00 EST" "2015-02-01 00:09:00 EST"
</code></pre>
<p>Now we can use the <i>Timestamp</i> variable to create a new categorical 'season' variable:</p>
<pre><code>
# create a variable for seasons
hvac$season <- "summer"
hvac$season[hvac$Timestamp < '2015-03-20 12:30:00'] <- "spring"
hvac$season[hvac$Timestamp > '2015-09-22 10:21:00' & hvac$Timestamp < '2015-12-21 05:44:00'] <- "fall"
hvac$season[hvac$Timestamp > '2015-12-21 05:44:00'] <- "winter"
hvac$season <- ordered(hvac$season, levels = c("spring", "summer", "fall", "winter"))
# now we can do things like group readings by season
ggplot(hvac, aes(x = season, y = HVAC_HVACTempSupplyAir, fill = season)) +
geom_violin(scale = "area") +
ggtitle("HVAC Air Supply Temperature by Season")
</code></pre>
<img class="image-padding" src="img/NIST-NetZero-HVAC-Temperature-By-Season.png" alt="HVAC temporature by season visualization" width="672">
<p>Additionally, we can compare readings between channels in the subsystem; this compares the air temperature in the HVAC supply air with the retun air:</p>
<pre><code class="r">
# Visualize supply and return air temperature
ggplot(hvac, aes(x = Timestamp)) +
geom_point(aes(y = HVAC_HVACTempSupplyAir, colour = season), alpha = 0.10, size = 1) +
geom_point(aes(y = HVAC_HVACTempReturnAir), colour = "grey", alpha = 0.10, size = 1) +
xlab("Time") +
ggtitle("Seasonal Air Vent Supply and Return Temperatures in the HVAC Subsystem")
</code></pre>
<img class="image-padding" src="img/NIST-NetZero-HVAC-Subsystem.png" width="672" alt="HVAC subsystem visualization">
</div>
</section>
<section id="Data-By-Timestamp" class="group">
<h2>Extract data by Timestamp</h2>
<p>The net-zero data also includes a few date/time variables like <i>Timestamp</i>, which is the date and timestamp for each reading, <i>DayOfWeek</i> and <i>TimeStampCount</i>.
<br>
<br>
<p>This tutorial walks through filtering data based on time of day, and comparing channel readings by day of the week.</p>
<div id="Data-By-Timestamp-A" class="subgroup">
<h3>Get the data you need</h3>
<p>If you want to analyze net-zero data for specific subsystems, rather than data for the whole house, you can download the data from the <a href="https://pages.nist.gov/netzero/data.html"> net-zero data portal</a> and import it into R, or you can use the download link directly like we did below.</p>
<p>In order to analyze data from channels (i.e. instrumentation data) in the <i>Electrical</i> subsystem, we can import the data using read.csv():</p>
<pre><code class="r">
# load libraries
library(ggplot2) # plotting library
# get data
elec <- read.csv("https://s3.amazonaws.com/nist-netzero/2015-data-files/Elec-minute.csv", header=TRUE, na.strings=c("NA", "NULL", "", " "))
</code></pre>
<p>There are 144 variables in the <i>Electrical</i> subsystem, here are the first 20 variables. The nomenclature includes the name of the subsystem and the name of the channel as <i>SubSystem_Channel</i>.</p>
<pre><code>
names(elec)[1:20]
</code></pre>
<pre><code>
## [1] "Timestamp"
## [2] "TimeStamp_Count"
## [3] "TimeStamp_SchedulerTime"
## [4] "TimeStamp_SystemTime"
## [5] "DayOfWeek"
## [6] "Elec_EnergyRPB1PlugsBaseAHeliodyneHXs"
## [7] "Elec_EnergyRPB13PlugsDR"
## [8] "Elec_EnergyRPB14PlugsBR4"
## [9] "Elec_EnergyRPB15PlugsEntryHall"
## [10] "Elec_EnergyRPB16PlugsLR"
## [11] "Elec_EnergyRPB17ClothesWasher"
## [12] "Elec_EnergyRPB18Dryer1of2"
## [13] "Elec_EnergyRPB19Dehumidifier"
## [14] "Elec_EnergyRPB2PlugsBaseB"
## [15] "Elec_EnergyRPB20Dryer2of2"
## [16] "Elec_EnergyRPB21HeatPump1of2"
## [17] "Elec_EnergyRPB22AHU21of2"
## [18] "Elec_EnergyRPB23HeatPump2of2"
## [19] "Elec_EnergyRPB24AHU22of2"
## [20] "Elec_EnergyRPB25HRV"
</code></pre>
</div>
<div id="Data-By-Timestamp-B" class="subgroup">
<h3>Filter and visualize the data</h3>
<p>Before we can visualize this data by date or time, we need to convert <i>Timestamp</i> into a date/time format using strptime().</p>
<pre><code>
# converts Timestamp variable into date/time format (POSIXlt)
elec$Timestamp <- strptime(elec$Timestamp, "%Y-%m-%d %H:%M:%S")
</code></pre>
<p>Here is a sample of what that looks like:</p>
<pre><code>
elec$Timestamp[1:10]
</code></pre>
<pre><code>
## [1] "2015-02-01 00:00:00 EST" "2015-02-01 00:01:00 EST"
## [3] "2015-02-01 00:02:00 EST" "2015-02-01 00:03:00 EST"
## [5] "2015-02-01 00:04:00 EST" "2015-02-01 00:05:00 EST"
## [7] "2015-02-01 00:06:00 EST" "2015-02-01 00:07:00 EST"
## [9] "2015-02-01 00:08:00 EST" "2015-02-01 00:09:00 EST"
</code></pre>
<p>Now we can choose a random day and look at what the refrigerator readings looked like by filtering our data using on <i>Timestamp</i> and using the <i>Elec_PowerRefrigerator</i> variable.</p>
<pre><code>
ggplot(elec[elec$Timestamp < '2015-10-02 00:00:00' & elec$Timestamp > '2015-10-01 00:00:00',], aes(x = Timestamp, y = Elec_PowerRefrigerator)) +
geom_line(alpha = 0.4) +
ggtitle("Instantaneous Power Consumption by Refrigerator")
</code></pre>
<img class="image-padding" src="img/NIST-NetZero-Instan-Consump-Refrig.png" width="673" alt="Refrigerator instantaneous consupmption by refrigerator visualization">
<p>Alternatively, to look at the cumulative energy consumption for that day (which resets once a day), we could visualize the <i>Elec_EnergyRefrigerator</i> variable.</p>
<pre><code>
ggplot(elec[elec$Timestamp < '2015-10-02 00:00:00' & elec$Timestamp > '2015-10-01 00:00:00',], aes(x = Timestamp, y = Elec_EnergyRefrigerator)) +
geom_line(alpha = 0.4) +
ggtitle("Cumulative Energy Consumption by Refrigerator")
</code></pre>
<img class="image-padding" src="img/NIST-NetZero-Cumul-Power-Refrig.png" width="673" alt="Refrigerator Channel cumulative power by day visualization">
<p>Visualizing instaneous power consumption by the refrigerator for that day in comparison to the rest of the week would allow us to see any spikes in power consumption.</p>
<pre><code>
ggplot(elec[elec$Timestamp < '2015-10-05 00:00:00' & elec$Timestamp > '2015-09-28 00:00:00',], aes(x = Timestamp , y = Elec_PowerRefrigerator)) +
geom_point(alpha = 0.4) +
geom_point(data = elec[elec$Timestamp < '2015-10-01 00:00:00' & elec$Timestamp > '2015-09-30 00:00:00',], alpha = 0.4, color = "blue") +
ggtitle("Refrigerator Channel Readings")
</code></pre>
<img class="image-padding" src="img/NIST-NetZero-Refrig-Channel-Readings.png" width="673" alt="Refrigerator Channel Readings visualization">
</div>
</section>
<section id="Analyze-Aggregate-Readings" class="group">
<h2>Analyzing Aggregated Readings</h2>
<p>Channels provide data at the instrumentation-level, however it is possible to analyze aggregate readings at the subsystem level.</p>
<p>This tutorial walks through analyzing aggregate/total instantaneous readings for channels in the <i>Electrical</i> subsystem</p>
<div id="Analyze-Aggregate-Readings-A" class="subgroup">
<h3>Get the data you need</h3>
<p>First, we can use the download link from the Data page to import the data for the <i>Electrical</i> Subsystem:</p>
<pre><code class="r">
# load libraries
library(ggplot2) # plotting library
library(reshape2) # library for reshaping data easily
# get data
elec <- read.csv("https://s3.amazonaws.com/nist-netzero/2015-data-files/Elec-minute.csv", header=TRUE, na.strings=c("NA", "NULL", "", " "))
</code></pre>
</div>
<div id="Analyze-Aggregate-Readings-B" class="subgroup">
<h3>Working with the data</h3>
<p>There are 158 channels in the Electrical subsystem, however it is possible to aggregate those instantaneous power consumption readings.</p>
<pre><code class="r">
# Row and column count for Electrical channel data
dim(elec)
</code></pre>
<pre><code>
## [1] 524161 163
</code></pre>
<pre><code class="r">
# create an object that only has instantaneous power readings
elec_power <- elec[,c("Timestamp", names(elec)[grep("_Power", names(elec))])]
# using the data dictionary or metadata files, this object could be narrowed down to power consumption in one room or for a specific appliance
# the 'total' variable below is a sum of all electrical power consumption channels
elec_power$total <- rowSums(elec_power[,2:ncol(elec_power)])
# ggplot(elec_power[,c("Timestamp", "total")], aes(x = Timestamp, y = total)) +
geom_point(aes(colour = strftime(elec_power$Timestamp, format = "%m")), alpha = 0.4) +
geom_smooth() +
theme(legend.position="none") +
ggtitle("Total Instantaneous Power Consumption Readings")
</code></pre>
<img class="image-padding" src="img/NIST-NetZero=Instan-Power-Consump.png" width="673" alt="Total Instantaneous Power Consumption Readings visualization">
</div>
<div id="csv_to_json" class="subgroup">
<br>
<br>
<h3>From CSV to JSON</h3>
<p>When you download the files from the <a href="data.html#download_data">Download table</a> it will be as a CSV file. If you are interested in building a project using JavaScript, NodeJS, or anything that is more suited to JSON file structures - you will need to covert them from CSVs to JSON. In our work we have recommended using the <a href="https://www.npmjs.com/package/csvtojson">CSVtoJSON Converter</a> module that you can download from npm. Once you have downloaded the npm module you can use the following code as a template to convert the raw CSV to a JSON file. (We do not recommend this tutorial for converting the 'All Subsystems' CSV file because of its size). </p>
<pre><code>
var Converter = require('csvtojson').Converter;
var converter = new Converter({
constructResult: false, ## if you are using a large file it does not hold the data to memory
toArrayString: true ## pipes the data to an array
});
var readStream = require('fs').createReadStream('../All-Subsystems-minute.csv'); ## relative path to where the downloaded CSV is in your repo
var writeStream = require('fs').createWriteStream('../output.json'); ## relative path to where you would like the JSON file to be made
readStream.pipe(converter).pipe(writeStream);
</code></pre>
<p>Please see the documentation <a href="https://www.npmjs.com/package/csvtojson">(link)</a> for all options that are available to you. In addition, if you are curious about <a href="https://nodejs.org/api/fs.html#fs_file_system">File Streams</a> in Node feel free to take a look at its documentation as well.</p>
<br>
</div>
</section>
<hr \>
<section class="footer">
<br>
<a target="_blank" href="http://www.nist.gov/public_affairs/privacy.cfm#privpolicy">Privacy Policy</a> | <a target="_blank" href="http://www.nist.gov/public_affairs/privacy.cfm#secnot">Security Notice</a> | <a target="_blank" href="http://www.nist.gov/public_affairs/privacy.cfm#accesstate">Accessibility Statement</a> | <a target="_blank" href="mailto:[email protected]?subject=Feedback%20on%20Web%20Site%20Template">Send feedback</a>
</section>
</div>
</div>
</div>
</body>
</html>