-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotBasinMaster.py
134 lines (97 loc) · 3.49 KB
/
plotBasinMaster.py
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
#!/usr/bin/env python
"""
Copyright(C) 2021, BrucesHobbies
All Rights Reserved
AUTHOR: BruceHobbies
DATE: 02/04/2021
REVISION HISTORY
DATE AUTHOR CHANGES
yyyy/mm/dd --------------- -------------------------------------
2021/02/10 BrucesHobbies Updated default filenames
OVERVIEW:
This program plots CSV files that were generated by sumpMaster.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
# fig.savefig(filename, bbox_inches='tight') # save the figure to file
filenames = ["basinMaster_WaterDepth.csv"]
#
# Read in a comma seperated variable file. Assumes a header row exists.
# Time series with time in seconds in first column.
# Ignore text string with date/time from second column
# data is columns [2:]
#
def importCsv(filename) :
print("Reading " + filename)
with open(filename, 'r') as csvfile :
csvData = list(csv.reader(csvfile))
hdr = csvData[0]
print(hdr)
tStamp = []
for row in csvData[1:] :
tStamp.append(float(row[0]))
data = {name : [] for name in hdr[2:]}
print(data)
for row in csvData[1:] :
for idx in range(2,len(hdr)) :
n = float(row[idx])
if n == -99 :
n = np.nan
data[hdr[idx]].append(n)
return hdr[2:], tStamp, data
#
# Plot single or multiple variables {"key":[]} on common subplot
#
def plotMultiVar(tStamp, data, title) :
t = [datetime.datetime.fromtimestamp(ts) for ts in tStamp]
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
for item in data :
# print(item)
ax1.plot(t, data[item], label=item)
# ax1.plot(t, data[item], marker='d', label=item)
ax1.set_title(title)
#ax1.set_xlabel('Time')
ax1.set_ylabel('Depth')
if len(data) > 1 :
ax1.legend(loc='upper right', shadow=True)
else :
ax1.set_ylabel(item)
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__" :
# Sump Well Water Depth
hdr, tStamp, data = importCsv(filenames)
plotMultiVar(tStamp, data, filenames)
plt.show() # Blocks, user must close plot window
# Pause to close plots
# input("Press [enter] key to close plots...")
# print("Done...")