-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotTempHumidity.py
More file actions
162 lines (124 loc) · 4.56 KB
/
Copy pathplotTempHumidity.py
File metadata and controls
162 lines (124 loc) · 4.56 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
#!/usr/bin/env python
"""
Copyright(C) 2020, BrucesHobbies
All Rights Reserved
AUTHOR: BruceHobbies
DATE: 12/22/2020
REVISION HISTORY
DATE AUTHOR CHANGES
yyyy/mm/dd --------------- -------------------------------------
OVERVIEW:
This program plots temperatures and humidity from the CSV files
generated by sdrWeatherStn.py
LICENSE:
This program code and documentation are for personal private use only.
No commercial use of this code is allowed without prior written consent.
This program is free for you to inspect, study, and modify for your
personal private use.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
INSTALLATION:
Requires:
sudo pip3 install matplotlib
"""
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
import math
import time
import datetime
import csv
stationFilenames = ["Acurite-Tower Id nnnn Ch C.csv","Ambientweather-F007TH Id nn Ch 1.csv","Ambientweather-F007TH Id nn Ch 2.csv"]
stationNames = ["Outdoor","Indoor","PumpHse"]
#
# Read in a comma seperated variable file. Assumes a header row exists.
# Time series with time in seconds in first column.
#
def importCsv(filename) :
print("Reading " + filename)
with open(filename, 'r') as csvfile :
data = list(csv.reader(csvfile))
header = data[0]
tStamp = []
temp = []
humidity = []
if "temperature_C" in header :
tIdx = header.index("temperature_C")
elif "temperature_F" in header :
tIdx = header.index("temperature_F")
else :
tIdx = 0
if "humidity" in header :
hIdx = header.index("humidity")
else :
hIdx = 0
for row in data[1:] :
tStamp.append(float(row[0]))
temp.append(float(row[tIdx]))
humidity.append(float(row[hIdx]))
return header, tStamp, temp, humidity
#
# Plot
#
def plotSingle(t, var, ylabel, title) :
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(t, var)
# ax1.plot(t, var, marker='d')
ax1.set_title(title)
ax1.set_xlabel('Time')
ax1.set_ylabel(ylabel)
# ax1.legend(loc='upper right', shadow=True)
ax1.grid(which='both')
plt.gcf().autofmt_xdate() # slant labels
dateFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
plt.gca().xaxis.set_major_formatter(dateFmt)
plt.show(block=False)
#
# Plot the files
#
if __name__ == "__main__" :
fig1 = plt.figure()
ax1 = fig1.add_subplot(1, 1, 1)
ax1.set_title("Temperature")
ax1.set_xlabel('Time')
ax1.set_ylabel("Temp Degrees")
ax1.grid(which='both')
plt.gcf().autofmt_xdate() # slant labels
dateFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
plt.gca().xaxis.set_major_formatter(dateFmt)
fig2 = plt.figure()
ax2 = fig2.add_subplot(1, 1, 1)
ax2.set_title("Humidity")
ax2.set_xlabel('Time')
ax2.set_ylabel("Percentage RH")
ax2.grid(which='both')
plt.gcf().autofmt_xdate() # slant labels
dateFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
plt.gca().xaxis.set_major_formatter(dateFmt)
for i in range(len(stationFilenames)) :
header, tStamp, temp, humidity = importCsv(stationFilenames[i])
t = [datetime.datetime.fromtimestamp(ts) for ts in tStamp]
if True :
if "temperature_C" in header :
for k in range(len(temp)) :
temp[k] = round(temp[k] * 9.0 / 5.0 + 32.0, 1)
else :
if "temperature_F" in header :
for k in range(len(temp)) :
temp[k] = round((temp[k] - 32.0) * 5.0 / 9.0, 1)
ax1.plot(t, temp, label=stationNames[i])
ax2.plot(t, humidity, label=stationNames[i])
ax1.legend(loc='upper right', shadow=True)
ax2.legend(loc='upper right', shadow=True)
plt.show(block=False)
# Pause to close plots
input("Press [enter] key to close plots...")
print("Done...")