-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotNarrowband.py
175 lines (147 loc) · 6.92 KB
/
PlotNarrowband.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
# -*- coding: utf-8 -*-
'''
Author: Ahmed Ammar, ahmed.ammar@fst.utm.tn
Purpose: - - -
Inputs: - - -
Outputs: - - -
Date Created: Thu Apr 12 20:12:48 2018
Date Modified: M D, Y
Date Released: M D, Y
Versions:
V0.01: ---
'''
from PyQt5.QtCore import pyqtSlot, QTime
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
from Ui_PlotNarrowband import Ui_MainWindow
from LoadData import Load_DAQ_Data
from DAQ_DataPhase import FixDAQ_DataPhase
import numpy as np
import json
class PlotNarrowband(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setupUi(self)
self.time_interval()
self.Plot_Data()
def Plot_Data(self):
"""
Plot Amplitude and Phase from AWESOME DATA
"""
with open("data_info.json", 'r') as f:
datastore=json.load(f)
pathnames= datastore["pathnames"]
filenames= datastore["filenames"]
TitlePlot= datastore["TitlePlot"]
max_nsp=len(pathnames)
nsp=0 # number of subplots
plt=self.mplwidget.canvas
plt.ax.clear()
plt.ax.axis('off')
for pathname, filename,title in zip(pathnames,filenames,TitlePlot):
nsp+=1
FixData=FixDAQ_DataPhase(pathname, filename)
time, Data, StationInfo =Load_DAQ_Data(FixData.path, FixData.filename)
fs=StationInfo['fs']
if StationInfo['data_type']==1.0:
Data_amp= Data
##Averaging
AveragingLengthAmp = 10
data_amp_averaged = np.zeros((len(Data_amp) - AveragingLengthAmp + 1,1),float)
for jj in range(0, (len(Data_amp)-AveragingLengthAmp+1)):
data_amp_averaged[jj] = np.mean(Data_amp[jj:(jj+AveragingLengthAmp-1)])
## Figure
ax1= plt.fig.add_subplot(max_nsp, 1, nsp)
if self.view_raw.isChecked() and self.view_average.isChecked() == True:
ax1.plot(time[:len(data_amp_averaged)], 20*np.log10(data_amp_averaged), lw=1, color='r')
ax1.plot(time, 20*np.log10(Data_amp), ls='-', lw=.5, color='b', alpha=.5)
elif self.view_raw.isChecked() == True and self.view_average.isChecked() == False:
ax1.clear()
ax1.plot(time, 20*np.log10(Data_amp), ls='-', lw=.5, color='b', alpha=.5)
elif self.view_raw.isChecked() == False and self.view_average.isChecked() == True:
ax1.clear()
ax1.plot(time[:len(data_amp_averaged)], 20*np.log10(data_amp_averaged), lw=1, color='r')
else:
ax1.clear()
ax1.set_title(title, fontsize=8, weight = 'bold')
ax1.set_xlabel("Time (UT)", fontsize=8, weight = 'bold')
ax1.set_ylabel("Amplitude (dB)", fontsize=8, weight = 'bold')
ax1.set_xlim(self.start, self.end)
else:
Data_phi= Data
##phase unwrapped
PhaseFixLength90 = 3000
PhaseFixLength180 =3000
averaging_length=fs*PhaseFixLength180
# print(averaging_length)
data_phase_fixed180 = FixData.fix_phasedata180(Data_phi, averaging_length)
# print(data_phase_fixed180)
data_phase_fixed90 = FixData.fix_phasedata90(data_phase_fixed180, averaging_length)
data_phase_unwrapped = np.zeros((len(data_phase_fixed90),1),float)
data_phase_unwrapped[0] = data_phase_fixed90[0]
offset = 0
for jj in range(1, (len(data_phase_fixed90))):
if data_phase_fixed90[jj]-data_phase_fixed90[jj-1] > 180:
offset = offset + 360
elif data_phase_fixed90[jj]-data_phase_fixed90[jj-1] < -180:
offset = offset - 360
data_phase_unwrapped[jj] = data_phase_fixed90[jj] - offset
##Averaging
AveragingLengthPhase = 10
data_phase_averaged = np.zeros((len(data_phase_unwrapped) - AveragingLengthPhase + 1,1),float)
for jj in range(0, (len(data_phase_unwrapped) - AveragingLengthPhase + 1)):
data_phase_averaged[jj] = np.mean(data_phase_unwrapped[jj:(jj+AveragingLengthPhase-1)])
## Figure
ax2= plt.fig.add_subplot(max_nsp, 1, nsp, sharex=ax1)
if self.view_raw.isChecked() and self.view_average.isChecked() == True:
ax2.plot(time[:len(data_phase_averaged)], data_phase_averaged, lw=1, color='r')
ax2.plot(time, data_phase_unwrapped, lw=.5, color='b', alpha=.5)
elif self.view_raw.isChecked() == True and self.view_average.isChecked() == False:
ax2.clear()
ax2.plot(time, data_phase_unwrapped, lw=.5, color='b', alpha=.5)
elif self.view_raw.isChecked() == False and self.view_average.isChecked() == True:
ax2.clear()
ax2.plot(time[:len(data_phase_averaged)], data_phase_averaged, lw=1, color='r')
else:
ax2.clear()
# ax2.plot(time[:len(data_phase_averaged)], data_phase_averaged, lw=1, color='r')
# ax2.plot(time, data_phase_unwrapped, lw=.5, color='b', alpha=.5)
ax2.set_title(title, fontsize=8, weight = 'bold')
ax2.set_xlabel("Time (UT)", fontsize=8, weight = 'bold')
ax2.set_ylabel("Phase (deg)", fontsize=8, weight = 'bold')
ax2.set_xlim(self.start,self.end)
plt.fig.tight_layout()
plt.draw()
@pyqtSlot()
def on_view_raw_clicked(self):
self.Plot_Data()
@pyqtSlot()
def on_view_average_clicked(self):
self.Plot_Data()
@pyqtSlot()
def on_replot_clicked(self):
self.Plot_Data()
def time_interval(self):
ts = self.startTime.time().toString()
(h, m, s) = ts.split(':')
self.start = int(h) + int(m) / 60 + int(s)/3600
te = self.endTime.time().toString()
(h, m, s) = te.split(':')
self.end = int(h) + int(m) / 60 + int(s)/3600
@pyqtSlot(QTime)
def on_startTime_timeChanged(self, QTime):
'''
Start time
'''
self.time_interval()
@pyqtSlot(QTime)
def on_endTime_timeChanged(self, QTime):
'''
End Time
'''
self.time_interval()
if __name__ == "__main__":
app = QApplication(sys.argv)
MyApplication = PlotNarrowband()
MyApplication.show()
sys.exit(app.exec_())