##// END OF EJS Templates
merge with BLTR and Madrigal modules
Juan C. Espinoza -
r1032:c711a14430f7 merge
parent child
Show More
@@ -0,0 +1,404
1 '''
2
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
6 import sys
7 import numpy
8 import copy
9 import datetime
10 from __builtin__ import None
11
12 SPEED_OF_LIGHT = 299792458
13 SPEED_OF_LIGHT = 3e8
14
15 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
16 ('FileMgcNumber','<u4'), #0x23020100
17 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
18 ('RadarUnitId','<u4'),
19 ('SiteName','<s32'), #Null terminated
20 ])
21
22 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
23 ('RecMgcNumber','<u4'), #0x23030001
24 ('RecCounter','<u4'), #Record counter(0,1, ...)
25 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
26 ('Off2StartData','<u4'), #Offset to start of data from start of this record
27 ('EpTimeStamp','<i4'), #Epoch time stamp of start of acquisition (seconds)
28 ('msCompTimeStamp','<u4'), #Millisecond component of time stamp (0,...,999)
29 ('ExpTagName','<s32'), #Experiment tag name (null terminated)
30 ('ExpComment','<s32'), #Experiment comment (null terminated)
31 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
32 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
33 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
34 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
35 ('ReceiveFrec','<u4'), #Receive frequency
36 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
37 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
38 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
39 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
40 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
41 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
42 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
43 ('SampResolution','<u4'), #Sampling resolution (meters)
44 ('nRangeGatesSamp','<u4'), #Number of range gates sampled
45 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
46 ('PRFhz','<u4'), #PRF (Hz)
47 ('Integrations','<u4'), #Integrations
48 ('nDataPointsTrsf','<u4'), #Number of data points transformed
49 ('nReceiveBeams','<u4'), #Number of receive beams stored in file (1 or N)
50 ('nSpectAverages','<u4'), #Number of spectral averages
51 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
52 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
53 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
54 ('AntennaCoord','<f24'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
55 ('RecPhaseCalibr','<f12'), #Receiver phase calibration (degrees) - N values
56 ('RecAmpCalibr','<f12'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
57 ('ReceiverGaindB','<u12'), #Receiver gains in dB - N values
58 ])
59
60
61 class Header(object):
62
63 def __init__(self):
64 raise NotImplementedError
65
66
67 def read(self):
68
69 raise NotImplementedError
70
71 def write(self):
72
73 raise NotImplementedError
74
75 def printInfo(self):
76
77 message = "#"*50 + "\n"
78 message += self.__class__.__name__.upper() + "\n"
79 message += "#"*50 + "\n"
80
81 keyList = self.__dict__.keys()
82 keyList.sort()
83
84 for key in keyList:
85 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
86
87 if "size" not in keyList:
88 attr = getattr(self, "size")
89
90 if attr:
91 message += "%s = %s" %("size", attr) + "\n"
92
93 print message
94
95 class FileHeader(Header):
96
97 FileMgcNumber= None
98 nFDTdataRecors=None #No Of FDT data records in this file (0 or more)
99 RadarUnitId= None
100 SiteName= None
101
102 #__LOCALTIME = None
103
104 def __init__(self, useLocalTime=True):
105
106 self.FileMgcNumber= 0 #0x23020100
107 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
108 self.RadarUnitId= 0
109 self.SiteName= ""
110 self.size = 48
111
112 #self.useLocalTime = useLocalTime
113
114 def read(self, fp):
115
116 try:
117 header = numpy.fromfile(fp, FILE_STRUCTURE,1)
118 ''' numpy.fromfile(file, dtype, count, sep='')
119 file : file or str
120 Open file object or filename.
121
122 dtype : data-type
123 Data type of the returned array. For binary files, it is used to determine
124 the size and byte-order of the items in the file.
125
126 count : int
127 Number of items to read. -1 means all items (i.e., the complete file).
128
129 sep : str
130 Separator between items if file is a text file. Empty (“”) separator means
131 the file should be treated as binary. Spaces (” ”) in the separator match zero
132 or more whitespace characters. A separator consisting only of spaces must match
133 at least one whitespace.
134
135 '''
136
137 except Exception, e:
138 print "FileHeader: "
139 print eBasicHeader
140 return 0
141
142 self.FileMgcNumber= byte(header['FileMgcNumber'][0])
143 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
144 self.RadarUnitId= int(header['RadarUnitId'][0])
145 self.SiteName= char(header['SiteName'][0])
146
147
148 if self.size <48:
149 return 0
150
151 return 1
152
153 def write(self, fp):
154
155 headerTuple = (self.FileMgcNumber,
156 self.nFDTdataRecors,
157 self.RadarUnitId,
158 self.SiteName,
159 self.size)
160
161
162 header = numpy.array(headerTuple, FILE_STRUCTURE)
163 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
164 header.tofile(fp)
165 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
166
167 fid : file or str
168 An open file object, or a string containing a filename.
169
170 sep : str
171 Separator between array items for text output. If “” (empty), a binary file is written,
172 equivalent to file.write(a.tobytes()).
173
174 format : str
175 Format string for text file output. Each entry in the array is formatted to text by
176 first converting it to the closest Python type, and then using “format” % item.
177
178 '''
179
180 return 1
181
182
183 class RecordHeader(Header):
184
185 RecMgcNumber=None #0x23030001
186 RecCounter= None
187 Off2StartNxtRec= None
188 EpTimeStamp= None
189 msCompTimeStamp= None
190 ExpTagName= None
191 ExpComment=None
192 SiteLatDegrees=None
193 SiteLongDegrees= None
194 RTCgpsStatus= None
195 TransmitFrec= None
196 ReceiveFrec= None
197 FirstOsciFrec= None
198 Polarisation= None
199 ReceiverFiltSett= None
200 nModesInUse= None
201 DualModeIndex= None
202 DualModeRange= None
203 nDigChannels= None
204 SampResolution= None
205 nRangeGatesSamp= None
206 StartRangeSamp= None
207 PRFhz= None
208 Integrations= None
209 nDataPointsTrsf= None
210 nReceiveBeams= None
211 nSpectAverages= None
212 FFTwindowingInd= None
213 BeamAngleAzim= None
214 BeamAngleZen= None
215 AntennaCoord= None
216 RecPhaseCalibr= None
217 RecAmpCalibr= None
218 ReceiverGaindB= None
219
220 '''size = None
221 nSamples = None
222 nProfiles = None
223 nChannels = None
224 adcResolution = None
225 pciDioBusWidth = None'''
226
227 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 0,
228 EpTimeStamp= 0, msCompTimeStamp= 0, ExpTagName= None,
229 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
230 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
231 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
232 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
233 nDigChannels= 0, SampResolution= 0, nRangeGatesSamp= 0,
234 StartRangeSamp= 0, PRFhz= 0, Integrations= 0,
235 nDataPointsTrsf= 0, nReceiveBeams= 0, nSpectAverages= 0,
236 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
237 AntennaCoord= 0, RecPhaseCalibr= 0, RecAmpCalibr= 0,
238 ReceiverGaindB= 0):
239
240 self.RecMgcNumber = RecMgcNumber #0x23030001
241 self.RecCounter = RecCounter
242 self.Off2StartNxtRec = Off2StartNxtRec
243 self.EpTimeStamp = EpTimeStamp
244 self.msCompTimeStamp = msCompTimeStamp
245 self.ExpTagName = ExpTagName
246 self.ExpComment = ExpComment
247 self.SiteLatDegrees = SiteLatDegrees
248 self.SiteLongDegrees = SiteLongDegrees
249 self.RTCgpsStatus = RTCgpsStatus
250 self.TransmitFrec = TransmitFrec
251 self.ReceiveFrec = ReceiveFrec
252 self.FirstOsciFrec = FirstOsciFrec
253 self.Polarisation = Polarisation
254 self.ReceiverFiltSett = ReceiverFiltSett
255 self.nModesInUse = nModesInUse
256 self.DualModeIndex = DualModeIndex
257 self.DualModeRange = DualModeRange
258 self.nDigChannels = nDigChannels
259 self.SampResolution = SampResolution
260 self.nRangeGatesSamp = nRangeGatesSamp
261 self.StartRangeSamp = StartRangeSamp
262 self.PRFhz = PRFhz
263 self.Integrations = Integrations
264 self.nDataPointsTrsf = nDataPointsTrsf
265 self.nReceiveBeams = nReceiveBeams
266 self.nSpectAverages = nSpectAverages
267 self.FFTwindowingInd = FFTwindowingInd
268 self.BeamAngleAzim = BeamAngleAzim
269 self.BeamAngleZen = BeamAngleZen
270 self.AntennaCoord = AntennaCoord
271 self.RecPhaseCalibr = RecPhaseCalibr
272 self.RecAmpCalibr = RecAmpCalibr
273 self.ReceiverGaindB = ReceiverGaindB
274
275
276 def read(self, fp):
277
278 startFp = fp.tell() #The method tell() returns the current position of the file read/write pointer within the file.
279
280 try:
281 header = numpy.fromfile(fp,RECORD_STRUCTURE,1)
282 except Exception, e:
283 print "System Header: " + e
284 return 0
285
286 self.RecMgcNumber = header['RecMgcNumber'][0] #0x23030001
287 self.RecCounter = header['RecCounter'][0]
288 self.Off2StartNxtRec = header['Off2StartNxtRec'][0]
289 self.EpTimeStamp = header['EpTimeStamp'][0]
290 self.msCompTimeStamp = header['msCompTimeStamp'][0]
291 self.ExpTagName = header['ExpTagName'][0]
292 self.ExpComment = header['ExpComment'][0]
293 self.SiteLatDegrees = header['SiteLatDegrees'][0]
294 self.SiteLongDegrees = header['SiteLongDegrees'][0]
295 self.RTCgpsStatus = header['RTCgpsStatus'][0]
296 self.TransmitFrec = header['TransmitFrec'][0]
297 self.ReceiveFrec = header['ReceiveFrec'][0]
298 self.FirstOsciFrec = header['FirstOsciFrec'][0]
299 self.Polarisation = header['Polarisation'][0]
300 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
301 self.nModesInUse = header['nModesInUse'][0]
302 self.DualModeIndex = header['DualModeIndex'][0]
303 self.DualModeRange = header['DualModeRange'][0]
304 self.nDigChannels = header['nDigChannels'][0]
305 self.SampResolution = header['SampResolution'][0]
306 self.nRangeGatesSamp = header['nRangeGatesSamp'][0]
307 self.StartRangeSamp = header['StartRangeSamp'][0]
308 self.PRFhz = header['PRFhz'][0]
309 self.Integrations = header['Integrations'][0]
310 self.nDataPointsTrsf = header['nDataPointsTrsf'][0]
311 self.nReceiveBeams = header['nReceiveBeams'][0]
312 self.nSpectAverages = header['nSpectAverages'][0]
313 self.FFTwindowingInd = header['FFTwindowingInd'][0]
314 self.BeamAngleAzim = header['BeamAngleAzim'][0]
315 self.BeamAngleZen = header['BeamAngleZen'][0]
316 self.AntennaCoord = header['AntennaCoord'][0]
317 self.RecPhaseCalibr = header['RecPhaseCalibr'][0]
318 self.RecAmpCalibr = header['RecAmpCalibr'][0]
319 self.ReceiverGaindB = header['ReceiverGaindB'][0]
320
321 Self.size = 180+20*3
322
323 endFp = self.size + startFp
324
325 if fp.tell() > endFp:
326 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
327 return 0
328
329 if fp.tell() < endFp:
330 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
331 return 0
332
333 return 1
334
335 def write(self, fp):
336
337 headerTuple = (self.RecMgcNumber,
338 self.RecCounter,
339 self.Off2StartNxtRec,
340 self.EpTimeStamp,
341 self.msCompTimeStamp,
342 self.ExpTagName,
343 self.ExpComment,
344 self.SiteLatDegrees,
345 self.SiteLongDegrees,
346 self.RTCgpsStatus,
347 self.TransmitFrec,
348 self.ReceiveFrec,
349 self.FirstOsciFrec,
350 self.Polarisation,
351 self.ReceiverFiltSett,
352 self.nModesInUse,
353 self.DualModeIndex,
354 self.DualModeRange,
355 self.nDigChannels,
356 self.SampResolution,
357 self.nRangeGatesSamp,
358 self.StartRangeSamp,
359 self.PRFhz,
360 self.Integrations,
361 self.nDataPointsTrsf,
362 self.nReceiveBeams,
363 self.nSpectAverages,
364 self.FFTwindowingInd,
365 self.BeamAngleAzim,
366 self.BeamAngleZen,
367 self.AntennaCoord,
368 self.RecPhaseCalibr,
369 self.RecAmpCalibr,
370 self.ReceiverGaindB)
371
372 # self.size,self.nSamples,
373 # self.nProfiles,
374 # self.nChannels,
375 # self.adcResolution,
376 # self.pciDioBusWidth
377
378 header = numpy.array(headerTuple,RECORD_STRUCTURE)
379 header.tofile(fp)
380
381 return 1
382
383
384 def get_dtype_index(numpy_dtype):
385
386 index = None
387
388 for i in range(len(NUMPY_DTYPE_LIST)):
389 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
390 index = i
391 break
392
393 return index
394
395 def get_numpy_dtype(index):
396
397 #dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
398
399 return NUMPY_DTYPE_LIST[index]
400
401
402 def get_dtype_width(index):
403
404 return DTYPE_WIDTH[index] No newline at end of file
@@ -0,0 +1,469
1 import numpy
2 import datetime
3 import sys
4 import matplotlib
5
6 if 'linux' in sys.platform:
7 matplotlib.use("TKAgg")
8
9 if 'darwin' in sys.platform:
10 matplotlib.use('TKAgg')
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 import matplotlib.pyplot
13
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 from matplotlib.ticker import FuncFormatter, LinearLocator
16
17 ###########################################
18 #Actualizacion de las funciones del driver
19 ###########################################
20
21 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
22 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
23 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
24 matplotlib.pyplot.register_cmap(cmap=ncmap)
25
26 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
27
28 matplotlib.pyplot.ioff()
29
30 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
31 fig.canvas.manager.set_window_title(wintitle)
32 # fig.canvas.manager.resize(width, height)
33 matplotlib.pyplot.ion()
34
35
36 if show:
37 matplotlib.pyplot.show()
38
39 return fig
40
41 def closeFigure(show=False, fig=None):
42
43 # matplotlib.pyplot.ioff()
44 # matplotlib.pyplot.pause(0)
45
46 if show:
47 matplotlib.pyplot.show()
48
49 if fig != None:
50 matplotlib.pyplot.close(fig)
51 # matplotlib.pyplot.pause(0)
52 # matplotlib.pyplot.ion()
53
54 return
55
56 matplotlib.pyplot.close("all")
57 # matplotlib.pyplot.pause(0)
58 # matplotlib.pyplot.ion()
59
60 return
61
62 def saveFigure(fig, filename):
63
64 # matplotlib.pyplot.ioff()
65 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
66 # matplotlib.pyplot.ion()
67
68 def clearFigure(fig):
69
70 fig.clf()
71
72 def setWinTitle(fig, title):
73
74 fig.canvas.manager.set_window_title(title)
75
76 def setTitle(fig, title):
77
78 fig.suptitle(title)
79
80 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
81
82 matplotlib.pyplot.ioff()
83 matplotlib.pyplot.figure(fig.number)
84 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
85 (xpos, ypos),
86 colspan=colspan,
87 rowspan=rowspan,
88 polar=polar)
89
90 axes.grid(True)
91 matplotlib.pyplot.ion()
92 return axes
93
94 def setAxesText(ax, text):
95
96 ax.annotate(text,
97 xy = (.1, .99),
98 xycoords = 'figure fraction',
99 horizontalalignment = 'left',
100 verticalalignment = 'top',
101 fontsize = 10)
102
103 def printLabels(ax, xlabel, ylabel, title):
104
105 ax.set_xlabel(xlabel, size=11)
106 ax.set_ylabel(ylabel, size=11)
107 ax.set_title(title, size=8)
108
109 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
110 ticksize=9, xtick_visible=True, ytick_visible=True,
111 nxticks=4, nyticks=10,
112 grid=None,color='blue'):
113
114 """
115
116 Input:
117 grid : None, 'both', 'x', 'y'
118 """
119
120 matplotlib.pyplot.ioff()
121
122 ax.set_xlim([xmin,xmax])
123 ax.set_ylim([ymin,ymax])
124
125 printLabels(ax, xlabel, ylabel, title)
126
127 ######################################################
128 if (xmax-xmin)<=1:
129 xtickspos = numpy.linspace(xmin,xmax,nxticks)
130 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
131 ax.set_xticks(xtickspos)
132 else:
133 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
134 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
135 ax.set_xticks(xtickspos)
136
137 for tick in ax.get_xticklabels():
138 tick.set_visible(xtick_visible)
139
140 for tick in ax.xaxis.get_major_ticks():
141 tick.label.set_fontsize(ticksize)
142
143 ######################################################
144 for tick in ax.get_yticklabels():
145 tick.set_visible(ytick_visible)
146
147 for tick in ax.yaxis.get_major_ticks():
148 tick.label.set_fontsize(ticksize)
149
150 ax.plot(x, y, color=color)
151 iplot = ax.lines[-1]
152
153 ######################################################
154 if '0.' in matplotlib.__version__[0:2]:
155 print "The matplotlib version has to be updated to 1.1 or newer"
156 return iplot
157
158 if '1.0.' in matplotlib.__version__[0:4]:
159 print "The matplotlib version has to be updated to 1.1 or newer"
160 return iplot
161
162 if grid != None:
163 ax.grid(b=True, which='major', axis=grid)
164
165 matplotlib.pyplot.tight_layout()
166
167 matplotlib.pyplot.ion()
168
169 return iplot
170
171 def set_linedata(ax, x, y, idline):
172
173 ax.lines[idline].set_data(x,y)
174
175 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
176
177 ax = iplot.get_axes()
178
179 printLabels(ax, xlabel, ylabel, title)
180
181 set_linedata(ax, x, y, idline=0)
182
183 def addpline(ax, x, y, color, linestyle, lw):
184
185 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
186
187
188 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
189 xlabel='', ylabel='', title='', ticksize = 9,
190 colormap='jet',cblabel='', cbsize="5%",
191 XAxisAsTime=False):
192
193 matplotlib.pyplot.ioff()
194
195 divider = make_axes_locatable(ax)
196 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
197 fig = ax.get_figure()
198 fig.add_axes(ax_cb)
199
200 ax.set_xlim([xmin,xmax])
201 ax.set_ylim([ymin,ymax])
202
203 printLabels(ax, xlabel, ylabel, title)
204
205 z = numpy.ma.masked_invalid(z)
206 cmap=matplotlib.pyplot.get_cmap(colormap)
207 cmap.set_bad('white',1.)
208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
210 cb.set_label(cblabel)
211
212 # for tl in ax_cb.get_yticklabels():
213 # tl.set_visible(True)
214
215 for tick in ax.yaxis.get_major_ticks():
216 tick.label.set_fontsize(ticksize)
217
218 for tick in ax.xaxis.get_major_ticks():
219 tick.label.set_fontsize(ticksize)
220
221 for tick in cb.ax.get_yticklabels():
222 tick.set_fontsize(ticksize)
223
224 ax_cb.yaxis.tick_right()
225
226 if '0.' in matplotlib.__version__[0:2]:
227 print "The matplotlib version has to be updated to 1.1 or newer"
228 return imesh
229
230 if '1.0.' in matplotlib.__version__[0:4]:
231 print "The matplotlib version has to be updated to 1.1 or newer"
232 return imesh
233
234 matplotlib.pyplot.tight_layout()
235
236 if XAxisAsTime:
237
238 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
239 ax.xaxis.set_major_formatter(FuncFormatter(func))
240 ax.xaxis.set_major_locator(LinearLocator(7))
241 ax.grid(True)
242 matplotlib.pyplot.ion()
243 return imesh
244
245 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
246
247 z = z.T
248 ax = imesh.get_axes()
249 printLabels(ax, xlabel, ylabel, title)
250 imesh.set_array(z.ravel())
251 ax.grid(True)
252
253 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
254
255 printLabels(ax, xlabel, ylabel, title)
256 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
257 ax.grid(True)
258
259 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
260
261 printLabels(ax, xlabel, ylabel, title)
262
263 ax.collections.remove(ax.collections[0])
264
265 z = numpy.ma.masked_invalid(z)
266
267 cmap=matplotlib.pyplot.get_cmap(colormap)
268 cmap.set_bad('white',1.)
269
270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
271 ax.grid(True)
272
273 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
274 ticksize=9, xtick_visible=True, ytick_visible=True,
275 nxticks=4, nyticks=10,
276 grid=None):
277
278 """
279
280 Input:
281 grid : None, 'both', 'x', 'y'
282 """
283
284 matplotlib.pyplot.ioff()
285
286 lines = ax.plot(x.T, y)
287 leg = ax.legend(lines, legendlabels, loc='upper right')
288 leg.get_frame().set_alpha(0.5)
289 ax.set_xlim([xmin,xmax])
290 ax.set_ylim([ymin,ymax])
291 printLabels(ax, xlabel, ylabel, title)
292
293 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
294 ax.set_xticks(xtickspos)
295
296 for tick in ax.get_xticklabels():
297 tick.set_visible(xtick_visible)
298
299 for tick in ax.xaxis.get_major_ticks():
300 tick.label.set_fontsize(ticksize)
301
302 for tick in ax.get_yticklabels():
303 tick.set_visible(ytick_visible)
304
305 for tick in ax.yaxis.get_major_ticks():
306 tick.label.set_fontsize(ticksize)
307
308 iplot = ax.lines[-1]
309
310 if '0.' in matplotlib.__version__[0:2]:
311 print "The matplotlib version has to be updated to 1.1 or newer"
312 return iplot
313
314 if '1.0.' in matplotlib.__version__[0:4]:
315 print "The matplotlib version has to be updated to 1.1 or newer"
316 return iplot
317
318 if grid != None:
319 ax.grid(b=True, which='major', axis=grid)
320
321 matplotlib.pyplot.tight_layout()
322
323 matplotlib.pyplot.ion()
324
325 return iplot
326
327
328 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
329
330 ax = iplot.get_axes()
331
332 printLabels(ax, xlabel, ylabel, title)
333
334 for i in range(len(ax.lines)):
335 line = ax.lines[i]
336 line.set_data(x[i,:],y)
337
338 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
339 ticksize=9, xtick_visible=True, ytick_visible=True,
340 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
341 grid=None, XAxisAsTime=False):
342
343 """
344
345 Input:
346 grid : None, 'both', 'x', 'y'
347 """
348
349 matplotlib.pyplot.ioff()
350
351 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
352 lines = ax.plot(x, y.T)
353 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
354 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
355
356 leg = ax.legend(lines, legendlabels,
357 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
358
359 for label in leg.get_texts(): label.set_fontsize(9)
360
361 ax.set_xlim([xmin,xmax])
362 ax.set_ylim([ymin,ymax])
363 printLabels(ax, xlabel, ylabel, title)
364
365 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
366 # ax.set_xticks(xtickspos)
367
368 for tick in ax.get_xticklabels():
369 tick.set_visible(xtick_visible)
370
371 for tick in ax.xaxis.get_major_ticks():
372 tick.label.set_fontsize(ticksize)
373
374 for tick in ax.get_yticklabels():
375 tick.set_visible(ytick_visible)
376
377 for tick in ax.yaxis.get_major_ticks():
378 tick.label.set_fontsize(ticksize)
379
380 iplot = ax.lines[-1]
381
382 if '0.' in matplotlib.__version__[0:2]:
383 print "The matplotlib version has to be updated to 1.1 or newer"
384 return iplot
385
386 if '1.0.' in matplotlib.__version__[0:4]:
387 print "The matplotlib version has to be updated to 1.1 or newer"
388 return iplot
389
390 if grid != None:
391 ax.grid(b=True, which='major', axis=grid)
392
393 matplotlib.pyplot.tight_layout()
394
395 if XAxisAsTime:
396
397 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
398 ax.xaxis.set_major_formatter(FuncFormatter(func))
399 ax.xaxis.set_major_locator(LinearLocator(7))
400
401 matplotlib.pyplot.ion()
402
403 return iplot
404
405 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
406
407 ax = iplot.get_axes()
408
409 printLabels(ax, xlabel, ylabel, title)
410
411 for i in range(len(ax.lines)):
412 line = ax.lines[i]
413 line.set_data(x,y[i,:])
414
415 def createPolar(ax, x, y,
416 xlabel='', ylabel='', title='', ticksize = 9,
417 colormap='jet',cblabel='', cbsize="5%",
418 XAxisAsTime=False):
419
420 matplotlib.pyplot.ioff()
421
422 ax.plot(x,y,'bo', markersize=5)
423 # ax.set_rmax(90)
424 ax.set_ylim(0,90)
425 ax.set_yticks(numpy.arange(0,90,20))
426 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
427 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
428 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
429 ax.yaxis.labelpad = 230
430 printLabels(ax, xlabel, ylabel, title)
431 iplot = ax.lines[-1]
432
433 if '0.' in matplotlib.__version__[0:2]:
434 print "The matplotlib version has to be updated to 1.1 or newer"
435 return iplot
436
437 if '1.0.' in matplotlib.__version__[0:4]:
438 print "The matplotlib version has to be updated to 1.1 or newer"
439 return iplot
440
441 # if grid != None:
442 # ax.grid(b=True, which='major', axis=grid)
443
444 matplotlib.pyplot.tight_layout()
445
446 matplotlib.pyplot.ion()
447
448
449 return iplot
450
451 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
452
453 ax = iplot.get_axes()
454
455 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
456 printLabels(ax, xlabel, ylabel, title)
457
458 set_linedata(ax, x, y, idline=0)
459
460 def draw(fig):
461
462 if type(fig) == 'int':
463 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
464
465 fig.canvas.draw()
466
467 def pause(interval=0.000001):
468
469 matplotlib.pyplot.pause(interval)
@@ -0,0 +1,321
1 import os, sys
2 import glob
3 import fnmatch
4 import datetime
5 import time
6 import re
7 import h5py
8 import numpy
9 import matplotlib.pyplot as plt
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
14 from scipy import stats
15
16 from duplicity.path import Path
17 from numpy.ma.core import getdata
18
19 SPEED_OF_LIGHT = 299792458
20 SPEED_OF_LIGHT = 3e8
21
22 try:
23 from gevent import sleep
24 except:
25 from time import sleep
26
27 from schainpy.model.data.jrodata import Spectra
28 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
29 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
30 #from schainpy.model.io.jroIO_bltr import BLTRReader
31 from numpy import imag, shape, NaN
32
33
34 startFp = open('/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc',"rb")
35
36
37 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
38 ('Hname',numpy.str_,32), #Original file name
39 ('Htime',numpy.str_,32), #Date and time when the file was created
40 ('Hoper',numpy.str_,64), #Name of operator who created the file
41 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
42 ('Hdescr',numpy.str_,256), #Description of measurements
43 ('Hdummy',numpy.str_,512), #Reserved space
44 #Main chunk
45 ('Msign','<i4'), #Main chunk signature FZKF or NUIG
46 ('MsizeData','<i4'), #Size of data block main chunk
47 #Processing DSP parameters
48 ('PPARsign','<i4'), #PPAR signature
49 ('PPARsize','<i4'), #PPAR size of block
50 ('PPARprf','<i4'), #Pulse repetition frequency
51 ('PPARpdr','<i4'), #Pulse duration
52 ('PPARsft','<i4'), #FFT length
53 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
54 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
55 ('PPARchg','<i4'), #Count for gates for moment estimation
56 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
57 #Service DSP parameters
58 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
59 ('SPARtx','<i4'), #OBSOLETE
60 ('SPARaddGain0','<f4'), #OBSOLETE
61 ('SPARaddGain1','<f4'), #OBSOLETE
62 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
63 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
64 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
65 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
66 ('SPARcal','<i4'), #OBSOLETE
67 ('SPARnos','<i4'), #OBSOLETE
68 ('SPARof0','<i4'), #detection threshold
69 ('SPARof1','<i4'), #OBSOLETE
70 ('SPARswt','<i4'), #2nd moment estimation threshold
71 ('SPARsum','<i4'), #OBSOLETE
72 ('SPARosc','<i4'), #flag Oscillosgram mode
73 ('SPARtst','<i4'), #OBSOLETE
74 ('SPARcor','<i4'), #OBSOLETE
75 ('SPARofs','<i4'), #OBSOLETE
76 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
77 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
78 ('SPARcalibPow_M','<f4'), #OBSOLETE
79 ('SPARcalibSNR_M','<f4'), #OBSOLETE
80 ('SPARcalibPow_S','<f4'), #OBSOLETE
81 ('SPARcalibSNR_S','<f4'), #OBSOLETE
82 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
83 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
84 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
85 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
86
87
88
89 self.Hname= None
90 self.Htime= None
91 self.Hoper= None
92 self.Hplace= None
93 self.Hdescr= None
94 self.Hdummy= None
95
96 self.Msign=None
97 self.MsizeData=None
98
99 self.PPARsign=None
100 self.PPARsize=None
101 self.PPARprf=None
102 self.PPARpdr=None
103 self.PPARsft=None
104 self.PPARavc=None
105 self.PPARihp=None
106 self.PPARchg=None
107 self.PPARpol=None
108 #Service DSP parameters
109 self.SPARatt=None
110 self.SPARtx=None
111 self.SPARaddGain0=None
112 self.SPARaddGain1=None
113 self.SPARwnd=None
114 self.SPARpos=None
115 self.SPARadd=None
116 self.SPARlen=None
117 self.SPARcal=None
118 self.SPARnos=None
119 self.SPARof0=None
120 self.SPARof1=None
121 self.SPARswt=None
122 self.SPARsum=None
123 self.SPARosc=None
124 self.SPARtst=None
125 self.SPARcor=None
126 self.SPARofs=None
127 self.SPARhsn=None
128 self.SPARhsa=None
129 self.SPARcalibPow_M=None
130 self.SPARcalibSNR_M=None
131 self.SPARcalibPow_S=None
132 self.SPARcalibSNR_S=None
133 self.SPARrawGate1=None
134 self.SPARrawGate2=None
135 self.SPARraw=None
136 self.SPARprc=None
137
138
139
140 header = numpy.fromfile(fp, FILE_HEADER,1)
141 ''' numpy.fromfile(file, dtype, count, sep='')
142 file : file or str
143 Open file object or filename.
144
145 dtype : data-type
146 Data type of the returned array. For binary files, it is used to determine
147 the size and byte-order of the items in the file.
148
149 count : int
150 Number of items to read. -1 means all items (i.e., the complete file).
151
152 sep : str
153 Separator between items if file is a text file. Empty ("") separator means
154 the file should be treated as binary. Spaces (" ") in the separator match zero
155 or more whitespace characters. A separator consisting only of spaces must match
156 at least one whitespace.
157
158 '''
159
160 Hname= str(header['Hname'][0])
161 Htime= str(header['Htime'][0])
162 Hoper= str(header['Hoper'][0])
163 Hplace= str(header['Hplace'][0])
164 Hdescr= str(header['Hdescr'][0])
165 Hdummy= str(header['Hdummy'][0])
166
167 Msign=header['Msign'][0]
168 MsizeData=header['MsizeData'][0]
169
170 PPARsign=header['PPARsign'][0]
171 PPARsize=header['PPARsize'][0]
172 PPARprf=header['PPARprf'][0]
173 PPARpdr=header['PPARpdr'][0]
174 PPARsft=header['PPARsft'][0]
175 PPARavc=header['PPARavc'][0]
176 PPARihp=header['PPARihp'][0]
177 PPARchg=header['PPARchg'][0]
178 PPARpol=header['PPARpol'][0]
179 #Service DSP parameters
180 SPARatt=header['SPARatt'][0]
181 SPARtx=header['SPARtx'][0]
182 SPARaddGain0=header['SPARaddGain0'][0]
183 SPARaddGain1=header['SPARaddGain1'][0]
184 SPARwnd=header['SPARwnd'][0]
185 SPARpos=header['SPARpos'][0]
186 SPARadd=header['SPARadd'][0]
187 SPARlen=header['SPARlen'][0]
188 SPARcal=header['SPARcal'][0]
189 SPARnos=header['SPARnos'][0]
190 SPARof0=header['SPARof0'][0]
191 SPARof1=header['SPARof1'][0]
192 SPARswt=header['SPARswt'][0]
193 SPARsum=header['SPARsum'][0]
194 SPARosc=header['SPARosc'][0]
195 SPARtst=header['SPARtst'][0]
196 SPARcor=header['SPARcor'][0]
197 SPARofs=header['SPARofs'][0]
198 SPARhsn=header['SPARhsn'][0]
199 SPARhsa=header['SPARhsa'][0]
200 SPARcalibPow_M=header['SPARcalibPow_M'][0]
201 SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
202 SPARcalibPow_S=header['SPARcalibPow_S'][0]
203 SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
204 SPARrawGate1=header['SPARrawGate1'][0]
205 SPARrawGate2=header['SPARrawGate2'][0]
206 SPARraw=header['SPARraw'][0]
207 SPARprc=header['SPARprc'][0]
208
209
210
211 SRVI_STRUCTURE = numpy.dtype([
212 ('frame_cnt','<u4'),#
213 ('time_t','<u4'), #
214 ('tpow','<f4'), #
215 ('npw1','<f4'), #
216 ('npw2','<f4'), #
217 ('cpw1','<f4'), #
218 ('pcw2','<f4'), #
219 ('ps_err','<u4'), #
220 ('te_err','<u4'), #
221 ('rc_err','<u4'), #
222 ('grs1','<u4'), #
223 ('grs2','<u4'), #
224 ('azipos','<f4'), #
225 ('azivel','<f4'), #
226 ('elvpos','<f4'), #
227 ('elvvel','<f4'), #
228 ('northAngle','<f4'), #
229 ('microsec','<u4'), #
230 ('azisetvel','<f4'), #
231 ('elvsetpos','<f4'), #
232 ('RadarConst','<f4'),]) #
233
234 JUMP_STRUCTURE = numpy.dtype([
235 ('jump','<u140'),#
236 ('SizeOfDataBlock1',numpy.str_,32),#
237 ('jump','<i4'),#
238 ('DataBlockTitleSRVI1',numpy.str_,32),#
239 ('SizeOfSRVI1','<i4'),])#
240
241
242
243 #frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
244 #cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
245 #grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
246 #microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
247
248
249 frame_cnt = frame_cnt
250 dwell = time_t
251 tpow = tpow
252 npw1 = npw1
253 npw2 = npw2
254 cpw1 = cpw1
255 pcw2 = pcw2
256 ps_err = ps_err
257 te_err = te_err
258 rc_err = rc_err
259 grs1 = grs1
260 grs2 = grs2
261 azipos = azipos
262 azivel = azivel
263 elvpos = elvpos
264 elvvel = elvvel
265 northAngle = northAngle
266 microsec = microsec
267 azisetvel = azisetvel
268 elvsetpos = elvsetpos
269 RadarConst5 = RadarConst
270
271
272
273 #print fp
274 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
275 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
276 #RecCounter=0
277 #Off2StartNxtRec=811248
278 #print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
279 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
280 #startFp.seek(OffRHeader, os.SEEK_SET)
281 print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader,self.RecCounter,self.Off2StartNxtRec
282 print 'Posicion del bloque: ',OffRHeader
283
284 header = numpy.fromfile(startFp,SRVI_STRUCTURE,1)
285
286 self.frame_cnt = header['frame_cnt'][0]#
287 self.time_t = header['frame_cnt'][0] #
288 self.tpow = header['frame_cnt'][0] #
289 self.npw1 = header['frame_cnt'][0] #
290 self.npw2 = header['frame_cnt'][0] #
291 self.cpw1 = header['frame_cnt'][0] #
292 self.pcw2 = header['frame_cnt'][0] #
293 self.ps_err = header['frame_cnt'][0] #
294 self.te_err = header['frame_cnt'][0] #
295 self.rc_err = header['frame_cnt'][0] #
296 self.grs1 = header['frame_cnt'][0] #
297 self.grs2 = header['frame_cnt'][0] #
298 self.azipos = header['frame_cnt'][0] #
299 self.azivel = header['frame_cnt'][0] #
300 self.elvpos = header['frame_cnt'][0] #
301 self.elvvel = header['frame_cnt'][0] #
302 self.northAngle = header['frame_cnt'][0] #
303 self.microsec = header['frame_cnt'][0] #
304 self.azisetvel = header['frame_cnt'][0] #
305 self.elvsetpos = header['frame_cnt'][0] #
306 self.RadarConst = header['frame_cnt'][0] #
307
308
309 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
310
311 self.RHsize = 180+20*self.nChannels
312 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
313 #print 'Datasize',self.Datasize
314 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
315
316 print '=============================================='
317
318 print '=============================================='
319
320
321 No newline at end of file
@@ -0,0 +1,362
1 '''
2 Created on Nov 9, 2016
3
4 @author: roj- LouVD
5 '''
6
7
8 import os
9 import sys
10 import time
11 import glob
12 import datetime
13
14 import numpy
15
16 from schainpy.model.proc.jroproc_base import ProcessingUnit
17 from schainpy.model.data.jrodata import Parameters
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
19
20 FILE_HEADER_STRUCTURE = numpy.dtype([
21 ('FMN', '<u4'),
22 ('nrec', '<u4'),
23 ('fr_offset', '<u4'),
24 ('id', '<u4'),
25 ('site', 'u1', (32,))
26 ])
27
28 REC_HEADER_STRUCTURE = numpy.dtype([
29 ('rmn', '<u4'),
30 ('rcounter', '<u4'),
31 ('nr_offset', '<u4'),
32 ('tr_offset', '<u4'),
33 ('time', '<u4'),
34 ('time_msec', '<u4'),
35 ('tag', 'u1', (32,)),
36 ('comments', 'u1', (32,)),
37 ('lat', '<f4'),
38 ('lon', '<f4'),
39 ('gps_status', '<u4'),
40 ('freq', '<u4'),
41 ('freq0', '<u4'),
42 ('nchan', '<u4'),
43 ('delta_r', '<u4'),
44 ('nranges', '<u4'),
45 ('r0', '<u4'),
46 ('prf', '<u4'),
47 ('ncoh', '<u4'),
48 ('npoints', '<u4'),
49 ('polarization', '<i4'),
50 ('rx_filter', '<u4'),
51 ('nmodes', '<u4'),
52 ('dmode_index', '<u4'),
53 ('dmode_rngcorr', '<u4'),
54 ('nrxs', '<u4'),
55 ('acf_length', '<u4'),
56 ('acf_lags', '<u4'),
57 ('sea_to_atmos', '<f4'),
58 ('sea_notch', '<u4'),
59 ('lh_sea', '<u4'),
60 ('hh_sea', '<u4'),
61 ('nbins_sea', '<u4'),
62 ('min_snr', '<f4'),
63 ('min_cc', '<f4'),
64 ('max_time_diff', '<f4')
65 ])
66
67 DATA_STRUCTURE = numpy.dtype([
68 ('range', '<u4'),
69 ('status', '<u4'),
70 ('zonal', '<f4'),
71 ('meridional', '<f4'),
72 ('vertical', '<f4'),
73 ('zonal_a', '<f4'),
74 ('meridional_a', '<f4'),
75 ('corrected_fading', '<f4'), # seconds
76 ('uncorrected_fading', '<f4'), # seconds
77 ('time_diff', '<f4'),
78 ('major_axis', '<f4'),
79 ('axial_ratio', '<f4'),
80 ('orientation', '<f4'),
81 ('sea_power', '<u4'),
82 ('sea_algorithm', '<u4')
83 ])
84
85 class BLTRParamReader(JRODataReader, ProcessingUnit):
86 '''
87 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
88 '''
89
90 ext = '.sswma'
91
92 def __init__(self, **kwargs):
93
94 ProcessingUnit.__init__(self , **kwargs)
95
96 self.dataOut = Parameters()
97 self.counter_records = 0
98 self.flagNoMoreFiles = 0
99 self.isConfig = False
100 self.filename = None
101
102 def setup(self,
103 path=None,
104 startDate=None,
105 endDate=None,
106 ext=None,
107 startTime=datetime.time(0, 0, 0),
108 endTime=datetime.time(23, 59, 59),
109 timezone=0,
110 status_value=0,
111 **kwargs):
112
113 self.path = path
114 self.startTime = startTime
115 self.endTime = endTime
116 self.status_value = status_value
117
118 if self.path is None:
119 raise ValueError, "The path is not valid"
120
121 if ext is None:
122 ext = self.ext
123
124 self.search_files(self.path, startDate, endDate, ext)
125 self.timezone = timezone
126 self.fileIndex = 0
127
128 if not self.fileList:
129 raise Warning, "There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' "%(path)
130
131 self.setNextFile()
132
133 def search_files(self, path, startDate, endDate, ext):
134 '''
135 Searching for BLTR rawdata file in path
136 Creating a list of file to proces included in [startDate,endDate]
137
138 Input:
139 path - Path to find BLTR rawdata files
140 startDate - Select file from this date
141 enDate - Select file until this date
142 ext - Extension of the file to read
143
144 '''
145
146 print 'Searching file in %s ' % (path)
147 foldercounter = 0
148 fileList0 = glob.glob1(path, "*%s" % ext)
149 fileList0.sort()
150
151 self.fileList = []
152 self.dateFileList = []
153
154 for thisFile in fileList0:
155 year = thisFile[-14:-10]
156 if not isNumber(year):
157 continue
158
159 month = thisFile[-10:-8]
160 if not isNumber(month):
161 continue
162
163 day = thisFile[-8:-6]
164 if not isNumber(day):
165 continue
166
167 year, month, day = int(year), int(month), int(day)
168 dateFile = datetime.date(year, month, day)
169
170 if (startDate > dateFile) or (endDate < dateFile):
171 continue
172
173 self.fileList.append(thisFile)
174 self.dateFileList.append(dateFile)
175
176 return
177
178 def setNextFile(self):
179
180 file_id = self.fileIndex
181
182 if file_id == len(self.fileList):
183 print '\nNo more files in the folder'
184 print 'Total number of file(s) read : {}'.format(self.fileIndex + 1)
185 self.flagNoMoreFiles = 1
186 return 0
187
188 print '\n[Setting file] (%s) ...' % self.fileList[file_id]
189 filename = os.path.join(self.path, self.fileList[file_id])
190
191 dirname, name = os.path.split(filename)
192 self.siteFile = name.split('.')[0] # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
193 if self.filename is not None:
194 self.fp.close()
195 self.filename = filename
196 self.fp = open(self.filename, 'rb')
197 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
198 self.nrecords = self.header_file['nrec'][0]
199 self.sizeOfFile = os.path.getsize(self.filename)
200 self.counter_records = 0
201 self.flagIsNewFile = 0
202 self.fileIndex += 1
203
204 return 1
205
206 def readNextBlock(self):
207
208 while True:
209 if self.counter_records == self.nrecords:
210 self.flagIsNewFile = 1
211 if not self.setNextFile():
212 return 0
213
214 self.readBlock()
215
216 if (self.datatime.time() < self.startTime) or (self.datatime.time() > self.endTime):
217 print "[Reading] Record No. %d/%d -> %s [Skipping]" %(
218 self.counter_records,
219 self.nrecords,
220 self.datatime.ctime())
221 continue
222 break
223
224 print "[Reading] Record No. %d/%d -> %s" %(
225 self.counter_records,
226 self.nrecords,
227 self.datatime.ctime())
228
229 return 1
230
231 def readBlock(self):
232
233 pointer = self.fp.tell()
234 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
235 self.nchannels = header_rec['nchan'][0]/2
236 self.kchan = header_rec['nrxs'][0]
237 self.nmodes = header_rec['nmodes'][0]
238 self.nranges = header_rec['nranges'][0]
239 self.fp.seek(pointer)
240 self.height = numpy.empty((self.nmodes, self.nranges))
241 self.snr = numpy.empty((self.nmodes, self.nchannels, self.nranges))
242 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
243
244 for mode in range(self.nmodes):
245 self.readHeader()
246 data = self.readData()
247 self.height[mode] = (data[0] - self.correction) / 1000.
248 self.buffer[mode] = data[1]
249 self.snr[mode] = data[2]
250
251 self.counter_records = self.counter_records + self.nmodes
252
253 return
254
255 def readHeader(self):
256 '''
257 RecordHeader of BLTR rawdata file
258 '''
259
260 header_structure = numpy.dtype(
261 REC_HEADER_STRUCTURE.descr + [
262 ('antenna_coord', 'f4', (2, self.nchannels)),
263 ('rx_gains', 'u4', (self.nchannels,)),
264 ('rx_analysis', 'u4', (self.nchannels,))
265 ]
266 )
267
268 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
269 self.lat = self.header_rec['lat'][0]
270 self.lon = self.header_rec['lon'][0]
271 self.delta = self.header_rec['delta_r'][0]
272 self.correction = self.header_rec['dmode_rngcorr'][0]
273 self.imode = self.header_rec['dmode_index'][0]
274 self.antenna = self.header_rec['antenna_coord']
275 self.rx_gains = self.header_rec['rx_gains']
276 self.time = self.header_rec['time'][0]
277 tseconds = self.header_rec['time'][0]
278 local_t1 = time.localtime(tseconds)
279 self.year = local_t1.tm_year
280 self.month = local_t1.tm_mon
281 self.day = local_t1.tm_mday
282 self.t = datetime.datetime(self.year, self.month, self.day)
283 self.datatime = datetime.datetime.utcfromtimestamp(self.time)
284
285 def readData(self):
286 '''
287 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
288
289 Input:
290 status_value - Array data is set to NAN for values that are not equal to status_value
291
292 '''
293
294 data_structure = numpy.dtype(
295 DATA_STRUCTURE.descr + [
296 ('rx_saturation', 'u4', (self.nchannels,)),
297 ('chan_offset', 'u4', (2 * self.nchannels,)),
298 ('rx_amp', 'u4', (self.nchannels,)),
299 ('rx_snr', 'f4', (self.nchannels,)),
300 ('cross_snr', 'f4', (self.kchan,)),
301 ('sea_power_relative', 'f4', (self.kchan,))]
302 )
303
304 data = numpy.fromfile(self.fp, data_structure, self.nranges)
305
306 height = data['range']
307 winds = numpy.array((data['zonal'], data['meridional'], data['vertical']))
308 snr = data['rx_snr'].T
309
310 winds[numpy.where(winds == -9999.)] = numpy.nan
311 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
312 snr[numpy.where(snr == -9999.)] = numpy.nan
313 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
314 snr = numpy.power(10, snr / 10)
315
316 return height, winds, snr
317
318 def set_output(self):
319 '''
320 Storing data from databuffer to dataOut object
321 '''
322
323 self.dataOut.data_SNR = self.snr
324 self.dataOut.height = self.height
325 self.dataOut.data_output = self.buffer
326 self.dataOut.utctimeInit = self.time
327 self.dataOut.utctime = self.dataOut.utctimeInit
328 self.dataOut.useLocalTime = False
329 self.dataOut.paramInterval = 157
330 self.dataOut.timezone = self.timezone
331 self.dataOut.site = self.siteFile
332 self.dataOut.nrecords = self.nrecords/self.nmodes
333 self.dataOut.sizeOfFile = self.sizeOfFile
334 self.dataOut.lat = self.lat
335 self.dataOut.lon = self.lon
336 self.dataOut.channelList = range(self.nchannels)
337 self.dataOut.kchan = self.kchan
338 # self.dataOut.nHeights = self.nranges
339 self.dataOut.delta = self.delta
340 self.dataOut.correction = self.correction
341 self.dataOut.nmodes = self.nmodes
342 self.dataOut.imode = self.imode
343 self.dataOut.antenna = self.antenna
344 self.dataOut.rx_gains = self.rx_gains
345 self.dataOut.flagNoData = False
346
347 def getData(self):
348 '''
349 Storing data from databuffer to dataOut object
350 '''
351 if self.flagNoMoreFiles:
352 self.dataOut.flagNoData = True
353 print 'No file left to process'
354 return 0
355
356 if not self.readNextBlock():
357 self.dataOut.flagNoData = True
358 return 0
359
360 self.set_output()
361
362 return 1
This diff has been collapsed as it changes many lines, (1154 lines changed) Show them Hide them
@@ -0,0 +1,1154
1 import os, sys
2 import glob
3 import fnmatch
4 import datetime
5 import time
6 import re
7 import h5py
8 import numpy
9 import matplotlib.pyplot as plt
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
13 from scipy import asarray as ar, exp
14 from scipy import stats
15
16 from numpy.ma.core import getdata
17
18 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
20
21 try:
22 from gevent import sleep
23 except:
24 from time import sleep
25
26 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN
31
32 from jroIO_base import JRODataReader
33
34
35 class Header(object):
36
37 def __init__(self):
38 raise NotImplementedError
39
40
41 def read(self):
42
43 raise NotImplementedError
44
45 def write(self):
46
47 raise NotImplementedError
48
49 def printInfo(self):
50
51 message = "#"*50 + "\n"
52 message += self.__class__.__name__.upper() + "\n"
53 message += "#"*50 + "\n"
54
55 keyList = self.__dict__.keys()
56 keyList.sort()
57
58 for key in keyList:
59 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
60
61 if "size" not in keyList:
62 attr = getattr(self, "size")
63
64 if attr:
65 message += "%s = %s" %("size", attr) + "\n"
66
67 #print message
68
69
70
71
72
73 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
74 ('FileMgcNumber','<u4'), #0x23020100
75 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
76 ('OffsetStartHeader','<u4'),
77 ('RadarUnitId','<u4'),
78 ('SiteName',numpy.str_,32), #Null terminated
79 ])
80
81 class FileHeaderBLTR(Header):
82
83 def __init__(self):
84
85 self.FileMgcNumber= 0 #0x23020100
86 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
87 self.RadarUnitId= 0
88 self.OffsetStartHeader=0
89 self.SiteName= ""
90 self.size = 48
91
92 def FHread(self, fp):
93 #try:
94 startFp = open(fp,"rb")
95
96 header = numpy.fromfile(startFp, FILE_STRUCTURE,1)
97
98 print ' '
99 print 'puntero file header', startFp.tell()
100 print ' '
101
102
103 ''' numpy.fromfile(file, dtype, count, sep='')
104 file : file or str
105 Open file object or filename.
106
107 dtype : data-type
108 Data type of the returned array. For binary files, it is used to determine
109 the size and byte-order of the items in the file.
110
111 count : int
112 Number of items to read. -1 means all items (i.e., the complete file).
113
114 sep : str
115 Separator between items if file is a text file. Empty ("") separator means
116 the file should be treated as binary. Spaces (" ") in the separator match zero
117 or more whitespace characters. A separator consisting only of spaces must match
118 at least one whitespace.
119
120 '''
121
122
123
124 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
125 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
126 self.RadarUnitId= int(header['RadarUnitId'][0])
127 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
128 self.SiteName= str(header['SiteName'][0])
129
130 #print 'Numero de bloques', self.nFDTdataRecors
131
132
133 if self.size <48:
134 return 0
135
136 return 1
137
138
139 def write(self, fp):
140
141 headerTuple = (self.FileMgcNumber,
142 self.nFDTdataRecors,
143 self.RadarUnitId,
144 self.SiteName,
145 self.size)
146
147
148 header = numpy.array(headerTuple, FILE_STRUCTURE)
149 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
150 header.tofile(fp)
151 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
152
153 fid : file or str
154 An open file object, or a string containing a filename.
155
156 sep : str
157 Separator between array items for text output. If "" (empty), a binary file is written,
158 equivalent to file.write(a.tobytes()).
159
160 format : str
161 Format string for text file output. Each entry in the array is formatted to text by
162 first converting it to the closest Python type, and then using "format" % item.
163
164 '''
165
166 return 1
167
168
169
170
171
172 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
173 ('RecMgcNumber','<u4'), #0x23030001
174 ('RecCounter','<u4'), #Record counter(0,1, ...)
175 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
176 ('Off2StartData','<u4'), #Offset to start of data from start of this record
177 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
178 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
179 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
180 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
181 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
182 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
183 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
184 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
185 ('ReceiveFrec','<u4'), #Receive frequency
186 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
187 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
188 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
189 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
190 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
191 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
192 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
193 ('SampResolution','<u4'), #Sampling resolution (meters)
194 ('nHeights','<u4'), #Number of range gates sampled
195 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
196 ('PRFhz','<u4'), #PRF (Hz)
197 ('nCohInt','<u4'), #Integrations
198 ('nProfiles','<u4'), #Number of data points transformed
199 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
200 ('nIncohInt','<u4'), #Number of spectral averages
201 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
202 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
203 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
204 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
205 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
206 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
207 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
209 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
211 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
212 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
213 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
214 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
215 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
216 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
217 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
218 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
219 ])
220
221
222 class RecordHeaderBLTR(Header):
223
224 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248,
225 nUtime= 0, nMilisec= 0, ExpTagName= None,
226 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
227 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
228 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
229 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
230 nDigChannels= 0, SampResolution= 0, nHeights= 0,
231 StartRangeSamp= 0, PRFhz= 0, nCohInt= 0,
232 nProfiles= 0, nChannels= 0, nIncohInt= 0,
233 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
234 AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0,
235 RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0,
236 RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0,
237 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
238 ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0):
239
240 self.RecMgcNumber = RecMgcNumber #0x23030001
241 self.RecCounter = RecCounter
242 self.Off2StartNxtRec = Off2StartNxtRec
243 self.Off2StartData = Off2StartData
244 self.nUtime = nUtime
245 self.nMilisec = nMilisec
246 self.ExpTagName = ExpTagName
247 self.ExpComment = ExpComment
248 self.SiteLatDegrees = SiteLatDegrees
249 self.SiteLongDegrees = SiteLongDegrees
250 self.RTCgpsStatus = RTCgpsStatus
251 self.TransmitFrec = TransmitFrec
252 self.ReceiveFrec = ReceiveFrec
253 self.FirstOsciFrec = FirstOsciFrec
254 self.Polarisation = Polarisation
255 self.ReceiverFiltSett = ReceiverFiltSett
256 self.nModesInUse = nModesInUse
257 self.DualModeIndex = DualModeIndex
258 self.DualModeRange = DualModeRange
259 self.nDigChannels = nDigChannels
260 self.SampResolution = SampResolution
261 self.nHeights = nHeights
262 self.StartRangeSamp = StartRangeSamp
263 self.PRFhz = PRFhz
264 self.nCohInt = nCohInt
265 self.nProfiles = nProfiles
266 self.nChannels = nChannels
267 self.nIncohInt = nIncohInt
268 self.FFTwindowingInd = FFTwindowingInd
269 self.BeamAngleAzim = BeamAngleAzim
270 self.BeamAngleZen = BeamAngleZen
271 self.AntennaCoord0 = AntennaCoord0
272 self.AntennaAngl0 = AntennaAngl0
273 self.AntennaAngl1 = AntennaAngl1
274 self.AntennaAngl2 = AntennaAngl2
275 self.AntennaCoord1 = AntennaCoord1
276 self.AntennaCoord2 = AntennaCoord2
277 self.RecPhaseCalibr0 = RecPhaseCalibr0
278 self.RecPhaseCalibr1 = RecPhaseCalibr1
279 self.RecPhaseCalibr2 = RecPhaseCalibr2
280 self.RecAmpCalibr0 = RecAmpCalibr0
281 self.RecAmpCalibr1 = RecAmpCalibr1
282 self.RecAmpCalibr2 = RecAmpCalibr2
283 self.ReceiverGaindB0 = ReceiverGaindB0
284 self.ReceiverGaindB1 = ReceiverGaindB1
285 self.ReceiverGaindB2 = ReceiverGaindB2
286 self.OffsetStartHeader = 48
287
288
289
290 def RHread(self, fp):
291 #print fp
292 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
293 startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
294 #RecCounter=0
295 #Off2StartNxtRec=811248
296 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
297 print ' '
298 print 'puntero Record Header', startFp.tell()
299 print ' '
300
301
302 startFp.seek(OffRHeader, os.SEEK_SET)
303
304 print ' '
305 print 'puntero Record Header con seek', startFp.tell()
306 print ' '
307
308 #print 'Posicion del bloque: ',OffRHeader
309
310 header = numpy.fromfile(startFp,RECORD_STRUCTURE,1)
311
312 print ' '
313 print 'puntero Record Header con seek', startFp.tell()
314 print ' '
315
316 print ' '
317 #
318 #print 'puntero Record Header despues de seek', header.tell()
319 print ' '
320
321 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) #0x23030001
322 self.RecCounter = int(header['RecCounter'][0])
323 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
324 self.Off2StartData = int(header['Off2StartData'][0])
325 self.nUtime = header['nUtime'][0]
326 self.nMilisec = header['nMilisec'][0]
327 self.ExpTagName = str(header['ExpTagName'][0])
328 self.ExpComment = str(header['ExpComment'][0])
329 self.SiteLatDegrees = header['SiteLatDegrees'][0]
330 self.SiteLongDegrees = header['SiteLongDegrees'][0]
331 self.RTCgpsStatus = header['RTCgpsStatus'][0]
332 self.TransmitFrec = header['TransmitFrec'][0]
333 self.ReceiveFrec = header['ReceiveFrec'][0]
334 self.FirstOsciFrec = header['FirstOsciFrec'][0]
335 self.Polarisation = header['Polarisation'][0]
336 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
337 self.nModesInUse = header['nModesInUse'][0]
338 self.DualModeIndex = header['DualModeIndex'][0]
339 self.DualModeRange = header['DualModeRange'][0]
340 self.nDigChannels = header['nDigChannels'][0]
341 self.SampResolution = header['SampResolution'][0]
342 self.nHeights = header['nHeights'][0]
343 self.StartRangeSamp = header['StartRangeSamp'][0]
344 self.PRFhz = header['PRFhz'][0]
345 self.nCohInt = header['nCohInt'][0]
346 self.nProfiles = header['nProfiles'][0]
347 self.nChannels = header['nChannels'][0]
348 self.nIncohInt = header['nIncohInt'][0]
349 self.FFTwindowingInd = header['FFTwindowingInd'][0]
350 self.BeamAngleAzim = header['BeamAngleAzim'][0]
351 self.BeamAngleZen = header['BeamAngleZen'][0]
352 self.AntennaCoord0 = header['AntennaCoord0'][0]
353 self.AntennaAngl0 = header['AntennaAngl0'][0]
354 self.AntennaCoord1 = header['AntennaCoord1'][0]
355 self.AntennaAngl1 = header['AntennaAngl1'][0]
356 self.AntennaCoord2 = header['AntennaCoord2'][0]
357 self.AntennaAngl2 = header['AntennaAngl2'][0]
358 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
359 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
360 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
361 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
362 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
363 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
364 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
365 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
366 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
367
368 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
369
370 self.RHsize = 180+20*self.nChannels
371 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
372 #print 'Datasize',self.Datasize
373 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
374
375 print '=============================================='
376 print 'RecMgcNumber ',self.RecMgcNumber
377 print 'RecCounter ',self.RecCounter
378 print 'Off2StartNxtRec ',self.Off2StartNxtRec
379 print 'Off2StartData ',self.Off2StartData
380 print 'Range Resolution ',self.SampResolution
381 print 'First Height ',self.StartRangeSamp
382 print 'PRF (Hz) ',self.PRFhz
383 print 'Heights (K) ',self.nHeights
384 print 'Channels (N) ',self.nChannels
385 print 'Profiles (J) ',self.nProfiles
386 print 'iCoh ',self.nCohInt
387 print 'iInCoh ',self.nIncohInt
388 print 'BeamAngleAzim ',self.BeamAngleAzim
389 print 'BeamAngleZen ',self.BeamAngleZen
390
391 #print 'ModoEnUso ',self.DualModeIndex
392 #print 'UtcTime ',self.nUtime
393 #print 'MiliSec ',self.nMilisec
394 #print 'Exp TagName ',self.ExpTagName
395 #print 'Exp Comment ',self.ExpComment
396 #print 'FFT Window Index ',self.FFTwindowingInd
397 #print 'N Dig. Channels ',self.nDigChannels
398 print 'Size de bloque ',self.RHsize
399 print 'DataSize ',self.Datasize
400 print 'BeamAngleAzim ',self.BeamAngleAzim
401 #print 'AntennaCoord0 ',self.AntennaCoord0
402 #print 'AntennaAngl0 ',self.AntennaAngl0
403 #print 'AntennaCoord1 ',self.AntennaCoord1
404 #print 'AntennaAngl1 ',self.AntennaAngl1
405 #print 'AntennaCoord2 ',self.AntennaCoord2
406 #print 'AntennaAngl2 ',self.AntennaAngl2
407 print 'RecPhaseCalibr0 ',self.RecPhaseCalibr0
408 print 'RecPhaseCalibr1 ',self.RecPhaseCalibr1
409 print 'RecPhaseCalibr2 ',self.RecPhaseCalibr2
410 print 'RecAmpCalibr0 ',self.RecAmpCalibr0
411 print 'RecAmpCalibr1 ',self.RecAmpCalibr1
412 print 'RecAmpCalibr2 ',self.RecAmpCalibr2
413 print 'ReceiverGaindB0 ',self.ReceiverGaindB0
414 print 'ReceiverGaindB1 ',self.ReceiverGaindB1
415 print 'ReceiverGaindB2 ',self.ReceiverGaindB2
416 print '=============================================='
417
418 if OffRHeader > endFp:
419 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp)
420 return 0
421
422 if OffRHeader < endFp:
423 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp)
424 return 0
425
426 return 1
427
428
429 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
430
431 path = None
432 startDate = None
433 endDate = None
434 startTime = None
435 endTime = None
436 walk = None
437 isConfig = False
438
439
440 fileList= None
441
442 #metadata
443 TimeZone= None
444 Interval= None
445 heightList= None
446
447 #data
448 data= None
449 utctime= None
450
451
452
453 def __init__(self, **kwargs):
454
455 #Eliminar de la base la herencia
456 ProcessingUnit.__init__(self, **kwargs)
457
458 #self.isConfig = False
459
460 #self.pts2read_SelfSpectra = 0
461 #self.pts2read_CrossSpectra = 0
462 #self.pts2read_DCchannels = 0
463 #self.datablock = None
464 self.utc = None
465 self.ext = ".fdt"
466 self.optchar = "P"
467 self.fpFile=None
468 self.fp = None
469 self.BlockCounter=0
470 self.dtype = None
471 self.fileSizeByHeader = None
472 self.filenameList = []
473 self.fileSelector = 0
474 self.Off2StartNxtRec=0
475 self.RecCounter=0
476 self.flagNoMoreFiles = 0
477 self.data_spc=None
478 self.data_cspc=None
479 self.data_output=None
480 self.path = None
481 self.OffsetStartHeader=0
482 self.Off2StartData=0
483 self.ipp = 0
484 self.nFDTdataRecors=0
485 self.blocksize = 0
486 self.dataOut = Spectra()
487 self.profileIndex = 1 #Always
488 self.dataOut.flagNoData=False
489 self.dataOut.nRdPairs = 0
490 self.dataOut.pairsList = []
491 self.dataOut.data_spc=None
492 self.dataOut.noise=[]
493 self.dataOut.velocityX=[]
494 self.dataOut.velocityY=[]
495 self.dataOut.velocityV=[]
496
497
498
499 def Files2Read(self, fp):
500 '''
501 Function that indicates the number of .fdt files that exist in the folder to be read.
502 It also creates an organized list with the names of the files to read.
503 '''
504 #self.__checkPath()
505
506 ListaData=os.listdir(fp) #Gets the list of files within the fp address
507 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
508 nFiles=0 #File Counter
509 FileList=[] #A list is created that will contain the .fdt files
510 for IndexFile in ListaData :
511 if '.fdt' in IndexFile:
512 FileList.append(IndexFile)
513 nFiles+=1
514
515 #print 'Files2Read'
516 #print 'Existen '+str(nFiles)+' archivos .fdt'
517
518 self.filenameList=FileList #List of files from least to largest by names
519
520
521 def run(self, **kwargs):
522 '''
523 This method will be the one that will initiate the data entry, will be called constantly.
524 You should first verify that your Setup () is set up and then continue to acquire
525 the data to be processed with getData ().
526 '''
527 if not self.isConfig:
528 self.setup(**kwargs)
529 self.isConfig = True
530
531 self.getData()
532 #print 'running'
533
534
535 def setup(self, path=None,
536 startDate=None,
537 endDate=None,
538 startTime=None,
539 endTime=None,
540 walk=True,
541 timezone='utc',
542 code = None,
543 online=False,
544 ReadMode=None,
545 **kwargs):
546
547 self.isConfig = True
548
549 self.path=path
550 self.startDate=startDate
551 self.endDate=endDate
552 self.startTime=startTime
553 self.endTime=endTime
554 self.walk=walk
555 self.ReadMode=int(ReadMode)
556
557 pass
558
559
560 def getData(self):
561 '''
562 Before starting this function, you should check that there is still an unread file,
563 If there are still blocks to read or if the data block is empty.
564
565 You should call the file "read".
566
567 '''
568
569 if self.flagNoMoreFiles:
570 self.dataOut.flagNoData = True
571 print 'NoData se vuelve true'
572 return 0
573
574 self.fp=self.path
575 self.Files2Read(self.fp)
576 self.readFile(self.fp)
577 self.dataOut.data_spc = self.data_spc
578 self.dataOut.data_cspc =self.data_cspc
579 self.dataOut.data_output=self.data_output
580
581 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
582
583 #self.removeDC()
584 return self.dataOut.data_spc
585
586
587 def readFile(self,fp):
588 '''
589 You must indicate if you are reading in Online or Offline mode and load the
590 The parameters for this file reading mode.
591
592 Then you must do 2 actions:
593
594 1. Get the BLTR FileHeader.
595 2. Start reading the first block.
596 '''
597
598 #The address of the folder is generated the name of the .fdt file that will be read
599 print "File: ",self.fileSelector+1
600
601 if self.fileSelector < len(self.filenameList):
602
603 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
604 #print self.fpFile
605 fheader = FileHeaderBLTR()
606 fheader.FHread(self.fpFile) #Bltr FileHeader Reading
607 self.nFDTdataRecors=fheader.nFDTdataRecors
608
609 self.readBlock() #Block reading
610 else:
611 print 'readFile FlagNoData becomes true'
612 self.flagNoMoreFiles=True
613 self.dataOut.flagNoData = True
614 return 0
615
616 def getVelRange(self, extrapoints=0):
617 Lambda= SPEED_OF_LIGHT/50000000
618 PRF = self.dataOut.PRF#1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
619 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
620 deltafreq = PRF / (self.nProfiles)
621 deltavel = (Vmax*2) / (self.nProfiles)
622 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
623 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
624 return velrange
625
626 def readBlock(self):
627 '''
628 It should be checked if the block has data, if it is not passed to the next file.
629
630 Then the following is done:
631
632 1. Read the RecordHeader
633 2. Fill the buffer with the current block number.
634
635 '''
636
637 if self.BlockCounter < self.nFDTdataRecors-2:
638 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
639 if self.ReadMode==1:
640 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1)
641 elif self.ReadMode==0:
642 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
643
644 rheader.RHread(self.fpFile) #Bltr FileHeader Reading
645
646 self.OffsetStartHeader=rheader.OffsetStartHeader
647 self.RecCounter=rheader.RecCounter
648 self.Off2StartNxtRec=rheader.Off2StartNxtRec
649 self.Off2StartData=rheader.Off2StartData
650 self.nProfiles=rheader.nProfiles
651 self.nChannels=rheader.nChannels
652 self.nHeights=rheader.nHeights
653 self.frequency=rheader.TransmitFrec
654 self.DualModeIndex=rheader.DualModeIndex
655
656 self.pairsList =[(0,1),(0,2),(1,2)]
657 self.dataOut.pairsList = self.pairsList
658
659 self.nRdPairs=len(self.dataOut.pairsList)
660 self.dataOut.nRdPairs = self.nRdPairs
661
662 self.__firstHeigth=rheader.StartRangeSamp
663 self.__deltaHeigth=rheader.SampResolution
664 self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth
665 self.dataOut.channelList = range(self.nChannels)
666 self.dataOut.nProfiles=rheader.nProfiles
667 self.dataOut.nIncohInt=rheader.nIncohInt
668 self.dataOut.nCohInt=rheader.nCohInt
669 self.dataOut.ippSeconds= 1/float(rheader.PRFhz)
670 self.dataOut.PRF=rheader.PRFhz
671 self.dataOut.nFFTPoints=rheader.nProfiles
672 self.dataOut.utctime=rheader.nUtime
673 self.dataOut.timeZone=0
674 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
675 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
676
677 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
678 print 'self.data_output', shape(self.data_output)
679 self.dataOut.velocityX=[]
680 self.dataOut.velocityY=[]
681 self.dataOut.velocityV=[]
682
683 '''Block Reading, the Block Data is received and Reshape is used to give it
684 shape.
685 '''
686
687 #Procedure to take the pointer to where the date block starts
688 startDATA = open(self.fpFile,"rb")
689 OffDATA= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec+self.Off2StartData
690 startDATA.seek(OffDATA, os.SEEK_SET)
691
692 def moving_average(x, N=2):
693 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
694
695 def gaus(xSamples,a,x0,sigma):
696 return a*exp(-(xSamples-x0)**2/(2*sigma**2))
697
698 def Find(x,value):
699 for index in range(len(x)):
700 if x[index]==value:
701 return index
702
703 def pol2cart(rho, phi):
704 x = rho * numpy.cos(phi)
705 y = rho * numpy.sin(phi)
706 return(x, y)
707
708
709
710
711 if self.DualModeIndex==self.ReadMode:
712
713 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
714
715 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
716
717 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
718
719 self.data_block = numpy.transpose(self.data_block, (1,2,0))
720
721 copy = self.data_block.copy()
722 spc = copy * numpy.conjugate(copy)
723
724 self.data_spc = numpy.absolute(spc) # valor absoluto o magnitud
725
726 factor = self.dataOut.normFactor
727
728
729 z = self.data_spc.copy()#/factor
730 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
731 #zdB = 10*numpy.log10(z)
732 print ' '
733 print 'Z: '
734 print shape(z)
735 print ' '
736 print ' '
737
738 self.dataOut.data_spc=self.data_spc
739
740 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
741 #noisedB = 10*numpy.log10(self.noise)
742
743
744 ySamples=numpy.ones([3,self.nProfiles])
745 phase=numpy.ones([3,self.nProfiles])
746 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
747 coherence=numpy.ones([3,self.nProfiles])
748 PhaseSlope=numpy.ones(3)
749 PhaseInter=numpy.ones(3)
750
751 '''****** Getting CrossSpectra ******'''
752 cspc=self.data_block.copy()
753 self.data_cspc=self.data_block.copy()
754
755 xFrec=self.getVelRange(1)
756 VelRange=self.getVelRange(1)
757 self.dataOut.VelRange=VelRange
758 #print ' '
759 #print ' '
760 #print 'xFrec',xFrec
761 #print ' '
762 #print ' '
763 #Height=35
764 for i in range(self.nRdPairs):
765
766 chan_index0 = self.dataOut.pairsList[i][0]
767 chan_index1 = self.dataOut.pairsList[i][1]
768
769 self.data_cspc[i,:,:]=cspc[chan_index0,:,:] * numpy.conjugate(cspc[chan_index1,:,:])
770
771
772 '''Getting Eij and Nij'''
773 (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
774 (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
775 (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
776
777 E01=AntennaX0-AntennaX1
778 N01=AntennaY0-AntennaY1
779
780 E02=AntennaX0-AntennaX2
781 N02=AntennaY0-AntennaY2
782
783 E12=AntennaX1-AntennaX2
784 N12=AntennaY1-AntennaY2
785
786 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
787
788 self.dataOut.ChanDist = self.ChanDist
789
790
791 # for Height in range(self.nHeights):
792 #
793 # for i in range(self.nRdPairs):
794 #
795 # '''****** Line of Data SPC ******'''
796 # zline=z[i,:,Height]
797 #
798 # '''****** DC is removed ******'''
799 # DC=Find(zline,numpy.amax(zline))
800 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
801 #
802 #
803 # '''****** SPC is normalized ******'''
804 # FactNorm= zline.copy() / numpy.sum(zline.copy())
805 # FactNorm= FactNorm/numpy.sum(FactNorm)
806 #
807 # SmoothSPC=moving_average(FactNorm,N=3)
808 #
809 # xSamples = ar(range(len(SmoothSPC)))
810 # ySamples[i] = SmoothSPC-self.noise[i]
811 #
812 # for i in range(self.nRdPairs):
813 #
814 # '''****** Line of Data CSPC ******'''
815 # cspcLine=self.data_cspc[i,:,Height].copy()
816 #
817 #
818 #
819 # '''****** CSPC is normalized ******'''
820 # chan_index0 = self.dataOut.pairsList[i][0]
821 # chan_index1 = self.dataOut.pairsList[i][1]
822 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
823 #
824 #
825 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
826 #
827 #
828 # CSPCSamples[i] = CSPCNorm-self.noise[i]
829 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
830 #
831 # '''****** DC is removed ******'''
832 # DC=Find(coherence[i],numpy.amax(coherence[i]))
833 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
834 # coherence[i]= moving_average(coherence[i],N=2)
835 #
836 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
837 #
838 #
839 # '''****** Getting fij width ******'''
840 #
841 # yMean=[]
842 # yMean2=[]
843 #
844 # for j in range(len(ySamples[1])):
845 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
846 #
847 # '''******* Getting fitting Gaussian ******'''
848 # meanGauss=sum(xSamples*yMean) / len(xSamples)
849 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
850 # #print 'Height',Height,'SNR', meanGauss/sigma**2
851 #
852 # if (abs(meanGauss/sigma**2) > 0.0001) :
853 #
854 # try:
855 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
856 #
857 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
858 # FitGauss=gaus(xSamples,*popt)
859 #
860 # else:
861 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
862 # print 'Verificador: Dentro', Height
863 # except RuntimeError:
864 #
865 # try:
866 # for j in range(len(ySamples[1])):
867 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
868 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
869 # FitGauss=gaus(xSamples,*popt)
870 # print 'Verificador: Exepcion1', Height
871 # except RuntimeError:
872 #
873 # try:
874 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
875 # FitGauss=gaus(xSamples,*popt)
876 # print 'Verificador: Exepcion2', Height
877 # except RuntimeError:
878 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
879 # print 'Verificador: Exepcion3', Height
880 # else:
881 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
882 # #print 'Verificador: Fuera', Height
883 #
884 #
885 #
886 # Maximun=numpy.amax(yMean)
887 # eMinus1=Maximun*numpy.exp(-1)
888 #
889 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
890 # HalfWidth= xFrec[HWpos]
891 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
892 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
893 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
894 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
895 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
896 # '''****** Getting Fij ******'''
897 #
898 # GaussCenter=xFrec[GCpos]
899 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
900 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
901 # else:
902 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
903 #
904 # '''****** Getting Frecuency range of significant data ******'''
905 #
906 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
907 #
908 # if Rangpos<GCpos:
909 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
910 # else:
911 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
912 #
913 # FrecRange=xFrec[Range[0]:Range[1]]
914 #
915 # #print 'FrecRange', FrecRange
916 # '''****** Getting SCPC Slope ******'''
917 #
918 # for i in range(self.nRdPairs):
919 #
920 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
921 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
922 #
923 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
924 # PhaseSlope[i]=slope
925 # PhaseInter[i]=intercept
926 # else:
927 # PhaseSlope[i]=0
928 # PhaseInter[i]=0
929 #
930 # # plt.figure(i+15)
931 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
932 # # plt.xlabel('Frecuencia (KHz)')
933 # # plt.ylabel('Magnitud')
934 # # #plt.subplot(311+i)
935 # # plt.plot(FrecRange,PhaseRange,'b')
936 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
937 #
938 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
939 #
940 #
941 # '''Getting constant C'''
942 # cC=(Fij*numpy.pi)**2
943 #
944 # # '''Getting Eij and Nij'''
945 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
946 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
947 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
948 # #
949 # # E01=AntennaX0-AntennaX1
950 # # N01=AntennaY0-AntennaY1
951 # #
952 # # E02=AntennaX0-AntennaX2
953 # # N02=AntennaY0-AntennaY2
954 # #
955 # # E12=AntennaX1-AntennaX2
956 # # N12=AntennaY1-AntennaY2
957 #
958 # '''****** Getting constants F and G ******'''
959 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
960 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
961 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
962 # MijResults=numpy.array([MijResult0,MijResult1])
963 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
964 #
965 # '''****** Getting constants A, B and H ******'''
966 # W01=numpy.amax(coherence[0])
967 # W02=numpy.amax(coherence[1])
968 # W12=numpy.amax(coherence[2])
969 #
970 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
971 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
972 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
973 #
974 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
975 #
976 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
977 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
978 #
979 # VxVy=numpy.array([[cA,cH],[cH,cB]])
980 #
981 # VxVyResults=numpy.array([-cF,-cG])
982 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
983 # Vzon = Vy
984 # Vmer = Vx
985 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
986 # Vang=numpy.arctan2(Vmer,Vzon)
987 #
988 # if abs(Vy)<100 and abs(Vy)> 0.:
989 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
990 # #print 'Vmag',Vmag
991 # else:
992 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
993 #
994 # if abs(Vx)<100 and abs(Vx) > 0.:
995 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
996 # #print 'Vang',Vang
997 # else:
998 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
999 #
1000 # if abs(GaussCenter)<2:
1001 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1002 #
1003 # else:
1004 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1005 #
1006 #
1007 # # print '********************************************'
1008 # # print 'HalfWidth ', HalfWidth
1009 # # print 'Maximun ', Maximun
1010 # # print 'eMinus1 ', eMinus1
1011 # # print 'Rangpos ', Rangpos
1012 # # print 'GaussCenter ',GaussCenter
1013 # # print 'E01 ',E01
1014 # # print 'N01 ',N01
1015 # # print 'E02 ',E02
1016 # # print 'N02 ',N02
1017 # # print 'E12 ',E12
1018 # # print 'N12 ',N12
1019 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1020 # # print 'Fij ', Fij
1021 # # print 'cC ', cC
1022 # # print 'cF ', cF
1023 # # print 'cG ', cG
1024 # # print 'cA ', cA
1025 # # print 'cB ', cB
1026 # # print 'cH ', cH
1027 # # print 'Vx ', Vx
1028 # # print 'Vy ', Vy
1029 # # print 'Vmag ', Vmag
1030 # # print 'Vang ', Vang*180/numpy.pi
1031 # # print 'PhaseSlope ',PhaseSlope[0]
1032 # # print 'PhaseSlope ',PhaseSlope[1]
1033 # # print 'PhaseSlope ',PhaseSlope[2]
1034 # # print '********************************************'
1035 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1036 #
1037 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1038 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1039 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1040 #
1041 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1042 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1043 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1044 #
1045 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1046 # print ' '
1047 # print 'VmagAverage',numpy.mean(prin)
1048 # print ' '
1049 # # plt.figure(5)
1050 # # plt.subplot(211)
1051 # # plt.plot(self.dataOut.velocityX,'yo:')
1052 # # plt.subplot(212)
1053 # # plt.plot(self.dataOut.velocityY,'yo:')
1054 #
1055 # # plt.figure(1)
1056 # # # plt.subplot(121)
1057 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1058 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1059 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1060 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1061 # # # plt.legend()
1062 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1063 # #
1064 # # plt.xlabel('Frecuencia (KHz)')
1065 # # plt.ylabel('Magnitud')
1066 # # # plt.subplot(122)
1067 # # # plt.title('Fit for Time Constant')
1068 # # #plt.plot(xFrec,zline)
1069 # # #plt.plot(xFrec,SmoothSPC,'g')
1070 # # plt.plot(xFrec,FactNorm)
1071 # # plt.axis([-4, 4, 0, 0.15])
1072 # # # plt.xlabel('SelfSpectra KHz')
1073 # #
1074 # # plt.figure(10)
1075 # # # plt.subplot(121)
1076 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1077 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1078 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1079 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1080 # # plt.legend()
1081 # # plt.title('SELFSPECTRA EN CANALES')
1082 # #
1083 # # plt.xlabel('Frecuencia (KHz)')
1084 # # plt.ylabel('Magnitud')
1085 # # # plt.subplot(122)
1086 # # # plt.title('Fit for Time Constant')
1087 # # #plt.plot(xFrec,zline)
1088 # # #plt.plot(xFrec,SmoothSPC,'g')
1089 # # # plt.plot(xFrec,FactNorm)
1090 # # # plt.axis([-4, 4, 0, 0.15])
1091 # # # plt.xlabel('SelfSpectra KHz')
1092 # #
1093 # # plt.figure(9)
1094 # #
1095 # #
1096 # # plt.title('DATOS SUAVIZADOS')
1097 # # plt.xlabel('Frecuencia (KHz)')
1098 # # plt.ylabel('Magnitud')
1099 # # plt.plot(xFrec,SmoothSPC,'g')
1100 # #
1101 # # #plt.plot(xFrec,FactNorm)
1102 # # plt.axis([-4, 4, 0, 0.15])
1103 # # # plt.xlabel('SelfSpectra KHz')
1104 # # #
1105 # # plt.figure(2)
1106 # # # #plt.subplot(121)
1107 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1108 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1109 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1110 # # # #plt.plot(xFrec,phase)
1111 # # # plt.xlabel('Suavizado, promediado KHz')
1112 # # plt.title('SELFSPECTRA PROMEDIADO')
1113 # # # #plt.subplot(122)
1114 # # # #plt.plot(xSamples,zline)
1115 # # plt.xlabel('Frecuencia (KHz)')
1116 # # plt.ylabel('Magnitud')
1117 # # plt.legend()
1118 # # #
1119 # # # plt.figure(3)
1120 # # # plt.subplot(311)
1121 # # # #plt.plot(xFrec,phase[0])
1122 # # # plt.plot(xFrec,phase[0],'g')
1123 # # # plt.subplot(312)
1124 # # # plt.plot(xFrec,phase[1],'g')
1125 # # # plt.subplot(313)
1126 # # # plt.plot(xFrec,phase[2],'g')
1127 # # # #plt.plot(xFrec,phase[2])
1128 # # #
1129 # # # plt.figure(4)
1130 # # #
1131 # # # plt.plot(xSamples,coherence[0],'b')
1132 # # # plt.plot(xSamples,coherence[1],'r')
1133 # # # plt.plot(xSamples,coherence[2],'g')
1134 # # plt.show()
1135 # # #
1136 # # # plt.clf()
1137 # # # plt.cla()
1138 # # # plt.close()
1139 #
1140 # print ' '
1141
1142
1143
1144 self.BlockCounter+=2
1145
1146 else:
1147 self.fileSelector+=1
1148 self.BlockCounter=0
1149 print "Next File"
1150
1151
1152
1153
1154
@@ -0,0 +1,243
1 '''
2 Created on Aug 1, 2017
3
4 @author: Juan C. Espinoza
5 '''
6
7 import os
8 import sys
9 import time
10 import json
11 import datetime
12
13 import numpy
14
15 try:
16 import madrigal
17 import madrigal.cedar
18 except:
19 print 'You should install "madrigal library" module if you want to read/write Madrigal data'
20
21 from schainpy.model.proc.jroproc_base import Operation
22 from schainpy.model.data.jrodata import Parameters
23
24 MISSING = -32767
25 DEF_CATALOG = {
26 'principleInvestigator': 'Marco Milla',
27 'expPurpose': None,
28 'expMode': None,
29 'cycleTime': None,
30 'correlativeExp': None,
31 'sciRemarks': None,
32 'instRemarks': None
33 }
34 DEF_HEADER = {
35 'kindatDesc': None,
36 'analyst': 'Jicamarca User',
37 'comments': None,
38 'history': None
39 }
40 MNEMONICS = {
41 10: 'jro',
42 11: 'jbr',
43 840: 'jul',
44 13: 'jas',
45 1000: 'pbr',
46 1001: 'hbr',
47 1002: 'obr',
48 }
49
50 def load_json(obj):
51 '''
52 Parse json as string instead of unicode
53 '''
54
55 if isinstance(obj, str):
56 obj = json.loads(obj)
57
58 return {str(k): load_json(v) if isinstance(v, dict) else str(v) if isinstance(v, unicode) else v
59 for k, v in obj.items()}
60
61
62 class MAD2Writer(Operation):
63
64 def __init__(self, **kwargs):
65
66 Operation.__init__(self, **kwargs)
67 self.dataOut = Parameters()
68 self.path = None
69 self.dataOut = None
70 self.ext = '.dat'
71
72 return
73
74 def run(self, dataOut, path, oneDList, twoDParam='', twoDList='{}', metadata='{}', **kwargs):
75 '''
76 Inputs:
77 path - path where files will be created
78 oneDList - json of one-dimensional parameters in record where keys
79 are Madrigal codes (integers or mnemonics) and values the corresponding
80 dataOut attribute e.g: {
81 'gdlatr': 'lat',
82 'gdlonr': 'lon',
83 'gdlat2':'lat',
84 'glon2':'lon'}
85 twoDParam - independent parameter to get the number of rows e.g:
86 heighList
87 twoDList - json of two-dimensional parameters in record where keys
88 are Madrigal codes (integers or mnemonics) and values the corresponding
89 dataOut attribute if multidimensional array specify as tupple
90 ('attr', pos) e.g: {
91 'gdalt': 'heightList',
92 'vn1p2': ('data_output', 0),
93 'vn2p2': ('data_output', 1),
94 'vn3': ('data_output', 2),
95 'snl': ('data_SNR', 'db')
96 }
97 metadata - json of madrigal metadata (kinst, kindat, catalog and header)
98 '''
99 if not self.isConfig:
100 self.setup(dataOut, path, oneDList, twoDParam, twoDList, metadata, **kwargs)
101 self.isConfig = True
102
103 self.putData()
104 return
105
106 def setup(self, dataOut, path, oneDList, twoDParam, twoDList, metadata, **kwargs):
107 '''
108 Configure Operation
109 '''
110
111 self.dataOut = dataOut
112 self.nmodes = self.dataOut.nmodes
113 self.path = path
114 self.blocks = kwargs.get('blocks', None)
115 self.counter = 0
116 self.oneDList = load_json(oneDList)
117 self.twoDList = load_json(twoDList)
118 self.twoDParam = twoDParam
119 meta = load_json(metadata)
120 self.kinst = meta.get('kinst')
121 self.kindat = meta.get('kindat')
122 self.catalog = meta.get('catalog', DEF_CATALOG)
123 self.header = meta.get('header', DEF_HEADER)
124
125 return
126
127 def setFile(self):
128 '''
129 Create new cedar file object
130 '''
131
132 self.mnemonic = MNEMONICS[self.kinst] #TODO get mnemonic from madrigal
133 date = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
134
135 filename = '%s%s_%s%s' % (self.mnemonic,
136 date.strftime('%Y%m%d_%H%M%S'),
137 self.dataOut.mode,
138 self.ext)
139
140 self.fullname = os.path.join(self.path, filename)
141
142 if os.path.isfile(self.fullname) :
143 print "Destination path '%s' already exists. Previous file deleted. " %self.fullname
144 os.remove(self.fullname)
145
146 try:
147 print '[Writing] creating file : %s' % (self.fullname)
148 self.cedarObj = madrigal.cedar.MadrigalCedarFile(self.fullname, True)
149 except ValueError, e:
150 print '[Error]: Impossible to create a cedar object with "madrigal.cedar.MadrigalCedarFile" '
151 return
152
153 return 1
154
155 def writeBlock(self):
156 '''
157 Add data records to cedar file taking data from oneDList and twoDList
158 attributes.
159 Allowed parameters in: parcodes.tab
160 '''
161
162 startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
163 endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval)
164 nrows = len(getattr(self.dataOut, self.twoDParam))
165
166 rec = madrigal.cedar.MadrigalDataRecord(
167 self.kinst,
168 self.kindat,
169 startTime.year,
170 startTime.month,
171 startTime.day,
172 startTime.hour,
173 startTime.minute,
174 startTime.second,
175 startTime.microsecond/10000,
176 endTime.year,
177 endTime.month,
178 endTime.day,
179 endTime.hour,
180 endTime.minute,
181 endTime.second,
182 endTime.microsecond/10000,
183 self.oneDList.keys(),
184 self.twoDList.keys(),
185 nrows
186 )
187
188 # Setting 1d values
189 for key in self.oneDList:
190 rec.set1D(key, getattr(self.dataOut, self.oneDList[key]))
191
192 # Setting 2d values
193 invalid = numpy.isnan(self.dataOut.data_output)
194 self.dataOut.data_output[invalid] = MISSING
195 out = {}
196 for key, value in self.twoDList.items():
197 if isinstance(value, str):
198 out[key] = getattr(self.dataOut, value)
199 elif isinstance(value, tuple):
200 attr, x = value
201 if isinstance(x, (int, float)):
202 out[key] = getattr(self.dataOut, attr)[int(x)]
203 elif x.lower()=='db':
204 tmp = getattr(self.dataOut, attr)
205 SNRavg = numpy.average(tmp, axis=0)
206 out[key] = 10*numpy.log10(SNRavg)
207
208 for n in range(nrows):
209 for key in out:
210 rec.set2D(key, n, out[key][n])
211
212 self.cedarObj.append(rec)
213 self.cedarObj.dump()
214 print '[Writing] Record No. {} (mode {}).'.format(
215 self.counter,
216 self.dataOut.mode
217 )
218
219 def setHeader(self):
220 '''
221 Create an add catalog and header to cedar file
222 '''
223
224 header = madrigal.cedar.CatalogHeaderCreator(self.fullname)
225 header.createCatalog(**self.catalog)
226 header.createHeader(**self.header)
227 header.write()
228
229 def putData(self):
230
231 if self.dataOut.flagNoData:
232 return 0
233
234 if self.counter == 0:
235 self.setFile()
236
237 if self.counter <= self.dataOut.nrecords:
238 self.writeBlock()
239 self.counter += 1
240
241 if self.counter == self.dataOut.nrecords or self.counter == self.blocks:
242 self.setHeader()
243 self.counter = 0
This diff has been collapsed as it changes many lines, (803 lines changed) Show them Hide them
@@ -0,0 +1,803
1 import os, sys
2 import glob
3 import fnmatch
4 import datetime
5 import time
6 import re
7 import h5py
8 import numpy
9 import matplotlib.pyplot as plt
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
14 from scipy import stats
15
16 from numpy.ma.core import getdata
17
18 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
20
21 try:
22 from gevent import sleep
23 except:
24 from time import sleep
25
26 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN, empty
31
32
33
34 class Header(object):
35
36 def __init__(self):
37 raise NotImplementedError
38
39
40 def read(self):
41
42 raise NotImplementedError
43
44 def write(self):
45
46 raise NotImplementedError
47
48 def printInfo(self):
49
50 message = "#"*50 + "\n"
51 message += self.__class__.__name__.upper() + "\n"
52 message += "#"*50 + "\n"
53
54 keyList = self.__dict__.keys()
55 keyList.sort()
56
57 for key in keyList:
58 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
59
60 if "size" not in keyList:
61 attr = getattr(self, "size")
62
63 if attr:
64 message += "%s = %s" %("size", attr) + "\n"
65
66 #print message
67
68
69 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
70 ('Hname','a32'), #Original file name
71 ('Htime',numpy.str_,32), #Date and time when the file was created
72 ('Hoper',numpy.str_,64), #Name of operator who created the file
73 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
74 ('Hdescr',numpy.str_,256), #Description of measurements
75 ('Hdummy',numpy.str_,512), #Reserved space
76 #Main chunk 8bytes
77 ('Msign',numpy.str_,4), #Main chunk signature FZKF or NUIG
78 ('MsizeData','<i4'), #Size of data block main chunk
79 #Processing DSP parameters 36bytes
80 ('PPARsign',numpy.str_,4), #PPAR signature
81 ('PPARsize','<i4'), #PPAR size of block
82 ('PPARprf','<i4'), #Pulse repetition frequency
83 ('PPARpdr','<i4'), #Pulse duration
84 ('PPARsft','<i4'), #FFT length
85 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
86 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
87 ('PPARchg','<i4'), #Count for gates for moment estimation
88 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
89 #Service DSP parameters 112bytes
90 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
91 ('SPARtx','<i4'), #OBSOLETE
92 ('SPARaddGain0','<f4'), #OBSOLETE
93 ('SPARaddGain1','<f4'), #OBSOLETE
94 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
95 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
96 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
97 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
98 ('SPARcal','<i4'), #OBSOLETE
99 ('SPARnos','<i4'), #OBSOLETE
100 ('SPARof0','<i4'), #detection threshold
101 ('SPARof1','<i4'), #OBSOLETE
102 ('SPARswt','<i4'), #2nd moment estimation threshold
103 ('SPARsum','<i4'), #OBSOLETE
104 ('SPARosc','<i4'), #flag Oscillosgram mode
105 ('SPARtst','<i4'), #OBSOLETE
106 ('SPARcor','<i4'), #OBSOLETE
107 ('SPARofs','<i4'), #OBSOLETE
108 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
109 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
110 ('SPARcalibPow_M','<f4'), #OBSOLETE
111 ('SPARcalibSNR_M','<f4'), #OBSOLETE
112 ('SPARcalibPow_S','<f4'), #OBSOLETE
113 ('SPARcalibSNR_S','<f4'), #OBSOLETE
114 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
115 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
116 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
117 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
118
119
120
121 class FileHeaderMIRA35c(Header):
122
123 def __init__(self):
124
125 self.Hname= None
126 self.Htime= None
127 self.Hoper= None
128 self.Hplace= None
129 self.Hdescr= None
130 self.Hdummy= None
131
132 self.Msign=None
133 self.MsizeData=None
134
135 self.PPARsign=None
136 self.PPARsize=None
137 self.PPARprf=None
138 self.PPARpdr=None
139 self.PPARsft=None
140 self.PPARavc=None
141 self.PPARihp=None
142 self.PPARchg=None
143 self.PPARpol=None
144 #Service DSP parameters
145 self.SPARatt=None
146 self.SPARtx=None
147 self.SPARaddGain0=None
148 self.SPARaddGain1=None
149 self.SPARwnd=None
150 self.SPARpos=None
151 self.SPARadd=None
152 self.SPARlen=None
153 self.SPARcal=None
154 self.SPARnos=None
155 self.SPARof0=None
156 self.SPARof1=None
157 self.SPARswt=None
158 self.SPARsum=None
159 self.SPARosc=None
160 self.SPARtst=None
161 self.SPARcor=None
162 self.SPARofs=None
163 self.SPARhsn=None
164 self.SPARhsa=None
165 self.SPARcalibPow_M=None
166 self.SPARcalibSNR_M=None
167 self.SPARcalibPow_S=None
168 self.SPARcalibSNR_S=None
169 self.SPARrawGate1=None
170 self.SPARrawGate2=None
171 self.SPARraw=None
172 self.SPARprc=None
173
174 self.FHsize=1180
175
176 def FHread(self, fp):
177
178 header = numpy.fromfile(fp, FILE_HEADER,1)
179 ''' numpy.fromfile(file, dtype, count, sep='')
180 file : file or str
181 Open file object or filename.
182
183 dtype : data-type
184 Data type of the returned array. For binary files, it is used to determine
185 the size and byte-order of the items in the file.
186
187 count : int
188 Number of items to read. -1 means all items (i.e., the complete file).
189
190 sep : str
191 Separator between items if file is a text file. Empty ("") separator means
192 the file should be treated as binary. Spaces (" ") in the separator match zero
193 or more whitespace characters. A separator consisting only of spaces must match
194 at least one whitespace.
195
196 '''
197
198
199 self.Hname= str(header['Hname'][0])
200 self.Htime= str(header['Htime'][0])
201 self.Hoper= str(header['Hoper'][0])
202 self.Hplace= str(header['Hplace'][0])
203 self.Hdescr= str(header['Hdescr'][0])
204 self.Hdummy= str(header['Hdummy'][0])
205 #1024
206
207 self.Msign=str(header['Msign'][0])
208 self.MsizeData=header['MsizeData'][0]
209 #8
210
211 self.PPARsign=str(header['PPARsign'][0])
212 self.PPARsize=header['PPARsize'][0]
213 self.PPARprf=header['PPARprf'][0]
214 self.PPARpdr=header['PPARpdr'][0]
215 self.PPARsft=header['PPARsft'][0]
216 self.PPARavc=header['PPARavc'][0]
217 self.PPARihp=header['PPARihp'][0]
218 self.PPARchg=header['PPARchg'][0]
219 self.PPARpol=header['PPARpol'][0]
220 #Service DSP parameters
221 #36
222
223 self.SPARatt=header['SPARatt'][0]
224 self.SPARtx=header['SPARtx'][0]
225 self.SPARaddGain0=header['SPARaddGain0'][0]
226 self.SPARaddGain1=header['SPARaddGain1'][0]
227 self.SPARwnd=header['SPARwnd'][0]
228 self.SPARpos=header['SPARpos'][0]
229 self.SPARadd=header['SPARadd'][0]
230 self.SPARlen=header['SPARlen'][0]
231 self.SPARcal=header['SPARcal'][0]
232 self.SPARnos=header['SPARnos'][0]
233 self.SPARof0=header['SPARof0'][0]
234 self.SPARof1=header['SPARof1'][0]
235 self.SPARswt=header['SPARswt'][0]
236 self.SPARsum=header['SPARsum'][0]
237 self.SPARosc=header['SPARosc'][0]
238 self.SPARtst=header['SPARtst'][0]
239 self.SPARcor=header['SPARcor'][0]
240 self.SPARofs=header['SPARofs'][0]
241 self.SPARhsn=header['SPARhsn'][0]
242 self.SPARhsa=header['SPARhsa'][0]
243 self.SPARcalibPow_M=header['SPARcalibPow_M'][0]
244 self.SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
245 self.SPARcalibPow_S=header['SPARcalibPow_S'][0]
246 self.SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
247 self.SPARrawGate1=header['SPARrawGate1'][0]
248 self.SPARrawGate2=header['SPARrawGate2'][0]
249 self.SPARraw=header['SPARraw'][0]
250 self.SPARprc=header['SPARprc'][0]
251 #112
252 #1180
253 #print 'Pointer fp header', fp.tell()
254 #print ' '
255 #print 'SPARrawGate'
256 #print self.SPARrawGate2 - self.SPARrawGate1
257
258 #print ' '
259 #print 'Hname'
260 #print self.Hname
261
262 #print ' '
263 #print 'Msign'
264 #print self.Msign
265
266 def write(self, fp):
267
268 headerTuple = (self.Hname,
269 self.Htime,
270 self.Hoper,
271 self.Hplace,
272 self.Hdescr,
273 self.Hdummy)
274
275
276 header = numpy.array(headerTuple, FILE_HEADER)
277 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
278 header.tofile(fp)
279 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
280
281 fid : file or str
282 An open file object, or a string containing a filename.
283
284 sep : str
285 Separator between array items for text output. If "" (empty), a binary file is written,
286 equivalent to file.write(a.tobytes()).
287
288 format : str
289 Format string for text file output. Each entry in the array is formatted to text by
290 first converting it to the closest Python type, and then using "format" % item.
291
292 '''
293
294 return 1
295
296 SRVI_HEADER = numpy.dtype([
297 ('SignatureSRVI1',numpy.str_,4),#
298 ('SizeOfDataBlock1','<i4'),#
299 ('DataBlockTitleSRVI1',numpy.str_,4),#
300 ('SizeOfSRVI1','<i4'),])#
301
302 class SRVIHeader(Header):
303 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
304
305 self.SignatureSRVI1 = SignatureSRVI1
306 self.SizeOfDataBlock1 = SizeOfDataBlock1
307 self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
308 self.SizeOfSRVI1 = SizeOfSRVI1
309
310 self.SRVIHsize=16
311
312 def SRVIread(self, fp):
313
314 header = numpy.fromfile(fp, SRVI_HEADER,1)
315
316 self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
317 self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
318 self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
319 self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
320 #16
321 print 'Pointer fp SRVIheader', fp.tell()
322
323
324 SRVI_STRUCTURE = numpy.dtype([
325 ('frame_cnt','<u4'),#
326 ('time_t','<u4'), #
327 ('tpow','<f4'), #
328 ('npw1','<f4'), #
329 ('npw2','<f4'), #
330 ('cpw1','<f4'), #
331 ('pcw2','<f4'), #
332 ('ps_err','<u4'), #
333 ('te_err','<u4'), #
334 ('rc_err','<u4'), #
335 ('grs1','<u4'), #
336 ('grs2','<u4'), #
337 ('azipos','<f4'), #
338 ('azivel','<f4'), #
339 ('elvpos','<f4'), #
340 ('elvvel','<f4'), #
341 ('northAngle','<f4'), #
342 ('microsec','<u4'), #
343 ('azisetvel','<f4'), #
344 ('elvsetpos','<f4'), #
345 ('RadarConst','<f4'),]) #
346
347
348
349
350 class RecordHeader(Header):
351
352
353 def __init__(self, frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
354 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
355 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
356 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 , RecCounter=0, Off2StartNxtRec=0):
357
358
359 self.frame_cnt = frame_cnt
360 self.dwell = time_t
361 self.tpow = tpow
362 self.npw1 = npw1
363 self.npw2 = npw2
364 self.cpw1 = cpw1
365 self.pcw2 = pcw2
366 self.ps_err = ps_err
367 self.te_err = te_err
368 self.rc_err = rc_err
369 self.grs1 = grs1
370 self.grs2 = grs2
371 self.azipos = azipos
372 self.azivel = azivel
373 self.elvpos = elvpos
374 self.elvvel = elvvel
375 self.northAngle = northangle
376 self.microsec = microsec
377 self.azisetvel = azisetvel
378 self.elvsetpos = elvsetpos
379 self.RadarConst = RadarConst
380 self.RHsize=84
381 self.RecCounter = RecCounter
382 self.Off2StartNxtRec=Off2StartNxtRec
383
384 def RHread(self, fp):
385
386 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
387
388 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
389 #startFp.seek(OffRHeader, os.SEEK_SET)
390
391 #print 'Posicion del bloque: ',OffRHeader
392
393 header = numpy.fromfile(fp,SRVI_STRUCTURE,1)
394
395 self.frame_cnt = header['frame_cnt'][0]#
396 self.time_t = header['time_t'][0] #
397 self.tpow = header['tpow'][0] #
398 self.npw1 = header['npw1'][0] #
399 self.npw2 = header['npw2'][0] #
400 self.cpw1 = header['cpw1'][0] #
401 self.pcw2 = header['pcw2'][0] #
402 self.ps_err = header['ps_err'][0] #
403 self.te_err = header['te_err'][0] #
404 self.rc_err = header['rc_err'][0] #
405 self.grs1 = header['grs1'][0] #
406 self.grs2 = header['grs2'][0] #
407 self.azipos = header['azipos'][0] #
408 self.azivel = header['azivel'][0] #
409 self.elvpos = header['elvpos'][0] #
410 self.elvvel = header['elvvel'][0] #
411 self.northAngle = header['northAngle'][0] #
412 self.microsec = header['microsec'][0] #
413 self.azisetvel = header['azisetvel'][0] #
414 self.elvsetpos = header['elvsetpos'][0] #
415 self.RadarConst = header['RadarConst'][0] #
416 #84
417
418 #print 'Pointer fp RECheader', fp.tell()
419
420 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
421
422 #self.RHsize = 180+20*self.nChannels
423 #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
424 #print 'Datasize',self.Datasize
425 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
426
427 print '=============================================='
428
429 print '=============================================='
430
431
432 return 1
433
434 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
435
436 path = None
437 startDate = None
438 endDate = None
439 startTime = None
440 endTime = None
441 walk = None
442 isConfig = False
443
444
445 fileList= None
446
447 #metadata
448 TimeZone= None
449 Interval= None
450 heightList= None
451
452 #data
453 data= None
454 utctime= None
455
456
457
458 def __init__(self, **kwargs):
459
460 #Eliminar de la base la herencia
461 ProcessingUnit.__init__(self, **kwargs)
462 self.PointerReader = 0
463 self.FileHeaderFlag = False
464 self.utc = None
465 self.ext = ".zspca"
466 self.optchar = "P"
467 self.fpFile=None
468 self.fp = None
469 self.BlockCounter=0
470 self.dtype = None
471 self.fileSizeByHeader = None
472 self.filenameList = []
473 self.fileSelector = 0
474 self.Off2StartNxtRec=0
475 self.RecCounter=0
476 self.flagNoMoreFiles = 0
477 self.data_spc=None
478 #self.data_cspc=None
479 self.data_output=None
480 self.path = None
481 self.OffsetStartHeader=0
482 self.Off2StartData=0
483 self.ipp = 0
484 self.nFDTdataRecors=0
485 self.blocksize = 0
486 self.dataOut = Spectra()
487 self.profileIndex = 1 #Always
488 self.dataOut.flagNoData=False
489 self.dataOut.nRdPairs = 0
490 self.dataOut.pairsList = []
491 self.dataOut.data_spc=None
492
493 self.dataOut.normFactor=1
494 self.nextfileflag = True
495 self.dataOut.RadarConst = 0
496 self.dataOut.HSDV = []
497 self.dataOut.NPW = []
498 self.dataOut.COFA = []
499 self.dataOut.noise = 0
500
501
502 def Files2Read(self, fp):
503 '''
504 Function that indicates the number of .fdt files that exist in the folder to be read.
505 It also creates an organized list with the names of the files to read.
506 '''
507 #self.__checkPath()
508
509 ListaData=os.listdir(fp) #Gets the list of files within the fp address
510 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
511 nFiles=0 #File Counter
512 FileList=[] #A list is created that will contain the .fdt files
513 for IndexFile in ListaData :
514 if '.zspca' in IndexFile and '.gz' not in IndexFile:
515 FileList.append(IndexFile)
516 nFiles+=1
517
518 #print 'Files2Read'
519 #print 'Existen '+str(nFiles)+' archivos .fdt'
520
521 self.filenameList=FileList #List of files from least to largest by names
522
523
524 def run(self, **kwargs):
525 '''
526 This method will be the one that will initiate the data entry, will be called constantly.
527 You should first verify that your Setup () is set up and then continue to acquire
528 the data to be processed with getData ().
529 '''
530 if not self.isConfig:
531 self.setup(**kwargs)
532 self.isConfig = True
533
534 self.getData()
535
536
537 def setup(self, path=None,
538 startDate=None,
539 endDate=None,
540 startTime=None,
541 endTime=None,
542 walk=True,
543 timezone='utc',
544 code = None,
545 online=False,
546 ReadMode=None, **kwargs):
547
548 self.isConfig = True
549
550 self.path=path
551 self.startDate=startDate
552 self.endDate=endDate
553 self.startTime=startTime
554 self.endTime=endTime
555 self.walk=walk
556 #self.ReadMode=int(ReadMode)
557
558 pass
559
560
561 def getData(self):
562 '''
563 Before starting this function, you should check that there is still an unread file,
564 If there are still blocks to read or if the data block is empty.
565
566 You should call the file "read".
567
568 '''
569
570 if self.flagNoMoreFiles:
571 self.dataOut.flagNoData = True
572 print 'NoData se vuelve true'
573 return 0
574
575 self.fp=self.path
576 self.Files2Read(self.fp)
577 self.readFile(self.fp)
578
579 self.dataOut.data_spc = self.dataOut_spc#self.data_spc.copy()
580 self.dataOut.RadarConst = self.RadarConst
581 self.dataOut.data_output=self.data_output
582 self.dataOut.noise = self.dataOut.getNoise()
583 #print 'ACAAAAAA', self.dataOut.noise
584 self.dataOut.data_spc = self.dataOut.data_spc+self.dataOut.noise
585 #print 'self.dataOut.noise',self.dataOut.noise
586
587
588 return self.dataOut.data_spc
589
590
591 def readFile(self,fp):
592 '''
593 You must indicate if you are reading in Online or Offline mode and load the
594 The parameters for this file reading mode.
595
596 Then you must do 2 actions:
597
598 1. Get the BLTR FileHeader.
599 2. Start reading the first block.
600 '''
601
602 #The address of the folder is generated the name of the .fdt file that will be read
603 print "File: ",self.fileSelector+1
604
605 if self.fileSelector < len(self.filenameList):
606
607 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
608
609 if self.nextfileflag==True:
610 self.fp = open(self.fpFile,"rb")
611 self.nextfileflag==False
612
613 '''HERE STARTING THE FILE READING'''
614
615
616 self.fheader = FileHeaderMIRA35c()
617 self.fheader.FHread(self.fp) #Bltr FileHeader Reading
618
619
620 self.SPARrawGate1 = self.fheader.SPARrawGate1
621 self.SPARrawGate2 = self.fheader.SPARrawGate2
622 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
623 self.Num_Bins = self.fheader.PPARsft
624 self.dataOut.nFFTPoints = self.fheader.PPARsft
625
626
627 self.Num_inCoh = self.fheader.PPARavc
628 self.dataOut.PRF = self.fheader.PPARprf
629 self.dataOut.frequency = 34.85*10**9
630 self.Lambda = SPEED_OF_LIGHT/self.dataOut.frequency
631 self.dataOut.ippSeconds= 1./float(self.dataOut.PRF)
632
633 pulse_width = self.fheader.PPARpdr * 10**-9
634 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
635
636 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins,2))#
637 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
638
639 self.Ze = numpy.zeros(self.Num_Hei)
640 self.ETA = numpy.zeros(([2,self.Num_Hei]))
641
642
643
644 self.readBlock() #Block reading
645
646 else:
647 print 'readFile FlagNoData becomes true'
648 self.flagNoMoreFiles=True
649 self.dataOut.flagNoData = True
650 self.FileHeaderFlag == True
651 return 0
652
653
654
655 def readBlock(self):
656 '''
657 It should be checked if the block has data, if it is not passed to the next file.
658
659 Then the following is done:
660
661 1. Read the RecordHeader
662 2. Fill the buffer with the current block number.
663
664 '''
665
666 if self.PointerReader > 1180:
667 self.fp.seek(self.PointerReader , os.SEEK_SET)
668 self.FirstPoint = self.PointerReader
669
670 else :
671 self.FirstPoint = 1180
672
673
674
675 self.srviHeader = SRVIHeader()
676
677 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
678
679 self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
680
681 if self.blocksize == 148:
682 print 'blocksize == 148 bug'
683 jump = numpy.fromfile(self.fp,[('jump',numpy.str_,140)] ,1)
684
685 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
686
687 if not self.srviHeader.SizeOfSRVI1:
688 self.fileSelector+=1
689 self.nextfileflag==True
690 self.FileHeaderFlag == True
691
692 self.recordheader = RecordHeader()
693 self.recordheader.RHread(self.fp)
694 self.RadarConst = self.recordheader.RadarConst
695 dwell = self.recordheader.time_t
696 npw1 = self.recordheader.npw1
697 npw2 = self.recordheader.npw2
698
699
700 self.dataOut.channelList = range(1)
701 self.dataOut.nIncohInt = self.Num_inCoh
702 self.dataOut.nProfiles = self.Num_Bins
703 self.dataOut.nCohInt = 1
704 self.dataOut.windowOfFilter = 1
705 self.dataOut.utctime = dwell
706 self.dataOut.timeZone=0
707
708 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
709 self.dataOut.heightList = self.SPARrawGate1*self.__deltaHeigth + numpy.array(range(self.Num_Hei))*self.__deltaHeigth
710
711
712
713 self.HSDVsign = numpy.fromfile( self.fp, [('HSDV',numpy.str_,4)],1)
714 self.SizeHSDV = numpy.fromfile( self.fp, [('SizeHSDV','<i4')],1)
715 self.HSDV_Co = numpy.fromfile( self.fp, [('HSDV_Co','<f4')],self.Num_Hei)
716 self.HSDV_Cx = numpy.fromfile( self.fp, [('HSDV_Cx','<f4')],self.Num_Hei)
717
718 self.COFAsign = numpy.fromfile( self.fp, [('COFA',numpy.str_,4)],1)
719 self.SizeCOFA = numpy.fromfile( self.fp, [('SizeCOFA','<i4')],1)
720 self.COFA_Co = numpy.fromfile( self.fp, [('COFA_Co','<f4')],self.Num_Hei)
721 self.COFA_Cx = numpy.fromfile( self.fp, [('COFA_Cx','<f4')],self.Num_Hei)
722
723 self.ZSPCsign = numpy.fromfile(self.fp, [('ZSPCsign',numpy.str_,4)],1)
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC','<i4')],1)
725
726 self.dataOut.HSDV[0]=self.HSDV_Co[:][0]
727 self.dataOut.HSDV[1]=self.HSDV_Cx[:][0]
728
729 for irg in range(self.Num_Hei):
730 nspc = numpy.fromfile(self.fp, [('nspc','int16')],1)[0][0] # Number of spectral sub pieces containing significant power
731
732 for k in range(nspc):
733 binIndex = numpy.fromfile(self.fp, [('binIndex','int16')],1)[0][0] # Index of the spectral bin where the piece is beginning
734 nbins = numpy.fromfile(self.fp, [('nbins','int16')],1)[0][0] # Number of bins of the piece
735
736 #Co_Channel
737 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] # Spectrum piece to be normaliced
738 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] # Maximun piece to be normaliced
739
740
741 self.data_spc[irg,binIndex:binIndex+nbins,0] = self.data_spc[irg,binIndex:binIndex+nbins,0]+jbin/65530.*jmax
742
743 #Cx_Channel
744 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0]
745 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0]
746
747
748 self.data_spc[irg,binIndex:binIndex+nbins,1] = self.data_spc[irg,binIndex:binIndex+nbins,1]+jbin/65530.*jmax
749
750 for bin in range(self.Num_Bins):
751
752 self.data_spc[:,bin,0] = self.data_spc[:,bin,0] - self.dataOut.HSDV[:,0]
753
754 self.data_spc[:,bin,1] = self.data_spc[:,bin,1] - self.dataOut.HSDV[:,1]
755
756
757 numpy.set_printoptions(threshold='nan')
758
759 self.data_spc = numpy.where(self.data_spc > 0. , self.data_spc, 0)
760
761 self.dataOut.COFA = numpy.array([self.COFA_Co , self.COFA_Cx])
762
763 print ' '
764 print 'SPC',numpy.shape(self.dataOut.data_spc)
765 #print 'SPC',self.dataOut.data_spc
766
767 noinor1 = 713031680
768 noinor2 = 30
769
770 npw1 = 1#0**(npw1/10) * noinor1 * noinor2
771 npw2 = 1#0**(npw2/10) * noinor1 * noinor2
772 self.dataOut.NPW = numpy.array([npw1, npw2])
773
774 print ' '
775
776 self.data_spc = numpy.transpose(self.data_spc, (2,1,0))
777 self.data_spc = numpy.fft.fftshift(self.data_spc, axes = 1)
778
779 self.data_spc = numpy.fliplr(self.data_spc)
780
781 self.data_spc = numpy.where(self.data_spc > 0. , self.data_spc, 0)
782 self.dataOut_spc= numpy.ones([1, self.Num_Bins , self.Num_Hei])
783 self.dataOut_spc[0,:,:] = self.data_spc[0,:,:]
784 #print 'SHAPE', self.dataOut_spc.shape
785 #For nyquist correction:
786 #fix = 20 # ~3m/s
787 #shift = self.Num_Bins/2 + fix
788 #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
789
790
791
792 '''Block Reading, the Block Data is received and Reshape is used to give it
793 shape.
794 '''
795
796 self.PointerReader = self.fp.tell()
797
798
799
800
801
802
803 No newline at end of file
@@ -0,0 +1,403
1 '''
2 Created on Oct 24, 2016
3
4 @author: roj- LouVD
5 '''
6
7 import numpy
8 import copy
9 import datetime
10 import time
11 from time import gmtime
12
13 from numpy import transpose
14
15 from jroproc_base import ProcessingUnit, Operation
16 from schainpy.model.data.jrodata import Parameters
17
18
19 class BLTRParametersProc(ProcessingUnit):
20 '''
21 Processing unit for BLTR parameters data (winds)
22
23 Inputs:
24 self.dataOut.nmodes - Number of operation modes
25 self.dataOut.nchannels - Number of channels
26 self.dataOut.nranges - Number of ranges
27
28 self.dataOut.data_SNR - SNR array
29 self.dataOut.data_output - Zonal, Vertical and Meridional velocity array
30 self.dataOut.height - Height array (km)
31 self.dataOut.time - Time array (seconds)
32
33 self.dataOut.fileIndex -Index of the file currently read
34 self.dataOut.lat - Latitude coordinate of BLTR location
35
36 self.dataOut.doy - Experiment doy (number of the day in the current year)
37 self.dataOut.month - Experiment month
38 self.dataOut.day - Experiment day
39 self.dataOut.year - Experiment year
40 '''
41
42 def __init__(self, **kwargs):
43 '''
44 Inputs: None
45 '''
46 ProcessingUnit.__init__(self, **kwargs)
47 self.dataOut = Parameters()
48 self.isConfig = False
49
50 def setup(self, mode):
51 '''
52 '''
53 self.dataOut.mode = mode
54
55 def run(self, mode, snr_threshold=None):
56 '''
57 Inputs:
58 mode = High resolution (0) or Low resolution (1) data
59 snr_threshold = snr filter value
60 '''
61
62 if not self.isConfig:
63 self.setup(mode)
64 self.isConfig = True
65
66 if self.dataIn.type == 'Parameters':
67 self.dataOut.copy(self.dataIn)
68
69 self.dataOut.data_output = self.dataOut.data_output[mode]
70 self.dataOut.heightList = self.dataOut.height[0]
71 self.dataOut.data_SNR = self.dataOut.data_SNR[mode]
72
73 if snr_threshold is not None:
74 SNRavg = numpy.average(self.dataOut.data_SNR, axis=0)
75 SNRavgdB = 10*numpy.log10(SNRavg)
76 for i in range(3):
77 self.dataOut.data_output[i][SNRavgdB <= snr_threshold] = numpy.nan
78
79 # TODO
80 class OutliersFilter(Operation):
81
82 def __init__(self, **kwargs):
83 '''
84 '''
85 Operation.__init__(self, **kwargs)
86
87 def run(self, svalue2, method, factor, filter, npoints=9):
88 '''
89 Inputs:
90 svalue - string to select array velocity
91 svalue2 - string to choose axis filtering
92 method - 0 for SMOOTH or 1 for MEDIAN
93 factor - number used to set threshold
94 filter - 1 for data filtering using the standard deviation criteria else 0
95 npoints - number of points for mask filter
96 '''
97
98 print ' Outliers Filter {} {} / threshold = {}'.format(svalue, svalue, factor)
99
100
101 yaxis = self.dataOut.heightList
102 xaxis = numpy.array([[self.dataOut.utctime]])
103
104 # Zonal
105 value_temp = self.dataOut.data_output[0]
106
107 # Zonal
108 value_temp = self.dataOut.data_output[1]
109
110 # Vertical
111 value_temp = numpy.transpose(self.dataOut.data_output[2])
112
113 htemp = yaxis
114 std = value_temp
115 for h in range(len(htemp)):
116 nvalues_valid = len(numpy.where(numpy.isfinite(value_temp[h]))[0])
117 minvalid = npoints
118
119 #only if valid values greater than the minimum required (10%)
120 if nvalues_valid > minvalid:
121
122 if method == 0:
123 #SMOOTH
124 w = value_temp[h] - self.Smooth(input=value_temp[h], width=npoints, edge_truncate=1)
125
126
127 if method == 1:
128 #MEDIAN
129 w = value_temp[h] - self.Median(input=value_temp[h], width = npoints)
130
131 dw = numpy.std(w[numpy.where(numpy.isfinite(w))],ddof = 1)
132
133 threshold = dw*factor
134 value_temp[numpy.where(w > threshold),h] = numpy.nan
135 value_temp[numpy.where(w < -1*threshold),h] = numpy.nan
136
137
138 #At the end
139 if svalue2 == 'inHeight':
140 value_temp = numpy.transpose(value_temp)
141 output_array[:,m] = value_temp
142
143 if svalue == 'zonal':
144 self.dataOut.data_output[0] = output_array
145
146 elif svalue == 'meridional':
147 self.dataOut.data_output[1] = output_array
148
149 elif svalue == 'vertical':
150 self.dataOut.data_output[2] = output_array
151
152 return self.dataOut.data_output
153
154
155 def Median(self,input,width):
156 '''
157 Inputs:
158 input - Velocity array
159 width - Number of points for mask filter
160
161 '''
162
163 if numpy.mod(width,2) == 1:
164 pc = int((width - 1) / 2)
165 cont = 0
166 output = []
167
168 for i in range(len(input)):
169 if i >= pc and i < len(input) - pc:
170 new2 = input[i-pc:i+pc+1]
171 temp = numpy.where(numpy.isfinite(new2))
172 new = new2[temp]
173 value = numpy.median(new)
174 output.append(value)
175
176 output = numpy.array(output)
177 output = numpy.hstack((input[0:pc],output))
178 output = numpy.hstack((output,input[-pc:len(input)]))
179
180 return output
181
182 def Smooth(self,input,width,edge_truncate = None):
183 '''
184 Inputs:
185 input - Velocity array
186 width - Number of points for mask filter
187 edge_truncate - 1 for truncate the convolution product else
188
189 '''
190
191 if numpy.mod(width,2) == 0:
192 real_width = width + 1
193 nzeros = width / 2
194 else:
195 real_width = width
196 nzeros = (width - 1) / 2
197
198 half_width = int(real_width)/2
199 length = len(input)
200
201 gate = numpy.ones(real_width,dtype='float')
202 norm_of_gate = numpy.sum(gate)
203
204 nan_process = 0
205 nan_id = numpy.where(numpy.isnan(input))
206 if len(nan_id[0]) > 0:
207 nan_process = 1
208 pb = numpy.zeros(len(input))
209 pb[nan_id] = 1.
210 input[nan_id] = 0.
211
212 if edge_truncate == True:
213 output = numpy.convolve(input/norm_of_gate,gate,mode='same')
214 elif edge_truncate == False or edge_truncate == None:
215 output = numpy.convolve(input/norm_of_gate,gate,mode='valid')
216 output = numpy.hstack((input[0:half_width],output))
217 output = numpy.hstack((output,input[len(input)-half_width:len(input)]))
218
219 if nan_process:
220 pb = numpy.convolve(pb/norm_of_gate,gate,mode='valid')
221 pb = numpy.hstack((numpy.zeros(half_width),pb))
222 pb = numpy.hstack((pb,numpy.zeros(half_width)))
223 output[numpy.where(pb > 0.9999)] = numpy.nan
224 input[nan_id] = numpy.nan
225 return output
226
227 def Average(self,aver=0,nhaver=1):
228 '''
229 Inputs:
230 aver - Indicates the time period over which is averaged or consensus data
231 nhaver - Indicates the decimation factor in heights
232
233 '''
234 nhpoints = 48
235
236 lat_piura = -5.17
237 lat_huancayo = -12.04
238 lat_porcuya = -5.8
239
240 if '%2.2f'%self.dataOut.lat == '%2.2f'%lat_piura:
241 hcm = 3.
242 if self.dataOut.year == 2003 :
243 if self.dataOut.doy >= 25 and self.dataOut.doy < 64:
244 nhpoints = 12
245
246 elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_huancayo:
247 hcm = 3.
248 if self.dataOut.year == 2003 :
249 if self.dataOut.doy >= 25 and self.dataOut.doy < 64:
250 nhpoints = 12
251
252
253 elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_porcuya:
254 hcm = 5.#2
255
256 pdata = 0.2
257 taver = [1,2,3,4,6,8,12,24]
258 t0 = 0
259 tf = 24
260 ntime =(tf-t0)/taver[aver]
261 ti = numpy.arange(ntime)
262 tf = numpy.arange(ntime) + taver[aver]
263
264
265 old_height = self.dataOut.heightList
266
267 if nhaver > 1:
268 num_hei = len(self.dataOut.heightList)/nhaver/self.dataOut.nmodes
269 deltha = 0.05*nhaver
270 minhvalid = pdata*nhaver
271 for im in range(self.dataOut.nmodes):
272 new_height = numpy.arange(num_hei)*deltha + self.dataOut.height[im,0] + deltha/2.
273
274
275 data_fHeigths_List = []
276 data_fZonal_List = []
277 data_fMeridional_List = []
278 data_fVertical_List = []
279 startDTList = []
280
281
282 for i in range(ntime):
283 height = old_height
284
285 start = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(ti[i])) - datetime.timedelta(hours = 5)
286 stop = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(tf[i])) - datetime.timedelta(hours = 5)
287
288
289 limit_sec1 = time.mktime(start.timetuple())
290 limit_sec2 = time.mktime(stop.timetuple())
291
292 t1 = numpy.where(self.f_timesec >= limit_sec1)
293 t2 = numpy.where(self.f_timesec < limit_sec2)
294 time_select = []
295 for val_sec in t1[0]:
296 if val_sec in t2[0]:
297 time_select.append(val_sec)
298
299
300 time_select = numpy.array(time_select,dtype = 'int')
301 minvalid = numpy.ceil(pdata*nhpoints)
302
303 zon_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
304 mer_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
305 ver_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
306
307 if nhaver > 1:
308 new_zon_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
309 new_mer_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
310 new_ver_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
311
312 if len(time_select) > minvalid:
313 time_average = self.f_timesec[time_select]
314
315 for im in range(self.dataOut.nmodes):
316
317 for ih in range(self.dataOut.nranges):
318 if numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) >= minvalid:
319 zon_aver[ih,im] = numpy.nansum(self.f_zon[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im]))
320
321 if numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) >= minvalid:
322 mer_aver[ih,im] = numpy.nansum(self.f_mer[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im]))
323
324 if numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) >= minvalid:
325 ver_aver[ih,im] = numpy.nansum(self.f_ver[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im]))
326
327 if nhaver > 1:
328 for ih in range(num_hei):
329 hvalid = numpy.arange(nhaver) + nhaver*ih
330
331 if numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) >= minvalid:
332 new_zon_aver[ih,im] = numpy.nansum(zon_aver[hvalid,im]) / numpy.sum(numpy.isfinite(zon_aver[hvalid,im]))
333
334 if numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) >= minvalid:
335 new_mer_aver[ih,im] = numpy.nansum(mer_aver[hvalid,im]) / numpy.sum(numpy.isfinite(mer_aver[hvalid,im]))
336
337 if numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) >= minvalid:
338 new_ver_aver[ih,im] = numpy.nansum(ver_aver[hvalid,im]) / numpy.sum(numpy.isfinite(ver_aver[hvalid,im]))
339 if nhaver > 1:
340 zon_aver = new_zon_aver
341 mer_aver = new_mer_aver
342 ver_aver = new_ver_aver
343 height = new_height
344
345
346 tstart = time_average[0]
347 tend = time_average[-1]
348 startTime = time.gmtime(tstart)
349
350 year = startTime.tm_year
351 month = startTime.tm_mon
352 day = startTime.tm_mday
353 hour = startTime.tm_hour
354 minute = startTime.tm_min
355 second = startTime.tm_sec
356
357 startDTList.append(datetime.datetime(year,month,day,hour,minute,second))
358
359
360 o_height = numpy.array([])
361 o_zon_aver = numpy.array([])
362 o_mer_aver = numpy.array([])
363 o_ver_aver = numpy.array([])
364 if self.dataOut.nmodes > 1:
365 for im in range(self.dataOut.nmodes):
366
367 if im == 0:
368 h_select = numpy.where(numpy.bitwise_and(height[0,:] >=0,height[0,:] <= hcm,numpy.isfinite(height[0,:])))
369 else:
370 h_select = numpy.where(numpy.bitwise_and(height[1,:] > hcm,height[1,:] < 20,numpy.isfinite(height[1,:])))
371
372
373 ht = h_select[0]
374
375 o_height = numpy.hstack((o_height,height[im,ht]))
376 o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im]))
377 o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im]))
378 o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im]))
379
380 data_fHeigths_List.append(o_height)
381 data_fZonal_List.append(o_zon_aver)
382 data_fMeridional_List.append(o_mer_aver)
383 data_fVertical_List.append(o_ver_aver)
384
385
386 else:
387 h_select = numpy.where(numpy.bitwise_and(height[0,:] <= hcm,numpy.isfinite(height[0,:])))
388 ht = h_select[0]
389 o_height = numpy.hstack((o_height,height[im,ht]))
390 o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im]))
391 o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im]))
392 o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im]))
393
394 data_fHeigths_List.append(o_height)
395 data_fZonal_List.append(o_zon_aver)
396 data_fMeridional_List.append(o_mer_aver)
397 data_fVertical_List.append(o_ver_aver)
398
399
400 return startDTList, data_fHeigths_List, data_fZonal_List, data_fMeridional_List, data_fVertical_List
401
402
403 No newline at end of file
@@ -1179,6 +1179,8 class Parameters(Spectra):
1179 nAvg = None
1179 nAvg = None
1180
1180
1181 noise_estimation = None
1181 noise_estimation = None
1182
1183 GauSPC = None #Fit gaussian SPC
1182
1184
1183
1185
1184 def __init__(self):
1186 def __init__(self):
@@ -1213,8 +1215,15 class Parameters(Spectra):
1213 else:
1215 else:
1214 return self.paramInterval
1216 return self.paramInterval
1215
1217
1218 def setValue(self, value):
1219
1220 print "This property should not be initialized"
1221
1222 return
1223
1216 def getNoise(self):
1224 def getNoise(self):
1217
1225
1218 return self.spc_noise
1226 return self.spc_noise
1219
1227
1220 timeInterval = property(getTimeInterval)
1228 timeInterval = property(getTimeInterval)
1229 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
@@ -6,81 +6,81 import copy
6 from figure import Figure, isRealtime
6 from figure import Figure, isRealtime
7
7
8 class CorrelationPlot(Figure):
8 class CorrelationPlot(Figure):
9
9
10 isConfig = None
10 isConfig = None
11 __nsubplots = None
11 __nsubplots = None
12
12
13 WIDTHPROF = None
13 WIDTHPROF = None
14 HEIGHTPROF = None
14 HEIGHTPROF = None
15 PREFIX = 'corr'
15 PREFIX = 'corr'
16
16
17 def __init__(self, **kwargs):
17 def __init__(self):
18 Figure.__init__(self, **kwargs)
18
19 self.isConfig = False
19 self.isConfig = False
20 self.__nsubplots = 1
20 self.__nsubplots = 1
21
21
22 self.WIDTH = 280
22 self.WIDTH = 280
23 self.HEIGHT = 250
23 self.HEIGHT = 250
24 self.WIDTHPROF = 120
24 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
25 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
26 self.counter_imagwr = 0
27
27
28 self.PLOT_CODE = 1
28 self.PLOT_CODE = 1
29 self.FTP_WEI = None
29 self.FTP_WEI = None
30 self.EXP_CODE = None
30 self.EXP_CODE = None
31 self.SUB_EXP_CODE = None
31 self.SUB_EXP_CODE = None
32 self.PLOT_POS = None
32 self.PLOT_POS = None
33
33
34 def getSubplots(self):
34 def getSubplots(self):
35
35
36 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 nrow = int(self.nplots*1./ncol + 0.9)
37 nrow = int(self.nplots*1./ncol + 0.9)
38
38
39 return nrow, ncol
39 return nrow, ncol
40
40
41 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
41 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
42
42
43 showprofile = False
43 showprofile = False
44 self.__showprofile = showprofile
44 self.__showprofile = showprofile
45 self.nplots = nplots
45 self.nplots = nplots
46
46
47 ncolspan = 1
47 ncolspan = 1
48 colspan = 1
48 colspan = 1
49 if showprofile:
49 if showprofile:
50 ncolspan = 3
50 ncolspan = 3
51 colspan = 2
51 colspan = 2
52 self.__nsubplots = 2
52 self.__nsubplots = 2
53
53
54 self.createFigure(id = id,
54 self.createFigure(id = id,
55 wintitle = wintitle,
55 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
56 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
58 show=show)
59
59
60 nrow, ncol = self.getSubplots()
60 nrow, ncol = self.getSubplots()
61
61
62 counter = 0
62 counter = 0
63 for y in range(nrow):
63 for y in range(nrow):
64 for x in range(ncol):
64 for x in range(ncol):
65
65
66 if counter >= self.nplots:
66 if counter >= self.nplots:
67 break
67 break
68
68
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
70
71 if showprofile:
71 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
73
74 counter += 1
74 counter += 1
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
79 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
81
82 """
82 """
83
83
84 Input:
84 Input:
85 dataOut :
85 dataOut :
86 id :
86 id :
@@ -94,15 +94,15 class CorrelationPlot(Figure):
94 zmin : None,
94 zmin : None,
95 zmax : None
95 zmax : None
96 """
96 """
97
97
98 if dataOut.flagNoData:
98 if dataOut.flagNoData:
99 return None
99 return None
100
100
101 if realtime:
101 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
103 print 'Skipping this plot function'
104 return
104 return
105
105
106 if channelList == None:
106 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
107 channelIndexList = dataOut.channelIndexList
108 else:
108 else:
@@ -111,53 +111,53 class CorrelationPlot(Figure):
111 if channel not in dataOut.channelList:
111 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
112 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
113 channelIndexList.append(dataOut.channelList.index(channel))
114
114
115 factor = dataOut.normFactor
115 factor = dataOut.normFactor
116 lenfactor = factor.shape[1]
116 lenfactor = factor.shape[1]
117 x = dataOut.getLagTRange(1)
117 x = dataOut.getLagTRange(1)
118 y = dataOut.getHeiRange()
118 y = dataOut.getHeiRange()
119
119
120 z = copy.copy(dataOut.data_corr[:,:,0,:])
120 z = copy.copy(dataOut.data_corr[:,:,0,:])
121 for i in range(dataOut.data_corr.shape[0]):
121 for i in range(dataOut.data_corr.shape[0]):
122 z[i,:,:] = z[i,:,:]/factor[i,:]
122 z[i,:,:] = z[i,:,:]/factor[i,:]
123 zdB = numpy.abs(z)
123 zdB = numpy.abs(z)
124
124
125 avg = numpy.average(z, axis=1)
125 avg = numpy.average(z, axis=1)
126 # avg = numpy.nanmean(z, axis=1)
126 # avg = numpy.nanmean(z, axis=1)
127 # noise = dataOut.noise/factor
127 # noise = dataOut.noise/factor
128
128
129 #thisDatetime = dataOut.datatime
129 #thisDatetime = dataOut.datatime
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 title = wintitle + " Correlation"
131 title = wintitle + " Correlation"
132 xlabel = "Lag T (s)"
132 xlabel = "Lag T (s)"
133 ylabel = "Range (Km)"
133 ylabel = "Range (Km)"
134
134
135 if not self.isConfig:
135 if not self.isConfig:
136
136
137 nplots = dataOut.data_corr.shape[0]
137 nplots = dataOut.data_corr.shape[0]
138
138
139 self.setup(id=id,
139 self.setup(id=id,
140 nplots=nplots,
140 nplots=nplots,
141 wintitle=wintitle,
141 wintitle=wintitle,
142 showprofile=showprofile,
142 showprofile=showprofile,
143 show=show)
143 show=show)
144
144
145 if xmin == None: xmin = numpy.nanmin(x)
145 if xmin == None: xmin = numpy.nanmin(x)
146 if xmax == None: xmax = numpy.nanmax(x)
146 if xmax == None: xmax = numpy.nanmax(x)
147 if ymin == None: ymin = numpy.nanmin(y)
147 if ymin == None: ymin = numpy.nanmin(y)
148 if ymax == None: ymax = numpy.nanmax(y)
148 if ymax == None: ymax = numpy.nanmax(y)
149 if zmin == None: zmin = 0
149 if zmin == None: zmin = 0
150 if zmax == None: zmax = 1
150 if zmax == None: zmax = 1
151
151
152 self.FTP_WEI = ftp_wei
152 self.FTP_WEI = ftp_wei
153 self.EXP_CODE = exp_code
153 self.EXP_CODE = exp_code
154 self.SUB_EXP_CODE = sub_exp_code
154 self.SUB_EXP_CODE = sub_exp_code
155 self.PLOT_POS = plot_pos
155 self.PLOT_POS = plot_pos
156
156
157 self.isConfig = True
157 self.isConfig = True
158
158
159 self.setWinTitle(title)
159 self.setWinTitle(title)
160
160
161 for i in range(self.nplots):
161 for i in range(self.nplots):
162 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
163 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
163 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
@@ -166,7 +166,7 class CorrelationPlot(Figure):
166 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
167 xlabel=xlabel, ylabel=ylabel, title=title,
167 xlabel=xlabel, ylabel=ylabel, title=title,
168 ticksize=9, cblabel='')
168 ticksize=9, cblabel='')
169
169
170 # if self.__showprofile:
170 # if self.__showprofile:
171 # axes = self.axesList[i*self.__nsubplots +1]
171 # axes = self.axesList[i*self.__nsubplots +1]
172 # axes.pline(avgdB[i], y,
172 # axes.pline(avgdB[i], y,
@@ -174,15 +174,15 class CorrelationPlot(Figure):
174 # xlabel='dB', ylabel='', title='',
174 # xlabel='dB', ylabel='', title='',
175 # ytick_visible=False,
175 # ytick_visible=False,
176 # grid='x')
176 # grid='x')
177 #
177 #
178 # noiseline = numpy.repeat(noisedB[i], len(y))
178 # noiseline = numpy.repeat(noisedB[i], len(y))
179 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
179 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
180
180
181 self.draw()
181 self.draw()
182
182
183 self.save(figpath=figpath,
183 self.save(figpath=figpath,
184 figfile=figfile,
184 figfile=figfile,
185 save=save,
185 save=save,
186 ftp=ftp,
186 ftp=ftp,
187 wr_period=wr_period,
187 wr_period=wr_period,
188 thisDatetime=thisDatetime)
188 thisDatetime=thisDatetime)
@@ -11,80 +11,79 from figure import Figure, isRealtime
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13 class SpectraHeisScope(Figure):
13 class SpectraHeisScope(Figure):
14
14
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self, **kwargs):
23 def __init__(self):
24
24
25 Figure.__init__(self, **kwargs)
26 self.isConfig = False
25 self.isConfig = False
27 self.__nsubplots = 1
26 self.__nsubplots = 1
28
27
29 self.WIDTH = 230
28 self.WIDTH = 230
30 self.HEIGHT = 250
29 self.HEIGHT = 250
31 self.WIDTHPROF = 120
30 self.WIDTHPROF = 120
32 self.HEIGHTPROF = 0
31 self.HEIGHTPROF = 0
33 self.counter_imagwr = 0
32 self.counter_imagwr = 0
34
33
35 self.PLOT_CODE = SPEC_CODE
34 self.PLOT_CODE = SPEC_CODE
36
35
37 def getSubplots(self):
36 def getSubplots(self):
38
37
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
41
40
42 return nrow, ncol
41 return nrow, ncol
43
42
44 def setup(self, id, nplots, wintitle, show):
43 def setup(self, id, nplots, wintitle, show):
45
44
46 showprofile = False
45 showprofile = False
47 self.__showprofile = showprofile
46 self.__showprofile = showprofile
48 self.nplots = nplots
47 self.nplots = nplots
49
48
50 ncolspan = 1
49 ncolspan = 1
51 colspan = 1
50 colspan = 1
52 if showprofile:
51 if showprofile:
53 ncolspan = 3
52 ncolspan = 3
54 colspan = 2
53 colspan = 2
55 self.__nsubplots = 2
54 self.__nsubplots = 2
56
55
57 self.createFigure(id = id,
56 self.createFigure(id = id,
58 wintitle = wintitle,
57 wintitle = wintitle,
59 widthplot = self.WIDTH + self.WIDTHPROF,
58 widthplot = self.WIDTH + self.WIDTHPROF,
60 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 show = show)
60 show = show)
62
61
63 nrow, ncol = self.getSubplots()
62 nrow, ncol = self.getSubplots()
64
63
65 counter = 0
64 counter = 0
66 for y in range(nrow):
65 for y in range(nrow):
67 for x in range(ncol):
66 for x in range(ncol):
68
67
69 if counter >= self.nplots:
68 if counter >= self.nplots:
70 break
69 break
71
70
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73
72
74 if showprofile:
73 if showprofile:
75 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76
75
77 counter += 1
76 counter += 1
78
77
79
78
80 def run(self, dataOut, id, wintitle="", channelList=None,
79 def run(self, dataOut, id, wintitle="", channelList=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
80 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
82 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
81 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
83 server=None, folder=None, username=None, password=None,
82 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
83 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
85
84
86 """
85 """
87
86
88 Input:
87 Input:
89 dataOut :
88 dataOut :
90 id :
89 id :
@@ -95,12 +94,12 class SpectraHeisScope(Figure):
95 ymin : None,
94 ymin : None,
96 ymax : None,
95 ymax : None,
97 """
96 """
98
97
99 if dataOut.realtime:
98 if dataOut.realtime:
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
99 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 print 'Skipping this plot function'
100 print 'Skipping this plot function'
102 return
101 return
103
102
104 if channelList == None:
103 if channelList == None:
105 channelIndexList = dataOut.channelIndexList
104 channelIndexList = dataOut.channelIndexList
106 else:
105 else:
@@ -109,9 +108,9 class SpectraHeisScope(Figure):
109 if channel not in dataOut.channelList:
108 if channel not in dataOut.channelList:
110 raise ValueError, "Channel %d is not in dataOut.channelList"
109 raise ValueError, "Channel %d is not in dataOut.channelList"
111 channelIndexList.append(dataOut.channelList.index(channel))
110 channelIndexList.append(dataOut.channelList.index(channel))
112
111
113 # x = dataOut.heightList
112 # x = dataOut.heightList
114 c = 3E8
113 c = 3E8
115 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
114 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
116 #deberia cambiar para el caso de 1Mhz y 100KHz
115 #deberia cambiar para el caso de 1Mhz y 100KHz
117 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
116 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
@@ -123,7 +122,7 class SpectraHeisScope(Figure):
123 data = dataOut.data_spc / factor
122 data = dataOut.data_spc / factor
124 datadB = 10.*numpy.log10(data)
123 datadB = 10.*numpy.log10(data)
125 y = datadB
124 y = datadB
126
125
127 #thisDatetime = dataOut.datatime
126 #thisDatetime = dataOut.datatime
128 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
127 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
128 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
@@ -131,29 +130,29 class SpectraHeisScope(Figure):
131 #para 1Mhz descomentar la siguiente linea
130 #para 1Mhz descomentar la siguiente linea
132 #xlabel = "Frequency x 10000"
131 #xlabel = "Frequency x 10000"
133 ylabel = "Intensity (dB)"
132 ylabel = "Intensity (dB)"
134
133
135 if not self.isConfig:
134 if not self.isConfig:
136 nplots = len(channelIndexList)
135 nplots = len(channelIndexList)
137
136
138 self.setup(id=id,
137 self.setup(id=id,
139 nplots=nplots,
138 nplots=nplots,
140 wintitle=wintitle,
139 wintitle=wintitle,
141 show=show)
140 show=show)
142
141
143 if xmin == None: xmin = numpy.nanmin(x)
142 if xmin == None: xmin = numpy.nanmin(x)
144 if xmax == None: xmax = numpy.nanmax(x)
143 if xmax == None: xmax = numpy.nanmax(x)
145 if ymin == None: ymin = numpy.nanmin(y)
144 if ymin == None: ymin = numpy.nanmin(y)
146 if ymax == None: ymax = numpy.nanmax(y)
145 if ymax == None: ymax = numpy.nanmax(y)
147
146
148 self.FTP_WEI = ftp_wei
147 self.FTP_WEI = ftp_wei
149 self.EXP_CODE = exp_code
148 self.EXP_CODE = exp_code
150 self.SUB_EXP_CODE = sub_exp_code
149 self.SUB_EXP_CODE = sub_exp_code
151 self.PLOT_POS = plot_pos
150 self.PLOT_POS = plot_pos
152
151
153 self.isConfig = True
152 self.isConfig = True
154
153
155 self.setWinTitle(title)
154 self.setWinTitle(title)
156
155
157 for i in range(len(self.axesList)):
156 for i in range(len(self.axesList)):
158 ychannel = y[i,:]
157 ychannel = y[i,:]
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
158 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
@@ -162,10 +161,10 class SpectraHeisScope(Figure):
162 axes.pline(x, ychannel,
161 axes.pline(x, ychannel,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
162 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
164 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
163 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
165
164
166
165
167 self.draw()
166 self.draw()
168
167
169 self.save(figpath=figpath,
168 self.save(figpath=figpath,
170 figfile=figfile,
169 figfile=figfile,
171 save=save,
170 save=save,
@@ -174,18 +173,18 class SpectraHeisScope(Figure):
174 thisDatetime=thisDatetime)
173 thisDatetime=thisDatetime)
175
174
176 class RTIfromSpectraHeis(Figure):
175 class RTIfromSpectraHeis(Figure):
177
176
178 isConfig = None
177 isConfig = None
179 __nsubplots = None
178 __nsubplots = None
180
179
181 PREFIX = 'rtinoise'
180 PREFIX = 'rtinoise'
182
181
183 def __init__(self, **kwargs):
182 def __init__(self):
184 Figure.__init__(self, **kwargs)
183
185 self.timerange = 24*60*60
184 self.timerange = 24*60*60
186 self.isConfig = False
185 self.isConfig = False
187 self.__nsubplots = 1
186 self.__nsubplots = 1
188
187
189 self.WIDTH = 820
188 self.WIDTH = 820
190 self.HEIGHT = 200
189 self.HEIGHT = 200
191 self.WIDTHPROF = 120
190 self.WIDTHPROF = 120
@@ -194,43 +193,43 class RTIfromSpectraHeis(Figure):
194 self.xdata = None
193 self.xdata = None
195 self.ydata = None
194 self.ydata = None
196 self.figfile = None
195 self.figfile = None
197
196
198 self.PLOT_CODE = RTI_CODE
197 self.PLOT_CODE = RTI_CODE
199
198
200 def getSubplots(self):
199 def getSubplots(self):
201
200
202 ncol = 1
201 ncol = 1
203 nrow = 1
202 nrow = 1
204
203
205 return nrow, ncol
204 return nrow, ncol
206
205
207 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
206 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
208
207
209 self.__showprofile = showprofile
208 self.__showprofile = showprofile
210 self.nplots = nplots
209 self.nplots = nplots
211
210
212 ncolspan = 7
211 ncolspan = 7
213 colspan = 6
212 colspan = 6
214 self.__nsubplots = 2
213 self.__nsubplots = 2
215
214
216 self.createFigure(id = id,
215 self.createFigure(id = id,
217 wintitle = wintitle,
216 wintitle = wintitle,
218 widthplot = self.WIDTH+self.WIDTHPROF,
217 widthplot = self.WIDTH+self.WIDTHPROF,
219 heightplot = self.HEIGHT+self.HEIGHTPROF,
218 heightplot = self.HEIGHT+self.HEIGHTPROF,
220 show = show)
219 show = show)
221
220
222 nrow, ncol = self.getSubplots()
221 nrow, ncol = self.getSubplots()
223
222
224 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
223 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
225
224
226
225
227 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
226 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
228 xmin=None, xmax=None, ymin=None, ymax=None,
227 xmin=None, xmax=None, ymin=None, ymax=None,
229 timerange=None,
228 timerange=None,
230 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
229 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
231 server=None, folder=None, username=None, password=None,
230 server=None, folder=None, username=None, password=None,
232 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
231 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
233
232
234 if channelList == None:
233 if channelList == None:
235 channelIndexList = dataOut.channelIndexList
234 channelIndexList = dataOut.channelIndexList
236 channelList = dataOut.channelList
235 channelList = dataOut.channelList
@@ -240,86 +239,86 class RTIfromSpectraHeis(Figure):
240 if channel not in dataOut.channelList:
239 if channel not in dataOut.channelList:
241 raise ValueError, "Channel %d is not in dataOut.channelList"
240 raise ValueError, "Channel %d is not in dataOut.channelList"
242 channelIndexList.append(dataOut.channelList.index(channel))
241 channelIndexList.append(dataOut.channelList.index(channel))
243
242
244 if timerange != None:
243 if timerange != None:
245 self.timerange = timerange
244 self.timerange = timerange
246
245
247 x = dataOut.getTimeRange()
246 x = dataOut.getTimeRange()
248 y = dataOut.getHeiRange()
247 y = dataOut.getHeiRange()
249
248
250 factor = dataOut.normFactor
249 factor = dataOut.normFactor
251 data = dataOut.data_spc / factor
250 data = dataOut.data_spc / factor
252 data = numpy.average(data,axis=1)
251 data = numpy.average(data,axis=1)
253 datadB = 10*numpy.log10(data)
252 datadB = 10*numpy.log10(data)
254
253
255 # factor = dataOut.normFactor
254 # factor = dataOut.normFactor
256 # noise = dataOut.getNoise()/factor
255 # noise = dataOut.getNoise()/factor
257 # noisedB = 10*numpy.log10(noise)
256 # noisedB = 10*numpy.log10(noise)
258
257
259 #thisDatetime = dataOut.datatime
258 #thisDatetime = dataOut.datatime
260 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
259 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
261 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
260 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
262 xlabel = "Local Time"
261 xlabel = "Local Time"
263 ylabel = "Intensity (dB)"
262 ylabel = "Intensity (dB)"
264
263
265 if not self.isConfig:
264 if not self.isConfig:
266
265
267 nplots = 1
266 nplots = 1
268
267
269 self.setup(id=id,
268 self.setup(id=id,
270 nplots=nplots,
269 nplots=nplots,
271 wintitle=wintitle,
270 wintitle=wintitle,
272 showprofile=showprofile,
271 showprofile=showprofile,
273 show=show)
272 show=show)
274
273
275 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
274 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
276
275
277 if ymin == None: ymin = numpy.nanmin(datadB)
276 if ymin == None: ymin = numpy.nanmin(datadB)
278 if ymax == None: ymax = numpy.nanmax(datadB)
277 if ymax == None: ymax = numpy.nanmax(datadB)
279
278
280 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
279 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
281 self.isConfig = True
280 self.isConfig = True
282 self.figfile = figfile
281 self.figfile = figfile
283 self.xdata = numpy.array([])
282 self.xdata = numpy.array([])
284 self.ydata = numpy.array([])
283 self.ydata = numpy.array([])
285
284
286 self.FTP_WEI = ftp_wei
285 self.FTP_WEI = ftp_wei
287 self.EXP_CODE = exp_code
286 self.EXP_CODE = exp_code
288 self.SUB_EXP_CODE = sub_exp_code
287 self.SUB_EXP_CODE = sub_exp_code
289 self.PLOT_POS = plot_pos
288 self.PLOT_POS = plot_pos
290
289
291 self.setWinTitle(title)
290 self.setWinTitle(title)
292
291
293
292
294 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
293 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
295 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
294 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
296
295
297 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
296 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
298 axes = self.axesList[0]
297 axes = self.axesList[0]
299
298
300 self.xdata = numpy.hstack((self.xdata, x[0:1]))
299 self.xdata = numpy.hstack((self.xdata, x[0:1]))
301
300
302 if len(self.ydata)==0:
301 if len(self.ydata)==0:
303 self.ydata = datadB[channelIndexList].reshape(-1,1)
302 self.ydata = datadB[channelIndexList].reshape(-1,1)
304 else:
303 else:
305 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
304 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
306
305
307
306
308 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
307 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
309 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
308 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
310 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
309 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
311 XAxisAsTime=True
310 XAxisAsTime=True
312 )
311 )
313
312
314 self.draw()
313 self.draw()
315
314
316 update_figfile = False
315 update_figfile = False
317
316
318 if dataOut.ltctime >= self.tmax:
317 if dataOut.ltctime >= self.tmax:
319 self.counter_imagwr = wr_period
318 self.counter_imagwr = wr_period
320 self.isConfig = False
319 self.isConfig = False
321 update_figfile = True
320 update_figfile = True
322
321
323 self.save(figpath=figpath,
322 self.save(figpath=figpath,
324 figfile=figfile,
323 figfile=figfile,
325 save=save,
324 save=save,
@@ -6,6 +6,217 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class FitGauPlot(Figure):
10
11 isConfig = None
12 __nsubplots = None
13
14 WIDTHPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'fitgau'
17
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
21 self.__nsubplots = 1
22
23 self.WIDTH = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
28
29 self.PLOT_CODE = SPEC_CODE
30
31 self.FTP_WEI = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
35
36 self.__xfilter_ena = False
37 self.__yfilter_ena = False
38
39 def getSubplots(self):
40
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
43
44 return nrow, ncol
45
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
47
48 self.__showprofile = showprofile
49 self.nplots = nplots
50
51 ncolspan = 1
52 colspan = 1
53 if showprofile:
54 ncolspan = 3
55 colspan = 2
56 self.__nsubplots = 2
57
58 self.createFigure(id = id,
59 wintitle = wintitle,
60 widthplot = self.WIDTH + self.WIDTHPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
62 show=show)
63
64 nrow, ncol = self.getSubplots()
65
66 counter = 0
67 for y in range(nrow):
68 for x in range(ncol):
69
70 if counter >= self.nplots:
71 break
72
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
74
75 if showprofile:
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
77
78 counter += 1
79
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 1):
86
87 """
88
89 Input:
90 dataOut :
91 id :
92 wintitle :
93 channelList :
94 showProfile :
95 xmin : None,
96 xmax : None,
97 ymin : None,
98 ymax : None,
99 zmin : None,
100 zmax : None
101 """
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
105 return
106
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
109 else:
110 channelIndexList = []
111 for channel in channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
114 channelIndexList.append(dataOut.channelList.index(channel))
115
116 # if normFactor is None:
117 # factor = dataOut.normFactor
118 # else:
119 # factor = normFactor
120 if xaxis == "frequency":
121 x = dataOut.spc_range[0]
122 xlabel = "Frequency (kHz)"
123
124 elif xaxis == "time":
125 x = dataOut.spc_range[1]
126 xlabel = "Time (ms)"
127
128 else:
129 x = dataOut.spc_range[2]
130 xlabel = "Velocity (m/s)"
131
132 ylabel = "Range (Km)"
133
134 y = dataOut.getHeiRange()
135
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
137 print 'GausSPC', z[0,32,10:40]
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 zdB = 10*numpy.log10(z)
140
141 avg = numpy.average(z, axis=1)
142 avgdB = 10*numpy.log10(avg)
143
144 noise = dataOut.spc_noise
145 noisedB = 10*numpy.log10(noise)
146
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 title = wintitle + " Spectra"
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151
152 if not self.isConfig:
153
154 nplots = len(channelIndexList)
155
156 self.setup(id=id,
157 nplots=nplots,
158 wintitle=wintitle,
159 showprofile=showprofile,
160 show=show)
161
162 if xmin == None: xmin = numpy.nanmin(x)
163 if xmax == None: xmax = numpy.nanmax(x)
164 if ymin == None: ymin = numpy.nanmin(y)
165 if ymax == None: ymax = numpy.nanmax(y)
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168
169 self.FTP_WEI = ftp_wei
170 self.EXP_CODE = exp_code
171 self.SUB_EXP_CODE = sub_exp_code
172 self.PLOT_POS = plot_pos
173
174 self.isConfig = True
175
176 self.setWinTitle(title)
177
178 for i in range(self.nplots):
179 index = channelIndexList[i]
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 if len(dataOut.beam.codeList) != 0:
183 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
184
185 axes = self.axesList[i*self.__nsubplots]
186 axes.pcolor(x, y, zdB[index,:,:],
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 ticksize=9, cblabel='')
190
191 if self.__showprofile:
192 axes = self.axesList[i*self.__nsubplots +1]
193 axes.pline(avgdB[index,:], y,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xlabel='dB', ylabel='', title='',
196 ytick_visible=False,
197 grid='x')
198
199 noiseline = numpy.repeat(noisedB[index], len(y))
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201
202 self.draw()
203
204 if figfile == None:
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 name = str_datetime
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 figfile = self.getFilename(name)
210
211 self.save(figpath=figpath,
212 figfile=figfile,
213 save=save,
214 ftp=ftp,
215 wr_period=wr_period,
216 thisDatetime=thisDatetime)
217
218
219
9 class MomentsPlot(Figure):
220 class MomentsPlot(Figure):
10
221
11 isConfig = None
222 isConfig = None
@@ -446,10 +657,9 class WindProfilerPlot(Figure):
446 # tmin = None
657 # tmin = None
447 # tmax = None
658 # tmax = None
448
659
449
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
661 y = dataOut.heightList
451 y = dataOut.heightList
662 z = dataOut.data_output.copy()
452 z = dataOut.data_output.copy()
453 nplots = z.shape[0] #Number of wind dimensions estimated
663 nplots = z.shape[0] #Number of wind dimensions estimated
454 nplotsw = nplots
664 nplotsw = nplots
455
665
@@ -559,7 +769,7 class WindProfilerPlot(Figure):
559 thisDatetime=thisDatetime,
769 thisDatetime=thisDatetime,
560 update_figfile=update_figfile)
770 update_figfile=update_figfile)
561
771
562 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
772 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
563 self.counter_imagwr = wr_period
773 self.counter_imagwr = wr_period
564 self.isConfig = False
774 self.isConfig = False
565 update_figfile = True
775 update_figfile = True
@@ -636,12 +846,12 class ParametersPlot(Figure):
636
846
637 counter += 1
847 counter += 1
638
848
639 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
849 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
640 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
850 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
641 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
851 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
642 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
852 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
643 server=None, folder=None, username=None, password=None,
853 server=None, folder=None, username=None, password=None,
644 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
854 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
645 """
855 """
646
856
647 Input:
857 Input:
@@ -657,12 +867,11 class ParametersPlot(Figure):
657 zmin : None,
867 zmin : None,
658 zmax : None
868 zmax : None
659 """
869 """
660
870
661 if colormap:
871 if HEIGHT is not None:
662 colormap="jet"
872 self.HEIGHT = HEIGHT
663 else:
873
664 colormap="RdBu_r"
874
665
666 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
875 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
667 return
876 return
668
877
@@ -86,7 +86,7 class SpectraPlot(Figure):
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 server=None, folder=None, username=None, password=None,
87 server=None, folder=None, username=None, password=None,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="velocity", **kwargs):
89 xaxis="frequency", colormap='jet', normFactor=None):
90
90
91 """
91 """
92
92
@@ -103,9 +103,6 class SpectraPlot(Figure):
103 zmin : None,
103 zmin : None,
104 zmax : None
104 zmax : None
105 """
105 """
106
107 colormap = kwargs.get('colormap','jet')
108
109 if realtime:
106 if realtime:
110 if not(isRealtime(utcdatatime = dataOut.utctime)):
107 if not(isRealtime(utcdatatime = dataOut.utctime)):
111 print 'Skipping this plot function'
108 print 'Skipping this plot function'
@@ -120,8 +117,10 class SpectraPlot(Figure):
120 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
117 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
121 channelIndexList.append(dataOut.channelList.index(channel))
118 channelIndexList.append(dataOut.channelList.index(channel))
122
119
123 factor = dataOut.normFactor
120 if normFactor is None:
124
121 factor = dataOut.normFactor
122 else:
123 factor = normFactor
125 if xaxis == "frequency":
124 if xaxis == "frequency":
126 x = dataOut.getFreqRange(1)/1000.
125 x = dataOut.getFreqRange(1)/1000.
127 xlabel = "Frequency (kHz)"
126 xlabel = "Frequency (kHz)"
@@ -282,7 +281,7 class CrossSpectraPlot(Figure):
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
281 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
282 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
284 server=None, folder=None, username=None, password=None,
283 server=None, folder=None, username=None, password=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
284 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
286 xaxis='frequency'):
285 xaxis='frequency'):
287
286
288 """
287 """
@@ -315,8 +314,11 class CrossSpectraPlot(Figure):
315
314
316 if len(pairsIndexList) > 4:
315 if len(pairsIndexList) > 4:
317 pairsIndexList = pairsIndexList[0:4]
316 pairsIndexList = pairsIndexList[0:4]
318
317
319 factor = dataOut.normFactor
318 if normFactor is None:
319 factor = dataOut.normFactor
320 else:
321 factor = normFactor
320 x = dataOut.getVelRange(1)
322 x = dataOut.getVelRange(1)
321 y = dataOut.getHeiRange()
323 y = dataOut.getHeiRange()
322 z = dataOut.data_spc[:,:,:]/factor
324 z = dataOut.data_spc[:,:,:]/factor
@@ -517,10 +519,10 class RTIPlot(Figure):
517
519
518 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
520 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
519 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
521 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
520 timerange=None,
522 timerange=None, colormap='jet',
521 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
523 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
522 server=None, folder=None, username=None, password=None,
524 server=None, folder=None, username=None, password=None,
523 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
525 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
524
526
525 """
527 """
526
528
@@ -538,7 +540,10 class RTIPlot(Figure):
538 zmax : None
540 zmax : None
539 """
541 """
540
542
541 colormap = kwargs.get('colormap', 'jet')
543 #colormap = kwargs.get('colormap', 'jet')
544 if HEIGHT is not None:
545 self.HEIGHT = HEIGHT
546
542 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
547 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
543 return
548 return
544
549
@@ -551,20 +556,21 class RTIPlot(Figure):
551 raise ValueError, "Channel %d is not in dataOut.channelList"
556 raise ValueError, "Channel %d is not in dataOut.channelList"
552 channelIndexList.append(dataOut.channelList.index(channel))
557 channelIndexList.append(dataOut.channelList.index(channel))
553
558
554 if hasattr(dataOut, 'normFactor'):
559 if normFactor is None:
555 factor = dataOut.normFactor
560 factor = dataOut.normFactor
556 else:
561 else:
557 factor = 1
562 factor = normFactor
558
563
559 # factor = dataOut.normFactor
564 # factor = dataOut.normFactor
560 x = dataOut.getTimeRange()
565 x = dataOut.getTimeRange()
561 y = dataOut.getHeiRange()
566 y = dataOut.getHeiRange()
562
567
563 # z = dataOut.data_spc/factor
568 z = dataOut.data_spc/factor
564 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
569 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
565 # avg = numpy.average(z, axis=1)
570 avg = numpy.average(z, axis=1)
566 # avgdB = 10.*numpy.log10(avg)
571 avgdB = 10.*numpy.log10(avg)
567 avgdB = dataOut.getPower()
572 # avgdB = dataOut.getPower()
573
568
574
569 thisDatetime = dataOut.datatime
575 thisDatetime = dataOut.datatime
570 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
576 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
@@ -1111,6 +1117,7 class Noise(Figure):
1111
1117
1112 PREFIX = 'noise'
1118 PREFIX = 'noise'
1113
1119
1120
1114 def __init__(self, **kwargs):
1121 def __init__(self, **kwargs):
1115 Figure.__init__(self, **kwargs)
1122 Figure.__init__(self, **kwargs)
1116 self.timerange = 24*60*60
1123 self.timerange = 24*60*60
@@ -88,6 +88,8 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
88 rowspan=rowspan,
88 rowspan=rowspan,
89 polar=polar)
89 polar=polar)
90
90
91 axes.grid(True)
92
91 matplotlib.pyplot.ion()
93 matplotlib.pyplot.ion()
92 return axes
94 return axes
93
95
@@ -174,7 +176,7 def set_linedata(ax, x, y, idline):
174
176
175 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
177 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
176
178
177 ax = iplot.axes
179 ax = iplot.get_axes()
178
180
179 printLabels(ax, xlabel, ylabel, title)
181 printLabels(ax, xlabel, ylabel, title)
180
182
@@ -204,7 +206,7 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
204
206
205 z = numpy.ma.masked_invalid(z)
207 z = numpy.ma.masked_invalid(z)
206 cmap=matplotlib.pyplot.get_cmap(colormap)
208 cmap=matplotlib.pyplot.get_cmap(colormap)
207 cmap.set_bad('black', 1.)
209 cmap.set_bad('white',1.)
208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
210 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
211 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
210 cb.set_label(cblabel)
212 cb.set_label(cblabel)
@@ -239,21 +241,32 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
239 ax.xaxis.set_major_formatter(FuncFormatter(func))
241 ax.xaxis.set_major_formatter(FuncFormatter(func))
240 ax.xaxis.set_major_locator(LinearLocator(7))
242 ax.xaxis.set_major_locator(LinearLocator(7))
241
243
244 ax.grid(True)
242 matplotlib.pyplot.ion()
245 matplotlib.pyplot.ion()
243 return imesh
246 return imesh
244
247
245 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
248 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
246
249
250 z = numpy.ma.masked_invalid(z)
251
252 cmap=matplotlib.pyplot.get_cmap('jet')
253 cmap.set_bad('white',1.)
254
247 z = z.T
255 z = z.T
248 ax = imesh.axes
256 ax = imesh.get_axes()
249 printLabels(ax, xlabel, ylabel, title)
257 printLabels(ax, xlabel, ylabel, title)
250 imesh.set_array(z.ravel())
258 imesh.set_array(z.ravel())
259 ax.grid(True)
260
251
261
252 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
262 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
253
263
254 printLabels(ax, xlabel, ylabel, title)
264 printLabels(ax, xlabel, ylabel, title)
255
265 z = numpy.ma.masked_invalid(z)
266 cmap=matplotlib.pyplot.get_cmap(colormap)
267 cmap.set_bad('white',1.)
256 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
268 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
269 ax.grid(True)
257
270
258 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
271 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
259
272
@@ -262,12 +275,13 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', col
262 ax.collections.remove(ax.collections[0])
275 ax.collections.remove(ax.collections[0])
263
276
264 z = numpy.ma.masked_invalid(z)
277 z = numpy.ma.masked_invalid(z)
265
278
266 cmap=matplotlib.pyplot.get_cmap(colormap)
279 cmap=matplotlib.pyplot.get_cmap(colormap)
267 cmap.set_bad('black', 1.)
280 cmap.set_bad('white',1.)
268
269
281
270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
282 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
283 ax.grid(True)
284
271
285
272 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
286 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
273 ticksize=9, xtick_visible=True, ytick_visible=True,
287 ticksize=9, xtick_visible=True, ytick_visible=True,
@@ -326,7 +340,7 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', tit
326
340
327 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
341 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
328
342
329 ax = iplot.axes
343 ax = iplot.get_axes()
330
344
331 printLabels(ax, xlabel, ylabel, title)
345 printLabels(ax, xlabel, ylabel, title)
332
346
@@ -403,8 +417,7 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel=''
403
417
404 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
418 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
405
419
406 ax = iplot.axes
420 ax = iplot.get_axes()
407
408 printLabels(ax, xlabel, ylabel, title)
421 printLabels(ax, xlabel, ylabel, title)
409
422
410 for i in range(len(ax.lines)):
423 for i in range(len(ax.lines)):
@@ -425,7 +438,7 def createPolar(ax, x, y,
425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
438 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
426 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
439 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
427 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
440 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
428 ax.yaxis.labelpad = 40
441 ax.yaxis.labelpad = 230
429 printLabels(ax, xlabel, ylabel, title)
442 printLabels(ax, xlabel, ylabel, title)
430 iplot = ax.lines[-1]
443 iplot = ax.lines[-1]
431
444
@@ -449,7 +462,7 def createPolar(ax, x, y,
449
462
450 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
463 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
451
464
452 ax = iplot.axes
465 ax = iplot.get_axes()
453
466
454 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
467 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
455 printLabels(ax, xlabel, ylabel, title)
468 printLabels(ax, xlabel, ylabel, title)
@@ -12,3 +12,10 from jroIO_usrp import *
12 from jroIO_kamisr import *
12 from jroIO_kamisr import *
13 from jroIO_param import *
13 from jroIO_param import *
14 from jroIO_hf import *
14 from jroIO_hf import *
15
16 from jroIO_madrigal import *
17
18 from bltrIO_param import *
19 from jroIO_bltr import *
20 from jroIO_mira35c import *
21
@@ -1432,11 +1432,12 class JRODataReader(JRODataIO):
1432 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1432 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1433
1433
1434 def printNumberOfBlock(self):
1434 def printNumberOfBlock(self):
1435 'SPAM!'
1435
1436
1436 if self.flagIsNewBlock:
1437 # if self.flagIsNewBlock:
1437 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1438 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1438 self.processingHeaderObj.dataBlocksPerFile,
1439 # self.processingHeaderObj.dataBlocksPerFile,
1439 self.dataOut.datatime.ctime())
1440 # self.dataOut.datatime.ctime())
1440
1441
1441 def printInfo(self):
1442 def printInfo(self):
1442
1443
@@ -178,8 +178,8 class ParamReader(ProcessingUnit):
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
179 print
179 print
180
180
181 for i in range(len(filenameList)):
181 # for i in range(len(filenameList)):
182 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
182 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
183
183
184 self.filenameList = filenameList
184 self.filenameList = filenameList
185 self.datetimeList = datetimeList
185 self.datetimeList = datetimeList
@@ -11,6 +11,7 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader,
11 from schainpy.model.data.jrodata import Spectra
11 from schainpy.model.data.jrodata import Spectra
12
12
13 class SpectraReader(JRODataReader, ProcessingUnit):
13 class SpectraReader(JRODataReader, ProcessingUnit):
14
14 """
15 """
15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
16 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
17 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
@@ -20,6 +21,7 class SpectraReader(JRODataReader, ProcessingUnit):
20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
21 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
21 canales * alturas (DC Channels)
22 canales * alturas (DC Channels)
22
23
24
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
25 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
26 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
27 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
@@ -74,6 +76,7 class SpectraReader(JRODataReader, ProcessingUnit):
74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
76 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
75
77
76 Inputs:
78 Inputs:
79
77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
80 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
78 almacenar un perfil de datos cada vez que se haga un requerimiento
81 almacenar un perfil de datos cada vez que se haga un requerimiento
79 (getData). El perfil sera obtenido a partir del buffer de datos,
82 (getData). El perfil sera obtenido a partir del buffer de datos,
@@ -81,104 +84,107 class SpectraReader(JRODataReader, ProcessingUnit):
81 bloque de datos.
84 bloque de datos.
82 Si este parametro no es pasado se creara uno internamente.
85 Si este parametro no es pasado se creara uno internamente.
83
86
84 Affected:
87
88 Affected:
89
85 self.dataOut
90 self.dataOut
86
91
87 Return : None
92 Return : None
88 """
93 """
89
94
95
90 #Eliminar de la base la herencia
96 #Eliminar de la base la herencia
91 ProcessingUnit.__init__(self, **kwargs)
97 ProcessingUnit.__init__(self, **kwargs)
92
98
93 # self.isConfig = False
99 # self.isConfig = False
94
100
95 self.pts2read_SelfSpectra = 0
101 self.pts2read_SelfSpectra = 0
96
102
97 self.pts2read_CrossSpectra = 0
103 self.pts2read_CrossSpectra = 0
98
104
99 self.pts2read_DCchannels = 0
105 self.pts2read_DCchannels = 0
100
106
101 self.datablock = None
107 self.datablock = None
102
108
103 self.utc = None
109 self.utc = None
104
110
105 self.ext = ".pdata"
111 self.ext = ".pdata"
106
112
107 self.optchar = "P"
113 self.optchar = "P"
108
114
109 self.basicHeaderObj = BasicHeader(LOCALTIME)
115 self.basicHeaderObj = BasicHeader(LOCALTIME)
110
116
111 self.systemHeaderObj = SystemHeader()
117 self.systemHeaderObj = SystemHeader()
112
118
113 self.radarControllerHeaderObj = RadarControllerHeader()
119 self.radarControllerHeaderObj = RadarControllerHeader()
114
120
115 self.processingHeaderObj = ProcessingHeader()
121 self.processingHeaderObj = ProcessingHeader()
116
122
117 self.online = 0
123 self.online = 0
118
124
119 self.fp = None
125 self.fp = None
120
126
121 self.idFile = None
127 self.idFile = None
122
128
123 self.dtype = None
129 self.dtype = None
124
130
125 self.fileSizeByHeader = None
131 self.fileSizeByHeader = None
126
132
127 self.filenameList = []
133 self.filenameList = []
128
134
129 self.filename = None
135 self.filename = None
130
136
131 self.fileSize = None
137 self.fileSize = None
132
138
133 self.firstHeaderSize = 0
139 self.firstHeaderSize = 0
134
140
135 self.basicHeaderSize = 24
141 self.basicHeaderSize = 24
136
142
137 self.pathList = []
143 self.pathList = []
138
144
139 self.lastUTTime = 0
145 self.lastUTTime = 0
140
146
141 self.maxTimeStep = 30
147 self.maxTimeStep = 30
142
148
143 self.flagNoMoreFiles = 0
149 self.flagNoMoreFiles = 0
144
150
145 self.set = 0
151 self.set = 0
146
152
147 self.path = None
153 self.path = None
148
154
149 self.delay = 60 #seconds
155 self.delay = 60 #seconds
150
156
151 self.nTries = 3 #quantity tries
157 self.nTries = 3 #quantity tries
152
158
153 self.nFiles = 3 #number of files for searching
159 self.nFiles = 3 #number of files for searching
154
160
155 self.nReadBlocks = 0
161 self.nReadBlocks = 0
156
162
157 self.flagIsNewFile = 1
163 self.flagIsNewFile = 1
158
164
159 self.__isFirstTimeOnline = 1
165 self.__isFirstTimeOnline = 1
160
166
161 # self.ippSeconds = 0
167 # self.ippSeconds = 0
162
168
163 self.flagDiscontinuousBlock = 0
169 self.flagDiscontinuousBlock = 0
164
170
165 self.flagIsNewBlock = 0
171 self.flagIsNewBlock = 0
166
172
167 self.nTotalBlocks = 0
173 self.nTotalBlocks = 0
168
174
169 self.blocksize = 0
175 self.blocksize = 0
170
176
171 self.dataOut = self.createObjByDefault()
177 self.dataOut = self.createObjByDefault()
172
178
173 self.profileIndex = 1 #Always
179 self.profileIndex = 1 #Always
174
180
175
181
176 def createObjByDefault(self):
182 def createObjByDefault(self):
177
183
178 dataObj = Spectra()
184 dataObj = Spectra()
179
185
180 return dataObj
186 return dataObj
181
187
182 def __hasNotDataInBuffer(self):
188 def __hasNotDataInBuffer(self):
183 return 1
189 return 1
184
190
@@ -186,7 +192,7 class SpectraReader(JRODataReader, ProcessingUnit):
186 def getBlockDimension(self):
192 def getBlockDimension(self):
187 """
193 """
188 Obtiene la cantidad de puntos a leer por cada bloque de datos
194 Obtiene la cantidad de puntos a leer por cada bloque de datos
189
195
190 Affected:
196 Affected:
191 self.nRdChannels
197 self.nRdChannels
192 self.nRdPairs
198 self.nRdPairs
@@ -206,37 +212,39 class SpectraReader(JRODataReader, ProcessingUnit):
206
212
207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
213 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
214 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
215 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
216
210 else:
217 else:
211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
218 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
219 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
213
220
214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
221 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
215
222
216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
223 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
217 self.blocksize = self.pts2read_SelfSpectra
224 self.blocksize = self.pts2read_SelfSpectra
218
225
219 if self.processingHeaderObj.flag_cspc:
226 if self.processingHeaderObj.flag_cspc:
220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
227 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
221 self.blocksize += self.pts2read_CrossSpectra
228 self.blocksize += self.pts2read_CrossSpectra
222
229
223 if self.processingHeaderObj.flag_dc:
230 if self.processingHeaderObj.flag_dc:
224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
231 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
225 self.blocksize += self.pts2read_DCchannels
232 self.blocksize += self.pts2read_DCchannels
226
233
227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
234 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
228
235
229
236
230 def readBlock(self):
237 def readBlock(self):
231 """
238 """
232 Lee el bloque de datos desde la posicion actual del puntero del archivo
239 Lee el bloque de datos desde la posicion actual del puntero del archivo
233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
240 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
241 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
235 es seteado a 0
242 es seteado a 0
236
243
237 Return: None
244 Return: None
238
245
239 Variables afectadas:
246 Variables afectadas:
247
240
248
241 self.flagIsNewFile
249 self.flagIsNewFile
242 self.flagIsNewBlock
250 self.flagIsNewBlock
@@ -245,9 +253,19 class SpectraReader(JRODataReader, ProcessingUnit):
245 self.data_cspc
253 self.data_cspc
246 self.data_dc
254 self.data_dc
247
255
248 Exceptions:
256 Exceptions:
249 Si un bloque leido no es un bloque valido
257 Si un bloque leido no es un bloque valido
250 """
258 """
259 print ' ======================================================== '
260 print ' '
261 print ' '
262 print self.processingHeaderObj.totalSpectra, 'TotalSpectra', type(self.processingHeaderObj.totalSpectra)
263 print self.processingHeaderObj.spectraComb, 'SpectraComb', type(self.processingHeaderObj.spectraComb)
264 print ' '
265 print ' '
266 print ' ======================================================== '
267
268
251 blockOk_flag = False
269 blockOk_flag = False
252 fpointer = self.fp.tell()
270 fpointer = self.fp.tell()
253
271
@@ -257,30 +275,32 class SpectraReader(JRODataReader, ProcessingUnit):
257 if self.processingHeaderObj.flag_cspc:
275 if self.processingHeaderObj.flag_cspc:
258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
276 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
277 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
260
278
261 if self.processingHeaderObj.flag_dc:
279 if self.processingHeaderObj.flag_dc:
262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
280 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
281 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
264
282
265
283
266 if not(self.processingHeaderObj.shif_fft):
284 if not(self.processingHeaderObj.shif_fft):
267 #desplaza a la derecha en el eje 2 determinadas posiciones
285 #desplaza a la derecha en el eje 2 determinadas posiciones
268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
286 shift = int(self.processingHeaderObj.profilesPerBlock/2)
269 spc = numpy.roll( spc, shift , axis=2 )
287 spc = numpy.roll( spc, shift , axis=2 )
270
288
271 if self.processingHeaderObj.flag_cspc:
289 if self.processingHeaderObj.flag_cspc:
272 #desplaza a la derecha en el eje 2 determinadas posiciones
290 #desplaza a la derecha en el eje 2 determinadas posiciones
273 cspc = numpy.roll( cspc, shift, axis=2 )
291 cspc = numpy.roll( cspc, shift, axis=2 )
274
292
275 #Dimensions : nChannels, nProfiles, nSamples
293 #Dimensions : nChannels, nProfiles, nSamples
276 spc = numpy.transpose( spc, (0,2,1) )
294 spc = numpy.transpose( spc, (0,2,1) )
277 self.data_spc = spc
295 self.data_spc = spc
296
297 if self.processingHeaderObj.flag_cspc:
278
298
279 if self.processingHeaderObj.flag_cspc:
280 cspc = numpy.transpose( cspc, (0,2,1) )
299 cspc = numpy.transpose( cspc, (0,2,1) )
281 self.data_cspc = cspc['real'] + cspc['imag']*1j
300 self.data_cspc = cspc['real'] + cspc['imag']*1j
282 else:
301 else:
283 self.data_cspc = None
302 self.data_cspc = None
303
284
304
285 if self.processingHeaderObj.flag_dc:
305 if self.processingHeaderObj.flag_dc:
286 self.data_dc = dc['real'] + dc['imag']*1j
306 self.data_dc = dc['real'] + dc['imag']*1j
@@ -294,60 +314,60 class SpectraReader(JRODataReader, ProcessingUnit):
294 self.nReadBlocks += 1
314 self.nReadBlocks += 1
295
315
296 return 1
316 return 1
297
317
298 def getFirstHeader(self):
318 def getFirstHeader(self):
299
319
300 self.getBasicHeader()
320 self.getBasicHeader()
301
321
302 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
322 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
303
323
304 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
324 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
305
325
306 # self.dataOut.ippSeconds = self.ippSeconds
326 # self.dataOut.ippSeconds = self.ippSeconds
307
327
308 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
328 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
309
329
310 self.dataOut.dtype = self.dtype
330 self.dataOut.dtype = self.dtype
311
331
312 # self.dataOut.nPairs = self.nPairs
332 # self.dataOut.nPairs = self.nPairs
313
333
314 self.dataOut.pairsList = self.rdPairList
334 self.dataOut.pairsList = self.rdPairList
315
335
316 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
336 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
317
337
318 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
338 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
319
339
320 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
340 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
321
341
322 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
342 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
323
343
324 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
344 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
325
345
326 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
346 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
327
347
328 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
348 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
329
349
330 self.dataOut.flagShiftFFT = True #Data is always shifted
350 self.dataOut.flagShiftFFT = True #Data is always shifted
331
351
332 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
352 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
333
353
334 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
354 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
335
355
336 def getData(self):
356 def getData(self):
337 """
357 """
338 First method to execute before "RUN" is called.
358 First method to execute before "RUN" is called.
339
359
340 Copia el buffer de lectura a la clase "Spectra",
360 Copia el buffer de lectura a la clase "Spectra",
341 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
361 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
342 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
362 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
343
363
344 Return:
364 Return:
345 0 : Si no hay mas archivos disponibles
365 0 : Si no hay mas archivos disponibles
346 1 : Si hizo una buena copia del buffer
366 1 : Si hizo una buena copia del buffer
347
367
348 Affected:
368 Affected:
349 self.dataOut
369 self.dataOut
350
370
351 self.flagDiscontinuousBlock
371 self.flagDiscontinuousBlock
352 self.flagIsNewBlock
372 self.flagIsNewBlock
353 """
373 """
@@ -356,68 +376,70 class SpectraReader(JRODataReader, ProcessingUnit):
356 self.dataOut.flagNoData = True
376 self.dataOut.flagNoData = True
357 print 'Process finished'
377 print 'Process finished'
358 return 0
378 return 0
359
379
360 self.flagDiscontinuousBlock = 0
380 self.flagDiscontinuousBlock = 0
361 self.flagIsNewBlock = 0
381 self.flagIsNewBlock = 0
362
382
363 if self.__hasNotDataInBuffer():
383 if self.__hasNotDataInBuffer():
364
384
365 if not( self.readNextBlock() ):
385 if not( self.readNextBlock() ):
366 self.dataOut.flagNoData = True
386 self.dataOut.flagNoData = True
367 return 0
387 return 0
388
368
389
369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
390 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
370
391
371 if self.data_spc is None:
392 if self.data_spc is None:
372 self.dataOut.flagNoData = True
393 self.dataOut.flagNoData = True
373 return 0
394 return 0
374
395
375 self.getBasicHeader()
396 self.getBasicHeader()
376
397
377 self.getFirstHeader()
398 self.getFirstHeader()
378
399
379 self.dataOut.data_spc = self.data_spc
400 self.dataOut.data_spc = self.data_spc
380
401
381 self.dataOut.data_cspc = self.data_cspc
402 self.dataOut.data_cspc = self.data_cspc
382
403
383 self.dataOut.data_dc = self.data_dc
404 self.dataOut.data_dc = self.data_dc
384
405
385 self.dataOut.flagNoData = False
406 self.dataOut.flagNoData = False
386
407
387 self.dataOut.realtime = self.online
408 self.dataOut.realtime = self.online
388
409
389 return self.dataOut.data_spc
410 return self.dataOut.data_spc
390
411
391 class SpectraWriter(JRODataWriter, Operation):
412 class SpectraWriter(JRODataWriter, Operation):
392
413
393 """
414 """
394 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
415 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
395 de los datos siempre se realiza por bloques.
416 de los datos siempre se realiza por bloques.
396 """
417 """
397
418
398 ext = ".pdata"
419 ext = ".pdata"
399
420
400 optchar = "P"
421 optchar = "P"
401
422
402 shape_spc_Buffer = None
423 shape_spc_Buffer = None
403
424
404 shape_cspc_Buffer = None
425 shape_cspc_Buffer = None
405
426
406 shape_dc_Buffer = None
427 shape_dc_Buffer = None
407
428
408 data_spc = None
429 data_spc = None
409
430
410 data_cspc = None
431 data_cspc = None
411
432
412 data_dc = None
433 data_dc = None
413
434
414 # dataOut = None
435 # dataOut = None
415
436
416 def __init__(self, **kwargs):
437 def __init__(self):
417 """
438 """
418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
439 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
440
441 Affected:
419
442
420 Affected:
421 self.dataOut
443 self.dataOut
422 self.basicHeaderObj
444 self.basicHeaderObj
423 self.systemHeaderObj
445 self.systemHeaderObj
@@ -426,49 +448,51 class SpectraWriter(JRODataWriter, Operation):
426
448
427 Return: None
449 Return: None
428 """
450 """
429
451
430 Operation.__init__(self, **kwargs)
452 Operation.__init__(self)
431
453
432 self.isConfig = False
454 self.isConfig = False
433
455
434 self.nTotalBlocks = 0
456 self.nTotalBlocks = 0
435
457
436 self.data_spc = None
458 self.data_spc = None
437
459
438 self.data_cspc = None
460 self.data_cspc = None
461
439
462
440 self.data_dc = None
463 self.data_dc = None
441
464
442 self.fp = None
465 self.fp = None
443
466
444 self.flagIsNewFile = 1
467 self.flagIsNewFile = 1
445
468
446 self.nTotalBlocks = 0
469 self.nTotalBlocks = 0
447
470
448 self.flagIsNewBlock = 0
471 self.flagIsNewBlock = 0
449
472
450 self.setFile = None
473 self.setFile = None
451
474
452 self.dtype = None
475 self.dtype = None
453
476
454 self.path = None
477 self.path = None
455
478
456 self.noMoreFiles = 0
479 self.noMoreFiles = 0
457
480
458 self.filename = None
481 self.filename = None
459
482
460 self.basicHeaderObj = BasicHeader(LOCALTIME)
483 self.basicHeaderObj = BasicHeader(LOCALTIME)
461
484
462 self.systemHeaderObj = SystemHeader()
485 self.systemHeaderObj = SystemHeader()
463
486
464 self.radarControllerHeaderObj = RadarControllerHeader()
487 self.radarControllerHeaderObj = RadarControllerHeader()
465
488
466 self.processingHeaderObj = ProcessingHeader()
489 self.processingHeaderObj = ProcessingHeader()
467
490
468
491
469 def hasAllDataInBuffer(self):
492 def hasAllDataInBuffer(self):
470 return 1
493 return 1
471
494
495
472
496
473 def setBlockDimension(self):
497 def setBlockDimension(self):
474 """
498 """
@@ -488,14 +512,15 class SpectraWriter(JRODataWriter, Operation):
488 self.shape_cspc_Buffer = (self.dataOut.nPairs,
512 self.shape_cspc_Buffer = (self.dataOut.nPairs,
489 self.processingHeaderObj.nHeights,
513 self.processingHeaderObj.nHeights,
490 self.processingHeaderObj.profilesPerBlock)
514 self.processingHeaderObj.profilesPerBlock)
491
515
492 self.shape_dc_Buffer = (self.dataOut.nChannels,
516 self.shape_dc_Buffer = (self.dataOut.nChannels,
493 self.processingHeaderObj.nHeights)
517 self.processingHeaderObj.nHeights)
494
518
495
519
496 def writeBlock(self):
520 def writeBlock(self):
497 """
521 """
498 Escribe el buffer en el file designado
522 Escribe el buffer en el file designado
523
499
524
500 Affected:
525 Affected:
501 self.data_spc
526 self.data_spc
@@ -504,11 +529,11 class SpectraWriter(JRODataWriter, Operation):
504 self.flagIsNewFile
529 self.flagIsNewFile
505 self.flagIsNewBlock
530 self.flagIsNewBlock
506 self.nTotalBlocks
531 self.nTotalBlocks
507 self.nWriteBlocks
532 self.nWriteBlocks
508
533
509 Return: None
534 Return: None
510 """
535 """
511
536
512 spc = numpy.transpose( self.data_spc, (0,2,1) )
537 spc = numpy.transpose( self.data_spc, (0,2,1) )
513 if not( self.processingHeaderObj.shif_fft ):
538 if not( self.processingHeaderObj.shif_fft ):
514 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
539 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
@@ -525,6 +550,7 class SpectraWriter(JRODataWriter, Operation):
525 data['imag'] = cspc.imag
550 data['imag'] = cspc.imag
526 data = data.reshape((-1))
551 data = data.reshape((-1))
527 data.tofile(self.fp)
552 data.tofile(self.fp)
553
528
554
529 if self.data_dc is not None:
555 if self.data_dc is not None:
530 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
556 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
@@ -535,145 +561,147 class SpectraWriter(JRODataWriter, Operation):
535 data.tofile(self.fp)
561 data.tofile(self.fp)
536
562
537 # self.data_spc.fill(0)
563 # self.data_spc.fill(0)
538 #
564 #
539 # if self.data_dc is not None:
565 # if self.data_dc is not None:
540 # self.data_dc.fill(0)
566 # self.data_dc.fill(0)
541 #
567 #
542 # if self.data_cspc is not None:
568 # if self.data_cspc is not None:
543 # self.data_cspc.fill(0)
569 # self.data_cspc.fill(0)
570
544
571
545 self.flagIsNewFile = 0
572 self.flagIsNewFile = 0
546 self.flagIsNewBlock = 1
573 self.flagIsNewBlock = 1
547 self.nTotalBlocks += 1
574 self.nTotalBlocks += 1
548 self.nWriteBlocks += 1
575 self.nWriteBlocks += 1
549 self.blockIndex += 1
576 self.blockIndex += 1
550
577
551 # print "[Writing] Block = %d04" %self.blockIndex
578 # print "[Writing] Block = %d04" %self.blockIndex
552
579
553 def putData(self):
580 def putData(self):
554 """
581 """
555 Setea un bloque de datos y luego los escribe en un file
582 Setea un bloque de datos y luego los escribe en un file
583
556
584
557 Affected:
585 Affected:
558 self.data_spc
586 self.data_spc
559 self.data_cspc
587 self.data_cspc
560 self.data_dc
588 self.data_dc
561
589
562 Return:
590 Return:
563 0 : Si no hay data o no hay mas files que puedan escribirse
591 0 : Si no hay data o no hay mas files que puedan escribirse
564 1 : Si se escribio la data de un bloque en un file
592 1 : Si se escribio la data de un bloque en un file
565 """
593 """
566
594
567 if self.dataOut.flagNoData:
595 if self.dataOut.flagNoData:
568 return 0
596 return 0
569
597
570 self.flagIsNewBlock = 0
598 self.flagIsNewBlock = 0
571
599
572 if self.dataOut.flagDiscontinuousBlock:
600 if self.dataOut.flagDiscontinuousBlock:
573 self.data_spc.fill(0)
601 self.data_spc.fill(0)
574 if self.dataOut.data_cspc is not None:
602 self.data_cspc.fill(0)
575 self.data_cspc.fill(0)
603 self.data_dc.fill(0)
576 if self.dataOut.data_dc is not None:
577 self.data_dc.fill(0)
578 self.setNextFile()
604 self.setNextFile()
579
605
580 if self.flagIsNewFile == 0:
606 if self.flagIsNewFile == 0:
581 self.setBasicHeader()
607 self.setBasicHeader()
582
608
583 self.data_spc = self.dataOut.data_spc.copy()
609 self.data_spc = self.dataOut.data_spc.copy()
584
610
585 if self.dataOut.data_cspc is not None:
611 if self.dataOut.data_cspc is not None:
586 self.data_cspc = self.dataOut.data_cspc.copy()
612 self.data_cspc = self.dataOut.data_cspc.copy()
587
613
588 if self.dataOut.data_dc is not None:
614 if self.dataOut.data_dc is not None:
589 self.data_dc = self.dataOut.data_dc.copy()
615 self.data_dc = self.dataOut.data_dc.copy()
590
616
591 # #self.processingHeaderObj.dataBlocksPerFile)
617 # #self.processingHeaderObj.dataBlocksPerFile)
592 if self.hasAllDataInBuffer():
618 if self.hasAllDataInBuffer():
593 # self.setFirstHeader()
619 # self.setFirstHeader()
594 self.writeNextBlock()
620 self.writeNextBlock()
595
621
596 return 1
622 return 1
623
597
624
598 def __getBlockSize(self):
625 def __getBlockSize(self):
599 '''
626 '''
600 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
627 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
601 '''
628 '''
602
629
603 dtype_width = self.getDtypeWidth()
630 dtype_width = self.getDtypeWidth()
604
631
605 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
632 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
606
633
607 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
634 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
608 blocksize = (pts2write_SelfSpectra*dtype_width)
635 blocksize = (pts2write_SelfSpectra*dtype_width)
609
636
610 if self.dataOut.data_cspc is not None:
637 if self.dataOut.data_cspc is not None:
611 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
638 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
612 blocksize += (pts2write_CrossSpectra*dtype_width*2)
639 blocksize += (pts2write_CrossSpectra*dtype_width*2)
613
640
614 if self.dataOut.data_dc is not None:
641 if self.dataOut.data_dc is not None:
615 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
642 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
616 blocksize += (pts2write_DCchannels*dtype_width*2)
643 blocksize += (pts2write_DCchannels*dtype_width*2)
617
644
618 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
645 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
619
646
620 return blocksize
647 return blocksize
621
648
622 def setFirstHeader(self):
649 def setFirstHeader(self):
623
650
624 """
651 """
625 Obtiene una copia del First Header
652 Obtiene una copia del First Header
626
653
627 Affected:
654 Affected:
628 self.systemHeaderObj
655 self.systemHeaderObj
629 self.radarControllerHeaderObj
656 self.radarControllerHeaderObj
630 self.dtype
657 self.dtype
631
658
632 Return:
659 Return:
633 None
660 None
634 """
661 """
635
662
636 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
663 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
637 self.systemHeaderObj.nChannels = self.dataOut.nChannels
664 self.systemHeaderObj.nChannels = self.dataOut.nChannels
638 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
665 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
639
666
640 self.processingHeaderObj.dtype = 1 # Spectra
667 self.processingHeaderObj.dtype = 1 # Spectra
641 self.processingHeaderObj.blockSize = self.__getBlockSize()
668 self.processingHeaderObj.blockSize = self.__getBlockSize()
642 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
669 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
643 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
670 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
644 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
671 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
645 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
672 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
646 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
673 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
647 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
674 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
648 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
675 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
676
649
677
650 if self.processingHeaderObj.totalSpectra > 0:
678 if self.processingHeaderObj.totalSpectra > 0:
651 channelList = []
679 channelList = []
652 for channel in range(self.dataOut.nChannels):
680 for channel in range(self.dataOut.nChannels):
653 channelList.append(channel)
681 channelList.append(channel)
654 channelList.append(channel)
682 channelList.append(channel)
655
683
656 pairsList = []
684 pairsList = []
657 if self.dataOut.nPairs > 0:
685 if self.dataOut.nPairs > 0:
658 for pair in self.dataOut.pairsList:
686 for pair in self.dataOut.pairsList:
659 pairsList.append(pair[0])
687 pairsList.append(pair[0])
660 pairsList.append(pair[1])
688 pairsList.append(pair[1])
661
689
662 spectraComb = channelList + pairsList
690 spectraComb = channelList + pairsList
663 spectraComb = numpy.array(spectraComb, dtype="u1")
691 spectraComb = numpy.array(spectraComb, dtype="u1")
664 self.processingHeaderObj.spectraComb = spectraComb
692 self.processingHeaderObj.spectraComb = spectraComb
665
693
666 if self.dataOut.code is not None:
694 if self.dataOut.code is not None:
667 self.processingHeaderObj.code = self.dataOut.code
695 self.processingHeaderObj.code = self.dataOut.code
668 self.processingHeaderObj.nCode = self.dataOut.nCode
696 self.processingHeaderObj.nCode = self.dataOut.nCode
669 self.processingHeaderObj.nBaud = self.dataOut.nBaud
697 self.processingHeaderObj.nBaud = self.dataOut.nBaud
670
698
671 if self.processingHeaderObj.nWindows != 0:
699 if self.processingHeaderObj.nWindows != 0:
672 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
700 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
673 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
701 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
674 self.processingHeaderObj.nHeights = self.dataOut.nHeights
702 self.processingHeaderObj.nHeights = self.dataOut.nHeights
675 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
703 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
676
704
677 self.processingHeaderObj.processFlags = self.getProcessFlags()
705 self.processingHeaderObj.processFlags = self.getProcessFlags()
678
706
679 self.setBasicHeader()
707 self.setBasicHeader()
@@ -527,10 +527,16 class VoltageReader(JRODataReader, ProcessingUnit):
527 self.dataOut.flagNoData = False
527 self.dataOut.flagNoData = False
528
528
529 self.getBasicHeader()
529 self.getBasicHeader()
530
530
531 #print self.basicHeaderObj.printInfo()
532 #print self.systemHeaderObj.printInfo()
533 #print self.radarControllerHeaderObj.printInfo()
534 #print self.processingHeaderObj.printInfo()
535
531 self.dataOut.realtime = self.online
536 self.dataOut.realtime = self.online
532
537
533 return self.dataOut.data
538 return self.dataOut.data
539
534
540
535 class VoltageWriter(JRODataWriter, Operation):
541 class VoltageWriter(JRODataWriter, Operation):
536 """
542 """
@@ -11,4 +11,5 from jroproc_amisr import *
11 from jroproc_correlation import *
11 from jroproc_correlation import *
12 from jroproc_parameters import *
12 from jroproc_parameters import *
13 from jroproc_spectra_lags import *
13 from jroproc_spectra_lags import *
14 from jroproc_spectra_acf import * No newline at end of file
14 from jroproc_spectra_acf import *
15 from bltrproc_parameters import *
This diff has been collapsed as it changes many lines, (2685 lines changed) Show them Hide them
@@ -1,39 +1,86
1 import numpy
1 import numpy
2 import math
2 import math
3 from scipy import optimize, interpolate, signal, stats, ndimage
3 from scipy import optimize, interpolate, signal, stats, ndimage
4 import scipy
4 import re
5 import re
5 import datetime
6 import datetime
6 import copy
7 import copy
7 import sys
8 import sys
8 import importlib
9 import importlib
9 import itertools
10 import itertools
10
11 from multiprocessing import Pool, TimeoutError
12 from multiprocessing.pool import ThreadPool
13 import copy_reg
14 import cPickle
15 import types
16 from functools import partial
17 import time
18 #from sklearn.cluster import KMeans
19
20 import matplotlib.pyplot as plt
21
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
11 from jroproc_base import ProcessingUnit, Operation
23 from jroproc_base import ProcessingUnit, Operation
12 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
24 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
25 from scipy import asarray as ar,exp
26 from scipy.optimize import curve_fit
13
27
28 import warnings
29 from numpy import NaN
30 from scipy.optimize.optimize import OptimizeWarning
31 warnings.filterwarnings('ignore')
14
32
15 class ParametersProc(ProcessingUnit):
16
33
34 SPEED_OF_LIGHT = 299792458
35
36
37 '''solving pickling issue'''
38
39 def _pickle_method(method):
40 func_name = method.im_func.__name__
41 obj = method.im_self
42 cls = method.im_class
43 return _unpickle_method, (func_name, obj, cls)
44
45 def _unpickle_method(func_name, obj, cls):
46 for cls in cls.mro():
47 try:
48 func = cls.__dict__[func_name]
49 except KeyError:
50 pass
51 else:
52 break
53 return func.__get__(obj, cls)
54
55
56
57
58
59
60
61
62 class ParametersProc(ProcessingUnit):
63
17 nSeconds = None
64 nSeconds = None
18
65
19 def __init__(self):
66 def __init__(self):
20 ProcessingUnit.__init__(self)
67 ProcessingUnit.__init__(self)
21
68
22 # self.objectDict = {}
69 # self.objectDict = {}
23 self.buffer = None
70 self.buffer = None
24 self.firstdatatime = None
71 self.firstdatatime = None
25 self.profIndex = 0
72 self.profIndex = 0
26 self.dataOut = Parameters()
73 self.dataOut = Parameters()
27
74
28 def __updateObjFromInput(self):
75 def __updateObjFromInput(self):
29
76
30 self.dataOut.inputUnit = self.dataIn.type
77 self.dataOut.inputUnit = self.dataIn.type
31
78
32 self.dataOut.timeZone = self.dataIn.timeZone
79 self.dataOut.timeZone = self.dataIn.timeZone
33 self.dataOut.dstFlag = self.dataIn.dstFlag
80 self.dataOut.dstFlag = self.dataIn.dstFlag
34 self.dataOut.errorCount = self.dataIn.errorCount
81 self.dataOut.errorCount = self.dataIn.errorCount
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
82 self.dataOut.useLocalTime = self.dataIn.useLocalTime
36
83
37 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
84 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
38 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
85 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
39 self.dataOut.channelList = self.dataIn.channelList
86 self.dataOut.channelList = self.dataIn.channelList
@@ -55,135 +102,1333 class ParametersProc(ProcessingUnit):
55 self.dataOut.ippSeconds = self.dataIn.ippSeconds
102 self.dataOut.ippSeconds = self.dataIn.ippSeconds
56 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
103 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
57 self.dataOut.timeInterval1 = self.dataIn.timeInterval
104 self.dataOut.timeInterval1 = self.dataIn.timeInterval
58 self.dataOut.heightList = self.dataIn.getHeiRange()
105 self.dataOut.heightList = self.dataIn.getHeiRange()
59 self.dataOut.frequency = self.dataIn.frequency
106 self.dataOut.frequency = self.dataIn.frequency
60 #self.dataOut.noise = self.dataIn.noise
107 self.dataOut.noise = self.dataIn.noise
61
108
109
110
62 def run(self):
111 def run(self):
63
112
64 #---------------------- Voltage Data ---------------------------
113 #---------------------- Voltage Data ---------------------------
65
114
66 if self.dataIn.type == "Voltage":
115 if self.dataIn.type == "Voltage":
67
116
68 self.__updateObjFromInput()
117 self.__updateObjFromInput()
69 self.dataOut.data_pre = self.dataIn.data.copy()
118 self.dataOut.data_pre = self.dataIn.data.copy()
70 self.dataOut.flagNoData = False
119 self.dataOut.flagNoData = False
71 self.dataOut.utctimeInit = self.dataIn.utctime
120 self.dataOut.utctimeInit = self.dataIn.utctime
72 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
121 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
73 return
122 return
74
123
75 #---------------------- Spectra Data ---------------------------
124 #---------------------- Spectra Data ---------------------------
76
125
77 if self.dataIn.type == "Spectra":
126 if self.dataIn.type == "Spectra":
78
127
79 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
128 self.dataOut.data_pre = (self.dataIn.data_spc,self.dataIn.data_cspc)
80 self.dataOut.data_spc = self.dataIn.data_spc
129 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
81 self.dataOut.data_cspc = self.dataIn.data_cspc
82 self.dataOut.nProfiles = self.dataIn.nProfiles
83 self.dataOut.nIncohInt = self.dataIn.nIncohInt
84 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
85 self.dataOut.ippFactor = self.dataIn.ippFactor
86 #self.dataOut.normFactor = self.dataIn.getNormFactor()
87 self.dataOut.pairsList = self.dataIn.pairsList
88 self.dataOut.groupList = self.dataIn.pairsList
89 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
130 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
131 self.dataOut.spc_noise = self.dataIn.getNoise()
132 self.dataOut.spc_range = (self.dataIn.getFreqRange(1)/1000. , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) )
133
134 self.dataOut.normFactor = self.dataIn.normFactor
135 #self.dataOut.outputInterval = self.dataIn.outputInterval
136 self.dataOut.groupList = self.dataIn.pairsList
90 self.dataOut.flagNoData = False
137 self.dataOut.flagNoData = False
91
138 #print 'datain chandist ',self.dataIn.ChanDist
139 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
140 self.dataOut.ChanDist = self.dataIn.ChanDist
141 else: self.dataOut.ChanDist = None
142
143 print 'datain chandist ',self.dataOut.ChanDist
144
145 if hasattr(self.dataIn, 'VelRange'): #Velocities range
146 self.dataOut.VelRange = self.dataIn.VelRange
147 else: self.dataOut.VelRange = None
148
149 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
150 self.dataOut.RadarConst = self.dataIn.RadarConst
151
152 if hasattr(self.dataIn, 'NPW'): #NPW
153 self.dataOut.NPW = self.dataIn.NPW
154
155 if hasattr(self.dataIn, 'COFA'): #COFA
156 self.dataOut.COFA = self.dataIn.COFA
157
158
159
92 #---------------------- Correlation Data ---------------------------
160 #---------------------- Correlation Data ---------------------------
93
161
94 if self.dataIn.type == "Correlation":
162 if self.dataIn.type == "Correlation":
95 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
163 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
96
164
97 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
165 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
98 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
166 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
99 self.dataOut.groupList = (acf_pairs, ccf_pairs)
167 self.dataOut.groupList = (acf_pairs, ccf_pairs)
100
168
101 self.dataOut.abscissaList = self.dataIn.lagRange
169 self.dataOut.abscissaList = self.dataIn.lagRange
102 self.dataOut.noise = self.dataIn.noise
170 self.dataOut.noise = self.dataIn.noise
103 self.dataOut.data_SNR = self.dataIn.SNR
171 self.dataOut.data_SNR = self.dataIn.SNR
104 self.dataOut.flagNoData = False
172 self.dataOut.flagNoData = False
105 self.dataOut.nAvg = self.dataIn.nAvg
173 self.dataOut.nAvg = self.dataIn.nAvg
106
174
107 #---------------------- Parameters Data ---------------------------
175 #---------------------- Parameters Data ---------------------------
108
176
109 if self.dataIn.type == "Parameters":
177 if self.dataIn.type == "Parameters":
110 self.dataOut.copy(self.dataIn)
178 self.dataOut.copy(self.dataIn)
111 self.dataOut.utctimeInit = self.dataIn.utctime
112 self.dataOut.flagNoData = False
179 self.dataOut.flagNoData = False
113
180
114 return True
181 return True
115
182
116 self.__updateObjFromInput()
183 self.__updateObjFromInput()
117 self.dataOut.utctimeInit = self.dataIn.utctime
184 self.dataOut.utctimeInit = self.dataIn.utctime
118 self.dataOut.paramInterval = self.dataIn.timeInterval
185 self.dataOut.paramInterval = self.dataIn.timeInterval
119
186
120 return
187 return
121
188
122 class SpectralMoments(Operation):
123
189
190 def target(tups):
191
192 obj, args = tups
193 #print 'TARGETTT', obj, args
194 return obj.FitGau(args)
195
196 class GaussianFit(Operation):
197
124 '''
198 '''
125 Function SpectralMoments()
199 Function that fit of one and two generalized gaussians (gg) based
200 on the PSD shape across an "power band" identified from a cumsum of
201 the measured spectrum - noise.
202
203 Input:
204 self.dataOut.data_pre : SelfSpectra
205
206 Output:
207 self.dataOut.GauSPC : SPC_ch1, SPC_ch2
208
209 '''
210 def __init__(self, **kwargs):
211 Operation.__init__(self, **kwargs)
212 self.i=0
213
214
215 def run(self, dataOut, num_intg=7, pnoise=1., vel_arr=None, SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
216 """This routine will find a couple of generalized Gaussians to a power spectrum
217 input: spc
218 output:
219 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
220 """
221
222 self.spc = dataOut.data_pre[0].copy()
223
224
225 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
226
227
228 #plt.figure(50)
229 #plt.subplot(121)
230 #plt.plot(self.spc,'k',label='spc(66)')
231 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
232 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
233 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
234 #plt.legend()
235 #plt.title('DATOS A ALTURA DE 7500 METROS')
236 #plt.show()
237
238 self.Num_Hei = self.spc.shape[2]
239 #self.Num_Bin = len(self.spc)
240 self.Num_Bin = self.spc.shape[1]
241 self.Num_Chn = self.spc.shape[0]
242
243 Vrange = dataOut.abscissaList
244
245 #print 'self.spc2', numpy.asarray(self.spc).shape
246
247 GauSPC = numpy.empty([2,self.Num_Bin,self.Num_Hei])
248 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
249 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
250 SPC_ch1[:] = numpy.NaN
251 SPC_ch2[:] = numpy.NaN
126
252
127 Calculates moments (power, mean, standard deviation) and SNR of the signal
253
254 start_time = time.time()
255
256 noise_ = dataOut.spc_noise[0].copy()
257
258
259
260 pool = Pool(processes=self.Num_Chn)
261 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
262 objs = [self for __ in range(self.Num_Chn)]
263 attrs = zip(objs, args)
264 gauSPC = pool.map(target, attrs)
265 dataOut.GauSPC = numpy.asarray(gauSPC)
266 # ret = []
267 # for n in range(self.Num_Chn):
268 # self.FitGau(args[n])
269 # dataOut.GauSPC = ret
270
271
272
273 # for ch in range(self.Num_Chn):
274 #
275 # for ht in range(self.Num_Hei):
276 # #print (numpy.asarray(self.spc).shape)
277 # spc = numpy.asarray(self.spc)[ch,:,ht]
278 #
279 # #############################################
280 # # normalizing spc and noise
281 # # This part differs from gg1
282 # spc_norm_max = max(spc)
283 # spc = spc / spc_norm_max
284 # pnoise = pnoise / spc_norm_max
285 # #############################################
286 #
287 # if abs(vel_arr[0])<15.0: # this switch is for spectra collected with different length IPP's
288 # fatspectra=1.0
289 # else:
290 # fatspectra=0.5
291 #
292 # wnoise = noise_ / spc_norm_max
293 # #print 'wnoise', noise_, dataOut.spc_noise[0], wnoise
294 # #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
295 # #if wnoise>1.1*pnoise: # to be tested later
296 # # wnoise=pnoise
297 # noisebl=wnoise*0.9; noisebh=wnoise*1.1
298 # spc=spc-wnoise
299 #
300 # minx=numpy.argmin(spc)
301 # spcs=numpy.roll(spc,-minx)
302 # cum=numpy.cumsum(spcs)
303 # tot_noise=wnoise * self.Num_Bin #64;
304 # #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
305 # #snr=tot_signal/tot_noise
306 # #snr=cum[-1]/tot_noise
307 #
308 # #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
309 #
310 # snr = sum(spcs)/tot_noise
311 # snrdB=10.*numpy.log10(snr)
312 #
313 # #if snrdB < -9 :
314 # # snrdB = numpy.NaN
315 # # continue
316 #
317 # #print 'snr',snrdB # , sum(spcs) , tot_noise
318 #
319 #
320 # #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
321 # # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
322 #
323 # cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
324 # cumlo=cummax*epsi;
325 # cumhi=cummax*(1-epsi)
326 # powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
327 #
328 # #if len(powerindex)==1:
329 # ##return [numpy.mod(powerindex[0]+minx,64),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
330 # #return [numpy.mod(powerindex[0]+minx, self.Num_Bin ),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
331 # #elif len(powerindex)<4*fatspectra:
332 # #return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
333 #
334 # if len(powerindex) < 1:# case for powerindex 0
335 # continue
336 # powerlo=powerindex[0]
337 # powerhi=powerindex[-1]
338 # powerwidth=powerhi-powerlo
339 #
340 # firstpeak=powerlo+powerwidth/10.# first gaussian energy location
341 # secondpeak=powerhi-powerwidth/10.#second gaussian energy location
342 # midpeak=(firstpeak+secondpeak)/2.
343 # firstamp=spcs[int(firstpeak)]
344 # secondamp=spcs[int(secondpeak)]
345 # midamp=spcs[int(midpeak)]
346 # #x=numpy.spc.shape[1]
347 #
348 # #x=numpy.arange(64)
349 # x=numpy.arange( self.Num_Bin )
350 # y_data=spc+wnoise
351 #
352 # # single gaussian
353 # #shift0=numpy.mod(midpeak+minx,64)
354 # shift0=numpy.mod(midpeak+minx, self.Num_Bin )
355 # width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
356 # power0=2.
357 # amplitude0=midamp
358 # state0=[shift0,width0,amplitude0,power0,wnoise]
359 # #bnds=((0,63),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
360 # bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
361 # #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(0.1,0.5))
362 # # bnds = range of fft, power width, amplitude, power, noise
363 # lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
364 #
365 # chiSq1=lsq1[1];
366 # jack1= self.y_jacobian1(x,lsq1[0])
367 #
368 #
369 # try:
370 # sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
371 # except:
372 # std1=32.; sigmas1=numpy.ones(5)
373 # else:
374 # std1=sigmas1[0]
375 #
376 #
377 # if fatspectra<1.0 and powerwidth<4:
378 # choice=0
379 # Amplitude0=lsq1[0][2]
380 # shift0=lsq1[0][0]
381 # width0=lsq1[0][1]
382 # p0=lsq1[0][3]
383 # Amplitude1=0.
384 # shift1=0.
385 # width1=0.
386 # p1=0.
387 # noise=lsq1[0][4]
388 # #return (numpy.array([shift0,width0,Amplitude0,p0]),
389 # # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
390 #
391 # # two gaussians
392 # #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
393 # shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
394 # shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
395 # width0=powerwidth/6.;
396 # width1=width0
397 # power0=2.;
398 # power1=power0
399 # amplitude0=firstamp;
400 # amplitude1=secondamp
401 # state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
402 # #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
403 # bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
404 # #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
405 #
406 # lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
407 #
408 #
409 # chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
410 #
411 #
412 # try:
413 # sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
414 # except:
415 # std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
416 # else:
417 # std2a=sigmas2[0]; std2b=sigmas2[4]
418 #
419 #
420 #
421 # oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
422 #
423 # if snrdB>-9: # when SNR is strong pick the peak with least shift (LOS velocity) error
424 # if oneG:
425 # choice=0
426 # else:
427 # w1=lsq2[0][1]; w2=lsq2[0][5]
428 # a1=lsq2[0][2]; a2=lsq2[0][6]
429 # p1=lsq2[0][3]; p2=lsq2[0][7]
430 # s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
431 # gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
432 #
433 # if gp1>gp2:
434 # if a1>0.7*a2:
435 # choice=1
436 # else:
437 # choice=2
438 # elif gp2>gp1:
439 # if a2>0.7*a1:
440 # choice=2
441 # else:
442 # choice=1
443 # else:
444 # choice=numpy.argmax([a1,a2])+1
445 # #else:
446 # #choice=argmin([std2a,std2b])+1
447 #
448 # else: # with low SNR go to the most energetic peak
449 # choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
450 #
451 # #print 'choice',choice
452 #
453 # if choice==0: # pick the single gaussian fit
454 # Amplitude0=lsq1[0][2]
455 # shift0=lsq1[0][0]
456 # width0=lsq1[0][1]
457 # p0=lsq1[0][3]
458 # Amplitude1=0.
459 # shift1=0.
460 # width1=0.
461 # p1=0.
462 # noise=lsq1[0][4]
463 # elif choice==1: # take the first one of the 2 gaussians fitted
464 # Amplitude0 = lsq2[0][2]
465 # shift0 = lsq2[0][0]
466 # width0 = lsq2[0][1]
467 # p0 = lsq2[0][3]
468 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
469 # shift1 = lsq2[0][4] # This is 0 in gg1
470 # width1 = lsq2[0][5] # This is 0 in gg1
471 # p1 = lsq2[0][7] # This is 0 in gg1
472 # noise = lsq2[0][8]
473 # else: # the second one
474 # Amplitude0 = lsq2[0][6]
475 # shift0 = lsq2[0][4]
476 # width0 = lsq2[0][5]
477 # p0 = lsq2[0][7]
478 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
479 # shift1 = lsq2[0][0] # This is 0 in gg1
480 # width1 = lsq2[0][1] # This is 0 in gg1
481 # p1 = lsq2[0][3] # This is 0 in gg1
482 # noise = lsq2[0][8]
483 #
484 # #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
485 # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
486 # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
487 # #print 'SPC_ch1.shape',SPC_ch1.shape
488 # #print 'SPC_ch2.shape',SPC_ch2.shape
489 # #dataOut.data_param = SPC_ch1
490 # GauSPC[0] = SPC_ch1
491 # GauSPC[1] = SPC_ch2
492
493 # #plt.gcf().clear()
494 # plt.figure(50+self.i)
495 # self.i=self.i+1
496 # #plt.subplot(121)
497 # plt.plot(self.spc,'k')#,label='spc(66)')
498 # plt.plot(SPC_ch1[ch,ht],'b')#,label='gg1')
499 # #plt.plot(SPC_ch2,'r')#,label='gg2')
500 # #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
501 # #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
502 # #plt.plot(xFrec,FitGauss,'yo:',label='fit')
503 # plt.legend()
504 # plt.title('DATOS A ALTURA DE 7500 METROS')
505 # plt.show()
506 # print 'shift0', shift0
507 # print 'Amplitude0', Amplitude0
508 # print 'width0', width0
509 # print 'p0', p0
510 # print '========================'
511 # print 'shift1', shift1
512 # print 'Amplitude1', Amplitude1
513 # print 'width1', width1
514 # print 'p1', p1
515 # print 'noise', noise
516 # print 's_noise', wnoise
517
518 print '========================================================'
519 print 'total_time: ', time.time()-start_time
520
521 # re-normalizing spc and noise
522 # This part differs from gg1
523
524
525
526 ''' Parameters:
527 1. Amplitude
528 2. Shift
529 3. Width
530 4. Power
531 '''
532
533
534 ###############################################################################
535 def FitGau(self, X):
536
537 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
538 #print 'VARSSSS', ch, pnoise, noise, num_intg
539
540 #print 'HEIGHTS', self.Num_Hei
541
542 GauSPC = []
543 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
544 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
545 SPC_ch1[:] = 0#numpy.NaN
546 SPC_ch2[:] = 0#numpy.NaN
547
548
549
550 for ht in range(self.Num_Hei):
551 #print (numpy.asarray(self.spc).shape)
552
553 #print 'TTTTT', ch , ht
554 #print self.spc.shape
555
556
557 spc = numpy.asarray(self.spc)[ch,:,ht]
558
559 #############################################
560 # normalizing spc and noise
561 # This part differs from gg1
562 spc_norm_max = max(spc)
563 spc = spc / spc_norm_max
564 pnoise = pnoise / spc_norm_max
565 #############################################
566
567 fatspectra=1.0
568
569 wnoise = noise_ / spc_norm_max
570 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
571 #if wnoise>1.1*pnoise: # to be tested later
572 # wnoise=pnoise
573 noisebl=wnoise*0.9; noisebh=wnoise*1.1
574 spc=spc-wnoise
575 # print 'wnoise', noise_[0], spc_norm_max, wnoise
576 minx=numpy.argmin(spc)
577 spcs=numpy.roll(spc,-minx)
578 cum=numpy.cumsum(spcs)
579 tot_noise=wnoise * self.Num_Bin #64;
580 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
581 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
582 #snr=tot_signal/tot_noise
583 #snr=cum[-1]/tot_noise
584 snr = sum(spcs)/tot_noise
585 snrdB=10.*numpy.log10(snr)
586
587 if snrdB < SNRlimit :
588 snr = numpy.NaN
589 SPC_ch1[:,ht] = 0#numpy.NaN
590 SPC_ch1[:,ht] = 0#numpy.NaN
591 GauSPC = (SPC_ch1,SPC_ch2)
592 continue
593 #print 'snr',snrdB #, sum(spcs) , tot_noise
594
595
596
597 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
598 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
599
600 cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
601 cumlo=cummax*epsi;
602 cumhi=cummax*(1-epsi)
603 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
604
605
606 if len(powerindex) < 1:# case for powerindex 0
607 continue
608 powerlo=powerindex[0]
609 powerhi=powerindex[-1]
610 powerwidth=powerhi-powerlo
611
612 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
613 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
614 midpeak=(firstpeak+secondpeak)/2.
615 firstamp=spcs[int(firstpeak)]
616 secondamp=spcs[int(secondpeak)]
617 midamp=spcs[int(midpeak)]
618
619 x=numpy.arange( self.Num_Bin )
620 y_data=spc+wnoise
621
622 # single gaussian
623 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
624 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
625 power0=2.
626 amplitude0=midamp
627 state0=[shift0,width0,amplitude0,power0,wnoise]
628 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
629 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
630
631 chiSq1=lsq1[1];
632 jack1= self.y_jacobian1(x,lsq1[0])
633
634
635 try:
636 sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
637 except:
638 std1=32.; sigmas1=numpy.ones(5)
639 else:
640 std1=sigmas1[0]
641
642
643 if fatspectra<1.0 and powerwidth<4:
644 choice=0
645 Amplitude0=lsq1[0][2]
646 shift0=lsq1[0][0]
647 width0=lsq1[0][1]
648 p0=lsq1[0][3]
649 Amplitude1=0.
650 shift1=0.
651 width1=0.
652 p1=0.
653 noise=lsq1[0][4]
654 #return (numpy.array([shift0,width0,Amplitude0,p0]),
655 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
656
657 # two gaussians
658 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
659 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
660 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
661 width0=powerwidth/6.;
662 width1=width0
663 power0=2.;
664 power1=power0
665 amplitude0=firstamp;
666 amplitude1=secondamp
667 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
668 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
669 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
670 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
671
672 lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
673
674
675 chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
676
677
678 try:
679 sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
680 except:
681 std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
682 else:
683 std2a=sigmas2[0]; std2b=sigmas2[4]
684
685
686
687 oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
688
689 if snrdB>-6: # when SNR is strong pick the peak with least shift (LOS velocity) error
690 if oneG:
691 choice=0
692 else:
693 w1=lsq2[0][1]; w2=lsq2[0][5]
694 a1=lsq2[0][2]; a2=lsq2[0][6]
695 p1=lsq2[0][3]; p2=lsq2[0][7]
696 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
697 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
698 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
699
700 if gp1>gp2:
701 if a1>0.7*a2:
702 choice=1
703 else:
704 choice=2
705 elif gp2>gp1:
706 if a2>0.7*a1:
707 choice=2
708 else:
709 choice=1
710 else:
711 choice=numpy.argmax([a1,a2])+1
712 #else:
713 #choice=argmin([std2a,std2b])+1
714
715 else: # with low SNR go to the most energetic peak
716 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
717
718
719 shift0=lsq2[0][0]; vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
720 shift1=lsq2[0][4]; vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
721
722 max_vel = 20
723
724 #first peak will be 0, second peak will be 1
725 if vel0 > 0 and vel0 < max_vel : #first peak is in the correct range
726 shift0=lsq2[0][0]
727 width0=lsq2[0][1]
728 Amplitude0=lsq2[0][2]
729 p0=lsq2[0][3]
730
731 shift1=lsq2[0][4]
732 width1=lsq2[0][5]
733 Amplitude1=lsq2[0][6]
734 p1=lsq2[0][7]
735 noise=lsq2[0][8]
736 else:
737 shift1=lsq2[0][0]
738 width1=lsq2[0][1]
739 Amplitude1=lsq2[0][2]
740 p1=lsq2[0][3]
741
742 shift0=lsq2[0][4]
743 width0=lsq2[0][5]
744 Amplitude0=lsq2[0][6]
745 p0=lsq2[0][7]
746 noise=lsq2[0][8]
747
748 if Amplitude0<0.1: # in case the peak is noise
749 shift0,width0,Amplitude0,p0 = 4*[numpy.NaN]
750 if Amplitude1<0.1:
751 shift1,width1,Amplitude1,p1 = 4*[numpy.NaN]
752
753
754 # if choice==0: # pick the single gaussian fit
755 # Amplitude0=lsq1[0][2]
756 # shift0=lsq1[0][0]
757 # width0=lsq1[0][1]
758 # p0=lsq1[0][3]
759 # Amplitude1=0.
760 # shift1=0.
761 # width1=0.
762 # p1=0.
763 # noise=lsq1[0][4]
764 # elif choice==1: # take the first one of the 2 gaussians fitted
765 # Amplitude0 = lsq2[0][2]
766 # shift0 = lsq2[0][0]
767 # width0 = lsq2[0][1]
768 # p0 = lsq2[0][3]
769 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
770 # shift1 = lsq2[0][4] # This is 0 in gg1
771 # width1 = lsq2[0][5] # This is 0 in gg1
772 # p1 = lsq2[0][7] # This is 0 in gg1
773 # noise = lsq2[0][8]
774 # else: # the second one
775 # Amplitude0 = lsq2[0][6]
776 # shift0 = lsq2[0][4]
777 # width0 = lsq2[0][5]
778 # p0 = lsq2[0][7]
779 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
780 # shift1 = lsq2[0][0] # This is 0 in gg1
781 # width1 = lsq2[0][1] # This is 0 in gg1
782 # p1 = lsq2[0][3] # This is 0 in gg1
783 # noise = lsq2[0][8]
784
785 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
786 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
787 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
788 #print 'SPC_ch1.shape',SPC_ch1.shape
789 #print 'SPC_ch2.shape',SPC_ch2.shape
790 #dataOut.data_param = SPC_ch1
791 GauSPC = (SPC_ch1,SPC_ch2)
792 #GauSPC[1] = SPC_ch2
793
794 # print 'shift0', shift0
795 # print 'Amplitude0', Amplitude0
796 # print 'width0', width0
797 # print 'p0', p0
798 # print '========================'
799 # print 'shift1', shift1
800 # print 'Amplitude1', Amplitude1
801 # print 'width1', width1
802 # print 'p1', p1
803 # print 'noise', noise
804 # print 's_noise', wnoise
805
806 return GauSPC
807
808
809 def y_jacobian1(self,x,state): # This function is for further analysis of generalized Gaussians, it is not too importan for the signal discrimination.
810 y_model=self.y_model1(x,state)
811 s0,w0,a0,p0,n=state
812 e0=((x-s0)/w0)**2;
813
814 e0u=((x-s0-self.Num_Bin)/w0)**2;
815
816 e0d=((x-s0+self.Num_Bin)/w0)**2
817 m0=numpy.exp(-0.5*e0**(p0/2.));
818 m0u=numpy.exp(-0.5*e0u**(p0/2.));
819 m0d=numpy.exp(-0.5*e0d**(p0/2.))
820 JA=m0+m0u+m0d
821 JP=(-1/4.)*a0*m0*e0**(p0/2.)*numpy.log(e0)+(-1/4.)*a0*m0u*e0u**(p0/2.)*numpy.log(e0u)+(-1/4.)*a0*m0d*e0d**(p0/2.)*numpy.log(e0d)
822
823 JS=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)
824
825 JW=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)**2+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)**2+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)**2
826 jack1=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,1./y_model])
827 return jack1.T
828
829 def y_jacobian2(self,x,state):
830 y_model=self.y_model2(x,state)
831 s0,w0,a0,p0,s1,w1,a1,p1,n=state
832 e0=((x-s0)/w0)**2;
833
834 e0u=((x-s0- self.Num_Bin )/w0)**2;
835
836 e0d=((x-s0+ self.Num_Bin )/w0)**2
837 e1=((x-s1)/w1)**2;
838
839 e1u=((x-s1- self.Num_Bin )/w1)**2;
840
841 e1d=((x-s1+ self.Num_Bin )/w1)**2
842 m0=numpy.exp(-0.5*e0**(p0/2.));
843 m0u=numpy.exp(-0.5*e0u**(p0/2.));
844 m0d=numpy.exp(-0.5*e0d**(p0/2.))
845 m1=numpy.exp(-0.5*e1**(p1/2.));
846 m1u=numpy.exp(-0.5*e1u**(p1/2.));
847 m1d=numpy.exp(-0.5*e1d**(p1/2.))
848 JA=m0+m0u+m0d
849 JA1=m1+m1u+m1d
850 JP=(-1/4.)*a0*m0*e0**(p0/2.)*numpy.log(e0)+(-1/4.)*a0*m0u*e0u**(p0/2.)*numpy.log(e0u)+(-1/4.)*a0*m0d*e0d**(p0/2.)*numpy.log(e0d)
851 JP1=(-1/4.)*a1*m1*e1**(p1/2.)*numpy.log(e1)+(-1/4.)*a1*m1u*e1u**(p1/2.)*numpy.log(e1u)+(-1/4.)*a1*m1d*e1d**(p1/2.)*numpy.log(e1d)
852
853 JS=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)
854
855 JS1=(p1/w1/2.)*a1*m1*e1**(p1/2.-1)*((x-s1)/w1)+(p1/w1/2.)*a1*m1u*e1u**(p1/2.-1)*((x-s1- self.Num_Bin )/w1)+(p1/w1/2.)*a1*m1d*e1d**(p1/2.-1)*((x-s1+ self.Num_Bin )/w1)
856
857 JW=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)**2+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)**2+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)**2
858
859 JW1=(p1/w1/2.)*a1*m1*e1**(p1/2.-1)*((x-s1)/w1)**2+(p1/w1/2.)*a1*m1u*e1u**(p1/2.-1)*((x-s1- self.Num_Bin )/w1)**2+(p1/w1/2.)*a1*m1d*e1d**(p1/2.-1)*((x-s1+ self.Num_Bin )/w1)**2
860 jack2=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,JS1/y_model,JW1/y_model,JA1/y_model,JP1/y_model,1./y_model])
861 return jack2.T
862
863 def y_model1(self,x,state):
864 shift0,width0,amplitude0,power0,noise=state
865 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
866
867 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
868
869 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
870 return model0+model0u+model0d+noise
871
872 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
873 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
874 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
875
876 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
877
878 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
879 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
880
881 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
882
883 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
884 return model0+model0u+model0d+model1+model1u+model1d+noise
885
886 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
128
887
129 Type of dataIn: Spectra
888 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
889
890 def misfit2(self,state,y_data,x,num_intg):
891 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
892
130
893
131 Configuration Parameters:
894 class PrecipitationProc(Operation):
895
896 '''
897 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
898
899 Input:
900 self.dataOut.data_pre : SelfSpectra
901
902 Output:
903
904 self.dataOut.data_output : Reflectivity factor, rainfall Rate
905
906
907 Parameters affected:
908 '''
909
910
911 def run(self, dataOut, radar=None, Pt=None, Gt=None, Gr=None, Lambda=None, aL=None,
912 tauW=None, ThetaT=None, ThetaR=None, Km = 0.93, Altitude=None):
913
914 self.spc = dataOut.data_pre[0].copy()
915 self.Num_Hei = self.spc.shape[2]
916 self.Num_Bin = self.spc.shape[1]
917 self.Num_Chn = self.spc.shape[0]
918
919 Velrange = dataOut.abscissaList
920
921 if radar == "MIRA35C" :
922
923 Ze = self.dBZeMODE2(dataOut)
924
925 else:
926
927 self.Pt = Pt
928 self.Gt = Gt
929 self.Gr = Gr
930 self.Lambda = Lambda
931 self.aL = aL
932 self.tauW = tauW
933 self.ThetaT = ThetaT
934 self.ThetaR = ThetaR
935
936 RadarConstant = GetRadarConstant()
937 SPCmean = numpy.mean(self.spc,0)
938 ETA = numpy.zeros(self.Num_Hei)
939 Pr = numpy.sum(SPCmean,0)
940
941 #for R in range(self.Num_Hei):
942 # ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
943
944 D_range = numpy.zeros(self.Num_Hei)
945 EqSec = numpy.zeros(self.Num_Hei)
946 del_V = numpy.zeros(self.Num_Hei)
947
948 for R in range(self.Num_Hei):
949 ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
950
951 h = R + Altitude #Range from ground to radar pulse altitude
952 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
953
954 D_range[R] = numpy.log( (9.65 - (Velrange[R]/del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
955 SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma)
956
957 N_dist[R] = ETA[R] / SIGMA[R]
958
959 Ze = (ETA * Lambda**4) / (numpy.pi * Km)
960 Z = numpy.sum( N_dist * D_range**6 )
961 RR = 6*10**-4*numpy.pi * numpy.sum( D_range**3 * N_dist * Velrange ) #Rainfall rate
962
963
964 RR = (Ze/200)**(1/1.6)
965 dBRR = 10*numpy.log10(RR)
966
967 dBZe = 10*numpy.log10(Ze)
968 dataOut.data_output = Ze
969 dataOut.data_param = numpy.ones([2,self.Num_Hei])
970 dataOut.channelList = [0,1]
971 print 'channelList', dataOut.channelList
972 dataOut.data_param[0]=dBZe
973 dataOut.data_param[1]=dBRR
974 print 'RR SHAPE', dBRR.shape
975 print 'Ze SHAPE', dBZe.shape
976 print 'dataOut.data_param SHAPE', dataOut.data_param.shape
977
978
979 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
980
981 NPW = dataOut.NPW
982 COFA = dataOut.COFA
983
984 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
985 RadarConst = dataOut.RadarConst
986 #frequency = 34.85*10**9
987
988 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
989 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
990
991 ETA = numpy.sum(SNR,1)
992 print 'ETA' , ETA
993 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
994
995 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
996
997 for r in range(self.Num_Hei):
998
999 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
1000 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
1001
1002 return Ze
1003
1004 def GetRadarConstant(self):
1005
1006 """
1007 Constants:
1008
1009 Pt: Transmission Power dB
1010 Gt: Transmission Gain dB
1011 Gr: Reception Gain dB
1012 Lambda: Wavelenght m
1013 aL: Attenuation loses dB
1014 tauW: Width of transmission pulse s
1015 ThetaT: Transmission antenna bean angle rad
1016 ThetaR: Reception antenna beam angle rad
1017
1018 """
1019 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
1020 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
1021 RadarConstant = Numerator / Denominator
1022
1023 return RadarConstant
1024
1025
1026
1027 class FullSpectralAnalysis(Operation):
1028
1029 """
1030 Function that implements Full Spectral Analisys technique.
1031
1032 Input:
1033 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
1034 self.dataOut.groupList : Pairlist of channels
1035 self.dataOut.ChanDist : Physical distance between receivers
1036
1037
1038 Output:
1039
1040 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
1041
1042
1043 Parameters affected: Winds, height range, SNR
1044
1045 """
1046 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
1047
1048 spc = dataOut.data_pre[0].copy()
1049 cspc = dataOut.data_pre[1].copy()
1050
1051 nChannel = spc.shape[0]
1052 nProfiles = spc.shape[1]
1053 nHeights = spc.shape[2]
1054
1055 pairsList = dataOut.groupList
1056 if dataOut.ChanDist is not None :
1057 ChanDist = dataOut.ChanDist
1058 else:
1059 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
1060
1061 #print 'ChanDist', ChanDist
1062
1063 if dataOut.VelRange is not None:
1064 VelRange= dataOut.VelRange
1065 else:
1066 VelRange= dataOut.abscissaList
1067
1068 ySamples=numpy.ones([nChannel,nProfiles])
1069 phase=numpy.ones([nChannel,nProfiles])
1070 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
1071 coherence=numpy.ones([nChannel,nProfiles])
1072 PhaseSlope=numpy.ones(nChannel)
1073 PhaseInter=numpy.ones(nChannel)
1074 dataSNR = dataOut.data_SNR
1075
1076
1077
1078 data = dataOut.data_pre
1079 noise = dataOut.noise
1080 print 'noise',noise
1081 #SNRdB = 10*numpy.log10(dataOut.data_SNR)
1082
1083 FirstMoment = numpy.average(dataOut.data_param[:,1,:],0)
1084 #SNRdBMean = []
132
1085
1086
1087 #for j in range(nHeights):
1088 # FirstMoment = numpy.append(FirstMoment,numpy.mean([dataOut.data_param[0,1,j],dataOut.data_param[1,1,j],dataOut.data_param[2,1,j]]))
1089 # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]]))
1090
1091 data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN
1092
1093 velocityX=[]
1094 velocityY=[]
1095 velocityV=[]
1096
1097 dbSNR = 10*numpy.log10(dataSNR)
1098 dbSNR = numpy.average(dbSNR,0)
1099 for Height in range(nHeights):
1100
1101 [Vzon,Vmer,Vver, GaussCenter]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR[Height], SNRlimit)
1102
1103 if abs(Vzon)<100. and abs(Vzon)> 0.:
1104 velocityX=numpy.append(velocityX, Vzon)#Vmag
1105
1106 else:
1107 print 'Vzon',Vzon
1108 velocityX=numpy.append(velocityX, numpy.NaN)
1109
1110 if abs(Vmer)<100. and abs(Vmer) > 0.:
1111 velocityY=numpy.append(velocityY, Vmer)#Vang
1112
1113 else:
1114 print 'Vmer',Vmer
1115 velocityY=numpy.append(velocityY, numpy.NaN)
1116
1117 if dbSNR[Height] > SNRlimit:
1118 velocityV=numpy.append(velocityV, FirstMoment[Height])
1119 else:
1120 velocityV=numpy.append(velocityV, numpy.NaN)
1121 #FirstMoment[Height]= numpy.NaN
1122 # if SNRdBMean[Height] <12:
1123 # FirstMoment[Height] = numpy.NaN
1124 # velocityX[Height] = numpy.NaN
1125 # velocityY[Height] = numpy.NaN
1126
1127
1128 data_output[0]=numpy.array(velocityX)
1129 data_output[1]=numpy.array(velocityY)
1130 data_output[2]=-velocityV#FirstMoment
1131
1132 print ' '
1133 #print 'FirstMoment'
1134 #print FirstMoment
1135 print 'velocityX',data_output[0]
1136 print ' '
1137 print 'velocityY',data_output[1]
1138 #print numpy.array(velocityY)
1139 print ' '
1140 #print 'SNR'
1141 #print 10*numpy.log10(dataOut.data_SNR)
1142 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1143 print ' '
1144
1145
1146 dataOut.data_output=data_output
1147 return
1148
1149
1150 def moving_average(self,x, N=2):
1151 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1152
1153 def gaus(self,xSamples,a,x0,sigma):
1154 return a*numpy.exp(-(xSamples-x0)**2/(2*sigma**2))
1155
1156 def Find(self,x,value):
1157 for index in range(len(x)):
1158 if x[index]==value:
1159 return index
1160
1161 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR, SNRlimit):
1162
1163 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1164 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1165 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1166 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1167 PhaseSlope=numpy.ones(spc.shape[0])
1168 PhaseInter=numpy.ones(spc.shape[0])
1169 xFrec=VelRange
1170
1171 '''Getting Eij and Nij'''
1172
1173 E01=ChanDist[0][0]
1174 N01=ChanDist[0][1]
1175
1176 E02=ChanDist[1][0]
1177 N02=ChanDist[1][1]
1178
1179 E12=ChanDist[2][0]
1180 N12=ChanDist[2][1]
1181
1182 z = spc.copy()
1183 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1184
1185 for i in range(spc.shape[0]):
1186
1187 '''****** Line of Data SPC ******'''
1188 zline=z[i,:,Height]
1189
1190 '''****** SPC is normalized ******'''
1191 FactNorm= (zline.copy()-noise[i]) / numpy.sum(zline.copy())
1192 FactNorm= FactNorm/numpy.sum(FactNorm)
1193
1194 SmoothSPC=self.moving_average(FactNorm,N=3)
1195
1196 xSamples = ar(range(len(SmoothSPC)))
1197 ySamples[i] = SmoothSPC
1198
1199 #dbSNR=10*numpy.log10(dataSNR)
1200 print ' '
1201 print ' '
1202 print ' '
1203
1204 #print 'dataSNR', dbSNR.shape, dbSNR[0,40:120]
1205 print 'SmoothSPC', SmoothSPC.shape, SmoothSPC[0:20]
1206 print 'noise',noise
1207 print 'zline',zline.shape, zline[0:20]
1208 print 'FactNorm',FactNorm.shape, FactNorm[0:20]
1209 print 'FactNorm suma', numpy.sum(FactNorm)
1210
1211 for i in range(spc.shape[0]):
1212
1213 '''****** Line of Data CSPC ******'''
1214 cspcLine=cspc[i,:,Height].copy()
1215
1216 '''****** CSPC is normalized ******'''
1217 chan_index0 = pairsList[i][0]
1218 chan_index1 = pairsList[i][1]
1219 CSPCFactor= abs(numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])) #
1220
1221 CSPCNorm = (cspcLine.copy() -noise[i]) / numpy.sqrt(CSPCFactor)
1222
1223 CSPCSamples[i] = CSPCNorm
1224 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1225
1226 coherence[i]= self.moving_average(coherence[i],N=2)
1227
1228 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1229
1230 print 'cspcLine', cspcLine.shape, cspcLine[0:20]
1231 print 'CSPCFactor', CSPCFactor#, CSPCFactor[0:20]
1232 print numpy.sum(ySamples[chan_index0]), numpy.sum(ySamples[chan_index1]), -noise[i]
1233 print 'CSPCNorm', CSPCNorm.shape, CSPCNorm[0:20]
1234 print 'CSPCNorm suma', numpy.sum(CSPCNorm)
1235 print 'CSPCSamples', CSPCSamples.shape, CSPCSamples[0,0:20]
1236
1237 '''****** Getting fij width ******'''
1238
1239 yMean=[]
1240 yMean2=[]
1241
1242 for j in range(len(ySamples[1])):
1243 yMean=numpy.append(yMean,numpy.mean([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
1244
1245 '''******* Getting fitting Gaussian ******'''
1246 meanGauss=sum(xSamples*yMean) / len(xSamples)
1247 sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
1248
1249 print '****************************'
1250 print 'len(xSamples): ',len(xSamples)
1251 print 'yMean: ', yMean.shape, yMean[0:20]
1252 print 'ySamples', ySamples.shape, ySamples[0,0:20]
1253 print 'xSamples: ',xSamples.shape, xSamples[0:20]
1254
1255 print 'meanGauss',meanGauss
1256 print 'sigma',sigma
1257
1258 #if (abs(meanGauss/sigma**2) > 0.0001) : #0.000000001):
1259 if dbSNR > SNRlimit :
1260 try:
1261 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
1262
1263 if numpy.amax(popt)>numpy.amax(yMean)*0.3:
1264 FitGauss=self.gaus(xSamples,*popt)
1265
1266 else:
1267 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1268 print 'Verificador: Dentro', Height
1269 except :#RuntimeError:
1270 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1271
1272
1273 else:
1274 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1275
1276 Maximun=numpy.amax(yMean)
1277 eMinus1=Maximun*numpy.exp(-1)#*0.8
1278
1279 HWpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
1280 HalfWidth= xFrec[HWpos]
1281 GCpos=self.Find(FitGauss, numpy.amax(FitGauss))
1282 Vpos=self.Find(FactNorm, numpy.amax(FactNorm))
1283
1284 #Vpos=FirstMoment[]
1285
1286 '''****** Getting Fij ******'''
1287
1288 GaussCenter=xFrec[GCpos]
1289 if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
1290 Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
1291 else:
1292 Fij=abs(GaussCenter-HalfWidth)+0.0000001
1293
1294 '''****** Getting Frecuency range of significant data ******'''
1295
1296 Rangpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
1297
1298 if Rangpos<GCpos:
1299 Range=numpy.array([Rangpos,2*GCpos-Rangpos])
1300 elif Rangpos< ( len(xFrec)- len(xFrec)*0.1):
1301 Range=numpy.array([2*GCpos-Rangpos,Rangpos])
1302 else:
1303 Range = numpy.array([0,0])
1304
1305 print ' '
1306 print 'GCpos',GCpos, ( len(xFrec)- len(xFrec)*0.1)
1307 print 'Rangpos',Rangpos
1308 print 'RANGE: ', Range
1309 FrecRange=xFrec[Range[0]:Range[1]]
1310
1311 '''****** Getting SCPC Slope ******'''
1312
1313 for i in range(spc.shape[0]):
1314
1315 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.5:
1316 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1317
1318 print 'FrecRange', len(FrecRange) , FrecRange
1319 print 'PhaseRange', len(PhaseRange), PhaseRange
1320 print ' '
1321 if len(FrecRange) == len(PhaseRange):
1322 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
1323 PhaseSlope[i]=slope
1324 PhaseInter[i]=intercept
1325 else:
1326 PhaseSlope[i]=0
1327 PhaseInter[i]=0
1328 else:
1329 PhaseSlope[i]=0
1330 PhaseInter[i]=0
1331
1332 '''Getting constant C'''
1333 cC=(Fij*numpy.pi)**2
1334
1335 '''****** Getting constants F and G ******'''
1336 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1337 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1338 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1339 MijResults=numpy.array([MijResult0,MijResult1])
1340 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1341
1342 '''****** Getting constants A, B and H ******'''
1343 W01=numpy.amax(coherence[0])
1344 W02=numpy.amax(coherence[1])
1345 W12=numpy.amax(coherence[2])
1346
1347 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1348 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1349 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1350
1351 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1352
1353 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1354 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1355
1356 VxVy=numpy.array([[cA,cH],[cH,cB]])
1357
1358 VxVyResults=numpy.array([-cF,-cG])
1359 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1360
1361 Vzon = Vy
1362 Vmer = Vx
1363 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1364 Vang=numpy.arctan2(Vmer,Vzon)
1365 Vver=xFrec[Vpos]
1366 print 'vzon y vmer', Vzon, Vmer
1367 return Vzon, Vmer, Vver, GaussCenter
1368
1369 class SpectralMoments(Operation):
1370
1371 '''
1372 Function SpectralMoments()
1373
1374 Calculates moments (power, mean, standard deviation) and SNR of the signal
1375
1376 Type of dataIn: Spectra
1377
1378 Configuration Parameters:
1379
133 dirCosx : Cosine director in X axis
1380 dirCosx : Cosine director in X axis
134 dirCosy : Cosine director in Y axis
1381 dirCosy : Cosine director in Y axis
135
1382
136 elevation :
1383 elevation :
137 azimuth :
1384 azimuth :
138
1385
139 Input:
1386 Input:
140 channelList : simple channel list to select e.g. [2,3,7]
1387 channelList : simple channel list to select e.g. [2,3,7]
141 self.dataOut.data_pre : Spectral data
1388 self.dataOut.data_pre : Spectral data
142 self.dataOut.abscissaList : List of frequencies
1389 self.dataOut.abscissaList : List of frequencies
143 self.dataOut.noise : Noise level per channel
1390 self.dataOut.noise : Noise level per channel
144
1391
145 Affected:
1392 Affected:
146 self.dataOut.data_param : Parameters per channel
1393 self.dataOut.data_param : Parameters per channel
147 self.dataOut.data_SNR : SNR per channel
1394 self.dataOut.data_SNR : SNR per channel
148
1395
149 '''
1396 '''
150
1397
151 def run(self, dataOut):
1398 def run(self, dataOut):
152
1399
153 #dataOut.data_pre = dataOut.data_pre[0]
1400 #dataOut.data_pre = dataOut.data_pre[0]
154 data = dataOut.data_pre[0]
1401 data = dataOut.data_pre[0]
155 absc = dataOut.abscissaList[:-1]
1402 absc = dataOut.abscissaList[:-1]
156 noise = dataOut.noise
1403 noise = dataOut.noise
157 nChannel = data.shape[0]
1404 nChannel = data.shape[0]
158 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1405 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
159
1406
160 for ind in range(nChannel):
1407 for ind in range(nChannel):
161 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
1408 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
162
1409
163 dataOut.data_param = data_param[:,1:,:]
1410 dataOut.data_param = data_param[:,1:,:]
164 dataOut.data_SNR = data_param[:,0]
1411 dataOut.data_SNR = data_param[:,0]
165 dataOut.data_DOP = data_param[:,1]
166 dataOut.data_MEAN = data_param[:,2]
167 dataOut.data_STD = data_param[:,3]
168 return
1412 return
169
1413
170 def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1414 def __calculateMoments(self, oldspec, oldfreq, n0,
171
1415 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
172 if (nicoh is None): nicoh = 1
1416
173 if (graph is None): graph = 0
1417 if (nicoh == None): nicoh = 1
174 if (smooth is None): smooth = 0
1418 if (graph == None): graph = 0
1419 if (smooth == None): smooth = 0
175 elif (self.smooth < 3): smooth = 0
1420 elif (self.smooth < 3): smooth = 0
176
1421
177 if (type1 is None): type1 = 0
1422 if (type1 == None): type1 = 0
178 if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1
1423 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
179 if (snrth is None): snrth = -3
1424 if (snrth == None): snrth = -3
180 if (dc is None): dc = 0
1425 if (dc == None): dc = 0
181 if (aliasing is None): aliasing = 0
1426 if (aliasing == None): aliasing = 0
182 if (oldfd is None): oldfd = 0
1427 if (oldfd == None): oldfd = 0
183 if (wwauto is None): wwauto = 0
1428 if (wwauto == None): wwauto = 0
184
1429
185 if (n0 < 1.e-20): n0 = 1.e-20
1430 if (n0 < 1.e-20): n0 = 1.e-20
186
1431
187 freq = oldfreq
1432 freq = oldfreq
188 vec_power = numpy.zeros(oldspec.shape[1])
1433 vec_power = numpy.zeros(oldspec.shape[1])
189 vec_fd = numpy.zeros(oldspec.shape[1])
1434 vec_fd = numpy.zeros(oldspec.shape[1])
@@ -191,86 +1436,86 class SpectralMoments(Operation):
191 vec_snr = numpy.zeros(oldspec.shape[1])
1436 vec_snr = numpy.zeros(oldspec.shape[1])
192
1437
193 for ind in range(oldspec.shape[1]):
1438 for ind in range(oldspec.shape[1]):
194
1439
195 spec = oldspec[:,ind]
1440 spec = oldspec[:,ind]
196 aux = spec*fwindow
1441 aux = spec*fwindow
197 max_spec = aux.max()
1442 max_spec = aux.max()
198 m = list(aux).index(max_spec)
1443 m = list(aux).index(max_spec)
199
1444
200 #Smooth
1445 #Smooth
201 if (smooth == 0): spec2 = spec
1446 if (smooth == 0): spec2 = spec
202 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1447 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
203
1448
204 # Calculo de Momentos
1449 # Calculo de Momentos
205 bb = spec2[range(m,spec2.size)]
1450 bb = spec2[range(m,spec2.size)]
206 bb = (bb<n0).nonzero()
1451 bb = (bb<n0).nonzero()
207 bb = bb[0]
1452 bb = bb[0]
208
1453
209 ss = spec2[range(0,m + 1)]
1454 ss = spec2[range(0,m + 1)]
210 ss = (ss<n0).nonzero()
1455 ss = (ss<n0).nonzero()
211 ss = ss[0]
1456 ss = ss[0]
212
1457
213 if (bb.size == 0):
1458 if (bb.size == 0):
214 bb0 = spec.size - 1 - m
1459 bb0 = spec.size - 1 - m
215 else:
1460 else:
216 bb0 = bb[0] - 1
1461 bb0 = bb[0] - 1
217 if (bb0 < 0):
1462 if (bb0 < 0):
218 bb0 = 0
1463 bb0 = 0
219
1464
220 if (ss.size == 0): ss1 = 1
1465 if (ss.size == 0): ss1 = 1
221 else: ss1 = max(ss) + 1
1466 else: ss1 = max(ss) + 1
222
1467
223 if (ss1 > m): ss1 = m
1468 if (ss1 > m): ss1 = m
224
1469
225 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1470 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
226 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1471 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
227 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1472 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
228 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1473 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
229 snr = (spec2.mean()-n0)/n0
1474 snr = (spec2.mean()-n0)/n0
230
1475
231 if (snr < 1.e-20) :
1476 if (snr < 1.e-20) :
232 snr = 1.e-20
1477 snr = 1.e-20
233
1478
234 vec_power[ind] = power
1479 vec_power[ind] = power
235 vec_fd[ind] = fd
1480 vec_fd[ind] = fd
236 vec_w[ind] = w
1481 vec_w[ind] = w
237 vec_snr[ind] = snr
1482 vec_snr[ind] = snr
238
1483
239 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1484 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
240 return moments
1485 return moments
241
1486
242 #------------------ Get SA Parameters --------------------------
1487 #------------------ Get SA Parameters --------------------------
243
1488
244 def GetSAParameters(self):
1489 def GetSAParameters(self):
245 #SA en frecuencia
1490 #SA en frecuencia
246 pairslist = self.dataOut.groupList
1491 pairslist = self.dataOut.groupList
247 num_pairs = len(pairslist)
1492 num_pairs = len(pairslist)
248
1493
249 vel = self.dataOut.abscissaList
1494 vel = self.dataOut.abscissaList
250 spectra = self.dataOut.data_pre[0]
1495 spectra = self.dataOut.data_pre
251 cspectra = self.dataOut.data_pre[1]
1496 cspectra = self.dataIn.data_cspc
252 delta_v = vel[1] - vel[0]
1497 delta_v = vel[1] - vel[0]
253
1498
254 #Calculating the power spectrum
1499 #Calculating the power spectrum
255 spc_pow = numpy.sum(spectra, 3)*delta_v
1500 spc_pow = numpy.sum(spectra, 3)*delta_v
256 #Normalizing Spectra
1501 #Normalizing Spectra
257 norm_spectra = spectra/spc_pow
1502 norm_spectra = spectra/spc_pow
258 #Calculating the norm_spectra at peak
1503 #Calculating the norm_spectra at peak
259 max_spectra = numpy.max(norm_spectra, 3)
1504 max_spectra = numpy.max(norm_spectra, 3)
260
1505
261 #Normalizing Cross Spectra
1506 #Normalizing Cross Spectra
262 norm_cspectra = numpy.zeros(cspectra.shape)
1507 norm_cspectra = numpy.zeros(cspectra.shape)
263
1508
264 for i in range(num_chan):
1509 for i in range(num_chan):
265 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1510 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
266
1511
267 max_cspectra = numpy.max(norm_cspectra,2)
1512 max_cspectra = numpy.max(norm_cspectra,2)
268 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1513 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
269
1514
270 for i in range(num_pairs):
1515 for i in range(num_pairs):
271 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1516 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
272 #------------------- Get Lags ----------------------------------
1517 #------------------- Get Lags ----------------------------------
273
1518
274 class SALags(Operation):
1519 class SALags(Operation):
275 '''
1520 '''
276 Function GetMoments()
1521 Function GetMoments()
@@ -283,19 +1528,19 class SALags(Operation):
283 self.dataOut.data_SNR
1528 self.dataOut.data_SNR
284 self.dataOut.groupList
1529 self.dataOut.groupList
285 self.dataOut.nChannels
1530 self.dataOut.nChannels
286
1531
287 Affected:
1532 Affected:
288 self.dataOut.data_param
1533 self.dataOut.data_param
289
1534
290 '''
1535 '''
291 def run(self, dataOut):
1536 def run(self, dataOut):
292 data_acf = dataOut.data_pre[0]
1537 data_acf = dataOut.data_pre[0]
293 data_ccf = dataOut.data_pre[1]
1538 data_ccf = dataOut.data_pre[1]
294 normFactor_acf = dataOut.normFactor[0]
1539 normFactor_acf = dataOut.normFactor[0]
295 normFactor_ccf = dataOut.normFactor[1]
1540 normFactor_ccf = dataOut.normFactor[1]
296 pairs_acf = dataOut.groupList[0]
1541 pairs_acf = dataOut.groupList[0]
297 pairs_ccf = dataOut.groupList[1]
1542 pairs_ccf = dataOut.groupList[1]
298
1543
299 nHeights = dataOut.nHeights
1544 nHeights = dataOut.nHeights
300 absc = dataOut.abscissaList
1545 absc = dataOut.abscissaList
301 noise = dataOut.noise
1546 noise = dataOut.noise
@@ -306,97 +1551,97 class SALags(Operation):
306
1551
307 for l in range(len(pairs_acf)):
1552 for l in range(len(pairs_acf)):
308 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1553 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
309
1554
310 for l in range(len(pairs_ccf)):
1555 for l in range(len(pairs_ccf)):
311 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1556 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
312
1557
313 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1558 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
314 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1559 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
315 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1560 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
316 return
1561 return
317
1562
318 # def __getPairsAutoCorr(self, pairsList, nChannels):
1563 # def __getPairsAutoCorr(self, pairsList, nChannels):
319 #
1564 #
320 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1565 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
321 #
1566 #
322 # for l in range(len(pairsList)):
1567 # for l in range(len(pairsList)):
323 # firstChannel = pairsList[l][0]
1568 # firstChannel = pairsList[l][0]
324 # secondChannel = pairsList[l][1]
1569 # secondChannel = pairsList[l][1]
325 #
1570 #
326 # #Obteniendo pares de Autocorrelacion
1571 # #Obteniendo pares de Autocorrelacion
327 # if firstChannel == secondChannel:
1572 # if firstChannel == secondChannel:
328 # pairsAutoCorr[firstChannel] = int(l)
1573 # pairsAutoCorr[firstChannel] = int(l)
329 #
1574 #
330 # pairsAutoCorr = pairsAutoCorr.astype(int)
1575 # pairsAutoCorr = pairsAutoCorr.astype(int)
331 #
1576 #
332 # pairsCrossCorr = range(len(pairsList))
1577 # pairsCrossCorr = range(len(pairsList))
333 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1578 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
334 #
1579 #
335 # return pairsAutoCorr, pairsCrossCorr
1580 # return pairsAutoCorr, pairsCrossCorr
336
1581
337 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1582 def __calculateTaus(self, data_acf, data_ccf, lagRange):
338
1583
339 lag0 = data_acf.shape[1]/2
1584 lag0 = data_acf.shape[1]/2
340 #Funcion de Autocorrelacion
1585 #Funcion de Autocorrelacion
341 mean_acf = stats.nanmean(data_acf, axis = 0)
1586 mean_acf = stats.nanmean(data_acf, axis = 0)
342
1587
343 #Obtencion Indice de TauCross
1588 #Obtencion Indice de TauCross
344 ind_ccf = data_ccf.argmax(axis = 1)
1589 ind_ccf = data_ccf.argmax(axis = 1)
345 #Obtencion Indice de TauAuto
1590 #Obtencion Indice de TauAuto
346 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1591 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
347 ccf_lag0 = data_ccf[:,lag0,:]
1592 ccf_lag0 = data_ccf[:,lag0,:]
348
1593
349 for i in range(ccf_lag0.shape[0]):
1594 for i in range(ccf_lag0.shape[0]):
350 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1595 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
351
1596
352 #Obtencion de TauCross y TauAuto
1597 #Obtencion de TauCross y TauAuto
353 tau_ccf = lagRange[ind_ccf]
1598 tau_ccf = lagRange[ind_ccf]
354 tau_acf = lagRange[ind_acf]
1599 tau_acf = lagRange[ind_acf]
355
1600
356 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1601 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
357
1602
358 tau_ccf[Nan1,Nan2] = numpy.nan
1603 tau_ccf[Nan1,Nan2] = numpy.nan
359 tau_acf[Nan1,Nan2] = numpy.nan
1604 tau_acf[Nan1,Nan2] = numpy.nan
360 tau = numpy.vstack((tau_ccf,tau_acf))
1605 tau = numpy.vstack((tau_ccf,tau_acf))
361
1606
362 return tau
1607 return tau
363
1608
364 def __calculateLag1Phase(self, data, lagTRange):
1609 def __calculateLag1Phase(self, data, lagTRange):
365 data1 = stats.nanmean(data, axis = 0)
1610 data1 = stats.nanmean(data, axis = 0)
366 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1611 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
367
1612
368 phase = numpy.angle(data1[lag1,:])
1613 phase = numpy.angle(data1[lag1,:])
369
1614
370 return phase
1615 return phase
371
1616
372 class SpectralFitting(Operation):
1617 class SpectralFitting(Operation):
373 '''
1618 '''
374 Function GetMoments()
1619 Function GetMoments()
375
1620
376 Input:
1621 Input:
377 Output:
1622 Output:
378 Variables modified:
1623 Variables modified:
379 '''
1624 '''
380
1625
381 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1626 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
382
1627
383
1628
384 if path != None:
1629 if path != None:
385 sys.path.append(path)
1630 sys.path.append(path)
386 self.dataOut.library = importlib.import_module(file)
1631 self.dataOut.library = importlib.import_module(file)
387
1632
388 #To be inserted as a parameter
1633 #To be inserted as a parameter
389 groupArray = numpy.array(groupList)
1634 groupArray = numpy.array(groupList)
390 # groupArray = numpy.array([[0,1],[2,3]])
1635 # groupArray = numpy.array([[0,1],[2,3]])
391 self.dataOut.groupList = groupArray
1636 self.dataOut.groupList = groupArray
392
1637
393 nGroups = groupArray.shape[0]
1638 nGroups = groupArray.shape[0]
394 nChannels = self.dataIn.nChannels
1639 nChannels = self.dataIn.nChannels
395 nHeights=self.dataIn.heightList.size
1640 nHeights=self.dataIn.heightList.size
396
1641
397 #Parameters Array
1642 #Parameters Array
398 self.dataOut.data_param = None
1643 self.dataOut.data_param = None
399
1644
400 #Set constants
1645 #Set constants
401 constants = self.dataOut.library.setConstants(self.dataIn)
1646 constants = self.dataOut.library.setConstants(self.dataIn)
402 self.dataOut.constants = constants
1647 self.dataOut.constants = constants
@@ -405,24 +1650,24 class SpectralFitting(Operation):
405 ippSeconds = self.dataIn.ippSeconds
1650 ippSeconds = self.dataIn.ippSeconds
406 K = self.dataIn.nIncohInt
1651 K = self.dataIn.nIncohInt
407 pairsArray = numpy.array(self.dataIn.pairsList)
1652 pairsArray = numpy.array(self.dataIn.pairsList)
408
1653
409 #List of possible combinations
1654 #List of possible combinations
410 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1655 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
411 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1656 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
412
1657
413 if getSNR:
1658 if getSNR:
414 listChannels = groupArray.reshape((groupArray.size))
1659 listChannels = groupArray.reshape((groupArray.size))
415 listChannels.sort()
1660 listChannels.sort()
416 noise = self.dataIn.getNoise()
1661 noise = self.dataIn.getNoise()
417 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1662 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
418
1663
419 for i in range(nGroups):
1664 for i in range(nGroups):
420 coord = groupArray[i,:]
1665 coord = groupArray[i,:]
421
1666
422 #Input data array
1667 #Input data array
423 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1668 data = self.dataIn.data_spc[coord,:,:]/(M*N)
424 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1669 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
425
1670
426 #Cross Spectra data array for Covariance Matrixes
1671 #Cross Spectra data array for Covariance Matrixes
427 ind = 0
1672 ind = 0
428 for pairs in listComb:
1673 for pairs in listComb:
@@ -431,10 +1676,10 class SpectralFitting(Operation):
431 ind += 1
1676 ind += 1
432 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1677 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
433 dataCross = dataCross**2/K
1678 dataCross = dataCross**2/K
434
1679
435 for h in range(nHeights):
1680 for h in range(nHeights):
436 # print self.dataOut.heightList[h]
1681 # print self.dataOut.heightList[h]
437
1682
438 #Input
1683 #Input
439 d = data[:,h]
1684 d = data[:,h]
440
1685
@@ -443,7 +1688,7 class SpectralFitting(Operation):
443 ind = 0
1688 ind = 0
444 for pairs in listComb:
1689 for pairs in listComb:
445 #Coordinates in Covariance Matrix
1690 #Coordinates in Covariance Matrix
446 x = pairs[0]
1691 x = pairs[0]
447 y = pairs[1]
1692 y = pairs[1]
448 #Channel Index
1693 #Channel Index
449 S12 = dataCross[ind,:,h]
1694 S12 = dataCross[ind,:,h]
@@ -457,15 +1702,15 class SpectralFitting(Operation):
457 LT=L.T
1702 LT=L.T
458
1703
459 dp = numpy.dot(LT,d)
1704 dp = numpy.dot(LT,d)
460
1705
461 #Initial values
1706 #Initial values
462 data_spc = self.dataIn.data_spc[coord,:,h]
1707 data_spc = self.dataIn.data_spc[coord,:,h]
463
1708
464 if (h>0)and(error1[3]<5):
1709 if (h>0)and(error1[3]<5):
465 p0 = self.dataOut.data_param[i,:,h-1]
1710 p0 = self.dataOut.data_param[i,:,h-1]
466 else:
1711 else:
467 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1712 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
468
1713
469 try:
1714 try:
470 #Least Squares
1715 #Least Squares
471 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1716 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
@@ -478,30 +1723,30 class SpectralFitting(Operation):
478 minp = p0*numpy.nan
1723 minp = p0*numpy.nan
479 error0 = numpy.nan
1724 error0 = numpy.nan
480 error1 = p0*numpy.nan
1725 error1 = p0*numpy.nan
481
1726
482 #Save
1727 #Save
483 if self.dataOut.data_param is None:
1728 if self.dataOut.data_param == None:
484 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1729 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
485 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1730 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
486
1731
487 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1732 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
488 self.dataOut.data_param[i,:,h] = minp
1733 self.dataOut.data_param[i,:,h] = minp
489 return
1734 return
490
1735
491 def __residFunction(self, p, dp, LT, constants):
1736 def __residFunction(self, p, dp, LT, constants):
492
1737
493 fm = self.dataOut.library.modelFunction(p, constants)
1738 fm = self.dataOut.library.modelFunction(p, constants)
494 fmp=numpy.dot(LT,fm)
1739 fmp=numpy.dot(LT,fm)
495
1740
496 return dp-fmp
1741 return dp-fmp
497
1742
498 def __getSNR(self, z, noise):
1743 def __getSNR(self, z, noise):
499
1744
500 avg = numpy.average(z, axis=1)
1745 avg = numpy.average(z, axis=1)
501 SNR = (avg.T-noise)/noise
1746 SNR = (avg.T-noise)/noise
502 SNR = SNR.T
1747 SNR = SNR.T
503 return SNR
1748 return SNR
504
1749
505 def __chisq(p,chindex,hindex):
1750 def __chisq(p,chindex,hindex):
506 #similar to Resid but calculates CHI**2
1751 #similar to Resid but calculates CHI**2
507 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1752 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
@@ -509,50 +1754,53 class SpectralFitting(Operation):
509 fmp=numpy.dot(LT,fm)
1754 fmp=numpy.dot(LT,fm)
510 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1755 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
511 return chisq
1756 return chisq
512
1757
513 class WindProfiler(Operation):
1758 class WindProfiler(Operation):
514
1759
515 __isConfig = False
1760 __isConfig = False
516
1761
517 __initime = None
1762 __initime = None
518 __lastdatatime = None
1763 __lastdatatime = None
519 __integrationtime = None
1764 __integrationtime = None
520
1765
521 __buffer = None
1766 __buffer = None
522
1767
523 __dataReady = False
1768 __dataReady = False
524
1769
525 __firstdata = None
1770 __firstdata = None
526
1771
527 n = None
1772 n = None
528
1773
1774 def __init__(self):
1775 Operation.__init__(self)
1776
529 def __calculateCosDir(self, elev, azim):
1777 def __calculateCosDir(self, elev, azim):
530 zen = (90 - elev)*numpy.pi/180
1778 zen = (90 - elev)*numpy.pi/180
531 azim = azim*numpy.pi/180
1779 azim = azim*numpy.pi/180
532 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1780 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
533 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1781 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
534
1782
535 signX = numpy.sign(numpy.cos(azim))
1783 signX = numpy.sign(numpy.cos(azim))
536 signY = numpy.sign(numpy.sin(azim))
1784 signY = numpy.sign(numpy.sin(azim))
537
1785
538 cosDirX = numpy.copysign(cosDirX, signX)
1786 cosDirX = numpy.copysign(cosDirX, signX)
539 cosDirY = numpy.copysign(cosDirY, signY)
1787 cosDirY = numpy.copysign(cosDirY, signY)
540 return cosDirX, cosDirY
1788 return cosDirX, cosDirY
541
1789
542 def __calculateAngles(self, theta_x, theta_y, azimuth):
1790 def __calculateAngles(self, theta_x, theta_y, azimuth):
543
1791
544 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1792 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
545 zenith_arr = numpy.arccos(dir_cosw)
1793 zenith_arr = numpy.arccos(dir_cosw)
546 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1794 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
547
1795
548 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1796 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
549 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1797 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
550
1798
551 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1799 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
552
1800
553 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1801 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
554
1802
555 #
1803 #
556 if horOnly:
1804 if horOnly:
557 A = numpy.c_[dir_cosu,dir_cosv]
1805 A = numpy.c_[dir_cosu,dir_cosv]
558 else:
1806 else:
@@ -566,37 +1814,37 class WindProfiler(Operation):
566 listPhi = phi.tolist()
1814 listPhi = phi.tolist()
567 maxid = listPhi.index(max(listPhi))
1815 maxid = listPhi.index(max(listPhi))
568 minid = listPhi.index(min(listPhi))
1816 minid = listPhi.index(min(listPhi))
569
1817
570 rango = range(len(phi))
1818 rango = range(len(phi))
571 # rango = numpy.delete(rango,maxid)
1819 # rango = numpy.delete(rango,maxid)
572
1820
573 heiRang1 = heiRang*math.cos(phi[maxid])
1821 heiRang1 = heiRang*math.cos(phi[maxid])
574 heiRangAux = heiRang*math.cos(phi[minid])
1822 heiRangAux = heiRang*math.cos(phi[minid])
575 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1823 indOut = (heiRang1 < heiRangAux[0]).nonzero()
576 heiRang1 = numpy.delete(heiRang1,indOut)
1824 heiRang1 = numpy.delete(heiRang1,indOut)
577
1825
578 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1826 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
579 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1827 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
580
1828
581 for i in rango:
1829 for i in rango:
582 x = heiRang*math.cos(phi[i])
1830 x = heiRang*math.cos(phi[i])
583 y1 = velRadial[i,:]
1831 y1 = velRadial[i,:]
584 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1832 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
585
1833
586 x1 = heiRang1
1834 x1 = heiRang1
587 y11 = f1(x1)
1835 y11 = f1(x1)
588
1836
589 y2 = SNR[i,:]
1837 y2 = SNR[i,:]
590 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1838 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
591 y21 = f2(x1)
1839 y21 = f2(x1)
592
1840
593 velRadial1[i,:] = y11
1841 velRadial1[i,:] = y11
594 SNR1[i,:] = y21
1842 SNR1[i,:] = y21
595
1843
596 return heiRang1, velRadial1, SNR1
1844 return heiRang1, velRadial1, SNR1
597
1845
598 def __calculateVelUVW(self, A, velRadial):
1846 def __calculateVelUVW(self, A, velRadial):
599
1847
600 #Operacion Matricial
1848 #Operacion Matricial
601 # velUVW = numpy.zeros((velRadial.shape[1],3))
1849 # velUVW = numpy.zeros((velRadial.shape[1],3))
602 # for ind in range(velRadial.shape[1]):
1850 # for ind in range(velRadial.shape[1]):
@@ -604,27 +1852,27 class WindProfiler(Operation):
604 # velUVW = velUVW.transpose()
1852 # velUVW = velUVW.transpose()
605 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1853 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
606 velUVW[:,:] = numpy.dot(A,velRadial)
1854 velUVW[:,:] = numpy.dot(A,velRadial)
607
1855
608
1856
609 return velUVW
1857 return velUVW
610
1858
611 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1859 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
612
1860
613 def techniqueDBS(self, kwargs):
1861 def techniqueDBS(self, kwargs):
614 """
1862 """
615 Function that implements Doppler Beam Swinging (DBS) technique.
1863 Function that implements Doppler Beam Swinging (DBS) technique.
616
1864
617 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1865 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
618 Direction correction (if necessary), Ranges and SNR
1866 Direction correction (if necessary), Ranges and SNR
619
1867
620 Output: Winds estimation (Zonal, Meridional and Vertical)
1868 Output: Winds estimation (Zonal, Meridional and Vertical)
621
1869
622 Parameters affected: Winds, height range, SNR
1870 Parameters affected: Winds, height range, SNR
623 """
1871 """
624 velRadial0 = kwargs['velRadial']
1872 velRadial0 = kwargs['velRadial']
625 heiRang = kwargs['heightList']
1873 heiRang = kwargs['heightList']
626 SNR0 = kwargs['SNR']
1874 SNR0 = kwargs['SNR']
627
1875
628 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1876 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
629 theta_x = numpy.array(kwargs['dirCosx'])
1877 theta_x = numpy.array(kwargs['dirCosx'])
630 theta_y = numpy.array(kwargs['dirCosy'])
1878 theta_y = numpy.array(kwargs['dirCosy'])
@@ -632,7 +1880,7 class WindProfiler(Operation):
632 elev = numpy.array(kwargs['elevation'])
1880 elev = numpy.array(kwargs['elevation'])
633 azim = numpy.array(kwargs['azimuth'])
1881 azim = numpy.array(kwargs['azimuth'])
634 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1882 theta_x, theta_y = self.__calculateCosDir(elev, azim)
635 azimuth = kwargs['correctAzimuth']
1883 azimuth = kwargs['correctAzimuth']
636 if kwargs.has_key('horizontalOnly'):
1884 if kwargs.has_key('horizontalOnly'):
637 horizontalOnly = kwargs['horizontalOnly']
1885 horizontalOnly = kwargs['horizontalOnly']
638 else: horizontalOnly = False
1886 else: horizontalOnly = False
@@ -647,22 +1895,22 class WindProfiler(Operation):
647 param = param[arrayChannel,:,:]
1895 param = param[arrayChannel,:,:]
648 theta_x = theta_x[arrayChannel]
1896 theta_x = theta_x[arrayChannel]
649 theta_y = theta_y[arrayChannel]
1897 theta_y = theta_y[arrayChannel]
650
1898
651 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1899 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
652 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1900 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
653 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1901 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
654
1902
655 #Calculo de Componentes de la velocidad con DBS
1903 #Calculo de Componentes de la velocidad con DBS
656 winds = self.__calculateVelUVW(A,velRadial1)
1904 winds = self.__calculateVelUVW(A,velRadial1)
657
1905
658 return winds, heiRang1, SNR1
1906 return winds, heiRang1, SNR1
659
1907
660 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1908 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
661
1909
662 nPairs = len(pairs_ccf)
1910 nPairs = len(pairs_ccf)
663 posx = numpy.asarray(posx)
1911 posx = numpy.asarray(posx)
664 posy = numpy.asarray(posy)
1912 posy = numpy.asarray(posy)
665
1913
666 #Rotacion Inversa para alinear con el azimuth
1914 #Rotacion Inversa para alinear con el azimuth
667 if azimuth!= None:
1915 if azimuth!= None:
668 azimuth = azimuth*math.pi/180
1916 azimuth = azimuth*math.pi/180
@@ -671,126 +1919,126 class WindProfiler(Operation):
671 else:
1919 else:
672 posx1 = posx
1920 posx1 = posx
673 posy1 = posy
1921 posy1 = posy
674
1922
675 #Calculo de Distancias
1923 #Calculo de Distancias
676 distx = numpy.zeros(nPairs)
1924 distx = numpy.zeros(nPairs)
677 disty = numpy.zeros(nPairs)
1925 disty = numpy.zeros(nPairs)
678 dist = numpy.zeros(nPairs)
1926 dist = numpy.zeros(nPairs)
679 ang = numpy.zeros(nPairs)
1927 ang = numpy.zeros(nPairs)
680
1928
681 for i in range(nPairs):
1929 for i in range(nPairs):
682 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1930 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
683 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1931 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
684 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1932 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
685 ang[i] = numpy.arctan2(disty[i],distx[i])
1933 ang[i] = numpy.arctan2(disty[i],distx[i])
686
1934
687 return distx, disty, dist, ang
1935 return distx, disty, dist, ang
688 #Calculo de Matrices
1936 #Calculo de Matrices
689 # nPairs = len(pairs)
1937 # nPairs = len(pairs)
690 # ang1 = numpy.zeros((nPairs, 2, 1))
1938 # ang1 = numpy.zeros((nPairs, 2, 1))
691 # dist1 = numpy.zeros((nPairs, 2, 1))
1939 # dist1 = numpy.zeros((nPairs, 2, 1))
692 #
1940 #
693 # for j in range(nPairs):
1941 # for j in range(nPairs):
694 # dist1[j,0,0] = dist[pairs[j][0]]
1942 # dist1[j,0,0] = dist[pairs[j][0]]
695 # dist1[j,1,0] = dist[pairs[j][1]]
1943 # dist1[j,1,0] = dist[pairs[j][1]]
696 # ang1[j,0,0] = ang[pairs[j][0]]
1944 # ang1[j,0,0] = ang[pairs[j][0]]
697 # ang1[j,1,0] = ang[pairs[j][1]]
1945 # ang1[j,1,0] = ang[pairs[j][1]]
698 #
1946 #
699 # return distx,disty, dist1,ang1
1947 # return distx,disty, dist1,ang1
700
1948
701
1949
702 def __calculateVelVer(self, phase, lagTRange, _lambda):
1950 def __calculateVelVer(self, phase, lagTRange, _lambda):
703
1951
704 Ts = lagTRange[1] - lagTRange[0]
1952 Ts = lagTRange[1] - lagTRange[0]
705 velW = -_lambda*phase/(4*math.pi*Ts)
1953 velW = -_lambda*phase/(4*math.pi*Ts)
706
1954
707 return velW
1955 return velW
708
1956
709 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1957 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
710 nPairs = tau1.shape[0]
1958 nPairs = tau1.shape[0]
711 nHeights = tau1.shape[1]
1959 nHeights = tau1.shape[1]
712 vel = numpy.zeros((nPairs,3,nHeights))
1960 vel = numpy.zeros((nPairs,3,nHeights))
713 dist1 = numpy.reshape(dist, (dist.size,1))
1961 dist1 = numpy.reshape(dist, (dist.size,1))
714
1962
715 angCos = numpy.cos(ang)
1963 angCos = numpy.cos(ang)
716 angSin = numpy.sin(ang)
1964 angSin = numpy.sin(ang)
717
1965
718 vel0 = dist1*tau1/(2*tau2**2)
1966 vel0 = dist1*tau1/(2*tau2**2)
719 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1967 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
720 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1968 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
721
1969
722 ind = numpy.where(numpy.isinf(vel))
1970 ind = numpy.where(numpy.isinf(vel))
723 vel[ind] = numpy.nan
1971 vel[ind] = numpy.nan
724
1972
725 return vel
1973 return vel
726
1974
727 # def __getPairsAutoCorr(self, pairsList, nChannels):
1975 # def __getPairsAutoCorr(self, pairsList, nChannels):
728 #
1976 #
729 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1977 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
730 #
1978 #
731 # for l in range(len(pairsList)):
1979 # for l in range(len(pairsList)):
732 # firstChannel = pairsList[l][0]
1980 # firstChannel = pairsList[l][0]
733 # secondChannel = pairsList[l][1]
1981 # secondChannel = pairsList[l][1]
734 #
1982 #
735 # #Obteniendo pares de Autocorrelacion
1983 # #Obteniendo pares de Autocorrelacion
736 # if firstChannel == secondChannel:
1984 # if firstChannel == secondChannel:
737 # pairsAutoCorr[firstChannel] = int(l)
1985 # pairsAutoCorr[firstChannel] = int(l)
738 #
1986 #
739 # pairsAutoCorr = pairsAutoCorr.astype(int)
1987 # pairsAutoCorr = pairsAutoCorr.astype(int)
740 #
1988 #
741 # pairsCrossCorr = range(len(pairsList))
1989 # pairsCrossCorr = range(len(pairsList))
742 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1990 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
743 #
1991 #
744 # return pairsAutoCorr, pairsCrossCorr
1992 # return pairsAutoCorr, pairsCrossCorr
745
1993
746 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1994 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
747 def techniqueSA(self, kwargs):
1995 def techniqueSA(self, kwargs):
748
1996
749 """
1997 """
750 Function that implements Spaced Antenna (SA) technique.
1998 Function that implements Spaced Antenna (SA) technique.
751
1999
752 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
2000 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
753 Direction correction (if necessary), Ranges and SNR
2001 Direction correction (if necessary), Ranges and SNR
754
2002
755 Output: Winds estimation (Zonal, Meridional and Vertical)
2003 Output: Winds estimation (Zonal, Meridional and Vertical)
756
2004
757 Parameters affected: Winds
2005 Parameters affected: Winds
758 """
2006 """
759 position_x = kwargs['positionX']
2007 position_x = kwargs['positionX']
760 position_y = kwargs['positionY']
2008 position_y = kwargs['positionY']
761 azimuth = kwargs['azimuth']
2009 azimuth = kwargs['azimuth']
762
2010
763 if kwargs.has_key('correctFactor'):
2011 if kwargs.has_key('correctFactor'):
764 correctFactor = kwargs['correctFactor']
2012 correctFactor = kwargs['correctFactor']
765 else:
2013 else:
766 correctFactor = 1
2014 correctFactor = 1
767
2015
768 groupList = kwargs['groupList']
2016 groupList = kwargs['groupList']
769 pairs_ccf = groupList[1]
2017 pairs_ccf = groupList[1]
770 tau = kwargs['tau']
2018 tau = kwargs['tau']
771 _lambda = kwargs['_lambda']
2019 _lambda = kwargs['_lambda']
772
2020
773 #Cross Correlation pairs obtained
2021 #Cross Correlation pairs obtained
774 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2022 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
775 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2023 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
776 # pairsSelArray = numpy.array(pairsSelected)
2024 # pairsSelArray = numpy.array(pairsSelected)
777 # pairs = []
2025 # pairs = []
778 #
2026 #
779 # #Wind estimation pairs obtained
2027 # #Wind estimation pairs obtained
780 # for i in range(pairsSelArray.shape[0]/2):
2028 # for i in range(pairsSelArray.shape[0]/2):
781 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2029 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
782 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2030 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
783 # pairs.append((ind1,ind2))
2031 # pairs.append((ind1,ind2))
784
2032
785 indtau = tau.shape[0]/2
2033 indtau = tau.shape[0]/2
786 tau1 = tau[:indtau,:]
2034 tau1 = tau[:indtau,:]
787 tau2 = tau[indtau:-1,:]
2035 tau2 = tau[indtau:-1,:]
788 # tau1 = tau1[pairs,:]
2036 # tau1 = tau1[pairs,:]
789 # tau2 = tau2[pairs,:]
2037 # tau2 = tau2[pairs,:]
790 phase1 = tau[-1,:]
2038 phase1 = tau[-1,:]
791
2039
792 #---------------------------------------------------------------------
2040 #---------------------------------------------------------------------
793 #Metodo Directo
2041 #Metodo Directo
794 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2042 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
795 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2043 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
796 winds = stats.nanmean(winds, axis=0)
2044 winds = stats.nanmean(winds, axis=0)
@@ -806,100 +2054,100 class WindProfiler(Operation):
806 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2054 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
807 winds = correctFactor*winds
2055 winds = correctFactor*winds
808 return winds
2056 return winds
809
2057
810 def __checkTime(self, currentTime, paramInterval, outputInterval):
2058 def __checkTime(self, currentTime, paramInterval, outputInterval):
811
2059
812 dataTime = currentTime + paramInterval
2060 dataTime = currentTime + paramInterval
813 deltaTime = dataTime - self.__initime
2061 deltaTime = dataTime - self.__initime
814
2062
815 if deltaTime >= outputInterval or deltaTime < 0:
2063 if deltaTime >= outputInterval or deltaTime < 0:
816 self.__dataReady = True
2064 self.__dataReady = True
817 return
2065 return
818
2066
819 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax, binkm=2):
2067 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
820 '''
2068 '''
821 Function that implements winds estimation technique with detected meteors.
2069 Function that implements winds estimation technique with detected meteors.
822
2070
823 Input: Detected meteors, Minimum meteor quantity to wind estimation
2071 Input: Detected meteors, Minimum meteor quantity to wind estimation
824
2072
825 Output: Winds estimation (Zonal and Meridional)
2073 Output: Winds estimation (Zonal and Meridional)
826
2074
827 Parameters affected: Winds
2075 Parameters affected: Winds
828 '''
2076 '''
829 # print arrayMeteor.shape
2077 # print arrayMeteor.shape
830 #Settings
2078 #Settings
831 nInt = (heightMax - heightMin)/binkm
2079 nInt = (heightMax - heightMin)/2
832 # print nInt
2080 # print nInt
833 nInt = int(nInt)
2081 nInt = int(nInt)
834 # print nInt
2082 # print nInt
835 winds = numpy.zeros((2,nInt))*numpy.nan
2083 winds = numpy.zeros((2,nInt))*numpy.nan
836
2084
837 #Filter errors
2085 #Filter errors
838 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2086 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
839 finalMeteor = arrayMeteor[error,:]
2087 finalMeteor = arrayMeteor[error,:]
840
2088
841 #Meteor Histogram
2089 #Meteor Histogram
842 finalHeights = finalMeteor[:,2]
2090 finalHeights = finalMeteor[:,2]
843 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2091 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
844 nMeteorsPerI = hist[0]
2092 nMeteorsPerI = hist[0]
845 heightPerI = hist[1]
2093 heightPerI = hist[1]
846
2094
847 #Sort of meteors
2095 #Sort of meteors
848 indSort = finalHeights.argsort()
2096 indSort = finalHeights.argsort()
849 finalMeteor2 = finalMeteor[indSort,:]
2097 finalMeteor2 = finalMeteor[indSort,:]
850
2098
851 # Calculating winds
2099 # Calculating winds
852 ind1 = 0
2100 ind1 = 0
853 ind2 = 0
2101 ind2 = 0
854
2102
855 for i in range(nInt):
2103 for i in range(nInt):
856 nMet = nMeteorsPerI[i]
2104 nMet = nMeteorsPerI[i]
857 ind1 = ind2
2105 ind1 = ind2
858 ind2 = ind1 + nMet
2106 ind2 = ind1 + nMet
859
2107
860 meteorAux = finalMeteor2[ind1:ind2,:]
2108 meteorAux = finalMeteor2[ind1:ind2,:]
861
2109
862 if meteorAux.shape[0] >= meteorThresh:
2110 if meteorAux.shape[0] >= meteorThresh:
863 vel = meteorAux[:, 6]
2111 vel = meteorAux[:, 6]
864 zen = meteorAux[:, 4]*numpy.pi/180
2112 zen = meteorAux[:, 4]*numpy.pi/180
865 azim = meteorAux[:, 3]*numpy.pi/180
2113 azim = meteorAux[:, 3]*numpy.pi/180
866
2114
867 n = numpy.cos(zen)
2115 n = numpy.cos(zen)
868 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2116 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
869 # l = m*numpy.tan(azim)
2117 # l = m*numpy.tan(azim)
870 l = numpy.sin(zen)*numpy.sin(azim)
2118 l = numpy.sin(zen)*numpy.sin(azim)
871 m = numpy.sin(zen)*numpy.cos(azim)
2119 m = numpy.sin(zen)*numpy.cos(azim)
872
2120
873 A = numpy.vstack((l, m)).transpose()
2121 A = numpy.vstack((l, m)).transpose()
874 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2122 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
875 windsAux = numpy.dot(A1, vel)
2123 windsAux = numpy.dot(A1, vel)
876
2124
877 winds[0,i] = windsAux[0]
2125 winds[0,i] = windsAux[0]
878 winds[1,i] = windsAux[1]
2126 winds[1,i] = windsAux[1]
879
2127
880 return winds, heightPerI[:-1]
2128 return winds, heightPerI[:-1]
881
2129
882 def techniqueNSM_SA(self, **kwargs):
2130 def techniqueNSM_SA(self, **kwargs):
883 metArray = kwargs['metArray']
2131 metArray = kwargs['metArray']
884 heightList = kwargs['heightList']
2132 heightList = kwargs['heightList']
885 timeList = kwargs['timeList']
2133 timeList = kwargs['timeList']
886
2134
887 rx_location = kwargs['rx_location']
2135 rx_location = kwargs['rx_location']
888 groupList = kwargs['groupList']
2136 groupList = kwargs['groupList']
889 azimuth = kwargs['azimuth']
2137 azimuth = kwargs['azimuth']
890 dfactor = kwargs['dfactor']
2138 dfactor = kwargs['dfactor']
891 k = kwargs['k']
2139 k = kwargs['k']
892
2140
893 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2141 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
894 d = dist*dfactor
2142 d = dist*dfactor
895 #Phase calculation
2143 #Phase calculation
896 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2144 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
897
2145
898 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2146 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
899
2147
900 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2148 velEst = numpy.zeros((heightList.size,2))*numpy.nan
901 azimuth1 = azimuth1*numpy.pi/180
2149 azimuth1 = azimuth1*numpy.pi/180
902
2150
903 for i in range(heightList.size):
2151 for i in range(heightList.size):
904 h = heightList[i]
2152 h = heightList[i]
905 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2153 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
@@ -912,71 +2160,71 class WindProfiler(Operation):
912 A = numpy.asmatrix(A)
2160 A = numpy.asmatrix(A)
913 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2161 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
914 velHor = numpy.dot(A1,velAux)
2162 velHor = numpy.dot(A1,velAux)
915
2163
916 velEst[i,:] = numpy.squeeze(velHor)
2164 velEst[i,:] = numpy.squeeze(velHor)
917 return velEst
2165 return velEst
918
2166
919 def __getPhaseSlope(self, metArray, heightList, timeList):
2167 def __getPhaseSlope(self, metArray, heightList, timeList):
920 meteorList = []
2168 meteorList = []
921 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2169 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
922 #Putting back together the meteor matrix
2170 #Putting back together the meteor matrix
923 utctime = metArray[:,0]
2171 utctime = metArray[:,0]
924 uniqueTime = numpy.unique(utctime)
2172 uniqueTime = numpy.unique(utctime)
925
2173
926 phaseDerThresh = 0.5
2174 phaseDerThresh = 0.5
927 ippSeconds = timeList[1] - timeList[0]
2175 ippSeconds = timeList[1] - timeList[0]
928 sec = numpy.where(timeList>1)[0][0]
2176 sec = numpy.where(timeList>1)[0][0]
929 nPairs = metArray.shape[1] - 6
2177 nPairs = metArray.shape[1] - 6
930 nHeights = len(heightList)
2178 nHeights = len(heightList)
931
2179
932 for t in uniqueTime:
2180 for t in uniqueTime:
933 metArray1 = metArray[utctime==t,:]
2181 metArray1 = metArray[utctime==t,:]
934 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2182 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
935 tmet = metArray1[:,1].astype(int)
2183 tmet = metArray1[:,1].astype(int)
936 hmet = metArray1[:,2].astype(int)
2184 hmet = metArray1[:,2].astype(int)
937
2185
938 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2186 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
939 metPhase[:,:] = numpy.nan
2187 metPhase[:,:] = numpy.nan
940 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2188 metPhase[:,hmet,tmet] = metArray1[:,6:].T
941
2189
942 #Delete short trails
2190 #Delete short trails
943 metBool = ~numpy.isnan(metPhase[0,:,:])
2191 metBool = ~numpy.isnan(metPhase[0,:,:])
944 heightVect = numpy.sum(metBool, axis = 1)
2192 heightVect = numpy.sum(metBool, axis = 1)
945 metBool[heightVect<sec,:] = False
2193 metBool[heightVect<sec,:] = False
946 metPhase[:,heightVect<sec,:] = numpy.nan
2194 metPhase[:,heightVect<sec,:] = numpy.nan
947
2195
948 #Derivative
2196 #Derivative
949 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2197 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
950 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2198 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
951 metPhase[phDerAux] = numpy.nan
2199 metPhase[phDerAux] = numpy.nan
952
2200
953 #--------------------------METEOR DETECTION -----------------------------------------
2201 #--------------------------METEOR DETECTION -----------------------------------------
954 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2202 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
955
2203
956 for p in numpy.arange(nPairs):
2204 for p in numpy.arange(nPairs):
957 phase = metPhase[p,:,:]
2205 phase = metPhase[p,:,:]
958 phDer = metDer[p,:,:]
2206 phDer = metDer[p,:,:]
959
2207
960 for h in indMet:
2208 for h in indMet:
961 height = heightList[h]
2209 height = heightList[h]
962 phase1 = phase[h,:] #82
2210 phase1 = phase[h,:] #82
963 phDer1 = phDer[h,:]
2211 phDer1 = phDer[h,:]
964
2212
965 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2213 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
966
2214
967 indValid = numpy.where(~numpy.isnan(phase1))[0]
2215 indValid = numpy.where(~numpy.isnan(phase1))[0]
968 initMet = indValid[0]
2216 initMet = indValid[0]
969 endMet = 0
2217 endMet = 0
970
2218
971 for i in range(len(indValid)-1):
2219 for i in range(len(indValid)-1):
972
2220
973 #Time difference
2221 #Time difference
974 inow = indValid[i]
2222 inow = indValid[i]
975 inext = indValid[i+1]
2223 inext = indValid[i+1]
976 idiff = inext - inow
2224 idiff = inext - inow
977 #Phase difference
2225 #Phase difference
978 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2226 phDiff = numpy.abs(phase1[inext] - phase1[inow])
979
2227
980 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2228 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
981 sizeTrail = inow - initMet + 1
2229 sizeTrail = inow - initMet + 1
982 if sizeTrail>3*sec: #Too short meteors
2230 if sizeTrail>3*sec: #Too short meteors
@@ -992,28 +2240,28 class WindProfiler(Operation):
992 vel = slope#*height*1000/(k*d)
2240 vel = slope#*height*1000/(k*d)
993 estAux = numpy.array([utctime,p,height, vel, rsq])
2241 estAux = numpy.array([utctime,p,height, vel, rsq])
994 meteorList.append(estAux)
2242 meteorList.append(estAux)
995 initMet = inext
2243 initMet = inext
996 metArray2 = numpy.array(meteorList)
2244 metArray2 = numpy.array(meteorList)
997
2245
998 return metArray2
2246 return metArray2
999
2247
1000 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2248 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
1001
2249
1002 azimuth1 = numpy.zeros(len(pairslist))
2250 azimuth1 = numpy.zeros(len(pairslist))
1003 dist = numpy.zeros(len(pairslist))
2251 dist = numpy.zeros(len(pairslist))
1004
2252
1005 for i in range(len(rx_location)):
2253 for i in range(len(rx_location)):
1006 ch0 = pairslist[i][0]
2254 ch0 = pairslist[i][0]
1007 ch1 = pairslist[i][1]
2255 ch1 = pairslist[i][1]
1008
2256
1009 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2257 diffX = rx_location[ch0][0] - rx_location[ch1][0]
1010 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2258 diffY = rx_location[ch0][1] - rx_location[ch1][1]
1011 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2259 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
1012 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2260 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
1013
2261
1014 azimuth1 -= azimuth0
2262 azimuth1 -= azimuth0
1015 return azimuth1, dist
2263 return azimuth1, dist
1016
2264
1017 def techniqueNSM_DBS(self, **kwargs):
2265 def techniqueNSM_DBS(self, **kwargs):
1018 metArray = kwargs['metArray']
2266 metArray = kwargs['metArray']
1019 heightList = kwargs['heightList']
2267 heightList = kwargs['heightList']
@@ -1068,39 +2316,39 class WindProfiler(Operation):
1068 # noise = dataOut.noise
2316 # noise = dataOut.noise
1069 heightList = dataOut.heightList
2317 heightList = dataOut.heightList
1070 SNR = dataOut.data_SNR
2318 SNR = dataOut.data_SNR
1071
2319
1072 if technique == 'DBS':
2320 if technique == 'DBS':
1073
2321
1074 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2322 kwargs['velRadial'] = param[:,1,:] #Radial velocity
1075 kwargs['heightList'] = heightList
2323 kwargs['heightList'] = heightList
1076 kwargs['SNR'] = SNR
2324 kwargs['SNR'] = SNR
1077
2325
1078 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2326 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
1079 dataOut.utctimeInit = dataOut.utctime
2327 dataOut.utctimeInit = dataOut.utctime
1080 dataOut.outputInterval = dataOut.paramInterval
2328 dataOut.outputInterval = dataOut.paramInterval
1081
2329
1082 elif technique == 'SA':
2330 elif technique == 'SA':
1083
2331
1084 #Parameters
2332 #Parameters
1085 # position_x = kwargs['positionX']
2333 # position_x = kwargs['positionX']
1086 # position_y = kwargs['positionY']
2334 # position_y = kwargs['positionY']
1087 # azimuth = kwargs['azimuth']
2335 # azimuth = kwargs['azimuth']
1088 #
2336 #
1089 # if kwargs.has_key('crosspairsList'):
2337 # if kwargs.has_key('crosspairsList'):
1090 # pairs = kwargs['crosspairsList']
2338 # pairs = kwargs['crosspairsList']
1091 # else:
2339 # else:
1092 # pairs = None
2340 # pairs = None
1093 #
2341 #
1094 # if kwargs.has_key('correctFactor'):
2342 # if kwargs.has_key('correctFactor'):
1095 # correctFactor = kwargs['correctFactor']
2343 # correctFactor = kwargs['correctFactor']
1096 # else:
2344 # else:
1097 # correctFactor = 1
2345 # correctFactor = 1
1098
2346
1099 # tau = dataOut.data_param
2347 # tau = dataOut.data_param
1100 # _lambda = dataOut.C/dataOut.frequency
2348 # _lambda = dataOut.C/dataOut.frequency
1101 # pairsList = dataOut.groupList
2349 # pairsList = dataOut.groupList
1102 # nChannels = dataOut.nChannels
2350 # nChannels = dataOut.nChannels
1103
2351
1104 kwargs['groupList'] = dataOut.groupList
2352 kwargs['groupList'] = dataOut.groupList
1105 kwargs['tau'] = dataOut.data_param
2353 kwargs['tau'] = dataOut.data_param
1106 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2354 kwargs['_lambda'] = dataOut.C/dataOut.frequency
@@ -1108,35 +2356,30 class WindProfiler(Operation):
1108 dataOut.data_output = self.techniqueSA(kwargs)
2356 dataOut.data_output = self.techniqueSA(kwargs)
1109 dataOut.utctimeInit = dataOut.utctime
2357 dataOut.utctimeInit = dataOut.utctime
1110 dataOut.outputInterval = dataOut.timeInterval
2358 dataOut.outputInterval = dataOut.timeInterval
1111
2359
1112 elif technique == 'Meteors':
2360 elif technique == 'Meteors':
1113 dataOut.flagNoData = True
2361 dataOut.flagNoData = True
1114 self.__dataReady = False
2362 self.__dataReady = False
1115
2363
1116 if kwargs.has_key('nHours'):
2364 if kwargs.has_key('nHours'):
1117 nHours = kwargs['nHours']
2365 nHours = kwargs['nHours']
1118 else:
2366 else:
1119 nHours = 1
2367 nHours = 1
1120
2368
1121 if kwargs.has_key('meteorsPerBin'):
2369 if kwargs.has_key('meteorsPerBin'):
1122 meteorThresh = kwargs['meteorsPerBin']
2370 meteorThresh = kwargs['meteorsPerBin']
1123 else:
2371 else:
1124 meteorThresh = 6
2372 meteorThresh = 6
1125
2373
1126 if kwargs.has_key('hmin'):
2374 if kwargs.has_key('hmin'):
1127 hmin = kwargs['hmin']
2375 hmin = kwargs['hmin']
1128 else: hmin = 70
2376 else: hmin = 70
1129 if kwargs.has_key('hmax'):
2377 if kwargs.has_key('hmax'):
1130 hmax = kwargs['hmax']
2378 hmax = kwargs['hmax']
1131 else: hmax = 110
2379 else: hmax = 110
1132
2380
1133 if kwargs.has_key('BinKm'):
1134 binkm = kwargs['BinKm']
1135 else:
1136 binkm = 2
1137
1138 dataOut.outputInterval = nHours*3600
2381 dataOut.outputInterval = nHours*3600
1139
2382
1140 if self.__isConfig == False:
2383 if self.__isConfig == False:
1141 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2384 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1142 #Get Initial LTC time
2385 #Get Initial LTC time
@@ -1144,29 +2387,29 class WindProfiler(Operation):
1144 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2387 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1145
2388
1146 self.__isConfig = True
2389 self.__isConfig = True
1147
2390
1148 if self.__buffer is None:
2391 if self.__buffer == None:
1149 self.__buffer = dataOut.data_param
2392 self.__buffer = dataOut.data_param
1150 self.__firstdata = copy.copy(dataOut)
2393 self.__firstdata = copy.copy(dataOut)
1151
2394
1152 else:
2395 else:
1153 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2396 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1154
2397
1155 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2398 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1156
2399
1157 if self.__dataReady:
2400 if self.__dataReady:
1158 dataOut.utctimeInit = self.__initime
2401 dataOut.utctimeInit = self.__initime
1159
2402
1160 self.__initime += dataOut.outputInterval #to erase time offset
2403 self.__initime += dataOut.outputInterval #to erase time offset
1161
2404
1162 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax, binkm)
2405 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
1163 dataOut.flagNoData = False
2406 dataOut.flagNoData = False
1164 self.__buffer = None
2407 self.__buffer = None
1165
2408
1166 elif technique == 'Meteors1':
2409 elif technique == 'Meteors1':
1167 dataOut.flagNoData = True
2410 dataOut.flagNoData = True
1168 self.__dataReady = False
2411 self.__dataReady = False
1169
2412
1170 if kwargs.has_key('nMins'):
2413 if kwargs.has_key('nMins'):
1171 nMins = kwargs['nMins']
2414 nMins = kwargs['nMins']
1172 else: nMins = 20
2415 else: nMins = 20
@@ -1187,17 +2430,17 class WindProfiler(Operation):
1187 else: mode = 'SA'
2430 else: mode = 'SA'
1188
2431
1189 #Borrar luego esto
2432 #Borrar luego esto
1190 if dataOut.groupList is None:
2433 if dataOut.groupList == None:
1191 dataOut.groupList = [(0,1),(0,2),(1,2)]
2434 dataOut.groupList = [(0,1),(0,2),(1,2)]
1192 groupList = dataOut.groupList
2435 groupList = dataOut.groupList
1193 C = 3e8
2436 C = 3e8
1194 freq = 50e6
2437 freq = 50e6
1195 lamb = C/freq
2438 lamb = C/freq
1196 k = 2*numpy.pi/lamb
2439 k = 2*numpy.pi/lamb
1197
2440
1198 timeList = dataOut.abscissaList
2441 timeList = dataOut.abscissaList
1199 heightList = dataOut.heightList
2442 heightList = dataOut.heightList
1200
2443
1201 if self.__isConfig == False:
2444 if self.__isConfig == False:
1202 dataOut.outputInterval = nMins*60
2445 dataOut.outputInterval = nMins*60
1203 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2446 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
@@ -1208,20 +2451,20 class WindProfiler(Operation):
1208 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2451 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1209
2452
1210 self.__isConfig = True
2453 self.__isConfig = True
1211
2454
1212 if self.__buffer is None:
2455 if self.__buffer == None:
1213 self.__buffer = dataOut.data_param
2456 self.__buffer = dataOut.data_param
1214 self.__firstdata = copy.copy(dataOut)
2457 self.__firstdata = copy.copy(dataOut)
1215
2458
1216 else:
2459 else:
1217 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2460 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1218
2461
1219 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2462 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1220
2463
1221 if self.__dataReady:
2464 if self.__dataReady:
1222 dataOut.utctimeInit = self.__initime
2465 dataOut.utctimeInit = self.__initime
1223 self.__initime += dataOut.outputInterval #to erase time offset
2466 self.__initime += dataOut.outputInterval #to erase time offset
1224
2467
1225 metArray = self.__buffer
2468 metArray = self.__buffer
1226 if mode == 'SA':
2469 if mode == 'SA':
1227 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2470 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
@@ -1232,69 +2475,71 class WindProfiler(Operation):
1232 self.__buffer = None
2475 self.__buffer = None
1233
2476
1234 return
2477 return
1235
2478
1236 class EWDriftsEstimation(Operation):
2479 class EWDriftsEstimation(Operation):
1237
2480
1238
2481 def __init__(self):
2482 Operation.__init__(self)
2483
1239 def __correctValues(self, heiRang, phi, velRadial, SNR):
2484 def __correctValues(self, heiRang, phi, velRadial, SNR):
1240 listPhi = phi.tolist()
2485 listPhi = phi.tolist()
1241 maxid = listPhi.index(max(listPhi))
2486 maxid = listPhi.index(max(listPhi))
1242 minid = listPhi.index(min(listPhi))
2487 minid = listPhi.index(min(listPhi))
1243
2488
1244 rango = range(len(phi))
2489 rango = range(len(phi))
1245 # rango = numpy.delete(rango,maxid)
2490 # rango = numpy.delete(rango,maxid)
1246
2491
1247 heiRang1 = heiRang*math.cos(phi[maxid])
2492 heiRang1 = heiRang*math.cos(phi[maxid])
1248 heiRangAux = heiRang*math.cos(phi[minid])
2493 heiRangAux = heiRang*math.cos(phi[minid])
1249 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2494 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1250 heiRang1 = numpy.delete(heiRang1,indOut)
2495 heiRang1 = numpy.delete(heiRang1,indOut)
1251
2496
1252 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2497 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1253 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2498 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1254
2499
1255 for i in rango:
2500 for i in rango:
1256 x = heiRang*math.cos(phi[i])
2501 x = heiRang*math.cos(phi[i])
1257 y1 = velRadial[i,:]
2502 y1 = velRadial[i,:]
1258 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2503 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1259
2504
1260 x1 = heiRang1
2505 x1 = heiRang1
1261 y11 = f1(x1)
2506 y11 = f1(x1)
1262
2507
1263 y2 = SNR[i,:]
2508 y2 = SNR[i,:]
1264 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2509 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1265 y21 = f2(x1)
2510 y21 = f2(x1)
1266
2511
1267 velRadial1[i,:] = y11
2512 velRadial1[i,:] = y11
1268 SNR1[i,:] = y21
2513 SNR1[i,:] = y21
1269
2514
1270 return heiRang1, velRadial1, SNR1
2515 return heiRang1, velRadial1, SNR1
1271
2516
1272 def run(self, dataOut, zenith, zenithCorrection):
2517 def run(self, dataOut, zenith, zenithCorrection):
1273 heiRang = dataOut.heightList
2518 heiRang = dataOut.heightList
1274 velRadial = dataOut.data_param[:,3,:]
2519 velRadial = dataOut.data_param[:,3,:]
1275 SNR = dataOut.data_SNR
2520 SNR = dataOut.data_SNR
1276
2521
1277 zenith = numpy.array(zenith)
2522 zenith = numpy.array(zenith)
1278 zenith -= zenithCorrection
2523 zenith -= zenithCorrection
1279 zenith *= numpy.pi/180
2524 zenith *= numpy.pi/180
1280
2525
1281 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2526 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
1282
2527
1283 alp = zenith[0]
2528 alp = zenith[0]
1284 bet = zenith[1]
2529 bet = zenith[1]
1285
2530
1286 w_w = velRadial1[0,:]
2531 w_w = velRadial1[0,:]
1287 w_e = velRadial1[1,:]
2532 w_e = velRadial1[1,:]
1288
2533
1289 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2534 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
1290 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2535 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
1291
2536
1292 winds = numpy.vstack((u,w))
2537 winds = numpy.vstack((u,w))
1293
2538
1294 dataOut.heightList = heiRang1
2539 dataOut.heightList = heiRang1
1295 dataOut.data_output = winds
2540 dataOut.data_output = winds
1296 dataOut.data_SNR = SNR1
2541 dataOut.data_SNR = SNR1
1297
2542
1298 dataOut.utctimeInit = dataOut.utctime
2543 dataOut.utctimeInit = dataOut.utctime
1299 dataOut.outputInterval = dataOut.timeInterval
2544 dataOut.outputInterval = dataOut.timeInterval
1300 return
2545 return
@@ -1333,7 +2578,7 class NonSpecularMeteorDetection(Operation):
1333 SNR[i] = (power[i]-noise[i])/noise[i]
2578 SNR[i] = (power[i]-noise[i])/noise[i]
1334 SNRm = numpy.nanmean(SNR, axis = 0)
2579 SNRm = numpy.nanmean(SNR, axis = 0)
1335 SNRdB = 10*numpy.log10(SNR)
2580 SNRdB = 10*numpy.log10(SNR)
1336
2581
1337 if mode == 'SA':
2582 if mode == 'SA':
1338 dataOut.groupList = dataOut.groupList[1]
2583 dataOut.groupList = dataOut.groupList[1]
1339 nPairs = data_ccf.shape[0]
2584 nPairs = data_ccf.shape[0]
@@ -1341,22 +2586,22 class NonSpecularMeteorDetection(Operation):
1341 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2586 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
1342 # phase1 = numpy.copy(phase)
2587 # phase1 = numpy.copy(phase)
1343 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2588 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
1344
2589
1345 for p in range(nPairs):
2590 for p in range(nPairs):
1346 ch0 = pairsList[p][0]
2591 ch0 = pairsList[p][0]
1347 ch1 = pairsList[p][1]
2592 ch1 = pairsList[p][1]
1348 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2593 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
1349 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2594 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
1350 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2595 # phase1[p,:,:] = numpy.angle(ccf) #median filter
1351 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2596 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
1352 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2597 # coh1[p,:,:] = numpy.abs(ccf) #median filter
1353 coh = numpy.nanmax(coh1, axis = 0)
2598 coh = numpy.nanmax(coh1, axis = 0)
1354 # struc = numpy.ones((5,1))
2599 # struc = numpy.ones((5,1))
1355 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2600 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
1356 #---------------------- Radial Velocity ----------------------------
2601 #---------------------- Radial Velocity ----------------------------
1357 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2602 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
1358 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2603 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
1359
2604
1360 if allData:
2605 if allData:
1361 boolMetFin = ~numpy.isnan(SNRm)
2606 boolMetFin = ~numpy.isnan(SNRm)
1362 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2607 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
@@ -1364,31 +2609,31 class NonSpecularMeteorDetection(Operation):
1364 #------------------------ Meteor mask ---------------------------------
2609 #------------------------ Meteor mask ---------------------------------
1365 # #SNR mask
2610 # #SNR mask
1366 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2611 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
1367 #
2612 #
1368 # #Erase small objects
2613 # #Erase small objects
1369 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2614 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
1370 #
2615 #
1371 # auxEEJ = numpy.sum(boolMet1,axis=0)
2616 # auxEEJ = numpy.sum(boolMet1,axis=0)
1372 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2617 # indOver = auxEEJ>nProfiles*0.8 #Use this later
1373 # indEEJ = numpy.where(indOver)[0]
2618 # indEEJ = numpy.where(indOver)[0]
1374 # indNEEJ = numpy.where(~indOver)[0]
2619 # indNEEJ = numpy.where(~indOver)[0]
1375 #
2620 #
1376 # boolMetFin = boolMet1
2621 # boolMetFin = boolMet1
1377 #
2622 #
1378 # if indEEJ.size > 0:
2623 # if indEEJ.size > 0:
1379 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2624 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
1380 #
2625 #
1381 # boolMet2 = coh > cohThresh
2626 # boolMet2 = coh > cohThresh
1382 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2627 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
1383 #
2628 #
1384 # #Final Meteor mask
2629 # #Final Meteor mask
1385 # boolMetFin = boolMet1|boolMet2
2630 # boolMetFin = boolMet1|boolMet2
1386
2631
1387 #Coherence mask
2632 #Coherence mask
1388 boolMet1 = coh > 0.75
2633 boolMet1 = coh > 0.75
1389 struc = numpy.ones((30,1))
2634 struc = numpy.ones((30,1))
1390 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2635 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
1391
2636
1392 #Derivative mask
2637 #Derivative mask
1393 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2638 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
1394 boolMet2 = derPhase < 0.2
2639 boolMet2 = derPhase < 0.2
@@ -1405,7 +2650,7 class NonSpecularMeteorDetection(Operation):
1405
2650
1406 tmet = coordMet[0]
2651 tmet = coordMet[0]
1407 hmet = coordMet[1]
2652 hmet = coordMet[1]
1408
2653
1409 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2654 data_param = numpy.zeros((tmet.size, 6 + nPairs))
1410 data_param[:,0] = utctime
2655 data_param[:,0] = utctime
1411 data_param[:,1] = tmet
2656 data_param[:,1] = tmet
@@ -1414,7 +2659,7 class NonSpecularMeteorDetection(Operation):
1414 data_param[:,4] = velRad[tmet,hmet]
2659 data_param[:,4] = velRad[tmet,hmet]
1415 data_param[:,5] = coh[tmet,hmet]
2660 data_param[:,5] = coh[tmet,hmet]
1416 data_param[:,6:] = phase[:,tmet,hmet].T
2661 data_param[:,6:] = phase[:,tmet,hmet].T
1417
2662
1418 elif mode == 'DBS':
2663 elif mode == 'DBS':
1419 dataOut.groupList = numpy.arange(nChannels)
2664 dataOut.groupList = numpy.arange(nChannels)
1420
2665
@@ -1422,7 +2667,7 class NonSpecularMeteorDetection(Operation):
1422 phase = numpy.angle(data_acf[:,1,:,:])
2667 phase = numpy.angle(data_acf[:,1,:,:])
1423 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2668 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
1424 velRad = phase*lamb/(4*numpy.pi*tSamp)
2669 velRad = phase*lamb/(4*numpy.pi*tSamp)
1425
2670
1426 #Spectral width
2671 #Spectral width
1427 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2672 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
1428 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2673 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
@@ -1437,24 +2682,24 class NonSpecularMeteorDetection(Operation):
1437 #SNR
2682 #SNR
1438 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2683 boolMet1 = (SNRdB>SNRthresh) #SNR mask
1439 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2684 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
1440
2685
1441 #Radial velocity
2686 #Radial velocity
1442 boolMet2 = numpy.abs(velRad) < 20
2687 boolMet2 = numpy.abs(velRad) < 20
1443 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2688 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
1444
2689
1445 #Spectral Width
2690 #Spectral Width
1446 boolMet3 = spcWidth < 30
2691 boolMet3 = spcWidth < 30
1447 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2692 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
1448 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2693 # boolMetFin = self.__erase_small(boolMet1, 10,5)
1449 boolMetFin = boolMet1&boolMet2&boolMet3
2694 boolMetFin = boolMet1&boolMet2&boolMet3
1450
2695
1451 #Creating data_param
2696 #Creating data_param
1452 coordMet = numpy.where(boolMetFin)
2697 coordMet = numpy.where(boolMetFin)
1453
2698
1454 cmet = coordMet[0]
2699 cmet = coordMet[0]
1455 tmet = coordMet[1]
2700 tmet = coordMet[1]
1456 hmet = coordMet[2]
2701 hmet = coordMet[2]
1457
2702
1458 data_param = numpy.zeros((tmet.size, 7))
2703 data_param = numpy.zeros((tmet.size, 7))
1459 data_param[:,0] = utctime
2704 data_param[:,0] = utctime
1460 data_param[:,1] = cmet
2705 data_param[:,1] = cmet
@@ -1463,7 +2708,7 class NonSpecularMeteorDetection(Operation):
1463 data_param[:,4] = SNR[cmet,tmet,hmet].T
2708 data_param[:,4] = SNR[cmet,tmet,hmet].T
1464 data_param[:,5] = velRad[cmet,tmet,hmet].T
2709 data_param[:,5] = velRad[cmet,tmet,hmet].T
1465 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2710 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
1466
2711
1467 # self.dataOut.data_param = data_int
2712 # self.dataOut.data_param = data_int
1468 if len(data_param) == 0:
2713 if len(data_param) == 0:
1469 dataOut.flagNoData = True
2714 dataOut.flagNoData = True
@@ -1473,21 +2718,21 class NonSpecularMeteorDetection(Operation):
1473 def __erase_small(self, binArray, threshX, threshY):
2718 def __erase_small(self, binArray, threshX, threshY):
1474 labarray, numfeat = ndimage.measurements.label(binArray)
2719 labarray, numfeat = ndimage.measurements.label(binArray)
1475 binArray1 = numpy.copy(binArray)
2720 binArray1 = numpy.copy(binArray)
1476
2721
1477 for i in range(1,numfeat + 1):
2722 for i in range(1,numfeat + 1):
1478 auxBin = (labarray==i)
2723 auxBin = (labarray==i)
1479 auxSize = auxBin.sum()
2724 auxSize = auxBin.sum()
1480
2725
1481 x,y = numpy.where(auxBin)
2726 x,y = numpy.where(auxBin)
1482 widthX = x.max() - x.min()
2727 widthX = x.max() - x.min()
1483 widthY = y.max() - y.min()
2728 widthY = y.max() - y.min()
1484
2729
1485 #width X: 3 seg -> 12.5*3
2730 #width X: 3 seg -> 12.5*3
1486 #width Y:
2731 #width Y:
1487
2732
1488 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2733 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
1489 binArray1[auxBin] = False
2734 binArray1[auxBin] = False
1490
2735
1491 return binArray1
2736 return binArray1
1492
2737
1493 #--------------- Specular Meteor ----------------
2738 #--------------- Specular Meteor ----------------
@@ -1497,36 +2742,36 class SMDetection(Operation):
1497 Function DetectMeteors()
2742 Function DetectMeteors()
1498 Project developed with paper:
2743 Project developed with paper:
1499 HOLDSWORTH ET AL. 2004
2744 HOLDSWORTH ET AL. 2004
1500
2745
1501 Input:
2746 Input:
1502 self.dataOut.data_pre
2747 self.dataOut.data_pre
1503
2748
1504 centerReceiverIndex: From the channels, which is the center receiver
2749 centerReceiverIndex: From the channels, which is the center receiver
1505
2750
1506 hei_ref: Height reference for the Beacon signal extraction
2751 hei_ref: Height reference for the Beacon signal extraction
1507 tauindex:
2752 tauindex:
1508 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2753 predefinedPhaseShifts: Predefined phase offset for the voltge signals
1509
2754
1510 cohDetection: Whether to user Coherent detection or not
2755 cohDetection: Whether to user Coherent detection or not
1511 cohDet_timeStep: Coherent Detection calculation time step
2756 cohDet_timeStep: Coherent Detection calculation time step
1512 cohDet_thresh: Coherent Detection phase threshold to correct phases
2757 cohDet_thresh: Coherent Detection phase threshold to correct phases
1513
2758
1514 noise_timeStep: Noise calculation time step
2759 noise_timeStep: Noise calculation time step
1515 noise_multiple: Noise multiple to define signal threshold
2760 noise_multiple: Noise multiple to define signal threshold
1516
2761
1517 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2762 multDet_timeLimit: Multiple Detection Removal time limit in seconds
1518 multDet_rangeLimit: Multiple Detection Removal range limit in km
2763 multDet_rangeLimit: Multiple Detection Removal range limit in km
1519
2764
1520 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2765 phaseThresh: Maximum phase difference between receiver to be consider a meteor
1521 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2766 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
1522
2767
1523 hmin: Minimum Height of the meteor to use it in the further wind estimations
2768 hmin: Minimum Height of the meteor to use it in the further wind estimations
1524 hmax: Maximum Height of the meteor to use it in the further wind estimations
2769 hmax: Maximum Height of the meteor to use it in the further wind estimations
1525 azimuth: Azimuth angle correction
2770 azimuth: Azimuth angle correction
1526
2771
1527 Affected:
2772 Affected:
1528 self.dataOut.data_param
2773 self.dataOut.data_param
1529
2774
1530 Rejection Criteria (Errors):
2775 Rejection Criteria (Errors):
1531 0: No error; analysis OK
2776 0: No error; analysis OK
1532 1: SNR < SNR threshold
2777 1: SNR < SNR threshold
@@ -1545,9 +2790,9 class SMDetection(Operation):
1545 14: height ambiguous echo: more then one possible height within 70 to 110 km
2790 14: height ambiguous echo: more then one possible height within 70 to 110 km
1546 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2791 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
1547 16: oscilatory echo, indicating event most likely not an underdense echo
2792 16: oscilatory echo, indicating event most likely not an underdense echo
1548
2793
1549 17: phase difference in meteor Reestimation
2794 17: phase difference in meteor Reestimation
1550
2795
1551 Data Storage:
2796 Data Storage:
1552 Meteors for Wind Estimation (8):
2797 Meteors for Wind Estimation (8):
1553 Utc Time | Range Height
2798 Utc Time | Range Height
@@ -1555,21 +2800,21 class SMDetection(Operation):
1555 VelRad errorVelRad
2800 VelRad errorVelRad
1556 Phase0 Phase1 Phase2 Phase3
2801 Phase0 Phase1 Phase2 Phase3
1557 TypeError
2802 TypeError
1558
2803
1559 '''
2804 '''
1560
2805
1561 def run(self, dataOut, hei_ref = None, tauindex = 0,
2806 def run(self, dataOut, hei_ref = None, tauindex = 0,
1562 phaseOffsets = None,
2807 phaseOffsets = None,
1563 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2808 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
1564 noise_timeStep = 4, noise_multiple = 4,
2809 noise_timeStep = 4, noise_multiple = 4,
1565 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2810 multDet_timeLimit = 1, multDet_rangeLimit = 3,
1566 phaseThresh = 20, SNRThresh = 5,
2811 phaseThresh = 20, SNRThresh = 5,
1567 hmin = 50, hmax=150, azimuth = 0,
2812 hmin = 50, hmax=150, azimuth = 0,
1568 channelPositions = None) :
2813 channelPositions = None) :
1569
2814
1570
2815
1571 #Getting Pairslist
2816 #Getting Pairslist
1572 if channelPositions is None:
2817 if channelPositions == None:
1573 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2818 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
1574 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2819 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
1575 meteorOps = SMOperations()
2820 meteorOps = SMOperations()
@@ -1577,53 +2822,53 class SMDetection(Operation):
1577 heiRang = dataOut.getHeiRange()
2822 heiRang = dataOut.getHeiRange()
1578 #Get Beacon signal - No Beacon signal anymore
2823 #Get Beacon signal - No Beacon signal anymore
1579 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2824 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
1580 #
2825 #
1581 # if hei_ref != None:
2826 # if hei_ref != None:
1582 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2827 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
1583 #
2828 #
1584
2829
1585
2830
1586 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2831 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
1587 # see if the user put in pre defined phase shifts
2832 # see if the user put in pre defined phase shifts
1588 voltsPShift = dataOut.data_pre.copy()
2833 voltsPShift = dataOut.data_pre.copy()
1589
2834
1590 # if predefinedPhaseShifts != None:
2835 # if predefinedPhaseShifts != None:
1591 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2836 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
1592 #
2837 #
1593 # # elif beaconPhaseShifts:
2838 # # elif beaconPhaseShifts:
1594 # # #get hardware phase shifts using beacon signal
2839 # # #get hardware phase shifts using beacon signal
1595 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2840 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
1596 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2841 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
1597 #
2842 #
1598 # else:
2843 # else:
1599 # hardwarePhaseShifts = numpy.zeros(5)
2844 # hardwarePhaseShifts = numpy.zeros(5)
1600 #
2845 #
1601 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2846 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
1602 # for i in range(self.dataOut.data_pre.shape[0]):
2847 # for i in range(self.dataOut.data_pre.shape[0]):
1603 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2848 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
1604
2849
1605 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2850 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
1606
2851
1607 #Remove DC
2852 #Remove DC
1608 voltsDC = numpy.mean(voltsPShift,1)
2853 voltsDC = numpy.mean(voltsPShift,1)
1609 voltsDC = numpy.mean(voltsDC,1)
2854 voltsDC = numpy.mean(voltsDC,1)
1610 for i in range(voltsDC.shape[0]):
2855 for i in range(voltsDC.shape[0]):
1611 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2856 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
1612
2857
1613 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2858 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
1614 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2859 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
1615
2860
1616 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2861 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
1617 #Coherent Detection
2862 #Coherent Detection
1618 if cohDetection:
2863 if cohDetection:
1619 #use coherent detection to get the net power
2864 #use coherent detection to get the net power
1620 cohDet_thresh = cohDet_thresh*numpy.pi/180
2865 cohDet_thresh = cohDet_thresh*numpy.pi/180
1621 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2866 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
1622
2867
1623 #Non-coherent detection!
2868 #Non-coherent detection!
1624 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2869 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
1625 #********** END OF COH/NON-COH POWER CALCULATION**********************
2870 #********** END OF COH/NON-COH POWER CALCULATION**********************
1626
2871
1627 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2872 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
1628 #Get noise
2873 #Get noise
1629 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2874 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
@@ -1633,7 +2878,7 class SMDetection(Operation):
1633 #Meteor echoes detection
2878 #Meteor echoes detection
1634 listMeteors = self.__findMeteors(powerNet, signalThresh)
2879 listMeteors = self.__findMeteors(powerNet, signalThresh)
1635 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2880 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
1636
2881
1637 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2882 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
1638 #Parameters
2883 #Parameters
1639 heiRange = dataOut.getHeiRange()
2884 heiRange = dataOut.getHeiRange()
@@ -1643,7 +2888,7 class SMDetection(Operation):
1643 #Multiple detection removals
2888 #Multiple detection removals
1644 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2889 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
1645 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2890 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
1646
2891
1647 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2892 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
1648 #Parameters
2893 #Parameters
1649 phaseThresh = phaseThresh*numpy.pi/180
2894 phaseThresh = phaseThresh*numpy.pi/180
@@ -1654,40 +2899,40 class SMDetection(Operation):
1654 #Estimation of decay times (Errors N 7, 8, 11)
2899 #Estimation of decay times (Errors N 7, 8, 11)
1655 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2900 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
1656 #******************* END OF METEOR REESTIMATION *******************
2901 #******************* END OF METEOR REESTIMATION *******************
1657
2902
1658 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2903 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
1659 #Calculating Radial Velocity (Error N 15)
2904 #Calculating Radial Velocity (Error N 15)
1660 radialStdThresh = 10
2905 radialStdThresh = 10
1661 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2906 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
1662
2907
1663 if len(listMeteors4) > 0:
2908 if len(listMeteors4) > 0:
1664 #Setting New Array
2909 #Setting New Array
1665 date = dataOut.utctime
2910 date = dataOut.utctime
1666 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2911 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
1667
2912
1668 #Correcting phase offset
2913 #Correcting phase offset
1669 if phaseOffsets != None:
2914 if phaseOffsets != None:
1670 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2915 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
1671 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2916 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
1672
2917
1673 #Second Pairslist
2918 #Second Pairslist
1674 pairsList = []
2919 pairsList = []
1675 pairx = (0,1)
2920 pairx = (0,1)
1676 pairy = (2,3)
2921 pairy = (2,3)
1677 pairsList.append(pairx)
2922 pairsList.append(pairx)
1678 pairsList.append(pairy)
2923 pairsList.append(pairy)
1679
2924
1680 jph = numpy.array([0,0,0,0])
2925 jph = numpy.array([0,0,0,0])
1681 h = (hmin,hmax)
2926 h = (hmin,hmax)
1682 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2927 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
1683
2928
1684 # #Calculate AOA (Error N 3, 4)
2929 # #Calculate AOA (Error N 3, 4)
1685 # #JONES ET AL. 1998
2930 # #JONES ET AL. 1998
1686 # error = arrayParameters[:,-1]
2931 # error = arrayParameters[:,-1]
1687 # AOAthresh = numpy.pi/8
2932 # AOAthresh = numpy.pi/8
1688 # phases = -arrayParameters[:,9:13]
2933 # phases = -arrayParameters[:,9:13]
1689 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2934 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
1690 #
2935 #
1691 # #Calculate Heights (Error N 13 and 14)
2936 # #Calculate Heights (Error N 13 and 14)
1692 # error = arrayParameters[:,-1]
2937 # error = arrayParameters[:,-1]
1693 # Ranges = arrayParameters[:,2]
2938 # Ranges = arrayParameters[:,2]
@@ -1695,73 +2940,73 class SMDetection(Operation):
1695 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2940 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
1696 # error = arrayParameters[:,-1]
2941 # error = arrayParameters[:,-1]
1697 #********************* END OF PARAMETERS CALCULATION **************************
2942 #********************* END OF PARAMETERS CALCULATION **************************
1698
2943
1699 #***************************+ PASS DATA TO NEXT STEP **********************
2944 #***************************+ PASS DATA TO NEXT STEP **********************
1700 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2945 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
1701 dataOut.data_param = arrayParameters
2946 dataOut.data_param = arrayParameters
1702
2947
1703 if arrayParameters is None:
2948 if arrayParameters == None:
1704 dataOut.flagNoData = True
2949 dataOut.flagNoData = True
1705 else:
2950 else:
1706 dataOut.flagNoData = True
2951 dataOut.flagNoData = True
1707
2952
1708 return
2953 return
1709
2954
1710 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2955 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
1711
2956
1712 minIndex = min(newheis[0])
2957 minIndex = min(newheis[0])
1713 maxIndex = max(newheis[0])
2958 maxIndex = max(newheis[0])
1714
2959
1715 voltage = voltage0[:,:,minIndex:maxIndex+1]
2960 voltage = voltage0[:,:,minIndex:maxIndex+1]
1716 nLength = voltage.shape[1]/n
2961 nLength = voltage.shape[1]/n
1717 nMin = 0
2962 nMin = 0
1718 nMax = 0
2963 nMax = 0
1719 phaseOffset = numpy.zeros((len(pairslist),n))
2964 phaseOffset = numpy.zeros((len(pairslist),n))
1720
2965
1721 for i in range(n):
2966 for i in range(n):
1722 nMax += nLength
2967 nMax += nLength
1723 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2968 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
1724 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2969 phaseCCF = numpy.mean(phaseCCF, axis = 2)
1725 phaseOffset[:,i] = phaseCCF.transpose()
2970 phaseOffset[:,i] = phaseCCF.transpose()
1726 nMin = nMax
2971 nMin = nMax
1727 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2972 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
1728
2973
1729 #Remove Outliers
2974 #Remove Outliers
1730 factor = 2
2975 factor = 2
1731 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2976 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
1732 dw = numpy.std(wt,axis = 1)
2977 dw = numpy.std(wt,axis = 1)
1733 dw = dw.reshape((dw.size,1))
2978 dw = dw.reshape((dw.size,1))
1734 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2979 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
1735 phaseOffset[ind] = numpy.nan
2980 phaseOffset[ind] = numpy.nan
1736 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2981 phaseOffset = stats.nanmean(phaseOffset, axis=1)
1737
2982
1738 return phaseOffset
2983 return phaseOffset
1739
2984
1740 def __shiftPhase(self, data, phaseShift):
2985 def __shiftPhase(self, data, phaseShift):
1741 #this will shift the phase of a complex number
2986 #this will shift the phase of a complex number
1742 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2987 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
1743 return dataShifted
2988 return dataShifted
1744
2989
1745 def __estimatePhaseDifference(self, array, pairslist):
2990 def __estimatePhaseDifference(self, array, pairslist):
1746 nChannel = array.shape[0]
2991 nChannel = array.shape[0]
1747 nHeights = array.shape[2]
2992 nHeights = array.shape[2]
1748 numPairs = len(pairslist)
2993 numPairs = len(pairslist)
1749 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2994 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
1750 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2995 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
1751
2996
1752 #Correct phases
2997 #Correct phases
1753 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2998 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
1754 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2999 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
1755
3000
1756 if indDer[0].shape[0] > 0:
3001 if indDer[0].shape[0] > 0:
1757 for i in range(indDer[0].shape[0]):
3002 for i in range(indDer[0].shape[0]):
1758 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
3003 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
1759 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
3004 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
1760
3005
1761 # for j in range(numSides):
3006 # for j in range(numSides):
1762 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
3007 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
1763 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
3008 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
1764 #
3009 #
1765 #Linear
3010 #Linear
1766 phaseInt = numpy.zeros((numPairs,1))
3011 phaseInt = numpy.zeros((numPairs,1))
1767 angAllCCF = phaseCCF[:,[0,1,3,4],0]
3012 angAllCCF = phaseCCF[:,[0,1,3,4],0]
@@ -1771,16 +3016,16 class SMDetection(Operation):
1771 #Phase Differences
3016 #Phase Differences
1772 phaseDiff = phaseInt - phaseCCF[:,2,:]
3017 phaseDiff = phaseInt - phaseCCF[:,2,:]
1773 phaseArrival = phaseInt.reshape(phaseInt.size)
3018 phaseArrival = phaseInt.reshape(phaseInt.size)
1774
3019
1775 #Dealias
3020 #Dealias
1776 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
3021 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
1777 # indAlias = numpy.where(phaseArrival > numpy.pi)
3022 # indAlias = numpy.where(phaseArrival > numpy.pi)
1778 # phaseArrival[indAlias] -= 2*numpy.pi
3023 # phaseArrival[indAlias] -= 2*numpy.pi
1779 # indAlias = numpy.where(phaseArrival < -numpy.pi)
3024 # indAlias = numpy.where(phaseArrival < -numpy.pi)
1780 # phaseArrival[indAlias] += 2*numpy.pi
3025 # phaseArrival[indAlias] += 2*numpy.pi
1781
3026
1782 return phaseDiff, phaseArrival
3027 return phaseDiff, phaseArrival
1783
3028
1784 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
3029 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
1785 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
3030 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
1786 #find the phase shifts of each channel over 1 second intervals
3031 #find the phase shifts of each channel over 1 second intervals
@@ -1790,25 +3035,25 class SMDetection(Operation):
1790 numHeights = volts.shape[2]
3035 numHeights = volts.shape[2]
1791 nChannel = volts.shape[0]
3036 nChannel = volts.shape[0]
1792 voltsCohDet = volts.copy()
3037 voltsCohDet = volts.copy()
1793
3038
1794 pairsarray = numpy.array(pairslist)
3039 pairsarray = numpy.array(pairslist)
1795 indSides = pairsarray[:,1]
3040 indSides = pairsarray[:,1]
1796 # indSides = numpy.array(range(nChannel))
3041 # indSides = numpy.array(range(nChannel))
1797 # indSides = numpy.delete(indSides, indCenter)
3042 # indSides = numpy.delete(indSides, indCenter)
1798 #
3043 #
1799 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3044 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
1800 listBlocks = numpy.array_split(volts, numBlocks, 1)
3045 listBlocks = numpy.array_split(volts, numBlocks, 1)
1801
3046
1802 startInd = 0
3047 startInd = 0
1803 endInd = 0
3048 endInd = 0
1804
3049
1805 for i in range(numBlocks):
3050 for i in range(numBlocks):
1806 startInd = endInd
3051 startInd = endInd
1807 endInd = endInd + listBlocks[i].shape[1]
3052 endInd = endInd + listBlocks[i].shape[1]
1808
3053
1809 arrayBlock = listBlocks[i]
3054 arrayBlock = listBlocks[i]
1810 # arrayBlockCenter = listCenter[i]
3055 # arrayBlockCenter = listCenter[i]
1811
3056
1812 #Estimate the Phase Difference
3057 #Estimate the Phase Difference
1813 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3058 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
1814 #Phase Difference RMS
3059 #Phase Difference RMS
@@ -1820,21 +3065,21 class SMDetection(Operation):
1820 for j in range(indSides.size):
3065 for j in range(indSides.size):
1821 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3066 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
1822 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3067 voltsCohDet[:,startInd:endInd,:] = arrayBlock
1823
3068
1824 return voltsCohDet
3069 return voltsCohDet
1825
3070
1826 def __calculateCCF(self, volts, pairslist ,laglist):
3071 def __calculateCCF(self, volts, pairslist ,laglist):
1827
3072
1828 nHeights = volts.shape[2]
3073 nHeights = volts.shape[2]
1829 nPoints = volts.shape[1]
3074 nPoints = volts.shape[1]
1830 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3075 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
1831
3076
1832 for i in range(len(pairslist)):
3077 for i in range(len(pairslist)):
1833 volts1 = volts[pairslist[i][0]]
3078 volts1 = volts[pairslist[i][0]]
1834 volts2 = volts[pairslist[i][1]]
3079 volts2 = volts[pairslist[i][1]]
1835
3080
1836 for t in range(len(laglist)):
3081 for t in range(len(laglist)):
1837 idxT = laglist[t]
3082 idxT = laglist[t]
1838 if idxT >= 0:
3083 if idxT >= 0:
1839 vStacked = numpy.vstack((volts2[idxT:,:],
3084 vStacked = numpy.vstack((volts2[idxT:,:],
1840 numpy.zeros((idxT, nHeights),dtype='complex')))
3085 numpy.zeros((idxT, nHeights),dtype='complex')))
@@ -1842,10 +3087,10 class SMDetection(Operation):
1842 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3087 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
1843 volts2[:(nPoints + idxT),:]))
3088 volts2[:(nPoints + idxT),:]))
1844 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3089 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
1845
3090
1846 vStacked = None
3091 vStacked = None
1847 return voltsCCF
3092 return voltsCCF
1848
3093
1849 def __getNoise(self, power, timeSegment, timeInterval):
3094 def __getNoise(self, power, timeSegment, timeInterval):
1850 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3095 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
1851 numBlocks = int(power.shape[0]/numProfPerBlock)
3096 numBlocks = int(power.shape[0]/numProfPerBlock)
@@ -1854,133 +3099,133 class SMDetection(Operation):
1854 listPower = numpy.array_split(power, numBlocks, 0)
3099 listPower = numpy.array_split(power, numBlocks, 0)
1855 noise = numpy.zeros((power.shape[0], power.shape[1]))
3100 noise = numpy.zeros((power.shape[0], power.shape[1]))
1856 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3101 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
1857
3102
1858 startInd = 0
3103 startInd = 0
1859 endInd = 0
3104 endInd = 0
1860
3105
1861 for i in range(numBlocks): #split por canal
3106 for i in range(numBlocks): #split por canal
1862 startInd = endInd
3107 startInd = endInd
1863 endInd = endInd + listPower[i].shape[0]
3108 endInd = endInd + listPower[i].shape[0]
1864
3109
1865 arrayBlock = listPower[i]
3110 arrayBlock = listPower[i]
1866 noiseAux = numpy.mean(arrayBlock, 0)
3111 noiseAux = numpy.mean(arrayBlock, 0)
1867 # noiseAux = numpy.median(noiseAux)
3112 # noiseAux = numpy.median(noiseAux)
1868 # noiseAux = numpy.mean(arrayBlock)
3113 # noiseAux = numpy.mean(arrayBlock)
1869 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3114 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
1870
3115
1871 noiseAux1 = numpy.mean(arrayBlock)
3116 noiseAux1 = numpy.mean(arrayBlock)
1872 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3117 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
1873
3118
1874 return noise, noise1
3119 return noise, noise1
1875
3120
1876 def __findMeteors(self, power, thresh):
3121 def __findMeteors(self, power, thresh):
1877 nProf = power.shape[0]
3122 nProf = power.shape[0]
1878 nHeights = power.shape[1]
3123 nHeights = power.shape[1]
1879 listMeteors = []
3124 listMeteors = []
1880
3125
1881 for i in range(nHeights):
3126 for i in range(nHeights):
1882 powerAux = power[:,i]
3127 powerAux = power[:,i]
1883 threshAux = thresh[:,i]
3128 threshAux = thresh[:,i]
1884
3129
1885 indUPthresh = numpy.where(powerAux > threshAux)[0]
3130 indUPthresh = numpy.where(powerAux > threshAux)[0]
1886 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3131 indDNthresh = numpy.where(powerAux <= threshAux)[0]
1887
3132
1888 j = 0
3133 j = 0
1889
3134
1890 while (j < indUPthresh.size - 2):
3135 while (j < indUPthresh.size - 2):
1891 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3136 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
1892 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3137 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
1893 indDNthresh = indDNthresh[indDNAux]
3138 indDNthresh = indDNthresh[indDNAux]
1894
3139
1895 if (indDNthresh.size > 0):
3140 if (indDNthresh.size > 0):
1896 indEnd = indDNthresh[0] - 1
3141 indEnd = indDNthresh[0] - 1
1897 indInit = indUPthresh[j] if isinstance(indUPthresh[j], (int, float)) else indUPthresh[j][0] ##CHECK!!!!
3142 indInit = indUPthresh[j]
1898
3143
1899 meteor = powerAux[indInit:indEnd + 1]
3144 meteor = powerAux[indInit:indEnd + 1]
1900 indPeak = meteor.argmax() + indInit
3145 indPeak = meteor.argmax() + indInit
1901 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3146 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
1902
3147
1903 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3148 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
1904 j = numpy.where(indUPthresh == indEnd)[0] + 1
3149 j = numpy.where(indUPthresh == indEnd)[0] + 1
1905 else: j+=1
3150 else: j+=1
1906 else: j+=1
3151 else: j+=1
1907
3152
1908 return listMeteors
3153 return listMeteors
1909
3154
1910 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3155 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
1911
3156
1912 arrayMeteors = numpy.asarray(listMeteors)
3157 arrayMeteors = numpy.asarray(listMeteors)
1913 listMeteors1 = []
3158 listMeteors1 = []
1914
3159
1915 while arrayMeteors.shape[0] > 0:
3160 while arrayMeteors.shape[0] > 0:
1916 FLAs = arrayMeteors[:,4]
3161 FLAs = arrayMeteors[:,4]
1917 maxFLA = FLAs.argmax()
3162 maxFLA = FLAs.argmax()
1918 listMeteors1.append(arrayMeteors[maxFLA,:])
3163 listMeteors1.append(arrayMeteors[maxFLA,:])
1919
3164
1920 MeteorInitTime = arrayMeteors[maxFLA,1]
3165 MeteorInitTime = arrayMeteors[maxFLA,1]
1921 MeteorEndTime = arrayMeteors[maxFLA,3]
3166 MeteorEndTime = arrayMeteors[maxFLA,3]
1922 MeteorHeight = arrayMeteors[maxFLA,0]
3167 MeteorHeight = arrayMeteors[maxFLA,0]
1923
3168
1924 #Check neighborhood
3169 #Check neighborhood
1925 maxHeightIndex = MeteorHeight + rangeLimit
3170 maxHeightIndex = MeteorHeight + rangeLimit
1926 minHeightIndex = MeteorHeight - rangeLimit
3171 minHeightIndex = MeteorHeight - rangeLimit
1927 minTimeIndex = MeteorInitTime - timeLimit
3172 minTimeIndex = MeteorInitTime - timeLimit
1928 maxTimeIndex = MeteorEndTime + timeLimit
3173 maxTimeIndex = MeteorEndTime + timeLimit
1929
3174
1930 #Check Heights
3175 #Check Heights
1931 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3176 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
1932 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3177 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
1933 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3178 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
1934
3179
1935 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3180 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
1936
3181
1937 return listMeteors1
3182 return listMeteors1
1938
3183
1939 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3184 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
1940 numHeights = volts.shape[2]
3185 numHeights = volts.shape[2]
1941 nChannel = volts.shape[0]
3186 nChannel = volts.shape[0]
1942
3187
1943 thresholdPhase = thresh[0]
3188 thresholdPhase = thresh[0]
1944 thresholdNoise = thresh[1]
3189 thresholdNoise = thresh[1]
1945 thresholdDB = float(thresh[2])
3190 thresholdDB = float(thresh[2])
1946
3191
1947 thresholdDB1 = 10**(thresholdDB/10)
3192 thresholdDB1 = 10**(thresholdDB/10)
1948 pairsarray = numpy.array(pairslist)
3193 pairsarray = numpy.array(pairslist)
1949 indSides = pairsarray[:,1]
3194 indSides = pairsarray[:,1]
1950
3195
1951 pairslist1 = list(pairslist)
3196 pairslist1 = list(pairslist)
1952 pairslist1.append((0,4))
3197 pairslist1.append((0,1))
1953 pairslist1.append((1,3))
3198 pairslist1.append((3,4))
1954
3199
1955 listMeteors1 = []
3200 listMeteors1 = []
1956 listPowerSeries = []
3201 listPowerSeries = []
1957 listVoltageSeries = []
3202 listVoltageSeries = []
1958 #volts has the war data
3203 #volts has the war data
1959
3204
1960 if frequency == 30.175e6:
3205 if frequency == 30e6:
1961 timeLag = 45*10**-3
3206 timeLag = 45*10**-3
1962 else:
3207 else:
1963 timeLag = 15*10**-3
3208 timeLag = 15*10**-3
1964 lag = int(numpy.ceil(timeLag/timeInterval))
3209 lag = numpy.ceil(timeLag/timeInterval)
1965
3210
1966 for i in range(len(listMeteors)):
3211 for i in range(len(listMeteors)):
1967
3212
1968 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3213 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
1969 meteorAux = numpy.zeros(16)
3214 meteorAux = numpy.zeros(16)
1970
3215
1971 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3216 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
1972 mHeight = int(listMeteors[i][0])
3217 mHeight = listMeteors[i][0]
1973 mStart = int(listMeteors[i][1])
3218 mStart = listMeteors[i][1]
1974 mPeak = int(listMeteors[i][2])
3219 mPeak = listMeteors[i][2]
1975 mEnd = int(listMeteors[i][3])
3220 mEnd = listMeteors[i][3]
1976
3221
1977 #get the volt data between the start and end times of the meteor
3222 #get the volt data between the start and end times of the meteor
1978 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3223 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
1979 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3224 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
1980
3225
1981 #3.6. Phase Difference estimation
3226 #3.6. Phase Difference estimation
1982 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3227 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
1983
3228
1984 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3229 #3.7. Phase difference removal & meteor start, peak and end times reestimated
1985 #meteorVolts0.- all Channels, all Profiles
3230 #meteorVolts0.- all Channels, all Profiles
1986 meteorVolts0 = volts[:,:,mHeight]
3231 meteorVolts0 = volts[:,:,mHeight]
@@ -1988,15 +3233,15 class SMDetection(Operation):
1988 meteorNoise = noise[:,mHeight]
3233 meteorNoise = noise[:,mHeight]
1989 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3234 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
1990 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3235 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
1991
3236
1992 #Times reestimation
3237 #Times reestimation
1993 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3238 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
1994 if mStart1.size > 0:
3239 if mStart1.size > 0:
1995 mStart1 = mStart1[-1] + 1
3240 mStart1 = mStart1[-1] + 1
1996
3241
1997 else:
3242 else:
1998 mStart1 = mPeak
3243 mStart1 = mPeak
1999
3244
2000 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3245 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
2001 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3246 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
2002 if mEndDecayTime1.size == 0:
3247 if mEndDecayTime1.size == 0:
@@ -2004,7 +3249,7 class SMDetection(Operation):
2004 else:
3249 else:
2005 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3250 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
2006 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3251 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
2007
3252
2008 #meteorVolts1.- all Channels, from start to end
3253 #meteorVolts1.- all Channels, from start to end
2009 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3254 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
2010 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3255 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
@@ -2013,17 +3258,17 class SMDetection(Operation):
2013 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3258 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
2014 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3259 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
2015 ##################### END PARAMETERS REESTIMATION #########################
3260 ##################### END PARAMETERS REESTIMATION #########################
2016
3261
2017 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3262 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
2018 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3263 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
2019 if meteorVolts2.shape[1] > 0:
3264 if meteorVolts2.shape[1] > 0:
2020 #Phase Difference re-estimation
3265 #Phase Difference re-estimation
2021 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3266 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
2022 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3267 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
2023 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3268 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
2024 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3269 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
2025 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3270 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
2026
3271
2027 #Phase Difference RMS
3272 #Phase Difference RMS
2028 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3273 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
2029 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3274 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
@@ -2038,50 +3283,50 class SMDetection(Operation):
2038 #Vectorize
3283 #Vectorize
2039 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3284 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
2040 meteorAux[7:11] = phaseDiffint[0:4]
3285 meteorAux[7:11] = phaseDiffint[0:4]
2041
3286
2042 #Rejection Criterions
3287 #Rejection Criterions
2043 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3288 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
2044 meteorAux[-1] = 17
3289 meteorAux[-1] = 17
2045 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3290 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
2046 meteorAux[-1] = 1
3291 meteorAux[-1] = 1
2047
3292
2048
3293
2049 else:
3294 else:
2050 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3295 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
2051 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3296 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
2052 PowerSeries = 0
3297 PowerSeries = 0
2053
3298
2054 listMeteors1.append(meteorAux)
3299 listMeteors1.append(meteorAux)
2055 listPowerSeries.append(PowerSeries)
3300 listPowerSeries.append(PowerSeries)
2056 listVoltageSeries.append(meteorVolts1)
3301 listVoltageSeries.append(meteorVolts1)
2057
3302
2058 return listMeteors1, listPowerSeries, listVoltageSeries
3303 return listMeteors1, listPowerSeries, listVoltageSeries
2059
3304
2060 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3305 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
2061
3306
2062 threshError = 10
3307 threshError = 10
2063 #Depending if it is 30 or 50 MHz
3308 #Depending if it is 30 or 50 MHz
2064 if frequency == 30.175e6:
3309 if frequency == 30e6:
2065 timeLag = 45*10**-3
3310 timeLag = 45*10**-3
2066 else:
3311 else:
2067 timeLag = 15*10**-3
3312 timeLag = 15*10**-3
2068 lag = int(numpy.ceil(timeLag/timeInterval))
3313 lag = numpy.ceil(timeLag/timeInterval)
2069
3314
2070 listMeteors1 = []
3315 listMeteors1 = []
2071
3316
2072 for i in range(len(listMeteors)):
3317 for i in range(len(listMeteors)):
2073 meteorPower = listPower[i]
3318 meteorPower = listPower[i]
2074 meteorAux = listMeteors[i]
3319 meteorAux = listMeteors[i]
2075
3320
2076 if meteorAux[-1] == 0:
3321 if meteorAux[-1] == 0:
2077
3322
2078 try:
3323 try:
2079 indmax = meteorPower.argmax()
3324 indmax = meteorPower.argmax()
2080 indlag = indmax + lag
3325 indlag = indmax + lag
2081
3326
2082 y = meteorPower[indlag:]
3327 y = meteorPower[indlag:]
2083 x = numpy.arange(0, y.size)*timeLag
3328 x = numpy.arange(0, y.size)*timeLag
2084
3329
2085 #first guess
3330 #first guess
2086 a = y[0]
3331 a = y[0]
2087 tau = timeLag
3332 tau = timeLag
@@ -2090,26 +3335,26 class SMDetection(Operation):
2090 y1 = self.__exponential_function(x, *popt)
3335 y1 = self.__exponential_function(x, *popt)
2091 #error estimation
3336 #error estimation
2092 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3337 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
2093
3338
2094 decayTime = popt[1]
3339 decayTime = popt[1]
2095 riseTime = indmax*timeInterval
3340 riseTime = indmax*timeInterval
2096 meteorAux[11:13] = [decayTime, error]
3341 meteorAux[11:13] = [decayTime, error]
2097
3342
2098 #Table items 7, 8 and 11
3343 #Table items 7, 8 and 11
2099 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3344 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
2100 meteorAux[-1] = 7
3345 meteorAux[-1] = 7
2101 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3346 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
2102 meteorAux[-1] = 8
3347 meteorAux[-1] = 8
2103 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3348 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
2104 meteorAux[-1] = 11
3349 meteorAux[-1] = 11
2105
3350
2106
3351
2107 except:
3352 except:
2108 meteorAux[-1] = 11
3353 meteorAux[-1] = 11
2109
3354
2110
3355
2111 listMeteors1.append(meteorAux)
3356 listMeteors1.append(meteorAux)
2112
3357
2113 return listMeteors1
3358 return listMeteors1
2114
3359
2115 #Exponential Function
3360 #Exponential Function
@@ -2117,45 +3362,45 class SMDetection(Operation):
2117 def __exponential_function(self, x, a, tau):
3362 def __exponential_function(self, x, a, tau):
2118 y = a*numpy.exp(-x/tau)
3363 y = a*numpy.exp(-x/tau)
2119 return y
3364 return y
2120
3365
2121 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3366 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
2122
3367
2123 pairslist1 = list(pairslist)
3368 pairslist1 = list(pairslist)
2124 pairslist1.append((0,4))
3369 pairslist1.append((0,1))
2125 pairslist1.append((1,3))
3370 pairslist1.append((3,4))
2126 numPairs = len(pairslist1)
3371 numPairs = len(pairslist1)
2127 #Time Lag
3372 #Time Lag
2128 timeLag = 45*10**-3
3373 timeLag = 45*10**-3
2129 c = 3e8
3374 c = 3e8
2130 lag = numpy.ceil(timeLag/timeInterval)
3375 lag = numpy.ceil(timeLag/timeInterval)
2131 freq = 30.175e6
3376 freq = 30e6
2132
3377
2133 listMeteors1 = []
3378 listMeteors1 = []
2134
3379
2135 for i in range(len(listMeteors)):
3380 for i in range(len(listMeteors)):
2136 meteorAux = listMeteors[i]
3381 meteorAux = listMeteors[i]
2137 if meteorAux[-1] == 0:
3382 if meteorAux[-1] == 0:
2138 mStart = listMeteors[i][1]
3383 mStart = listMeteors[i][1]
2139 mPeak = listMeteors[i][2]
3384 mPeak = listMeteors[i][2]
2140 mLag = mPeak - mStart + lag
3385 mLag = mPeak - mStart + lag
2141
3386
2142 #get the volt data between the start and end times of the meteor
3387 #get the volt data between the start and end times of the meteor
2143 meteorVolts = listVolts[i]
3388 meteorVolts = listVolts[i]
2144 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3389 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
2145
3390
2146 #Get CCF
3391 #Get CCF
2147 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3392 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
2148
3393
2149 #Method 2
3394 #Method 2
2150 slopes = numpy.zeros(numPairs)
3395 slopes = numpy.zeros(numPairs)
2151 time = numpy.array([-2,-1,1,2])*timeInterval
3396 time = numpy.array([-2,-1,1,2])*timeInterval
2152 angAllCCF = numpy.angle(allCCFs[:,[0,4,2,3],0])
3397 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
2153
3398
2154 #Correct phases
3399 #Correct phases
2155 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3400 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
2156 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3401 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2157
3402
2158 if indDer[0].shape[0] > 0:
3403 if indDer[0].shape[0] > 0:
2159 for i in range(indDer[0].shape[0]):
3404 for i in range(indDer[0].shape[0]):
2160 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3405 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
2161 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3406 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
@@ -2164,51 +3409,51 class SMDetection(Operation):
2164 for j in range(numPairs):
3409 for j in range(numPairs):
2165 fit = stats.linregress(time, angAllCCF[j,:])
3410 fit = stats.linregress(time, angAllCCF[j,:])
2166 slopes[j] = fit[0]
3411 slopes[j] = fit[0]
2167
3412
2168 #Remove Outlier
3413 #Remove Outlier
2169 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3414 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
2170 # slopes = numpy.delete(slopes,indOut)
3415 # slopes = numpy.delete(slopes,indOut)
2171 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3416 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
2172 # slopes = numpy.delete(slopes,indOut)
3417 # slopes = numpy.delete(slopes,indOut)
2173
3418
2174 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3419 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
2175 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3420 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
2176 meteorAux[-2] = radialError
3421 meteorAux[-2] = radialError
2177 meteorAux[-3] = radialVelocity
3422 meteorAux[-3] = radialVelocity
2178
3423
2179 #Setting Error
3424 #Setting Error
2180 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3425 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
2181 if numpy.abs(radialVelocity) > 200:
3426 if numpy.abs(radialVelocity) > 200:
2182 meteorAux[-1] = 15
3427 meteorAux[-1] = 15
2183 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3428 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
2184 elif radialError > radialStdThresh:
3429 elif radialError > radialStdThresh:
2185 meteorAux[-1] = 12
3430 meteorAux[-1] = 12
2186
3431
2187 listMeteors1.append(meteorAux)
3432 listMeteors1.append(meteorAux)
2188 return listMeteors1
3433 return listMeteors1
2189
3434
2190 def __setNewArrays(self, listMeteors, date, heiRang):
3435 def __setNewArrays(self, listMeteors, date, heiRang):
2191
3436
2192 #New arrays
3437 #New arrays
2193 arrayMeteors = numpy.array(listMeteors)
3438 arrayMeteors = numpy.array(listMeteors)
2194 arrayParameters = numpy.zeros((len(listMeteors), 13))
3439 arrayParameters = numpy.zeros((len(listMeteors), 13))
2195
3440
2196 #Date inclusion
3441 #Date inclusion
2197 # date = re.findall(r'\((.*?)\)', date)
3442 # date = re.findall(r'\((.*?)\)', date)
2198 # date = date[0].split(',')
3443 # date = date[0].split(',')
2199 # date = map(int, date)
3444 # date = map(int, date)
2200 #
3445 #
2201 # if len(date)<6:
3446 # if len(date)<6:
2202 # date.append(0)
3447 # date.append(0)
2203 #
3448 #
2204 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3449 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
2205 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3450 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
2206 arrayDate = numpy.tile(date, (len(listMeteors)))
3451 arrayDate = numpy.tile(date, (len(listMeteors)))
2207
3452
2208 #Meteor array
3453 #Meteor array
2209 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3454 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
2210 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3455 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
2211
3456
2212 #Parameters Array
3457 #Parameters Array
2213 arrayParameters[:,0] = arrayDate #Date
3458 arrayParameters[:,0] = arrayDate #Date
2214 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3459 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
@@ -2216,13 +3461,13 class SMDetection(Operation):
2216 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3461 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
2217 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3462 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
2218
3463
2219
3464
2220 return arrayParameters
3465 return arrayParameters
2221
3466
2222 class CorrectSMPhases(Operation):
3467 class CorrectSMPhases(Operation):
2223
3468
2224 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3469 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
2225
3470
2226 arrayParameters = dataOut.data_param
3471 arrayParameters = dataOut.data_param
2227 pairsList = []
3472 pairsList = []
2228 pairx = (0,1)
3473 pairx = (0,1)
@@ -2230,49 +3475,49 class CorrectSMPhases(Operation):
2230 pairsList.append(pairx)
3475 pairsList.append(pairx)
2231 pairsList.append(pairy)
3476 pairsList.append(pairy)
2232 jph = numpy.zeros(4)
3477 jph = numpy.zeros(4)
2233
3478
2234 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3479 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2235 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3480 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2236 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3481 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
2237
3482
2238 meteorOps = SMOperations()
3483 meteorOps = SMOperations()
2239 if channelPositions is None:
3484 if channelPositions == None:
2240 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3485 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2241 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3486 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2242
3487
2243 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3488 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2244 h = (hmin,hmax)
3489 h = (hmin,hmax)
2245
3490
2246 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3491 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2247
3492
2248 dataOut.data_param = arrayParameters
3493 dataOut.data_param = arrayParameters
2249 return
3494 return
2250
3495
2251 class SMPhaseCalibration(Operation):
3496 class SMPhaseCalibration(Operation):
2252
3497
2253 __buffer = None
3498 __buffer = None
2254
3499
2255 __initime = None
3500 __initime = None
2256
3501
2257 __dataReady = False
3502 __dataReady = False
2258
3503
2259 __isConfig = False
3504 __isConfig = False
2260
3505
2261 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3506 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
2262
3507
2263 dataTime = currentTime + paramInterval
3508 dataTime = currentTime + paramInterval
2264 deltaTime = dataTime - initTime
3509 deltaTime = dataTime - initTime
2265
3510
2266 if deltaTime >= outputInterval or deltaTime < 0:
3511 if deltaTime >= outputInterval or deltaTime < 0:
2267 return True
3512 return True
2268
3513
2269 return False
3514 return False
2270
3515
2271 def __getGammas(self, pairs, d, phases):
3516 def __getGammas(self, pairs, d, phases):
2272 gammas = numpy.zeros(2)
3517 gammas = numpy.zeros(2)
2273
3518
2274 for i in range(len(pairs)):
3519 for i in range(len(pairs)):
2275
3520
2276 pairi = pairs[i]
3521 pairi = pairs[i]
2277
3522
2278 phip3 = phases[:,pairi[0]]
3523 phip3 = phases[:,pairi[0]]
@@ -2286,7 +3531,7 class SMPhaseCalibration(Operation):
2286 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3531 jgamma = numpy.angle(numpy.exp(1j*jgamma))
2287 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3532 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
2288 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3533 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
2289
3534
2290 #Revised distribution
3535 #Revised distribution
2291 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3536 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
2292
3537
@@ -2295,39 +3540,39 class SMPhaseCalibration(Operation):
2295 rmin = -0.5*numpy.pi
3540 rmin = -0.5*numpy.pi
2296 rmax = 0.5*numpy.pi
3541 rmax = 0.5*numpy.pi
2297 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3542 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
2298
3543
2299 meteorsY = phaseHisto[0]
3544 meteorsY = phaseHisto[0]
2300 phasesX = phaseHisto[1][:-1]
3545 phasesX = phaseHisto[1][:-1]
2301 width = phasesX[1] - phasesX[0]
3546 width = phasesX[1] - phasesX[0]
2302 phasesX += width/2
3547 phasesX += width/2
2303
3548
2304 #Gaussian aproximation
3549 #Gaussian aproximation
2305 bpeak = meteorsY.argmax()
3550 bpeak = meteorsY.argmax()
2306 peak = meteorsY.max()
3551 peak = meteorsY.max()
2307 jmin = bpeak - 5
3552 jmin = bpeak - 5
2308 jmax = bpeak + 5 + 1
3553 jmax = bpeak + 5 + 1
2309
3554
2310 if jmin<0:
3555 if jmin<0:
2311 jmin = 0
3556 jmin = 0
2312 jmax = 6
3557 jmax = 6
2313 elif jmax > meteorsY.size:
3558 elif jmax > meteorsY.size:
2314 jmin = meteorsY.size - 6
3559 jmin = meteorsY.size - 6
2315 jmax = meteorsY.size
3560 jmax = meteorsY.size
2316
3561
2317 x0 = numpy.array([peak,bpeak,50])
3562 x0 = numpy.array([peak,bpeak,50])
2318 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3563 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
2319
3564
2320 #Gammas
3565 #Gammas
2321 gammas[i] = coeff[0][1]
3566 gammas[i] = coeff[0][1]
2322
3567
2323 return gammas
3568 return gammas
2324
3569
2325 def __residualFunction(self, coeffs, y, t):
3570 def __residualFunction(self, coeffs, y, t):
2326
3571
2327 return y - self.__gauss_function(t, coeffs)
3572 return y - self.__gauss_function(t, coeffs)
2328
3573
2329 def __gauss_function(self, t, coeffs):
3574 def __gauss_function(self, t, coeffs):
2330
3575
2331 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3576 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
2332
3577
2333 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3578 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
@@ -2348,16 +3593,16 class SMPhaseCalibration(Operation):
2348 max_xangle = range_angle[iz]/2 + center_xangle
3593 max_xangle = range_angle[iz]/2 + center_xangle
2349 min_yangle = -range_angle[iz]/2 + center_yangle
3594 min_yangle = -range_angle[iz]/2 + center_yangle
2350 max_yangle = range_angle[iz]/2 + center_yangle
3595 max_yangle = range_angle[iz]/2 + center_yangle
2351
3596
2352 inc_x = (max_xangle-min_xangle)/nstepsx
3597 inc_x = (max_xangle-min_xangle)/nstepsx
2353 inc_y = (max_yangle-min_yangle)/nstepsy
3598 inc_y = (max_yangle-min_yangle)/nstepsy
2354
3599
2355 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3600 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
2356 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3601 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
2357 penalty = numpy.zeros((nstepsx,nstepsy))
3602 penalty = numpy.zeros((nstepsx,nstepsy))
2358 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3603 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
2359 jph = numpy.zeros(nchan)
3604 jph = numpy.zeros(nchan)
2360
3605
2361 # Iterations looking for the offset
3606 # Iterations looking for the offset
2362 for iy in range(int(nstepsy)):
3607 for iy in range(int(nstepsy)):
2363 for ix in range(int(nstepsx)):
3608 for ix in range(int(nstepsx)):
@@ -2387,24 +3632,24 class SMPhaseCalibration(Operation):
2387 error = meteorsArray1[:,-1]
3632 error = meteorsArray1[:,-1]
2388 ind1 = numpy.where(error==0)[0]
3633 ind1 = numpy.where(error==0)[0]
2389 penalty[ix,iy] = ind1.size
3634 penalty[ix,iy] = ind1.size
2390
3635
2391 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3636 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
2392 phOffset = jph_array[:,i,j]
3637 phOffset = jph_array[:,i,j]
2393
3638
2394 center_xangle = phOffset[pairx[1]]
3639 center_xangle = phOffset[pairx[1]]
2395 center_yangle = phOffset[pairy[1]]
3640 center_yangle = phOffset[pairy[1]]
2396
3641
2397 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3642 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
2398 phOffset = phOffset*180/numpy.pi
3643 phOffset = phOffset*180/numpy.pi
2399 return phOffset
3644 return phOffset
2400
3645
2401
3646
2402 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3647 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
2403
3648
2404 dataOut.flagNoData = True
3649 dataOut.flagNoData = True
2405 self.__dataReady = False
3650 self.__dataReady = False
2406 dataOut.outputInterval = nHours*3600
3651 dataOut.outputInterval = nHours*3600
2407
3652
2408 if self.__isConfig == False:
3653 if self.__isConfig == False:
2409 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3654 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2410 #Get Initial LTC time
3655 #Get Initial LTC time
@@ -2412,19 +3657,19 class SMPhaseCalibration(Operation):
2412 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3657 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2413
3658
2414 self.__isConfig = True
3659 self.__isConfig = True
2415
3660
2416 if self.__buffer is None:
3661 if self.__buffer == None:
2417 self.__buffer = dataOut.data_param.copy()
3662 self.__buffer = dataOut.data_param.copy()
2418
3663
2419 else:
3664 else:
2420 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3665 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2421
3666
2422 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3667 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2423
3668
2424 if self.__dataReady:
3669 if self.__dataReady:
2425 dataOut.utctimeInit = self.__initime
3670 dataOut.utctimeInit = self.__initime
2426 self.__initime += dataOut.outputInterval #to erase time offset
3671 self.__initime += dataOut.outputInterval #to erase time offset
2427
3672
2428 freq = dataOut.frequency
3673 freq = dataOut.frequency
2429 c = dataOut.C #m/s
3674 c = dataOut.C #m/s
2430 lamb = c/freq
3675 lamb = c/freq
@@ -2452,7 +3697,7 class SMPhaseCalibration(Operation):
2452 else:
3697 else:
2453 pairs.append((2,3))
3698 pairs.append((2,3))
2454 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3699 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
2455
3700
2456 meteorsArray = self.__buffer
3701 meteorsArray = self.__buffer
2457 error = meteorsArray[:,-1]
3702 error = meteorsArray[:,-1]
2458 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3703 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
@@ -2460,7 +3705,7 class SMPhaseCalibration(Operation):
2460 meteorsArray = meteorsArray[ind1,:]
3705 meteorsArray = meteorsArray[ind1,:]
2461 meteorsArray[:,-1] = 0
3706 meteorsArray[:,-1] = 0
2462 phases = meteorsArray[:,8:12]
3707 phases = meteorsArray[:,8:12]
2463
3708
2464 #Calculate Gammas
3709 #Calculate Gammas
2465 gammas = self.__getGammas(pairs, distances, phases)
3710 gammas = self.__getGammas(pairs, distances, phases)
2466 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3711 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
@@ -2469,24 +3714,23 class SMPhaseCalibration(Operation):
2469 phasesOff = phasesOff.reshape((1,phasesOff.size))
3714 phasesOff = phasesOff.reshape((1,phasesOff.size))
2470 dataOut.data_output = -phasesOff
3715 dataOut.data_output = -phasesOff
2471 dataOut.flagNoData = False
3716 dataOut.flagNoData = False
2472 dataOut.channelList = pairslist0
2473 self.__buffer = None
3717 self.__buffer = None
2474
3718
2475
3719
2476 return
3720 return
2477
3721
2478 class SMOperations():
3722 class SMOperations():
2479
3723
2480 def __init__(self):
3724 def __init__(self):
2481
3725
2482 return
3726 return
2483
3727
2484 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3728 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
2485
3729
2486 arrayParameters = arrayParameters0.copy()
3730 arrayParameters = arrayParameters0.copy()
2487 hmin = h[0]
3731 hmin = h[0]
2488 hmax = h[1]
3732 hmax = h[1]
2489
3733
2490 #Calculate AOA (Error N 3, 4)
3734 #Calculate AOA (Error N 3, 4)
2491 #JONES ET AL. 1998
3735 #JONES ET AL. 1998
2492 AOAthresh = numpy.pi/8
3736 AOAthresh = numpy.pi/8
@@ -2494,72 +3738,72 class SMOperations():
2494 phases = -arrayParameters[:,8:12] + jph
3738 phases = -arrayParameters[:,8:12] + jph
2495 # phases = numpy.unwrap(phases)
3739 # phases = numpy.unwrap(phases)
2496 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3740 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
2497
3741
2498 #Calculate Heights (Error N 13 and 14)
3742 #Calculate Heights (Error N 13 and 14)
2499 error = arrayParameters[:,-1]
3743 error = arrayParameters[:,-1]
2500 Ranges = arrayParameters[:,1]
3744 Ranges = arrayParameters[:,1]
2501 zenith = arrayParameters[:,4]
3745 zenith = arrayParameters[:,4]
2502 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3746 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
2503
3747
2504 #----------------------- Get Final data ------------------------------------
3748 #----------------------- Get Final data ------------------------------------
2505 # error = arrayParameters[:,-1]
3749 # error = arrayParameters[:,-1]
2506 # ind1 = numpy.where(error==0)[0]
3750 # ind1 = numpy.where(error==0)[0]
2507 # arrayParameters = arrayParameters[ind1,:]
3751 # arrayParameters = arrayParameters[ind1,:]
2508
3752
2509 return arrayParameters
3753 return arrayParameters
2510
3754
2511 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3755 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
2512
3756
2513 arrayAOA = numpy.zeros((phases.shape[0],3))
3757 arrayAOA = numpy.zeros((phases.shape[0],3))
2514 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3758 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
2515
3759
2516 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3760 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2517 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3761 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2518 arrayAOA[:,2] = cosDirError
3762 arrayAOA[:,2] = cosDirError
2519
3763
2520 azimuthAngle = arrayAOA[:,0]
3764 azimuthAngle = arrayAOA[:,0]
2521 zenithAngle = arrayAOA[:,1]
3765 zenithAngle = arrayAOA[:,1]
2522
3766
2523 #Setting Error
3767 #Setting Error
2524 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3768 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
2525 error[indError] = 0
3769 error[indError] = 0
2526 #Number 3: AOA not fesible
3770 #Number 3: AOA not fesible
2527 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3771 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2528 error[indInvalid] = 3
3772 error[indInvalid] = 3
2529 #Number 4: Large difference in AOAs obtained from different antenna baselines
3773 #Number 4: Large difference in AOAs obtained from different antenna baselines
2530 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3774 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2531 error[indInvalid] = 4
3775 error[indInvalid] = 4
2532 return arrayAOA, error
3776 return arrayAOA, error
2533
3777
2534 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3778 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
2535
3779
2536 #Initializing some variables
3780 #Initializing some variables
2537 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3781 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2538 ang_aux = ang_aux.reshape(1,ang_aux.size)
3782 ang_aux = ang_aux.reshape(1,ang_aux.size)
2539
3783
2540 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3784 cosdir = numpy.zeros((arrayPhase.shape[0],2))
2541 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3785 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2542
3786
2543
3787
2544 for i in range(2):
3788 for i in range(2):
2545 ph0 = arrayPhase[:,pairsList[i][0]]
3789 ph0 = arrayPhase[:,pairsList[i][0]]
2546 ph1 = arrayPhase[:,pairsList[i][1]]
3790 ph1 = arrayPhase[:,pairsList[i][1]]
2547 d0 = distances[pairsList[i][0]]
3791 d0 = distances[pairsList[i][0]]
2548 d1 = distances[pairsList[i][1]]
3792 d1 = distances[pairsList[i][1]]
2549
3793
2550 ph0_aux = ph0 + ph1
3794 ph0_aux = ph0 + ph1
2551 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3795 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
2552 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3796 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
2553 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3797 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
2554 #First Estimation
3798 #First Estimation
2555 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3799 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
2556
3800
2557 #Most-Accurate Second Estimation
3801 #Most-Accurate Second Estimation
2558 phi1_aux = ph0 - ph1
3802 phi1_aux = ph0 - ph1
2559 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3803 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2560 #Direction Cosine 1
3804 #Direction Cosine 1
2561 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3805 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
2562
3806
2563 #Searching the correct Direction Cosine
3807 #Searching the correct Direction Cosine
2564 cosdir0_aux = cosdir0[:,i]
3808 cosdir0_aux = cosdir0[:,i]
2565 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3809 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
@@ -2568,59 +3812,59 class SMOperations():
2568 indcos = cosDiff.argmin(axis = 1)
3812 indcos = cosDiff.argmin(axis = 1)
2569 #Saving Value obtained
3813 #Saving Value obtained
2570 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3814 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2571
3815
2572 return cosdir0, cosdir
3816 return cosdir0, cosdir
2573
3817
2574 def __calculateAOA(self, cosdir, azimuth):
3818 def __calculateAOA(self, cosdir, azimuth):
2575 cosdirX = cosdir[:,0]
3819 cosdirX = cosdir[:,0]
2576 cosdirY = cosdir[:,1]
3820 cosdirY = cosdir[:,1]
2577
3821
2578 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3822 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2579 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3823 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
2580 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3824 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2581
3825
2582 return angles
3826 return angles
2583
3827
2584 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3828 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2585
3829
2586 Ramb = 375 #Ramb = c/(2*PRF)
3830 Ramb = 375 #Ramb = c/(2*PRF)
2587 Re = 6371 #Earth Radius
3831 Re = 6371 #Earth Radius
2588 heights = numpy.zeros(Ranges.shape)
3832 heights = numpy.zeros(Ranges.shape)
2589
3833
2590 R_aux = numpy.array([0,1,2])*Ramb
3834 R_aux = numpy.array([0,1,2])*Ramb
2591 R_aux = R_aux.reshape(1,R_aux.size)
3835 R_aux = R_aux.reshape(1,R_aux.size)
2592
3836
2593 Ranges = Ranges.reshape(Ranges.size,1)
3837 Ranges = Ranges.reshape(Ranges.size,1)
2594
3838
2595 Ri = Ranges + R_aux
3839 Ri = Ranges + R_aux
2596 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3840 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2597
3841
2598 #Check if there is a height between 70 and 110 km
3842 #Check if there is a height between 70 and 110 km
2599 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3843 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2600 ind_h = numpy.where(h_bool == 1)[0]
3844 ind_h = numpy.where(h_bool == 1)[0]
2601
3845
2602 hCorr = hi[ind_h, :]
3846 hCorr = hi[ind_h, :]
2603 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3847 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2604
3848
2605 hCorr = hi[ind_hCorr][:len(ind_h)]
3849 hCorr = hi[ind_hCorr][:len(ind_h)]
2606 heights[ind_h] = hCorr
3850 heights[ind_h] = hCorr
2607
3851
2608 #Setting Error
3852 #Setting Error
2609 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3853 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2610 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3854 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2611 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3855 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
2612 error[indError] = 0
3856 error[indError] = 0
2613 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3857 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2614 error[indInvalid2] = 14
3858 error[indInvalid2] = 14
2615 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3859 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2616 error[indInvalid1] = 13
3860 error[indInvalid1] = 13
2617
3861
2618 return heights, error
3862 return heights, error
2619
3863
2620 def getPhasePairs(self, channelPositions):
3864 def getPhasePairs(self, channelPositions):
2621 chanPos = numpy.array(channelPositions)
3865 chanPos = numpy.array(channelPositions)
2622 listOper = list(itertools.combinations(range(5),2))
3866 listOper = list(itertools.combinations(range(5),2))
2623
3867
2624 distances = numpy.zeros(4)
3868 distances = numpy.zeros(4)
2625 axisX = []
3869 axisX = []
2626 axisY = []
3870 axisY = []
@@ -2628,15 +3872,15 class SMOperations():
2628 distY = numpy.zeros(3)
3872 distY = numpy.zeros(3)
2629 ix = 0
3873 ix = 0
2630 iy = 0
3874 iy = 0
2631
3875
2632 pairX = numpy.zeros((2,2))
3876 pairX = numpy.zeros((2,2))
2633 pairY = numpy.zeros((2,2))
3877 pairY = numpy.zeros((2,2))
2634
3878
2635 for i in range(len(listOper)):
3879 for i in range(len(listOper)):
2636 pairi = listOper[i]
3880 pairi = listOper[i]
2637
3881
2638 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3882 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
2639
3883
2640 if posDif[0] == 0:
3884 if posDif[0] == 0:
2641 axisY.append(pairi)
3885 axisY.append(pairi)
2642 distY[iy] = posDif[1]
3886 distY[iy] = posDif[1]
@@ -2645,7 +3889,7 class SMOperations():
2645 axisX.append(pairi)
3889 axisX.append(pairi)
2646 distX[ix] = posDif[0]
3890 distX[ix] = posDif[0]
2647 ix += 1
3891 ix += 1
2648
3892
2649 for i in range(2):
3893 for i in range(2):
2650 if i==0:
3894 if i==0:
2651 dist0 = distX
3895 dist0 = distX
@@ -2653,7 +3897,7 class SMOperations():
2653 else:
3897 else:
2654 dist0 = distY
3898 dist0 = distY
2655 axis0 = axisY
3899 axis0 = axisY
2656
3900
2657 side = numpy.argsort(dist0)[:-1]
3901 side = numpy.argsort(dist0)[:-1]
2658 axis0 = numpy.array(axis0)[side,:]
3902 axis0 = numpy.array(axis0)[side,:]
2659 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3903 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
@@ -2661,7 +3905,7 class SMOperations():
2661 side = axis1[axis1 != chanC]
3905 side = axis1[axis1 != chanC]
2662 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3906 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
2663 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3907 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
2664 if diff1<0:
3908 if diff1<0:
2665 chan2 = side[0]
3909 chan2 = side[0]
2666 d2 = numpy.abs(diff1)
3910 d2 = numpy.abs(diff1)
2667 chan1 = side[1]
3911 chan1 = side[1]
@@ -2671,7 +3915,7 class SMOperations():
2671 d2 = numpy.abs(diff2)
3915 d2 = numpy.abs(diff2)
2672 chan1 = side[0]
3916 chan1 = side[0]
2673 d1 = numpy.abs(diff1)
3917 d1 = numpy.abs(diff1)
2674
3918
2675 if i==0:
3919 if i==0:
2676 chanCX = chanC
3920 chanCX = chanC
2677 chan1X = chan1
3921 chan1X = chan1
@@ -2683,10 +3927,10 class SMOperations():
2683 chan2Y = chan2
3927 chan2Y = chan2
2684 distances[2:4] = numpy.array([d1,d2])
3928 distances[2:4] = numpy.array([d1,d2])
2685 # axisXsides = numpy.reshape(axisX[ix,:],4)
3929 # axisXsides = numpy.reshape(axisX[ix,:],4)
2686 #
3930 #
2687 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3931 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
2688 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3932 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
2689 #
3933 #
2690 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3934 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
2691 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3935 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
2692 # channel25X = int(pairX[0,ind25X])
3936 # channel25X = int(pairX[0,ind25X])
@@ -2695,59 +3939,59 class SMOperations():
2695 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3939 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
2696 # channel25Y = int(pairY[0,ind25Y])
3940 # channel25Y = int(pairY[0,ind25Y])
2697 # channel20Y = int(pairY[1,ind20Y])
3941 # channel20Y = int(pairY[1,ind20Y])
2698
3942
2699 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3943 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
2700 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3944 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
2701
3945
2702 return pairslist, distances
3946 return pairslist, distances
2703 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3947 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
2704 #
3948 #
2705 # arrayAOA = numpy.zeros((phases.shape[0],3))
3949 # arrayAOA = numpy.zeros((phases.shape[0],3))
2706 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3950 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
2707 #
3951 #
2708 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3952 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2709 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3953 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2710 # arrayAOA[:,2] = cosDirError
3954 # arrayAOA[:,2] = cosDirError
2711 #
3955 #
2712 # azimuthAngle = arrayAOA[:,0]
3956 # azimuthAngle = arrayAOA[:,0]
2713 # zenithAngle = arrayAOA[:,1]
3957 # zenithAngle = arrayAOA[:,1]
2714 #
3958 #
2715 # #Setting Error
3959 # #Setting Error
2716 # #Number 3: AOA not fesible
3960 # #Number 3: AOA not fesible
2717 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3961 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2718 # error[indInvalid] = 3
3962 # error[indInvalid] = 3
2719 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3963 # #Number 4: Large difference in AOAs obtained from different antenna baselines
2720 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3964 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2721 # error[indInvalid] = 4
3965 # error[indInvalid] = 4
2722 # return arrayAOA, error
3966 # return arrayAOA, error
2723 #
3967 #
2724 # def __getDirectionCosines(self, arrayPhase, pairsList):
3968 # def __getDirectionCosines(self, arrayPhase, pairsList):
2725 #
3969 #
2726 # #Initializing some variables
3970 # #Initializing some variables
2727 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3971 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2728 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3972 # ang_aux = ang_aux.reshape(1,ang_aux.size)
2729 #
3973 #
2730 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3974 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
2731 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3975 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2732 #
3976 #
2733 #
3977 #
2734 # for i in range(2):
3978 # for i in range(2):
2735 # #First Estimation
3979 # #First Estimation
2736 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3980 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
2737 # #Dealias
3981 # #Dealias
2738 # indcsi = numpy.where(phi0_aux > numpy.pi)
3982 # indcsi = numpy.where(phi0_aux > numpy.pi)
2739 # phi0_aux[indcsi] -= 2*numpy.pi
3983 # phi0_aux[indcsi] -= 2*numpy.pi
2740 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3984 # indcsi = numpy.where(phi0_aux < -numpy.pi)
2741 # phi0_aux[indcsi] += 2*numpy.pi
3985 # phi0_aux[indcsi] += 2*numpy.pi
2742 # #Direction Cosine 0
3986 # #Direction Cosine 0
2743 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3987 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
2744 #
3988 #
2745 # #Most-Accurate Second Estimation
3989 # #Most-Accurate Second Estimation
2746 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3990 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
2747 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3991 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2748 # #Direction Cosine 1
3992 # #Direction Cosine 1
2749 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3993 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
2750 #
3994 #
2751 # #Searching the correct Direction Cosine
3995 # #Searching the correct Direction Cosine
2752 # cosdir0_aux = cosdir0[:,i]
3996 # cosdir0_aux = cosdir0[:,i]
2753 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3997 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
@@ -2756,50 +4000,51 class SMOperations():
2756 # indcos = cosDiff.argmin(axis = 1)
4000 # indcos = cosDiff.argmin(axis = 1)
2757 # #Saving Value obtained
4001 # #Saving Value obtained
2758 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
4002 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2759 #
4003 #
2760 # return cosdir0, cosdir
4004 # return cosdir0, cosdir
2761 #
4005 #
2762 # def __calculateAOA(self, cosdir, azimuth):
4006 # def __calculateAOA(self, cosdir, azimuth):
2763 # cosdirX = cosdir[:,0]
4007 # cosdirX = cosdir[:,0]
2764 # cosdirY = cosdir[:,1]
4008 # cosdirY = cosdir[:,1]
2765 #
4009 #
2766 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
4010 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2767 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
4011 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
2768 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
4012 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2769 #
4013 #
2770 # return angles
4014 # return angles
2771 #
4015 #
2772 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
4016 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2773 #
4017 #
2774 # Ramb = 375 #Ramb = c/(2*PRF)
4018 # Ramb = 375 #Ramb = c/(2*PRF)
2775 # Re = 6371 #Earth Radius
4019 # Re = 6371 #Earth Radius
2776 # heights = numpy.zeros(Ranges.shape)
4020 # heights = numpy.zeros(Ranges.shape)
2777 #
4021 #
2778 # R_aux = numpy.array([0,1,2])*Ramb
4022 # R_aux = numpy.array([0,1,2])*Ramb
2779 # R_aux = R_aux.reshape(1,R_aux.size)
4023 # R_aux = R_aux.reshape(1,R_aux.size)
2780 #
4024 #
2781 # Ranges = Ranges.reshape(Ranges.size,1)
4025 # Ranges = Ranges.reshape(Ranges.size,1)
2782 #
4026 #
2783 # Ri = Ranges + R_aux
4027 # Ri = Ranges + R_aux
2784 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
4028 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2785 #
4029 #
2786 # #Check if there is a height between 70 and 110 km
4030 # #Check if there is a height between 70 and 110 km
2787 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
4031 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2788 # ind_h = numpy.where(h_bool == 1)[0]
4032 # ind_h = numpy.where(h_bool == 1)[0]
2789 #
4033 #
2790 # hCorr = hi[ind_h, :]
4034 # hCorr = hi[ind_h, :]
2791 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
4035 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2792 #
4036 #
2793 # hCorr = hi[ind_hCorr]
4037 # hCorr = hi[ind_hCorr]
2794 # heights[ind_h] = hCorr
4038 # heights[ind_h] = hCorr
2795 #
4039 #
2796 # #Setting Error
4040 # #Setting Error
2797 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
4041 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2798 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
4042 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2799 #
4043 #
2800 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
4044 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2801 # error[indInvalid2] = 14
4045 # error[indInvalid2] = 14
2802 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
4046 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2803 # error[indInvalid1] = 13
4047 # error[indInvalid1] = 13
2804 #
4048 #
2805 # return heights, error
4049 # return heights, error
4050 No newline at end of file
@@ -902,3 +902,4 class IncohInt(Operation):
902 dataOut.nIncohInt *= self.n
902 dataOut.nIncohInt *= self.n
903 dataOut.utctime = avgdatatime
903 dataOut.utctime = avgdatatime
904 dataOut.flagNoData = False
904 dataOut.flagNoData = False
905
@@ -42,7 +42,7 setup(name="schainpy",
42 scripts=['schainpy/gui/schainGUI'],
42 scripts=['schainpy/gui/schainGUI'],
43 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"], include_dirs=[numpy.get_include()])],
43 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"], include_dirs=[numpy.get_include()])],
44 install_requires=[
44 install_requires=[
45 "scipy >= 0.14.0",
45 "scipy >= 0.13.0",
46 "h5py >= 2.2.1",
46 "h5py >= 2.2.1",
47 "matplotlib >= 1.4.2",
47 "matplotlib >= 1.4.2",
48 "pyfits >= 3.4",
48 "pyfits >= 3.4",
@@ -1,1 +0,0
1 You should install "digital_rf_hdf5" module if you want to read USRP data
General Comments 0
You need to be logged in to leave comments. Login now