-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotTime.py
105 lines (89 loc) · 2.52 KB
/
plotTime.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
'''Plot output vs time'''
import glob
import pdb
from srcOutput import readOutput
from matplotlib import pyplot as pp
import numpy as np
import datetime
import matplotlib.dates as mdates
import os
datadir = input("Enter data directory: ")
newfiles = glob.glob(datadir+"/*dat")
filetypes = set([])
for file in newfiles:
pos = file.rfind("/")+1
filetypes.add(file[pos:pos+5])
filetypes = list(filetypes)
filetypes.sort()
for i in range(len(filetypes)):
print(i,filetypes[i])
if len(filetypes) > 1:
itype = int(input("Enter which type of file to plot: "))
newfiles = glob.glob(datadir+"/"+filetypes[itype]+"*.dat")
files = sorted( newfiles, key = lambda file: os.path.getctime(file))
nfiles = len(files)
if nfiles < 1:
print("No files found!")
exit(1)
f = open(files[0],'r')
altitude = []
i=0
started = False
for line in f:
if started:
t = line.split()
altitude.append(float(t[0]))
print('{}: {}'.format(i,altitude[i]))
i+=1
if line[0:4] == "#Alt":
vars = line.strip("#").strip("\n").split("\t")
started = True
iAlt = int(input("Enter which alt to plot: "))
f.close()
for i in range(1,len(vars)):
#skip altitude as an option
print("{}: {}".format(i,vars[i]))
iVar = int(input("Enter which variable to plot: (-1 for all)"))
time = []
data = []
dPlanet = []
for file in files:
temp,header = readOutput.readOutputFile(file)
dPlanet.append(float(header[-1].split("=")[1]))
if iVar < 0:
data.append(temp[iAlt,:])
else:
data.append(temp[iAlt,iVar])
pos = file.find(".dat") - 12
days = int(file[pos:pos+5])
hours = int(file[pos+6:pos+8])
mins = int(file[pos+8:pos+10])
secs = int(file[pos+10:pos+12])
time.append(datetime.timedelta(days=days,hours=hours,\
minutes=mins,seconds=secs))
data = np.array(data)
ymin = float(input("Enter minimum to plot (0 for auto):"))
ymax = float(input("Enter maximum to plot (0 for auto):"))
time = [t.days*24+t.seconds/3600. for t in time]
plotDistance = True
fig=pp.figure()
ax = fig.add_subplot(221)
if iVar < 0:
for i in range(1,len(vars)):
pp.plot(time,data[:,i],label=vars[i])
pp.ylabel(vars[1][0])
else:
pp.plot(time,data)
pp.ylabel(vars[iVar])
if ymin != 0 and ymax != 0:
pp.ylim([ymin,ymax])
# pp.ylim([2.17e12,2.18e12])
if plotDistance:
ax = fig.add_subplot(223)
pp.plot(time,dPlanet)
pp.ylabel("Planet Distance (AU)")
pp.xlabel("Time (hours)")
else:
pp.tight_layout()
pp.xlabel("Time (hours)")
pp.savefig(datadir+'/plot.png')