-
Notifications
You must be signed in to change notification settings - Fork 0
/
mahalidiff.py
184 lines (148 loc) · 6.23 KB
/
mahalidiff.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
import os, glob, datetime,sys,getopt
from GeoData.GeoData import GeoData
import matplotlib.pyplot as plt
import numpy as np
from GeoData.utilityfuncs import readIonofiles, readAllskyFITS,readSRI_h5
from PlottingClass import str2posix
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter,MinuteLocator, HourLocator,MinuteLocator
def PlotTECdiff(gpsloc,timelist,satnum,sublist,pname='mahdiff.png',tectype = 'TEC'):
""" This will plot the differences between two gps sites. The code filters
first by satilite number. The TEC is interpolated over the time period
and then subtracted.
Inputs
gpsloc - The directory holding the ionofiles.
timelist - A list of strings holding the time the data will be interpolated over
[date1,time1,date2,time1]
satnum - The satilite number as an int or float.
sublist - This is the name of the recievers that will have their values compared
pname - Name of the plot
tectype - Either vTEC or TEC, determines which type will be compared."""
# Figure out location or receivers
flist1 = glob.glob(os.path.join(gpsloc,'*.iono'))
fnames = np.array([os.path.splitext(os.path.split(i)[1])[0].lower().split('-')[0] for i in flist1])
[f0,f1] = [np.argwhere(i.lower()==fnames)[0][0] for i in sublist]
# read in the receivers and filter out by sat number
mah0str = flist1[f0]
mah1str = flist1[f1]
mah0 = GeoData(readIonofiles,(mah0str,))
mah1 = GeoData(readIonofiles,(mah1str,))
sat230 = mah0.data['satnum']==satnum
sat231 = mah1.data['satnum']==satnum
timemah0 = mah0.times[sat230]
timemah1 = mah1.times[sat231]
TEC0 = mah0.data[tectype][sat230]
TEC1 = mah1.data[tectype][sat231]
# Interpolation
xends = str2posix(timelist)
xint = np.linspace(xends[0],xends[1],180)
mah0int = np.interp(xint,timemah0[:,0],TEC0)
mah1int = np.interp(xint,timemah1[:,0],TEC1)
mahdif = mah0int-mah1int
#plotting
dts = map(datetime.datetime.utcfromtimestamp, xint)
fig, axmat = plt.subplots(1,1,dpi=300)
lines = axmat.plot(dts,mahdif)
axmat.set_title(sublist[0]+' - '+sublist[1] +' '+ timelist[0])
dtfmt = DateFormatter('%H:%M:%S')
axmat.xaxis.set_major_locator(HourLocator())
axmat.xaxis.set_major_formatter(dtfmt)
axmat.xaxis.set_minor_locator(MinuteLocator(interval=15))
axmat.set_xlabel('Time UT')
axmat.set_ylabel(tectype)
plt.savefig(pname)
def plottecvstime(TECGD,satnum,fig,ax):
""" This will plot a single set of TEC data.
Inputs
TECGD - A GeoData instance that has been filtered by time to the desired period.
satnum - The number of the satilite that will be plotted.
fig - The figure handle.
ax - the axis handle.
outputs
lines - The handle for the line plot
"""
keep = TECGD.data['satnum']==satnum
times = TECGD.times[:,0][keep]
vtec = TECGD.data['vTEC'][keep]
dts = map(datetime.datetime.utcfromtimestamp, times)
dtfmt = DateFormatter('%H:%M:%S')
lines = ax.plot(dts,vtec)
ax.xaxis.set_major_locator(MinuteLocator(byminute = [0,15,30,45]))#interval=15))
ax.xaxis.set_major_formatter(dtfmt)
ax.set_ylabel('TEC')
ax.set_ylim([-10.,30.])
ax.set_title('Data From Sat {0:d}'.format(satnum))
return lines
def plotalltecvstime(TEClist1,flist1,satnum,pfname='TECMaps'):
""" This will plot a single set of TEC data.
Inputs
TEClist1 - A list of GeoData objects that have been filtered by time to the desired period.
flist1 - The name of the files that the goedata objects are from
satnum - The number of the satilite that will be plotted.
pfname - The name of the plot."""
flist=[]
TEClist = []
for i,j in enumerate(TEClist1):
if np.any(j.data['satnum']==satnum):
TEClist.append(j)
flist.append(flist1[i])
col = 2.
numr = np.ceil(len(flist)/col)
dxs = 4.0
dys = 2.
fig, axmat = plt.subplots(int(numr),int(col),dpi=300,sharex=True,sharey=True,figsize=(dxs*col,dys*(numr+1)))
plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
axvec= axmat.flatten()
dnames = [os.path.splitext(os.path.split(i)[-1])[0] for i in flist]
for i,iGD in enumerate(TEClist):
lines = plottecvstime(iGD,satnum,fig,axvec[i])
axvec[i].set_title(dnames[i])
plt.suptitle('Data from Sat: {0:d}'.format(satnum))
plt.subplots_adjust(top=0.95)
plt.savefig(pfname)
if __name__== '__main__':
argv = sys.argv[1:]
outstr = '''
Usage: mahlidiff.py -i <ionofile dir>, -s <sat number>, -b <begining time>, -e <endtime>, -p <plotname> -m <first receiver> -n <second receiver>
or
python plotdata.py -h
This script will run comparethe TEC in two mahali recievers
Optional arguments
-i The directory that holds all of the TEC data in ionofile formats.
-s Satlilite number
-b begining time.
-e endtime
-p plotdir
-m first receiver
-n seocnd receiver
'''
try:
opts, args = getopt.gnu_getopt(argv,"hs:i:b:e:p:m:n:")
except getopt.GetoptError:
print(outstr)
sys.exit(2)
gpsloc=''
ASloc=''
ISRloc=''
inifile=None
sublist = ['','']
for opt, arg in opts:
if opt == '-h':
print(outstr)
sys.exit()
elif opt in ("-i", "--ifile"):
gpsloc = os.path.expanduser(arg)
elif opt in ("-s", "--sat"):
satnum=int(float(arg))
elif opt in ("-b", "--btime"):
btime=os.path.expanduser(arg)
elif opt in ("-e", "--etime"):
endtime = os.path.expanduser(arg)
elif opt in ('-p','--pdir'):
plotdir=os.path.expanduser(arg)
elif opt in ('-m','--minu'):
sublist[0] = arg
elif opt in ('-n','--ninu'):
sublist[1] = arg
timelist = btime.split(' ') +endtime.split(' ')
PlotTECdiff(gpsloc,timelist,satnum,sublist)