-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatToPlot.py
More file actions
77 lines (64 loc) · 1.86 KB
/
datToPlot.py
File metadata and controls
77 lines (64 loc) · 1.86 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
#!/usr/bin/env python
# ==================================================================
# The program reads data file(s) and generates corresponding plots.
# ==================================================================
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as ml
from userInput import *
def getMultiple(path, numSnapshots):
"""searching for a sequence of snapshots"""
filename = path.split('/')[-1]
dirpath = path.replace(filename, '')
time = filename.split('-')[-1]
filelist = [path]
while True:
try:
index = int(time.replace('s.dat', ''))
except ValueError:
print "[ERROR]: not a data file from multiple snapshots."
sys.exit()
new_time = str(index+numSnapshots) + 's.dat'
filename = filename.replace(time, new_time)
target = dirpath + filename
if os.path.isfile(target):
filelist.append(target)
time = new_time
else:
break
return filelist
# end of getMultiple
def datToMatrix(filename, alongStrike, downDip):
try:
x, y, data = np.loadtxt(filename, unpack = True)
except IOError:
print "[ERROR]: unable to laod file " + filename + '.'
data = np.reshape(data, (downDip, alongStrike), order='F')
data = data.transpose()
return data
def plot(data, cmap):
im = plt.imshow(data, cmap = cmap)
plt.axis('off')
plt.gca().invert_yaxis()
plt.colorbar(im)
plt.xlabel('X')
plt.ylabel('Y')
# plt.suptitle('t = ' + (str)(index), fontsize=20)
plt.axis('scaled')
plt.show()
# end of plot
if __name__ == "__main__":
if len(sys.argv) > 1:
argument = tuple(sys.argv[1:])
i = DatInput(*argument)
else:
i = DatInput()
if i.snapshots == 's':
data = datToMatrix(i.path, i.alongStrike, i.downDip)
plot(data, i.colorMap)
elif i.snapshots == 'm':
filelist = getMultiple(i.path, i.numSnapshots)
for f in filelist:
data = datToMatrix(f, i.alongStrike, i.downDip)
plot(data, i.colorMap)