|
9 | 9 | REVISION HISTORY
|
10 | 10 | DATE AUTHOR CHANGES
|
11 | 11 | yyyy/mm/dd --------------- -------------------------------------
|
| 12 | + 2021/03/01 BrucesHobbies Revised default log file names |
| 13 | + 2021/03/05 BrucesHobbies Updated for pubScribe |
12 | 14 |
|
13 | 15 |
|
14 | 16 | OVERVIEW:
|
|
53 | 55 | #
|
54 | 56 | # Read in a comma seperated variable file. Assumes a header row exists.
|
55 | 57 | # Time series with time in seconds in first column.
|
| 58 | +# Ignore text string with date/time from second column |
| 59 | +# data is columns [2:] |
56 | 60 | #
|
57 | 61 | def importCsv(filename) :
|
58 | 62 | print("Reading " + filename)
|
59 | 63 |
|
60 | 64 | with open(filename, 'r') as csvfile :
|
61 |
| - data = list(csv.reader(csvfile)) |
| 65 | + csvData = list(csv.reader(csvfile)) |
62 | 66 |
|
63 |
| - header = data[0] |
64 |
| - print(header) |
| 67 | + hdr = csvData[0] |
| 68 | + print(hdr) |
65 | 69 |
|
66 |
| - a = np.array(data[1:], dtype=np.float) |
| 70 | + tStamp = [] |
| 71 | + for row in csvData[1:] : |
| 72 | + tStamp.append(float(row[0])) |
67 | 73 |
|
68 |
| - print("Elements: ", a.size) |
69 |
| - print("Rows : ", len(a[:,0])) |
70 |
| - print("Cols : ", len(a[0,:])) |
| 74 | + data = {name : [] for name in hdr[2:]} |
| 75 | + # print(data) |
| 76 | + |
| 77 | + for row in csvData[1:] : |
| 78 | + for idx in range(2,len(hdr)) : |
| 79 | + n = float(row[idx]) |
| 80 | + if n == -99 : |
| 81 | + n = np.nan |
| 82 | + data[hdr[idx]].append(n) |
| 83 | + |
| 84 | + return hdr[2:], tStamp, data |
71 | 85 |
|
72 |
| - return header, a |
73 | 86 |
|
74 | 87 | #
|
75 |
| -# Plot Short-Term and Long-Term radon levels |
76 |
| -# thresholds(y_value,"label") |
| 88 | +# Plot single or multiple variables {"key":[]} on common subplot |
77 | 89 | #
|
78 |
| -def plotRadon(thresholds) : |
| 90 | +def plotMultiVar(tStamp, data, title) : |
| 91 | + |
| 92 | + t = [datetime.datetime.fromtimestamp(ts) for ts in tStamp] |
| 93 | + |
79 | 94 | fig = plt.figure()
|
80 | 95 | ax1 = fig.add_subplot(1, 1, 1)
|
81 | 96 |
|
82 |
| - ax1.plot(t, a[:,1], 'b', label='ST') |
83 |
| - ax1.plot(t, a[:,2], 'r', label='LT') |
84 |
| - # ax1.plot(t, a[:,1], 'b', marker='d', label='ST') |
85 |
| - # ax1.plot(t, a[:,2], 'r', marker='d', label='LT') |
| 97 | + for item in data : |
| 98 | + # print(item) |
| 99 | + ax1.plot(t, data[item], label=item) |
| 100 | + # ax1.plot(t, data[item], marker='d', label=item) |
86 | 101 |
|
87 |
| - for item in thresholds : |
88 |
| - ax1.plot([t[0], t[len(t)-1]], [item[0], item[0]], item[1]) |
| 102 | + ax1.set_title(title) |
89 | 103 |
|
90 |
| - ax1.set_title("Radon") |
91 |
| - ax1.set_xlabel('Time') |
92 |
| - ax1.set_ylabel(header[1][9:]) |
93 |
| - ax1.legend(loc='upper right', shadow=True) |
| 104 | + if len(data) > 1 : |
| 105 | + ax1.legend(loc='upper right', shadow=True) |
| 106 | + else : |
| 107 | + ax1.set_ylabel(item) |
94 | 108 |
|
95 | 109 | ax1.grid(which='both')
|
| 110 | + |
96 | 111 | plt.gcf().autofmt_xdate() # slant labels
|
97 | 112 | dateFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
|
98 | 113 | plt.gca().xaxis.set_major_formatter(dateFmt)
|
99 | 114 |
|
100 |
| - plt.show(block=False) |
101 | 115 |
|
102 | 116 | #
|
103 |
| -# Plot VOC, CO2, Temperature, Relative, Humidity, and air pressure |
| 117 | +# Plot single variable {"item":[]} |
104 | 118 | #
|
105 |
| -def plotSingle(var, ylabel, title) : |
| 119 | +def plotSingleVar(tStamp, data, title, item) : |
| 120 | + |
| 121 | + t = [datetime.datetime.fromtimestamp(ts) for ts in tStamp] |
| 122 | + |
106 | 123 | fig = plt.figure()
|
107 | 124 | ax1 = fig.add_subplot(1, 1, 1)
|
108 | 125 |
|
109 |
| - ax1.plot(t, var) |
110 |
| - # ax1.plot(t, var, marker='d') |
| 126 | + ax1.plot(t, data[item], label=item) |
| 127 | + # ax1.plot(t, data[item], marker='d', label=item) |
111 | 128 |
|
112 | 129 | ax1.set_title(title)
|
113 |
| - ax1.set_xlabel('Time') |
114 |
| - ax1.set_ylabel(ylabel) |
115 |
| - |
| 130 | + ax1.set_ylabel(item) |
| 131 | + |
116 | 132 | ax1.grid(which='both')
|
| 133 | + |
117 | 134 | plt.gcf().autofmt_xdate() # slant labels
|
118 | 135 | dateFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
|
119 | 136 | plt.gca().xaxis.set_major_formatter(dateFmt)
|
120 | 137 |
|
121 |
| - plt.show(block=False) |
122 | 138 |
|
123 | 139 | #
|
124 | 140 | # Plot two files
|
125 | 141 | #
|
126 | 142 | if __name__ == "__main__" :
|
127 | 143 |
|
128 |
| - # --- Radon Short-term and Long-term --- |
129 |
| - # (time in column 0, data in columns 1 - 2) |
130 |
| - # filename = "radonLogFile.csv" |
131 |
| - filename = "waveLogFile.csv" |
132 |
| - header, a = importCsv(filename) |
133 |
| - |
134 |
| - tstamp = [] |
135 |
| - for item in a[:,0] : |
136 |
| - tstamp.append(item) |
137 |
| - t = [datetime.datetime.fromtimestamp(ts) for ts in tstamp] |
138 |
| - |
139 |
| - plotRadon([(1.3, 'g--'),(2.7, 'y--'),(4.0, 'r--')]) |
140 |
| - |
141 |
| - # Plot remaining data from WavePlus (columns 4 - 8) |
142 |
| - for col in range(3, len(header)-1) : |
143 |
| - plotSingle(a[:,col],header[col],header[col]) |
| 144 | + # --- WavePlus data --- |
| 145 | + # (time in column 0, data in columns 2:) |
| 146 | + filename = "RadonMaster_WavePlus.csv" |
| 147 | + header, tStamp, data = importCsv(filename) |
144 | 148 |
|
| 149 | + for item in data : |
| 150 | + plotSingleVar(tStamp, data, filename[:-4], item) |
145 | 151 |
|
146 | 152 | # --- Mitigation fan pressure ---
|
147 |
| - filename = "radonMaster.csv" |
148 |
| - header, a = importCsv(filename) |
149 |
| - |
150 |
| - tstamp = [] |
151 |
| - for item in a[:,0] : |
152 |
| - tstamp.append(item) |
153 |
| - t = [datetime.datetime.fromtimestamp(ts) for ts in tstamp] |
| 153 | + filename = "RadonMaster_PresSensor.csv" |
| 154 | + header, tStamp, data = importCsv(filename) |
154 | 155 |
|
155 |
| - plotSingle(a[:,1],'Inches W.C.','Mitigation Fan Vacuum') |
| 156 | + plotMultiVar(tStamp, data, 'Mitigation Fan Vacuum') |
156 | 157 |
|
157 | 158 | # Pause to close plots
|
| 159 | + plt.show(False) # Blocks, user must close plot window |
| 160 | + print("") |
158 | 161 | input("Press [enter] key to close plots...")
|
159 | 162 | print("Done...")
|
0 commit comments