##// END OF EJS Templates
Merge with Claire_proc
Juan C. Espinoza -
r1188:b1c63639a885 merge
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,116 +1,114
1 # Byte-compiled / optimized / DLL files
1 # Byte-compiled / optimized / DLL files
2 __pycache__/
2 __pycache__/
3 *.py[cod]
3 *.py[cod]
4 *$py.class
4 *$py.class
5
5
6 # C extensions
6 # C extensions
7 *.so
7 *.so
8
8
9 # Distribution / packaging
9 # Distribution / packaging
10 .Python
10 .Python
11 env/
11 env/
12 build/
12 build/
13 develop-eggs/
13 develop-eggs/
14 dist/
14 dist/
15 downloads/
15 downloads/
16 eggs/
16 eggs/
17 .eggs/
17 .eggs/
18 lib/
18 lib/
19 lib64/
19 lib64/
20 parts/
20 parts/
21 sdist/
21 sdist/
22 var/
22 var/
23 wheels/
23 wheels/
24 *.egg-info/
24 *.egg-info/
25 .installed.cfg
25 .installed.cfg
26 *.egg
26 *.egg
27
27
28 # PyInstaller
28 # PyInstaller
29 # Usually these files are written by a python script from a template
29 # Usually these files are written by a python script from a template
30 # before PyInstaller builds the exe, so as to inject date/other infos into it.
30 # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 *.manifest
31 *.manifest
32 *.spec
32 *.spec
33
33
34 # Installer logs
34 # Installer logs
35 pip-log.txt
35 pip-log.txt
36 pip-delete-this-directory.txt
36 pip-delete-this-directory.txt
37
37
38 # Unit test / coverage reports
38 # Unit test / coverage reports
39 htmlcov/
39 htmlcov/
40 .tox/
40 .tox/
41 .coverage
41 .coverage
42 .coverage.*
42 .coverage.*
43 .cache
43 .cache
44 nosetests.xml
44 nosetests.xml
45 coverage.xml
45 coverage.xml
46 *,cover
46 *,cover
47 .hypothesis/
47 .hypothesis/
48
48
49 # Translations
49 # Translations
50 *.mo
50 *.mo
51 *.pot
51 *.pot
52
52
53 # Django stuff:
53 # Django stuff:
54 *.log
54 *.log
55 local_settings.py
55 local_settings.py
56
56
57 # Flask stuff:
57 # Flask stuff:
58 instance/
58 instance/
59 .webassets-cache
59 .webassets-cache
60
60
61 # Scrapy stuff:
61 # Scrapy stuff:
62 .scrapy
62 .scrapy
63
63
64 # Sphinx documentation
64 # Sphinx documentation
65 docs/_build/
65 docs/_build/
66
66
67 # PyBuilder
67 # PyBuilder
68 target/
68 target/
69
69
70 # Jupyter Notebook
70 # Jupyter Notebook
71 .ipynb_checkpoints
71 .ipynb_checkpoints
72
72
73 # pyenv
73 # pyenv
74 .python-version
74 .python-version
75
75
76 # celery beat schedule file
76 # celery beat schedule file
77 celerybeat-schedule
77 celerybeat-schedule
78
78
79 # SageMath parsed files
79 # SageMath parsed files
80 *.sage.py
80 *.sage.py
81
81
82 # dotenv
82 # dotenv
83 .env
83 .env
84
84
85 # virtualenv
85 # virtualenv
86 .venv
86 .venv
87 venv/
87 venv/
88 ENV/
88 ENV/
89
89
90 # Spyder project settings
90 # Spyder project settings
91 .spyderproject
91 .spyderproject
92 .spyproject
92 .spyproject
93
93
94 # Rope project settings
94 # Rope project settings
95 .ropeproject
95 .ropeproject
96
96
97 # mkdocs documentation
97 # mkdocs documentation
98 /site
98 /site
99
99
100 # eclipse
100 # eclipse
101 .project
101 .project
102 .pydevproject
102 .pydevproject
103 # vscode
103 # vscode
104
104
105 .vscode
105 .vscode
106
106
107 schaingui/node_modules/
107 schaingui/node_modules/
108 schainpy/scripts/
108 schainpy/scripts/
109 .svn/
109 .svn/
110 *.png
110 *.png
111 *.pyc
111 *.pyc
112 .vscode
112 .vscode
113 trash
113 trash
114 *.log
114 *.log
115 schainpy/scripts/testDigitalRF.py
116 schainpy/scripts/testDigitalRFWriter.py
@@ -1,1342 +1,1345
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10 import json
10 import json
11
11
12 from schainpy.utils import log
12 from schainpy.utils import log
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
14
14
15
15
16 def getNumpyDtype(dataTypeCode):
16 def getNumpyDtype(dataTypeCode):
17
17
18 if dataTypeCode == 0:
18 if dataTypeCode == 0:
19 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
19 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
20 elif dataTypeCode == 1:
20 elif dataTypeCode == 1:
21 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
21 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
22 elif dataTypeCode == 2:
22 elif dataTypeCode == 2:
23 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
23 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
24 elif dataTypeCode == 3:
24 elif dataTypeCode == 3:
25 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
25 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
26 elif dataTypeCode == 4:
26 elif dataTypeCode == 4:
27 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
27 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
28 elif dataTypeCode == 5:
28 elif dataTypeCode == 5:
29 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
29 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
30 else:
30 else:
31 raise ValueError('dataTypeCode was not defined')
31 raise ValueError('dataTypeCode was not defined')
32
32
33 return numpyDtype
33 return numpyDtype
34
34
35
35
36 def getDataTypeCode(numpyDtype):
36 def getDataTypeCode(numpyDtype):
37
37
38 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
38 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
39 datatype = 0
39 datatype = 0
40 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
40 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
41 datatype = 1
41 datatype = 1
42 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
42 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
43 datatype = 2
43 datatype = 2
44 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
44 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
45 datatype = 3
45 datatype = 3
46 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
46 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
47 datatype = 4
47 datatype = 4
48 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
48 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
49 datatype = 5
49 datatype = 5
50 else:
50 else:
51 datatype = None
51 datatype = None
52
52
53 return datatype
53 return datatype
54
54
55
55
56 def hildebrand_sekhon(data, navg):
56 def hildebrand_sekhon(data, navg):
57 """
57 """
58 This method is for the objective determination of the noise level in Doppler spectra. This
58 This method is for the objective determination of the noise level in Doppler spectra. This
59 implementation technique is based on the fact that the standard deviation of the spectral
59 implementation technique is based on the fact that the standard deviation of the spectral
60 densities is equal to the mean spectral density for white Gaussian noise
60 densities is equal to the mean spectral density for white Gaussian noise
61
61
62 Inputs:
62 Inputs:
63 Data : heights
63 Data : heights
64 navg : numbers of averages
64 navg : numbers of averages
65
65
66 Return:
66 Return:
67 mean : noise's level
67 mean : noise's level
68 """
68 """
69
69
70 sortdata = numpy.sort(data, axis=None)
70 sortdata = numpy.sort(data, axis=None)
71 lenOfData = len(sortdata)
71 lenOfData = len(sortdata)
72 nums_min = lenOfData*0.2
72 nums_min = lenOfData*0.2
73
73
74 if nums_min <= 5:
74 if nums_min <= 5:
75
75
76 nums_min = 5
76 nums_min = 5
77
77
78 sump = 0.
78 sump = 0.
79 sumq = 0.
79 sumq = 0.
80
80
81 j = 0
81 j = 0
82 cont = 1
82 cont = 1
83
83
84 while((cont == 1)and(j < lenOfData)):
84 while((cont == 1)and(j < lenOfData)):
85
85
86 sump += sortdata[j]
86 sump += sortdata[j]
87 sumq += sortdata[j]**2
87 sumq += sortdata[j]**2
88
88
89 if j > nums_min:
89 if j > nums_min:
90 rtest = float(j)/(j-1) + 1.0/navg
90 rtest = float(j)/(j-1) + 1.0/navg
91 if ((sumq*j) > (rtest*sump**2)):
91 if ((sumq*j) > (rtest*sump**2)):
92 j = j - 1
92 j = j - 1
93 sump = sump - sortdata[j]
93 sump = sump - sortdata[j]
94 sumq = sumq - sortdata[j]**2
94 sumq = sumq - sortdata[j]**2
95 cont = 0
95 cont = 0
96
96
97 j += 1
97 j += 1
98
98
99 lnoise = sump / j
99 lnoise = sump / j
100
100
101 return lnoise
101 return lnoise
102
102
103
103
104 class Beam:
104 class Beam:
105
105
106 def __init__(self):
106 def __init__(self):
107 self.codeList = []
107 self.codeList = []
108 self.azimuthList = []
108 self.azimuthList = []
109 self.zenithList = []
109 self.zenithList = []
110
110
111
111
112 class GenericData(object):
112 class GenericData(object):
113
113
114 flagNoData = True
114 flagNoData = True
115
115
116 def copy(self, inputObj=None):
116 def copy(self, inputObj=None):
117
117
118 if inputObj == None:
118 if inputObj == None:
119 return copy.deepcopy(self)
119 return copy.deepcopy(self)
120
120
121 for key in list(inputObj.__dict__.keys()):
121 for key in list(inputObj.__dict__.keys()):
122
122
123 attribute = inputObj.__dict__[key]
123 attribute = inputObj.__dict__[key]
124
124
125 # If this attribute is a tuple or list
125 # If this attribute is a tuple or list
126 if type(inputObj.__dict__[key]) in (tuple, list):
126 if type(inputObj.__dict__[key]) in (tuple, list):
127 self.__dict__[key] = attribute[:]
127 self.__dict__[key] = attribute[:]
128 continue
128 continue
129
129
130 # If this attribute is another object or instance
130 # If this attribute is another object or instance
131 if hasattr(attribute, '__dict__'):
131 if hasattr(attribute, '__dict__'):
132 self.__dict__[key] = attribute.copy()
132 self.__dict__[key] = attribute.copy()
133 continue
133 continue
134
134
135 self.__dict__[key] = inputObj.__dict__[key]
135 self.__dict__[key] = inputObj.__dict__[key]
136
136
137 def deepcopy(self):
137 def deepcopy(self):
138
138
139 return copy.deepcopy(self)
139 return copy.deepcopy(self)
140
140
141 def isEmpty(self):
141 def isEmpty(self):
142
142
143 return self.flagNoData
143 return self.flagNoData
144
144
145
145
146 class JROData(GenericData):
146 class JROData(GenericData):
147
147
148 # m_BasicHeader = BasicHeader()
148 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
149 # m_ProcessingHeader = ProcessingHeader()
150
150
151 systemHeaderObj = SystemHeader()
151 systemHeaderObj = SystemHeader()
152 radarControllerHeaderObj = RadarControllerHeader()
152 radarControllerHeaderObj = RadarControllerHeader()
153 # data = None
153 # data = None
154 type = None
154 type = None
155 datatype = None # dtype but in string
155 datatype = None # dtype but in string
156 # dtype = None
156 # dtype = None
157 # nChannels = None
157 # nChannels = None
158 # nHeights = None
158 # nHeights = None
159 nProfiles = None
159 nProfiles = None
160 heightList = None
160 heightList = None
161 channelList = None
161 channelList = None
162 flagDiscontinuousBlock = False
162 flagDiscontinuousBlock = False
163 useLocalTime = False
163 useLocalTime = False
164 utctime = None
164 utctime = None
165 timeZone = None
165 timeZone = None
166 dstFlag = None
166 dstFlag = None
167 errorCount = None
167 errorCount = None
168 blocksize = None
168 blocksize = None
169 # nCode = None
169 # nCode = None
170 # nBaud = None
170 # nBaud = None
171 # code = None
171 # code = None
172 flagDecodeData = False # asumo q la data no esta decodificada
172 flagDecodeData = False # asumo q la data no esta decodificada
173 flagDeflipData = False # asumo q la data no esta sin flip
173 flagDeflipData = False # asumo q la data no esta sin flip
174 flagShiftFFT = False
174 flagShiftFFT = False
175 # ippSeconds = None
175 # ippSeconds = None
176 # timeInterval = None
176 # timeInterval = None
177 nCohInt = None
177 nCohInt = None
178 # noise = None
178 # noise = None
179 windowOfFilter = 1
179 windowOfFilter = 1
180 # Speed of ligth
180 # Speed of ligth
181 C = 3e8
181 C = 3e8
182 frequency = 49.92e6
182 frequency = 49.92e6
183 realtime = False
183 realtime = False
184 beacon_heiIndexList = None
184 beacon_heiIndexList = None
185 last_block = None
185 last_block = None
186 blocknow = None
186 blocknow = None
187 azimuth = None
187 azimuth = None
188 zenith = None
188 zenith = None
189 beam = Beam()
189 beam = Beam()
190 profileIndex = None
190 profileIndex = None
191 error = None
191 error = None
192 data = None
192 data = None
193 data_plt = None
193 nmodes = None
194
195
194
196 def __str__(self):
195 def __str__(self):
197
196
198 return '{} - {}'.format(self.type, self.getDatatime())
197 return '{} - {}'.format(self.type, self.getDatatime())
199
198
200 def getNoise(self):
199 def getNoise(self):
201
200
202 raise NotImplementedError
201 raise NotImplementedError
203
202
204 def getNChannels(self):
203 def getNChannels(self):
205
204
206 return len(self.channelList)
205 return len(self.channelList)
207
206
208 def getChannelIndexList(self):
207 def getChannelIndexList(self):
209
208
210 return list(range(self.nChannels))
209 return list(range(self.nChannels))
211
210
212 def getNHeights(self):
211 def getNHeights(self):
213
212
214 return len(self.heightList)
213 return len(self.heightList)
215
214
216 def getHeiRange(self, extrapoints=0):
215 def getHeiRange(self, extrapoints=0):
217
216
218 heis = self.heightList
217 heis = self.heightList
219 # deltah = self.heightList[1] - self.heightList[0]
218 # deltah = self.heightList[1] - self.heightList[0]
220 #
219 #
221 # heis.append(self.heightList[-1])
220 # heis.append(self.heightList[-1])
222
221
223 return heis
222 return heis
224
223
225 def getDeltaH(self):
224 def getDeltaH(self):
226
225
227 delta = self.heightList[1] - self.heightList[0]
226 delta = self.heightList[1] - self.heightList[0]
228
227
229 return delta
228 return delta
230
229
231 def getltctime(self):
230 def getltctime(self):
232
231
233 if self.useLocalTime:
232 if self.useLocalTime:
234 return self.utctime - self.timeZone * 60
233 return self.utctime - self.timeZone * 60
235
234
236 return self.utctime
235 return self.utctime
237
236
238 def getDatatime(self):
237 def getDatatime(self):
239
238
240 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
239 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
241 return datatimeValue
240 return datatimeValue
242
241
243 def getTimeRange(self):
242 def getTimeRange(self):
244
243
245 datatime = []
244 datatime = []
246
245
247 datatime.append(self.ltctime)
246 datatime.append(self.ltctime)
248 datatime.append(self.ltctime + self.timeInterval + 1)
247 datatime.append(self.ltctime + self.timeInterval + 1)
249
248
250 datatime = numpy.array(datatime)
249 datatime = numpy.array(datatime)
251
250
252 return datatime
251 return datatime
253
252
254 def getFmaxTimeResponse(self):
253 def getFmaxTimeResponse(self):
255
254
256 period = (10**-6) * self.getDeltaH() / (0.15)
255 period = (10**-6) * self.getDeltaH() / (0.15)
257
256
258 PRF = 1. / (period * self.nCohInt)
257 PRF = 1. / (period * self.nCohInt)
259
258
260 fmax = PRF
259 fmax = PRF
261
260
262 return fmax
261 return fmax
263
262
264 def getFmax(self):
263 def getFmax(self):
265 PRF = 1. / (self.ippSeconds * self.nCohInt)
264 PRF = 1. / (self.ippSeconds * self.nCohInt)
266
265
267 fmax = PRF
266 fmax = PRF
268 return fmax
267 return fmax
269
268
270 def getVmax(self):
269 def getVmax(self):
271
270
272 _lambda = self.C / self.frequency
271 _lambda = self.C / self.frequency
273
272
274 vmax = self.getFmax() * _lambda / 2
273 vmax = self.getFmax() * _lambda / 2
275
274
276 return vmax
275 return vmax
277
276
278 def get_ippSeconds(self):
277 def get_ippSeconds(self):
279 '''
278 '''
280 '''
279 '''
281 return self.radarControllerHeaderObj.ippSeconds
280 return self.radarControllerHeaderObj.ippSeconds
282
281
283 def set_ippSeconds(self, ippSeconds):
282 def set_ippSeconds(self, ippSeconds):
284 '''
283 '''
285 '''
284 '''
286
285
287 self.radarControllerHeaderObj.ippSeconds = ippSeconds
286 self.radarControllerHeaderObj.ippSeconds = ippSeconds
288
287
289 return
288 return
290
289
291 def get_dtype(self):
290 def get_dtype(self):
292 '''
291 '''
293 '''
292 '''
294 return getNumpyDtype(self.datatype)
293 return getNumpyDtype(self.datatype)
295
294
296 def set_dtype(self, numpyDtype):
295 def set_dtype(self, numpyDtype):
297 '''
296 '''
298 '''
297 '''
299
298
300 self.datatype = getDataTypeCode(numpyDtype)
299 self.datatype = getDataTypeCode(numpyDtype)
301
300
302 def get_code(self):
301 def get_code(self):
303 '''
302 '''
304 '''
303 '''
305 return self.radarControllerHeaderObj.code
304 return self.radarControllerHeaderObj.code
306
305
307 def set_code(self, code):
306 def set_code(self, code):
308 '''
307 '''
309 '''
308 '''
310 self.radarControllerHeaderObj.code = code
309 self.radarControllerHeaderObj.code = code
311
310
312 return
311 return
313
312
314 def get_ncode(self):
313 def get_ncode(self):
315 '''
314 '''
316 '''
315 '''
317 return self.radarControllerHeaderObj.nCode
316 return self.radarControllerHeaderObj.nCode
318
317
319 def set_ncode(self, nCode):
318 def set_ncode(self, nCode):
320 '''
319 '''
321 '''
320 '''
322 self.radarControllerHeaderObj.nCode = nCode
321 self.radarControllerHeaderObj.nCode = nCode
323
322
324 return
323 return
325
324
326 def get_nbaud(self):
325 def get_nbaud(self):
327 '''
326 '''
328 '''
327 '''
329 return self.radarControllerHeaderObj.nBaud
328 return self.radarControllerHeaderObj.nBaud
330
329
331 def set_nbaud(self, nBaud):
330 def set_nbaud(self, nBaud):
332 '''
331 '''
333 '''
332 '''
334 self.radarControllerHeaderObj.nBaud = nBaud
333 self.radarControllerHeaderObj.nBaud = nBaud
335
334
336 return
335 return
337
336
338 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
337 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
339 channelIndexList = property(
338 channelIndexList = property(
340 getChannelIndexList, "I'm the 'channelIndexList' property.")
339 getChannelIndexList, "I'm the 'channelIndexList' property.")
341 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
340 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
342 #noise = property(getNoise, "I'm the 'nHeights' property.")
341 #noise = property(getNoise, "I'm the 'nHeights' property.")
343 datatime = property(getDatatime, "I'm the 'datatime' property")
342 datatime = property(getDatatime, "I'm the 'datatime' property")
344 ltctime = property(getltctime, "I'm the 'ltctime' property")
343 ltctime = property(getltctime, "I'm the 'ltctime' property")
345 ippSeconds = property(get_ippSeconds, set_ippSeconds)
344 ippSeconds = property(get_ippSeconds, set_ippSeconds)
346 dtype = property(get_dtype, set_dtype)
345 dtype = property(get_dtype, set_dtype)
347 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
346 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
348 code = property(get_code, set_code)
347 code = property(get_code, set_code)
349 nCode = property(get_ncode, set_ncode)
348 nCode = property(get_ncode, set_ncode)
350 nBaud = property(get_nbaud, set_nbaud)
349 nBaud = property(get_nbaud, set_nbaud)
351
350
352
351
353 class Voltage(JROData):
352 class Voltage(JROData):
354
353
355 # data es un numpy array de 2 dmensiones (canales, alturas)
354 # data es un numpy array de 2 dmensiones (canales, alturas)
356 data = None
355 data = None
357
356
358 def __init__(self):
357 def __init__(self):
359 '''
358 '''
360 Constructor
359 Constructor
361 '''
360 '''
362
361
363 self.useLocalTime = True
362 self.useLocalTime = True
364 self.radarControllerHeaderObj = RadarControllerHeader()
363 self.radarControllerHeaderObj = RadarControllerHeader()
365 self.systemHeaderObj = SystemHeader()
364 self.systemHeaderObj = SystemHeader()
366 self.type = "Voltage"
365 self.type = "Voltage"
367 self.data = None
366 self.data = None
368 # self.dtype = None
367 # self.dtype = None
369 # self.nChannels = 0
368 # self.nChannels = 0
370 # self.nHeights = 0
369 # self.nHeights = 0
371 self.nProfiles = None
370 self.nProfiles = None
372 self.heightList = Non
371 self.heightList = Non
373 self.channelList = None
372 self.channelList = None
374 # self.channelIndexList = None
373 # self.channelIndexList = None
375 self.flagNoData = True
374 self.flagNoData = True
376 self.flagDiscontinuousBlock = False
375 self.flagDiscontinuousBlock = False
377 self.utctime = None
376 self.utctime = None
378 self.timeZone = None
377 self.timeZone = None
379 self.dstFlag = None
378 self.dstFlag = None
380 self.errorCount = None
379 self.errorCount = None
381 self.nCohInt = None
380 self.nCohInt = None
382 self.blocksize = None
381 self.blocksize = None
383 self.flagDecodeData = False # asumo q la data no esta decodificada
382 self.flagDecodeData = False # asumo q la data no esta decodificada
384 self.flagDeflipData = False # asumo q la data no esta sin flip
383 self.flagDeflipData = False # asumo q la data no esta sin flip
385 self.flagShiftFFT = False
384 self.flagShiftFFT = False
386 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
385 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
387 self.profileIndex = 0
386 self.profileIndex = 0
388
387
389 def getNoisebyHildebrand(self, channel=None):
388 def getNoisebyHildebrand(self, channel=None):
390 """
389 """
391 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
390 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
392
391
393 Return:
392 Return:
394 noiselevel
393 noiselevel
395 """
394 """
396
395
397 if channel != None:
396 if channel != None:
398 data = self.data[channel]
397 data = self.data[channel]
399 nChannels = 1
398 nChannels = 1
400 else:
399 else:
401 data = self.data
400 data = self.data
402 nChannels = self.nChannels
401 nChannels = self.nChannels
403
402
404 noise = numpy.zeros(nChannels)
403 noise = numpy.zeros(nChannels)
405 power = data * numpy.conjugate(data)
404 power = data * numpy.conjugate(data)
406
405
407 for thisChannel in range(nChannels):
406 for thisChannel in range(nChannels):
408 if nChannels == 1:
407 if nChannels == 1:
409 daux = power[:].real
408 daux = power[:].real
410 else:
409 else:
411 daux = power[thisChannel, :].real
410 daux = power[thisChannel, :].real
412 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
411 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
413
412
414 return noise
413 return noise
415
414
416 def getNoise(self, type=1, channel=None):
415 def getNoise(self, type=1, channel=None):
417
416
418 if type == 1:
417 if type == 1:
419 noise = self.getNoisebyHildebrand(channel)
418 noise = self.getNoisebyHildebrand(channel)
420
419
421 return noise
420 return noise
422
421
423 def getPower(self, channel=None):
422 def getPower(self, channel=None):
424
423
425 if channel != None:
424 if channel != None:
426 data = self.data[channel]
425 data = self.data[channel]
427 else:
426 else:
428 data = self.data
427 data = self.data
429
428
430 power = data * numpy.conjugate(data)
429 power = data * numpy.conjugate(data)
431 powerdB = 10 * numpy.log10(power.real)
430 powerdB = 10 * numpy.log10(power.real)
432 powerdB = numpy.squeeze(powerdB)
431 powerdB = numpy.squeeze(powerdB)
433
432
434 return powerdB
433 return powerdB
435
434
436 def getTimeInterval(self):
435 def getTimeInterval(self):
437
436
438 timeInterval = self.ippSeconds * self.nCohInt
437 timeInterval = self.ippSeconds * self.nCohInt
439
438
440 return timeInterval
439 return timeInterval
441
440
442 noise = property(getNoise, "I'm the 'nHeights' property.")
441 noise = property(getNoise, "I'm the 'nHeights' property.")
443 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
442 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
444
443
445
444
446 class Spectra(JROData):
445 class Spectra(JROData):
447
446
448 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
447 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
449 data_spc = None
448 data_spc = None
450 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
449 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
451 data_cspc = None
450 data_cspc = None
452 # data dc es un numpy array de 2 dmensiones (canales, alturas)
451 # data dc es un numpy array de 2 dmensiones (canales, alturas)
453 data_dc = None
452 data_dc = None
454 # data power
453 # data power
455 data_pwr = None
454 data_pwr = None
456 nFFTPoints = None
455 nFFTPoints = None
457 # nPairs = None
456 # nPairs = None
458 pairsList = None
457 pairsList = None
459 nIncohInt = None
458 nIncohInt = None
460 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
459 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
461 nCohInt = None # se requiere para determinar el valor de timeInterval
460 nCohInt = None # se requiere para determinar el valor de timeInterval
462 ippFactor = None
461 ippFactor = None
463 profileIndex = 0
462 profileIndex = 0
464 plotting = "spectra"
463 plotting = "spectra"
464
465 def __init__(self):
465 def __init__(self):
466 '''
466 '''
467 Constructor
467 Constructor
468 '''
468 '''
469
469
470 self.useLocalTime = True
470 self.useLocalTime = True
471 self.radarControllerHeaderObj = RadarControllerHeader()
471 self.radarControllerHeaderObj = RadarControllerHeader()
472 self.systemHeaderObj = SystemHeader()
472 self.systemHeaderObj = SystemHeader()
473 self.type = "Spectra"
473 self.type = "Spectra"
474 # self.data = None
474 # self.data = None
475 # self.dtype = None
475 # self.dtype = None
476 # self.nChannels = 0
476 # self.nChannels = 0
477 # self.nHeights = 0
477 # self.nHeights = 0
478 self.nProfiles = None
478 self.nProfiles = None
479 self.heightList = None
479 self.heightList = None
480 self.channelList = None
480 self.channelList = None
481 # self.channelIndexList = None
481 # self.channelIndexList = None
482 self.pairsList = None
482 self.pairsList = None
483 self.flagNoData = True
483 self.flagNoData = True
484 self.flagDiscontinuousBlock = False
484 self.flagDiscontinuousBlock = False
485 self.utctime = None
485 self.utctime = None
486 self.nCohInt = None
486 self.nCohInt = None
487 self.nIncohInt = None
487 self.nIncohInt = None
488 self.blocksize = None
488 self.blocksize = None
489 self.nFFTPoints = None
489 self.nFFTPoints = None
490 self.wavelength = None
490 self.wavelength = None
491 self.flagDecodeData = False # asumo q la data no esta decodificada
491 self.flagDecodeData = False # asumo q la data no esta decodificada
492 self.flagDeflipData = False # asumo q la data no esta sin flip
492 self.flagDeflipData = False # asumo q la data no esta sin flip
493 self.flagShiftFFT = False
493 self.flagShiftFFT = False
494 self.ippFactor = 1
494 self.ippFactor = 1
495 #self.noise = None
495 #self.noise = None
496 self.beacon_heiIndexList = []
496 self.beacon_heiIndexList = []
497 self.noise_estimation = None
497 self.noise_estimation = None
498
498
499 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
499 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
500 """
500 """
501 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
501 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
502
502
503 Return:
503 Return:
504 noiselevel
504 noiselevel
505 """
505 """
506
506
507 noise = numpy.zeros(self.nChannels)
507 noise = numpy.zeros(self.nChannels)
508
508
509 for channel in range(self.nChannels):
509 for channel in range(self.nChannels):
510 daux = self.data_spc[channel,
510 daux = self.data_spc[channel,
511 xmin_index:xmax_index, ymin_index:ymax_index]
511 xmin_index:xmax_index, ymin_index:ymax_index]
512 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
512 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
513
513
514 return noise
514 return noise
515
515
516 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
516 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
517
517
518 if self.noise_estimation is not None:
518 if self.noise_estimation is not None:
519 # this was estimated by getNoise Operation defined in jroproc_spectra.py
519 # this was estimated by getNoise Operation defined in jroproc_spectra.py
520 return self.noise_estimation
520 return self.noise_estimation
521 else:
521 else:
522 noise = self.getNoisebyHildebrand(
522 noise = self.getNoisebyHildebrand(
523 xmin_index, xmax_index, ymin_index, ymax_index)
523 xmin_index, xmax_index, ymin_index, ymax_index)
524 return noise
524 return noise
525
525
526 def getFreqRangeTimeResponse(self, extrapoints=0):
526 def getFreqRangeTimeResponse(self, extrapoints=0):
527
527
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
529 freqrange = deltafreq * \
529 freqrange = deltafreq * \
530 (numpy.arange(self.nFFTPoints + extrapoints) -
530 (numpy.arange(self.nFFTPoints + extrapoints) -
531 self.nFFTPoints / 2.) - deltafreq / 2
531 self.nFFTPoints / 2.) - deltafreq / 2
532
532
533 return freqrange
533 return freqrange
534
534
535 def getAcfRange(self, extrapoints=0):
535 def getAcfRange(self, extrapoints=0):
536
536
537 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
537 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
538 freqrange = deltafreq * \
538 freqrange = deltafreq * \
539 (numpy.arange(self.nFFTPoints + extrapoints) -
539 (numpy.arange(self.nFFTPoints + extrapoints) -
540 self.nFFTPoints / 2.) - deltafreq / 2
540 self.nFFTPoints / 2.) - deltafreq / 2
541
541
542 return freqrange
542 return freqrange
543
543
544 def getFreqRange(self, extrapoints=0):
544 def getFreqRange(self, extrapoints=0):
545
545
546 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
546 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
547 freqrange = deltafreq * \
547 freqrange = deltafreq * \
548 (numpy.arange(self.nFFTPoints + extrapoints) -
548 (numpy.arange(self.nFFTPoints + extrapoints) -
549 self.nFFTPoints / 2.) - deltafreq / 2
549 self.nFFTPoints / 2.) - deltafreq / 2
550
550
551 return freqrange
551 return freqrange
552
552
553 def getVelRange(self, extrapoints=0):
553 def getVelRange(self, extrapoints=0):
554
554
555 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
555 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
556 velrange = deltav * (numpy.arange(self.nFFTPoints +
556 velrange = deltav * (numpy.arange(self.nFFTPoints +
557 extrapoints) - self.nFFTPoints / 2.) # - deltav/2
557 extrapoints) - self.nFFTPoints / 2.)
558
558
559 return velrange
559 if self.nmodes:
560 return velrange/self.nmodes
561 else:
562 return velrange
560
563
561 def getNPairs(self):
564 def getNPairs(self):
562
565
563 return len(self.pairsList)
566 return len(self.pairsList)
564
567
565 def getPairsIndexList(self):
568 def getPairsIndexList(self):
566
569
567 return list(range(self.nPairs))
570 return list(range(self.nPairs))
568
571
569 def getNormFactor(self):
572 def getNormFactor(self):
570
573
571 pwcode = 1
574 pwcode = 1
572
575
573 if self.flagDecodeData:
576 if self.flagDecodeData:
574 pwcode = numpy.sum(self.code[0]**2)
577 pwcode = numpy.sum(self.code[0]**2)
575 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
578 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
576 normFactor = self.nProfiles * self.nIncohInt * \
579 normFactor = self.nProfiles * self.nIncohInt * \
577 self.nCohInt * pwcode * self.windowOfFilter
580 self.nCohInt * pwcode * self.windowOfFilter
578
581
579 return normFactor
582 return normFactor
580
583
581 def getFlagCspc(self):
584 def getFlagCspc(self):
582
585
583 if self.data_cspc is None:
586 if self.data_cspc is None:
584 return True
587 return True
585
588
586 return False
589 return False
587
590
588 def getFlagDc(self):
591 def getFlagDc(self):
589
592
590 if self.data_dc is None:
593 if self.data_dc is None:
591 return True
594 return True
592
595
593 return False
596 return False
594
597
595 def getTimeInterval(self):
598 def getTimeInterval(self):
596
599
597 timeInterval = self.ippSeconds * self.nCohInt * \
600 timeInterval = self.ippSeconds * self.nCohInt * \
598 self.nIncohInt * self.nProfiles * self.ippFactor
601 self.nIncohInt * self.nProfiles * self.ippFactor
599
602
600 return timeInterval
603 return timeInterval
601
604
602 def getPower(self):
605 def getPower(self):
603
606
604 factor = self.normFactor
607 factor = self.normFactor
605 z = self.data_spc / factor
608 z = self.data_spc / factor
606 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
609 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
607 avg = numpy.average(z, axis=1)
610 avg = numpy.average(z, axis=1)
608
611
609 return 10 * numpy.log10(avg)
612 return 10 * numpy.log10(avg)
610
613
611 def getCoherence(self, pairsList=None, phase=False):
614 def getCoherence(self, pairsList=None, phase=False):
612
615
613 z = []
616 z = []
614 if pairsList is None:
617 if pairsList is None:
615 pairsIndexList = self.pairsIndexList
618 pairsIndexList = self.pairsIndexList
616 else:
619 else:
617 pairsIndexList = []
620 pairsIndexList = []
618 for pair in pairsList:
621 for pair in pairsList:
619 if pair not in self.pairsList:
622 if pair not in self.pairsList:
620 raise ValueError("Pair %s is not in dataOut.pairsList" % (
623 raise ValueError("Pair %s is not in dataOut.pairsList" % (
621 pair))
624 pair))
622 pairsIndexList.append(self.pairsList.index(pair))
625 pairsIndexList.append(self.pairsList.index(pair))
623 for i in range(len(pairsIndexList)):
626 for i in range(len(pairsIndexList)):
624 pair = self.pairsList[pairsIndexList[i]]
627 pair = self.pairsList[pairsIndexList[i]]
625 ccf = numpy.average(
628 ccf = numpy.average(
626 self.data_cspc[pairsIndexList[i], :, :], axis=0)
629 self.data_cspc[pairsIndexList[i], :, :], axis=0)
627 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
630 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
628 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
631 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
629 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
632 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
630 if phase:
633 if phase:
631 data = numpy.arctan2(avgcoherenceComplex.imag,
634 data = numpy.arctan2(avgcoherenceComplex.imag,
632 avgcoherenceComplex.real) * 180 / numpy.pi
635 avgcoherenceComplex.real) * 180 / numpy.pi
633 else:
636 else:
634 data = numpy.abs(avgcoherenceComplex)
637 data = numpy.abs(avgcoherenceComplex)
635
638
636 z.append(data)
639 z.append(data)
637
640
638 return numpy.array(z)
641 return numpy.array(z)
639
642
640 def setValue(self, value):
643 def setValue(self, value):
641
644
642 print("This property should not be initialized")
645 print("This property should not be initialized")
643
646
644 return
647 return
645
648
646 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
649 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
647 pairsIndexList = property(
650 pairsIndexList = property(
648 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
651 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
649 normFactor = property(getNormFactor, setValue,
652 normFactor = property(getNormFactor, setValue,
650 "I'm the 'getNormFactor' property.")
653 "I'm the 'getNormFactor' property.")
651 flag_cspc = property(getFlagCspc, setValue)
654 flag_cspc = property(getFlagCspc, setValue)
652 flag_dc = property(getFlagDc, setValue)
655 flag_dc = property(getFlagDc, setValue)
653 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
656 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
654 timeInterval = property(getTimeInterval, setValue,
657 timeInterval = property(getTimeInterval, setValue,
655 "I'm the 'timeInterval' property")
658 "I'm the 'timeInterval' property")
656
659
657
660
658 class SpectraHeis(Spectra):
661 class SpectraHeis(Spectra):
659
662
660 data_spc = None
663 data_spc = None
661 data_cspc = None
664 data_cspc = None
662 data_dc = None
665 data_dc = None
663 nFFTPoints = None
666 nFFTPoints = None
664 # nPairs = None
667 # nPairs = None
665 pairsList = None
668 pairsList = None
666 nCohInt = None
669 nCohInt = None
667 nIncohInt = None
670 nIncohInt = None
668
671
669 def __init__(self):
672 def __init__(self):
670
673
671 self.radarControllerHeaderObj = RadarControllerHeader()
674 self.radarControllerHeaderObj = RadarControllerHeader()
672
675
673 self.systemHeaderObj = SystemHeader()
676 self.systemHeaderObj = SystemHeader()
674
677
675 self.type = "SpectraHeis"
678 self.type = "SpectraHeis"
676
679
677 # self.dtype = None
680 # self.dtype = None
678
681
679 # self.nChannels = 0
682 # self.nChannels = 0
680
683
681 # self.nHeights = 0
684 # self.nHeights = 0
682
685
683 self.nProfiles = None
686 self.nProfiles = None
684
687
685 self.heightList = None
688 self.heightList = None
686
689
687 self.channelList = None
690 self.channelList = None
688
691
689 # self.channelIndexList = None
692 # self.channelIndexList = None
690
693
691 self.flagNoData = True
694 self.flagNoData = True
692
695
693 self.flagDiscontinuousBlock = False
696 self.flagDiscontinuousBlock = False
694
697
695 # self.nPairs = 0
698 # self.nPairs = 0
696
699
697 self.utctime = None
700 self.utctime = None
698
701
699 self.blocksize = None
702 self.blocksize = None
700
703
701 self.profileIndex = 0
704 self.profileIndex = 0
702
705
703 self.nCohInt = 1
706 self.nCohInt = 1
704
707
705 self.nIncohInt = 1
708 self.nIncohInt = 1
706
709
707 def getNormFactor(self):
710 def getNormFactor(self):
708 pwcode = 1
711 pwcode = 1
709 if self.flagDecodeData:
712 if self.flagDecodeData:
710 pwcode = numpy.sum(self.code[0]**2)
713 pwcode = numpy.sum(self.code[0]**2)
711
714
712 normFactor = self.nIncohInt * self.nCohInt * pwcode
715 normFactor = self.nIncohInt * self.nCohInt * pwcode
713
716
714 return normFactor
717 return normFactor
715
718
716 def getTimeInterval(self):
719 def getTimeInterval(self):
717
720
718 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
721 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
719
722
720 return timeInterval
723 return timeInterval
721
724
722 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
725 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
723 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
726 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
724
727
725
728
726 class Fits(JROData):
729 class Fits(JROData):
727
730
728 heightList = None
731 heightList = None
729 channelList = None
732 channelList = None
730 flagNoData = True
733 flagNoData = True
731 flagDiscontinuousBlock = False
734 flagDiscontinuousBlock = False
732 useLocalTime = False
735 useLocalTime = False
733 utctime = None
736 utctime = None
734 timeZone = None
737 timeZone = None
735 # ippSeconds = None
738 # ippSeconds = None
736 # timeInterval = None
739 # timeInterval = None
737 nCohInt = None
740 nCohInt = None
738 nIncohInt = None
741 nIncohInt = None
739 noise = None
742 noise = None
740 windowOfFilter = 1
743 windowOfFilter = 1
741 # Speed of ligth
744 # Speed of ligth
742 C = 3e8
745 C = 3e8
743 frequency = 49.92e6
746 frequency = 49.92e6
744 realtime = False
747 realtime = False
745
748
746 def __init__(self):
749 def __init__(self):
747
750
748 self.type = "Fits"
751 self.type = "Fits"
749
752
750 self.nProfiles = None
753 self.nProfiles = None
751
754
752 self.heightList = None
755 self.heightList = None
753
756
754 self.channelList = None
757 self.channelList = None
755
758
756 # self.channelIndexList = None
759 # self.channelIndexList = None
757
760
758 self.flagNoData = True
761 self.flagNoData = True
759
762
760 self.utctime = None
763 self.utctime = None
761
764
762 self.nCohInt = 1
765 self.nCohInt = 1
763
766
764 self.nIncohInt = 1
767 self.nIncohInt = 1
765
768
766 self.useLocalTime = True
769 self.useLocalTime = True
767
770
768 self.profileIndex = 0
771 self.profileIndex = 0
769
772
770 # self.utctime = None
773 # self.utctime = None
771 # self.timeZone = None
774 # self.timeZone = None
772 # self.ltctime = None
775 # self.ltctime = None
773 # self.timeInterval = None
776 # self.timeInterval = None
774 # self.header = None
777 # self.header = None
775 # self.data_header = None
778 # self.data_header = None
776 # self.data = None
779 # self.data = None
777 # self.datatime = None
780 # self.datatime = None
778 # self.flagNoData = False
781 # self.flagNoData = False
779 # self.expName = ''
782 # self.expName = ''
780 # self.nChannels = None
783 # self.nChannels = None
781 # self.nSamples = None
784 # self.nSamples = None
782 # self.dataBlocksPerFile = None
785 # self.dataBlocksPerFile = None
783 # self.comments = ''
786 # self.comments = ''
784 #
787 #
785
788
786 def getltctime(self):
789 def getltctime(self):
787
790
788 if self.useLocalTime:
791 if self.useLocalTime:
789 return self.utctime - self.timeZone * 60
792 return self.utctime - self.timeZone * 60
790
793
791 return self.utctime
794 return self.utctime
792
795
793 def getDatatime(self):
796 def getDatatime(self):
794
797
795 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
798 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
796 return datatime
799 return datatime
797
800
798 def getTimeRange(self):
801 def getTimeRange(self):
799
802
800 datatime = []
803 datatime = []
801
804
802 datatime.append(self.ltctime)
805 datatime.append(self.ltctime)
803 datatime.append(self.ltctime + self.timeInterval)
806 datatime.append(self.ltctime + self.timeInterval)
804
807
805 datatime = numpy.array(datatime)
808 datatime = numpy.array(datatime)
806
809
807 return datatime
810 return datatime
808
811
809 def getHeiRange(self):
812 def getHeiRange(self):
810
813
811 heis = self.heightList
814 heis = self.heightList
812
815
813 return heis
816 return heis
814
817
815 def getNHeights(self):
818 def getNHeights(self):
816
819
817 return len(self.heightList)
820 return len(self.heightList)
818
821
819 def getNChannels(self):
822 def getNChannels(self):
820
823
821 return len(self.channelList)
824 return len(self.channelList)
822
825
823 def getChannelIndexList(self):
826 def getChannelIndexList(self):
824
827
825 return list(range(self.nChannels))
828 return list(range(self.nChannels))
826
829
827 def getNoise(self, type=1):
830 def getNoise(self, type=1):
828
831
829 #noise = numpy.zeros(self.nChannels)
832 #noise = numpy.zeros(self.nChannels)
830
833
831 if type == 1:
834 if type == 1:
832 noise = self.getNoisebyHildebrand()
835 noise = self.getNoisebyHildebrand()
833
836
834 if type == 2:
837 if type == 2:
835 noise = self.getNoisebySort()
838 noise = self.getNoisebySort()
836
839
837 if type == 3:
840 if type == 3:
838 noise = self.getNoisebyWindow()
841 noise = self.getNoisebyWindow()
839
842
840 return noise
843 return noise
841
844
842 def getTimeInterval(self):
845 def getTimeInterval(self):
843
846
844 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
847 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
845
848
846 return timeInterval
849 return timeInterval
847
850
848 datatime = property(getDatatime, "I'm the 'datatime' property")
851 datatime = property(getDatatime, "I'm the 'datatime' property")
849 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
852 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
850 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
853 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
851 channelIndexList = property(
854 channelIndexList = property(
852 getChannelIndexList, "I'm the 'channelIndexList' property.")
855 getChannelIndexList, "I'm the 'channelIndexList' property.")
853 noise = property(getNoise, "I'm the 'nHeights' property.")
856 noise = property(getNoise, "I'm the 'nHeights' property.")
854
857
855 ltctime = property(getltctime, "I'm the 'ltctime' property")
858 ltctime = property(getltctime, "I'm the 'ltctime' property")
856 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
859 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
857
860
858
861
859 class Correlation(JROData):
862 class Correlation(JROData):
860
863
861 noise = None
864 noise = None
862 SNR = None
865 SNR = None
863 #--------------------------------------------------
866 #--------------------------------------------------
864 mode = None
867 mode = None
865 split = False
868 split = False
866 data_cf = None
869 data_cf = None
867 lags = None
870 lags = None
868 lagRange = None
871 lagRange = None
869 pairsList = None
872 pairsList = None
870 normFactor = None
873 normFactor = None
871 #--------------------------------------------------
874 #--------------------------------------------------
872 # calculateVelocity = None
875 # calculateVelocity = None
873 nLags = None
876 nLags = None
874 nPairs = None
877 nPairs = None
875 nAvg = None
878 nAvg = None
876
879
877 def __init__(self):
880 def __init__(self):
878 '''
881 '''
879 Constructor
882 Constructor
880 '''
883 '''
881 self.radarControllerHeaderObj = RadarControllerHeader()
884 self.radarControllerHeaderObj = RadarControllerHeader()
882
885
883 self.systemHeaderObj = SystemHeader()
886 self.systemHeaderObj = SystemHeader()
884
887
885 self.type = "Correlation"
888 self.type = "Correlation"
886
889
887 self.data = None
890 self.data = None
888
891
889 self.dtype = None
892 self.dtype = None
890
893
891 self.nProfiles = None
894 self.nProfiles = None
892
895
893 self.heightList = None
896 self.heightList = None
894
897
895 self.channelList = None
898 self.channelList = None
896
899
897 self.flagNoData = True
900 self.flagNoData = True
898
901
899 self.flagDiscontinuousBlock = False
902 self.flagDiscontinuousBlock = False
900
903
901 self.utctime = None
904 self.utctime = None
902
905
903 self.timeZone = None
906 self.timeZone = None
904
907
905 self.dstFlag = None
908 self.dstFlag = None
906
909
907 self.errorCount = None
910 self.errorCount = None
908
911
909 self.blocksize = None
912 self.blocksize = None
910
913
911 self.flagDecodeData = False # asumo q la data no esta decodificada
914 self.flagDecodeData = False # asumo q la data no esta decodificada
912
915
913 self.flagDeflipData = False # asumo q la data no esta sin flip
916 self.flagDeflipData = False # asumo q la data no esta sin flip
914
917
915 self.pairsList = None
918 self.pairsList = None
916
919
917 self.nPoints = None
920 self.nPoints = None
918
921
919 def getPairsList(self):
922 def getPairsList(self):
920
923
921 return self.pairsList
924 return self.pairsList
922
925
923 def getNoise(self, mode=2):
926 def getNoise(self, mode=2):
924
927
925 indR = numpy.where(self.lagR == 0)[0][0]
928 indR = numpy.where(self.lagR == 0)[0][0]
926 indT = numpy.where(self.lagT == 0)[0][0]
929 indT = numpy.where(self.lagT == 0)[0][0]
927
930
928 jspectra0 = self.data_corr[:, :, indR, :]
931 jspectra0 = self.data_corr[:, :, indR, :]
929 jspectra = copy.copy(jspectra0)
932 jspectra = copy.copy(jspectra0)
930
933
931 num_chan = jspectra.shape[0]
934 num_chan = jspectra.shape[0]
932 num_hei = jspectra.shape[2]
935 num_hei = jspectra.shape[2]
933
936
934 freq_dc = jspectra.shape[1] / 2
937 freq_dc = jspectra.shape[1] / 2
935 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
938 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
936
939
937 if ind_vel[0] < 0:
940 if ind_vel[0] < 0:
938 ind_vel[list(range(0, 1))] = ind_vel[list(
941 ind_vel[list(range(0, 1))] = ind_vel[list(
939 range(0, 1))] + self.num_prof
942 range(0, 1))] + self.num_prof
940
943
941 if mode == 1:
944 if mode == 1:
942 jspectra[:, freq_dc, :] = (
945 jspectra[:, freq_dc, :] = (
943 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
946 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
944
947
945 if mode == 2:
948 if mode == 2:
946
949
947 vel = numpy.array([-2, -1, 1, 2])
950 vel = numpy.array([-2, -1, 1, 2])
948 xx = numpy.zeros([4, 4])
951 xx = numpy.zeros([4, 4])
949
952
950 for fil in range(4):
953 for fil in range(4):
951 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
954 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
952
955
953 xx_inv = numpy.linalg.inv(xx)
956 xx_inv = numpy.linalg.inv(xx)
954 xx_aux = xx_inv[0, :]
957 xx_aux = xx_inv[0, :]
955
958
956 for ich in range(num_chan):
959 for ich in range(num_chan):
957 yy = jspectra[ich, ind_vel, :]
960 yy = jspectra[ich, ind_vel, :]
958 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
961 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
959
962
960 junkid = jspectra[ich, freq_dc, :] <= 0
963 junkid = jspectra[ich, freq_dc, :] <= 0
961 cjunkid = sum(junkid)
964 cjunkid = sum(junkid)
962
965
963 if cjunkid.any():
966 if cjunkid.any():
964 jspectra[ich, freq_dc, junkid.nonzero()] = (
967 jspectra[ich, freq_dc, junkid.nonzero()] = (
965 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
968 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
966
969
967 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
970 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
968
971
969 return noise
972 return noise
970
973
971 def getTimeInterval(self):
974 def getTimeInterval(self):
972
975
973 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
976 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
974
977
975 return timeInterval
978 return timeInterval
976
979
977 def splitFunctions(self):
980 def splitFunctions(self):
978
981
979 pairsList = self.pairsList
982 pairsList = self.pairsList
980 ccf_pairs = []
983 ccf_pairs = []
981 acf_pairs = []
984 acf_pairs = []
982 ccf_ind = []
985 ccf_ind = []
983 acf_ind = []
986 acf_ind = []
984 for l in range(len(pairsList)):
987 for l in range(len(pairsList)):
985 chan0 = pairsList[l][0]
988 chan0 = pairsList[l][0]
986 chan1 = pairsList[l][1]
989 chan1 = pairsList[l][1]
987
990
988 # Obteniendo pares de Autocorrelacion
991 # Obteniendo pares de Autocorrelacion
989 if chan0 == chan1:
992 if chan0 == chan1:
990 acf_pairs.append(chan0)
993 acf_pairs.append(chan0)
991 acf_ind.append(l)
994 acf_ind.append(l)
992 else:
995 else:
993 ccf_pairs.append(pairsList[l])
996 ccf_pairs.append(pairsList[l])
994 ccf_ind.append(l)
997 ccf_ind.append(l)
995
998
996 data_acf = self.data_cf[acf_ind]
999 data_acf = self.data_cf[acf_ind]
997 data_ccf = self.data_cf[ccf_ind]
1000 data_ccf = self.data_cf[ccf_ind]
998
1001
999 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1002 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1000
1003
1001 def getNormFactor(self):
1004 def getNormFactor(self):
1002 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1005 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1003 acf_pairs = numpy.array(acf_pairs)
1006 acf_pairs = numpy.array(acf_pairs)
1004 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1007 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1005
1008
1006 for p in range(self.nPairs):
1009 for p in range(self.nPairs):
1007 pair = self.pairsList[p]
1010 pair = self.pairsList[p]
1008
1011
1009 ch0 = pair[0]
1012 ch0 = pair[0]
1010 ch1 = pair[1]
1013 ch1 = pair[1]
1011
1014
1012 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1015 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1013 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1016 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1014 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1017 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1015
1018
1016 return normFactor
1019 return normFactor
1017
1020
1018 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1021 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1019 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1022 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1020
1023
1021
1024
1022 class Parameters(Spectra):
1025 class Parameters(Spectra):
1023
1026
1024 experimentInfo = None # Information about the experiment
1027 experimentInfo = None # Information about the experiment
1025 # Information from previous data
1028 # Information from previous data
1026 inputUnit = None # Type of data to be processed
1029 inputUnit = None # Type of data to be processed
1027 operation = None # Type of operation to parametrize
1030 operation = None # Type of operation to parametrize
1028 # normFactor = None #Normalization Factor
1031 # normFactor = None #Normalization Factor
1029 groupList = None # List of Pairs, Groups, etc
1032 groupList = None # List of Pairs, Groups, etc
1030 # Parameters
1033 # Parameters
1031 data_param = None # Parameters obtained
1034 data_param = None # Parameters obtained
1032 data_pre = None # Data Pre Parametrization
1035 data_pre = None # Data Pre Parametrization
1033 data_SNR = None # Signal to Noise Ratio
1036 data_SNR = None # Signal to Noise Ratio
1034 # heightRange = None #Heights
1037 # heightRange = None #Heights
1035 abscissaList = None # Abscissa, can be velocities, lags or time
1038 abscissaList = None # Abscissa, can be velocities, lags or time
1036 # noise = None #Noise Potency
1039 # noise = None #Noise Potency
1037 utctimeInit = None # Initial UTC time
1040 utctimeInit = None # Initial UTC time
1038 paramInterval = None # Time interval to calculate Parameters in seconds
1041 paramInterval = None # Time interval to calculate Parameters in seconds
1039 useLocalTime = True
1042 useLocalTime = True
1040 # Fitting
1043 # Fitting
1041 data_error = None # Error of the estimation
1044 data_error = None # Error of the estimation
1042 constants = None
1045 constants = None
1043 library = None
1046 library = None
1044 # Output signal
1047 # Output signal
1045 outputInterval = None # Time interval to calculate output signal in seconds
1048 outputInterval = None # Time interval to calculate output signal in seconds
1046 data_output = None # Out signal
1049 data_output = None # Out signal
1047 nAvg = None
1050 nAvg = None
1048 noise_estimation = None
1051 noise_estimation = None
1049 GauSPC = None # Fit gaussian SPC
1052 GauSPC = None # Fit gaussian SPC
1050
1053
1051 def __init__(self):
1054 def __init__(self):
1052 '''
1055 '''
1053 Constructor
1056 Constructor
1054 '''
1057 '''
1055 self.radarControllerHeaderObj = RadarControllerHeader()
1058 self.radarControllerHeaderObj = RadarControllerHeader()
1056
1059
1057 self.systemHeaderObj = SystemHeader()
1060 self.systemHeaderObj = SystemHeader()
1058
1061
1059 self.type = "Parameters"
1062 self.type = "Parameters"
1060
1063
1061 def getTimeRange1(self, interval):
1064 def getTimeRange1(self, interval):
1062
1065
1063 datatime = []
1066 datatime = []
1064
1067
1065 if self.useLocalTime:
1068 if self.useLocalTime:
1066 time1 = self.utctimeInit - self.timeZone * 60
1069 time1 = self.utctimeInit - self.timeZone * 60
1067 else:
1070 else:
1068 time1 = self.utctimeInit
1071 time1 = self.utctimeInit
1069
1072
1070 datatime.append(time1)
1073 datatime.append(time1)
1071 datatime.append(time1 + interval)
1074 datatime.append(time1 + interval)
1072 datatime = numpy.array(datatime)
1075 datatime = numpy.array(datatime)
1073
1076
1074 return datatime
1077 return datatime
1075
1078
1076 def getTimeInterval(self):
1079 def getTimeInterval(self):
1077
1080
1078 if hasattr(self, 'timeInterval1'):
1081 if hasattr(self, 'timeInterval1'):
1079 return self.timeInterval1
1082 return self.timeInterval1
1080 else:
1083 else:
1081 return self.paramInterval
1084 return self.paramInterval
1082
1085
1083 def setValue(self, value):
1086 def setValue(self, value):
1084
1087
1085 print("This property should not be initialized")
1088 print("This property should not be initialized")
1086
1089
1087 return
1090 return
1088
1091
1089 def getNoise(self):
1092 def getNoise(self):
1090
1093
1091 return self.spc_noise
1094 return self.spc_noise
1092
1095
1093 timeInterval = property(getTimeInterval)
1096 timeInterval = property(getTimeInterval)
1094 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1097 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1095
1098
1096
1099
1097 class PlotterData(object):
1100 class PlotterData(object):
1098 '''
1101 '''
1099 Object to hold data to be plotted
1102 Object to hold data to be plotted
1100 '''
1103 '''
1101
1104
1102 MAXNUMX = 100
1105 MAXNUMX = 100
1103 MAXNUMY = 100
1106 MAXNUMY = 100
1104
1107
1105 def __init__(self, code, throttle_value, exp_code, buffering=True):
1108 def __init__(self, code, throttle_value, exp_code, buffering=True):
1106
1109
1107 self.throttle = throttle_value
1110 self.throttle = throttle_value
1108 self.exp_code = exp_code
1111 self.exp_code = exp_code
1109 self.buffering = buffering
1112 self.buffering = buffering
1110 self.ready = False
1113 self.ready = False
1111 self.localtime = False
1114 self.localtime = False
1112 self.data = {}
1115 self.data = {}
1113 self.meta = {}
1116 self.meta = {}
1114 self.__times = []
1117 self.__times = []
1115 self.__heights = []
1118 self.__heights = []
1116
1119
1117 if 'snr' in code:
1120 if 'snr' in code:
1118 self.plottypes = ['snr']
1121 self.plottypes = ['snr']
1119 elif code == 'spc':
1122 elif code == 'spc':
1120 self.plottypes = ['spc', 'noise', 'rti']
1123 self.plottypes = ['spc', 'noise', 'rti']
1121 elif code == 'rti':
1124 elif code == 'rti':
1122 self.plottypes = ['noise', 'rti']
1125 self.plottypes = ['noise', 'rti']
1123 else:
1126 else:
1124 self.plottypes = [code]
1127 self.plottypes = [code]
1125
1128
1126 for plot in self.plottypes:
1129 for plot in self.plottypes:
1127 self.data[plot] = {}
1130 self.data[plot] = {}
1128
1131
1129 def __str__(self):
1132 def __str__(self):
1130 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1133 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1131 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1134 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1132
1135
1133 def __len__(self):
1136 def __len__(self):
1134 return len(self.__times)
1137 return len(self.__times)
1135
1138
1136 def __getitem__(self, key):
1139 def __getitem__(self, key):
1137
1140
1138 if key not in self.data:
1141 if key not in self.data:
1139 raise KeyError(log.error('Missing key: {}'.format(key)))
1142 raise KeyError(log.error('Missing key: {}'.format(key)))
1140 if 'spc' in key or not self.buffering:
1143 if 'spc' in key or not self.buffering:
1141 ret = self.data[key]
1144 ret = self.data[key]
1142 else:
1145 else:
1143 ret = numpy.array([self.data[key][x] for x in self.times])
1146 ret = numpy.array([self.data[key][x] for x in self.times])
1144 if ret.ndim > 1:
1147 if ret.ndim > 1:
1145 ret = numpy.swapaxes(ret, 0, 1)
1148 ret = numpy.swapaxes(ret, 0, 1)
1146 return ret
1149 return ret
1147
1150
1148 def __contains__(self, key):
1151 def __contains__(self, key):
1149 return key in self.data
1152 return key in self.data
1150
1153
1151 def setup(self):
1154 def setup(self):
1152 '''
1155 '''
1153 Configure object
1156 Configure object
1154 '''
1157 '''
1155
1158
1156 self.type = ''
1159 self.type = ''
1157 self.ready = False
1160 self.ready = False
1158 self.data = {}
1161 self.data = {}
1159 self.__times = []
1162 self.__times = []
1160 self.__heights = []
1163 self.__heights = []
1161 self.__all_heights = set()
1164 self.__all_heights = set()
1162 for plot in self.plottypes:
1165 for plot in self.plottypes:
1163 if 'snr' in plot:
1166 if 'snr' in plot:
1164 plot = 'snr'
1167 plot = 'snr'
1165 self.data[plot] = {}
1168 self.data[plot] = {}
1166
1169
1167 if 'spc' in self.data or 'rti' in self.data:
1170 if 'spc' in self.data or 'rti' in self.data:
1168 self.data['noise'] = {}
1171 self.data['noise'] = {}
1169 if 'noise' not in self.plottypes:
1172 if 'noise' not in self.plottypes:
1170 self.plottypes.append('noise')
1173 self.plottypes.append('noise')
1171
1174
1172 def shape(self, key):
1175 def shape(self, key):
1173 '''
1176 '''
1174 Get the shape of the one-element data for the given key
1177 Get the shape of the one-element data for the given key
1175 '''
1178 '''
1176
1179
1177 if len(self.data[key]):
1180 if len(self.data[key]):
1178 if 'spc' in key or not self.buffering:
1181 if 'spc' in key or not self.buffering:
1179 return self.data[key].shape
1182 return self.data[key].shape
1180 return self.data[key][self.__times[0]].shape
1183 return self.data[key][self.__times[0]].shape
1181 return (0,)
1184 return (0,)
1182
1185
1183 def update(self, dataOut, tm):
1186 def update(self, dataOut, tm):
1184 '''
1187 '''
1185 Update data object with new dataOut
1188 Update data object with new dataOut
1186 '''
1189 '''
1187
1190
1188 if tm in self.__times:
1191 if tm in self.__times:
1189 return
1192 return
1190
1193
1191 self.type = dataOut.type
1194 self.type = dataOut.type
1192 self.parameters = getattr(dataOut, 'parameters', [])
1195 self.parameters = getattr(dataOut, 'parameters', [])
1193 if hasattr(dataOut, 'pairsList'):
1196 if hasattr(dataOut, 'pairsList'):
1194 self.pairs = dataOut.pairsList
1197 self.pairs = dataOut.pairsList
1195 if hasattr(dataOut, 'meta'):
1198 if hasattr(dataOut, 'meta'):
1196 self.meta = dataOut.meta
1199 self.meta = dataOut.meta
1197 self.channels = dataOut.channelList
1200 self.channels = dataOut.channelList
1198 self.interval = dataOut.getTimeInterval()
1201 self.interval = dataOut.getTimeInterval()
1199 self.localtime = dataOut.useLocalTime
1202 self.localtime = dataOut.useLocalTime
1200 if 'spc' in self.plottypes or 'cspc' in self.plottypes:
1203 if 'spc' in self.plottypes or 'cspc' in self.plottypes:
1201 self.xrange = (dataOut.getFreqRange(1)/1000.,
1204 self.xrange = (dataOut.getFreqRange(1)/1000.,
1202 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1205 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1203 self.__heights.append(dataOut.heightList)
1206 self.__heights.append(dataOut.heightList)
1204 self.__all_heights.update(dataOut.heightList)
1207 self.__all_heights.update(dataOut.heightList)
1205 self.__times.append(tm)
1208 self.__times.append(tm)
1206
1209
1207 for plot in self.plottypes:
1210 for plot in self.plottypes:
1208 if plot == 'spc':
1211 if plot == 'spc':
1209 z = dataOut.data_spc/dataOut.normFactor
1212 z = dataOut.data_spc/dataOut.normFactor
1210 buffer = 10*numpy.log10(z)
1213 buffer = 10*numpy.log10(z)
1211 if plot == 'cspc':
1214 if plot == 'cspc':
1212 buffer = dataOut.data_cspc
1215 buffer = dataOut.data_cspc
1213 if plot == 'noise':
1216 if plot == 'noise':
1214 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1217 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1215 if plot == 'rti':
1218 if plot == 'rti':
1216 buffer = dataOut.getPower()
1219 buffer = dataOut.getPower()
1217 if plot == 'snr_db':
1220 if plot == 'snr_db':
1218 buffer = dataOut.data_SNR
1221 buffer = dataOut.data_SNR
1219 if plot == 'snr':
1222 if plot == 'snr':
1220 buffer = 10*numpy.log10(dataOut.data_SNR)
1223 buffer = 10*numpy.log10(dataOut.data_SNR)
1221 if plot == 'dop':
1224 if plot == 'dop':
1222 buffer = 10*numpy.log10(dataOut.data_DOP)
1225 buffer = 10*numpy.log10(dataOut.data_DOP)
1223 if plot == 'mean':
1226 if plot == 'mean':
1224 buffer = dataOut.data_MEAN
1227 buffer = dataOut.data_MEAN
1225 if plot == 'std':
1228 if plot == 'std':
1226 buffer = dataOut.data_STD
1229 buffer = dataOut.data_STD
1227 if plot == 'coh':
1230 if plot == 'coh':
1228 buffer = dataOut.getCoherence()
1231 buffer = dataOut.getCoherence()
1229 if plot == 'phase':
1232 if plot == 'phase':
1230 buffer = dataOut.getCoherence(phase=True)
1233 buffer = dataOut.getCoherence(phase=True)
1231 if plot == 'output':
1234 if plot == 'output':
1232 buffer = dataOut.data_output
1235 buffer = dataOut.data_output
1233 if plot == 'param':
1236 if plot == 'param':
1234 buffer = dataOut.data_param
1237 buffer = dataOut.data_param
1235
1238
1236 if 'spc' in plot:
1239 if 'spc' in plot:
1237 self.data[plot] = buffer
1240 self.data[plot] = buffer
1238 else:
1241 else:
1239 if self.buffering:
1242 if self.buffering:
1240 self.data[plot][tm] = buffer
1243 self.data[plot][tm] = buffer
1241 else:
1244 else:
1242 self.data[plot] = buffer
1245 self.data[plot] = buffer
1243
1246
1244 def normalize_heights(self):
1247 def normalize_heights(self):
1245 '''
1248 '''
1246 Ensure same-dimension of the data for different heighList
1249 Ensure same-dimension of the data for different heighList
1247 '''
1250 '''
1248
1251
1249 H = numpy.array(list(self.__all_heights))
1252 H = numpy.array(list(self.__all_heights))
1250 H.sort()
1253 H.sort()
1251 for key in self.data:
1254 for key in self.data:
1252 shape = self.shape(key)[:-1] + H.shape
1255 shape = self.shape(key)[:-1] + H.shape
1253 for tm, obj in list(self.data[key].items()):
1256 for tm, obj in list(self.data[key].items()):
1254 h = self.__heights[self.__times.index(tm)]
1257 h = self.__heights[self.__times.index(tm)]
1255 if H.size == h.size:
1258 if H.size == h.size:
1256 continue
1259 continue
1257 index = numpy.where(numpy.in1d(H, h))[0]
1260 index = numpy.where(numpy.in1d(H, h))[0]
1258 dummy = numpy.zeros(shape) + numpy.nan
1261 dummy = numpy.zeros(shape) + numpy.nan
1259 if len(shape) == 2:
1262 if len(shape) == 2:
1260 dummy[:, index] = obj
1263 dummy[:, index] = obj
1261 else:
1264 else:
1262 dummy[index] = obj
1265 dummy[index] = obj
1263 self.data[key][tm] = dummy
1266 self.data[key][tm] = dummy
1264
1267
1265 self.__heights = [H for tm in self.__times]
1268 self.__heights = [H for tm in self.__times]
1266
1269
1267 def jsonify(self, decimate=False):
1270 def jsonify(self, decimate=False):
1268 '''
1271 '''
1269 Convert data to json
1272 Convert data to json
1270 '''
1273 '''
1271
1274
1272 data = {}
1275 data = {}
1273 tm = self.times[-1]
1276 tm = self.times[-1]
1274 dy = int(self.heights.size/self.MAXNUMY) + 1
1277 dy = int(self.heights.size/self.MAXNUMY) + 1
1275 for key in self.data:
1278 for key in self.data:
1276 if key in ('spc', 'cspc') or not self.buffering:
1279 if key in ('spc', 'cspc') or not self.buffering:
1277 dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1
1280 dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1
1278 data[key] = self.roundFloats(
1281 data[key] = self.roundFloats(
1279 self.data[key][::, ::dx, ::dy].tolist())
1282 self.data[key][::, ::dx, ::dy].tolist())
1280 else:
1283 else:
1281 data[key] = self.roundFloats(self.data[key][tm].tolist())
1284 data[key] = self.roundFloats(self.data[key][tm].tolist())
1282
1285
1283 ret = {'data': data}
1286 ret = {'data': data}
1284 ret['exp_code'] = self.exp_code
1287 ret['exp_code'] = self.exp_code
1285 ret['time'] = float(tm)
1288 ret['time'] = float(tm)
1286 ret['interval'] = float(self.interval)
1289 ret['interval'] = float(self.interval)
1287 ret['localtime'] = self.localtime
1290 ret['localtime'] = self.localtime
1288 ret['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1291 ret['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1289 if 'spc' in self.data or 'cspc' in self.data:
1292 if 'spc' in self.data or 'cspc' in self.data:
1290 ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1293 ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1291 else:
1294 else:
1292 ret['xrange'] = []
1295 ret['xrange'] = []
1293 if hasattr(self, 'pairs'):
1296 if hasattr(self, 'pairs'):
1294 ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs]
1297 ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs]
1295 else:
1298 else:
1296 ret['pairs'] = []
1299 ret['pairs'] = []
1297
1300
1298 for key, value in list(self.meta.items()):
1301 for key, value in list(self.meta.items()):
1299 ret[key] = value
1302 ret[key] = value
1300
1303
1301 return json.dumps(ret)
1304 return json.dumps(ret)
1302
1305
1303 @property
1306 @property
1304 def times(self):
1307 def times(self):
1305 '''
1308 '''
1306 Return the list of times of the current data
1309 Return the list of times of the current data
1307 '''
1310 '''
1308
1311
1309 ret = numpy.array(self.__times)
1312 ret = numpy.array(self.__times)
1310 ret.sort()
1313 ret.sort()
1311 return ret
1314 return ret
1312
1315
1313 @property
1316 @property
1314 def min_time(self):
1317 def min_time(self):
1315 '''
1318 '''
1316 Return the minimun time value
1319 Return the minimun time value
1317 '''
1320 '''
1318
1321
1319 return self.times[0]
1322 return self.times[0]
1320
1323
1321 @property
1324 @property
1322 def max_time(self):
1325 def max_time(self):
1323 '''
1326 '''
1324 Return the maximun time value
1327 Return the maximun time value
1325 '''
1328 '''
1326
1329
1327 return self.times[-1]
1330 return self.times[-1]
1328
1331
1329 @property
1332 @property
1330 def heights(self):
1333 def heights(self):
1331 '''
1334 '''
1332 Return the list of heights of the current data
1335 Return the list of heights of the current data
1333 '''
1336 '''
1334
1337
1335 return numpy.array(self.__heights[-1])
1338 return numpy.array(self.__heights[-1])
1336
1339
1337 @staticmethod
1340 @staticmethod
1338 def roundFloats(obj):
1341 def roundFloats(obj):
1339 if isinstance(obj, list):
1342 if isinstance(obj, list):
1340 return list(map(PlotterData.roundFloats, obj))
1343 return list(map(PlotterData.roundFloats, obj))
1341 elif isinstance(obj, float):
1344 elif isinstance(obj, float):
1342 return round(obj, 2)
1345 return round(obj, 2)
@@ -1,2158 +1,2389
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
5 from .figure import Figure, isRealtime, isTimeInHourRange
5 from .figure import Figure, isRealtime, isTimeInHourRange
6 from .plotting_codes import *
6 from .plotting_codes import *
7 from schainpy.model.proc.jroproc_base import MPDecorator
7 from schainpy.model.proc.jroproc_base import MPDecorator
8 from schainpy.utils import log
8 from schainpy.utils import log
9
9
10 class FitGauPlot_(Figure):
10 class ParamLine_(Figure):
11
12 isConfig = None
13
14 def __init__(self):
15
16 self.isConfig = False
17 self.WIDTH = 300
18 self.HEIGHT = 200
19 self.counter_imagwr = 0
20
21 def getSubplots(self):
22
23 nrow = self.nplots
24 ncol = 3
25 return nrow, ncol
26
27 def setup(self, id, nplots, wintitle, show):
28
29 self.nplots = nplots
30
31 self.createFigure(id=id,
32 wintitle=wintitle,
33 show=show)
34
35 nrow,ncol = self.getSubplots()
36 colspan = 3
37 rowspan = 1
38
39 for i in range(nplots):
40 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
41
42 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
43 yreal = y[channelIndexList,:].real
44 yimag = y[channelIndexList,:].imag
45
46 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
47 xlabel = "Range (Km)"
48 ylabel = "Intensity - IQ"
49
50 if not self.isConfig:
51 nplots = len(channelIndexList)
52
53 self.setup(id=id,
54 nplots=nplots,
55 wintitle='',
56 show=show)
57
58 if xmin == None: xmin = numpy.nanmin(x)
59 if xmax == None: xmax = numpy.nanmax(x)
60 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
61 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
62
63 self.isConfig = True
64
65 self.setWinTitle(title)
66
67 for i in range(len(self.axesList)):
68 title = "Channel %d" %(i)
69 axes = self.axesList[i]
70
71 axes.pline(x, yreal[i,:],
72 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
73 xlabel=xlabel, ylabel=ylabel, title=title)
74
75 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
76
77 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
78 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
79 yreal = y.real
80
81 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
82 xlabel = "Range (Km)"
83 ylabel = "Intensity"
84
85 if not self.isConfig:
86 nplots = len(channelIndexList)
87
88 self.setup(id=id,
89 nplots=nplots,
90 wintitle='',
91 show=show)
92
93 if xmin == None: xmin = numpy.nanmin(x)
94 if xmax == None: xmax = numpy.nanmax(x)
95 if ymin == None: ymin = numpy.nanmin(yreal)
96 if ymax == None: ymax = numpy.nanmax(yreal)
97
98 self.isConfig = True
99
100 self.setWinTitle(title)
101
102 for i in range(len(self.axesList)):
103 title = "Channel %d" %(i)
104 axes = self.axesList[i]
105 ychannel = yreal[i,:]
106 axes.pline(x, ychannel,
107 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
108 xlabel=xlabel, ylabel=ylabel, title=title)
109
110
111 def run(self, dataOut, id, wintitle="", channelList=None,
112 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
113 figpath='./', figfile=None, show=True, wr_period=1,
114 ftp=False, server=None, folder=None, username=None, password=None):
115
116 """
117
118 Input:
119 dataOut :
120 id :
121 wintitle :
122 channelList :
123 xmin : None,
124 xmax : None,
125 ymin : None,
126 ymax : None,
127 """
128
129 if channelList == None:
130 channelIndexList = dataOut.channelIndexList
131 else:
132 channelIndexList = []
133 for channel in channelList:
134 if channel not in dataOut.channelList:
135 raise ValueError("Channel %d is not in dataOut.channelList" % channel)
136 channelIndexList.append(dataOut.channelList.index(channel))
137
138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
139
140 y = dataOut.RR
141
142 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
143 xlabel = "Range (Km)"
144 ylabel = "Intensity"
145
146 if not self.isConfig:
147 nplots = len(channelIndexList)
148
149 self.setup(id=id,
150 nplots=nplots,
151 wintitle='',
152 show=show)
153
154 if xmin == None: xmin = numpy.nanmin(x)
155 if xmax == None: xmax = numpy.nanmax(x)
156 if ymin == None: ymin = numpy.nanmin(y)
157 if ymax == None: ymax = numpy.nanmax(y)
158
159 self.isConfig = True
160
161 self.setWinTitle(title)
162
163 for i in range(len(self.axesList)):
164 title = "Channel %d" %(i)
165 axes = self.axesList[i]
166 ychannel = y[i,:]
167 axes.pline(x, ychannel,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
169 xlabel=xlabel, ylabel=ylabel, title=title)
170
171
172 self.draw()
173
174 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
175 figfile = self.getFilename(name = str_datetime)
176
177 self.save(figpath=figpath,
178 figfile=figfile,
179 save=save,
180 ftp=ftp,
181 wr_period=wr_period,
182 thisDatetime=thisDatetime)
183
184
185
186 class SpcParamPlot_(Figure):
11
187
12 isConfig = None
188 isConfig = None
13 __nsubplots = None
189 __nsubplots = None
14
190
15 WIDTHPROF = None
191 WIDTHPROF = None
16 HEIGHTPROF = None
192 HEIGHTPROF = None
17 PREFIX = 'fitgau'
193 PREFIX = 'SpcParam'
18
194
19 def __init__(self, **kwargs):
195 def __init__(self, **kwargs):
20 Figure.__init__(self, **kwargs)
196 Figure.__init__(self, **kwargs)
21 self.isConfig = False
197 self.isConfig = False
22 self.__nsubplots = 1
198 self.__nsubplots = 1
23
199
24 self.WIDTH = 250
200 self.WIDTH = 250
25 self.HEIGHT = 250
201 self.HEIGHT = 250
26 self.WIDTHPROF = 120
202 self.WIDTHPROF = 120
27 self.HEIGHTPROF = 0
203 self.HEIGHTPROF = 0
28 self.counter_imagwr = 0
204 self.counter_imagwr = 0
29
205
30 self.PLOT_CODE = SPEC_CODE
206 self.PLOT_CODE = SPEC_CODE
31
207
32 self.FTP_WEI = None
208 self.FTP_WEI = None
33 self.EXP_CODE = None
209 self.EXP_CODE = None
34 self.SUB_EXP_CODE = None
210 self.SUB_EXP_CODE = None
35 self.PLOT_POS = None
211 self.PLOT_POS = None
36
212
37 self.__xfilter_ena = False
213 self.__xfilter_ena = False
38 self.__yfilter_ena = False
214 self.__yfilter_ena = False
39
215
40 def getSubplots(self):
216 def getSubplots(self):
41
217
42 ncol = int(numpy.sqrt(self.nplots)+0.9)
218 ncol = int(numpy.sqrt(self.nplots)+0.9)
43 nrow = int(self.nplots*1./ncol + 0.9)
219 nrow = int(self.nplots*1./ncol + 0.9)
44
220
45 return nrow, ncol
221 return nrow, ncol
46
222
47 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
223 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
48
224
49 self.__showprofile = showprofile
225 self.__showprofile = showprofile
50 self.nplots = nplots
226 self.nplots = nplots
51
227
52 ncolspan = 1
228 ncolspan = 1
53 colspan = 1
229 colspan = 1
54 if showprofile:
230 if showprofile:
55 ncolspan = 3
231 ncolspan = 3
56 colspan = 2
232 colspan = 2
57 self.__nsubplots = 2
233 self.__nsubplots = 2
58
234
59 self.createFigure(id = id,
235 self.createFigure(id = id,
60 wintitle = wintitle,
236 wintitle = wintitle,
61 widthplot = self.WIDTH + self.WIDTHPROF,
237 widthplot = self.WIDTH + self.WIDTHPROF,
62 heightplot = self.HEIGHT + self.HEIGHTPROF,
238 heightplot = self.HEIGHT + self.HEIGHTPROF,
63 show=show)
239 show=show)
64
240
65 nrow, ncol = self.getSubplots()
241 nrow, ncol = self.getSubplots()
66
242
67 counter = 0
243 counter = 0
68 for y in range(nrow):
244 for y in range(nrow):
69 for x in range(ncol):
245 for x in range(ncol):
70
246
71 if counter >= self.nplots:
247 if counter >= self.nplots:
72 break
248 break
73
249
74 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
250 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
75
251
76 if showprofile:
252 if showprofile:
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
253 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
78
254
79 counter += 1
255 counter += 1
80
256
81 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
257 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
82 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
258 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
83 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
259 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
84 server=None, folder=None, username=None, password=None,
260 server=None, folder=None, username=None, password=None,
85 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
261 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
86 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 1):
262 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
87
263
88 """
264 """
89
265
90 Input:
266 Input:
91 dataOut :
267 dataOut :
92 id :
268 id :
93 wintitle :
269 wintitle :
94 channelList :
270 channelList :
95 showProfile :
271 showProfile :
96 xmin : None,
272 xmin : None,
97 xmax : None,
273 xmax : None,
98 ymin : None,
274 ymin : None,
99 ymax : None,
275 ymax : None,
100 zmin : None,
276 zmin : None,
101 zmax : None
277 zmax : None
102 """
278 """
103 if realtime:
279 if realtime:
104 if not(isRealtime(utcdatatime = dataOut.utctime)):
280 if not(isRealtime(utcdatatime = dataOut.utctime)):
105 print('Skipping this plot function')
281 print('Skipping this plot function')
106 return
282 return
107
283
108 if channelList == None:
284 if channelList == None:
109 channelIndexList = dataOut.channelIndexList
285 channelIndexList = dataOut.channelIndexList
110 else:
286 else:
111 channelIndexList = []
287 channelIndexList = []
112 for channel in channelList:
288 for channel in channelList:
113 if channel not in dataOut.channelList:
289 if channel not in dataOut.channelList:
114 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
290 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
115 channelIndexList.append(dataOut.channelList.index(channel))
291 channelIndexList.append(dataOut.channelList.index(channel))
116
292
117 # if normFactor is None:
293 # if normFactor is None:
118 # factor = dataOut.normFactor
294 # factor = dataOut.normFactor
119 # else:
295 # else:
120 # factor = normFactor
296 # factor = normFactor
121 if xaxis == "frequency":
297 if xaxis == "frequency":
122 x = dataOut.spc_range[0]
298 x = dataOut.spcparam_range[0]
123 xlabel = "Frequency (kHz)"
299 xlabel = "Frequency (kHz)"
124
300
125 elif xaxis == "time":
301 elif xaxis == "time":
126 x = dataOut.spc_range[1]
302 x = dataOut.spcparam_range[1]
127 xlabel = "Time (ms)"
303 xlabel = "Time (ms)"
128
304
129 else:
305 else:
130 x = dataOut.spc_range[2]
306 x = dataOut.spcparam_range[2]
131 xlabel = "Velocity (m/s)"
307 xlabel = "Velocity (m/s)"
132
308
133 ylabel = "Range (Km)"
309 ylabel = "Range (km)"
134
310
135 y = dataOut.getHeiRange()
311 y = dataOut.getHeiRange()
136
312
137 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
313 z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor
138 print('GausSPC', z[0,32,10:40])
139 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
314 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
140 zdB = 10*numpy.log10(z)
315 zdB = 10*numpy.log10(z)
141
316
142 avg = numpy.average(z, axis=1)
317 avg = numpy.average(z, axis=1)
143 avgdB = 10*numpy.log10(avg)
318 avgdB = 10*numpy.log10(avg)
144
319
145 noise = dataOut.spc_noise
320 noise = dataOut.spc_noise
146 noisedB = 10*numpy.log10(noise)
321 noisedB = 10*numpy.log10(noise)
147
322
148 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
323 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
149 title = wintitle + " Spectra"
324 title = wintitle + " Spectra"
150 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
325 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
151 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
326 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
152
327
153 if not self.isConfig:
328 if not self.isConfig:
154
329
155 nplots = len(channelIndexList)
330 nplots = len(channelIndexList)
156
331
157 self.setup(id=id,
332 self.setup(id=id,
158 nplots=nplots,
333 nplots=nplots,
159 wintitle=wintitle,
334 wintitle=wintitle,
160 showprofile=showprofile,
335 showprofile=showprofile,
161 show=show)
336 show=show)
162
337
163 if xmin == None: xmin = numpy.nanmin(x)
338 if xmin == None: xmin = numpy.nanmin(x)
164 if xmax == None: xmax = numpy.nanmax(x)
339 if xmax == None: xmax = numpy.nanmax(x)
165 if ymin == None: ymin = numpy.nanmin(y)
340 if ymin == None: ymin = numpy.nanmin(y)
166 if ymax == None: ymax = numpy.nanmax(y)
341 if ymax == None: ymax = numpy.nanmax(y)
167 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
342 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
168 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
343 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
169
344
170 self.FTP_WEI = ftp_wei
345 self.FTP_WEI = ftp_wei
171 self.EXP_CODE = exp_code
346 self.EXP_CODE = exp_code
172 self.SUB_EXP_CODE = sub_exp_code
347 self.SUB_EXP_CODE = sub_exp_code
173 self.PLOT_POS = plot_pos
348 self.PLOT_POS = plot_pos
174
349
175 self.isConfig = True
350 self.isConfig = True
176
351
177 self.setWinTitle(title)
352 self.setWinTitle(title)
178
353
179 for i in range(self.nplots):
354 for i in range(self.nplots):
180 index = channelIndexList[i]
355 index = channelIndexList[i]
181 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
356 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
182 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
357 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
183 if len(dataOut.beam.codeList) != 0:
358 if len(dataOut.beam.codeList) != 0:
184 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)
359 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)
185
360
186 axes = self.axesList[i*self.__nsubplots]
361 axes = self.axesList[i*self.__nsubplots]
187 axes.pcolor(x, y, zdB[index,:,:],
362 axes.pcolor(x, y, zdB[index,:,:],
188 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
363 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
189 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
364 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
190 ticksize=9, cblabel='')
365 ticksize=9, cblabel='')
191
366
192 if self.__showprofile:
367 if self.__showprofile:
193 axes = self.axesList[i*self.__nsubplots +1]
368 axes = self.axesList[i*self.__nsubplots +1]
194 axes.pline(avgdB[index,:], y,
369 axes.pline(avgdB[index,:], y,
195 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
370 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
196 xlabel='dB', ylabel='', title='',
371 xlabel='dB', ylabel='', title='',
197 ytick_visible=False,
372 ytick_visible=False,
198 grid='x')
373 grid='x')
199
374
200 noiseline = numpy.repeat(noisedB[index], len(y))
375 noiseline = numpy.repeat(noisedB[index], len(y))
201 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
376 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
202
377
203 self.draw()
378 self.draw()
204
379
205 if figfile == None:
380 if figfile == None:
206 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
381 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
207 name = str_datetime
382 name = str_datetime
208 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
383 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
209 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
384 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
210 figfile = self.getFilename(name)
385 figfile = self.getFilename(name)
211
386
212 self.save(figpath=figpath,
387 self.save(figpath=figpath,
213 figfile=figfile,
388 figfile=figfile,
214 save=save,
389 save=save,
215 ftp=ftp,
390 ftp=ftp,
216 wr_period=wr_period,
391 wr_period=wr_period,
217 thisDatetime=thisDatetime)
392 thisDatetime=thisDatetime)
218
393
219
394
220
395
221 class MomentsPlot_(Figure):
396 class MomentsPlot_(Figure):
222
397
223 isConfig = None
398 isConfig = None
224 __nsubplots = None
399 __nsubplots = None
225
400
226 WIDTHPROF = None
401 WIDTHPROF = None
227 HEIGHTPROF = None
402 HEIGHTPROF = None
228 PREFIX = 'prm'
403 PREFIX = 'prm'
229 def __init__(self):
404 def __init__(self):
230 Figure.__init__(self)
405 Figure.__init__(self)
231 self.isConfig = False
406 self.isConfig = False
232 self.__nsubplots = 1
407 self.__nsubplots = 1
233
408
234 self.WIDTH = 280
409 self.WIDTH = 280
235 self.HEIGHT = 250
410 self.HEIGHT = 250
236 self.WIDTHPROF = 120
411 self.WIDTHPROF = 120
237 self.HEIGHTPROF = 0
412 self.HEIGHTPROF = 0
238 self.counter_imagwr = 0
413 self.counter_imagwr = 0
239
414
240 self.PLOT_CODE = MOMENTS_CODE
415 self.PLOT_CODE = MOMENTS_CODE
241
416
242 self.FTP_WEI = None
417 self.FTP_WEI = None
243 self.EXP_CODE = None
418 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
419 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
420 self.PLOT_POS = None
246
421
247 def getSubplots(self):
422 def getSubplots(self):
248
423
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
424 ncol = int(numpy.sqrt(self.nplots)+0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
425 nrow = int(self.nplots*1./ncol + 0.9)
251
426
252 return nrow, ncol
427 return nrow, ncol
253
428
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
429 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
430
256 self.__showprofile = showprofile
431 self.__showprofile = showprofile
257 self.nplots = nplots
432 self.nplots = nplots
258
433
259 ncolspan = 1
434 ncolspan = 1
260 colspan = 1
435 colspan = 1
261 if showprofile:
436 if showprofile:
262 ncolspan = 3
437 ncolspan = 3
263 colspan = 2
438 colspan = 2
264 self.__nsubplots = 2
439 self.__nsubplots = 2
265
440
266 self.createFigure(id = id,
441 self.createFigure(id = id,
267 wintitle = wintitle,
442 wintitle = wintitle,
268 widthplot = self.WIDTH + self.WIDTHPROF,
443 widthplot = self.WIDTH + self.WIDTHPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
444 heightplot = self.HEIGHT + self.HEIGHTPROF,
270 show=show)
445 show=show)
271
446
272 nrow, ncol = self.getSubplots()
447 nrow, ncol = self.getSubplots()
273
448
274 counter = 0
449 counter = 0
275 for y in range(nrow):
450 for y in range(nrow):
276 for x in range(ncol):
451 for x in range(ncol):
277
452
278 if counter >= self.nplots:
453 if counter >= self.nplots:
279 break
454 break
280
455
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
456 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
282
457
283 if showprofile:
458 if showprofile:
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
459 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
285
460
286 counter += 1
461 counter += 1
287
462
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
463 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
464 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
465 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
291 server=None, folder=None, username=None, password=None,
466 server=None, folder=None, username=None, password=None,
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
467 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
293
468
294 """
469 """
295
470
296 Input:
471 Input:
297 dataOut :
472 dataOut :
298 id :
473 id :
299 wintitle :
474 wintitle :
300 channelList :
475 channelList :
301 showProfile :
476 showProfile :
302 xmin : None,
477 xmin : None,
303 xmax : None,
478 xmax : None,
304 ymin : None,
479 ymin : None,
305 ymax : None,
480 ymax : None,
306 zmin : None,
481 zmin : None,
307 zmax : None
482 zmax : None
308 """
483 """
309
484
310 if dataOut.flagNoData:
485 if dataOut.flagNoData:
311 return None
486 return None
312
487
313 if realtime:
488 if realtime:
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
489 if not(isRealtime(utcdatatime = dataOut.utctime)):
315 print('Skipping this plot function')
490 print('Skipping this plot function')
316 return
491 return
317
492
318 if channelList == None:
493 if channelList == None:
319 channelIndexList = dataOut.channelIndexList
494 channelIndexList = dataOut.channelIndexList
320 else:
495 else:
321 channelIndexList = []
496 channelIndexList = []
322 for channel in channelList:
497 for channel in channelList:
323 if channel not in dataOut.channelList:
498 if channel not in dataOut.channelList:
324 raise ValueError("Channel %d is not in dataOut.channelList")
499 raise ValueError("Channel %d is not in dataOut.channelList")
325 channelIndexList.append(dataOut.channelList.index(channel))
500 channelIndexList.append(dataOut.channelList.index(channel))
326
501
327 factor = dataOut.normFactor
502 factor = dataOut.normFactor
328 x = dataOut.abscissaList
503 x = dataOut.abscissaList
329 y = dataOut.heightList
504 y = dataOut.heightList
330
505
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
506 z = dataOut.data_pre[channelIndexList,:,:]/factor
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
507 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
333 avg = numpy.average(z, axis=1)
508 avg = numpy.average(z, axis=1)
334 noise = dataOut.noise/factor
509 noise = dataOut.noise/factor
335
510
336 zdB = 10*numpy.log10(z)
511 zdB = 10*numpy.log10(z)
337 avgdB = 10*numpy.log10(avg)
512 avgdB = 10*numpy.log10(avg)
338 noisedB = 10*numpy.log10(noise)
513 noisedB = 10*numpy.log10(noise)
339
514
340 #thisDatetime = dataOut.datatime
515 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
516 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Parameters"
517 title = wintitle + " Parameters"
343 xlabel = "Velocity (m/s)"
518 xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
519 ylabel = "Range (Km)"
345
520
346 update_figfile = False
521 update_figfile = False
347
522
348 if not self.isConfig:
523 if not self.isConfig:
349
524
350 nplots = len(channelIndexList)
525 nplots = len(channelIndexList)
351
526
352 self.setup(id=id,
527 self.setup(id=id,
353 nplots=nplots,
528 nplots=nplots,
354 wintitle=wintitle,
529 wintitle=wintitle,
355 showprofile=showprofile,
530 showprofile=showprofile,
356 show=show)
531 show=show)
357
532
358 if xmin == None: xmin = numpy.nanmin(x)
533 if xmin == None: xmin = numpy.nanmin(x)
359 if xmax == None: xmax = numpy.nanmax(x)
534 if xmax == None: xmax = numpy.nanmax(x)
360 if ymin == None: ymin = numpy.nanmin(y)
535 if ymin == None: ymin = numpy.nanmin(y)
361 if ymax == None: ymax = numpy.nanmax(y)
536 if ymax == None: ymax = numpy.nanmax(y)
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
537 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
538 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
364
539
365 self.FTP_WEI = ftp_wei
540 self.FTP_WEI = ftp_wei
366 self.EXP_CODE = exp_code
541 self.EXP_CODE = exp_code
367 self.SUB_EXP_CODE = sub_exp_code
542 self.SUB_EXP_CODE = sub_exp_code
368 self.PLOT_POS = plot_pos
543 self.PLOT_POS = plot_pos
369
544
370 self.isConfig = True
545 self.isConfig = True
371 update_figfile = True
546 update_figfile = True
372
547
373 self.setWinTitle(title)
548 self.setWinTitle(title)
374
549
375 for i in range(self.nplots):
550 for i in range(self.nplots):
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
551 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
552 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
378 axes = self.axesList[i*self.__nsubplots]
553 axes = self.axesList[i*self.__nsubplots]
379 axes.pcolor(x, y, zdB[i,:,:],
554 axes.pcolor(x, y, zdB[i,:,:],
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
555 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
381 xlabel=xlabel, ylabel=ylabel, title=title,
556 xlabel=xlabel, ylabel=ylabel, title=title,
382 ticksize=9, cblabel='')
557 ticksize=9, cblabel='')
383 #Mean Line
558 #Mean Line
384 mean = dataOut.data_param[i, 1, :]
559 mean = dataOut.data_param[i, 1, :]
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
560 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
386
561
387 if self.__showprofile:
562 if self.__showprofile:
388 axes = self.axesList[i*self.__nsubplots +1]
563 axes = self.axesList[i*self.__nsubplots +1]
389 axes.pline(avgdB[i], y,
564 axes.pline(avgdB[i], y,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
565 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
391 xlabel='dB', ylabel='', title='',
566 xlabel='dB', ylabel='', title='',
392 ytick_visible=False,
567 ytick_visible=False,
393 grid='x')
568 grid='x')
394
569
395 noiseline = numpy.repeat(noisedB[i], len(y))
570 noiseline = numpy.repeat(noisedB[i], len(y))
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
571 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
397
572
398 self.draw()
573 self.draw()
399
574
400 self.save(figpath=figpath,
575 self.save(figpath=figpath,
401 figfile=figfile,
576 figfile=figfile,
402 save=save,
577 save=save,
403 ftp=ftp,
578 ftp=ftp,
404 wr_period=wr_period,
579 wr_period=wr_period,
405 thisDatetime=thisDatetime)
580 thisDatetime=thisDatetime)
406
581
407
582
408 class SkyMapPlot_(Figure):
583 class SkyMapPlot_(Figure):
409
584
410 __isConfig = None
585 __isConfig = None
411 __nsubplots = None
586 __nsubplots = None
412
587
413 WIDTHPROF = None
588 WIDTHPROF = None
414 HEIGHTPROF = None
589 HEIGHTPROF = None
415 PREFIX = 'mmap'
590 PREFIX = 'mmap'
416
591
417 def __init__(self, **kwargs):
592 def __init__(self, **kwargs):
418 Figure.__init__(self, **kwargs)
593 Figure.__init__(self, **kwargs)
419 self.isConfig = False
594 self.isConfig = False
420 self.__nsubplots = 1
595 self.__nsubplots = 1
421
596
422 # self.WIDTH = 280
597 # self.WIDTH = 280
423 # self.HEIGHT = 250
598 # self.HEIGHT = 250
424 self.WIDTH = 600
599 self.WIDTH = 600
425 self.HEIGHT = 600
600 self.HEIGHT = 600
426 self.WIDTHPROF = 120
601 self.WIDTHPROF = 120
427 self.HEIGHTPROF = 0
602 self.HEIGHTPROF = 0
428 self.counter_imagwr = 0
603 self.counter_imagwr = 0
429
604
430 self.PLOT_CODE = MSKYMAP_CODE
605 self.PLOT_CODE = MSKYMAP_CODE
431
606
432 self.FTP_WEI = None
607 self.FTP_WEI = None
433 self.EXP_CODE = None
608 self.EXP_CODE = None
434 self.SUB_EXP_CODE = None
609 self.SUB_EXP_CODE = None
435 self.PLOT_POS = None
610 self.PLOT_POS = None
436
611
437 def getSubplots(self):
612 def getSubplots(self):
438
613
439 ncol = int(numpy.sqrt(self.nplots)+0.9)
614 ncol = int(numpy.sqrt(self.nplots)+0.9)
440 nrow = int(self.nplots*1./ncol + 0.9)
615 nrow = int(self.nplots*1./ncol + 0.9)
441
616
442 return nrow, ncol
617 return nrow, ncol
443
618
444 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
619 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
445
620
446 self.__showprofile = showprofile
621 self.__showprofile = showprofile
447 self.nplots = nplots
622 self.nplots = nplots
448
623
449 ncolspan = 1
624 ncolspan = 1
450 colspan = 1
625 colspan = 1
451
626
452 self.createFigure(id = id,
627 self.createFigure(id = id,
453 wintitle = wintitle,
628 wintitle = wintitle,
454 widthplot = self.WIDTH, #+ self.WIDTHPROF,
629 widthplot = self.WIDTH, #+ self.WIDTHPROF,
455 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
630 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
456 show=show)
631 show=show)
457
632
458 nrow, ncol = 1,1
633 nrow, ncol = 1,1
459 counter = 0
634 counter = 0
460 x = 0
635 x = 0
461 y = 0
636 y = 0
462 self.addAxes(1, 1, 0, 0, 1, 1, True)
637 self.addAxes(1, 1, 0, 0, 1, 1, True)
463
638
464 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
639 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
465 tmin=0, tmax=24, timerange=None,
640 tmin=0, tmax=24, timerange=None,
466 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
641 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
467 server=None, folder=None, username=None, password=None,
642 server=None, folder=None, username=None, password=None,
468 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
643 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
469
644
470 """
645 """
471
646
472 Input:
647 Input:
473 dataOut :
648 dataOut :
474 id :
649 id :
475 wintitle :
650 wintitle :
476 channelList :
651 channelList :
477 showProfile :
652 showProfile :
478 xmin : None,
653 xmin : None,
479 xmax : None,
654 xmax : None,
480 ymin : None,
655 ymin : None,
481 ymax : None,
656 ymax : None,
482 zmin : None,
657 zmin : None,
483 zmax : None
658 zmax : None
484 """
659 """
485
660
486 arrayParameters = dataOut.data_param
661 arrayParameters = dataOut.data_param
487 error = arrayParameters[:,-1]
662 error = arrayParameters[:,-1]
488 indValid = numpy.where(error == 0)[0]
663 indValid = numpy.where(error == 0)[0]
489 finalMeteor = arrayParameters[indValid,:]
664 finalMeteor = arrayParameters[indValid,:]
490 finalAzimuth = finalMeteor[:,3]
665 finalAzimuth = finalMeteor[:,3]
491 finalZenith = finalMeteor[:,4]
666 finalZenith = finalMeteor[:,4]
492
667
493 x = finalAzimuth*numpy.pi/180
668 x = finalAzimuth*numpy.pi/180
494 y = finalZenith
669 y = finalZenith
495 x1 = [dataOut.ltctime, dataOut.ltctime]
670 x1 = [dataOut.ltctime, dataOut.ltctime]
496
671
497 #thisDatetime = dataOut.datatime
672 #thisDatetime = dataOut.datatime
498 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
673 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
499 title = wintitle + " Parameters"
674 title = wintitle + " Parameters"
500 xlabel = "Zonal Zenith Angle (deg) "
675 xlabel = "Zonal Zenith Angle (deg) "
501 ylabel = "Meridional Zenith Angle (deg)"
676 ylabel = "Meridional Zenith Angle (deg)"
502 update_figfile = False
677 update_figfile = False
503
678
504 if not self.isConfig:
679 if not self.isConfig:
505
680
506 nplots = 1
681 nplots = 1
507
682
508 self.setup(id=id,
683 self.setup(id=id,
509 nplots=nplots,
684 nplots=nplots,
510 wintitle=wintitle,
685 wintitle=wintitle,
511 showprofile=showprofile,
686 showprofile=showprofile,
512 show=show)
687 show=show)
513
688
514 if self.xmin is None and self.xmax is None:
689 if self.xmin is None and self.xmax is None:
515 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
690 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
516
691
517 if timerange != None:
692 if timerange != None:
518 self.timerange = timerange
693 self.timerange = timerange
519 else:
694 else:
520 self.timerange = self.xmax - self.xmin
695 self.timerange = self.xmax - self.xmin
521
696
522 self.FTP_WEI = ftp_wei
697 self.FTP_WEI = ftp_wei
523 self.EXP_CODE = exp_code
698 self.EXP_CODE = exp_code
524 self.SUB_EXP_CODE = sub_exp_code
699 self.SUB_EXP_CODE = sub_exp_code
525 self.PLOT_POS = plot_pos
700 self.PLOT_POS = plot_pos
526 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
701 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
527 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
702 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
528 self.isConfig = True
703 self.isConfig = True
529 update_figfile = True
704 update_figfile = True
530
705
531 self.setWinTitle(title)
706 self.setWinTitle(title)
532
707
533 i = 0
708 i = 0
534 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
709 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
535
710
536 axes = self.axesList[i*self.__nsubplots]
711 axes = self.axesList[i*self.__nsubplots]
537 nevents = axes.x_buffer.shape[0] + x.shape[0]
712 nevents = axes.x_buffer.shape[0] + x.shape[0]
538 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
713 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
539 axes.polar(x, y,
714 axes.polar(x, y,
540 title=title, xlabel=xlabel, ylabel=ylabel,
715 title=title, xlabel=xlabel, ylabel=ylabel,
541 ticksize=9, cblabel='')
716 ticksize=9, cblabel='')
542
717
543 self.draw()
718 self.draw()
544
719
545 self.save(figpath=figpath,
720 self.save(figpath=figpath,
546 figfile=figfile,
721 figfile=figfile,
547 save=save,
722 save=save,
548 ftp=ftp,
723 ftp=ftp,
549 wr_period=wr_period,
724 wr_period=wr_period,
550 thisDatetime=thisDatetime,
725 thisDatetime=thisDatetime,
551 update_figfile=update_figfile)
726 update_figfile=update_figfile)
552
727
553 if dataOut.ltctime >= self.xmax:
728 if dataOut.ltctime >= self.xmax:
554 self.isConfigmagwr = wr_period
729 self.isConfigmagwr = wr_period
555 self.isConfig = False
730 self.isConfig = False
556 update_figfile = True
731 update_figfile = True
557 axes.__firsttime = True
732 axes.__firsttime = True
558 self.xmin += self.timerange
733 self.xmin += self.timerange
559 self.xmax += self.timerange
734 self.xmax += self.timerange
560
735
561
736
562
737
563
738
564 class WindProfilerPlot_(Figure):
739 class WindProfilerPlot_(Figure):
565
740
566 __isConfig = None
741 __isConfig = None
567 __nsubplots = None
742 __nsubplots = None
568
743
569 WIDTHPROF = None
744 WIDTHPROF = None
570 HEIGHTPROF = None
745 HEIGHTPROF = None
571 PREFIX = 'wind'
746 PREFIX = 'wind'
572
747
573 def __init__(self, **kwargs):
748 def __init__(self, **kwargs):
574 Figure.__init__(self, **kwargs)
749 Figure.__init__(self, **kwargs)
575 self.timerange = None
750 self.timerange = None
576 self.isConfig = False
751 self.isConfig = False
577 self.__nsubplots = 1
752 self.__nsubplots = 1
578
753
579 self.WIDTH = 800
754 self.WIDTH = 800
580 self.HEIGHT = 300
755 self.HEIGHT = 300
581 self.WIDTHPROF = 120
756 self.WIDTHPROF = 120
582 self.HEIGHTPROF = 0
757 self.HEIGHTPROF = 0
583 self.counter_imagwr = 0
758 self.counter_imagwr = 0
584
759
585 self.PLOT_CODE = WIND_CODE
760 self.PLOT_CODE = WIND_CODE
586
761
587 self.FTP_WEI = None
762 self.FTP_WEI = None
588 self.EXP_CODE = None
763 self.EXP_CODE = None
589 self.SUB_EXP_CODE = None
764 self.SUB_EXP_CODE = None
590 self.PLOT_POS = None
765 self.PLOT_POS = None
591 self.tmin = None
766 self.tmin = None
592 self.tmax = None
767 self.tmax = None
593
768
594 self.xmin = None
769 self.xmin = None
595 self.xmax = None
770 self.xmax = None
596
771
597 self.figfile = None
772 self.figfile = None
598
773
599 def getSubplots(self):
774 def getSubplots(self):
600
775
601 ncol = 1
776 ncol = 1
602 nrow = self.nplots
777 nrow = self.nplots
603
778
604 return nrow, ncol
779 return nrow, ncol
605
780
606 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
781 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
607
782
608 self.__showprofile = showprofile
783 self.__showprofile = showprofile
609 self.nplots = nplots
784 self.nplots = nplots
610
785
611 ncolspan = 1
786 ncolspan = 1
612 colspan = 1
787 colspan = 1
613
788
614 self.createFigure(id = id,
789 self.createFigure(id = id,
615 wintitle = wintitle,
790 wintitle = wintitle,
616 widthplot = self.WIDTH + self.WIDTHPROF,
791 widthplot = self.WIDTH + self.WIDTHPROF,
617 heightplot = self.HEIGHT + self.HEIGHTPROF,
792 heightplot = self.HEIGHT + self.HEIGHTPROF,
618 show=show)
793 show=show)
619
794
620 nrow, ncol = self.getSubplots()
795 nrow, ncol = self.getSubplots()
621
796
622 counter = 0
797 counter = 0
623 for y in range(nrow):
798 for y in range(nrow):
624 if counter >= self.nplots:
799 if counter >= self.nplots:
625 break
800 break
626
801
627 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
802 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
628 counter += 1
803 counter += 1
629
804
630 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
805 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
631 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
806 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
632 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
807 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
633 timerange=None, SNRthresh = None,
808 timerange=None, SNRthresh = None,
634 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
809 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
635 server=None, folder=None, username=None, password=None,
810 server=None, folder=None, username=None, password=None,
636 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
811 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
637 """
812 """
638
813
639 Input:
814 Input:
640 dataOut :
815 dataOut :
641 id :
816 id :
642 wintitle :
817 wintitle :
643 channelList :
818 channelList :
644 showProfile :
819 showProfile :
645 xmin : None,
820 xmin : None,
646 xmax : None,
821 xmax : None,
647 ymin : None,
822 ymin : None,
648 ymax : None,
823 ymax : None,
649 zmin : None,
824 zmin : None,
650 zmax : None
825 zmax : None
651 """
826 """
652
827
653 # if timerange is not None:
828 # if timerange is not None:
654 # self.timerange = timerange
829 # self.timerange = timerange
655 #
830 #
656 # tmin = None
831 # tmin = None
657 # tmax = None
832 # tmax = None
658
833
659 x = dataOut.getTimeRange1(dataOut.paramInterval)
834 x = dataOut.getTimeRange1(dataOut.paramInterval)
660 y = dataOut.heightList
835 y = dataOut.heightList
661 z = dataOut.data_output.copy()
836 z = dataOut.data_output.copy()
662 nplots = z.shape[0] #Number of wind dimensions estimated
837 nplots = z.shape[0] #Number of wind dimensions estimated
663 nplotsw = nplots
838 nplotsw = nplots
664
839
665
840
666 #If there is a SNR function defined
841 #If there is a SNR function defined
667 if dataOut.data_SNR is not None:
842 if dataOut.data_SNR is not None:
668 nplots += 1
843 nplots += 1
669 SNR = dataOut.data_SNR
844 SNR = dataOut.data_SNR[0]
670 SNRavg = numpy.average(SNR, axis=0)
845 SNRavg = SNR#numpy.average(SNR, axis=0)
671
846
672 SNRdB = 10*numpy.log10(SNR)
847 SNRdB = 10*numpy.log10(SNR)
673 SNRavgdB = 10*numpy.log10(SNRavg)
848 SNRavgdB = 10*numpy.log10(SNRavg)
674
849
675 if SNRthresh == None: SNRthresh = -5.0
850 if SNRthresh == None:
851 SNRthresh = -5.0
676 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
852 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
677
853
678 for i in range(nplotsw):
854 for i in range(nplotsw):
679 z[i,ind] = numpy.nan
855 z[i,ind] = numpy.nan
680
856
681 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
857 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
682 #thisDatetime = datetime.datetime.now()
858 #thisDatetime = datetime.datetime.now()
683 title = wintitle + "Wind"
859 title = wintitle + "Wind"
684 xlabel = ""
860 xlabel = ""
685 ylabel = "Height (km)"
861 ylabel = "Height (km)"
686 update_figfile = False
862 update_figfile = False
687
863
688 if not self.isConfig:
864 if not self.isConfig:
689
865
690 self.setup(id=id,
866 self.setup(id=id,
691 nplots=nplots,
867 nplots=nplots,
692 wintitle=wintitle,
868 wintitle=wintitle,
693 showprofile=showprofile,
869 showprofile=showprofile,
694 show=show)
870 show=show)
695
871
696 if timerange is not None:
872 if timerange is not None:
697 self.timerange = timerange
873 self.timerange = timerange
698
874
699 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
875 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
700
876
701 if ymin == None: ymin = numpy.nanmin(y)
877 if ymin == None: ymin = numpy.nanmin(y)
702 if ymax == None: ymax = numpy.nanmax(y)
878 if ymax == None: ymax = numpy.nanmax(y)
703
879
704 if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:]))
880 if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:]))
705 #if numpy.isnan(zmax): zmax = 50
881 #if numpy.isnan(zmax): zmax = 50
706 if zmin == None: zmin = -zmax
882 if zmin == None: zmin = -zmax
707
883
708 if nplotsw == 3:
884 if nplotsw == 3:
709 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
885 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
710 if zmin_ver == None: zmin_ver = -zmax_ver
886 if zmin_ver == None: zmin_ver = -zmax_ver
711
887
712 if dataOut.data_SNR is not None:
888 if dataOut.data_SNR is not None:
713 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
889 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
714 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
890 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
715
891
716
892
717 self.FTP_WEI = ftp_wei
893 self.FTP_WEI = ftp_wei
718 self.EXP_CODE = exp_code
894 self.EXP_CODE = exp_code
719 self.SUB_EXP_CODE = sub_exp_code
895 self.SUB_EXP_CODE = sub_exp_code
720 self.PLOT_POS = plot_pos
896 self.PLOT_POS = plot_pos
721
897
722 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
898 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
723 self.isConfig = True
899 self.isConfig = True
724 self.figfile = figfile
900 self.figfile = figfile
725 update_figfile = True
901 update_figfile = True
726
902
727 self.setWinTitle(title)
903 self.setWinTitle(title)
728
904
729 if ((self.xmax - x[1]) < (x[1]-x[0])):
905 if ((self.xmax - x[1]) < (x[1]-x[0])):
730 x[1] = self.xmax
906 x[1] = self.xmax
731
907
732 strWind = ['Zonal', 'Meridional', 'Vertical']
908 strWind = ['Zonal', 'Meridional', 'Vertical']
733 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
909 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
734 zmaxVector = [zmax, zmax, zmax_ver]
910 zmaxVector = [zmax, zmax, zmax_ver]
735 zminVector = [zmin, zmin, zmin_ver]
911 zminVector = [zmin, zmin, zmin_ver]
736 windFactor = [1,1,100]
912 windFactor = [1,1,100]
737
913
738 for i in range(nplotsw):
914 for i in range(nplotsw):
739
915
740 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
916 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
741 axes = self.axesList[i*self.__nsubplots]
917 axes = self.axesList[i*self.__nsubplots]
742
918
743 z1 = z[i,:].reshape((1,-1))*windFactor[i]
919 z1 = z[i,:].reshape((1,-1))*windFactor[i]
744 #z1=numpy.ma.masked_where(z1==0.,z1)
920
745
746 axes.pcolorbuffer(x, y, z1,
921 axes.pcolorbuffer(x, y, z1,
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
922 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
923 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
749 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
924 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
750
925
751 if dataOut.data_SNR is not None:
926 if dataOut.data_SNR is not None:
752 i += 1
927 i += 1
753 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
928 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
754 axes = self.axesList[i*self.__nsubplots]
929 axes = self.axesList[i*self.__nsubplots]
755 SNRavgdB = SNRavgdB.reshape((1,-1))
930 SNRavgdB = SNRavgdB.reshape((1,-1))
756 axes.pcolorbuffer(x, y, SNRavgdB,
931 axes.pcolorbuffer(x, y, SNRavgdB,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
932 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
933 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
759 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
934 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
760
935
761 self.draw()
936 self.draw()
762
937
763 self.save(figpath=figpath,
938 self.save(figpath=figpath,
764 figfile=figfile,
939 figfile=figfile,
765 save=save,
940 save=save,
766 ftp=ftp,
941 ftp=ftp,
767 wr_period=wr_period,
942 wr_period=wr_period,
768 thisDatetime=thisDatetime,
943 thisDatetime=thisDatetime,
769 update_figfile=update_figfile)
944 update_figfile=update_figfile)
770
945
771 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
946 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
772 self.counter_imagwr = wr_period
947 self.counter_imagwr = wr_period
773 self.isConfig = False
948 self.isConfig = False
774 update_figfile = True
949 update_figfile = True
775
950
776 @MPDecorator
951 @MPDecorator
777 class ParametersPlot_(Figure):
952 class ParametersPlot_(Figure):
778
953
779 __isConfig = None
954 __isConfig = None
780 __nsubplots = None
955 __nsubplots = None
781
956
782 WIDTHPROF = None
957 WIDTHPROF = None
783 HEIGHTPROF = None
958 HEIGHTPROF = None
784 PREFIX = 'param'
959 PREFIX = 'param'
785
960
786 nplots = None
961 nplots = None
787 nchan = None
962 nchan = None
788
963
789 def __init__(self):#, **kwargs):
964 def __init__(self):#, **kwargs):
790 Figure.__init__(self)#, **kwargs)
965 Figure.__init__(self)#, **kwargs)
791 self.timerange = None
966 self.timerange = None
792 self.isConfig = False
967 self.isConfig = False
793 self.__nsubplots = 1
968 self.__nsubplots = 1
794
969
795 self.WIDTH = 800
970 self.WIDTH = 300
796 self.HEIGHT = 180
971 self.HEIGHT = 550
797 self.WIDTHPROF = 120
972 self.WIDTHPROF = 120
798 self.HEIGHTPROF = 0
973 self.HEIGHTPROF = 0
799 self.counter_imagwr = 0
974 self.counter_imagwr = 0
800
975
801 self.PLOT_CODE = RTI_CODE
976 self.PLOT_CODE = RTI_CODE
802
977
803 self.FTP_WEI = None
978 self.FTP_WEI = None
804 self.EXP_CODE = None
979 self.EXP_CODE = None
805 self.SUB_EXP_CODE = None
980 self.SUB_EXP_CODE = None
806 self.PLOT_POS = None
981 self.PLOT_POS = None
807 self.tmin = None
982 self.tmin = None
808 self.tmax = None
983 self.tmax = None
809
984
810 self.xmin = None
985 self.xmin = None
811 self.xmax = None
986 self.xmax = None
812
987
813 self.figfile = None
988 self.figfile = None
814
989
815 def getSubplots(self):
990 def getSubplots(self):
816
991
817 ncol = 1
992 ncol = 1
818 nrow = self.nplots
993 nrow = self.nplots
819
994
820 return nrow, ncol
995 return nrow, ncol
821
996
822 def setup(self, id, nplots, wintitle, show=True):
997 def setup(self, id, nplots, wintitle, show=True):
823
998
824 self.nplots = nplots
999 self.nplots = nplots
825
1000
826 ncolspan = 1
1001 ncolspan = 1
827 colspan = 1
1002 colspan = 1
828
1003
829 self.createFigure(id = id,
1004 self.createFigure(id = id,
830 wintitle = wintitle,
1005 wintitle = wintitle,
831 widthplot = self.WIDTH + self.WIDTHPROF,
1006 widthplot = self.WIDTH + self.WIDTHPROF,
832 heightplot = self.HEIGHT + self.HEIGHTPROF,
1007 heightplot = self.HEIGHT + self.HEIGHTPROF,
833 show=show)
1008 show=show)
834
1009
835 nrow, ncol = self.getSubplots()
1010 nrow, ncol = self.getSubplots()
836
1011
837 counter = 0
1012 counter = 0
838 for y in range(nrow):
1013 for y in range(nrow):
839 for x in range(ncol):
1014 for x in range(ncol):
840
1015
841 if counter >= self.nplots:
1016 if counter >= self.nplots:
842 break
1017 break
843
1018
844 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1019 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
845
1020
846 counter += 1
1021 counter += 1
847
1022
848 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
1023 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
849 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
1024 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
850 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
1025 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
851 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1026 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
852 server=None, folder=None, username=None, password=None,
1027 server=None, folder=None, username=None, password=None,
853 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
1028 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
854 """
1029 """
855
1030
856 Input:
1031 Input:
857 dataOut :
1032 dataOut :
858 id :
1033 id :
859 wintitle :
1034 wintitle :
860 channelList :
1035 channelList :
861 showProfile :
1036 showProfile :
862 xmin : None,
1037 xmin : None,
863 xmax : None,
1038 xmax : None,
864 ymin : None,
1039 ymin : None,
865 ymax : None,
1040 ymax : None,
866 zmin : None,
1041 zmin : None,
867 zmax : None
1042 zmax : None
868 """
1043 """
869 if dataOut.flagNoData:
1044 if dataOut.flagNoData:
870 return dataOut
1045 return dataOut
871
1046
872
1047
873 if HEIGHT is not None:
1048 if HEIGHT is not None:
874 self.HEIGHT = HEIGHT
1049 self.HEIGHT = HEIGHT
875
1050
876
1051
877 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1052 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
878 return
1053 return
879
1054
880 if channelList == None:
1055 if channelList == None:
881 channelIndexList = list(range(dataOut.data_param.shape[0]))
1056 channelIndexList = list(range(dataOut.data_param.shape[0]))
882 else:
1057 else:
883 channelIndexList = []
1058 channelIndexList = []
884 for channel in channelList:
1059 for channel in channelList:
885 if channel not in dataOut.channelList:
1060 if channel not in dataOut.channelList:
886 raise ValueError("Channel %d is not in dataOut.channelList")
1061 raise ValueError("Channel %d is not in dataOut.channelList")
887 channelIndexList.append(dataOut.channelList.index(channel))
1062 channelIndexList.append(dataOut.channelList.index(channel))
888
1063
889 x = dataOut.getTimeRange1(dataOut.paramInterval)
1064 x = dataOut.getTimeRange1(dataOut.paramInterval)
890 y = dataOut.getHeiRange()
1065 y = dataOut.getHeiRange()
891
1066
892 if dataOut.data_param.ndim == 3:
1067 if dataOut.data_param.ndim == 3:
893 z = dataOut.data_param[channelIndexList,paramIndex,:]
1068 z = dataOut.data_param[channelIndexList,paramIndex,:]
894 else:
1069 else:
895 z = dataOut.data_param[channelIndexList,:]
1070 z = dataOut.data_param[channelIndexList,:]
896
1071
897 if showSNR:
1072 if showSNR:
898 #SNR data
1073 #SNR data
899 SNRarray = dataOut.data_SNR[channelIndexList,:]
1074 SNRarray = dataOut.data_SNR[channelIndexList,:]
900 SNRdB = 10*numpy.log10(SNRarray)
1075 SNRdB = 10*numpy.log10(SNRarray)
901 ind = numpy.where(SNRdB < SNRthresh)
1076 ind = numpy.where(SNRdB < SNRthresh)
902 z[ind] = numpy.nan
1077 z[ind] = numpy.nan
903
1078
904 thisDatetime = dataOut.datatime
1079 thisDatetime = dataOut.datatime
905 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1080 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
906 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1081 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
907 xlabel = ""
1082 xlabel = ""
908 ylabel = "Range (Km)"
1083 ylabel = "Range (km)"
909
1084
910 update_figfile = False
1085 update_figfile = False
911
1086
912 if not self.isConfig:
1087 if not self.isConfig:
913
1088
914 nchan = len(channelIndexList)
1089 nchan = len(channelIndexList)
915 self.nchan = nchan
1090 self.nchan = nchan
916 self.plotFact = 1
1091 self.plotFact = 1
917 nplots = nchan
1092 nplots = nchan
918
1093
919 if showSNR:
1094 if showSNR:
920 nplots = nchan*2
1095 nplots = nchan*2
921 self.plotFact = 2
1096 self.plotFact = 2
922 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1097 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
923 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1098 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
924
1099
925 self.setup(id=id,
1100 self.setup(id=id,
926 nplots=nplots,
1101 nplots=nplots,
927 wintitle=wintitle,
1102 wintitle=wintitle,
928 show=show)
1103 show=show)
929
1104
930 if timerange != None:
1105 if timerange != None:
931 self.timerange = timerange
1106 self.timerange = timerange
932
1107
933 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1108 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
934
1109
935 if ymin == None: ymin = numpy.nanmin(y)
1110 if ymin == None: ymin = numpy.nanmin(y)
936 if ymax == None: ymax = numpy.nanmax(y)
1111 if ymax == None: ymax = numpy.nanmax(y)
937 if zmin == None: zmin = numpy.nanmin(z)
1112 if zmin == None: zmin = numpy.nanmin(z)
938 if zmax == None: zmax = numpy.nanmax(z)
1113 if zmax == None: zmax = numpy.nanmax(z)
939
1114
940 self.FTP_WEI = ftp_wei
1115 self.FTP_WEI = ftp_wei
941 self.EXP_CODE = exp_code
1116 self.EXP_CODE = exp_code
942 self.SUB_EXP_CODE = sub_exp_code
1117 self.SUB_EXP_CODE = sub_exp_code
943 self.PLOT_POS = plot_pos
1118 self.PLOT_POS = plot_pos
944
1119
945 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1120 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
946 self.isConfig = True
1121 self.isConfig = True
947 self.figfile = figfile
1122 self.figfile = figfile
948 update_figfile = True
1123 update_figfile = True
949
1124
950 self.setWinTitle(title)
1125 self.setWinTitle(title)
951
1126
952 for i in range(self.nchan):
1127 # for i in range(self.nchan):
953 index = channelIndexList[i]
1128 # index = channelIndexList[i]
954 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1129 # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
955 axes = self.axesList[i*self.plotFact]
1130 # axes = self.axesList[i*self.plotFact]
956 z1 = z[i,:].reshape((1,-1))
1131 # z1 = z[i,:].reshape((1,-1))
957 axes.pcolorbuffer(x, y, z1,
1132 # axes.pcolorbuffer(x, y, z1,
958 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1133 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
959 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1134 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
960 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1135 # ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
961
1136 #
962 if showSNR:
1137 # if showSNR:
963 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1138 # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
964 axes = self.axesList[i*self.plotFact + 1]
1139 # axes = self.axesList[i*self.plotFact + 1]
965 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1140 # SNRdB1 = SNRdB[i,:].reshape((1,-1))
966 axes.pcolorbuffer(x, y, SNRdB1,
1141 # axes.pcolorbuffer(x, y, SNRdB1,
967 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1142 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
968 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1143 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
969 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1144 # ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1145
1146 i=0
1147 index = channelIndexList[i]
1148 title = "Factor de reflectividad Z [dBZ]"
1149 axes = self.axesList[i*self.plotFact]
1150 z1 = z[i,:].reshape((1,-1))
1151 axes.pcolorbuffer(x, y, z1,
1152 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1153 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1154 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1155
1156 if showSNR:
1157 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1158 axes = self.axesList[i*self.plotFact + 1]
1159 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1160 axes.pcolorbuffer(x, y, SNRdB1,
1161 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1162 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1163 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1164
1165 i=1
1166 index = channelIndexList[i]
1167 title = "Velocidad vertical Doppler [m/s]"
1168 axes = self.axesList[i*self.plotFact]
1169 z1 = z[i,:].reshape((1,-1))
1170 axes.pcolorbuffer(x, y, z1,
1171 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-10, zmax=10,
1172 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1173 ticksize=9, cblabel='', cbsize="1%",colormap='seismic_r')
1174
1175 if showSNR:
1176 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1177 axes = self.axesList[i*self.plotFact + 1]
1178 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1179 axes.pcolorbuffer(x, y, SNRdB1,
1180 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1181 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1182 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1183
1184 i=2
1185 index = channelIndexList[i]
1186 title = "Intensidad de lluvia [mm/h]"
1187 axes = self.axesList[i*self.plotFact]
1188 z1 = z[i,:].reshape((1,-1))
1189 axes.pcolorbuffer(x, y, z1,
1190 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=40,
1191 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1192 ticksize=9, cblabel='', cbsize="1%",colormap='ocean_r')
1193
1194 if showSNR:
1195 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1196 axes = self.axesList[i*self.plotFact + 1]
1197 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1198 axes.pcolorbuffer(x, y, SNRdB1,
1199 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1200 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1201 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
970
1202
971
1203
972 self.draw()
1204 self.draw()
973
1205
974 if dataOut.ltctime >= self.xmax:
1206 if dataOut.ltctime >= self.xmax:
975 self.counter_imagwr = wr_period
1207 self.counter_imagwr = wr_period
976 self.isConfig = False
1208 self.isConfig = False
977 update_figfile = True
1209 update_figfile = True
978
1210
979 self.save(figpath=figpath,
1211 self.save(figpath=figpath,
980 figfile=figfile,
1212 figfile=figfile,
981 save=save,
1213 save=save,
982 ftp=ftp,
1214 ftp=ftp,
983 wr_period=wr_period,
1215 wr_period=wr_period,
984 thisDatetime=thisDatetime,
1216 thisDatetime=thisDatetime,
985 update_figfile=update_figfile)
1217 update_figfile=update_figfile)
986
1218
987 return dataOut
1219 return dataOut
988 @MPDecorator
1220 @MPDecorator
989 class Parameters1Plot_(Figure):
1221 class Parameters1Plot_(Figure):
990
1222
991 __isConfig = None
1223 __isConfig = None
992 __nsubplots = None
1224 __nsubplots = None
993
1225
994 WIDTHPROF = None
1226 WIDTHPROF = None
995 HEIGHTPROF = None
1227 HEIGHTPROF = None
996 PREFIX = 'prm'
1228 PREFIX = 'prm'
997
1229
998 def __init__(self):
1230 def __init__(self):
999 Figure.__init__(self)
1231 Figure.__init__(self)
1000 self.timerange = 2*60*60
1232 self.timerange = 2*60*60
1001 self.isConfig = False
1233 self.isConfig = False
1002 self.__nsubplots = 1
1234 self.__nsubplots = 1
1003
1235
1004 self.WIDTH = 800
1236 self.WIDTH = 800
1005 self.HEIGHT = 180
1237 self.HEIGHT = 180
1006 self.WIDTHPROF = 120
1238 self.WIDTHPROF = 120
1007 self.HEIGHTPROF = 0
1239 self.HEIGHTPROF = 0
1008 self.counter_imagwr = 0
1240 self.counter_imagwr = 0
1009
1241
1010 self.PLOT_CODE = PARMS_CODE
1242 self.PLOT_CODE = PARMS_CODE
1011
1243
1012 self.FTP_WEI = None
1244 self.FTP_WEI = None
1013 self.EXP_CODE = None
1245 self.EXP_CODE = None
1014 self.SUB_EXP_CODE = None
1246 self.SUB_EXP_CODE = None
1015 self.PLOT_POS = None
1247 self.PLOT_POS = None
1016 self.tmin = None
1248 self.tmin = None
1017 self.tmax = None
1249 self.tmax = None
1018
1250
1019 self.xmin = None
1251 self.xmin = None
1020 self.xmax = None
1252 self.xmax = None
1021
1253
1022 self.figfile = None
1254 self.figfile = None
1023
1255
1024 def getSubplots(self):
1256 def getSubplots(self):
1025
1257
1026 ncol = 1
1258 ncol = 1
1027 nrow = self.nplots
1259 nrow = self.nplots
1028
1260
1029 return nrow, ncol
1261 return nrow, ncol
1030
1262
1031 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1263 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1032
1264
1033 self.__showprofile = showprofile
1265 self.__showprofile = showprofile
1034 self.nplots = nplots
1266 self.nplots = nplots
1035
1267
1036 ncolspan = 1
1268 ncolspan = 1
1037 colspan = 1
1269 colspan = 1
1038
1270
1039 self.createFigure(id = id,
1271 self.createFigure(id = id,
1040 wintitle = wintitle,
1272 wintitle = wintitle,
1041 widthplot = self.WIDTH + self.WIDTHPROF,
1273 widthplot = self.WIDTH + self.WIDTHPROF,
1042 heightplot = self.HEIGHT + self.HEIGHTPROF,
1274 heightplot = self.HEIGHT + self.HEIGHTPROF,
1043 show=show)
1275 show=show)
1044
1276
1045 nrow, ncol = self.getSubplots()
1277 nrow, ncol = self.getSubplots()
1046
1278
1047 counter = 0
1279 counter = 0
1048 for y in range(nrow):
1280 for y in range(nrow):
1049 for x in range(ncol):
1281 for x in range(ncol):
1050
1282
1051 if counter >= self.nplots:
1283 if counter >= self.nplots:
1052 break
1284 break
1053
1285
1054 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1286 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1055
1287
1056 if showprofile:
1288 if showprofile:
1057 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1289 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1058
1290
1059 counter += 1
1291 counter += 1
1060
1292
1061 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1293 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1062 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1294 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1063 parameterIndex = None, onlyPositive = False,
1295 parameterIndex = None, onlyPositive = False,
1064 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1296 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1065 DOP = True,
1297 DOP = True,
1066 zlabel = "", parameterName = "", parameterObject = "data_param",
1298 zlabel = "", parameterName = "", parameterObject = "data_param",
1067 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1299 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1068 server=None, folder=None, username=None, password=None,
1300 server=None, folder=None, username=None, password=None,
1069 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1301 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1070 #print inspect.getargspec(self.run).args
1071 """
1072
1302
1303 """
1073 Input:
1304 Input:
1074 dataOut :
1305 dataOut :
1075 id :
1306 id :
1076 wintitle :
1307 wintitle :
1077 channelList :
1308 channelList :
1078 showProfile :
1309 showProfile :
1079 xmin : None,
1310 xmin : None,
1080 xmax : None,
1311 xmax : None,
1081 ymin : None,
1312 ymin : None,
1082 ymax : None,
1313 ymax : None,
1083 zmin : None,
1314 zmin : None,
1084 zmax : None
1315 zmax : None
1085 """
1316 """
1086 if dataOut.flagNoData:
1317 if dataOut.flagNoData:
1087 return dataOut
1318 return dataOut
1088
1319
1089 data_param = getattr(dataOut, parameterObject)
1320 data_param = getattr(dataOut, parameterObject)
1090
1321
1091 if channelList == None:
1322 if channelList == None:
1092 channelIndexList = numpy.arange(data_param.shape[0])
1323 channelIndexList = numpy.arange(data_param.shape[0])
1093 else:
1324 else:
1094 channelIndexList = numpy.array(channelList)
1325 channelIndexList = numpy.array(channelList)
1095
1326
1096 nchan = len(channelIndexList) #Number of channels being plotted
1327 nchan = len(channelIndexList) #Number of channels being plotted
1097
1328
1098 if nchan < 1:
1329 if nchan < 1:
1099 return
1330 return
1100
1331
1101 nGraphsByChannel = 0
1332 nGraphsByChannel = 0
1102
1333
1103 if SNR:
1334 if SNR:
1104 nGraphsByChannel += 1
1335 nGraphsByChannel += 1
1105 if DOP:
1336 if DOP:
1106 nGraphsByChannel += 1
1337 nGraphsByChannel += 1
1107
1338
1108 if nGraphsByChannel < 1:
1339 if nGraphsByChannel < 1:
1109 return
1340 return
1110
1341
1111 nplots = nGraphsByChannel*nchan
1342 nplots = nGraphsByChannel*nchan
1112
1343
1113 if timerange is not None:
1344 if timerange is not None:
1114 self.timerange = timerange
1345 self.timerange = timerange
1115
1346
1116 #tmin = None
1347 #tmin = None
1117 #tmax = None
1348 #tmax = None
1118 if parameterIndex == None:
1349 if parameterIndex == None:
1119 parameterIndex = 1
1350 parameterIndex = 1
1120
1351
1121 x = dataOut.getTimeRange1(dataOut.paramInterval)
1352 x = dataOut.getTimeRange1(dataOut.paramInterval)
1122 y = dataOut.heightList
1353 y = dataOut.heightList
1123
1354
1124 if dataOut.data_param.ndim == 3:
1355 if dataOut.data_param.ndim == 3:
1125 z = dataOut.data_param[channelIndexList,parameterIndex,:]
1356 z = dataOut.data_param[channelIndexList,parameterIndex,:]
1126 else:
1357 else:
1127 z = dataOut.data_param[channelIndexList,:]
1358 z = dataOut.data_param[channelIndexList,:]
1128
1359
1129 if dataOut.data_SNR is not None:
1360 if dataOut.data_SNR is not None:
1130 if dataOut.data_SNR.ndim == 2:
1361 if dataOut.data_SNR.ndim == 2:
1131 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
1362 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
1132 else:
1363 else:
1133 SNRavg = dataOut.data_SNR
1364 SNRavg = dataOut.data_SNR
1134 SNRdB = 10*numpy.log10(SNRavg)
1365 SNRdB = 10*numpy.log10(SNRavg)
1135
1366
1136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1367 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1137 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1368 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1138 xlabel = ""
1369 xlabel = ""
1139 ylabel = "Range (Km)"
1370 ylabel = "Range (Km)"
1140
1371
1141 if onlyPositive:
1372 if onlyPositive:
1142 colormap = "jet"
1373 colormap = "jet"
1143 zmin = 0
1374 zmin = 0
1144 else: colormap = "RdBu_r"
1375 else: colormap = "RdBu_r"
1145
1376
1146 if not self.isConfig:
1377 if not self.isConfig:
1147
1378
1148 self.setup(id=id,
1379 self.setup(id=id,
1149 nplots=nplots,
1380 nplots=nplots,
1150 wintitle=wintitle,
1381 wintitle=wintitle,
1151 showprofile=showprofile,
1382 showprofile=showprofile,
1152 show=show)
1383 show=show)
1153
1384
1154 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1385 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1155
1386
1156 if ymin == None: ymin = numpy.nanmin(y)
1387 if ymin == None: ymin = numpy.nanmin(y)
1157 if ymax == None: ymax = numpy.nanmax(y)
1388 if ymax == None: ymax = numpy.nanmax(y)
1158 if zmin == None: zmin = numpy.nanmin(z)
1389 if zmin == None: zmin = numpy.nanmin(z)
1159 if zmax == None: zmax = numpy.nanmax(z)
1390 if zmax == None: zmax = numpy.nanmax(z)
1160
1391
1161 if SNR:
1392 if SNR:
1162 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1393 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1163 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1394 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1164
1395
1165 self.FTP_WEI = ftp_wei
1396 self.FTP_WEI = ftp_wei
1166 self.EXP_CODE = exp_code
1397 self.EXP_CODE = exp_code
1167 self.SUB_EXP_CODE = sub_exp_code
1398 self.SUB_EXP_CODE = sub_exp_code
1168 self.PLOT_POS = plot_pos
1399 self.PLOT_POS = plot_pos
1169
1400
1170 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1401 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1171 self.isConfig = True
1402 self.isConfig = True
1172 self.figfile = figfile
1403 self.figfile = figfile
1173
1404
1174 self.setWinTitle(title)
1405 self.setWinTitle(title)
1175
1406
1176 if ((self.xmax - x[1]) < (x[1]-x[0])):
1407 if ((self.xmax - x[1]) < (x[1]-x[0])):
1177 x[1] = self.xmax
1408 x[1] = self.xmax
1178
1409
1179 for i in range(nchan):
1410 for i in range(nchan):
1180
1411
1181 if (SNR and not onlySNR): j = 2*i
1412 if (SNR and not onlySNR): j = 2*i
1182 else: j = i
1413 else: j = i
1183
1414
1184 j = nGraphsByChannel*i
1415 j = nGraphsByChannel*i
1185
1416
1186 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1417 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1187 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1418 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1188
1419
1189 if not onlySNR:
1420 if not onlySNR:
1190 axes = self.axesList[j*self.__nsubplots]
1421 axes = self.axesList[j*self.__nsubplots]
1191 z1 = z[i,:].reshape((1,-1))
1422 z1 = z[i,:].reshape((1,-1))
1192 axes.pcolorbuffer(x, y, z1,
1423 axes.pcolorbuffer(x, y, z1,
1193 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1424 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1194 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1425 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1195 ticksize=9, cblabel=zlabel, cbsize="1%")
1426 ticksize=9, cblabel=zlabel, cbsize="1%")
1196
1427
1197 if DOP:
1428 if DOP:
1198 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1429 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1199
1430
1200 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1431 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1201 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1432 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1202 axes = self.axesList[j]
1433 axes = self.axesList[j]
1203 z1 = z[i,:].reshape((1,-1))
1434 z1 = z[i,:].reshape((1,-1))
1204 axes.pcolorbuffer(x, y, z1,
1435 axes.pcolorbuffer(x, y, z1,
1205 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1436 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1206 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1437 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1207 ticksize=9, cblabel=zlabel, cbsize="1%")
1438 ticksize=9, cblabel=zlabel, cbsize="1%")
1208
1439
1209 if SNR:
1440 if SNR:
1210 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1441 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1211 axes = self.axesList[(j)*self.__nsubplots]
1442 axes = self.axesList[(j)*self.__nsubplots]
1212 if not onlySNR:
1443 if not onlySNR:
1213 axes = self.axesList[(j + 1)*self.__nsubplots]
1444 axes = self.axesList[(j + 1)*self.__nsubplots]
1214
1445
1215 axes = self.axesList[(j + nGraphsByChannel-1)]
1446 axes = self.axesList[(j + nGraphsByChannel-1)]
1216 z1 = SNRdB.reshape((1,-1))
1447 z1 = SNRdB.reshape((1,-1))
1217 axes.pcolorbuffer(x, y, z1,
1448 axes.pcolorbuffer(x, y, z1,
1218 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1449 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1219 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1450 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1220 ticksize=9, cblabel=zlabel, cbsize="1%")
1451 ticksize=9, cblabel=zlabel, cbsize="1%")
1221
1452
1222
1453
1223
1454
1224 self.draw()
1455 self.draw()
1225
1456
1226 if x[1] >= self.axesList[0].xmax:
1457 if x[1] >= self.axesList[0].xmax:
1227 self.counter_imagwr = wr_period
1458 self.counter_imagwr = wr_period
1228 self.isConfig = False
1459 self.isConfig = False
1229 self.figfile = None
1460 self.figfile = None
1230
1461
1231 self.save(figpath=figpath,
1462 self.save(figpath=figpath,
1232 figfile=figfile,
1463 figfile=figfile,
1233 save=save,
1464 save=save,
1234 ftp=ftp,
1465 ftp=ftp,
1235 wr_period=wr_period,
1466 wr_period=wr_period,
1236 thisDatetime=thisDatetime,
1467 thisDatetime=thisDatetime,
1237 update_figfile=False)
1468 update_figfile=False)
1238 return dataOut
1469 return dataOut
1239
1470
1240 class SpectralFittingPlot_(Figure):
1471 class SpectralFittingPlot_(Figure):
1241
1472
1242 __isConfig = None
1473 __isConfig = None
1243 __nsubplots = None
1474 __nsubplots = None
1244
1475
1245 WIDTHPROF = None
1476 WIDTHPROF = None
1246 HEIGHTPROF = None
1477 HEIGHTPROF = None
1247 PREFIX = 'prm'
1478 PREFIX = 'prm'
1248
1479
1249
1480
1250 N = None
1481 N = None
1251 ippSeconds = None
1482 ippSeconds = None
1252
1483
1253 def __init__(self, **kwargs):
1484 def __init__(self, **kwargs):
1254 Figure.__init__(self, **kwargs)
1485 Figure.__init__(self, **kwargs)
1255 self.isConfig = False
1486 self.isConfig = False
1256 self.__nsubplots = 1
1487 self.__nsubplots = 1
1257
1488
1258 self.PLOT_CODE = SPECFIT_CODE
1489 self.PLOT_CODE = SPECFIT_CODE
1259
1490
1260 self.WIDTH = 450
1491 self.WIDTH = 450
1261 self.HEIGHT = 250
1492 self.HEIGHT = 250
1262 self.WIDTHPROF = 0
1493 self.WIDTHPROF = 0
1263 self.HEIGHTPROF = 0
1494 self.HEIGHTPROF = 0
1264
1495
1265 def getSubplots(self):
1496 def getSubplots(self):
1266
1497
1267 ncol = int(numpy.sqrt(self.nplots)+0.9)
1498 ncol = int(numpy.sqrt(self.nplots)+0.9)
1268 nrow = int(self.nplots*1./ncol + 0.9)
1499 nrow = int(self.nplots*1./ncol + 0.9)
1269
1500
1270 return nrow, ncol
1501 return nrow, ncol
1271
1502
1272 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1503 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1273
1504
1274 showprofile = False
1505 showprofile = False
1275 self.__showprofile = showprofile
1506 self.__showprofile = showprofile
1276 self.nplots = nplots
1507 self.nplots = nplots
1277
1508
1278 ncolspan = 5
1509 ncolspan = 5
1279 colspan = 4
1510 colspan = 4
1280 if showprofile:
1511 if showprofile:
1281 ncolspan = 5
1512 ncolspan = 5
1282 colspan = 4
1513 colspan = 4
1283 self.__nsubplots = 2
1514 self.__nsubplots = 2
1284
1515
1285 self.createFigure(id = id,
1516 self.createFigure(id = id,
1286 wintitle = wintitle,
1517 wintitle = wintitle,
1287 widthplot = self.WIDTH + self.WIDTHPROF,
1518 widthplot = self.WIDTH + self.WIDTHPROF,
1288 heightplot = self.HEIGHT + self.HEIGHTPROF,
1519 heightplot = self.HEIGHT + self.HEIGHTPROF,
1289 show=show)
1520 show=show)
1290
1521
1291 nrow, ncol = self.getSubplots()
1522 nrow, ncol = self.getSubplots()
1292
1523
1293 counter = 0
1524 counter = 0
1294 for y in range(nrow):
1525 for y in range(nrow):
1295 for x in range(ncol):
1526 for x in range(ncol):
1296
1527
1297 if counter >= self.nplots:
1528 if counter >= self.nplots:
1298 break
1529 break
1299
1530
1300 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1531 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1301
1532
1302 if showprofile:
1533 if showprofile:
1303 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1534 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1304
1535
1305 counter += 1
1536 counter += 1
1306
1537
1307 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1538 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1308 xmin=None, xmax=None, ymin=None, ymax=None,
1539 xmin=None, xmax=None, ymin=None, ymax=None,
1309 save=False, figpath='./', figfile=None, show=True):
1540 save=False, figpath='./', figfile=None, show=True):
1310
1541
1311 """
1542 """
1312
1543
1313 Input:
1544 Input:
1314 dataOut :
1545 dataOut :
1315 id :
1546 id :
1316 wintitle :
1547 wintitle :
1317 channelList :
1548 channelList :
1318 showProfile :
1549 showProfile :
1319 xmin : None,
1550 xmin : None,
1320 xmax : None,
1551 xmax : None,
1321 zmin : None,
1552 zmin : None,
1322 zmax : None
1553 zmax : None
1323 """
1554 """
1324
1555
1325 if cutHeight==None:
1556 if cutHeight==None:
1326 h=270
1557 h=270
1327 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1558 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1328 cutHeight = dataOut.heightList[heightindex]
1559 cutHeight = dataOut.heightList[heightindex]
1329
1560
1330 factor = dataOut.normFactor
1561 factor = dataOut.normFactor
1331 x = dataOut.abscissaList[:-1]
1562 x = dataOut.abscissaList[:-1]
1332 #y = dataOut.getHeiRange()
1563 #y = dataOut.getHeiRange()
1333
1564
1334 z = dataOut.data_pre[:,:,heightindex]/factor
1565 z = dataOut.data_pre[:,:,heightindex]/factor
1335 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1566 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1336 avg = numpy.average(z, axis=1)
1567 avg = numpy.average(z, axis=1)
1337 listChannels = z.shape[0]
1568 listChannels = z.shape[0]
1338
1569
1339 #Reconstruct Function
1570 #Reconstruct Function
1340 if fit==True:
1571 if fit==True:
1341 groupArray = dataOut.groupList
1572 groupArray = dataOut.groupList
1342 listChannels = groupArray.reshape((groupArray.size))
1573 listChannels = groupArray.reshape((groupArray.size))
1343 listChannels.sort()
1574 listChannels.sort()
1344 spcFitLine = numpy.zeros(z.shape)
1575 spcFitLine = numpy.zeros(z.shape)
1345 constants = dataOut.constants
1576 constants = dataOut.constants
1346
1577
1347 nGroups = groupArray.shape[0]
1578 nGroups = groupArray.shape[0]
1348 nChannels = groupArray.shape[1]
1579 nChannels = groupArray.shape[1]
1349 nProfiles = z.shape[1]
1580 nProfiles = z.shape[1]
1350
1581
1351 for f in range(nGroups):
1582 for f in range(nGroups):
1352 groupChann = groupArray[f,:]
1583 groupChann = groupArray[f,:]
1353 p = dataOut.data_param[f,:,heightindex]
1584 p = dataOut.data_param[f,:,heightindex]
1354 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1585 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1355 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1586 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1356 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1587 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1357 spcFitLine[groupChann,:] = fitLineAux
1588 spcFitLine[groupChann,:] = fitLineAux
1358 # spcFitLine = spcFitLine/factor
1589 # spcFitLine = spcFitLine/factor
1359
1590
1360 z = z[listChannels,:]
1591 z = z[listChannels,:]
1361 spcFitLine = spcFitLine[listChannels,:]
1592 spcFitLine = spcFitLine[listChannels,:]
1362 spcFitLinedB = 10*numpy.log10(spcFitLine)
1593 spcFitLinedB = 10*numpy.log10(spcFitLine)
1363
1594
1364 zdB = 10*numpy.log10(z)
1595 zdB = 10*numpy.log10(z)
1365 #thisDatetime = dataOut.datatime
1596 #thisDatetime = dataOut.datatime
1366 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1597 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1367 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1598 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1368 xlabel = "Velocity (m/s)"
1599 xlabel = "Velocity (m/s)"
1369 ylabel = "Spectrum"
1600 ylabel = "Spectrum"
1370
1601
1371 if not self.isConfig:
1602 if not self.isConfig:
1372
1603
1373 nplots = listChannels.size
1604 nplots = listChannels.size
1374
1605
1375 self.setup(id=id,
1606 self.setup(id=id,
1376 nplots=nplots,
1607 nplots=nplots,
1377 wintitle=wintitle,
1608 wintitle=wintitle,
1378 showprofile=showprofile,
1609 showprofile=showprofile,
1379 show=show)
1610 show=show)
1380
1611
1381 if xmin == None: xmin = numpy.nanmin(x)
1612 if xmin == None: xmin = numpy.nanmin(x)
1382 if xmax == None: xmax = numpy.nanmax(x)
1613 if xmax == None: xmax = numpy.nanmax(x)
1383 if ymin == None: ymin = numpy.nanmin(zdB)
1614 if ymin == None: ymin = numpy.nanmin(zdB)
1384 if ymax == None: ymax = numpy.nanmax(zdB)+2
1615 if ymax == None: ymax = numpy.nanmax(zdB)+2
1385
1616
1386 self.isConfig = True
1617 self.isConfig = True
1387
1618
1388 self.setWinTitle(title)
1619 self.setWinTitle(title)
1389 for i in range(self.nplots):
1620 for i in range(self.nplots):
1390 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1621 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1391 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1622 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1392 axes = self.axesList[i*self.__nsubplots]
1623 axes = self.axesList[i*self.__nsubplots]
1393 if fit == False:
1624 if fit == False:
1394 axes.pline(x, zdB[i,:],
1625 axes.pline(x, zdB[i,:],
1395 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1626 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1396 xlabel=xlabel, ylabel=ylabel, title=title
1627 xlabel=xlabel, ylabel=ylabel, title=title
1397 )
1628 )
1398 if fit == True:
1629 if fit == True:
1399 fitline=spcFitLinedB[i,:]
1630 fitline=spcFitLinedB[i,:]
1400 y=numpy.vstack([zdB[i,:],fitline] )
1631 y=numpy.vstack([zdB[i,:],fitline] )
1401 legendlabels=['Data','Fitting']
1632 legendlabels=['Data','Fitting']
1402 axes.pmultilineyaxis(x, y,
1633 axes.pmultilineyaxis(x, y,
1403 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1634 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1404 xlabel=xlabel, ylabel=ylabel, title=title,
1635 xlabel=xlabel, ylabel=ylabel, title=title,
1405 legendlabels=legendlabels, marker=None,
1636 legendlabels=legendlabels, marker=None,
1406 linestyle='solid', grid='both')
1637 linestyle='solid', grid='both')
1407
1638
1408 self.draw()
1639 self.draw()
1409
1640
1410 self.save(figpath=figpath,
1641 self.save(figpath=figpath,
1411 figfile=figfile,
1642 figfile=figfile,
1412 save=save,
1643 save=save,
1413 ftp=ftp,
1644 ftp=ftp,
1414 wr_period=wr_period,
1645 wr_period=wr_period,
1415 thisDatetime=thisDatetime)
1646 thisDatetime=thisDatetime)
1416
1647
1417
1648
1418 class EWDriftsPlot_(Figure):
1649 class EWDriftsPlot_(Figure):
1419
1650
1420 __isConfig = None
1651 __isConfig = None
1421 __nsubplots = None
1652 __nsubplots = None
1422
1653
1423 WIDTHPROF = None
1654 WIDTHPROF = None
1424 HEIGHTPROF = None
1655 HEIGHTPROF = None
1425 PREFIX = 'drift'
1656 PREFIX = 'drift'
1426
1657
1427 def __init__(self, **kwargs):
1658 def __init__(self, **kwargs):
1428 Figure.__init__(self, **kwargs)
1659 Figure.__init__(self, **kwargs)
1429 self.timerange = 2*60*60
1660 self.timerange = 2*60*60
1430 self.isConfig = False
1661 self.isConfig = False
1431 self.__nsubplots = 1
1662 self.__nsubplots = 1
1432
1663
1433 self.WIDTH = 800
1664 self.WIDTH = 800
1434 self.HEIGHT = 150
1665 self.HEIGHT = 150
1435 self.WIDTHPROF = 120
1666 self.WIDTHPROF = 120
1436 self.HEIGHTPROF = 0
1667 self.HEIGHTPROF = 0
1437 self.counter_imagwr = 0
1668 self.counter_imagwr = 0
1438
1669
1439 self.PLOT_CODE = EWDRIFT_CODE
1670 self.PLOT_CODE = EWDRIFT_CODE
1440
1671
1441 self.FTP_WEI = None
1672 self.FTP_WEI = None
1442 self.EXP_CODE = None
1673 self.EXP_CODE = None
1443 self.SUB_EXP_CODE = None
1674 self.SUB_EXP_CODE = None
1444 self.PLOT_POS = None
1675 self.PLOT_POS = None
1445 self.tmin = None
1676 self.tmin = None
1446 self.tmax = None
1677 self.tmax = None
1447
1678
1448 self.xmin = None
1679 self.xmin = None
1449 self.xmax = None
1680 self.xmax = None
1450
1681
1451 self.figfile = None
1682 self.figfile = None
1452
1683
1453 def getSubplots(self):
1684 def getSubplots(self):
1454
1685
1455 ncol = 1
1686 ncol = 1
1456 nrow = self.nplots
1687 nrow = self.nplots
1457
1688
1458 return nrow, ncol
1689 return nrow, ncol
1459
1690
1460 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1691 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1461
1692
1462 self.__showprofile = showprofile
1693 self.__showprofile = showprofile
1463 self.nplots = nplots
1694 self.nplots = nplots
1464
1695
1465 ncolspan = 1
1696 ncolspan = 1
1466 colspan = 1
1697 colspan = 1
1467
1698
1468 self.createFigure(id = id,
1699 self.createFigure(id = id,
1469 wintitle = wintitle,
1700 wintitle = wintitle,
1470 widthplot = self.WIDTH + self.WIDTHPROF,
1701 widthplot = self.WIDTH + self.WIDTHPROF,
1471 heightplot = self.HEIGHT + self.HEIGHTPROF,
1702 heightplot = self.HEIGHT + self.HEIGHTPROF,
1472 show=show)
1703 show=show)
1473
1704
1474 nrow, ncol = self.getSubplots()
1705 nrow, ncol = self.getSubplots()
1475
1706
1476 counter = 0
1707 counter = 0
1477 for y in range(nrow):
1708 for y in range(nrow):
1478 if counter >= self.nplots:
1709 if counter >= self.nplots:
1479 break
1710 break
1480
1711
1481 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1712 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1482 counter += 1
1713 counter += 1
1483
1714
1484 def run(self, dataOut, id, wintitle="", channelList=None,
1715 def run(self, dataOut, id, wintitle="", channelList=None,
1485 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1716 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1486 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1717 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1487 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1718 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1488 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1719 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1489 server=None, folder=None, username=None, password=None,
1720 server=None, folder=None, username=None, password=None,
1490 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1721 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1491 """
1722 """
1492
1723
1493 Input:
1724 Input:
1494 dataOut :
1725 dataOut :
1495 id :
1726 id :
1496 wintitle :
1727 wintitle :
1497 channelList :
1728 channelList :
1498 showProfile :
1729 showProfile :
1499 xmin : None,
1730 xmin : None,
1500 xmax : None,
1731 xmax : None,
1501 ymin : None,
1732 ymin : None,
1502 ymax : None,
1733 ymax : None,
1503 zmin : None,
1734 zmin : None,
1504 zmax : None
1735 zmax : None
1505 """
1736 """
1506
1737
1507 if timerange is not None:
1738 if timerange is not None:
1508 self.timerange = timerange
1739 self.timerange = timerange
1509
1740
1510 tmin = None
1741 tmin = None
1511 tmax = None
1742 tmax = None
1512
1743
1513 x = dataOut.getTimeRange1(dataOut.outputInterval)
1744 x = dataOut.getTimeRange1(dataOut.outputInterval)
1514 # y = dataOut.heightList
1745 # y = dataOut.heightList
1515 y = dataOut.heightList
1746 y = dataOut.heightList
1516
1747
1517 z = dataOut.data_output
1748 z = dataOut.data_output
1518 nplots = z.shape[0] #Number of wind dimensions estimated
1749 nplots = z.shape[0] #Number of wind dimensions estimated
1519 nplotsw = nplots
1750 nplotsw = nplots
1520
1751
1521 #If there is a SNR function defined
1752 #If there is a SNR function defined
1522 if dataOut.data_SNR is not None:
1753 if dataOut.data_SNR is not None:
1523 nplots += 1
1754 nplots += 1
1524 SNR = dataOut.data_SNR
1755 SNR = dataOut.data_SNR
1525
1756
1526 if SNR_1:
1757 if SNR_1:
1527 SNR += 1
1758 SNR += 1
1528
1759
1529 SNRavg = numpy.average(SNR, axis=0)
1760 SNRavg = numpy.average(SNR, axis=0)
1530
1761
1531 SNRdB = 10*numpy.log10(SNR)
1762 SNRdB = 10*numpy.log10(SNR)
1532 SNRavgdB = 10*numpy.log10(SNRavg)
1763 SNRavgdB = 10*numpy.log10(SNRavg)
1533
1764
1534 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1765 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1535
1766
1536 for i in range(nplotsw):
1767 for i in range(nplotsw):
1537 z[i,ind] = numpy.nan
1768 z[i,ind] = numpy.nan
1538
1769
1539
1770
1540 showprofile = False
1771 showprofile = False
1541 # thisDatetime = dataOut.datatime
1772 # thisDatetime = dataOut.datatime
1542 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1773 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1543 title = wintitle + " EW Drifts"
1774 title = wintitle + " EW Drifts"
1544 xlabel = ""
1775 xlabel = ""
1545 ylabel = "Height (Km)"
1776 ylabel = "Height (Km)"
1546
1777
1547 if not self.isConfig:
1778 if not self.isConfig:
1548
1779
1549 self.setup(id=id,
1780 self.setup(id=id,
1550 nplots=nplots,
1781 nplots=nplots,
1551 wintitle=wintitle,
1782 wintitle=wintitle,
1552 showprofile=showprofile,
1783 showprofile=showprofile,
1553 show=show)
1784 show=show)
1554
1785
1555 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1786 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1556
1787
1557 if ymin == None: ymin = numpy.nanmin(y)
1788 if ymin == None: ymin = numpy.nanmin(y)
1558 if ymax == None: ymax = numpy.nanmax(y)
1789 if ymax == None: ymax = numpy.nanmax(y)
1559
1790
1560 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1791 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1561 if zminZonal == None: zminZonal = -zmaxZonal
1792 if zminZonal == None: zminZonal = -zmaxZonal
1562 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1793 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1563 if zminVertical == None: zminVertical = -zmaxVertical
1794 if zminVertical == None: zminVertical = -zmaxVertical
1564
1795
1565 if dataOut.data_SNR is not None:
1796 if dataOut.data_SNR is not None:
1566 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1797 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1567 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1798 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1568
1799
1569 self.FTP_WEI = ftp_wei
1800 self.FTP_WEI = ftp_wei
1570 self.EXP_CODE = exp_code
1801 self.EXP_CODE = exp_code
1571 self.SUB_EXP_CODE = sub_exp_code
1802 self.SUB_EXP_CODE = sub_exp_code
1572 self.PLOT_POS = plot_pos
1803 self.PLOT_POS = plot_pos
1573
1804
1574 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1805 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1575 self.isConfig = True
1806 self.isConfig = True
1576
1807
1577
1808
1578 self.setWinTitle(title)
1809 self.setWinTitle(title)
1579
1810
1580 if ((self.xmax - x[1]) < (x[1]-x[0])):
1811 if ((self.xmax - x[1]) < (x[1]-x[0])):
1581 x[1] = self.xmax
1812 x[1] = self.xmax
1582
1813
1583 strWind = ['Zonal','Vertical']
1814 strWind = ['Zonal','Vertical']
1584 strCb = 'Velocity (m/s)'
1815 strCb = 'Velocity (m/s)'
1585 zmaxVector = [zmaxZonal, zmaxVertical]
1816 zmaxVector = [zmaxZonal, zmaxVertical]
1586 zminVector = [zminZonal, zminVertical]
1817 zminVector = [zminZonal, zminVertical]
1587
1818
1588 for i in range(nplotsw):
1819 for i in range(nplotsw):
1589
1820
1590 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1821 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1591 axes = self.axesList[i*self.__nsubplots]
1822 axes = self.axesList[i*self.__nsubplots]
1592
1823
1593 z1 = z[i,:].reshape((1,-1))
1824 z1 = z[i,:].reshape((1,-1))
1594
1825
1595 axes.pcolorbuffer(x, y, z1,
1826 axes.pcolorbuffer(x, y, z1,
1596 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1827 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1597 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1828 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1598 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1829 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1599
1830
1600 if dataOut.data_SNR is not None:
1831 if dataOut.data_SNR is not None:
1601 i += 1
1832 i += 1
1602 if SNR_1:
1833 if SNR_1:
1603 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1834 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1604 else:
1835 else:
1605 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1836 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1606 axes = self.axesList[i*self.__nsubplots]
1837 axes = self.axesList[i*self.__nsubplots]
1607 SNRavgdB = SNRavgdB.reshape((1,-1))
1838 SNRavgdB = SNRavgdB.reshape((1,-1))
1608
1839
1609 axes.pcolorbuffer(x, y, SNRavgdB,
1840 axes.pcolorbuffer(x, y, SNRavgdB,
1610 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1841 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1611 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1842 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1612 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1843 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1613
1844
1614 self.draw()
1845 self.draw()
1615
1846
1616 if x[1] >= self.axesList[0].xmax:
1847 if x[1] >= self.axesList[0].xmax:
1617 self.counter_imagwr = wr_period
1848 self.counter_imagwr = wr_period
1618 self.isConfig = False
1849 self.isConfig = False
1619 self.figfile = None
1850 self.figfile = None
1620
1851
1621
1852
1622
1853
1623
1854
1624 class PhasePlot_(Figure):
1855 class PhasePlot_(Figure):
1625
1856
1626 __isConfig = None
1857 __isConfig = None
1627 __nsubplots = None
1858 __nsubplots = None
1628
1859
1629 PREFIX = 'mphase'
1860 PREFIX = 'mphase'
1630
1861
1631
1862
1632 def __init__(self, **kwargs):
1863 def __init__(self, **kwargs):
1633 Figure.__init__(self, **kwargs)
1864 Figure.__init__(self, **kwargs)
1634 self.timerange = 24*60*60
1865 self.timerange = 24*60*60
1635 self.isConfig = False
1866 self.isConfig = False
1636 self.__nsubplots = 1
1867 self.__nsubplots = 1
1637 self.counter_imagwr = 0
1868 self.counter_imagwr = 0
1638 self.WIDTH = 600
1869 self.WIDTH = 600
1639 self.HEIGHT = 300
1870 self.HEIGHT = 300
1640 self.WIDTHPROF = 120
1871 self.WIDTHPROF = 120
1641 self.HEIGHTPROF = 0
1872 self.HEIGHTPROF = 0
1642 self.xdata = None
1873 self.xdata = None
1643 self.ydata = None
1874 self.ydata = None
1644
1875
1645 self.PLOT_CODE = MPHASE_CODE
1876 self.PLOT_CODE = MPHASE_CODE
1646
1877
1647 self.FTP_WEI = None
1878 self.FTP_WEI = None
1648 self.EXP_CODE = None
1879 self.EXP_CODE = None
1649 self.SUB_EXP_CODE = None
1880 self.SUB_EXP_CODE = None
1650 self.PLOT_POS = None
1881 self.PLOT_POS = None
1651
1882
1652
1883
1653 self.filename_phase = None
1884 self.filename_phase = None
1654
1885
1655 self.figfile = None
1886 self.figfile = None
1656
1887
1657 def getSubplots(self):
1888 def getSubplots(self):
1658
1889
1659 ncol = 1
1890 ncol = 1
1660 nrow = 1
1891 nrow = 1
1661
1892
1662 return nrow, ncol
1893 return nrow, ncol
1663
1894
1664 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1895 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1665
1896
1666 self.__showprofile = showprofile
1897 self.__showprofile = showprofile
1667 self.nplots = nplots
1898 self.nplots = nplots
1668
1899
1669 ncolspan = 7
1900 ncolspan = 7
1670 colspan = 6
1901 colspan = 6
1671 self.__nsubplots = 2
1902 self.__nsubplots = 2
1672
1903
1673 self.createFigure(id = id,
1904 self.createFigure(id = id,
1674 wintitle = wintitle,
1905 wintitle = wintitle,
1675 widthplot = self.WIDTH+self.WIDTHPROF,
1906 widthplot = self.WIDTH+self.WIDTHPROF,
1676 heightplot = self.HEIGHT+self.HEIGHTPROF,
1907 heightplot = self.HEIGHT+self.HEIGHTPROF,
1677 show=show)
1908 show=show)
1678
1909
1679 nrow, ncol = self.getSubplots()
1910 nrow, ncol = self.getSubplots()
1680
1911
1681 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1912 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1682
1913
1683
1914
1684 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1915 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1685 xmin=None, xmax=None, ymin=None, ymax=None,
1916 xmin=None, xmax=None, ymin=None, ymax=None,
1686 timerange=None,
1917 timerange=None,
1687 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1918 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1688 server=None, folder=None, username=None, password=None,
1919 server=None, folder=None, username=None, password=None,
1689 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1920 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1690
1921
1691
1922
1692 tmin = None
1923 tmin = None
1693 tmax = None
1924 tmax = None
1694 x = dataOut.getTimeRange1(dataOut.outputInterval)
1925 x = dataOut.getTimeRange1(dataOut.outputInterval)
1695 y = dataOut.getHeiRange()
1926 y = dataOut.getHeiRange()
1696
1927
1697
1928
1698 #thisDatetime = dataOut.datatime
1929 #thisDatetime = dataOut.datatime
1699 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1930 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1700 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1931 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1701 xlabel = "Local Time"
1932 xlabel = "Local Time"
1702 ylabel = "Phase"
1933 ylabel = "Phase"
1703
1934
1704
1935
1705 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1936 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1706 phase_beacon = dataOut.data_output
1937 phase_beacon = dataOut.data_output
1707 update_figfile = False
1938 update_figfile = False
1708
1939
1709 if not self.isConfig:
1940 if not self.isConfig:
1710
1941
1711 self.nplots = phase_beacon.size
1942 self.nplots = phase_beacon.size
1712
1943
1713 self.setup(id=id,
1944 self.setup(id=id,
1714 nplots=self.nplots,
1945 nplots=self.nplots,
1715 wintitle=wintitle,
1946 wintitle=wintitle,
1716 showprofile=showprofile,
1947 showprofile=showprofile,
1717 show=show)
1948 show=show)
1718
1949
1719 if timerange is not None:
1950 if timerange is not None:
1720 self.timerange = timerange
1951 self.timerange = timerange
1721
1952
1722 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1953 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1723
1954
1724 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1955 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1725 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1956 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1726
1957
1727 self.FTP_WEI = ftp_wei
1958 self.FTP_WEI = ftp_wei
1728 self.EXP_CODE = exp_code
1959 self.EXP_CODE = exp_code
1729 self.SUB_EXP_CODE = sub_exp_code
1960 self.SUB_EXP_CODE = sub_exp_code
1730 self.PLOT_POS = plot_pos
1961 self.PLOT_POS = plot_pos
1731
1962
1732 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1963 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1733 self.isConfig = True
1964 self.isConfig = True
1734 self.figfile = figfile
1965 self.figfile = figfile
1735 self.xdata = numpy.array([])
1966 self.xdata = numpy.array([])
1736 self.ydata = numpy.array([])
1967 self.ydata = numpy.array([])
1737
1968
1738 #open file beacon phase
1969 #open file beacon phase
1739 path = '%s%03d' %(self.PREFIX, self.id)
1970 path = '%s%03d' %(self.PREFIX, self.id)
1740 beacon_file = os.path.join(path,'%s.txt'%self.name)
1971 beacon_file = os.path.join(path,'%s.txt'%self.name)
1741 self.filename_phase = os.path.join(figpath,beacon_file)
1972 self.filename_phase = os.path.join(figpath,beacon_file)
1742 update_figfile = True
1973 update_figfile = True
1743
1974
1744
1975
1745 #store data beacon phase
1976 #store data beacon phase
1746 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1977 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1747
1978
1748 self.setWinTitle(title)
1979 self.setWinTitle(title)
1749
1980
1750
1981
1751 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1982 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1752
1983
1753 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1984 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1754
1985
1755 axes = self.axesList[0]
1986 axes = self.axesList[0]
1756
1987
1757 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1988 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1758
1989
1759 if len(self.ydata)==0:
1990 if len(self.ydata)==0:
1760 self.ydata = phase_beacon.reshape(-1,1)
1991 self.ydata = phase_beacon.reshape(-1,1)
1761 else:
1992 else:
1762 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1993 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1763
1994
1764
1995
1765 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1996 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1766 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1997 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1767 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1998 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1768 XAxisAsTime=True, grid='both'
1999 XAxisAsTime=True, grid='both'
1769 )
2000 )
1770
2001
1771 self.draw()
2002 self.draw()
1772
2003
1773 self.save(figpath=figpath,
2004 self.save(figpath=figpath,
1774 figfile=figfile,
2005 figfile=figfile,
1775 save=save,
2006 save=save,
1776 ftp=ftp,
2007 ftp=ftp,
1777 wr_period=wr_period,
2008 wr_period=wr_period,
1778 thisDatetime=thisDatetime,
2009 thisDatetime=thisDatetime,
1779 update_figfile=update_figfile)
2010 update_figfile=update_figfile)
1780
2011
1781 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
2012 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1782 self.counter_imagwr = wr_period
2013 self.counter_imagwr = wr_period
1783 self.isConfig = False
2014 self.isConfig = False
1784 update_figfile = True
2015 update_figfile = True
1785
2016
1786
2017
1787
2018
1788 class NSMeteorDetection1Plot_(Figure):
2019 class NSMeteorDetection1Plot_(Figure):
1789
2020
1790 isConfig = None
2021 isConfig = None
1791 __nsubplots = None
2022 __nsubplots = None
1792
2023
1793 WIDTHPROF = None
2024 WIDTHPROF = None
1794 HEIGHTPROF = None
2025 HEIGHTPROF = None
1795 PREFIX = 'nsm'
2026 PREFIX = 'nsm'
1796
2027
1797 zminList = None
2028 zminList = None
1798 zmaxList = None
2029 zmaxList = None
1799 cmapList = None
2030 cmapList = None
1800 titleList = None
2031 titleList = None
1801 nPairs = None
2032 nPairs = None
1802 nChannels = None
2033 nChannels = None
1803 nParam = None
2034 nParam = None
1804
2035
1805 def __init__(self, **kwargs):
2036 def __init__(self, **kwargs):
1806 Figure.__init__(self, **kwargs)
2037 Figure.__init__(self, **kwargs)
1807 self.isConfig = False
2038 self.isConfig = False
1808 self.__nsubplots = 1
2039 self.__nsubplots = 1
1809
2040
1810 self.WIDTH = 750
2041 self.WIDTH = 750
1811 self.HEIGHT = 250
2042 self.HEIGHT = 250
1812 self.WIDTHPROF = 120
2043 self.WIDTHPROF = 120
1813 self.HEIGHTPROF = 0
2044 self.HEIGHTPROF = 0
1814 self.counter_imagwr = 0
2045 self.counter_imagwr = 0
1815
2046
1816 self.PLOT_CODE = SPEC_CODE
2047 self.PLOT_CODE = SPEC_CODE
1817
2048
1818 self.FTP_WEI = None
2049 self.FTP_WEI = None
1819 self.EXP_CODE = None
2050 self.EXP_CODE = None
1820 self.SUB_EXP_CODE = None
2051 self.SUB_EXP_CODE = None
1821 self.PLOT_POS = None
2052 self.PLOT_POS = None
1822
2053
1823 self.__xfilter_ena = False
2054 self.__xfilter_ena = False
1824 self.__yfilter_ena = False
2055 self.__yfilter_ena = False
1825
2056
1826 def getSubplots(self):
2057 def getSubplots(self):
1827
2058
1828 ncol = 3
2059 ncol = 3
1829 nrow = int(numpy.ceil(self.nplots/3.0))
2060 nrow = int(numpy.ceil(self.nplots/3.0))
1830
2061
1831 return nrow, ncol
2062 return nrow, ncol
1832
2063
1833 def setup(self, id, nplots, wintitle, show=True):
2064 def setup(self, id, nplots, wintitle, show=True):
1834
2065
1835 self.nplots = nplots
2066 self.nplots = nplots
1836
2067
1837 ncolspan = 1
2068 ncolspan = 1
1838 colspan = 1
2069 colspan = 1
1839
2070
1840 self.createFigure(id = id,
2071 self.createFigure(id = id,
1841 wintitle = wintitle,
2072 wintitle = wintitle,
1842 widthplot = self.WIDTH + self.WIDTHPROF,
2073 widthplot = self.WIDTH + self.WIDTHPROF,
1843 heightplot = self.HEIGHT + self.HEIGHTPROF,
2074 heightplot = self.HEIGHT + self.HEIGHTPROF,
1844 show=show)
2075 show=show)
1845
2076
1846 nrow, ncol = self.getSubplots()
2077 nrow, ncol = self.getSubplots()
1847
2078
1848 counter = 0
2079 counter = 0
1849 for y in range(nrow):
2080 for y in range(nrow):
1850 for x in range(ncol):
2081 for x in range(ncol):
1851
2082
1852 if counter >= self.nplots:
2083 if counter >= self.nplots:
1853 break
2084 break
1854
2085
1855 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2086 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1856
2087
1857 counter += 1
2088 counter += 1
1858
2089
1859 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2090 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1860 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2091 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1861 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2092 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1862 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2093 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1863 server=None, folder=None, username=None, password=None,
2094 server=None, folder=None, username=None, password=None,
1864 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2095 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1865 xaxis="frequency"):
2096 xaxis="frequency"):
1866
2097
1867 """
2098 """
1868
2099
1869 Input:
2100 Input:
1870 dataOut :
2101 dataOut :
1871 id :
2102 id :
1872 wintitle :
2103 wintitle :
1873 channelList :
2104 channelList :
1874 showProfile :
2105 showProfile :
1875 xmin : None,
2106 xmin : None,
1876 xmax : None,
2107 xmax : None,
1877 ymin : None,
2108 ymin : None,
1878 ymax : None,
2109 ymax : None,
1879 zmin : None,
2110 zmin : None,
1880 zmax : None
2111 zmax : None
1881 """
2112 """
1882 #SEPARAR EN DOS PLOTS
2113 #SEPARAR EN DOS PLOTS
1883 nParam = dataOut.data_param.shape[1] - 3
2114 nParam = dataOut.data_param.shape[1] - 3
1884
2115
1885 utctime = dataOut.data_param[0,0]
2116 utctime = dataOut.data_param[0,0]
1886 tmet = dataOut.data_param[:,1].astype(int)
2117 tmet = dataOut.data_param[:,1].astype(int)
1887 hmet = dataOut.data_param[:,2].astype(int)
2118 hmet = dataOut.data_param[:,2].astype(int)
1888
2119
1889 x = dataOut.abscissaList
2120 x = dataOut.abscissaList
1890 y = dataOut.heightList
2121 y = dataOut.heightList
1891
2122
1892 z = numpy.zeros((nParam, y.size, x.size - 1))
2123 z = numpy.zeros((nParam, y.size, x.size - 1))
1893 z[:,:] = numpy.nan
2124 z[:,:] = numpy.nan
1894 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
2125 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1895 z[0,:,:] = 10*numpy.log10(z[0,:,:])
2126 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1896
2127
1897 xlabel = "Time (s)"
2128 xlabel = "Time (s)"
1898 ylabel = "Range (km)"
2129 ylabel = "Range (km)"
1899
2130
1900 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1901
2132
1902 if not self.isConfig:
2133 if not self.isConfig:
1903
2134
1904 nplots = nParam
2135 nplots = nParam
1905
2136
1906 self.setup(id=id,
2137 self.setup(id=id,
1907 nplots=nplots,
2138 nplots=nplots,
1908 wintitle=wintitle,
2139 wintitle=wintitle,
1909 show=show)
2140 show=show)
1910
2141
1911 if xmin is None: xmin = numpy.nanmin(x)
2142 if xmin is None: xmin = numpy.nanmin(x)
1912 if xmax is None: xmax = numpy.nanmax(x)
2143 if xmax is None: xmax = numpy.nanmax(x)
1913 if ymin is None: ymin = numpy.nanmin(y)
2144 if ymin is None: ymin = numpy.nanmin(y)
1914 if ymax is None: ymax = numpy.nanmax(y)
2145 if ymax is None: ymax = numpy.nanmax(y)
1915 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2146 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1916 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2147 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1917 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2148 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1918 if vmin is None: vmin = -vmax
2149 if vmin is None: vmin = -vmax
1919 if wmin is None: wmin = 0
2150 if wmin is None: wmin = 0
1920 if wmax is None: wmax = 50
2151 if wmax is None: wmax = 50
1921
2152
1922 pairsList = dataOut.groupList
2153 pairsList = dataOut.groupList
1923 self.nPairs = len(dataOut.groupList)
2154 self.nPairs = len(dataOut.groupList)
1924
2155
1925 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
2156 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1926 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
2157 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1927 titleList = ["SNR","Radial Velocity","Coherence"]
2158 titleList = ["SNR","Radial Velocity","Coherence"]
1928 cmapList = ["jet","RdBu_r","jet"]
2159 cmapList = ["jet","RdBu_r","jet"]
1929
2160
1930 for i in range(self.nPairs):
2161 for i in range(self.nPairs):
1931 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
2162 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1932 titleList = titleList + [strAux1]
2163 titleList = titleList + [strAux1]
1933 cmapList = cmapList + ["RdBu_r"]
2164 cmapList = cmapList + ["RdBu_r"]
1934
2165
1935 self.zminList = zminList
2166 self.zminList = zminList
1936 self.zmaxList = zmaxList
2167 self.zmaxList = zmaxList
1937 self.cmapList = cmapList
2168 self.cmapList = cmapList
1938 self.titleList = titleList
2169 self.titleList = titleList
1939
2170
1940 self.FTP_WEI = ftp_wei
2171 self.FTP_WEI = ftp_wei
1941 self.EXP_CODE = exp_code
2172 self.EXP_CODE = exp_code
1942 self.SUB_EXP_CODE = sub_exp_code
2173 self.SUB_EXP_CODE = sub_exp_code
1943 self.PLOT_POS = plot_pos
2174 self.PLOT_POS = plot_pos
1944
2175
1945 self.isConfig = True
2176 self.isConfig = True
1946
2177
1947 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2178 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1948
2179
1949 for i in range(nParam):
2180 for i in range(nParam):
1950 title = self.titleList[i] + ": " +str_datetime
2181 title = self.titleList[i] + ": " +str_datetime
1951 axes = self.axesList[i]
2182 axes = self.axesList[i]
1952 axes.pcolor(x, y, z[i,:].T,
2183 axes.pcolor(x, y, z[i,:].T,
1953 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1954 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2185 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1955 self.draw()
2186 self.draw()
1956
2187
1957 if figfile == None:
2188 if figfile == None:
1958 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2189 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1959 name = str_datetime
2190 name = str_datetime
1960 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2191 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1961 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2192 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1962 figfile = self.getFilename(name)
2193 figfile = self.getFilename(name)
1963
2194
1964 self.save(figpath=figpath,
2195 self.save(figpath=figpath,
1965 figfile=figfile,
2196 figfile=figfile,
1966 save=save,
2197 save=save,
1967 ftp=ftp,
2198 ftp=ftp,
1968 wr_period=wr_period,
2199 wr_period=wr_period,
1969 thisDatetime=thisDatetime)
2200 thisDatetime=thisDatetime)
1970
2201
1971
2202
1972 class NSMeteorDetection2Plot_(Figure):
2203 class NSMeteorDetection2Plot_(Figure):
1973
2204
1974 isConfig = None
2205 isConfig = None
1975 __nsubplots = None
2206 __nsubplots = None
1976
2207
1977 WIDTHPROF = None
2208 WIDTHPROF = None
1978 HEIGHTPROF = None
2209 HEIGHTPROF = None
1979 PREFIX = 'nsm'
2210 PREFIX = 'nsm'
1980
2211
1981 zminList = None
2212 zminList = None
1982 zmaxList = None
2213 zmaxList = None
1983 cmapList = None
2214 cmapList = None
1984 titleList = None
2215 titleList = None
1985 nPairs = None
2216 nPairs = None
1986 nChannels = None
2217 nChannels = None
1987 nParam = None
2218 nParam = None
1988
2219
1989 def __init__(self, **kwargs):
2220 def __init__(self, **kwargs):
1990 Figure.__init__(self, **kwargs)
2221 Figure.__init__(self, **kwargs)
1991 self.isConfig = False
2222 self.isConfig = False
1992 self.__nsubplots = 1
2223 self.__nsubplots = 1
1993
2224
1994 self.WIDTH = 750
2225 self.WIDTH = 750
1995 self.HEIGHT = 250
2226 self.HEIGHT = 250
1996 self.WIDTHPROF = 120
2227 self.WIDTHPROF = 120
1997 self.HEIGHTPROF = 0
2228 self.HEIGHTPROF = 0
1998 self.counter_imagwr = 0
2229 self.counter_imagwr = 0
1999
2230
2000 self.PLOT_CODE = SPEC_CODE
2231 self.PLOT_CODE = SPEC_CODE
2001
2232
2002 self.FTP_WEI = None
2233 self.FTP_WEI = None
2003 self.EXP_CODE = None
2234 self.EXP_CODE = None
2004 self.SUB_EXP_CODE = None
2235 self.SUB_EXP_CODE = None
2005 self.PLOT_POS = None
2236 self.PLOT_POS = None
2006
2237
2007 self.__xfilter_ena = False
2238 self.__xfilter_ena = False
2008 self.__yfilter_ena = False
2239 self.__yfilter_ena = False
2009
2240
2010 def getSubplots(self):
2241 def getSubplots(self):
2011
2242
2012 ncol = 3
2243 ncol = 3
2013 nrow = int(numpy.ceil(self.nplots/3.0))
2244 nrow = int(numpy.ceil(self.nplots/3.0))
2014
2245
2015 return nrow, ncol
2246 return nrow, ncol
2016
2247
2017 def setup(self, id, nplots, wintitle, show=True):
2248 def setup(self, id, nplots, wintitle, show=True):
2018
2249
2019 self.nplots = nplots
2250 self.nplots = nplots
2020
2251
2021 ncolspan = 1
2252 ncolspan = 1
2022 colspan = 1
2253 colspan = 1
2023
2254
2024 self.createFigure(id = id,
2255 self.createFigure(id = id,
2025 wintitle = wintitle,
2256 wintitle = wintitle,
2026 widthplot = self.WIDTH + self.WIDTHPROF,
2257 widthplot = self.WIDTH + self.WIDTHPROF,
2027 heightplot = self.HEIGHT + self.HEIGHTPROF,
2258 heightplot = self.HEIGHT + self.HEIGHTPROF,
2028 show=show)
2259 show=show)
2029
2260
2030 nrow, ncol = self.getSubplots()
2261 nrow, ncol = self.getSubplots()
2031
2262
2032 counter = 0
2263 counter = 0
2033 for y in range(nrow):
2264 for y in range(nrow):
2034 for x in range(ncol):
2265 for x in range(ncol):
2035
2266
2036 if counter >= self.nplots:
2267 if counter >= self.nplots:
2037 break
2268 break
2038
2269
2039 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2270 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2040
2271
2041 counter += 1
2272 counter += 1
2042
2273
2043 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2274 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2044 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2275 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2045 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2276 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2046 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2277 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2047 server=None, folder=None, username=None, password=None,
2278 server=None, folder=None, username=None, password=None,
2048 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2279 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2049 xaxis="frequency"):
2280 xaxis="frequency"):
2050
2281
2051 """
2282 """
2052
2283
2053 Input:
2284 Input:
2054 dataOut :
2285 dataOut :
2055 id :
2286 id :
2056 wintitle :
2287 wintitle :
2057 channelList :
2288 channelList :
2058 showProfile :
2289 showProfile :
2059 xmin : None,
2290 xmin : None,
2060 xmax : None,
2291 xmax : None,
2061 ymin : None,
2292 ymin : None,
2062 ymax : None,
2293 ymax : None,
2063 zmin : None,
2294 zmin : None,
2064 zmax : None
2295 zmax : None
2065 """
2296 """
2066 #Rebuild matrix
2297 #Rebuild matrix
2067 utctime = dataOut.data_param[0,0]
2298 utctime = dataOut.data_param[0,0]
2068 cmet = dataOut.data_param[:,1].astype(int)
2299 cmet = dataOut.data_param[:,1].astype(int)
2069 tmet = dataOut.data_param[:,2].astype(int)
2300 tmet = dataOut.data_param[:,2].astype(int)
2070 hmet = dataOut.data_param[:,3].astype(int)
2301 hmet = dataOut.data_param[:,3].astype(int)
2071
2302
2072 nParam = 3
2303 nParam = 3
2073 nChan = len(dataOut.groupList)
2304 nChan = len(dataOut.groupList)
2074 x = dataOut.abscissaList
2305 x = dataOut.abscissaList
2075 y = dataOut.heightList
2306 y = dataOut.heightList
2076
2307
2077 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2308 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2078 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2309 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2079 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2310 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2080 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2311 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2081
2312
2082 xlabel = "Time (s)"
2313 xlabel = "Time (s)"
2083 ylabel = "Range (km)"
2314 ylabel = "Range (km)"
2084
2315
2085 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2316 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2086
2317
2087 if not self.isConfig:
2318 if not self.isConfig:
2088
2319
2089 nplots = nParam*nChan
2320 nplots = nParam*nChan
2090
2321
2091 self.setup(id=id,
2322 self.setup(id=id,
2092 nplots=nplots,
2323 nplots=nplots,
2093 wintitle=wintitle,
2324 wintitle=wintitle,
2094 show=show)
2325 show=show)
2095
2326
2096 if xmin is None: xmin = numpy.nanmin(x)
2327 if xmin is None: xmin = numpy.nanmin(x)
2097 if xmax is None: xmax = numpy.nanmax(x)
2328 if xmax is None: xmax = numpy.nanmax(x)
2098 if ymin is None: ymin = numpy.nanmin(y)
2329 if ymin is None: ymin = numpy.nanmin(y)
2099 if ymax is None: ymax = numpy.nanmax(y)
2330 if ymax is None: ymax = numpy.nanmax(y)
2100 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2331 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2101 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2332 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2102 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2333 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2103 if vmin is None: vmin = -vmax
2334 if vmin is None: vmin = -vmax
2104 if wmin is None: wmin = 0
2335 if wmin is None: wmin = 0
2105 if wmax is None: wmax = 50
2336 if wmax is None: wmax = 50
2106
2337
2107 self.nChannels = nChan
2338 self.nChannels = nChan
2108
2339
2109 zminList = []
2340 zminList = []
2110 zmaxList = []
2341 zmaxList = []
2111 titleList = []
2342 titleList = []
2112 cmapList = []
2343 cmapList = []
2113 for i in range(self.nChannels):
2344 for i in range(self.nChannels):
2114 strAux1 = "SNR Channel "+ str(i)
2345 strAux1 = "SNR Channel "+ str(i)
2115 strAux2 = "Radial Velocity Channel "+ str(i)
2346 strAux2 = "Radial Velocity Channel "+ str(i)
2116 strAux3 = "Spectral Width Channel "+ str(i)
2347 strAux3 = "Spectral Width Channel "+ str(i)
2117
2348
2118 titleList = titleList + [strAux1,strAux2,strAux3]
2349 titleList = titleList + [strAux1,strAux2,strAux3]
2119 cmapList = cmapList + ["jet","RdBu_r","jet"]
2350 cmapList = cmapList + ["jet","RdBu_r","jet"]
2120 zminList = zminList + [SNRmin,vmin,wmin]
2351 zminList = zminList + [SNRmin,vmin,wmin]
2121 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2352 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2122
2353
2123 self.zminList = zminList
2354 self.zminList = zminList
2124 self.zmaxList = zmaxList
2355 self.zmaxList = zmaxList
2125 self.cmapList = cmapList
2356 self.cmapList = cmapList
2126 self.titleList = titleList
2357 self.titleList = titleList
2127
2358
2128 self.FTP_WEI = ftp_wei
2359 self.FTP_WEI = ftp_wei
2129 self.EXP_CODE = exp_code
2360 self.EXP_CODE = exp_code
2130 self.SUB_EXP_CODE = sub_exp_code
2361 self.SUB_EXP_CODE = sub_exp_code
2131 self.PLOT_POS = plot_pos
2362 self.PLOT_POS = plot_pos
2132
2363
2133 self.isConfig = True
2364 self.isConfig = True
2134
2365
2135 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2366 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2136
2367
2137 for i in range(self.nplots):
2368 for i in range(self.nplots):
2138 title = self.titleList[i] + ": " +str_datetime
2369 title = self.titleList[i] + ": " +str_datetime
2139 axes = self.axesList[i]
2370 axes = self.axesList[i]
2140 axes.pcolor(x, y, z[i,:].T,
2371 axes.pcolor(x, y, z[i,:].T,
2141 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2372 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2142 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2373 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2143 self.draw()
2374 self.draw()
2144
2375
2145 if figfile == None:
2376 if figfile == None:
2146 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2377 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2147 name = str_datetime
2378 name = str_datetime
2148 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2379 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2149 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2380 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2150 figfile = self.getFilename(name)
2381 figfile = self.getFilename(name)
2151
2382
2152 self.save(figpath=figpath,
2383 self.save(figpath=figpath,
2153 figfile=figfile,
2384 figfile=figfile,
2154 save=save,
2385 save=save,
2155 ftp=ftp,
2386 ftp=ftp,
2156 wr_period=wr_period,
2387 wr_period=wr_period,
2157 thisDatetime=thisDatetime)
2388 thisDatetime=thisDatetime)
2158 No newline at end of file
2389
@@ -1,1587 +1,1588
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from .figure import Figure, isRealtime, isTimeInHourRange
10 from .figure import Figure, isRealtime, isTimeInHourRange
11 from .plotting_codes import *
11 from .plotting_codes import *
12 from schainpy.model.proc.jroproc_base import MPDecorator
12 from schainpy.model.proc.jroproc_base import MPDecorator
13
13
14 from schainpy.utils import log
14 from schainpy.utils import log
15
15
16 @MPDecorator
16 @MPDecorator
17 class SpectraPlot_(Figure):
17 class SpectraPlot_(Figure):
18
18
19 isConfig = None
19 isConfig = None
20 __nsubplots = None
20 __nsubplots = None
21
21
22 WIDTHPROF = None
22 WIDTHPROF = None
23 HEIGHTPROF = None
23 HEIGHTPROF = None
24 PREFIX = 'spc'
24 PREFIX = 'spc'
25
25
26 def __init__(self):
26 def __init__(self):
27 Figure.__init__(self)
27 Figure.__init__(self)
28 self.isConfig = False
28 self.isConfig = False
29 self.__nsubplots = 1
29 self.__nsubplots = 1
30 self.WIDTH = 250
30 self.WIDTH = 250
31 self.HEIGHT = 250
31 self.HEIGHT = 250
32 self.WIDTHPROF = 120
32 self.WIDTHPROF = 120
33 self.HEIGHTPROF = 0
33 self.HEIGHTPROF = 0
34 self.counter_imagwr = 0
34 self.counter_imagwr = 0
35
35
36 self.PLOT_CODE = SPEC_CODE
36 self.PLOT_CODE = SPEC_CODE
37
37
38 self.FTP_WEI = None
38 self.FTP_WEI = None
39 self.EXP_CODE = None
39 self.EXP_CODE = None
40 self.SUB_EXP_CODE = None
40 self.SUB_EXP_CODE = None
41 self.PLOT_POS = None
41 self.PLOT_POS = None
42
42
43 self.__xfilter_ena = False
43 self.__xfilter_ena = False
44 self.__yfilter_ena = False
44 self.__yfilter_ena = False
45
46 self.indice=1
45
47
46 def getSubplots(self):
48 def getSubplots(self):
47
49
48 ncol = int(numpy.sqrt(self.nplots)+0.9)
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
49 nrow = int(self.nplots*1./ncol + 0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
50
52
51 return nrow, ncol
53 return nrow, ncol
52
54
53 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
54
56
55 self.__showprofile = showprofile
57 self.__showprofile = showprofile
56 self.nplots = nplots
58 self.nplots = nplots
57
59
58 ncolspan = 1
60 ncolspan = 1
59 colspan = 1
61 colspan = 1
60 if showprofile:
62 if showprofile:
61 ncolspan = 3
63 ncolspan = 3
62 colspan = 2
64 colspan = 2
63 self.__nsubplots = 2
65 self.__nsubplots = 2
64
66
65 self.createFigure(id = id,
67 self.createFigure(id = id,
66 wintitle = wintitle,
68 wintitle = wintitle,
67 widthplot = self.WIDTH + self.WIDTHPROF,
69 widthplot = self.WIDTH + self.WIDTHPROF,
68 heightplot = self.HEIGHT + self.HEIGHTPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
69 show=show)
71 show=show)
70
72
71 nrow, ncol = self.getSubplots()
73 nrow, ncol = self.getSubplots()
72
74
73 counter = 0
75 counter = 0
74 for y in range(nrow):
76 for y in range(nrow):
75 for x in range(ncol):
77 for x in range(ncol):
76
78
77 if counter >= self.nplots:
79 if counter >= self.nplots:
78 break
80 break
79
81
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
81
83
82 if showprofile:
84 if showprofile:
83 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
84
86
85 counter += 1
87 counter += 1
86
88
87 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
88 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
89 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
90 server=None, folder=None, username=None, password=None,
92 server=None, folder=None, username=None, password=None,
91 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
92 xaxis="frequency", colormap='jet', normFactor=None):
94 xaxis="frequency", colormap='jet', normFactor=None):
93
95
94 """
96 """
95
97
96 Input:
98 Input:
97 dataOut :
99 dataOut :
98 id :
100 id :
99 wintitle :
101 wintitle :
100 channelList :
102 channelList :
101 showProfile :
103 showProfile :
102 xmin : None,
104 xmin : None,
103 xmax : None,
105 xmax : None,
104 ymin : None,
106 ymin : None,
105 ymax : None,
107 ymax : None,
106 zmin : None,
108 zmin : None,
107 zmax : None
109 zmax : None
108 """
110 """
109 if dataOut.flagNoData:
111 if dataOut.flagNoData:
110 return dataOut
112 return dataOut
111
113
112 if realtime:
114 if realtime:
113 if not(isRealtime(utcdatatime = dataOut.utctime)):
115 if not(isRealtime(utcdatatime = dataOut.utctime)):
114 print('Skipping this plot function')
116 print('Skipping this plot function')
115 return
117 return
116
118
117 if channelList == None:
119 if channelList == None:
118 channelIndexList = dataOut.channelIndexList
120 channelIndexList = dataOut.channelIndexList
119 else:
121 else:
120 channelIndexList = []
122 channelIndexList = []
121 for channel in channelList:
123 for channel in channelList:
122 if channel not in dataOut.channelList:
124 if channel not in dataOut.channelList:
123 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
125 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
124 channelIndexList.append(dataOut.channelList.index(channel))
126 channelIndexList.append(dataOut.channelList.index(channel))
125
127
126 if normFactor is None:
128 if normFactor is None:
127 factor = dataOut.normFactor
129 factor = dataOut.normFactor
128 else:
130 else:
129 factor = normFactor
131 factor = normFactor
130 if xaxis == "frequency":
132 if xaxis == "frequency":
131 x = dataOut.getFreqRange(1)/1000.
133 x = dataOut.getFreqRange(1)/1000.
132 xlabel = "Frequency (kHz)"
134 xlabel = "Frequency (kHz)"
133
135
134 elif xaxis == "time":
136 elif xaxis == "time":
135 x = dataOut.getAcfRange(1)
137 x = dataOut.getAcfRange(1)
136 xlabel = "Time (ms)"
138 xlabel = "Time (ms)"
137
139
138 else:
140 else:
139 x = dataOut.getVelRange(1)
141 x = dataOut.getVelRange(1)
140 xlabel = "Velocity (m/s)"
142 xlabel = "Velocity (m/s)"
141
143
142 ylabel = "Range (Km)"
144 ylabel = "Range (km)"
143
145
144 y = dataOut.getHeiRange()
146 y = dataOut.getHeiRange()
145
146 z = dataOut.data_spc/factor
147 z = dataOut.data_spc/factor
147 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
148 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
148 zdB = 10*numpy.log10(z)
149 zdB = 10*numpy.log10(z)
149
150
150 avg = numpy.average(z, axis=1)
151 avg = numpy.average(z, axis=1)
151 avgdB = 10*numpy.log10(avg)
152 avgdB = 10*numpy.log10(avg)
152
153
153 noise = dataOut.getNoise()/factor
154 noise = dataOut.getNoise()/factor
154 noisedB = 10*numpy.log10(noise)
155 noisedB = 10*numpy.log10(noise)
155
156
156 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
157 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
157 title = wintitle + " Spectra"
158 title = wintitle + " Spectra"
159
158 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
160 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
159 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
161 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
160
162
161 if not self.isConfig:
163 if not self.isConfig:
162
164
163 nplots = len(channelIndexList)
165 nplots = len(channelIndexList)
164
166
165 self.setup(id=id,
167 self.setup(id=id,
166 nplots=nplots,
168 nplots=nplots,
167 wintitle=wintitle,
169 wintitle=wintitle,
168 showprofile=showprofile,
170 showprofile=showprofile,
169 show=show)
171 show=show)
170
172
171 if xmin == None: xmin = numpy.nanmin(x)
173 if xmin == None: xmin = numpy.nanmin(x)
172 if xmax == None: xmax = numpy.nanmax(x)
174 if xmax == None: xmax = numpy.nanmax(x)
173 if ymin == None: ymin = numpy.nanmin(y)
175 if ymin == None: ymin = numpy.nanmin(y)
174 if ymax == None: ymax = numpy.nanmax(y)
176 if ymax == None: ymax = numpy.nanmax(y)
175 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
177 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
176 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
178 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
177
179
178 self.FTP_WEI = ftp_wei
180 self.FTP_WEI = ftp_wei
179 self.EXP_CODE = exp_code
181 self.EXP_CODE = exp_code
180 self.SUB_EXP_CODE = sub_exp_code
182 self.SUB_EXP_CODE = sub_exp_code
181 self.PLOT_POS = plot_pos
183 self.PLOT_POS = plot_pos
182
184
183 self.isConfig = True
185 self.isConfig = True
184
186
185 self.setWinTitle(title)
187 self.setWinTitle(title)
186
188
187 for i in range(self.nplots):
189 for i in range(self.nplots):
188 index = channelIndexList[i]
190 index = channelIndexList[i]
189 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
191 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
190 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
192 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
191 if len(dataOut.beam.codeList) != 0:
193 if len(dataOut.beam.codeList) != 0:
192 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)
194 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)
193
195
194 axes = self.axesList[i*self.__nsubplots]
196 axes = self.axesList[i*self.__nsubplots]
195 axes.pcolor(x, y, zdB[index,:,:],
197 axes.pcolor(x, y, zdB[index,:,:],
196 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
198 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
197 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
199 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
198 ticksize=9, cblabel='')
200 ticksize=9, cblabel='')
199
201
200 if self.__showprofile:
202 if self.__showprofile:
201 axes = self.axesList[i*self.__nsubplots +1]
203 axes = self.axesList[i*self.__nsubplots +1]
202 axes.pline(avgdB[index,:], y,
204 axes.pline(avgdB[index,:], y,
203 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
205 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
204 xlabel='dB', ylabel='', title='',
206 xlabel='dB', ylabel='', title='',
205 ytick_visible=False,
207 ytick_visible=False,
206 grid='x')
208 grid='x')
207
209
208 noiseline = numpy.repeat(noisedB[index], len(y))
210 noiseline = numpy.repeat(noisedB[index], len(y))
209 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
211 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
210
212
211 self.draw()
213 self.draw()
212
214
213 if figfile == None:
215 if figfile == None:
214 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
216 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
215 name = str_datetime
217 name = str_datetime
216 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
218 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
217 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
219 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
218 figfile = self.getFilename(name)
220 figfile = self.getFilename(name)
219
221
220 self.save(figpath=figpath,
222 self.save(figpath=figpath,
221 figfile=figfile,
223 figfile=figfile,
222 save=save,
224 save=save,
223 ftp=ftp,
225 ftp=ftp,
224 wr_period=wr_period,
226 wr_period=wr_period,
225 thisDatetime=thisDatetime)
227 thisDatetime=thisDatetime)
228
226
229
227 return dataOut
230 return dataOut
228 @MPDecorator
231 @MPDecorator
229 class CrossSpectraPlot_(Figure):
232 class CrossSpectraPlot_(Figure):
230
233
231 isConfig = None
234 isConfig = None
232 __nsubplots = None
235 __nsubplots = None
233
236
234 WIDTH = None
237 WIDTH = None
235 HEIGHT = None
238 HEIGHT = None
236 WIDTHPROF = None
239 WIDTHPROF = None
237 HEIGHTPROF = None
240 HEIGHTPROF = None
238 PREFIX = 'cspc'
241 PREFIX = 'cspc'
239
242
240 def __init__(self):
243 def __init__(self):
241 Figure.__init__(self)
244 Figure.__init__(self)
242 self.isConfig = False
245 self.isConfig = False
243 self.__nsubplots = 4
246 self.__nsubplots = 4
244 self.counter_imagwr = 0
247 self.counter_imagwr = 0
245 self.WIDTH = 250
248 self.WIDTH = 250
246 self.HEIGHT = 250
249 self.HEIGHT = 250
247 self.WIDTHPROF = 0
250 self.WIDTHPROF = 0
248 self.HEIGHTPROF = 0
251 self.HEIGHTPROF = 0
249
252
250 self.PLOT_CODE = CROSS_CODE
253 self.PLOT_CODE = CROSS_CODE
251 self.FTP_WEI = None
254 self.FTP_WEI = None
252 self.EXP_CODE = None
255 self.EXP_CODE = None
253 self.SUB_EXP_CODE = None
256 self.SUB_EXP_CODE = None
254 self.PLOT_POS = None
257 self.PLOT_POS = None
258
259 self.indice=0
255
260
256 def getSubplots(self):
261 def getSubplots(self):
257
262
258 ncol = 4
263 ncol = 4
259 nrow = self.nplots
264 nrow = self.nplots
260
265
261 return nrow, ncol
266 return nrow, ncol
262
267
263 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
268 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
264
269
265 self.__showprofile = showprofile
270 self.__showprofile = showprofile
266 self.nplots = nplots
271 self.nplots = nplots
267
272
268 ncolspan = 1
273 ncolspan = 1
269 colspan = 1
274 colspan = 1
270
275
271 self.createFigure(id = id,
276 self.createFigure(id = id,
272 wintitle = wintitle,
277 wintitle = wintitle,
273 widthplot = self.WIDTH + self.WIDTHPROF,
278 widthplot = self.WIDTH + self.WIDTHPROF,
274 heightplot = self.HEIGHT + self.HEIGHTPROF,
279 heightplot = self.HEIGHT + self.HEIGHTPROF,
275 show=True)
280 show=True)
276
281
277 nrow, ncol = self.getSubplots()
282 nrow, ncol = self.getSubplots()
278
283
279 counter = 0
284 counter = 0
280 for y in range(nrow):
285 for y in range(nrow):
281 for x in range(ncol):
286 for x in range(ncol):
282 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
287 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
283
288
284 counter += 1
289 counter += 1
285
290
286 def run(self, dataOut, id, wintitle="", pairsList=None,
291 def run(self, dataOut, id, wintitle="", pairsList=None,
287 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
292 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
288 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
293 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
289 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
294 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
290 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
295 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
291 server=None, folder=None, username=None, password=None,
296 server=None, folder=None, username=None, password=None,
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
297 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
293 xaxis='frequency'):
298 xaxis='frequency'):
294
299
295 """
300 """
296
301
297 Input:
302 Input:
298 dataOut :
303 dataOut :
299 id :
304 id :
300 wintitle :
305 wintitle :
301 channelList :
306 channelList :
302 showProfile :
307 showProfile :
303 xmin : None,
308 xmin : None,
304 xmax : None,
309 xmax : None,
305 ymin : None,
310 ymin : None,
306 ymax : None,
311 ymax : None,
307 zmin : None,
312 zmin : None,
308 zmax : None
313 zmax : None
309 """
314 """
310
315
311 if dataOut.flagNoData:
316 if dataOut.flagNoData:
312 return dataOut
317 return dataOut
313
318
314 if pairsList == None:
319 if pairsList == None:
315 pairsIndexList = dataOut.pairsIndexList
320 pairsIndexList = dataOut.pairsIndexList
316 else:
321 else:
317 pairsIndexList = []
322 pairsIndexList = []
318 for pair in pairsList:
323 for pair in pairsList:
319 if pair not in dataOut.pairsList:
324 if pair not in dataOut.pairsList:
320 raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair))
325 raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair))
321 pairsIndexList.append(dataOut.pairsList.index(pair))
326 pairsIndexList.append(dataOut.pairsList.index(pair))
322
327
323 if not pairsIndexList:
328 if not pairsIndexList:
324 return
329 return
325
330
326 if len(pairsIndexList) > 4:
331 if len(pairsIndexList) > 4:
327 pairsIndexList = pairsIndexList[0:4]
332 pairsIndexList = pairsIndexList[0:4]
328
333
329 if normFactor is None:
334 if normFactor is None:
330 factor = dataOut.normFactor
335 factor = dataOut.normFactor
331 else:
336 else:
332 factor = normFactor
337 factor = normFactor
333 x = dataOut.getVelRange(1)
338 x = dataOut.getVelRange(1)
334 y = dataOut.getHeiRange()
339 y = dataOut.getHeiRange()
335 z = dataOut.data_spc[:,:,:]/factor
340 z = dataOut.data_spc[:,:,:]/factor
336 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
341 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
337
342
338 noise = dataOut.noise/factor
343 noise = dataOut.noise/factor
339
344
340 zdB = 10*numpy.log10(z)
345 zdB = 10*numpy.log10(z)
341 noisedB = 10*numpy.log10(noise)
346 noisedB = 10*numpy.log10(noise)
342
347
343 if coh_min == None:
348 if coh_min == None:
344 coh_min = 0.0
349 coh_min = 0.0
345 if coh_max == None:
350 if coh_max == None:
346 coh_max = 1.0
351 coh_max = 1.0
347
352
348 if phase_min == None:
353 if phase_min == None:
349 phase_min = -180
354 phase_min = -180
350 if phase_max == None:
355 if phase_max == None:
351 phase_max = 180
356 phase_max = 180
352
357
353 #thisDatetime = dataOut.datatime
358 #thisDatetime = dataOut.datatime
354 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
359 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
355 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
360 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
356 # xlabel = "Velocity (m/s)"
361 # xlabel = "Velocity (m/s)"
357 ylabel = "Range (Km)"
362 ylabel = "Range (Km)"
358
363
359 if xaxis == "frequency":
364 if xaxis == "frequency":
360 x = dataOut.getFreqRange(1)/1000.
365 x = dataOut.getFreqRange(1)/1000.
361 xlabel = "Frequency (kHz)"
366 xlabel = "Frequency (kHz)"
362
367
363 elif xaxis == "time":
368 elif xaxis == "time":
364 x = dataOut.getAcfRange(1)
369 x = dataOut.getAcfRange(1)
365 xlabel = "Time (ms)"
370 xlabel = "Time (ms)"
366
371
367 else:
372 else:
368 x = dataOut.getVelRange(1)
373 x = dataOut.getVelRange(1)
369 xlabel = "Velocity (m/s)"
374 xlabel = "Velocity (m/s)"
370
375
371 if not self.isConfig:
376 if not self.isConfig:
372
377
373 nplots = len(pairsIndexList)
378 nplots = len(pairsIndexList)
374
379
375 self.setup(id=id,
380 self.setup(id=id,
376 nplots=nplots,
381 nplots=nplots,
377 wintitle=wintitle,
382 wintitle=wintitle,
378 showprofile=False,
383 showprofile=False,
379 show=show)
384 show=show)
380
385
381 avg = numpy.abs(numpy.average(z, axis=1))
386 avg = numpy.abs(numpy.average(z, axis=1))
382 avgdB = 10*numpy.log10(avg)
387 avgdB = 10*numpy.log10(avg)
383
388
384 if xmin == None: xmin = numpy.nanmin(x)
389 if xmin == None: xmin = numpy.nanmin(x)
385 if xmax == None: xmax = numpy.nanmax(x)
390 if xmax == None: xmax = numpy.nanmax(x)
386 if ymin == None: ymin = numpy.nanmin(y)
391 if ymin == None: ymin = numpy.nanmin(y)
387 if ymax == None: ymax = numpy.nanmax(y)
392 if ymax == None: ymax = numpy.nanmax(y)
388 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
393 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
389 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
394 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
390
395
391 self.FTP_WEI = ftp_wei
396 self.FTP_WEI = ftp_wei
392 self.EXP_CODE = exp_code
397 self.EXP_CODE = exp_code
393 self.SUB_EXP_CODE = sub_exp_code
398 self.SUB_EXP_CODE = sub_exp_code
394 self.PLOT_POS = plot_pos
399 self.PLOT_POS = plot_pos
395
400
396 self.isConfig = True
401 self.isConfig = True
397
402
398 self.setWinTitle(title)
403 self.setWinTitle(title)
404
399
405
400 for i in range(self.nplots):
406 for i in range(self.nplots):
401 pair = dataOut.pairsList[pairsIndexList[i]]
407 pair = dataOut.pairsList[pairsIndexList[i]]
402
408
403 chan_index0 = dataOut.channelList.index(pair[0])
409 chan_index0 = dataOut.channelList.index(pair[0])
404 chan_index1 = dataOut.channelList.index(pair[1])
410 chan_index1 = dataOut.channelList.index(pair[1])
405
411
406 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
412 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
407 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
413 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
408 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
414 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
409 axes0 = self.axesList[i*self.__nsubplots]
415 axes0 = self.axesList[i*self.__nsubplots]
410 axes0.pcolor(x, y, zdB,
416 axes0.pcolor(x, y, zdB,
411 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
417 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
412 xlabel=xlabel, ylabel=ylabel, title=title,
418 xlabel=xlabel, ylabel=ylabel, title=title,
413 ticksize=9, colormap=power_cmap, cblabel='')
419 ticksize=9, colormap=power_cmap, cblabel='')
414
420
415 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
421 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
416 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
422 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
417 axes0 = self.axesList[i*self.__nsubplots+1]
423 axes0 = self.axesList[i*self.__nsubplots+1]
418 axes0.pcolor(x, y, zdB,
424 axes0.pcolor(x, y, zdB,
419 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
425 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
420 xlabel=xlabel, ylabel=ylabel, title=title,
426 xlabel=xlabel, ylabel=ylabel, title=title,
421 ticksize=9, colormap=power_cmap, cblabel='')
427 ticksize=9, colormap=power_cmap, cblabel='')
422
428
423 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
429 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
424 coherence = numpy.abs(coherenceComplex)
430 coherence = numpy.abs(coherenceComplex)
425 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
431 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
426 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
432 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
427
433
428 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
434 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
429 axes0 = self.axesList[i*self.__nsubplots+2]
435 axes0 = self.axesList[i*self.__nsubplots+2]
430 axes0.pcolor(x, y, coherence,
436 axes0.pcolor(x, y, coherence,
431 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
437 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
432 xlabel=xlabel, ylabel=ylabel, title=title,
438 xlabel=xlabel, ylabel=ylabel, title=title,
433 ticksize=9, colormap=coherence_cmap, cblabel='')
439 ticksize=9, colormap=coherence_cmap, cblabel='')
434
440
435 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
441 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
436 axes0 = self.axesList[i*self.__nsubplots+3]
442 axes0 = self.axesList[i*self.__nsubplots+3]
437 axes0.pcolor(x, y, phase,
443 axes0.pcolor(x, y, phase,
438 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
444 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
439 xlabel=xlabel, ylabel=ylabel, title=title,
445 xlabel=xlabel, ylabel=ylabel, title=title,
440 ticksize=9, colormap=phase_cmap, cblabel='')
446 ticksize=9, colormap=phase_cmap, cblabel='')
441
447
442
443
444 self.draw()
448 self.draw()
445
449
446 self.save(figpath=figpath,
450 self.save(figpath=figpath,
447 figfile=figfile,
451 figfile=figfile,
448 save=save,
452 save=save,
449 ftp=ftp,
453 ftp=ftp,
450 wr_period=wr_period,
454 wr_period=wr_period,
451 thisDatetime=thisDatetime)
455 thisDatetime=thisDatetime)
452
456
453 return dataOut
457 return dataOut
454
458
455 @MPDecorator
459 @MPDecorator
456 class RTIPlot_(Figure):
460 class RTIPlot_(Figure):
457
461
458 __isConfig = None
462 __isConfig = None
459 __nsubplots = None
463 __nsubplots = None
460
464
461 WIDTHPROF = None
465 WIDTHPROF = None
462 HEIGHTPROF = None
466 HEIGHTPROF = None
463 PREFIX = 'rti'
467 PREFIX = 'rti'
464
468
465 def __init__(self):
469 def __init__(self):
466
470
467 Figure.__init__(self)
471 Figure.__init__(self)
468 self.timerange = None
472 self.timerange = None
469 self.isConfig = False
473 self.isConfig = False
470 self.__nsubplots = 1
474 self.__nsubplots = 1
471
475
472 self.WIDTH = 800
476 self.WIDTH = 800
473 self.HEIGHT = 180
477 self.HEIGHT = 250
474 self.WIDTHPROF = 120
478 self.WIDTHPROF = 120
475 self.HEIGHTPROF = 0
479 self.HEIGHTPROF = 0
476 self.counter_imagwr = 0
480 self.counter_imagwr = 0
477
481
478 self.PLOT_CODE = RTI_CODE
482 self.PLOT_CODE = RTI_CODE
479
483
480 self.FTP_WEI = None
484 self.FTP_WEI = None
481 self.EXP_CODE = None
485 self.EXP_CODE = None
482 self.SUB_EXP_CODE = None
486 self.SUB_EXP_CODE = None
483 self.PLOT_POS = None
487 self.PLOT_POS = None
484 self.tmin = None
488 self.tmin = None
485 self.tmax = None
489 self.tmax = None
486
490
487 self.xmin = None
491 self.xmin = None
488 self.xmax = None
492 self.xmax = None
489
493
490 self.figfile = None
494 self.figfile = None
491
495
492 def getSubplots(self):
496 def getSubplots(self):
493
497
494 ncol = 1
498 ncol = 1
495 nrow = self.nplots
499 nrow = self.nplots
496
500
497 return nrow, ncol
501 return nrow, ncol
498
502
499 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
503 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
500
504
501 self.__showprofile = showprofile
505 self.__showprofile = showprofile
502 self.nplots = nplots
506 self.nplots = nplots
503
507
504 ncolspan = 1
508 ncolspan = 1
505 colspan = 1
509 colspan = 1
506 if showprofile:
510 if showprofile:
507 ncolspan = 7
511 ncolspan = 7
508 colspan = 6
512 colspan = 6
509 self.__nsubplots = 2
513 self.__nsubplots = 2
510
514
511 self.createFigure(id = id,
515 self.createFigure(id = id,
512 wintitle = wintitle,
516 wintitle = wintitle,
513 widthplot = self.WIDTH + self.WIDTHPROF,
517 widthplot = self.WIDTH + self.WIDTHPROF,
514 heightplot = self.HEIGHT + self.HEIGHTPROF,
518 heightplot = self.HEIGHT + self.HEIGHTPROF,
515 show=show)
519 show=show)
516
520
517 nrow, ncol = self.getSubplots()
521 nrow, ncol = self.getSubplots()
518
522
519 counter = 0
523 counter = 0
520 for y in range(nrow):
524 for y in range(nrow):
521 for x in range(ncol):
525 for x in range(ncol):
522
526
523 if counter >= self.nplots:
527 if counter >= self.nplots:
524 break
528 break
525
529
526 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
530 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
527
531
528 if showprofile:
532 if showprofile:
529 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
533 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
530
534
531 counter += 1
535 counter += 1
532
536
533 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
537 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
534 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
538 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
535 timerange=None, colormap='jet',
539 timerange=None, colormap='jet',
536 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
540 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
537 server=None, folder=None, username=None, password=None,
541 server=None, folder=None, username=None, password=None,
538 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
542 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
539
543
540 """
544 """
541
545
542 Input:
546 Input:
543 dataOut :
547 dataOut :
544 id :
548 id :
545 wintitle :
549 wintitle :
546 channelList :
550 channelList :
547 showProfile :
551 showProfile :
548 xmin : None,
552 xmin : None,
549 xmax : None,
553 xmax : None,
550 ymin : None,
554 ymin : None,
551 ymax : None,
555 ymax : None,
552 zmin : None,
556 zmin : None,
553 zmax : None
557 zmax : None
554 """
558 """
555 if dataOut.flagNoData:
559 if dataOut.flagNoData:
556 return dataOut
560 return dataOut
557
561
558 #colormap = kwargs.get('colormap', 'jet')
562 #colormap = kwargs.get('colormap', 'jet')
559 if HEIGHT is not None:
563 if HEIGHT is not None:
560 self.HEIGHT = HEIGHT
564 self.HEIGHT = HEIGHT
561
565
562 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
566 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
563 return
567 return
564
568
565 if channelList == None:
569 if channelList == None:
566 channelIndexList = dataOut.channelIndexList
570 channelIndexList = dataOut.channelIndexList
567 else:
571 else:
568 channelIndexList = []
572 channelIndexList = []
569 for channel in channelList:
573 for channel in channelList:
570 if channel not in dataOut.channelList:
574 if channel not in dataOut.channelList:
571 raise ValueError("Channel %d is not in dataOut.channelList")
575 raise ValueError("Channel %d is not in dataOut.channelList")
572 channelIndexList.append(dataOut.channelList.index(channel))
576 channelIndexList.append(dataOut.channelList.index(channel))
573
577
574 if normFactor is None:
578 if normFactor is None:
575 factor = dataOut.normFactor
579 factor = dataOut.normFactor
576 else:
580 else:
577 factor = normFactor
581 factor = normFactor
578
582
579 #factor = dataOut.normFactor
583 #factor = dataOut.normFactor
580 x = dataOut.getTimeRange()
584 x = dataOut.getTimeRange()
581 y = dataOut.getHeiRange()
585 y = dataOut.getHeiRange()
582
586
583 z = dataOut.data_spc/factor
587 z = dataOut.data_spc/factor
584 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
588 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
585 avg = numpy.average(z, axis=1)
589 avg = numpy.average(z, axis=1)
586 avgdB = 10.*numpy.log10(avg)
590 avgdB = 10.*numpy.log10(avg)
587 # avgdB = dataOut.getPower()
591 # avgdB = dataOut.getPower()
588
592
589
593
590 thisDatetime = dataOut.datatime
594 thisDatetime = dataOut.datatime
591 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
595 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
592 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
596 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
593 xlabel = ""
597 xlabel = ""
594 ylabel = "Range (Km)"
598 ylabel = "Range (Km)"
595
599
596 update_figfile = False
600 update_figfile = False
597
601
598 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
602 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
599 self.counter_imagwr = wr_period
603 self.counter_imagwr = wr_period
600 self.isConfig = False
604 self.isConfig = False
601 update_figfile = True
605 update_figfile = True
602
606
603 if not self.isConfig:
607 if not self.isConfig:
604
608
605 nplots = len(channelIndexList)
609 nplots = len(channelIndexList)
606
610
607 self.setup(id=id,
611 self.setup(id=id,
608 nplots=nplots,
612 nplots=nplots,
609 wintitle=wintitle,
613 wintitle=wintitle,
610 showprofile=showprofile,
614 showprofile=showprofile,
611 show=show)
615 show=show)
612
616
613 if timerange != None:
617 if timerange != None:
614 self.timerange = timerange
618 self.timerange = timerange
615
619
616 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
620 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
617
621
618 noise = dataOut.noise/factor
622 noise = dataOut.noise/factor
619 noisedB = 10*numpy.log10(noise)
623 noisedB = 10*numpy.log10(noise)
620
624
621 if ymin == None: ymin = numpy.nanmin(y)
625 if ymin == None: ymin = numpy.nanmin(y)
622 if ymax == None: ymax = numpy.nanmax(y)
626 if ymax == None: ymax = numpy.nanmax(y)
623 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
627 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
624 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
628 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
625
629
626 self.FTP_WEI = ftp_wei
630 self.FTP_WEI = ftp_wei
627 self.EXP_CODE = exp_code
631 self.EXP_CODE = exp_code
628 self.SUB_EXP_CODE = sub_exp_code
632 self.SUB_EXP_CODE = sub_exp_code
629 self.PLOT_POS = plot_pos
633 self.PLOT_POS = plot_pos
630
634
631 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
635 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
632 self.isConfig = True
636 self.isConfig = True
633 self.figfile = figfile
637 self.figfile = figfile
634 update_figfile = True
638 update_figfile = True
635
639
636 self.setWinTitle(title)
640 self.setWinTitle(title)
637
641
638 for i in range(self.nplots):
642 for i in range(self.nplots):
639 index = channelIndexList[i]
643 index = channelIndexList[i]
640 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
644 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
641 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
645 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
642 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
646 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
643 axes = self.axesList[i*self.__nsubplots]
647 axes = self.axesList[i*self.__nsubplots]
644 zdB = avgdB[index].reshape((1,-1))
648 zdB = avgdB[index].reshape((1,-1))
645 axes.pcolorbuffer(x, y, zdB,
649 axes.pcolorbuffer(x, y, zdB,
646 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
650 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
647 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
651 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
648 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
652 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
649
653
650 if self.__showprofile:
654 if self.__showprofile:
651 axes = self.axesList[i*self.__nsubplots +1]
655 axes = self.axesList[i*self.__nsubplots +1]
652 axes.pline(avgdB[index], y,
656 axes.pline(avgdB[index], y,
653 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
657 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
654 xlabel='dB', ylabel='', title='',
658 xlabel='dB', ylabel='', title='',
655 ytick_visible=False,
659 ytick_visible=False,
656 grid='x')
660 grid='x')
657
661
658 self.draw()
662 self.draw()
659
663
660 self.save(figpath=figpath,
664 self.save(figpath=figpath,
661 figfile=figfile,
665 figfile=figfile,
662 save=save,
666 save=save,
663 ftp=ftp,
667 ftp=ftp,
664 wr_period=wr_period,
668 wr_period=wr_period,
665 thisDatetime=thisDatetime,
669 thisDatetime=thisDatetime,
666 update_figfile=update_figfile)
670 update_figfile=update_figfile)
667 return dataOut
671 return dataOut
668
672
669 @MPDecorator
673 @MPDecorator
670 class CoherenceMap_(Figure):
674 class CoherenceMap_(Figure):
671 isConfig = None
675 isConfig = None
672 __nsubplots = None
676 __nsubplots = None
673
677
674 WIDTHPROF = None
678 WIDTHPROF = None
675 HEIGHTPROF = None
679 HEIGHTPROF = None
676 PREFIX = 'cmap'
680 PREFIX = 'cmap'
677
681
678 def __init__(self):
682 def __init__(self):
679 Figure.__init__(self)
683 Figure.__init__(self)
680 self.timerange = 2*60*60
684 self.timerange = 2*60*60
681 self.isConfig = False
685 self.isConfig = False
682 self.__nsubplots = 1
686 self.__nsubplots = 1
683
687
684 self.WIDTH = 800
688 self.WIDTH = 800
685 self.HEIGHT = 180
689 self.HEIGHT = 180
686 self.WIDTHPROF = 120
690 self.WIDTHPROF = 120
687 self.HEIGHTPROF = 0
691 self.HEIGHTPROF = 0
688 self.counter_imagwr = 0
692 self.counter_imagwr = 0
689
693
690 self.PLOT_CODE = COH_CODE
694 self.PLOT_CODE = COH_CODE
691
695
692 self.FTP_WEI = None
696 self.FTP_WEI = None
693 self.EXP_CODE = None
697 self.EXP_CODE = None
694 self.SUB_EXP_CODE = None
698 self.SUB_EXP_CODE = None
695 self.PLOT_POS = None
699 self.PLOT_POS = None
696 self.counter_imagwr = 0
700 self.counter_imagwr = 0
697
701
698 self.xmin = None
702 self.xmin = None
699 self.xmax = None
703 self.xmax = None
700
704
701 def getSubplots(self):
705 def getSubplots(self):
702 ncol = 1
706 ncol = 1
703 nrow = self.nplots*2
707 nrow = self.nplots*2
704
708
705 return nrow, ncol
709 return nrow, ncol
706
710
707 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
711 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
708 self.__showprofile = showprofile
712 self.__showprofile = showprofile
709 self.nplots = nplots
713 self.nplots = nplots
710
714
711 ncolspan = 1
715 ncolspan = 1
712 colspan = 1
716 colspan = 1
713 if showprofile:
717 if showprofile:
714 ncolspan = 7
718 ncolspan = 7
715 colspan = 6
719 colspan = 6
716 self.__nsubplots = 2
720 self.__nsubplots = 2
717
721
718 self.createFigure(id = id,
722 self.createFigure(id = id,
719 wintitle = wintitle,
723 wintitle = wintitle,
720 widthplot = self.WIDTH + self.WIDTHPROF,
724 widthplot = self.WIDTH + self.WIDTHPROF,
721 heightplot = self.HEIGHT + self.HEIGHTPROF,
725 heightplot = self.HEIGHT + self.HEIGHTPROF,
722 show=True)
726 show=True)
723
727
724 nrow, ncol = self.getSubplots()
728 nrow, ncol = self.getSubplots()
725
729
726 for y in range(nrow):
730 for y in range(nrow):
727 for x in range(ncol):
731 for x in range(ncol):
728
732
729 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
733 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
730
734
731 if showprofile:
735 if showprofile:
732 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
736 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
733
737
734 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
738 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
735 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
739 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
736 timerange=None, phase_min=None, phase_max=None,
740 timerange=None, phase_min=None, phase_max=None,
737 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
741 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
738 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
742 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
739 server=None, folder=None, username=None, password=None,
743 server=None, folder=None, username=None, password=None,
740 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
744 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
741
745
742
746
743 if dataOut.flagNoData:
747 if dataOut.flagNoData:
744 return dataOut
748 return dataOut
745
749
746 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
750 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
747 return
751 return
748
752
749 if pairsList == None:
753 if pairsList == None:
750 pairsIndexList = dataOut.pairsIndexList
754 pairsIndexList = dataOut.pairsIndexList
751 else:
755 else:
752 pairsIndexList = []
756 pairsIndexList = []
753 for pair in pairsList:
757 for pair in pairsList:
754 if pair not in dataOut.pairsList:
758 if pair not in dataOut.pairsList:
755 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
759 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
756 pairsIndexList.append(dataOut.pairsList.index(pair))
760 pairsIndexList.append(dataOut.pairsList.index(pair))
757
761
758 if pairsIndexList == []:
762 if pairsIndexList == []:
759 return
763 return
760
764
761 if len(pairsIndexList) > 4:
765 if len(pairsIndexList) > 4:
762 pairsIndexList = pairsIndexList[0:4]
766 pairsIndexList = pairsIndexList[0:4]
763
767
764 if phase_min == None:
768 if phase_min == None:
765 phase_min = -180
769 phase_min = -180
766 if phase_max == None:
770 if phase_max == None:
767 phase_max = 180
771 phase_max = 180
768
772
769 x = dataOut.getTimeRange()
773 x = dataOut.getTimeRange()
770 y = dataOut.getHeiRange()
774 y = dataOut.getHeiRange()
771
775
772 thisDatetime = dataOut.datatime
776 thisDatetime = dataOut.datatime
773
777
774 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
778 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
775 xlabel = ""
779 xlabel = ""
776 ylabel = "Range (Km)"
780 ylabel = "Range (Km)"
777 update_figfile = False
781 update_figfile = False
778
782
779 if not self.isConfig:
783 if not self.isConfig:
780 nplots = len(pairsIndexList)
784 nplots = len(pairsIndexList)
781 self.setup(id=id,
785 self.setup(id=id,
782 nplots=nplots,
786 nplots=nplots,
783 wintitle=wintitle,
787 wintitle=wintitle,
784 showprofile=showprofile,
788 showprofile=showprofile,
785 show=show)
789 show=show)
786
790
787 if timerange != None:
791 if timerange != None:
788 self.timerange = timerange
792 self.timerange = timerange
789
793
790 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
794 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
791
795
792 if ymin == None: ymin = numpy.nanmin(y)
796 if ymin == None: ymin = numpy.nanmin(y)
793 if ymax == None: ymax = numpy.nanmax(y)
797 if ymax == None: ymax = numpy.nanmax(y)
794 if zmin == None: zmin = 0.
798 if zmin == None: zmin = 0.
795 if zmax == None: zmax = 1.
799 if zmax == None: zmax = 1.
796
800
797 self.FTP_WEI = ftp_wei
801 self.FTP_WEI = ftp_wei
798 self.EXP_CODE = exp_code
802 self.EXP_CODE = exp_code
799 self.SUB_EXP_CODE = sub_exp_code
803 self.SUB_EXP_CODE = sub_exp_code
800 self.PLOT_POS = plot_pos
804 self.PLOT_POS = plot_pos
801
805
802 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
806 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
803
807
804 self.isConfig = True
808 self.isConfig = True
805 update_figfile = True
809 update_figfile = True
806
810
807 self.setWinTitle(title)
811 self.setWinTitle(title)
808
812
809 for i in range(self.nplots):
813 for i in range(self.nplots):
810
814
811 pair = dataOut.pairsList[pairsIndexList[i]]
815 pair = dataOut.pairsList[pairsIndexList[i]]
812
816
813 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
817 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
814 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
818 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
815 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
819 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
816
820
817
821
818 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
822 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
819 coherence = numpy.abs(avgcoherenceComplex)
823 coherence = numpy.abs(avgcoherenceComplex)
820
824
821 z = coherence.reshape((1,-1))
825 z = coherence.reshape((1,-1))
822
826
823 counter = 0
827 counter = 0
824
828
825 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
829 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
826 axes = self.axesList[i*self.__nsubplots*2]
830 axes = self.axesList[i*self.__nsubplots*2]
827 axes.pcolorbuffer(x, y, z,
831 axes.pcolorbuffer(x, y, z,
828 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
832 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
829 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
833 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
830 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
834 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
831
835
832 if self.__showprofile:
836 if self.__showprofile:
833 counter += 1
837 counter += 1
834 axes = self.axesList[i*self.__nsubplots*2 + counter]
838 axes = self.axesList[i*self.__nsubplots*2 + counter]
835 axes.pline(coherence, y,
839 axes.pline(coherence, y,
836 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
840 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
837 xlabel='', ylabel='', title='', ticksize=7,
841 xlabel='', ylabel='', title='', ticksize=7,
838 ytick_visible=False, nxticks=5,
842 ytick_visible=False, nxticks=5,
839 grid='x')
843 grid='x')
840
844
841 counter += 1
845 counter += 1
842
846
843 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
847 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
844
848
845 z = phase.reshape((1,-1))
849 z = phase.reshape((1,-1))
846
850
847 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
851 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
848 axes = self.axesList[i*self.__nsubplots*2 + counter]
852 axes = self.axesList[i*self.__nsubplots*2 + counter]
849 axes.pcolorbuffer(x, y, z,
853 axes.pcolorbuffer(x, y, z,
850 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
854 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
851 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
855 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
852 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
856 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
853
857
854 if self.__showprofile:
858 if self.__showprofile:
855 counter += 1
859 counter += 1
856 axes = self.axesList[i*self.__nsubplots*2 + counter]
860 axes = self.axesList[i*self.__nsubplots*2 + counter]
857 axes.pline(phase, y,
861 axes.pline(phase, y,
858 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
862 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
859 xlabel='', ylabel='', title='', ticksize=7,
863 xlabel='', ylabel='', title='', ticksize=7,
860 ytick_visible=False, nxticks=4,
864 ytick_visible=False, nxticks=4,
861 grid='x')
865 grid='x')
862
866
863 self.draw()
867 self.draw()
864
868
865 if dataOut.ltctime >= self.xmax:
869 if dataOut.ltctime >= self.xmax:
866 self.counter_imagwr = wr_period
870 self.counter_imagwr = wr_period
867 self.isConfig = False
871 self.isConfig = False
868 update_figfile = True
872 update_figfile = True
869
873
870 self.save(figpath=figpath,
874 self.save(figpath=figpath,
871 figfile=figfile,
875 figfile=figfile,
872 save=save,
876 save=save,
873 ftp=ftp,
877 ftp=ftp,
874 wr_period=wr_period,
878 wr_period=wr_period,
875 thisDatetime=thisDatetime,
879 thisDatetime=thisDatetime,
876 update_figfile=update_figfile)
880 update_figfile=update_figfile)
877
881
878 return dataOut
882 return dataOut
879
883
880 @MPDecorator
884 @MPDecorator
881 class PowerProfilePlot_(Figure):
885 class PowerProfilePlot_(Figure):
882
886
883 isConfig = None
887 isConfig = None
884 __nsubplots = None
888 __nsubplots = None
885
889
886 WIDTHPROF = None
890 WIDTHPROF = None
887 HEIGHTPROF = None
891 HEIGHTPROF = None
888 PREFIX = 'spcprofile'
892 PREFIX = 'spcprofile'
889
893
890 def __init__(self):
894 def __init__(self):
891 Figure.__init__(self)
895 Figure.__init__(self)
892 self.isConfig = False
896 self.isConfig = False
893 self.__nsubplots = 1
897 self.__nsubplots = 1
894
898
895 self.PLOT_CODE = POWER_CODE
899 self.PLOT_CODE = POWER_CODE
896
900
897 self.WIDTH = 300
901 self.WIDTH = 300
898 self.HEIGHT = 500
902 self.HEIGHT = 500
899 self.counter_imagwr = 0
903 self.counter_imagwr = 0
900
904
901 def getSubplots(self):
905 def getSubplots(self):
902 ncol = 1
906 ncol = 1
903 nrow = 1
907 nrow = 1
904
908
905 return nrow, ncol
909 return nrow, ncol
906
910
907 def setup(self, id, nplots, wintitle, show):
911 def setup(self, id, nplots, wintitle, show):
908
912
909 self.nplots = nplots
913 self.nplots = nplots
910
914
911 ncolspan = 1
915 ncolspan = 1
912 colspan = 1
916 colspan = 1
913
917
914 self.createFigure(id = id,
918 self.createFigure(id = id,
915 wintitle = wintitle,
919 wintitle = wintitle,
916 widthplot = self.WIDTH,
920 widthplot = self.WIDTH,
917 heightplot = self.HEIGHT,
921 heightplot = self.HEIGHT,
918 show=show)
922 show=show)
919
923
920 nrow, ncol = self.getSubplots()
924 nrow, ncol = self.getSubplots()
921
925
922 counter = 0
926 counter = 0
923 for y in range(nrow):
927 for y in range(nrow):
924 for x in range(ncol):
928 for x in range(ncol):
925 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
929 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
926
930
927 def run(self, dataOut, id, wintitle="", channelList=None,
931 def run(self, dataOut, id, wintitle="", channelList=None,
928 xmin=None, xmax=None, ymin=None, ymax=None,
932 xmin=None, xmax=None, ymin=None, ymax=None,
929 save=False, figpath='./', figfile=None, show=True,
933 save=False, figpath='./', figfile=None, show=True,
930 ftp=False, wr_period=1, server=None,
934 ftp=False, wr_period=1, server=None,
931 folder=None, username=None, password=None):
935 folder=None, username=None, password=None):
932
936
933 if dataOut.flagNoData:
937 if dataOut.flagNoData:
934 return dataOut
938 return dataOut
935
939
936
940
937 if channelList == None:
941 if channelList == None:
938 channelIndexList = dataOut.channelIndexList
942 channelIndexList = dataOut.channelIndexList
939 channelList = dataOut.channelList
943 channelList = dataOut.channelList
940 else:
944 else:
941 channelIndexList = []
945 channelIndexList = []
942 for channel in channelList:
946 for channel in channelList:
943 if channel not in dataOut.channelList:
947 if channel not in dataOut.channelList:
944 raise ValueError("Channel %d is not in dataOut.channelList")
948 raise ValueError("Channel %d is not in dataOut.channelList")
945 channelIndexList.append(dataOut.channelList.index(channel))
949 channelIndexList.append(dataOut.channelList.index(channel))
946
950
947 factor = dataOut.normFactor
951 factor = dataOut.normFactor
948
952
949 y = dataOut.getHeiRange()
953 y = dataOut.getHeiRange()
950
954
951 #for voltage
955 #for voltage
952 if dataOut.type == 'Voltage':
956 if dataOut.type == 'Voltage':
953 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
957 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
954 x = x.real
958 x = x.real
955 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
959 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
956
960
957 #for spectra
961 #for spectra
958 if dataOut.type == 'Spectra':
962 if dataOut.type == 'Spectra':
959 x = dataOut.data_spc[channelIndexList,:,:]/factor
963 x = dataOut.data_spc[channelIndexList,:,:]/factor
960 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
964 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
961 x = numpy.average(x, axis=1)
965 x = numpy.average(x, axis=1)
962
966
963
967
964 xdB = 10*numpy.log10(x)
968 xdB = 10*numpy.log10(x)
965
969
966 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
970 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
967 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
971 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
968 xlabel = "dB"
972 xlabel = "dB"
969 ylabel = "Range (Km)"
973 ylabel = "Range (Km)"
970
974
971 if not self.isConfig:
975 if not self.isConfig:
972
976
973 nplots = 1
977 nplots = 1
974
978
975 self.setup(id=id,
979 self.setup(id=id,
976 nplots=nplots,
980 nplots=nplots,
977 wintitle=wintitle,
981 wintitle=wintitle,
978 show=show)
982 show=show)
979
983
980 if ymin == None: ymin = numpy.nanmin(y)
984 if ymin == None: ymin = numpy.nanmin(y)
981 if ymax == None: ymax = numpy.nanmax(y)
985 if ymax == None: ymax = numpy.nanmax(y)
982 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
986 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
983 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
987 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
984
988
985 self.isConfig = True
989 self.isConfig = True
986
990
987 self.setWinTitle(title)
991 self.setWinTitle(title)
988
992
989 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
993 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
990 axes = self.axesList[0]
994 axes = self.axesList[0]
991
995
992 legendlabels = ["channel %d"%x for x in channelList]
996 legendlabels = ["channel %d"%x for x in channelList]
993 axes.pmultiline(xdB, y,
997 axes.pmultiline(xdB, y,
994 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
998 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
995 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
999 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
996 ytick_visible=True, nxticks=5,
1000 ytick_visible=True, nxticks=5,
997 grid='x')
1001 grid='x')
998
1002
999 self.draw()
1003 self.draw()
1000
1004
1001 self.save(figpath=figpath,
1005 self.save(figpath=figpath,
1002 figfile=figfile,
1006 figfile=figfile,
1003 save=save,
1007 save=save,
1004 ftp=ftp,
1008 ftp=ftp,
1005 wr_period=wr_period,
1009 wr_period=wr_period,
1006 thisDatetime=thisDatetime)
1010 thisDatetime=thisDatetime)
1007
1011
1008 return dataOut
1012 return dataOut
1009
1013
1010 @MPDecorator
1014 @MPDecorator
1011 class SpectraCutPlot_(Figure):
1015 class SpectraCutPlot_(Figure):
1012
1016
1013 isConfig = None
1017 isConfig = None
1014 __nsubplots = None
1018 __nsubplots = None
1015
1019
1016 WIDTHPROF = None
1020 WIDTHPROF = None
1017 HEIGHTPROF = None
1021 HEIGHTPROF = None
1018 PREFIX = 'spc_cut'
1022 PREFIX = 'spc_cut'
1019
1023
1020 def __init__(self):
1024 def __init__(self):
1021 Figure.__init__(self)
1025 Figure.__init__(self)
1022 self.isConfig = False
1026 self.isConfig = False
1023 self.__nsubplots = 1
1027 self.__nsubplots = 1
1024
1028
1025 self.PLOT_CODE = POWER_CODE
1029 self.PLOT_CODE = POWER_CODE
1026
1030
1027 self.WIDTH = 700
1031 self.WIDTH = 700
1028 self.HEIGHT = 500
1032 self.HEIGHT = 500
1029 self.counter_imagwr = 0
1033 self.counter_imagwr = 0
1030
1034
1031 def getSubplots(self):
1035 def getSubplots(self):
1032 ncol = 1
1036 ncol = 1
1033 nrow = 1
1037 nrow = 1
1034
1038
1035 return nrow, ncol
1039 return nrow, ncol
1036
1040
1037 def setup(self, id, nplots, wintitle, show):
1041 def setup(self, id, nplots, wintitle, show):
1038
1042
1039 self.nplots = nplots
1043 self.nplots = nplots
1040
1044
1041 ncolspan = 1
1045 ncolspan = 1
1042 colspan = 1
1046 colspan = 1
1043
1047
1044 self.createFigure(id = id,
1048 self.createFigure(id = id,
1045 wintitle = wintitle,
1049 wintitle = wintitle,
1046 widthplot = self.WIDTH,
1050 widthplot = self.WIDTH,
1047 heightplot = self.HEIGHT,
1051 heightplot = self.HEIGHT,
1048 show=show)
1052 show=show)
1049
1053
1050 nrow, ncol = self.getSubplots()
1054 nrow, ncol = self.getSubplots()
1051
1055
1052 counter = 0
1056 counter = 0
1053 for y in range(nrow):
1057 for y in range(nrow):
1054 for x in range(ncol):
1058 for x in range(ncol):
1055 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1059 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1056
1060
1057 def run(self, dataOut, id, wintitle="", channelList=None,
1061 def run(self, dataOut, id, wintitle="", channelList=None,
1058 xmin=None, xmax=None, ymin=None, ymax=None,
1062 xmin=None, xmax=None, ymin=None, ymax=None,
1059 save=False, figpath='./', figfile=None, show=True,
1063 save=False, figpath='./', figfile=None, show=True,
1060 ftp=False, wr_period=1, server=None,
1064 ftp=False, wr_period=1, server=None,
1061 folder=None, username=None, password=None,
1065 folder=None, username=None, password=None,
1062 xaxis="frequency"):
1066 xaxis="frequency"):
1063
1067
1064 if dataOut.flagNoData:
1068 if dataOut.flagNoData:
1065 return dataOut
1069 return dataOut
1066
1070
1067 if channelList == None:
1071 if channelList == None:
1068 channelIndexList = dataOut.channelIndexList
1072 channelIndexList = dataOut.channelIndexList
1069 channelList = dataOut.channelList
1073 channelList = dataOut.channelList
1070 else:
1074 else:
1071 channelIndexList = []
1075 channelIndexList = []
1072 for channel in channelList:
1076 for channel in channelList:
1073 if channel not in dataOut.channelList:
1077 if channel not in dataOut.channelList:
1074 raise ValueError("Channel %d is not in dataOut.channelList")
1078 raise ValueError("Channel %d is not in dataOut.channelList")
1075 channelIndexList.append(dataOut.channelList.index(channel))
1079 channelIndexList.append(dataOut.channelList.index(channel))
1076
1080
1077 factor = dataOut.normFactor
1081 factor = dataOut.normFactor
1078
1082
1079 y = dataOut.getHeiRange()
1083 y = dataOut.getHeiRange()
1080
1084
1081 z = dataOut.data_spc/factor
1085 z = dataOut.data_spc/factor
1082 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1086 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1083
1087
1084 hei_index = numpy.arange(25)*3 + 20
1088 hei_index = numpy.arange(25)*3 + 20
1085
1089
1086 if xaxis == "frequency":
1090 if xaxis == "frequency":
1087 x = dataOut.getFreqRange()/1000.
1091 x = dataOut.getFreqRange()/1000.
1088 zdB = 10*numpy.log10(z[0,:,hei_index])
1092 zdB = 10*numpy.log10(z[0,:,hei_index])
1089 xlabel = "Frequency (kHz)"
1093 xlabel = "Frequency (kHz)"
1090 ylabel = "Power (dB)"
1094 ylabel = "Power (dB)"
1091
1095
1092 elif xaxis == "time":
1096 elif xaxis == "time":
1093 x = dataOut.getAcfRange()
1097 x = dataOut.getAcfRange()
1094 zdB = z[0,:,hei_index]
1098 zdB = z[0,:,hei_index]
1095 xlabel = "Time (ms)"
1099 xlabel = "Time (ms)"
1096 ylabel = "ACF"
1100 ylabel = "ACF"
1097
1101
1098 else:
1102 else:
1099 x = dataOut.getVelRange()
1103 x = dataOut.getVelRange()
1100 zdB = 10*numpy.log10(z[0,:,hei_index])
1104 zdB = 10*numpy.log10(z[0,:,hei_index])
1101 xlabel = "Velocity (m/s)"
1105 xlabel = "Velocity (m/s)"
1102 ylabel = "Power (dB)"
1106 ylabel = "Power (dB)"
1103
1107
1104 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1108 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1105 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1109 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1106
1110
1107 if not self.isConfig:
1111 if not self.isConfig:
1108
1112
1109 nplots = 1
1113 nplots = 1
1110
1114
1111 self.setup(id=id,
1115 self.setup(id=id,
1112 nplots=nplots,
1116 nplots=nplots,
1113 wintitle=wintitle,
1117 wintitle=wintitle,
1114 show=show)
1118 show=show)
1115
1119
1116 if xmin == None: xmin = numpy.nanmin(x)*0.9
1120 if xmin == None: xmin = numpy.nanmin(x)*0.9
1117 if xmax == None: xmax = numpy.nanmax(x)*1.1
1121 if xmax == None: xmax = numpy.nanmax(x)*1.1
1118 if ymin == None: ymin = numpy.nanmin(zdB)
1122 if ymin == None: ymin = numpy.nanmin(zdB)
1119 if ymax == None: ymax = numpy.nanmax(zdB)
1123 if ymax == None: ymax = numpy.nanmax(zdB)
1120
1124
1121 self.isConfig = True
1125 self.isConfig = True
1122
1126
1123 self.setWinTitle(title)
1127 self.setWinTitle(title)
1124
1128
1125 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1129 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1126 axes = self.axesList[0]
1130 axes = self.axesList[0]
1127
1131
1128 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1132 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1129
1133
1130 axes.pmultilineyaxis( x, zdB,
1134 axes.pmultilineyaxis( x, zdB,
1131 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1132 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1136 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1133 ytick_visible=True, nxticks=5,
1137 ytick_visible=True, nxticks=5,
1134 grid='x')
1138 grid='x')
1135
1139
1136 self.draw()
1140 self.draw()
1137
1141
1138 self.save(figpath=figpath,
1142 self.save(figpath=figpath,
1139 figfile=figfile,
1143 figfile=figfile,
1140 save=save,
1144 save=save,
1141 ftp=ftp,
1145 ftp=ftp,
1142 wr_period=wr_period,
1146 wr_period=wr_period,
1143 thisDatetime=thisDatetime)
1147 thisDatetime=thisDatetime)
1144
1148
1145 return dataOut
1149 return dataOut
1146
1150
1147 @MPDecorator
1151 @MPDecorator
1148 class Noise_(Figure):
1152 class Noise_(Figure):
1149
1153
1150 isConfig = None
1154 isConfig = None
1151 __nsubplots = None
1155 __nsubplots = None
1152
1156
1153 PREFIX = 'noise'
1157 PREFIX = 'noise'
1154
1158
1155
1159
1156 def __init__(self):
1160 def __init__(self):
1157 Figure.__init__(self)
1161 Figure.__init__(self)
1158 self.timerange = 24*60*60
1162 self.timerange = 24*60*60
1159 self.isConfig = False
1163 self.isConfig = False
1160 self.__nsubplots = 1
1164 self.__nsubplots = 1
1161 self.counter_imagwr = 0
1165 self.counter_imagwr = 0
1162 self.WIDTH = 800
1166 self.WIDTH = 800
1163 self.HEIGHT = 400
1167 self.HEIGHT = 400
1164 self.WIDTHPROF = 120
1168 self.WIDTHPROF = 120
1165 self.HEIGHTPROF = 0
1169 self.HEIGHTPROF = 0
1166 self.xdata = None
1170 self.xdata = None
1167 self.ydata = None
1171 self.ydata = None
1168
1172
1169 self.PLOT_CODE = NOISE_CODE
1173 self.PLOT_CODE = NOISE_CODE
1170
1174
1171 self.FTP_WEI = None
1175 self.FTP_WEI = None
1172 self.EXP_CODE = None
1176 self.EXP_CODE = None
1173 self.SUB_EXP_CODE = None
1177 self.SUB_EXP_CODE = None
1174 self.PLOT_POS = None
1178 self.PLOT_POS = None
1175 self.figfile = None
1179 self.figfile = None
1176
1180
1177 self.xmin = None
1181 self.xmin = None
1178 self.xmax = None
1182 self.xmax = None
1179
1183
1180 def getSubplots(self):
1184 def getSubplots(self):
1181
1185
1182 ncol = 1
1186 ncol = 1
1183 nrow = 1
1187 nrow = 1
1184
1188
1185 return nrow, ncol
1189 return nrow, ncol
1186
1190
1187 def openfile(self, filename):
1191 def openfile(self, filename):
1188 dirname = os.path.dirname(filename)
1192 dirname = os.path.dirname(filename)
1189
1193
1190 if not os.path.exists(dirname):
1194 if not os.path.exists(dirname):
1191 os.mkdir(dirname)
1195 os.mkdir(dirname)
1192
1196
1193 f = open(filename,'w+')
1197 f = open(filename,'w+')
1194 f.write('\n\n')
1198 f.write('\n\n')
1195 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1199 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1196 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1200 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1197 f.close()
1201 f.close()
1198
1202
1199 def save_data(self, filename_phase, data, data_datetime):
1203 def save_data(self, filename_phase, data, data_datetime):
1200
1204
1201 f=open(filename_phase,'a')
1205 f=open(filename_phase,'a')
1202
1206
1203 timetuple_data = data_datetime.timetuple()
1207 timetuple_data = data_datetime.timetuple()
1204 day = str(timetuple_data.tm_mday)
1208 day = str(timetuple_data.tm_mday)
1205 month = str(timetuple_data.tm_mon)
1209 month = str(timetuple_data.tm_mon)
1206 year = str(timetuple_data.tm_year)
1210 year = str(timetuple_data.tm_year)
1207 hour = str(timetuple_data.tm_hour)
1211 hour = str(timetuple_data.tm_hour)
1208 minute = str(timetuple_data.tm_min)
1212 minute = str(timetuple_data.tm_min)
1209 second = str(timetuple_data.tm_sec)
1213 second = str(timetuple_data.tm_sec)
1210
1214
1211 data_msg = ''
1215 data_msg = ''
1212 for i in range(len(data)):
1216 for i in range(len(data)):
1213 data_msg += str(data[i]) + ' '
1217 data_msg += str(data[i]) + ' '
1214
1218
1215 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1219 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1216 f.close()
1220 f.close()
1217
1221
1218
1222
1219 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1223 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1220
1224
1221 self.__showprofile = showprofile
1225 self.__showprofile = showprofile
1222 self.nplots = nplots
1226 self.nplots = nplots
1223
1227
1224 ncolspan = 7
1228 ncolspan = 7
1225 colspan = 6
1229 colspan = 6
1226 self.__nsubplots = 2
1230 self.__nsubplots = 2
1227
1231
1228 self.createFigure(id = id,
1232 self.createFigure(id = id,
1229 wintitle = wintitle,
1233 wintitle = wintitle,
1230 widthplot = self.WIDTH+self.WIDTHPROF,
1234 widthplot = self.WIDTH+self.WIDTHPROF,
1231 heightplot = self.HEIGHT+self.HEIGHTPROF,
1235 heightplot = self.HEIGHT+self.HEIGHTPROF,
1232 show=show)
1236 show=show)
1233
1237
1234 nrow, ncol = self.getSubplots()
1238 nrow, ncol = self.getSubplots()
1235
1239
1236 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1240 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1237
1241
1238
1242
1239 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1243 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1240 xmin=None, xmax=None, ymin=None, ymax=None,
1244 xmin=None, xmax=None, ymin=None, ymax=None,
1241 timerange=None,
1245 timerange=None,
1242 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1246 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1243 server=None, folder=None, username=None, password=None,
1247 server=None, folder=None, username=None, password=None,
1244 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1248 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1245
1249
1246 if dataOut.flagNoData:
1250 if dataOut.flagNoData:
1247 return dataOut
1251 return dataOut
1248
1252
1249 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1253 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1250 return
1254 return
1251
1255
1252 if channelList == None:
1256 if channelList == None:
1253 channelIndexList = dataOut.channelIndexList
1257 channelIndexList = dataOut.channelIndexList
1254 channelList = dataOut.channelList
1258 channelList = dataOut.channelList
1255 else:
1259 else:
1256 channelIndexList = []
1260 channelIndexList = []
1257 for channel in channelList:
1261 for channel in channelList:
1258 if channel not in dataOut.channelList:
1262 if channel not in dataOut.channelList:
1259 raise ValueError("Channel %d is not in dataOut.channelList")
1263 raise ValueError("Channel %d is not in dataOut.channelList")
1260 channelIndexList.append(dataOut.channelList.index(channel))
1264 channelIndexList.append(dataOut.channelList.index(channel))
1261
1265
1262 x = dataOut.getTimeRange()
1266 x = dataOut.getTimeRange()
1263 #y = dataOut.getHeiRange()
1267 #y = dataOut.getHeiRange()
1264 factor = dataOut.normFactor
1268 factor = dataOut.normFactor
1265 noise = dataOut.noise[channelIndexList]/factor
1269 noise = dataOut.noise[channelIndexList]/factor
1266 noisedB = 10*numpy.log10(noise)
1270 noisedB = 10*numpy.log10(noise)
1267
1271
1268 thisDatetime = dataOut.datatime
1272 thisDatetime = dataOut.datatime
1269
1273
1270 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1274 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1271 xlabel = ""
1275 xlabel = ""
1272 ylabel = "Intensity (dB)"
1276 ylabel = "Intensity (dB)"
1273 update_figfile = False
1277 update_figfile = False
1274
1278
1275 if not self.isConfig:
1279 if not self.isConfig:
1276
1280
1277 nplots = 1
1281 nplots = 1
1278
1282
1279 self.setup(id=id,
1283 self.setup(id=id,
1280 nplots=nplots,
1284 nplots=nplots,
1281 wintitle=wintitle,
1285 wintitle=wintitle,
1282 showprofile=showprofile,
1286 showprofile=showprofile,
1283 show=show)
1287 show=show)
1284
1288
1285 if timerange != None:
1289 if timerange != None:
1286 self.timerange = timerange
1290 self.timerange = timerange
1287
1291
1288 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1292 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1289
1293
1290 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1294 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1291 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1295 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1292
1296
1293 self.FTP_WEI = ftp_wei
1297 self.FTP_WEI = ftp_wei
1294 self.EXP_CODE = exp_code
1298 self.EXP_CODE = exp_code
1295 self.SUB_EXP_CODE = sub_exp_code
1299 self.SUB_EXP_CODE = sub_exp_code
1296 self.PLOT_POS = plot_pos
1300 self.PLOT_POS = plot_pos
1297
1301
1298
1302
1299 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1300 self.isConfig = True
1304 self.isConfig = True
1301 self.figfile = figfile
1305 self.figfile = figfile
1302 self.xdata = numpy.array([])
1306 self.xdata = numpy.array([])
1303 self.ydata = numpy.array([])
1307 self.ydata = numpy.array([])
1304
1308
1305 update_figfile = True
1309 update_figfile = True
1306
1310
1307 #open file beacon phase
1311 #open file beacon phase
1308 path = '%s%03d' %(self.PREFIX, self.id)
1312 path = '%s%03d' %(self.PREFIX, self.id)
1309 noise_file = os.path.join(path,'%s.txt'%self.name)
1313 noise_file = os.path.join(path,'%s.txt'%self.name)
1310 self.filename_noise = os.path.join(figpath,noise_file)
1314 self.filename_noise = os.path.join(figpath,noise_file)
1311
1315
1312 self.setWinTitle(title)
1316 self.setWinTitle(title)
1313
1317
1314 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1318 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1315
1319
1316 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1320 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1317 axes = self.axesList[0]
1321 axes = self.axesList[0]
1318
1322
1319 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1323 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1320
1324
1321 if len(self.ydata)==0:
1325 if len(self.ydata)==0:
1322 self.ydata = noisedB.reshape(-1,1)
1326 self.ydata = noisedB.reshape(-1,1)
1323 else:
1327 else:
1324 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1328 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1325
1329
1326
1330
1327 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1331 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1328 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1332 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1329 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1333 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1330 XAxisAsTime=True, grid='both'
1334 XAxisAsTime=True, grid='both'
1331 )
1335 )
1332
1336
1333 self.draw()
1337 self.draw()
1334
1338
1335 if dataOut.ltctime >= self.xmax:
1339 if dataOut.ltctime >= self.xmax:
1336 self.counter_imagwr = wr_period
1340 self.counter_imagwr = wr_period
1337 self.isConfig = False
1341 self.isConfig = False
1338 update_figfile = True
1342 update_figfile = True
1339
1343
1340 self.save(figpath=figpath,
1344 self.save(figpath=figpath,
1341 figfile=figfile,
1345 figfile=figfile,
1342 save=save,
1346 save=save,
1343 ftp=ftp,
1347 ftp=ftp,
1344 wr_period=wr_period,
1348 wr_period=wr_period,
1345 thisDatetime=thisDatetime,
1349 thisDatetime=thisDatetime,
1346 update_figfile=update_figfile)
1350 update_figfile=update_figfile)
1347
1351
1348 #store data beacon phase
1352 #store data beacon phase
1349 if save:
1353 if save:
1350 self.save_data(self.filename_noise, noisedB, thisDatetime)
1354 self.save_data(self.filename_noise, noisedB, thisDatetime)
1351
1355
1352 return dataOut
1356 return dataOut
1353
1357
1354 @MPDecorator
1358 @MPDecorator
1355 class BeaconPhase_(Figure):
1359 class BeaconPhase_(Figure):
1356
1360
1357 __isConfig = None
1361 __isConfig = None
1358 __nsubplots = None
1362 __nsubplots = None
1359
1363
1360 PREFIX = 'beacon_phase'
1364 PREFIX = 'beacon_phase'
1361
1365
1362 def __init__(self):
1366 def __init__(self):
1363 Figure.__init__(self)
1367 Figure.__init__(self)
1364 self.timerange = 24*60*60
1368 self.timerange = 24*60*60
1365 self.isConfig = False
1369 self.isConfig = False
1366 self.__nsubplots = 1
1370 self.__nsubplots = 1
1367 self.counter_imagwr = 0
1371 self.counter_imagwr = 0
1368 self.WIDTH = 800
1372 self.WIDTH = 800
1369 self.HEIGHT = 400
1373 self.HEIGHT = 400
1370 self.WIDTHPROF = 120
1374 self.WIDTHPROF = 120
1371 self.HEIGHTPROF = 0
1375 self.HEIGHTPROF = 0
1372 self.xdata = None
1376 self.xdata = None
1373 self.ydata = None
1377 self.ydata = None
1374
1378
1375 self.PLOT_CODE = BEACON_CODE
1379 self.PLOT_CODE = BEACON_CODE
1376
1380
1377 self.FTP_WEI = None
1381 self.FTP_WEI = None
1378 self.EXP_CODE = None
1382 self.EXP_CODE = None
1379 self.SUB_EXP_CODE = None
1383 self.SUB_EXP_CODE = None
1380 self.PLOT_POS = None
1384 self.PLOT_POS = None
1381
1385
1382 self.filename_phase = None
1386 self.filename_phase = None
1383
1387
1384 self.figfile = None
1388 self.figfile = None
1385
1389
1386 self.xmin = None
1390 self.xmin = None
1387 self.xmax = None
1391 self.xmax = None
1388
1392
1389 def getSubplots(self):
1393 def getSubplots(self):
1390
1394
1391 ncol = 1
1395 ncol = 1
1392 nrow = 1
1396 nrow = 1
1393
1397
1394 return nrow, ncol
1398 return nrow, ncol
1395
1399
1396 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1400 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1397
1401
1398 self.__showprofile = showprofile
1402 self.__showprofile = showprofile
1399 self.nplots = nplots
1403 self.nplots = nplots
1400
1404
1401 ncolspan = 7
1405 ncolspan = 7
1402 colspan = 6
1406 colspan = 6
1403 self.__nsubplots = 2
1407 self.__nsubplots = 2
1404
1408
1405 self.createFigure(id = id,
1409 self.createFigure(id = id,
1406 wintitle = wintitle,
1410 wintitle = wintitle,
1407 widthplot = self.WIDTH+self.WIDTHPROF,
1411 widthplot = self.WIDTH+self.WIDTHPROF,
1408 heightplot = self.HEIGHT+self.HEIGHTPROF,
1412 heightplot = self.HEIGHT+self.HEIGHTPROF,
1409 show=show)
1413 show=show)
1410
1414
1411 nrow, ncol = self.getSubplots()
1415 nrow, ncol = self.getSubplots()
1412
1416
1413 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1417 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1414
1418
1415 def save_phase(self, filename_phase):
1419 def save_phase(self, filename_phase):
1416 f = open(filename_phase,'w+')
1420 f = open(filename_phase,'w+')
1417 f.write('\n\n')
1421 f.write('\n\n')
1418 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1422 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1419 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1423 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1420 f.close()
1424 f.close()
1421
1425
1422 def save_data(self, filename_phase, data, data_datetime):
1426 def save_data(self, filename_phase, data, data_datetime):
1423 f=open(filename_phase,'a')
1427 f=open(filename_phase,'a')
1424 timetuple_data = data_datetime.timetuple()
1428 timetuple_data = data_datetime.timetuple()
1425 day = str(timetuple_data.tm_mday)
1429 day = str(timetuple_data.tm_mday)
1426 month = str(timetuple_data.tm_mon)
1430 month = str(timetuple_data.tm_mon)
1427 year = str(timetuple_data.tm_year)
1431 year = str(timetuple_data.tm_year)
1428 hour = str(timetuple_data.tm_hour)
1432 hour = str(timetuple_data.tm_hour)
1429 minute = str(timetuple_data.tm_min)
1433 minute = str(timetuple_data.tm_min)
1430 second = str(timetuple_data.tm_sec)
1434 second = str(timetuple_data.tm_sec)
1431 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1435 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1432 f.close()
1436 f.close()
1433
1437
1434
1438
1435 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1439 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1436 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1440 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1437 timerange=None,
1441 timerange=None,
1438 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1442 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1439 server=None, folder=None, username=None, password=None,
1443 server=None, folder=None, username=None, password=None,
1440 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1444 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1441
1445
1442 if dataOut.flagNoData:
1446 if dataOut.flagNoData:
1443 return dataOut
1447 return dataOut
1444
1448
1445 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1449 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1446 return
1450 return
1447
1451
1448 if pairsList == None:
1452 if pairsList == None:
1449 pairsIndexList = dataOut.pairsIndexList[:10]
1453 pairsIndexList = dataOut.pairsIndexList[:10]
1450 else:
1454 else:
1451 pairsIndexList = []
1455 pairsIndexList = []
1452 for pair in pairsList:
1456 for pair in pairsList:
1453 if pair not in dataOut.pairsList:
1457 if pair not in dataOut.pairsList:
1454 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1458 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1455 pairsIndexList.append(dataOut.pairsList.index(pair))
1459 pairsIndexList.append(dataOut.pairsList.index(pair))
1456
1460
1457 if pairsIndexList == []:
1461 if pairsIndexList == []:
1458 return
1462 return
1459
1463
1460 # if len(pairsIndexList) > 4:
1464 # if len(pairsIndexList) > 4:
1461 # pairsIndexList = pairsIndexList[0:4]
1465 # pairsIndexList = pairsIndexList[0:4]
1462
1466
1463 hmin_index = None
1467 hmin_index = None
1464 hmax_index = None
1468 hmax_index = None
1465
1469
1466 if hmin != None and hmax != None:
1470 if hmin != None and hmax != None:
1467 indexes = numpy.arange(dataOut.nHeights)
1471 indexes = numpy.arange(dataOut.nHeights)
1468 hmin_list = indexes[dataOut.heightList >= hmin]
1472 hmin_list = indexes[dataOut.heightList >= hmin]
1469 hmax_list = indexes[dataOut.heightList <= hmax]
1473 hmax_list = indexes[dataOut.heightList <= hmax]
1470
1474
1471 if hmin_list.any():
1475 if hmin_list.any():
1472 hmin_index = hmin_list[0]
1476 hmin_index = hmin_list[0]
1473
1477
1474 if hmax_list.any():
1478 if hmax_list.any():
1475 hmax_index = hmax_list[-1]+1
1479 hmax_index = hmax_list[-1]+1
1476
1480
1477 x = dataOut.getTimeRange()
1481 x = dataOut.getTimeRange()
1478 #y = dataOut.getHeiRange()
1482 #y = dataOut.getHeiRange()
1479
1483
1480
1484
1481 thisDatetime = dataOut.datatime
1485 thisDatetime = dataOut.datatime
1482
1486
1483 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1487 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1484 xlabel = "Local Time"
1488 xlabel = "Local Time"
1485 ylabel = "Phase (degrees)"
1489 ylabel = "Phase (degrees)"
1486
1490
1487 update_figfile = False
1491 update_figfile = False
1488
1492
1489 nplots = len(pairsIndexList)
1493 nplots = len(pairsIndexList)
1490 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1494 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1491 phase_beacon = numpy.zeros(len(pairsIndexList))
1495 phase_beacon = numpy.zeros(len(pairsIndexList))
1492 for i in range(nplots):
1496 for i in range(nplots):
1493 pair = dataOut.pairsList[pairsIndexList[i]]
1497 pair = dataOut.pairsList[pairsIndexList[i]]
1494 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1498 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1495 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1499 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1496 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1500 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1497 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1501 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1498 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1502 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1499
1503
1500 #print "Phase %d%d" %(pair[0], pair[1])
1501 #print phase[dataOut.beacon_heiIndexList]
1502
1503 if dataOut.beacon_heiIndexList:
1504 if dataOut.beacon_heiIndexList:
1504 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1505 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1505 else:
1506 else:
1506 phase_beacon[i] = numpy.average(phase)
1507 phase_beacon[i] = numpy.average(phase)
1507
1508
1508 if not self.isConfig:
1509 if not self.isConfig:
1509
1510
1510 nplots = len(pairsIndexList)
1511 nplots = len(pairsIndexList)
1511
1512
1512 self.setup(id=id,
1513 self.setup(id=id,
1513 nplots=nplots,
1514 nplots=nplots,
1514 wintitle=wintitle,
1515 wintitle=wintitle,
1515 showprofile=showprofile,
1516 showprofile=showprofile,
1516 show=show)
1517 show=show)
1517
1518
1518 if timerange != None:
1519 if timerange != None:
1519 self.timerange = timerange
1520 self.timerange = timerange
1520
1521
1521 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1522 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1522
1523
1523 if ymin == None: ymin = 0
1524 if ymin == None: ymin = 0
1524 if ymax == None: ymax = 360
1525 if ymax == None: ymax = 360
1525
1526
1526 self.FTP_WEI = ftp_wei
1527 self.FTP_WEI = ftp_wei
1527 self.EXP_CODE = exp_code
1528 self.EXP_CODE = exp_code
1528 self.SUB_EXP_CODE = sub_exp_code
1529 self.SUB_EXP_CODE = sub_exp_code
1529 self.PLOT_POS = plot_pos
1530 self.PLOT_POS = plot_pos
1530
1531
1531 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1532 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1532 self.isConfig = True
1533 self.isConfig = True
1533 self.figfile = figfile
1534 self.figfile = figfile
1534 self.xdata = numpy.array([])
1535 self.xdata = numpy.array([])
1535 self.ydata = numpy.array([])
1536 self.ydata = numpy.array([])
1536
1537
1537 update_figfile = True
1538 update_figfile = True
1538
1539
1539 #open file beacon phase
1540 #open file beacon phase
1540 path = '%s%03d' %(self.PREFIX, self.id)
1541 path = '%s%03d' %(self.PREFIX, self.id)
1541 beacon_file = os.path.join(path,'%s.txt'%self.name)
1542 beacon_file = os.path.join(path,'%s.txt'%self.name)
1542 self.filename_phase = os.path.join(figpath,beacon_file)
1543 self.filename_phase = os.path.join(figpath,beacon_file)
1543 #self.save_phase(self.filename_phase)
1544 #self.save_phase(self.filename_phase)
1544
1545
1545
1546
1546 #store data beacon phase
1547 #store data beacon phase
1547 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1548 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1548
1549
1549 self.setWinTitle(title)
1550 self.setWinTitle(title)
1550
1551
1551
1552
1552 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1553 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1553
1554
1554 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1555 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1555
1556
1556 axes = self.axesList[0]
1557 axes = self.axesList[0]
1557
1558
1558 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1559 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1559
1560
1560 if len(self.ydata)==0:
1561 if len(self.ydata)==0:
1561 self.ydata = phase_beacon.reshape(-1,1)
1562 self.ydata = phase_beacon.reshape(-1,1)
1562 else:
1563 else:
1563 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1564 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1564
1565
1565
1566
1566 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1567 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1567 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1568 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1568 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1569 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1569 XAxisAsTime=True, grid='both'
1570 XAxisAsTime=True, grid='both'
1570 )
1571 )
1571
1572
1572 self.draw()
1573 self.draw()
1573
1574
1574 if dataOut.ltctime >= self.xmax:
1575 if dataOut.ltctime >= self.xmax:
1575 self.counter_imagwr = wr_period
1576 self.counter_imagwr = wr_period
1576 self.isConfig = False
1577 self.isConfig = False
1577 update_figfile = True
1578 update_figfile = True
1578
1579
1579 self.save(figpath=figpath,
1580 self.save(figpath=figpath,
1580 figfile=figfile,
1581 figfile=figfile,
1581 save=save,
1582 save=save,
1582 ftp=ftp,
1583 ftp=ftp,
1583 wr_period=wr_period,
1584 wr_period=wr_period,
1584 thisDatetime=thisDatetime,
1585 thisDatetime=thisDatetime,
1585 update_figfile=update_figfile)
1586 update_figfile=update_figfile)
1586
1587
1587 return dataOut No newline at end of file
1588 return dataOut
@@ -1,501 +1,500
1 import os
1 import os
2 import sys
2 import sys
3 import datetime
3 import datetime
4 import numpy
4 import numpy
5 import matplotlib
5 import matplotlib
6
6
7 if 'BACKEND' in os.environ:
7 if 'BACKEND' in os.environ:
8 matplotlib.use(os.environ['BACKEND'])
8 matplotlib.use(os.environ['BACKEND'])
9 elif 'linux' in sys.platform:
9 elif 'linux' in sys.platform:
10 matplotlib.use("TkAgg")
10 matplotlib.use("TkAgg")
11 elif 'darwin' in sys.platform:
11 elif 'darwin' in sys.platform:
12 matplotlib.use('TkAgg')
12 matplotlib.use('TkAgg')
13 else:
13 else:
14 from schainpy.utils import log
14 from schainpy.utils import log
15 log.warning('Using default Backend="Agg"', 'INFO')
15 log.warning('Using default Backend="Agg"', 'INFO')
16 matplotlib.use('Agg')
16 matplotlib.use('Agg')
17 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
17 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
18 import matplotlib.pyplot
18 import matplotlib.pyplot
19
19
20 from mpl_toolkits.axes_grid1 import make_axes_locatable
20 from mpl_toolkits.axes_grid1 import make_axes_locatable
21 from matplotlib.ticker import FuncFormatter, LinearLocator
21 from matplotlib.ticker import FuncFormatter, LinearLocator
22
22
23 ###########################################
23 ###########################################
24 # Actualizacion de las funciones del driver
24 # Actualizacion de las funciones del driver
25 ###########################################
25 ###########################################
26
26
27 # create jro colormap
27 # create jro colormap
28
28
29 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
29 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
30 blu_values = matplotlib.pyplot.get_cmap(
30 blu_values = matplotlib.pyplot.get_cmap(
31 "seismic_r", 20)(numpy.arange(20))[10:15]
31 "seismic_r", 20)(numpy.arange(20))[10:15]
32 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
32 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
33 "jro", numpy.vstack((blu_values, jet_values)))
33 "jro", numpy.vstack((blu_values, jet_values)))
34 matplotlib.pyplot.register_cmap(cmap=ncmap)
34 matplotlib.pyplot.register_cmap(cmap=ncmap)
35
35
36
36
37 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
37 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
38
38
39 matplotlib.pyplot.ioff()
39 matplotlib.pyplot.ioff()
40
40
41 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
41 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
42 1.0 * width / dpi, 1.0 * height / dpi))
42 1.0 * width / dpi, 1.0 * height / dpi))
43 fig.canvas.manager.set_window_title(wintitle)
43 fig.canvas.manager.set_window_title(wintitle)
44 # fig.canvas.manager.resize(width, height)
44 # fig.canvas.manager.resize(width, height)
45 matplotlib.pyplot.ion()
45 matplotlib.pyplot.ion()
46
46
47 if show:
47 if show:
48 matplotlib.pyplot.show()
48 matplotlib.pyplot.show()
49
49
50 return fig
50 return fig
51
51
52
52
53 def closeFigure(show=False, fig=None):
53 def closeFigure(show=False, fig=None):
54
54
55 # matplotlib.pyplot.ioff()
55 # matplotlib.pyplot.ioff()
56 # matplotlib.pyplot.pause(0)
56 # matplotlib.pyplot.pause(0)
57
57
58 if show:
58 if show:
59 matplotlib.pyplot.show()
59 matplotlib.pyplot.show()
60
60
61 if fig != None:
61 if fig != None:
62 matplotlib.pyplot.close(fig)
62 matplotlib.pyplot.close(fig)
63 # matplotlib.pyplot.pause(0)
63 # matplotlib.pyplot.pause(0)
64 # matplotlib.pyplot.ion()
64 # matplotlib.pyplot.ion()
65
65
66 return
66 return
67
67
68 matplotlib.pyplot.close("all")
68 matplotlib.pyplot.close("all")
69 # matplotlib.pyplot.pause(0)
69 # matplotlib.pyplot.pause(0)
70 # matplotlib.pyplot.ion()
70 # matplotlib.pyplot.ion()
71
71
72 return
72 return
73
73
74
74
75 def saveFigure(fig, filename):
75 def saveFigure(fig, filename):
76
76
77 # matplotlib.pyplot.ioff()
77 # matplotlib.pyplot.ioff()
78 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
78 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
79 # matplotlib.pyplot.ion()
79 # matplotlib.pyplot.ion()
80
80
81
81
82 def clearFigure(fig):
82 def clearFigure(fig):
83
83
84 fig.clf()
84 fig.clf()
85
85
86
86
87 def setWinTitle(fig, title):
87 def setWinTitle(fig, title):
88
88
89 fig.canvas.manager.set_window_title(title)
89 fig.canvas.manager.set_window_title(title)
90
90
91
91
92 def setTitle(fig, title):
92 def setTitle(fig, title):
93
93
94 fig.suptitle(title)
94 fig.suptitle(title)
95
95
96
96
97 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
97 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
98
98
99 matplotlib.pyplot.ioff()
99 matplotlib.pyplot.ioff()
100 matplotlib.pyplot.figure(fig.number)
100 matplotlib.pyplot.figure(fig.number)
101 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
101 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
102 (xpos, ypos),
102 (xpos, ypos),
103 colspan=colspan,
103 colspan=colspan,
104 rowspan=rowspan,
104 rowspan=rowspan,
105 polar=polar)
105 polar=polar)
106
106
107 matplotlib.pyplot.ion()
107 matplotlib.pyplot.ion()
108 return axes
108 return axes
109
109
110
110
111 def setAxesText(ax, text):
111 def setAxesText(ax, text):
112
112
113 ax.annotate(text,
113 ax.annotate(text,
114 xy=(.1, .99),
114 xy=(.1, .99),
115 xycoords='figure fraction',
115 xycoords='figure fraction',
116 horizontalalignment='left',
116 horizontalalignment='left',
117 verticalalignment='top',
117 verticalalignment='top',
118 fontsize=10)
118 fontsize=10)
119
119
120
120
121 def printLabels(ax, xlabel, ylabel, title):
121 def printLabels(ax, xlabel, ylabel, title):
122
122
123 ax.set_xlabel(xlabel, size=11)
123 ax.set_xlabel(xlabel, size=11)
124 ax.set_ylabel(ylabel, size=11)
124 ax.set_ylabel(ylabel, size=11)
125 ax.set_title(title, size=8)
125 ax.set_title(title, size=8)
126
126
127
127
128 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
128 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
129 ticksize=9, xtick_visible=True, ytick_visible=True,
129 ticksize=9, xtick_visible=True, ytick_visible=True,
130 nxticks=4, nyticks=10,
130 nxticks=4, nyticks=10,
131 grid=None, color='blue'):
131 grid=None, color='blue'):
132 """
132 """
133
133
134 Input:
134 Input:
135 grid : None, 'both', 'x', 'y'
135 grid : None, 'both', 'x', 'y'
136 """
136 """
137
137
138 matplotlib.pyplot.ioff()
138 matplotlib.pyplot.ioff()
139
139
140 ax.set_xlim([xmin, xmax])
140 ax.set_xlim([xmin, xmax])
141 ax.set_ylim([ymin, ymax])
141 ax.set_ylim([ymin, ymax])
142
142
143 printLabels(ax, xlabel, ylabel, title)
143 printLabels(ax, xlabel, ylabel, title)
144
144
145 ######################################################
145 ######################################################
146 if (xmax - xmin) <= 1:
146 if (xmax - xmin) <= 1:
147 xtickspos = numpy.linspace(xmin, xmax, nxticks)
147 xtickspos = numpy.linspace(xmin, xmax, nxticks)
148 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
148 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
149 ax.set_xticks(xtickspos)
149 ax.set_xticks(xtickspos)
150 else:
150 else:
151 xtickspos = numpy.arange(nxticks) * \
151 xtickspos = numpy.arange(nxticks) * \
152 int((xmax - xmin) / (nxticks)) + int(xmin)
152 int((xmax - xmin) / (nxticks)) + int(xmin)
153 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
153 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
154 ax.set_xticks(xtickspos)
154 ax.set_xticks(xtickspos)
155
155
156 for tick in ax.get_xticklabels():
156 for tick in ax.get_xticklabels():
157 tick.set_visible(xtick_visible)
157 tick.set_visible(xtick_visible)
158
158
159 for tick in ax.xaxis.get_major_ticks():
159 for tick in ax.xaxis.get_major_ticks():
160 tick.label.set_fontsize(ticksize)
160 tick.label.set_fontsize(ticksize)
161
161
162 ######################################################
162 ######################################################
163 for tick in ax.get_yticklabels():
163 for tick in ax.get_yticklabels():
164 tick.set_visible(ytick_visible)
164 tick.set_visible(ytick_visible)
165
165
166 for tick in ax.yaxis.get_major_ticks():
166 for tick in ax.yaxis.get_major_ticks():
167 tick.label.set_fontsize(ticksize)
167 tick.label.set_fontsize(ticksize)
168
168
169 ax.plot(x, y, color=color)
169 ax.plot(x, y, color=color)
170 iplot = ax.lines[-1]
170 iplot = ax.lines[-1]
171
171
172 ######################################################
172 ######################################################
173 if '0.' in matplotlib.__version__[0:2]:
173 if '0.' in matplotlib.__version__[0:2]:
174 print("The matplotlib version has to be updated to 1.1 or newer")
174 print("The matplotlib version has to be updated to 1.1 or newer")
175 return iplot
175 return iplot
176
176
177 if '1.0.' in matplotlib.__version__[0:4]:
177 if '1.0.' in matplotlib.__version__[0:4]:
178 print("The matplotlib version has to be updated to 1.1 or newer")
178 print("The matplotlib version has to be updated to 1.1 or newer")
179 return iplot
179 return iplot
180
180
181 if grid != None:
181 if grid != None:
182 ax.grid(b=True, which='major', axis=grid)
182 ax.grid(b=True, which='major', axis=grid)
183
183
184 matplotlib.pyplot.tight_layout()
184 matplotlib.pyplot.tight_layout()
185
185
186 matplotlib.pyplot.ion()
186 matplotlib.pyplot.ion()
187
187
188 return iplot
188 return iplot
189
189
190
190
191 def set_linedata(ax, x, y, idline):
191 def set_linedata(ax, x, y, idline):
192
192
193 ax.lines[idline].set_data(x, y)
193 ax.lines[idline].set_data(x, y)
194
194
195
195
196 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
196 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
197
197
198 ax = iplot.axes
198 ax = iplot.axes
199
199
200 printLabels(ax, xlabel, ylabel, title)
200 printLabels(ax, xlabel, ylabel, title)
201
201
202 set_linedata(ax, x, y, idline=0)
202 set_linedata(ax, x, y, idline=0)
203
203
204
204
205 def addpline(ax, x, y, color, linestyle, lw):
205 def addpline(ax, x, y, color, linestyle, lw):
206
206
207 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
207 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
208
208
209
209
210 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
210 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
211 xlabel='', ylabel='', title='', ticksize=9,
211 xlabel='', ylabel='', title='', ticksize=9,
212 colormap='jet', cblabel='', cbsize="5%",
212 colormap='jet', cblabel='', cbsize="5%",
213 XAxisAsTime=False):
213 XAxisAsTime=False):
214
214
215 matplotlib.pyplot.ioff()
215 matplotlib.pyplot.ioff()
216
216
217 divider = make_axes_locatable(ax)
217 divider = make_axes_locatable(ax)
218 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
218 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
219 fig = ax.get_figure()
219 fig = ax.get_figure()
220 fig.add_axes(ax_cb)
220 fig.add_axes(ax_cb)
221
221
222 ax.set_xlim([xmin, xmax])
222 ax.set_xlim([xmin, xmax])
223 ax.set_ylim([ymin, ymax])
223 ax.set_ylim([ymin, ymax])
224
224
225 printLabels(ax, xlabel, ylabel, title)
225 printLabels(ax, xlabel, ylabel, title)
226
226
227 z = numpy.ma.masked_invalid(z)
227 z = numpy.ma.masked_invalid(z)
228 cmap = matplotlib.pyplot.get_cmap(colormap)
228 cmap = matplotlib.pyplot.get_cmap(colormap)
229 cmap.set_bad('black', 1.)
229 cmap.set_bad('black', 1.)
230 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
230 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
231 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
231 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
232 cb.set_label(cblabel)
232 cb.set_label(cblabel)
233
233
234 # for tl in ax_cb.get_yticklabels():
234 # for tl in ax_cb.get_yticklabels():
235 # tl.set_visible(True)
235 # tl.set_visible(True)
236
236
237 for tick in ax.yaxis.get_major_ticks():
237 for tick in ax.yaxis.get_major_ticks():
238 tick.label.set_fontsize(ticksize)
238 tick.label.set_fontsize(ticksize)
239
239
240 for tick in ax.xaxis.get_major_ticks():
240 for tick in ax.xaxis.get_major_ticks():
241 tick.label.set_fontsize(ticksize)
241 tick.label.set_fontsize(ticksize)
242
242
243 for tick in cb.ax.get_yticklabels():
243 for tick in cb.ax.get_yticklabels():
244 tick.set_fontsize(ticksize)
244 tick.set_fontsize(ticksize)
245
245
246 ax_cb.yaxis.tick_right()
246 ax_cb.yaxis.tick_right()
247
247
248 if '0.' in matplotlib.__version__[0:2]:
248 if '0.' in matplotlib.__version__[0:2]:
249 print("The matplotlib version has to be updated to 1.1 or newer")
249 print("The matplotlib version has to be updated to 1.1 or newer")
250 return imesh
250 return imesh
251
251
252 if '1.0.' in matplotlib.__version__[0:4]:
252 if '1.0.' in matplotlib.__version__[0:4]:
253 print("The matplotlib version has to be updated to 1.1 or newer")
253 print("The matplotlib version has to be updated to 1.1 or newer")
254 return imesh
254 return imesh
255
255
256 matplotlib.pyplot.tight_layout()
256 matplotlib.pyplot.tight_layout()
257
257
258 if XAxisAsTime:
258 if XAxisAsTime:
259
259
260 def func(x, pos): return ('%s') % (
260 def func(x, pos): return ('%s') % (
261 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
261 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
262 ax.xaxis.set_major_formatter(FuncFormatter(func))
262 ax.xaxis.set_major_formatter(FuncFormatter(func))
263 ax.xaxis.set_major_locator(LinearLocator(7))
263 ax.xaxis.set_major_locator(LinearLocator(7))
264
264
265 matplotlib.pyplot.ion()
265 matplotlib.pyplot.ion()
266 return imesh
266 return imesh
267
267
268
268
269 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
269 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
270
270
271 z = z.T
271 z = z.T
272 ax = imesh.axes
272 ax = imesh.axes
273 printLabels(ax, xlabel, ylabel, title)
273 printLabels(ax, xlabel, ylabel, title)
274 imesh.set_array(z.ravel())
274 imesh.set_array(z.ravel())
275
275
276
276
277 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
277 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
278
278
279 printLabels(ax, xlabel, ylabel, title)
279 printLabels(ax, xlabel, ylabel, title)
280
280
281 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
281 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
282 cmap=matplotlib.pyplot.get_cmap(colormap))
282 cmap=matplotlib.pyplot.get_cmap(colormap))
283
283
284
284
285 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
285 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
286
286
287 printLabels(ax, xlabel, ylabel, title)
287 printLabels(ax, xlabel, ylabel, title)
288
288
289 ax.collections.remove(ax.collections[0])
289 ax.collections.remove(ax.collections[0])
290
290
291 z = numpy.ma.masked_invalid(z)
291 z = numpy.ma.masked_invalid(z)
292
292
293 cmap = matplotlib.pyplot.get_cmap(colormap)
293 cmap = matplotlib.pyplot.get_cmap(colormap)
294 cmap.set_bad('black', 1.)
294 cmap.set_bad('black', 1.)
295
295
296 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
296 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
297
297
298
298
299 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
299 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
300 ticksize=9, xtick_visible=True, ytick_visible=True,
300 ticksize=9, xtick_visible=True, ytick_visible=True,
301 nxticks=4, nyticks=10,
301 nxticks=4, nyticks=10,
302 grid=None):
302 grid=None):
303 """
303 """
304
304
305 Input:
305 Input:
306 grid : None, 'both', 'x', 'y'
306 grid : None, 'both', 'x', 'y'
307 """
307 """
308
308
309 matplotlib.pyplot.ioff()
309 matplotlib.pyplot.ioff()
310
310
311 lines = ax.plot(x.T, y)
311 lines = ax.plot(x.T, y)
312 leg = ax.legend(lines, legendlabels, loc='upper right')
312 leg = ax.legend(lines, legendlabels, loc='upper right')
313 leg.get_frame().set_alpha(0.5)
313 leg.get_frame().set_alpha(0.5)
314 ax.set_xlim([xmin, xmax])
314 ax.set_xlim([xmin, xmax])
315 ax.set_ylim([ymin, ymax])
315 ax.set_ylim([ymin, ymax])
316 printLabels(ax, xlabel, ylabel, title)
316 printLabels(ax, xlabel, ylabel, title)
317
317
318 xtickspos = numpy.arange(nxticks) * \
318 xtickspos = numpy.arange(nxticks) * \
319 int((xmax - xmin) / (nxticks)) + int(xmin)
319 int((xmax - xmin) / (nxticks)) + int(xmin)
320 ax.set_xticks(xtickspos)
320 ax.set_xticks(xtickspos)
321
321
322 for tick in ax.get_xticklabels():
322 for tick in ax.get_xticklabels():
323 tick.set_visible(xtick_visible)
323 tick.set_visible(xtick_visible)
324
324
325 for tick in ax.xaxis.get_major_ticks():
325 for tick in ax.xaxis.get_major_ticks():
326 tick.label.set_fontsize(ticksize)
326 tick.label.set_fontsize(ticksize)
327
327
328 for tick in ax.get_yticklabels():
328 for tick in ax.get_yticklabels():
329 tick.set_visible(ytick_visible)
329 tick.set_visible(ytick_visible)
330
330
331 for tick in ax.yaxis.get_major_ticks():
331 for tick in ax.yaxis.get_major_ticks():
332 tick.label.set_fontsize(ticksize)
332 tick.label.set_fontsize(ticksize)
333
333
334 iplot = ax.lines[-1]
334 iplot = ax.lines[-1]
335
335
336 if '0.' in matplotlib.__version__[0:2]:
336 if '0.' in matplotlib.__version__[0:2]:
337 print("The matplotlib version has to be updated to 1.1 or newer")
337 print("The matplotlib version has to be updated to 1.1 or newer")
338 return iplot
338 return iplot
339
339
340 if '1.0.' in matplotlib.__version__[0:4]:
340 if '1.0.' in matplotlib.__version__[0:4]:
341 print("The matplotlib version has to be updated to 1.1 or newer")
341 print("The matplotlib version has to be updated to 1.1 or newer")
342 return iplot
342 return iplot
343
343
344 if grid != None:
344 if grid != None:
345 ax.grid(b=True, which='major', axis=grid)
345 ax.grid(b=True, which='major', axis=grid)
346
346
347 matplotlib.pyplot.tight_layout()
347 matplotlib.pyplot.tight_layout()
348
348
349 matplotlib.pyplot.ion()
349 matplotlib.pyplot.ion()
350
350
351 return iplot
351 return iplot
352
352
353
353
354 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
354 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
355
355
356 ax = iplot.axes
356 ax = iplot.axes
357
357
358 printLabels(ax, xlabel, ylabel, title)
358 printLabels(ax, xlabel, ylabel, title)
359
359
360 for i in range(len(ax.lines)):
360 for i in range(len(ax.lines)):
361 line = ax.lines[i]
361 line = ax.lines[i]
362 line.set_data(x[i, :], y)
362 line.set_data(x[i, :], y)
363
363
364
364
365 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
365 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
366 ticksize=9, xtick_visible=True, ytick_visible=True,
366 ticksize=9, xtick_visible=True, ytick_visible=True,
367 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
367 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
368 grid=None, XAxisAsTime=False):
368 grid=None, XAxisAsTime=False):
369 """
369 """
370
370
371 Input:
371 Input:
372 grid : None, 'both', 'x', 'y'
372 grid : None, 'both', 'x', 'y'
373 """
373 """
374
374
375 matplotlib.pyplot.ioff()
375 matplotlib.pyplot.ioff()
376
376
377 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
377 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
378 lines = ax.plot(x, y.T)
378 lines = ax.plot(x, y.T)
379 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
379 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
380 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
380 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
381
381
382 leg = ax.legend(lines, legendlabels,
382 leg = ax.legend(lines, legendlabels,
383 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
383 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
384
384
385 for label in leg.get_texts():
385 for label in leg.get_texts():
386 label.set_fontsize(9)
386 label.set_fontsize(9)
387
387
388 ax.set_xlim([xmin, xmax])
388 ax.set_xlim([xmin, xmax])
389 ax.set_ylim([ymin, ymax])
389 ax.set_ylim([ymin, ymax])
390 printLabels(ax, xlabel, ylabel, title)
390 printLabels(ax, xlabel, ylabel, title)
391
391
392 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
392 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
393 # ax.set_xticks(xtickspos)
393 # ax.set_xticks(xtickspos)
394
394
395 for tick in ax.get_xticklabels():
395 for tick in ax.get_xticklabels():
396 tick.set_visible(xtick_visible)
396 tick.set_visible(xtick_visible)
397
397
398 for tick in ax.xaxis.get_major_ticks():
398 for tick in ax.xaxis.get_major_ticks():
399 tick.label.set_fontsize(ticksize)
399 tick.label.set_fontsize(ticksize)
400
400
401 for tick in ax.get_yticklabels():
401 for tick in ax.get_yticklabels():
402 tick.set_visible(ytick_visible)
402 tick.set_visible(ytick_visible)
403
403
404 for tick in ax.yaxis.get_major_ticks():
404 for tick in ax.yaxis.get_major_ticks():
405 tick.label.set_fontsize(ticksize)
405 tick.label.set_fontsize(ticksize)
406
406
407 iplot = ax.lines[-1]
407 iplot = ax.lines[-1]
408
408
409 if '0.' in matplotlib.__version__[0:2]:
409 if '0.' in matplotlib.__version__[0:2]:
410 print("The matplotlib version has to be updated to 1.1 or newer")
410 print("The matplotlib version has to be updated to 1.1 or newer")
411 return iplot
411 return iplot
412
412
413 if '1.0.' in matplotlib.__version__[0:4]:
413 if '1.0.' in matplotlib.__version__[0:4]:
414 print("The matplotlib version has to be updated to 1.1 or newer")
414 print("The matplotlib version has to be updated to 1.1 or newer")
415 return iplot
415 return iplot
416
416
417 if grid != None:
417 if grid != None:
418 ax.grid(b=True, which='major', axis=grid)
418 ax.grid(b=True, which='major', axis=grid)
419
419
420 matplotlib.pyplot.tight_layout()
420 matplotlib.pyplot.tight_layout()
421
421
422 if XAxisAsTime:
422 if XAxisAsTime:
423
423
424 def func(x, pos): return ('%s') % (
424 def func(x, pos): return ('%s') % (
425 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
425 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
426 ax.xaxis.set_major_formatter(FuncFormatter(func))
426 ax.xaxis.set_major_formatter(FuncFormatter(func))
427 ax.xaxis.set_major_locator(LinearLocator(7))
427 ax.xaxis.set_major_locator(LinearLocator(7))
428
428
429 matplotlib.pyplot.ion()
429 matplotlib.pyplot.ion()
430
430
431 return iplot
431 return iplot
432
432
433
433
434 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
434 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
435
435
436 ax = iplot.axes
436 ax = iplot.axes
437
438 printLabels(ax, xlabel, ylabel, title)
437 printLabels(ax, xlabel, ylabel, title)
439
438
440 for i in range(len(ax.lines)):
439 for i in range(len(ax.lines)):
441 line = ax.lines[i]
440 line = ax.lines[i]
442 line.set_data(x, y[i, :])
441 line.set_data(x, y[i, :])
443
442
444
443
445 def createPolar(ax, x, y,
444 def createPolar(ax, x, y,
446 xlabel='', ylabel='', title='', ticksize=9,
445 xlabel='', ylabel='', title='', ticksize=9,
447 colormap='jet', cblabel='', cbsize="5%",
446 colormap='jet', cblabel='', cbsize="5%",
448 XAxisAsTime=False):
447 XAxisAsTime=False):
449
448
450 matplotlib.pyplot.ioff()
449 matplotlib.pyplot.ioff()
451
450
452 ax.plot(x, y, 'bo', markersize=5)
451 ax.plot(x, y, 'bo', markersize=5)
453 # ax.set_rmax(90)
452 # ax.set_rmax(90)
454 ax.set_ylim(0, 90)
453 ax.set_ylim(0, 90)
455 ax.set_yticks(numpy.arange(0, 90, 20))
454 ax.set_yticks(numpy.arange(0, 90, 20))
456 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
455 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
457 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
456 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
458 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
457 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
459 ax.yaxis.labelpad = 40
458 ax.yaxis.labelpad = 40
460 printLabels(ax, xlabel, ylabel, title)
459 printLabels(ax, xlabel, ylabel, title)
461 iplot = ax.lines[-1]
460 iplot = ax.lines[-1]
462
461
463 if '0.' in matplotlib.__version__[0:2]:
462 if '0.' in matplotlib.__version__[0:2]:
464 print("The matplotlib version has to be updated to 1.1 or newer")
463 print("The matplotlib version has to be updated to 1.1 or newer")
465 return iplot
464 return iplot
466
465
467 if '1.0.' in matplotlib.__version__[0:4]:
466 if '1.0.' in matplotlib.__version__[0:4]:
468 print("The matplotlib version has to be updated to 1.1 or newer")
467 print("The matplotlib version has to be updated to 1.1 or newer")
469 return iplot
468 return iplot
470
469
471 # if grid != None:
470 # if grid != None:
472 # ax.grid(b=True, which='major', axis=grid)
471 # ax.grid(b=True, which='major', axis=grid)
473
472
474 matplotlib.pyplot.tight_layout()
473 matplotlib.pyplot.tight_layout()
475
474
476 matplotlib.pyplot.ion()
475 matplotlib.pyplot.ion()
477
476
478 return iplot
477 return iplot
479
478
480
479
481 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
480 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
482
481
483 ax = iplot.axes
482 ax = iplot.axes
484
483
485 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
484 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
486 printLabels(ax, xlabel, ylabel, title)
485 printLabels(ax, xlabel, ylabel, title)
487
486
488 set_linedata(ax, x, y, idline=0)
487 set_linedata(ax, x, y, idline=0)
489
488
490
489
491 def draw(fig):
490 def draw(fig):
492
491
493 if type(fig) == 'int':
492 if type(fig) == 'int':
494 raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure")
493 raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure")
495
494
496 fig.canvas.draw()
495 fig.canvas.draw()
497
496
498
497
499 def pause(interval=0.000001):
498 def pause(interval=0.000001):
500
499
501 matplotlib.pyplot.pause(interval) No newline at end of file
500 matplotlib.pyplot.pause(interval)
@@ -1,369 +1,368
1 '''
1 '''
2 Created on Nov 9, 2016
2 Created on Nov 9, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6
6
7
7
8 import os
8 import os
9 import sys
9 import sys
10 import time
10 import time
11 import glob
11 import glob
12 import datetime
12 import datetime
13
13
14 import numpy
14 import numpy
15
15
16 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator
16 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator
17 from schainpy.model.data.jrodata import Parameters
17 from schainpy.model.data.jrodata import Parameters
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
19 from schainpy.utils import log
19 from schainpy.utils import log
20
20
21 FILE_HEADER_STRUCTURE = numpy.dtype([
21 FILE_HEADER_STRUCTURE = numpy.dtype([
22 ('FMN', '<u4'),
22 ('FMN', '<u4'),
23 ('nrec', '<u4'),
23 ('nrec', '<u4'),
24 ('fr_offset', '<u4'),
24 ('fr_offset', '<u4'),
25 ('id', '<u4'),
25 ('id', '<u4'),
26 ('site', 'u1', (32,))
26 ('site', 'u1', (32,))
27 ])
27 ])
28
28
29 REC_HEADER_STRUCTURE = numpy.dtype([
29 REC_HEADER_STRUCTURE = numpy.dtype([
30 ('rmn', '<u4'),
30 ('rmn', '<u4'),
31 ('rcounter', '<u4'),
31 ('rcounter', '<u4'),
32 ('nr_offset', '<u4'),
32 ('nr_offset', '<u4'),
33 ('tr_offset', '<u4'),
33 ('tr_offset', '<u4'),
34 ('time', '<u4'),
34 ('time', '<u4'),
35 ('time_msec', '<u4'),
35 ('time_msec', '<u4'),
36 ('tag', 'u1', (32,)),
36 ('tag', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
38 ('lat', '<f4'),
38 ('lat', '<f4'),
39 ('lon', '<f4'),
39 ('lon', '<f4'),
40 ('gps_status', '<u4'),
40 ('gps_status', '<u4'),
41 ('freq', '<u4'),
41 ('freq', '<u4'),
42 ('freq0', '<u4'),
42 ('freq0', '<u4'),
43 ('nchan', '<u4'),
43 ('nchan', '<u4'),
44 ('delta_r', '<u4'),
44 ('delta_r', '<u4'),
45 ('nranges', '<u4'),
45 ('nranges', '<u4'),
46 ('r0', '<u4'),
46 ('r0', '<u4'),
47 ('prf', '<u4'),
47 ('prf', '<u4'),
48 ('ncoh', '<u4'),
48 ('ncoh', '<u4'),
49 ('npoints', '<u4'),
49 ('npoints', '<u4'),
50 ('polarization', '<i4'),
50 ('polarization', '<i4'),
51 ('rx_filter', '<u4'),
51 ('rx_filter', '<u4'),
52 ('nmodes', '<u4'),
52 ('nmodes', '<u4'),
53 ('dmode_index', '<u4'),
53 ('dmode_index', '<u4'),
54 ('dmode_rngcorr', '<u4'),
54 ('dmode_rngcorr', '<u4'),
55 ('nrxs', '<u4'),
55 ('nrxs', '<u4'),
56 ('acf_length', '<u4'),
56 ('acf_length', '<u4'),
57 ('acf_lags', '<u4'),
57 ('acf_lags', '<u4'),
58 ('sea_to_atmos', '<f4'),
58 ('sea_to_atmos', '<f4'),
59 ('sea_notch', '<u4'),
59 ('sea_notch', '<u4'),
60 ('lh_sea', '<u4'),
60 ('lh_sea', '<u4'),
61 ('hh_sea', '<u4'),
61 ('hh_sea', '<u4'),
62 ('nbins_sea', '<u4'),
62 ('nbins_sea', '<u4'),
63 ('min_snr', '<f4'),
63 ('min_snr', '<f4'),
64 ('min_cc', '<f4'),
64 ('min_cc', '<f4'),
65 ('max_time_diff', '<f4')
65 ('max_time_diff', '<f4')
66 ])
66 ])
67
67
68 DATA_STRUCTURE = numpy.dtype([
68 DATA_STRUCTURE = numpy.dtype([
69 ('range', '<u4'),
69 ('range', '<u4'),
70 ('status', '<u4'),
70 ('status', '<u4'),
71 ('zonal', '<f4'),
71 ('zonal', '<f4'),
72 ('meridional', '<f4'),
72 ('meridional', '<f4'),
73 ('vertical', '<f4'),
73 ('vertical', '<f4'),
74 ('zonal_a', '<f4'),
74 ('zonal_a', '<f4'),
75 ('meridional_a', '<f4'),
75 ('meridional_a', '<f4'),
76 ('corrected_fading', '<f4'), # seconds
76 ('corrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
78 ('time_diff', '<f4'),
78 ('time_diff', '<f4'),
79 ('major_axis', '<f4'),
79 ('major_axis', '<f4'),
80 ('axial_ratio', '<f4'),
80 ('axial_ratio', '<f4'),
81 ('orientation', '<f4'),
81 ('orientation', '<f4'),
82 ('sea_power', '<u4'),
82 ('sea_power', '<u4'),
83 ('sea_algorithm', '<u4')
83 ('sea_algorithm', '<u4')
84 ])
84 ])
85
85
86 @MPDecorator
86 @MPDecorator
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
88 '''
88 '''
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
90 '''
90 '''
91
91
92 ext = '.sswma'
92 ext = '.sswma'
93
93
94 def __init__(self):
94 def __init__(self):
95
95
96 ProcessingUnit.__init__(self)
96 ProcessingUnit.__init__(self)
97
97
98 self.dataOut = Parameters()
98 self.dataOut = Parameters()
99 self.counter_records = 0
99 self.counter_records = 0
100 self.flagNoMoreFiles = 0
100 self.flagNoMoreFiles = 0
101 self.isConfig = False
101 self.isConfig = False
102 self.filename = None
102 self.filename = None
103
103
104 def setup(self,
104 def setup(self,
105 path=None,
105 path=None,
106 startDate=None,
106 startDate=None,
107 endDate=None,
107 endDate=None,
108 ext=None,
108 ext=None,
109 startTime=datetime.time(0, 0, 0),
109 startTime=datetime.time(0, 0, 0),
110 endTime=datetime.time(23, 59, 59),
110 endTime=datetime.time(23, 59, 59),
111 timezone=0,
111 timezone=0,
112 status_value=0,
112 status_value=0,
113 **kwargs):
113 **kwargs):
114
115 self.path = path
114 self.path = path
116 self.startDate = startDate
115 self.startDate = startDate
117 self.endDate = endDate
116 self.endDate = endDate
118 self.startTime = startTime
117 self.startTime = startTime
119 self.endTime = endTime
118 self.endTime = endTime
120 self.status_value = status_value
119 self.status_value = status_value
121 self.datatime = datetime.datetime(1900,1,1)
120 self.datatime = datetime.datetime(1900,1,1)
122
121
123 if self.path is None:
122 if self.path is None:
124 raise ValueError("The path is not valid")
123 raise ValueError("The path is not valid")
125
124
126 if ext is None:
125 if ext is None:
127 ext = self.ext
126 ext = self.ext
128
127
129 self.search_files(self.path, startDate, endDate, ext)
128 self.search_files(self.path, startDate, endDate, ext)
130 self.timezone = timezone
129 self.timezone = timezone
131 self.fileIndex = 0
130 self.fileIndex = 0
132
131
133 if not self.fileList:
132 if not self.fileList:
134 raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
133 raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
135 path))
134 path))
136
135
137 self.setNextFile()
136 self.setNextFile()
138
137
139 def search_files(self, path, startDate, endDate, ext):
138 def search_files(self, path, startDate, endDate, ext):
140 '''
139 '''
141 Searching for BLTR rawdata file in path
140 Searching for BLTR rawdata file in path
142 Creating a list of file to proces included in [startDate,endDate]
141 Creating a list of file to proces included in [startDate,endDate]
143
142
144 Input:
143 Input:
145 path - Path to find BLTR rawdata files
144 path - Path to find BLTR rawdata files
146 startDate - Select file from this date
145 startDate - Select file from this date
147 enDate - Select file until this date
146 enDate - Select file until this date
148 ext - Extension of the file to read
147 ext - Extension of the file to read
149 '''
148 '''
150
149
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
150 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
152 foldercounter = 0
151 foldercounter = 0
153 fileList0 = glob.glob1(path, "*%s" % ext)
152 fileList0 = glob.glob1(path, "*%s" % ext)
154 fileList0.sort()
153 fileList0.sort()
155
154
156 self.fileList = []
155 self.fileList = []
157 self.dateFileList = []
156 self.dateFileList = []
158
157
159 for thisFile in fileList0:
158 for thisFile in fileList0:
160 year = thisFile[-14:-10]
159 year = thisFile[-14:-10]
161 if not isNumber(year):
160 if not isNumber(year):
162 continue
161 continue
163
162
164 month = thisFile[-10:-8]
163 month = thisFile[-10:-8]
165 if not isNumber(month):
164 if not isNumber(month):
166 continue
165 continue
167
166
168 day = thisFile[-8:-6]
167 day = thisFile[-8:-6]
169 if not isNumber(day):
168 if not isNumber(day):
170 continue
169 continue
171
170
172 year, month, day = int(year), int(month), int(day)
171 year, month, day = int(year), int(month), int(day)
173 dateFile = datetime.date(year, month, day)
172 dateFile = datetime.date(year, month, day)
174
173
175 if (startDate > dateFile) or (endDate < dateFile):
174 if (startDate > dateFile) or (endDate < dateFile):
176 continue
175 continue
177
176
178 self.fileList.append(thisFile)
177 self.fileList.append(thisFile)
179 self.dateFileList.append(dateFile)
178 self.dateFileList.append(dateFile)
180
179
181 return
180 return
182
181
183 def setNextFile(self):
182 def setNextFile(self):
184
183
185 file_id = self.fileIndex
184 file_id = self.fileIndex
186
185
187 if file_id == len(self.fileList):
186 if file_id == len(self.fileList):
188 self.flagNoMoreFiles = 1
187 self.flagNoMoreFiles = 1
189 return 0
188 return 0
190
189
191 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
190 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
192 filename = os.path.join(self.path, self.fileList[file_id])
191 filename = os.path.join(self.path, self.fileList[file_id])
193
192
194 dirname, name = os.path.split(filename)
193 dirname, name = os.path.split(filename)
195 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
194 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
196 self.siteFile = name.split('.')[0]
195 self.siteFile = name.split('.')[0]
197 if self.filename is not None:
196 if self.filename is not None:
198 self.fp.close()
197 self.fp.close()
199 self.filename = filename
198 self.filename = filename
200 self.fp = open(self.filename, 'rb')
199 self.fp = open(self.filename, 'rb')
201 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
200 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
202 self.nrecords = self.header_file['nrec'][0]
201 self.nrecords = self.header_file['nrec'][0]
203 self.sizeOfFile = os.path.getsize(self.filename)
202 self.sizeOfFile = os.path.getsize(self.filename)
204 self.counter_records = 0
203 self.counter_records = 0
205 self.flagIsNewFile = 0
204 self.flagIsNewFile = 0
206 self.fileIndex += 1
205 self.fileIndex += 1
207
206
208 return 1
207 return 1
209
208
210 def readNextBlock(self):
209 def readNextBlock(self):
211
210
212 while True:
211 while True:
213 if self.counter_records == self.nrecords:
212 if self.counter_records == self.nrecords:
214 self.flagIsNewFile = 1
213 self.flagIsNewFile = 1
215 if not self.setNextFile():
214 if not self.setNextFile():
216 return 0
215 return 0
217
216
218 self.readBlock()
217 self.readBlock()
219
218
220 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
219 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
221 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
220 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
222 log.warning(
221 log.warning(
223 'Reading Record No. {}/{} -> {} [Skipping]'.format(
222 'Reading Record No. {}/{} -> {} [Skipping]'.format(
224 self.counter_records,
223 self.counter_records,
225 self.nrecords,
224 self.nrecords,
226 self.datatime.ctime()),
225 self.datatime.ctime()),
227 'BLTRParamReader')
226 'BLTRParamReader')
228 continue
227 continue
229 break
228 break
230
229
231 log.log('Reading Record No. {}/{} -> {}'.format(
230 log.log('Reading Record No. {}/{} -> {}'.format(
232 self.counter_records,
231 self.counter_records,
233 self.nrecords,
232 self.nrecords,
234 self.datatime.ctime()), 'BLTRParamReader')
233 self.datatime.ctime()), 'BLTRParamReader')
235
234
236 return 1
235 return 1
237
236
238 def readBlock(self):
237 def readBlock(self):
239
238
240 pointer = self.fp.tell()
239 pointer = self.fp.tell()
241 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
240 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
242 self.nchannels = int(header_rec['nchan'][0] / 2)
241 self.nchannels = int(header_rec['nchan'][0] / 2)
243 self.kchan = header_rec['nrxs'][0]
242 self.kchan = header_rec['nrxs'][0]
244 self.nmodes = header_rec['nmodes'][0]
243 self.nmodes = header_rec['nmodes'][0]
245 self.nranges = header_rec['nranges'][0]
244 self.nranges = header_rec['nranges'][0]
246 self.fp.seek(pointer)
245 self.fp.seek(pointer)
247 self.height = numpy.empty((self.nmodes, self.nranges))
246 self.height = numpy.empty((self.nmodes, self.nranges))
248 self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges))
247 self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges))
249 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
248 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
250 self.flagDiscontinuousBlock = 0
249 self.flagDiscontinuousBlock = 0
251
250
252 for mode in range(self.nmodes):
251 for mode in range(self.nmodes):
253 self.readHeader()
252 self.readHeader()
254 data = self.readData()
253 data = self.readData()
255 self.height[mode] = (data[0] - self.correction) / 1000.
254 self.height[mode] = (data[0] - self.correction) / 1000.
256 self.buffer[mode] = data[1]
255 self.buffer[mode] = data[1]
257 self.snr[mode] = data[2]
256 self.snr[mode] = data[2]
258
257
259 self.counter_records = self.counter_records + self.nmodes
258 self.counter_records = self.counter_records + self.nmodes
260
259
261 return
260 return
262
261
263 def readHeader(self):
262 def readHeader(self):
264 '''
263 '''
265 RecordHeader of BLTR rawdata file
264 RecordHeader of BLTR rawdata file
266 '''
265 '''
267
266
268 header_structure = numpy.dtype(
267 header_structure = numpy.dtype(
269 REC_HEADER_STRUCTURE.descr + [
268 REC_HEADER_STRUCTURE.descr + [
270 ('antenna_coord', 'f4', (2, int(self.nchannels))),
269 ('antenna_coord', 'f4', (2, int(self.nchannels))),
271 ('rx_gains', 'u4', (int(self.nchannels),)),
270 ('rx_gains', 'u4', (int(self.nchannels),)),
272 ('rx_analysis', 'u4', (int(self.nchannels),))
271 ('rx_analysis', 'u4', (int(self.nchannels),))
273 ]
272 ]
274 )
273 )
275
274
276 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
275 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
277 self.lat = self.header_rec['lat'][0]
276 self.lat = self.header_rec['lat'][0]
278 self.lon = self.header_rec['lon'][0]
277 self.lon = self.header_rec['lon'][0]
279 self.delta = self.header_rec['delta_r'][0]
278 self.delta = self.header_rec['delta_r'][0]
280 self.correction = self.header_rec['dmode_rngcorr'][0]
279 self.correction = self.header_rec['dmode_rngcorr'][0]
281 self.imode = self.header_rec['dmode_index'][0]
280 self.imode = self.header_rec['dmode_index'][0]
282 self.antenna = self.header_rec['antenna_coord']
281 self.antenna = self.header_rec['antenna_coord']
283 self.rx_gains = self.header_rec['rx_gains']
282 self.rx_gains = self.header_rec['rx_gains']
284 self.time = self.header_rec['time'][0]
283 self.time = self.header_rec['time'][0]
285 dt = datetime.datetime.utcfromtimestamp(self.time)
284 dt = datetime.datetime.utcfromtimestamp(self.time)
286 if dt.date()>self.datatime.date():
285 if dt.date()>self.datatime.date():
287 self.flagDiscontinuousBlock = 1
286 self.flagDiscontinuousBlock = 1
288 self.datatime = dt
287 self.datatime = dt
289
288
290 def readData(self):
289 def readData(self):
291 '''
290 '''
292 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
291 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
293
292
294 Input:
293 Input:
295 status_value - Array data is set to NAN for values that are not equal to status_value
294 status_value - Array data is set to NAN for values that are not equal to status_value
296
295
297 '''
296 '''
298 self.nchannels = int(self.nchannels)
297 self.nchannels = int(self.nchannels)
299
298
300 data_structure = numpy.dtype(
299 data_structure = numpy.dtype(
301 DATA_STRUCTURE.descr + [
300 DATA_STRUCTURE.descr + [
302 ('rx_saturation', 'u4', (self.nchannels,)),
301 ('rx_saturation', 'u4', (self.nchannels,)),
303 ('chan_offset', 'u4', (2 * self.nchannels,)),
302 ('chan_offset', 'u4', (2 * self.nchannels,)),
304 ('rx_amp', 'u4', (self.nchannels,)),
303 ('rx_amp', 'u4', (self.nchannels,)),
305 ('rx_snr', 'f4', (self.nchannels,)),
304 ('rx_snr', 'f4', (self.nchannels,)),
306 ('cross_snr', 'f4', (self.kchan,)),
305 ('cross_snr', 'f4', (self.kchan,)),
307 ('sea_power_relative', 'f4', (self.kchan,))]
306 ('sea_power_relative', 'f4', (self.kchan,))]
308 )
307 )
309
308
310 data = numpy.fromfile(self.fp, data_structure, self.nranges)
309 data = numpy.fromfile(self.fp, data_structure, self.nranges)
311
310
312 height = data['range']
311 height = data['range']
313 winds = numpy.array(
312 winds = numpy.array(
314 (data['zonal'], data['meridional'], data['vertical']))
313 (data['zonal'], data['meridional'], data['vertical']))
315 snr = data['rx_snr'].T
314 snr = data['rx_snr'].T
316
315
317 winds[numpy.where(winds == -9999.)] = numpy.nan
316 winds[numpy.where(winds == -9999.)] = numpy.nan
318 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
317 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
319 snr[numpy.where(snr == -9999.)] = numpy.nan
318 snr[numpy.where(snr == -9999.)] = numpy.nan
320 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
319 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
321 snr = numpy.power(10, snr / 10)
320 snr = numpy.power(10, snr / 10)
322
321
323 return height, winds, snr
322 return height, winds, snr
324
323
325 def set_output(self):
324 def set_output(self):
326 '''
325 '''
327 Storing data from databuffer to dataOut object
326 Storing data from databuffer to dataOut object
328 '''
327 '''
329
328
330 self.dataOut.data_SNR = self.snr
329 self.dataOut.data_SNR = self.snr
331 self.dataOut.height = self.height
330 self.dataOut.height = self.height
332 self.dataOut.data = self.buffer
331 self.dataOut.data = self.buffer
333 self.dataOut.utctimeInit = self.time
332 self.dataOut.utctimeInit = self.time
334 self.dataOut.utctime = self.dataOut.utctimeInit
333 self.dataOut.utctime = self.dataOut.utctimeInit
335 self.dataOut.useLocalTime = False
334 self.dataOut.useLocalTime = False
336 self.dataOut.paramInterval = 157
335 self.dataOut.paramInterval = 157
337 self.dataOut.timezone = self.timezone
336 self.dataOut.timezone = self.timezone
338 self.dataOut.site = self.siteFile
337 self.dataOut.site = self.siteFile
339 self.dataOut.nrecords = self.nrecords / self.nmodes
338 self.dataOut.nrecords = self.nrecords / self.nmodes
340 self.dataOut.sizeOfFile = self.sizeOfFile
339 self.dataOut.sizeOfFile = self.sizeOfFile
341 self.dataOut.lat = self.lat
340 self.dataOut.lat = self.lat
342 self.dataOut.lon = self.lon
341 self.dataOut.lon = self.lon
343 self.dataOut.channelList = list(range(self.nchannels))
342 self.dataOut.channelList = list(range(self.nchannels))
344 self.dataOut.kchan = self.kchan
343 self.dataOut.kchan = self.kchan
345 self.dataOut.delta = self.delta
344 self.dataOut.delta = self.delta
346 self.dataOut.correction = self.correction
345 self.dataOut.correction = self.correction
347 self.dataOut.nmodes = self.nmodes
346 self.dataOut.nmodes = self.nmodes
348 self.dataOut.imode = self.imode
347 self.dataOut.imode = self.imode
349 self.dataOut.antenna = self.antenna
348 self.dataOut.antenna = self.antenna
350 self.dataOut.rx_gains = self.rx_gains
349 self.dataOut.rx_gains = self.rx_gains
351 self.dataOut.flagNoData = False
350 self.dataOut.flagNoData = False
352 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
351 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
353
352
354 def getData(self):
353 def getData(self):
355 '''
354 '''
356 Storing data from databuffer to dataOut object
355 Storing data from databuffer to dataOut object
357 '''
356 '''
358 if self.flagNoMoreFiles:
357 if self.flagNoMoreFiles:
359 self.dataOut.flagNoData = True
358 self.dataOut.flagNoData = True
360 self.dataOut.error = (1, 'No More files to read')
359 self.dataOut.error = (1, 'No More files to read')
361
360
362 if not self.readNextBlock():
361 if not self.readNextBlock():
363 self.dataOut.flagNoData = True
362 self.dataOut.flagNoData = True
364 return 0
363 return 0
365
364
366 self.set_output()
365 self.set_output()
367
366
368 return 1
367 return 1
369 No newline at end of file
368
@@ -1,1828 +1,1828
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import sys
7 import sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import inspect
12 import inspect
13 import time
13 import time
14 import datetime
14 import datetime
15 import traceback
15 import traceback
16 import zmq
16 import zmq
17
17
18 try:
18 try:
19 from gevent import sleep
19 from gevent import sleep
20 except:
20 except:
21 from time import sleep
21 from time import sleep
22
22
23 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
23 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
24 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
24 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
25 from schainpy.utils import log
25 from schainpy.utils import log
26 import schainpy.admin
26 import schainpy.admin
27
27
28 LOCALTIME = True
28 LOCALTIME = True
29
29
30
30
31 def isNumber(cad):
31 def isNumber(cad):
32 """
32 """
33 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
33 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
34
34
35 Excepciones:
35 Excepciones:
36 Si un determinado string no puede ser convertido a numero
36 Si un determinado string no puede ser convertido a numero
37 Input:
37 Input:
38 str, string al cual se le analiza para determinar si convertible a un numero o no
38 str, string al cual se le analiza para determinar si convertible a un numero o no
39
39
40 Return:
40 Return:
41 True : si el string es uno numerico
41 True : si el string es uno numerico
42 False : no es un string numerico
42 False : no es un string numerico
43 """
43 """
44 try:
44 try:
45 float(cad)
45 float(cad)
46 return True
46 return True
47 except:
47 except:
48 return False
48 return False
49
49
50
50
51 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
51 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
52 """
52 """
53 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
53 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
54
54
55 Inputs:
55 Inputs:
56 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
56 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
57
57
58 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
58 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
59 segundos contados desde 01/01/1970.
59 segundos contados desde 01/01/1970.
60 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
60 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
61 segundos contados desde 01/01/1970.
61 segundos contados desde 01/01/1970.
62
62
63 Return:
63 Return:
64 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
64 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
65 fecha especificado, de lo contrario retorna False.
65 fecha especificado, de lo contrario retorna False.
66
66
67 Excepciones:
67 Excepciones:
68 Si el archivo no existe o no puede ser abierto
68 Si el archivo no existe o no puede ser abierto
69 Si la cabecera no puede ser leida.
69 Si la cabecera no puede ser leida.
70
70
71 """
71 """
72 basicHeaderObj = BasicHeader(LOCALTIME)
72 basicHeaderObj = BasicHeader(LOCALTIME)
73
73
74 try:
74 try:
75 fp = open(filename, 'rb')
75 fp = open(filename, 'rb')
76 except IOError:
76 except IOError:
77 print("The file %s can't be opened" % (filename))
77 print("The file %s can't be opened" % (filename))
78 return 0
78 return 0
79
79
80 sts = basicHeaderObj.read(fp)
80 sts = basicHeaderObj.read(fp)
81 fp.close()
81 fp.close()
82
82
83 if not(sts):
83 if not(sts):
84 print("Skipping the file %s because it has not a valid header" % (filename))
84 print("Skipping the file %s because it has not a valid header" % (filename))
85 return 0
85 return 0
86
86
87 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
87 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
88 return 0
88 return 0
89
89
90 return 1
90 return 1
91
91
92
92
93 def isTimeInRange(thisTime, startTime, endTime):
93 def isTimeInRange(thisTime, startTime, endTime):
94 if endTime >= startTime:
94 if endTime >= startTime:
95 if (thisTime < startTime) or (thisTime > endTime):
95 if (thisTime < startTime) or (thisTime > endTime):
96 return 0
96 return 0
97 return 1
97 return 1
98 else:
98 else:
99 if (thisTime < startTime) and (thisTime > endTime):
99 if (thisTime < startTime) and (thisTime > endTime):
100 return 0
100 return 0
101 return 1
101 return 1
102
102
103
103
104 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
104 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
105 """
105 """
106 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
106 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
107
107
108 Inputs:
108 Inputs:
109 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
109 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
110
110
111 startDate : fecha inicial del rango seleccionado en formato datetime.date
111 startDate : fecha inicial del rango seleccionado en formato datetime.date
112
112
113 endDate : fecha final del rango seleccionado en formato datetime.date
113 endDate : fecha final del rango seleccionado en formato datetime.date
114
114
115 startTime : tiempo inicial del rango seleccionado en formato datetime.time
115 startTime : tiempo inicial del rango seleccionado en formato datetime.time
116
116
117 endTime : tiempo final del rango seleccionado en formato datetime.time
117 endTime : tiempo final del rango seleccionado en formato datetime.time
118
118
119 Return:
119 Return:
120 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
120 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
121 fecha especificado, de lo contrario retorna False.
121 fecha especificado, de lo contrario retorna False.
122
122
123 Excepciones:
123 Excepciones:
124 Si el archivo no existe o no puede ser abierto
124 Si el archivo no existe o no puede ser abierto
125 Si la cabecera no puede ser leida.
125 Si la cabecera no puede ser leida.
126
126
127 """
127 """
128
128
129 try:
129 try:
130 fp = open(filename, 'rb')
130 fp = open(filename, 'rb')
131 except IOError:
131 except IOError:
132 print("The file %s can't be opened" % (filename))
132 print("The file %s can't be opened" % (filename))
133 return None
133 return None
134
134
135 firstBasicHeaderObj = BasicHeader(LOCALTIME)
135 firstBasicHeaderObj = BasicHeader(LOCALTIME)
136 systemHeaderObj = SystemHeader()
136 systemHeaderObj = SystemHeader()
137 radarControllerHeaderObj = RadarControllerHeader()
137 radarControllerHeaderObj = RadarControllerHeader()
138 processingHeaderObj = ProcessingHeader()
138 processingHeaderObj = ProcessingHeader()
139
139
140 lastBasicHeaderObj = BasicHeader(LOCALTIME)
140 lastBasicHeaderObj = BasicHeader(LOCALTIME)
141
141
142 sts = firstBasicHeaderObj.read(fp)
142 sts = firstBasicHeaderObj.read(fp)
143
143
144 if not(sts):
144 if not(sts):
145 print("[Reading] Skipping the file %s because it has not a valid header" % (filename))
145 print("[Reading] Skipping the file %s because it has not a valid header" % (filename))
146 return None
146 return None
147
147
148 if not systemHeaderObj.read(fp):
148 if not systemHeaderObj.read(fp):
149 return None
149 return None
150
150
151 if not radarControllerHeaderObj.read(fp):
151 if not radarControllerHeaderObj.read(fp):
152 return None
152 return None
153
153
154 if not processingHeaderObj.read(fp):
154 if not processingHeaderObj.read(fp):
155 return None
155 return None
156
156
157 filesize = os.path.getsize(filename)
157 filesize = os.path.getsize(filename)
158
158
159 offset = processingHeaderObj.blockSize + 24 # header size
159 offset = processingHeaderObj.blockSize + 24 # header size
160
160
161 if filesize <= offset:
161 if filesize <= offset:
162 print("[Reading] %s: This file has not enough data" % filename)
162 print("[Reading] %s: This file has not enough data" % filename)
163 return None
163 return None
164
164
165 fp.seek(-offset, 2)
165 fp.seek(-offset, 2)
166
166
167 sts = lastBasicHeaderObj.read(fp)
167 sts = lastBasicHeaderObj.read(fp)
168
168
169 fp.close()
169 fp.close()
170
170
171 thisDatetime = lastBasicHeaderObj.datatime
171 thisDatetime = lastBasicHeaderObj.datatime
172 thisTime_last_block = thisDatetime.time()
172 thisTime_last_block = thisDatetime.time()
173
173
174 thisDatetime = firstBasicHeaderObj.datatime
174 thisDatetime = firstBasicHeaderObj.datatime
175 thisDate = thisDatetime.date()
175 thisDate = thisDatetime.date()
176 thisTime_first_block = thisDatetime.time()
176 thisTime_first_block = thisDatetime.time()
177
177
178 # General case
178 # General case
179 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
179 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
180 #-----------o----------------------------o-----------
180 #-----------o----------------------------o-----------
181 # startTime endTime
181 # startTime endTime
182
182
183 if endTime >= startTime:
183 if endTime >= startTime:
184 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
184 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
185 return None
185 return None
186
186
187 return thisDatetime
187 return thisDatetime
188
188
189 # If endTime < startTime then endTime belongs to the next day
189 # If endTime < startTime then endTime belongs to the next day
190
190
191 #<<<<<<<<<<<o o>>>>>>>>>>>
191 #<<<<<<<<<<<o o>>>>>>>>>>>
192 #-----------o----------------------------o-----------
192 #-----------o----------------------------o-----------
193 # endTime startTime
193 # endTime startTime
194
194
195 if (thisDate == startDate) and (thisTime_last_block < startTime):
195 if (thisDate == startDate) and (thisTime_last_block < startTime):
196 return None
196 return None
197
197
198 if (thisDate == endDate) and (thisTime_first_block > endTime):
198 if (thisDate == endDate) and (thisTime_first_block > endTime):
199 return None
199 return None
200
200
201 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
201 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
202 return None
202 return None
203
203
204 return thisDatetime
204 return thisDatetime
205
205
206
206
207 def isFolderInDateRange(folder, startDate=None, endDate=None):
207 def isFolderInDateRange(folder, startDate=None, endDate=None):
208 """
208 """
209 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
209 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
210
210
211 Inputs:
211 Inputs:
212 folder : nombre completo del directorio.
212 folder : nombre completo del directorio.
213 Su formato deberia ser "/path_root/?YYYYDDD"
213 Su formato deberia ser "/path_root/?YYYYDDD"
214
214
215 siendo:
215 siendo:
216 YYYY : Anio (ejemplo 2015)
216 YYYY : Anio (ejemplo 2015)
217 DDD : Dia del anio (ejemplo 305)
217 DDD : Dia del anio (ejemplo 305)
218
218
219 startDate : fecha inicial del rango seleccionado en formato datetime.date
219 startDate : fecha inicial del rango seleccionado en formato datetime.date
220
220
221 endDate : fecha final del rango seleccionado en formato datetime.date
221 endDate : fecha final del rango seleccionado en formato datetime.date
222
222
223 Return:
223 Return:
224 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
224 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
225 fecha especificado, de lo contrario retorna False.
225 fecha especificado, de lo contrario retorna False.
226 Excepciones:
226 Excepciones:
227 Si el directorio no tiene el formato adecuado
227 Si el directorio no tiene el formato adecuado
228 """
228 """
229
229
230 basename = os.path.basename(folder)
230 basename = os.path.basename(folder)
231
231
232 if not isRadarFolder(basename):
232 if not isRadarFolder(basename):
233 print("The folder %s has not the rigth format" % folder)
233 print("The folder %s has not the rigth format" % folder)
234 return 0
234 return 0
235
235
236 if startDate and endDate:
236 if startDate and endDate:
237 thisDate = getDateFromRadarFolder(basename)
237 thisDate = getDateFromRadarFolder(basename)
238
238
239 if thisDate < startDate:
239 if thisDate < startDate:
240 return 0
240 return 0
241
241
242 if thisDate > endDate:
242 if thisDate > endDate:
243 return 0
243 return 0
244
244
245 return 1
245 return 1
246
246
247
247
248 def isFileInDateRange(filename, startDate=None, endDate=None):
248 def isFileInDateRange(filename, startDate=None, endDate=None):
249 """
249 """
250 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
250 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
251
251
252 Inputs:
252 Inputs:
253 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
253 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
254
254
255 Su formato deberia ser "?YYYYDDDsss"
255 Su formato deberia ser "?YYYYDDDsss"
256
256
257 siendo:
257 siendo:
258 YYYY : Anio (ejemplo 2015)
258 YYYY : Anio (ejemplo 2015)
259 DDD : Dia del anio (ejemplo 305)
259 DDD : Dia del anio (ejemplo 305)
260 sss : set
260 sss : set
261
261
262 startDate : fecha inicial del rango seleccionado en formato datetime.date
262 startDate : fecha inicial del rango seleccionado en formato datetime.date
263
263
264 endDate : fecha final del rango seleccionado en formato datetime.date
264 endDate : fecha final del rango seleccionado en formato datetime.date
265
265
266 Return:
266 Return:
267 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
267 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
268 fecha especificado, de lo contrario retorna False.
268 fecha especificado, de lo contrario retorna False.
269 Excepciones:
269 Excepciones:
270 Si el archivo no tiene el formato adecuado
270 Si el archivo no tiene el formato adecuado
271 """
271 """
272
272
273 basename = os.path.basename(filename)
273 basename = os.path.basename(filename)
274
274
275 if not isRadarFile(basename):
275 if not isRadarFile(basename):
276 print("The filename %s has not the rigth format" % filename)
276 print("The filename %s has not the rigth format" % filename)
277 return 0
277 return 0
278
278
279 if startDate and endDate:
279 if startDate and endDate:
280 thisDate = getDateFromRadarFile(basename)
280 thisDate = getDateFromRadarFile(basename)
281
281
282 if thisDate < startDate:
282 if thisDate < startDate:
283 return 0
283 return 0
284
284
285 if thisDate > endDate:
285 if thisDate > endDate:
286 return 0
286 return 0
287
287
288 return 1
288 return 1
289
289
290
290
291 def getFileFromSet(path, ext, set):
291 def getFileFromSet(path, ext, set):
292 validFilelist = []
292 validFilelist = []
293 fileList = os.listdir(path)
293 fileList = os.listdir(path)
294
294
295 # 0 1234 567 89A BCDE
295 # 0 1234 567 89A BCDE
296 # H YYYY DDD SSS .ext
296 # H YYYY DDD SSS .ext
297
297
298 for thisFile in fileList:
298 for thisFile in fileList:
299 try:
299 try:
300 year = int(thisFile[1:5])
300 year = int(thisFile[1:5])
301 doy = int(thisFile[5:8])
301 doy = int(thisFile[5:8])
302 except:
302 except:
303 continue
303 continue
304
304
305 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
305 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
306 continue
306 continue
307
307
308 validFilelist.append(thisFile)
308 validFilelist.append(thisFile)
309
309
310 myfile = fnmatch.filter(
310 myfile = fnmatch.filter(
311 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
311 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
312
312
313 if len(myfile) != 0:
313 if len(myfile) != 0:
314 return myfile[0]
314 return myfile[0]
315 else:
315 else:
316 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
316 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
317 print('the filename %s does not exist' % filename)
317 print('the filename %s does not exist' % filename)
318 print('...going to the last file: ')
318 print('...going to the last file: ')
319
319
320 if validFilelist:
320 if validFilelist:
321 validFilelist = sorted(validFilelist, key=str.lower)
321 validFilelist = sorted(validFilelist, key=str.lower)
322 return validFilelist[-1]
322 return validFilelist[-1]
323
323
324 return None
324 return None
325
325
326
326
327 def getlastFileFromPath(path, ext):
327 def getlastFileFromPath(path, ext):
328 """
328 """
329 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
329 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
330 al final de la depuracion devuelve el ultimo file de la lista que quedo.
330 al final de la depuracion devuelve el ultimo file de la lista que quedo.
331
331
332 Input:
332 Input:
333 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
333 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
334 ext : extension de los files contenidos en una carpeta
334 ext : extension de los files contenidos en una carpeta
335
335
336 Return:
336 Return:
337 El ultimo file de una determinada carpeta, no se considera el path.
337 El ultimo file de una determinada carpeta, no se considera el path.
338 """
338 """
339 validFilelist = []
339 validFilelist = []
340 fileList = os.listdir(path)
340 fileList = os.listdir(path)
341
341
342 # 0 1234 567 89A BCDE
342 # 0 1234 567 89A BCDE
343 # H YYYY DDD SSS .ext
343 # H YYYY DDD SSS .ext
344
344
345 for thisFile in fileList:
345 for thisFile in fileList:
346
346
347 year = thisFile[1:5]
347 year = thisFile[1:5]
348 if not isNumber(year):
348 if not isNumber(year):
349 continue
349 continue
350
350
351 doy = thisFile[5:8]
351 doy = thisFile[5:8]
352 if not isNumber(doy):
352 if not isNumber(doy):
353 continue
353 continue
354
354
355 year = int(year)
355 year = int(year)
356 doy = int(doy)
356 doy = int(doy)
357
357
358 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
358 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
359 continue
359 continue
360
360
361 validFilelist.append(thisFile)
361 validFilelist.append(thisFile)
362
362
363 if validFilelist:
363 if validFilelist:
364 validFilelist = sorted(validFilelist, key=str.lower)
364 validFilelist = sorted(validFilelist, key=str.lower)
365 return validFilelist[-1]
365 return validFilelist[-1]
366
366
367 return None
367 return None
368
368
369
369
370 def checkForRealPath(path, foldercounter, year, doy, set, ext):
370 def checkForRealPath(path, foldercounter, year, doy, set, ext):
371 """
371 """
372 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
372 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
373 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
373 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
374 el path exacto de un determinado file.
374 el path exacto de un determinado file.
375
375
376 Example :
376 Example :
377 nombre correcto del file es .../.../D2009307/P2009307367.ext
377 nombre correcto del file es .../.../D2009307/P2009307367.ext
378
378
379 Entonces la funcion prueba con las siguientes combinaciones
379 Entonces la funcion prueba con las siguientes combinaciones
380 .../.../y2009307367.ext
380 .../.../y2009307367.ext
381 .../.../Y2009307367.ext
381 .../.../Y2009307367.ext
382 .../.../x2009307/y2009307367.ext
382 .../.../x2009307/y2009307367.ext
383 .../.../x2009307/Y2009307367.ext
383 .../.../x2009307/Y2009307367.ext
384 .../.../X2009307/y2009307367.ext
384 .../.../X2009307/y2009307367.ext
385 .../.../X2009307/Y2009307367.ext
385 .../.../X2009307/Y2009307367.ext
386 siendo para este caso, la ultima combinacion de letras, identica al file buscado
386 siendo para este caso, la ultima combinacion de letras, identica al file buscado
387
387
388 Return:
388 Return:
389 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
389 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
390 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
390 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
391 para el filename
391 para el filename
392 """
392 """
393 fullfilename = None
393 fullfilename = None
394 find_flag = False
394 find_flag = False
395 filename = None
395 filename = None
396
396
397 prefixDirList = [None, 'd', 'D']
397 prefixDirList = [None, 'd', 'D']
398 if ext.lower() == ".r": # voltage
398 if ext.lower() == ".r": # voltage
399 prefixFileList = ['d', 'D']
399 prefixFileList = ['d', 'D']
400 elif ext.lower() == ".pdata": # spectra
400 elif ext.lower() == ".pdata": # spectra
401 prefixFileList = ['p', 'P']
401 prefixFileList = ['p', 'P']
402 else:
402 else:
403 return None, filename
403 return None, filename
404
404
405 # barrido por las combinaciones posibles
405 # barrido por las combinaciones posibles
406 for prefixDir in prefixDirList:
406 for prefixDir in prefixDirList:
407 thispath = path
407 thispath = path
408 if prefixDir != None:
408 if prefixDir != None:
409 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
409 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
410 if foldercounter == 0:
410 if foldercounter == 0:
411 thispath = os.path.join(path, "%s%04d%03d" %
411 thispath = os.path.join(path, "%s%04d%03d" %
412 (prefixDir, year, doy))
412 (prefixDir, year, doy))
413 else:
413 else:
414 thispath = os.path.join(path, "%s%04d%03d_%02d" % (
414 thispath = os.path.join(path, "%s%04d%03d_%02d" % (
415 prefixDir, year, doy, foldercounter))
415 prefixDir, year, doy, foldercounter))
416 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
416 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
417 # formo el nombre del file xYYYYDDDSSS.ext
417 # formo el nombre del file xYYYYDDDSSS.ext
418 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
418 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
419 fullfilename = os.path.join(
419 fullfilename = os.path.join(
420 thispath, filename) # formo el path completo
420 thispath, filename) # formo el path completo
421
421
422 if os.path.exists(fullfilename): # verifico que exista
422 if os.path.exists(fullfilename): # verifico que exista
423 find_flag = True
423 find_flag = True
424 break
424 break
425 if find_flag:
425 if find_flag:
426 break
426 break
427
427
428 if not(find_flag):
428 if not(find_flag):
429 return None, filename
429 return None, filename
430
430
431 return fullfilename, filename
431 return fullfilename, filename
432
432
433
433
434 def isRadarFolder(folder):
434 def isRadarFolder(folder):
435 try:
435 try:
436 year = int(folder[1:5])
436 year = int(folder[1:5])
437 doy = int(folder[5:8])
437 doy = int(folder[5:8])
438 except:
438 except:
439 return 0
439 return 0
440
440
441 return 1
441 return 1
442
442
443
443
444 def isRadarFile(file):
444 def isRadarFile(file):
445 try:
445 try:
446 year = int(file[1:5])
446 year = int(file[1:5])
447 doy = int(file[5:8])
447 doy = int(file[5:8])
448 set = int(file[8:11])
448 set = int(file[8:11])
449 except:
449 except:
450 return 0
450 return 0
451
451
452 return 1
452 return 1
453
453
454
454
455 def getDateFromRadarFile(file):
455 def getDateFromRadarFile(file):
456 try:
456 try:
457 year = int(file[1:5])
457 year = int(file[1:5])
458 doy = int(file[5:8])
458 doy = int(file[5:8])
459 set = int(file[8:11])
459 set = int(file[8:11])
460 except:
460 except:
461 return None
461 return None
462
462
463 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
463 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
464 return thisDate
464 return thisDate
465
465
466
466
467 def getDateFromRadarFolder(folder):
467 def getDateFromRadarFolder(folder):
468 try:
468 try:
469 year = int(folder[1:5])
469 year = int(folder[1:5])
470 doy = int(folder[5:8])
470 doy = int(folder[5:8])
471 except:
471 except:
472 return None
472 return None
473
473
474 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
474 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
475 return thisDate
475 return thisDate
476
476
477
477
478 class JRODataIO:
478 class JRODataIO:
479
479
480 c = 3E8
480 c = 3E8
481
481
482 isConfig = False
482 isConfig = False
483
483
484 basicHeaderObj = None
484 basicHeaderObj = None
485
485
486 systemHeaderObj = None
486 systemHeaderObj = None
487
487
488 radarControllerHeaderObj = None
488 radarControllerHeaderObj = None
489
489
490 processingHeaderObj = None
490 processingHeaderObj = None
491
491
492 dtype = None
492 dtype = None
493
493
494 pathList = []
494 pathList = []
495
495
496 filenameList = []
496 filenameList = []
497
497
498 filename = None
498 filename = None
499
499
500 ext = None
500 ext = None
501
501
502 flagIsNewFile = 1
502 flagIsNewFile = 1
503
503
504 flagDiscontinuousBlock = 0
504 flagDiscontinuousBlock = 0
505
505
506 flagIsNewBlock = 0
506 flagIsNewBlock = 0
507
507
508 fp = None
508 fp = None
509
509
510 firstHeaderSize = 0
510 firstHeaderSize = 0
511
511
512 basicHeaderSize = 24
512 basicHeaderSize = 24
513
513
514 versionFile = 1103
514 versionFile = 1103
515
515
516 fileSize = None
516 fileSize = None
517
517
518 # ippSeconds = None
518 # ippSeconds = None
519
519
520 fileSizeByHeader = None
520 fileSizeByHeader = None
521
521
522 fileIndex = None
522 fileIndex = None
523
523
524 profileIndex = None
524 profileIndex = None
525
525
526 blockIndex = None
526 blockIndex = None
527
527
528 nTotalBlocks = None
528 nTotalBlocks = None
529
529
530 maxTimeStep = 30
530 maxTimeStep = 30
531
531
532 lastUTTime = None
532 lastUTTime = None
533
533
534 datablock = None
534 datablock = None
535
535
536 dataOut = None
536 dataOut = None
537
537
538 blocksize = None
538 blocksize = None
539
539
540 getByBlock = False
540 getByBlock = False
541
541
542 def __init__(self):
542 def __init__(self):
543
543
544 raise NotImplementedError
544 raise NotImplementedError
545
545
546 def run(self):
546 def run(self):
547
547
548 raise NotImplementedError
548 raise NotImplementedError
549
549
550 def getDtypeWidth(self):
550 def getDtypeWidth(self):
551
551
552 dtype_index = get_dtype_index(self.dtype)
552 dtype_index = get_dtype_index(self.dtype)
553 dtype_width = get_dtype_width(dtype_index)
553 dtype_width = get_dtype_width(dtype_index)
554
554
555 return dtype_width
555 return dtype_width
556
556
557 def getAllowedArgs(self):
557 def getAllowedArgs(self):
558 if hasattr(self, '__attrs__'):
558 if hasattr(self, '__attrs__'):
559 return self.__attrs__
559 return self.__attrs__
560 else:
560 else:
561 return inspect.getargspec(self.run).args
561 return inspect.getargspec(self.run).args
562
562
563
563
564 class JRODataReader(JRODataIO):
564 class JRODataReader(JRODataIO):
565
565
566 online = 0
566 online = 0
567
567
568 realtime = 0
568 realtime = 0
569
569
570 nReadBlocks = 0
570 nReadBlocks = 0
571
571
572 delay = 10 # number of seconds waiting a new file
572 delay = 10 # number of seconds waiting a new file
573
573
574 nTries = 3 # quantity tries
574 nTries = 3 # quantity tries
575
575
576 nFiles = 3 # number of files for searching
576 nFiles = 3 # number of files for searching
577
577
578 path = None
578 path = None
579
579
580 foldercounter = 0
580 foldercounter = 0
581
581
582 flagNoMoreFiles = 0
582 flagNoMoreFiles = 0
583
583
584 datetimeList = []
584 datetimeList = []
585
585
586 __isFirstTimeOnline = 1
586 __isFirstTimeOnline = 1
587
587
588 __printInfo = True
588 __printInfo = True
589
589
590 profileIndex = None
590 profileIndex = None
591
591
592 nTxs = 1
592 nTxs = 1
593
593
594 txIndex = None
594 txIndex = None
595
595
596 # Added--------------------
596 # Added--------------------
597
597
598 selBlocksize = None
598 selBlocksize = None
599
599
600 selBlocktime = None
600 selBlocktime = None
601
601
602 def __init__(self):
602 def __init__(self):
603 """
603 """
604 This class is used to find data files
604 This class is used to find data files
605
605
606 Example:
606 Example:
607 reader = JRODataReader()
607 reader = JRODataReader()
608 fileList = reader.findDataFiles()
608 fileList = reader.findDataFiles()
609
609
610 """
610 """
611 pass
611 pass
612
612
613 def createObjByDefault(self):
613 def createObjByDefault(self):
614 """
614 """
615
615
616 """
616 """
617 raise NotImplementedError
617 raise NotImplementedError
618
618
619 def getBlockDimension(self):
619 def getBlockDimension(self):
620
620
621 raise NotImplementedError
621 raise NotImplementedError
622
622
623 def searchFilesOffLine(self,
623 def searchFilesOffLine(self,
624 path,
624 path,
625 startDate=None,
625 startDate=None,
626 endDate=None,
626 endDate=None,
627 startTime=datetime.time(0, 0, 0),
627 startTime=datetime.time(0, 0, 0),
628 endTime=datetime.time(23, 59, 59),
628 endTime=datetime.time(23, 59, 59),
629 set=None,
629 set=None,
630 expLabel='',
630 expLabel='',
631 ext='.r',
631 ext='.r',
632 cursor=None,
632 cursor=None,
633 skip=None,
633 skip=None,
634 walk=True):
634 walk=True):
635
635
636 self.filenameList = []
636 self.filenameList = []
637 self.datetimeList = []
637 self.datetimeList = []
638
638
639 pathList = []
639 pathList = []
640
640
641 dateList, pathList = self.findDatafiles(
641 dateList, pathList = self.findDatafiles(
642 path, startDate, endDate, expLabel, ext, walk, include_path=True)
642 path, startDate, endDate, expLabel, ext, walk, include_path=True)
643
643
644 if dateList == []:
644 if dateList == []:
645 return [], []
645 return [], []
646
646
647 if len(dateList) > 1:
647 if len(dateList) > 1:
648 print("[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList)))
648 print("[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList)))
649 else:
649 else:
650 print("[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0]))
650 print("[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0]))
651
651
652 filenameList = []
652 filenameList = []
653 datetimeList = []
653 datetimeList = []
654
654
655 for thisPath in pathList:
655 for thisPath in pathList:
656
656
657 fileList = glob.glob1(thisPath, "*%s" % ext)
657 fileList = glob.glob1(thisPath, "*%s" % ext)
658 fileList.sort()
658 fileList.sort()
659
659
660 for file in fileList:
660 for file in fileList:
661
661
662 filename = os.path.join(thisPath, file)
662 filename = os.path.join(thisPath, file)
663
663
664 if not isFileInDateRange(filename, startDate, endDate):
664 if not isFileInDateRange(filename, startDate, endDate):
665 continue
665 continue
666
666
667 thisDatetime = isFileInTimeRange(
667 thisDatetime = isFileInTimeRange(
668 filename, startDate, endDate, startTime, endTime)
668 filename, startDate, endDate, startTime, endTime)
669
669
670 if not(thisDatetime):
670 if not(thisDatetime):
671 continue
671 continue
672
672
673 filenameList.append(filename)
673 filenameList.append(filename)
674 datetimeList.append(thisDatetime)
674 datetimeList.append(thisDatetime)
675
675
676 if cursor is not None and skip is not None:
676 if cursor is not None and skip is not None:
677 filenameList = filenameList[cursor * skip:cursor * skip + skip]
677 filenameList = filenameList[cursor * skip:cursor * skip + skip]
678 datetimeList = datetimeList[cursor * skip:cursor * skip + skip]
678 datetimeList = datetimeList[cursor * skip:cursor * skip + skip]
679
679
680 if not(filenameList):
680 if not(filenameList):
681 print("[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path))
681 print("[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path))
682 return [], []
682 return [], []
683
683
684 print("[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime))
684 print("[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime))
685
685
686 # for i in range(len(filenameList)):
686 # for i in range(len(filenameList)):
687 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
687 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
688
688
689 self.filenameList = filenameList
689 self.filenameList = filenameList
690 self.datetimeList = datetimeList
690 self.datetimeList = datetimeList
691
691
692 return pathList, filenameList
692 return pathList, filenameList
693
693
694 def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None):
694 def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None):
695 """
695 """
696 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
696 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
697 devuelve el archivo encontrado ademas de otros datos.
697 devuelve el archivo encontrado ademas de otros datos.
698
698
699 Input:
699 Input:
700 path : carpeta donde estan contenidos los files que contiene data
700 path : carpeta donde estan contenidos los files que contiene data
701
701
702 expLabel : Nombre del subexperimento (subfolder)
702 expLabel : Nombre del subexperimento (subfolder)
703
703
704 ext : extension de los files
704 ext : extension de los files
705
705
706 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
706 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
707
707
708 Return:
708 Return:
709 directory : eL directorio donde esta el file encontrado
709 directory : eL directorio donde esta el file encontrado
710 filename : el ultimo file de una determinada carpeta
710 filename : el ultimo file de una determinada carpeta
711 year : el anho
711 year : el anho
712 doy : el numero de dia del anho
712 doy : el numero de dia del anho
713 set : el set del archivo
713 set : el set del archivo
714
714
715
715
716 """
716 """
717 if not os.path.isdir(path):
717 if not os.path.isdir(path):
718 return None, None, None, None, None, None
718 return None, None, None, None, None, None
719
719
720 dirList = []
720 dirList = []
721
721
722 if not walk:
722 if not walk:
723 fullpath = path
723 fullpath = path
724 foldercounter = 0
724 foldercounter = 0
725 else:
725 else:
726 # Filtra solo los directorios
726 # Filtra solo los directorios
727 for thisPath in os.listdir(path):
727 for thisPath in os.listdir(path):
728 if not os.path.isdir(os.path.join(path, thisPath)):
728 if not os.path.isdir(os.path.join(path, thisPath)):
729 continue
729 continue
730 if not isRadarFolder(thisPath):
730 if not isRadarFolder(thisPath):
731 continue
731 continue
732
732
733 dirList.append(thisPath)
733 dirList.append(thisPath)
734
734
735 if not(dirList):
735 if not(dirList):
736 return None, None, None, None, None, None
736 return None, None, None, None, None, None
737
737
738 dirList = sorted(dirList, key=str.lower)
738 dirList = sorted(dirList, key=str.lower)
739
739
740 doypath = dirList[-1]
740 doypath = dirList[-1]
741 foldercounter = int(doypath.split('_')[1]) if len(
741 foldercounter = int(doypath.split('_')[1]) if len(
742 doypath.split('_')) > 1 else 0
742 doypath.split('_')) > 1 else 0
743 fullpath = os.path.join(path, doypath, expLabel)
743 fullpath = os.path.join(path, doypath, expLabel)
744
744
745 print("[Reading] %s folder was found: " % (fullpath))
745 print("[Reading] %s folder was found: " % (fullpath))
746
746
747 if set == None:
747 if set == None:
748 filename = getlastFileFromPath(fullpath, ext)
748 filename = getlastFileFromPath(fullpath, ext)
749 else:
749 else:
750 filename = getFileFromSet(fullpath, ext, set)
750 filename = getFileFromSet(fullpath, ext, set)
751
751
752 if not(filename):
752 if not(filename):
753 return None, None, None, None, None, None
753 return None, None, None, None, None, None
754
754
755 print("[Reading] %s file was found" % (filename))
755 print("[Reading] %s file was found" % (filename))
756
756
757 if not(self.__verifyFile(os.path.join(fullpath, filename))):
757 if not(self.__verifyFile(os.path.join(fullpath, filename))):
758 return None, None, None, None, None, None
758 return None, None, None, None, None, None
759
759
760 year = int(filename[1:5])
760 year = int(filename[1:5])
761 doy = int(filename[5:8])
761 doy = int(filename[5:8])
762 set = int(filename[8:11])
762 set = int(filename[8:11])
763
763
764 return fullpath, foldercounter, filename, year, doy, set
764 return fullpath, foldercounter, filename, year, doy, set
765
765
766 def __setNextFileOffline(self):
766 def __setNextFileOffline(self):
767
767
768 idFile = self.fileIndex
768 idFile = self.fileIndex
769
769
770 while (True):
770 while (True):
771 idFile += 1
771 idFile += 1
772 if not(idFile < len(self.filenameList)):
772 if not(idFile < len(self.filenameList)):
773 self.flagNoMoreFiles = 1
773 self.flagNoMoreFiles = 1
774 # print "[Reading] No more Files"
774 # print "[Reading] No more Files"
775 return 0
775 return 0
776
776
777 filename = self.filenameList[idFile]
777 filename = self.filenameList[idFile]
778
778
779 if not(self.__verifyFile(filename)):
779 if not(self.__verifyFile(filename)):
780 continue
780 continue
781
781
782 fileSize = os.path.getsize(filename)
782 fileSize = os.path.getsize(filename)
783 fp = open(filename, 'rb')
783 fp = open(filename, 'rb')
784 break
784 break
785
785
786 self.flagIsNewFile = 1
786 self.flagIsNewFile = 1
787 self.fileIndex = idFile
787 self.fileIndex = idFile
788 self.filename = filename
788 self.filename = filename
789 self.fileSize = fileSize
789 self.fileSize = fileSize
790 self.fp = fp
790 self.fp = fp
791
791
792 # print "[Reading] Setting the file: %s"%self.filename
792 # print "[Reading] Setting the file: %s"%self.filename
793
793
794 return 1
794 return 1
795
795
796 def __setNextFileOnline(self):
796 def __setNextFileOnline(self):
797 """
797 """
798 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
798 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
799 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
799 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
800 siguientes.
800 siguientes.
801
801
802 Affected:
802 Affected:
803 self.flagIsNewFile
803 self.flagIsNewFile
804 self.filename
804 self.filename
805 self.fileSize
805 self.fileSize
806 self.fp
806 self.fp
807 self.set
807 self.set
808 self.flagNoMoreFiles
808 self.flagNoMoreFiles
809
809
810 Return:
810 Return:
811 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
811 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
812 1 : si el file fue abierto con exito y esta listo a ser leido
812 1 : si el file fue abierto con exito y esta listo a ser leido
813
813
814 Excepciones:
814 Excepciones:
815 Si un determinado file no puede ser abierto
815 Si un determinado file no puede ser abierto
816 """
816 """
817 nFiles = 0
817 nFiles = 0
818 fileOk_flag = False
818 fileOk_flag = False
819 firstTime_flag = True
819 firstTime_flag = True
820
820
821 self.set += 1
821 self.set += 1
822
822
823 if self.set > 999:
823 if self.set > 999:
824 self.set = 0
824 self.set = 0
825 self.foldercounter += 1
825 self.foldercounter += 1
826
826
827 # busca el 1er file disponible
827 # busca el 1er file disponible
828 fullfilename, filename = checkForRealPath(
828 fullfilename, filename = checkForRealPath(
829 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
829 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
830 if fullfilename:
830 if fullfilename:
831 if self.__verifyFile(fullfilename, False):
831 if self.__verifyFile(fullfilename, False):
832 fileOk_flag = True
832 fileOk_flag = True
833
833
834 # si no encuentra un file entonces espera y vuelve a buscar
834 # si no encuentra un file entonces espera y vuelve a buscar
835 if not(fileOk_flag):
835 if not(fileOk_flag):
836 # busco en los siguientes self.nFiles+1 files posibles
836 # busco en los siguientes self.nFiles+1 files posibles
837 for nFiles in range(self.nFiles + 1):
837 for nFiles in range(self.nFiles + 1):
838
838
839 if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces
839 if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces
840 tries = self.nTries
840 tries = self.nTries
841 else:
841 else:
842 tries = 1 # si no es la 1era vez entonces solo lo hace una vez
842 tries = 1 # si no es la 1era vez entonces solo lo hace una vez
843
843
844 for nTries in range(tries):
844 for nTries in range(tries):
845 if firstTime_flag:
845 if firstTime_flag:
846 print("\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1))
846 print("\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1))
847 sleep(self.delay)
847 sleep(self.delay)
848 else:
848 else:
849 print("\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext))
849 print("\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext))
850
850
851 fullfilename, filename = checkForRealPath(
851 fullfilename, filename = checkForRealPath(
852 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
852 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
853 if fullfilename:
853 if fullfilename:
854 if self.__verifyFile(fullfilename):
854 if self.__verifyFile(fullfilename):
855 fileOk_flag = True
855 fileOk_flag = True
856 break
856 break
857
857
858 if fileOk_flag:
858 if fileOk_flag:
859 break
859 break
860
860
861 firstTime_flag = False
861 firstTime_flag = False
862
862
863 log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename))
863 log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename))
864 self.set += 1
864 self.set += 1
865
865
866 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
866 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
867 if nFiles == (self.nFiles - 1):
867 if nFiles == (self.nFiles - 1):
868 self.set = 0
868 self.set = 0
869 self.doy += 1
869 self.doy += 1
870 self.foldercounter = 0
870 self.foldercounter = 0
871
871
872 if fileOk_flag:
872 if fileOk_flag:
873 self.fileSize = os.path.getsize(fullfilename)
873 self.fileSize = os.path.getsize(fullfilename)
874 self.filename = fullfilename
874 self.filename = fullfilename
875 self.flagIsNewFile = 1
875 self.flagIsNewFile = 1
876 if self.fp != None:
876 if self.fp != None:
877 self.fp.close()
877 self.fp.close()
878 self.fp = open(fullfilename, 'rb')
878 self.fp = open(fullfilename, 'rb')
879 self.flagNoMoreFiles = 0
879 self.flagNoMoreFiles = 0
880 # print '[Reading] Setting the file: %s' % fullfilename
880 # print '[Reading] Setting the file: %s' % fullfilename
881 else:
881 else:
882 self.fileSize = 0
882 self.fileSize = 0
883 self.filename = None
883 self.filename = None
884 self.flagIsNewFile = 0
884 self.flagIsNewFile = 0
885 self.fp = None
885 self.fp = None
886 self.flagNoMoreFiles = 1
886 self.flagNoMoreFiles = 1
887 # print '[Reading] No more files to read'
887 # print '[Reading] No more files to read'
888
888
889 return fileOk_flag
889 return fileOk_flag
890
890
891 def setNextFile(self):
891 def setNextFile(self):
892 if self.fp != None:
892 if self.fp != None:
893 self.fp.close()
893 self.fp.close()
894
894
895 if self.online:
895 if self.online:
896 newFile = self.__setNextFileOnline()
896 newFile = self.__setNextFileOnline()
897 else:
897 else:
898 newFile = self.__setNextFileOffline()
898 newFile = self.__setNextFileOffline()
899
899
900 if not(newFile):
900 if not(newFile):
901 self.dataOut.error = (-1, 'No more files to read')
901 self.dataOut.error = (-1, 'No more files to read')
902 return 0
902 return 0
903
903
904 if self.verbose:
904 if self.verbose:
905 print('[Reading] Setting the file: %s' % self.filename)
905 print('[Reading] Setting the file: %s' % self.filename)
906
906
907 self.__readFirstHeader()
907 self.__readFirstHeader()
908 self.nReadBlocks = 0
908 self.nReadBlocks = 0
909 return 1
909 return 1
910
910
911 def __waitNewBlock(self):
911 def __waitNewBlock(self):
912 """
912 """
913 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
913 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
914
914
915 Si el modo de lectura es OffLine siempre retorn 0
915 Si el modo de lectura es OffLine siempre retorn 0
916 """
916 """
917 if not self.online:
917 if not self.online:
918 return 0
918 return 0
919
919
920 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
920 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
921 return 0
921 return 0
922
922
923 currentPointer = self.fp.tell()
923 currentPointer = self.fp.tell()
924
924
925 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
925 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
926
926
927 for nTries in range(self.nTries):
927 for nTries in range(self.nTries):
928
928
929 self.fp.close()
929 self.fp.close()
930 self.fp = open(self.filename, 'rb')
930 self.fp = open(self.filename, 'rb')
931 self.fp.seek(currentPointer)
931 self.fp.seek(currentPointer)
932
932
933 self.fileSize = os.path.getsize(self.filename)
933 self.fileSize = os.path.getsize(self.filename)
934 currentSize = self.fileSize - currentPointer
934 currentSize = self.fileSize - currentPointer
935
935
936 if (currentSize >= neededSize):
936 if (currentSize >= neededSize):
937 self.basicHeaderObj.read(self.fp)
937 self.basicHeaderObj.read(self.fp)
938 return 1
938 return 1
939
939
940 if self.fileSize == self.fileSizeByHeader:
940 if self.fileSize == self.fileSizeByHeader:
941 # self.flagEoF = True
941 # self.flagEoF = True
942 return 0
942 return 0
943
943
944 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
944 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
945 sleep(self.delay)
945 sleep(self.delay)
946
946
947 return 0
947 return 0
948
948
949 def waitDataBlock(self, pointer_location):
949 def waitDataBlock(self, pointer_location):
950
950
951 currentPointer = pointer_location
951 currentPointer = pointer_location
952
952
953 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
953 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
954
954
955 for nTries in range(self.nTries):
955 for nTries in range(self.nTries):
956 self.fp.close()
956 self.fp.close()
957 self.fp = open(self.filename, 'rb')
957 self.fp = open(self.filename, 'rb')
958 self.fp.seek(currentPointer)
958 self.fp.seek(currentPointer)
959
959
960 self.fileSize = os.path.getsize(self.filename)
960 self.fileSize = os.path.getsize(self.filename)
961 currentSize = self.fileSize - currentPointer
961 currentSize = self.fileSize - currentPointer
962
962
963 if (currentSize >= neededSize):
963 if (currentSize >= neededSize):
964 return 1
964 return 1
965
965
966 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
966 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
967 sleep(self.delay)
967 sleep(self.delay)
968
968
969 return 0
969 return 0
970
970
971 def __jumpToLastBlock(self):
971 def __jumpToLastBlock(self):
972
972
973 if not(self.__isFirstTimeOnline):
973 if not(self.__isFirstTimeOnline):
974 return
974 return
975
975
976 csize = self.fileSize - self.fp.tell()
976 csize = self.fileSize - self.fp.tell()
977 blocksize = self.processingHeaderObj.blockSize
977 blocksize = self.processingHeaderObj.blockSize
978
978
979 # salta el primer bloque de datos
979 # salta el primer bloque de datos
980 if csize > self.processingHeaderObj.blockSize:
980 if csize > self.processingHeaderObj.blockSize:
981 self.fp.seek(self.fp.tell() + blocksize)
981 self.fp.seek(self.fp.tell() + blocksize)
982 else:
982 else:
983 return
983 return
984
984
985 csize = self.fileSize - self.fp.tell()
985 csize = self.fileSize - self.fp.tell()
986 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
986 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
987 while True:
987 while True:
988
988
989 if self.fp.tell() < self.fileSize:
989 if self.fp.tell() < self.fileSize:
990 self.fp.seek(self.fp.tell() + neededsize)
990 self.fp.seek(self.fp.tell() + neededsize)
991 else:
991 else:
992 self.fp.seek(self.fp.tell() - neededsize)
992 self.fp.seek(self.fp.tell() - neededsize)
993 break
993 break
994
994
995 # csize = self.fileSize - self.fp.tell()
995 # csize = self.fileSize - self.fp.tell()
996 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
996 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
997 # factor = int(csize/neededsize)
997 # factor = int(csize/neededsize)
998 # if factor > 0:
998 # if factor > 0:
999 # self.fp.seek(self.fp.tell() + factor*neededsize)
999 # self.fp.seek(self.fp.tell() + factor*neededsize)
1000
1000
1001 self.flagIsNewFile = 0
1001 self.flagIsNewFile = 0
1002 self.__isFirstTimeOnline = 0
1002 self.__isFirstTimeOnline = 0
1003
1003
1004 def __setNewBlock(self):
1004 def __setNewBlock(self):
1005 # if self.server is None:
1005 # if self.server is None:
1006 if self.fp == None:
1006 if self.fp == None:
1007 return 0
1007 return 0
1008
1008
1009 # if self.online:
1009 # if self.online:
1010 # self.__jumpToLastBlock()
1010 # self.__jumpToLastBlock()
1011
1011
1012 if self.flagIsNewFile:
1012 if self.flagIsNewFile:
1013 self.lastUTTime = self.basicHeaderObj.utc
1013 self.lastUTTime = self.basicHeaderObj.utc
1014 return 1
1014 return 1
1015
1015
1016 if self.realtime:
1016 if self.realtime:
1017 self.flagDiscontinuousBlock = 1
1017 self.flagDiscontinuousBlock = 1
1018 if not(self.setNextFile()):
1018 if not(self.setNextFile()):
1019 return 0
1019 return 0
1020 else:
1020 else:
1021 return 1
1021 return 1
1022 # if self.server is None:
1022 # if self.server is None:
1023 currentSize = self.fileSize - self.fp.tell()
1023 currentSize = self.fileSize - self.fp.tell()
1024 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1024 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1025 if (currentSize >= neededSize):
1025 if (currentSize >= neededSize):
1026 self.basicHeaderObj.read(self.fp)
1026 self.basicHeaderObj.read(self.fp)
1027 self.lastUTTime = self.basicHeaderObj.utc
1027 self.lastUTTime = self.basicHeaderObj.utc
1028 return 1
1028 return 1
1029 # else:
1029 # else:
1030 # self.basicHeaderObj.read(self.zHeader)
1030 # self.basicHeaderObj.read(self.zHeader)
1031 # self.lastUTTime = self.basicHeaderObj.utc
1031 # self.lastUTTime = self.basicHeaderObj.utc
1032 # return 1
1032 # return 1
1033 if self.__waitNewBlock():
1033 if self.__waitNewBlock():
1034 self.lastUTTime = self.basicHeaderObj.utc
1034 self.lastUTTime = self.basicHeaderObj.utc
1035 return 1
1035 return 1
1036 # if self.server is None:
1036 # if self.server is None:
1037 if not(self.setNextFile()):
1037 if not(self.setNextFile()):
1038 return 0
1038 return 0
1039
1039
1040 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
1040 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
1041 self.lastUTTime = self.basicHeaderObj.utc
1041 self.lastUTTime = self.basicHeaderObj.utc
1042
1042
1043 self.flagDiscontinuousBlock = 0
1043 self.flagDiscontinuousBlock = 0
1044
1044
1045 if deltaTime > self.maxTimeStep:
1045 if deltaTime > self.maxTimeStep:
1046 self.flagDiscontinuousBlock = 1
1046 self.flagDiscontinuousBlock = 1
1047
1047
1048 return 1
1048 return 1
1049
1049
1050 def readNextBlock(self):
1050 def readNextBlock(self):
1051
1051
1052 # Skip block out of startTime and endTime
1052 # Skip block out of startTime and endTime
1053 while True:
1053 while True:
1054 if not(self.__setNewBlock()):
1054 if not(self.__setNewBlock()):
1055 self.dataOut.error = (-1, 'No more files to read')
1055 self.dataOut.error = (-1, 'No more files to read')
1056 return 0
1056 return 0
1057
1057
1058 if not(self.readBlock()):
1058 if not(self.readBlock()):
1059 return 0
1059 return 0
1060
1060
1061 self.getBasicHeader()
1061 self.getBasicHeader()
1062 if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
1062 if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
1063 print("[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1063 print("[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1064 self.processingHeaderObj.dataBlocksPerFile,
1064 self.processingHeaderObj.dataBlocksPerFile,
1065 self.dataOut.datatime.ctime()))
1065 self.dataOut.datatime.ctime()))
1066 continue
1066 continue
1067
1067
1068 break
1068 break
1069
1069
1070 if self.verbose:
1070 if self.verbose:
1071 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
1071 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
1072 self.processingHeaderObj.dataBlocksPerFile,
1072 self.processingHeaderObj.dataBlocksPerFile,
1073 self.dataOut.datatime.ctime()))
1073 self.dataOut.datatime.ctime()))
1074 return 1
1074 return 1
1075
1075
1076 def __readFirstHeader(self):
1076 def __readFirstHeader(self):
1077
1077
1078 self.basicHeaderObj.read(self.fp)
1078 self.basicHeaderObj.read(self.fp)
1079 self.systemHeaderObj.read(self.fp)
1079 self.systemHeaderObj.read(self.fp)
1080 self.radarControllerHeaderObj.read(self.fp)
1080 self.radarControllerHeaderObj.read(self.fp)
1081 self.processingHeaderObj.read(self.fp)
1081 self.processingHeaderObj.read(self.fp)
1082
1082
1083 self.firstHeaderSize = self.basicHeaderObj.size
1083 self.firstHeaderSize = self.basicHeaderObj.size
1084
1084
1085 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
1085 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
1086 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
1086 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
1087 if datatype == 0:
1087 if datatype == 0:
1088 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
1088 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
1089 elif datatype == 1:
1089 elif datatype == 1:
1090 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
1090 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
1091 elif datatype == 2:
1091 elif datatype == 2:
1092 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
1092 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
1093 elif datatype == 3:
1093 elif datatype == 3:
1094 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
1094 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
1095 elif datatype == 4:
1095 elif datatype == 4:
1096 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
1096 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
1097 elif datatype == 5:
1097 elif datatype == 5:
1098 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
1098 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
1099 else:
1099 else:
1100 raise ValueError('Data type was not defined')
1100 raise ValueError('Data type was not defined')
1101
1101
1102 self.dtype = datatype_str
1102 self.dtype = datatype_str
1103 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1103 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1104 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
1104 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
1105 self.firstHeaderSize + self.basicHeaderSize * \
1105 self.firstHeaderSize + self.basicHeaderSize * \
1106 (self.processingHeaderObj.dataBlocksPerFile - 1)
1106 (self.processingHeaderObj.dataBlocksPerFile - 1)
1107 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1107 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1108 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1108 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1109 self.getBlockDimension()
1109 self.getBlockDimension()
1110
1110
1111 def __verifyFile(self, filename, msgFlag=True):
1111 def __verifyFile(self, filename, msgFlag=True):
1112
1112
1113 msg = None
1113 msg = None
1114
1114
1115 try:
1115 try:
1116 fp = open(filename, 'rb')
1116 fp = open(filename, 'rb')
1117 except IOError:
1117 except IOError:
1118
1118
1119 if msgFlag:
1119 if msgFlag:
1120 print("[Reading] File %s can't be opened" % (filename))
1120 print("[Reading] File %s can't be opened" % (filename))
1121
1121
1122 return False
1122 return False
1123
1123
1124 currentPosition = fp.tell()
1124 currentPosition = fp.tell()
1125 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1125 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1126
1126
1127 if neededSize == 0:
1127 if neededSize == 0:
1128 basicHeaderObj = BasicHeader(LOCALTIME)
1128 basicHeaderObj = BasicHeader(LOCALTIME)
1129 systemHeaderObj = SystemHeader()
1129 systemHeaderObj = SystemHeader()
1130 radarControllerHeaderObj = RadarControllerHeader()
1130 radarControllerHeaderObj = RadarControllerHeader()
1131 processingHeaderObj = ProcessingHeader()
1131 processingHeaderObj = ProcessingHeader()
1132
1132
1133 if not(basicHeaderObj.read(fp)):
1133 if not(basicHeaderObj.read(fp)):
1134 fp.close()
1134 fp.close()
1135 return False
1135 return False
1136
1136
1137 if not(systemHeaderObj.read(fp)):
1137 if not(systemHeaderObj.read(fp)):
1138 fp.close()
1138 fp.close()
1139 return False
1139 return False
1140
1140
1141 if not(radarControllerHeaderObj.read(fp)):
1141 if not(radarControllerHeaderObj.read(fp)):
1142 fp.close()
1142 fp.close()
1143 return False
1143 return False
1144
1144
1145 if not(processingHeaderObj.read(fp)):
1145 if not(processingHeaderObj.read(fp)):
1146 fp.close()
1146 fp.close()
1147 return False
1147 return False
1148
1148
1149 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1149 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1150 else:
1150 else:
1151 msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename
1151 msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename
1152
1152
1153 fp.close()
1153 fp.close()
1154
1154
1155 fileSize = os.path.getsize(filename)
1155 fileSize = os.path.getsize(filename)
1156 currentSize = fileSize - currentPosition
1156 currentSize = fileSize - currentPosition
1157
1157
1158 if currentSize < neededSize:
1158 if currentSize < neededSize:
1159 if msgFlag and (msg != None):
1159 if msgFlag and (msg != None):
1160 print(msg)
1160 print(msg)
1161 return False
1161 return False
1162
1162
1163 return True
1163 return True
1164
1164
1165 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1165 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1166
1166
1167 path_empty = True
1167 path_empty = True
1168
1168
1169 dateList = []
1169 dateList = []
1170 pathList = []
1170 pathList = []
1171
1171
1172 multi_path = path.split(',')
1172 multi_path = path.split(',')
1173
1173
1174 if not walk:
1174 if not walk:
1175
1175
1176 for single_path in multi_path:
1176 for single_path in multi_path:
1177
1177
1178 if not os.path.isdir(single_path):
1178 if not os.path.isdir(single_path):
1179 continue
1179 continue
1180
1180
1181 fileList = glob.glob1(single_path, "*" + ext)
1181 fileList = glob.glob1(single_path, "*" + ext)
1182
1182
1183 if not fileList:
1183 if not fileList:
1184 continue
1184 continue
1185
1185
1186 path_empty = False
1186 path_empty = False
1187
1187
1188 fileList.sort()
1188 fileList.sort()
1189
1189
1190 for thisFile in fileList:
1190 for thisFile in fileList:
1191
1191
1192 if not os.path.isfile(os.path.join(single_path, thisFile)):
1192 if not os.path.isfile(os.path.join(single_path, thisFile)):
1193 continue
1193 continue
1194
1194
1195 if not isRadarFile(thisFile):
1195 if not isRadarFile(thisFile):
1196 continue
1196 continue
1197
1197
1198 if not isFileInDateRange(thisFile, startDate, endDate):
1198 if not isFileInDateRange(thisFile, startDate, endDate):
1199 continue
1199 continue
1200
1200
1201 thisDate = getDateFromRadarFile(thisFile)
1201 thisDate = getDateFromRadarFile(thisFile)
1202
1202
1203 if thisDate in dateList:
1203 if thisDate in dateList:
1204 continue
1204 continue
1205
1205
1206 dateList.append(thisDate)
1206 dateList.append(thisDate)
1207 pathList.append(single_path)
1207 pathList.append(single_path)
1208
1208
1209 else:
1209 else:
1210 for single_path in multi_path:
1210 for single_path in multi_path:
1211
1211
1212 if not os.path.isdir(single_path):
1212 if not os.path.isdir(single_path):
1213 continue
1213 continue
1214
1214
1215 dirList = []
1215 dirList = []
1216
1216
1217 for thisPath in os.listdir(single_path):
1217 for thisPath in os.listdir(single_path):
1218
1218
1219 if not os.path.isdir(os.path.join(single_path, thisPath)):
1219 if not os.path.isdir(os.path.join(single_path, thisPath)):
1220 continue
1220 continue
1221
1221
1222 if not isRadarFolder(thisPath):
1222 if not isRadarFolder(thisPath):
1223 continue
1223 continue
1224
1224
1225 if not isFolderInDateRange(thisPath, startDate, endDate):
1225 if not isFolderInDateRange(thisPath, startDate, endDate):
1226 continue
1226 continue
1227
1227
1228 dirList.append(thisPath)
1228 dirList.append(thisPath)
1229
1229
1230 if not dirList:
1230 if not dirList:
1231 continue
1231 continue
1232
1232
1233 dirList.sort()
1233 dirList.sort()
1234
1234
1235 for thisDir in dirList:
1235 for thisDir in dirList:
1236
1236
1237 datapath = os.path.join(single_path, thisDir, expLabel)
1237 datapath = os.path.join(single_path, thisDir, expLabel)
1238 fileList = glob.glob1(datapath, "*" + ext)
1238 fileList = glob.glob1(datapath, "*" + ext)
1239
1239
1240 if not fileList:
1240 if not fileList:
1241 continue
1241 continue
1242
1242
1243 path_empty = False
1243 path_empty = False
1244
1244
1245 thisDate = getDateFromRadarFolder(thisDir)
1245 thisDate = getDateFromRadarFolder(thisDir)
1246
1246
1247 pathList.append(datapath)
1247 pathList.append(datapath)
1248 dateList.append(thisDate)
1248 dateList.append(thisDate)
1249
1249
1250 dateList.sort()
1250 dateList.sort()
1251
1251
1252 if walk:
1252 if walk:
1253 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1253 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1254 else:
1254 else:
1255 pattern_path = multi_path[0]
1255 pattern_path = multi_path[0]
1256
1256
1257 if path_empty:
1257 if path_empty:
1258 print("[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate))
1258 print("[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate))
1259 else:
1259 else:
1260 if not dateList:
1260 if not dateList:
1261 print("[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path))
1261 print("[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path))
1262
1262
1263 if include_path:
1263 if include_path:
1264 return dateList, pathList
1264 return dateList, pathList
1265
1265
1266 return dateList
1266 return dateList
1267
1267
1268 def setup(self,
1268 def setup(self,
1269 path=None,
1269 path=None,
1270 startDate=None,
1270 startDate=None,
1271 endDate=None,
1271 endDate=None,
1272 startTime=datetime.time(0, 0, 0),
1272 startTime=datetime.time(0, 0, 0),
1273 endTime=datetime.time(23, 59, 59),
1273 endTime=datetime.time(23, 59, 59),
1274 set=None,
1274 set=None,
1275 expLabel="",
1275 expLabel="",
1276 ext=None,
1276 ext=None,
1277 online=False,
1277 online=False,
1278 delay=60,
1278 delay=60,
1279 walk=True,
1279 walk=True,
1280 getblock=False,
1280 getblock=False,
1281 nTxs=1,
1281 nTxs=1,
1282 realtime=False,
1282 realtime=False,
1283 blocksize=None,
1283 blocksize=None,
1284 blocktime=None,
1284 blocktime=None,
1285 skip=None,
1285 skip=None,
1286 cursor=None,
1286 cursor=None,
1287 warnings=True,
1287 warnings=True,
1288 verbose=True,
1288 verbose=True,
1289 server=None,
1289 server=None,
1290 format=None,
1290 format=None,
1291 oneDDict=None,
1291 oneDDict=None,
1292 twoDDict=None,
1292 twoDDict=None,
1293 ind2DList=None):
1293 ind2DList=None):
1294 if server is not None:
1294 if server is not None:
1295 if 'tcp://' in server:
1295 if 'tcp://' in server:
1296 address = server
1296 address = server
1297 else:
1297 else:
1298 address = 'ipc:///tmp/%s' % server
1298 address = 'ipc:///tmp/%s' % server
1299 self.server = address
1299 self.server = address
1300 self.context = zmq.Context()
1300 self.context = zmq.Context()
1301 self.receiver = self.context.socket(zmq.PULL)
1301 self.receiver = self.context.socket(zmq.PULL)
1302 self.receiver.connect(self.server)
1302 self.receiver.connect(self.server)
1303 time.sleep(0.5)
1303 time.sleep(0.5)
1304 print('[Starting] ReceiverData from {}'.format(self.server))
1304 print('[Starting] ReceiverData from {}'.format(self.server))
1305 else:
1305 else:
1306 self.server = None
1306 self.server = None
1307 if path == None:
1307 if path == None:
1308 raise ValueError("[Reading] The path is not valid")
1308 raise ValueError("[Reading] The path is not valid")
1309
1309
1310 if ext == None:
1310 if ext == None:
1311 ext = self.ext
1311 ext = self.ext
1312
1312
1313 if online:
1313 if online:
1314 print("[Reading] Searching files in online mode...")
1314 print("[Reading] Searching files in online mode...")
1315
1315
1316 for nTries in range(self.nTries):
1316 for nTries in range(self.nTries):
1317 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(
1317 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(
1318 path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1318 path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1319
1319
1320 if fullpath:
1320 if fullpath:
1321 break
1321 break
1322
1322
1323 print('[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1))
1323 print('[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1))
1324 sleep(self.delay)
1324 sleep(self.delay)
1325
1325
1326 if not(fullpath):
1326 if not(fullpath):
1327 self.dataOut.error = (-1, 'There isn\'t any valid file in {}'.format(path))
1327 self.dataOut.error = (-1, 'There isn\'t any valid file in {}'.format(path))
1328 return
1328 return
1329
1329
1330 self.year = year
1330 self.year = year
1331 self.doy = doy
1331 self.doy = doy
1332 self.set = set - 1
1332 self.set = set - 1
1333 self.path = path
1333 self.path = path
1334 self.foldercounter = foldercounter
1334 self.foldercounter = foldercounter
1335 last_set = None
1335 last_set = None
1336 else:
1336 else:
1337 print("[Reading] Searching files in offline mode ...")
1337 print("[Reading] Searching files in offline mode ...")
1338 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1338 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1339 startTime=startTime, endTime=endTime,
1339 startTime=startTime, endTime=endTime,
1340 set=set, expLabel=expLabel, ext=ext,
1340 set=set, expLabel=expLabel, ext=ext,
1341 walk=walk, cursor=cursor,
1341 walk=walk, cursor=cursor,
1342 skip=skip)
1342 skip=skip)
1343
1343
1344 if not(pathList):
1344 if not(pathList):
1345 self.fileIndex = -1
1345 self.fileIndex = -1
1346 self.pathList = []
1346 self.pathList = []
1347 self.filenameList = []
1347 self.filenameList = []
1348 return
1348 return
1349
1349
1350 self.fileIndex = -1
1350 self.fileIndex = -1
1351 self.pathList = pathList
1351 self.pathList = pathList
1352 self.filenameList = filenameList
1352 self.filenameList = filenameList
1353 file_name = os.path.basename(filenameList[-1])
1353 file_name = os.path.basename(filenameList[-1])
1354 basename, ext = os.path.splitext(file_name)
1354 basename, ext = os.path.splitext(file_name)
1355 last_set = int(basename[-3:])
1355 last_set = int(basename[-3:])
1356
1356
1357 self.online = online
1357 self.online = online
1358 self.realtime = realtime
1358 self.realtime = realtime
1359 self.delay = delay
1359 self.delay = delay
1360 ext = ext.lower()
1360 ext = ext.lower()
1361 self.ext = ext
1361 self.ext = ext
1362 self.getByBlock = getblock
1362 self.getByBlock = getblock
1363 self.nTxs = nTxs
1363 self.nTxs = nTxs
1364 self.startTime = startTime
1364 self.startTime = startTime
1365 self.endTime = endTime
1365 self.endTime = endTime
1366 self.endDate = endDate
1366 self.endDate = endDate
1367 self.startDate = startDate
1367 self.startDate = startDate
1368 # Added-----------------
1368 # Added-----------------
1369 self.selBlocksize = blocksize
1369 self.selBlocksize = blocksize
1370 self.selBlocktime = blocktime
1370 self.selBlocktime = blocktime
1371
1371
1372 # Verbose-----------
1372 # Verbose-----------
1373 self.verbose = verbose
1373 self.verbose = verbose
1374 self.warnings = warnings
1374 self.warnings = warnings
1375
1375
1376 if not(self.setNextFile()):
1376 if not(self.setNextFile()):
1377 if (startDate != None) and (endDate != None):
1377 if (startDate != None) and (endDate != None):
1378 print("[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime()))
1378 print("[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime()))
1379 elif startDate != None:
1379 elif startDate != None:
1380 print("[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime()))
1380 print("[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime()))
1381 else:
1381 else:
1382 print("[Reading] No files")
1382 print("[Reading] No files")
1383
1383
1384 self.fileIndex = -1
1384 self.fileIndex = -1
1385 self.pathList = []
1385 self.pathList = []
1386 self.filenameList = []
1386 self.filenameList = []
1387 return
1387 return
1388
1388
1389 # self.getBasicHeader()
1389 # self.getBasicHeader()
1390
1390
1391 if last_set != None:
1391 if last_set != None:
1392 self.dataOut.last_block = last_set * \
1392 self.dataOut.last_block = last_set * \
1393 self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1393 self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1394 return
1394 return
1395
1395
1396 def getBasicHeader(self):
1396 def getBasicHeader(self):
1397
1397
1398 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1398 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1399 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1399 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1400
1400
1401 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1401 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1402
1402
1403 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1403 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1404
1404
1405 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1405 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1406
1406
1407 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1407 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1408
1408
1409 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1409 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1410
1410
1411 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1411 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1412
1412
1413 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1413 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1414
1414
1415 def getFirstHeader(self):
1415 def getFirstHeader(self):
1416
1416
1417 raise NotImplementedError
1417 raise NotImplementedError
1418
1418
1419 def getData(self):
1419 def getData(self):
1420
1420
1421 raise NotImplementedError
1421 raise NotImplementedError
1422
1422
1423 def hasNotDataInBuffer(self):
1423 def hasNotDataInBuffer(self):
1424
1424
1425 raise NotImplementedError
1425 raise NotImplementedError
1426
1426
1427 def readBlock(self):
1427 def readBlock(self):
1428
1428
1429 raise NotImplementedError
1429 raise NotImplementedError
1430
1430
1431 def isEndProcess(self):
1431 def isEndProcess(self):
1432
1432
1433 return self.flagNoMoreFiles
1433 return self.flagNoMoreFiles
1434
1434
1435 def printReadBlocks(self):
1435 def printReadBlocks(self):
1436
1436
1437 print("[Reading] Number of read blocks per file %04d" % self.nReadBlocks)
1437 print("[Reading] Number of read blocks per file %04d" % self.nReadBlocks)
1438
1438
1439 def printTotalBlocks(self):
1439 def printTotalBlocks(self):
1440
1440
1441 print("[Reading] Number of read blocks %04d" % self.nTotalBlocks)
1441 print("[Reading] Number of read blocks %04d" % self.nTotalBlocks)
1442
1442
1443 def printNumberOfBlock(self):
1443 def printNumberOfBlock(self):
1444 'SPAM!'
1444 'SPAM!'
1445
1445
1446 # if self.flagIsNewBlock:
1446 # if self.flagIsNewBlock:
1447 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1447 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1448 # self.processingHeaderObj.dataBlocksPerFile,
1448 # self.processingHeaderObj.dataBlocksPerFile,
1449 # self.dataOut.datatime.ctime())
1449 # self.dataOut.datatime.ctime())
1450
1450
1451 def printInfo(self):
1451 def printInfo(self):
1452
1452
1453 if self.__printInfo == False:
1453 if self.__printInfo == False:
1454 return
1454 return
1455
1455
1456 self.basicHeaderObj.printInfo()
1456 self.basicHeaderObj.printInfo()
1457 self.systemHeaderObj.printInfo()
1457 self.systemHeaderObj.printInfo()
1458 self.radarControllerHeaderObj.printInfo()
1458 self.radarControllerHeaderObj.printInfo()
1459 self.processingHeaderObj.printInfo()
1459 self.processingHeaderObj.printInfo()
1460
1460
1461 self.__printInfo = False
1461 self.__printInfo = False
1462
1462
1463 def run(self,
1463 def run(self,
1464 path=None,
1464 path=None,
1465 startDate=None,
1465 startDate=None,
1466 endDate=None,
1466 endDate=None,
1467 startTime=datetime.time(0, 0, 0),
1467 startTime=datetime.time(0, 0, 0),
1468 endTime=datetime.time(23, 59, 59),
1468 endTime=datetime.time(23, 59, 59),
1469 set=None,
1469 set=None,
1470 expLabel="",
1470 expLabel="",
1471 ext=None,
1471 ext=None,
1472 online=False,
1472 online=False,
1473 delay=60,
1473 delay=60,
1474 walk=True,
1474 walk=True,
1475 getblock=False,
1475 getblock=False,
1476 nTxs=1,
1476 nTxs=1,
1477 realtime=False,
1477 realtime=False,
1478 blocksize=None,
1478 blocksize=None,
1479 blocktime=None,
1479 blocktime=None,
1480 skip=None,
1480 skip=None,
1481 cursor=None,
1481 cursor=None,
1482 warnings=True,
1482 warnings=True,
1483 server=None,
1483 server=None,
1484 verbose=True,
1484 verbose=True,
1485 format=None,
1485 format=None,
1486 oneDDict=None,
1486 oneDDict=None,
1487 twoDDict=None,
1487 twoDDict=None,
1488 ind2DList=None, **kwargs):
1488 ind2DList=None, **kwargs):
1489
1489
1490 if not(self.isConfig):
1490 if not(self.isConfig):
1491 self.setup(path=path,
1491 self.setup(path=path,
1492 startDate=startDate,
1492 startDate=startDate,
1493 endDate=endDate,
1493 endDate=endDate,
1494 startTime=startTime,
1494 startTime=startTime,
1495 endTime=endTime,
1495 endTime=endTime,
1496 set=set,
1496 set=set,
1497 expLabel=expLabel,
1497 expLabel=expLabel,
1498 ext=ext,
1498 ext=ext,
1499 online=online,
1499 online=online,
1500 delay=delay,
1500 delay=delay,
1501 walk=walk,
1501 walk=walk,
1502 getblock=getblock,
1502 getblock=getblock,
1503 nTxs=nTxs,
1503 nTxs=nTxs,
1504 realtime=realtime,
1504 realtime=realtime,
1505 blocksize=blocksize,
1505 blocksize=blocksize,
1506 blocktime=blocktime,
1506 blocktime=blocktime,
1507 skip=skip,
1507 skip=skip,
1508 cursor=cursor,
1508 cursor=cursor,
1509 warnings=warnings,
1509 warnings=warnings,
1510 server=server,
1510 server=server,
1511 verbose=verbose,
1511 verbose=verbose,
1512 format=format,
1512 format=format,
1513 oneDDict=oneDDict,
1513 oneDDict=oneDDict,
1514 twoDDict=twoDDict,
1514 twoDDict=twoDDict,
1515 ind2DList=ind2DList)
1515 ind2DList=ind2DList)
1516 self.isConfig = True
1516 self.isConfig = True
1517 if server is None:
1517 if server is None:
1518 self.getData()
1518 self.getData()
1519 else:
1519 else:
1520 self.getFromServer()
1520 self.getFromServer()
1521
1521
1522
1522
1523 class JRODataWriter(JRODataIO):
1523 class JRODataWriter(JRODataIO):
1524
1524
1525 """
1525 """
1526 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1526 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1527 de los datos siempre se realiza por bloques.
1527 de los datos siempre se realiza por bloques.
1528 """
1528 """
1529
1529
1530 blockIndex = 0
1530 blockIndex = 0
1531
1531
1532 path = None
1532 path = None
1533
1533
1534 setFile = None
1534 setFile = None
1535
1535
1536 profilesPerBlock = None
1536 profilesPerBlock = None
1537
1537
1538 blocksPerFile = None
1538 blocksPerFile = None
1539
1539
1540 nWriteBlocks = 0
1540 nWriteBlocks = 0
1541
1541
1542 fileDate = None
1542 fileDate = None
1543
1543
1544 def __init__(self, dataOut=None):
1544 def __init__(self, dataOut=None):
1545 raise NotImplementedError
1545 raise NotImplementedError
1546
1546
1547 def hasAllDataInBuffer(self):
1547 def hasAllDataInBuffer(self):
1548 raise NotImplementedError
1548 raise NotImplementedError
1549
1549
1550 def setBlockDimension(self):
1550 def setBlockDimension(self):
1551 raise NotImplementedError
1551 raise NotImplementedError
1552
1552
1553 def writeBlock(self):
1553 def writeBlock(self):
1554 raise NotImplementedError
1554 raise NotImplementedError
1555
1555
1556 def putData(self):
1556 def putData(self):
1557 raise NotImplementedError
1557 raise NotImplementedError
1558
1558
1559 def getProcessFlags(self):
1559 def getProcessFlags(self):
1560
1560
1561 processFlags = 0
1561 processFlags = 0
1562
1562
1563 dtype_index = get_dtype_index(self.dtype)
1563 dtype_index = get_dtype_index(self.dtype)
1564 procflag_dtype = get_procflag_dtype(dtype_index)
1564 procflag_dtype = get_procflag_dtype(dtype_index)
1565
1565
1566 processFlags += procflag_dtype
1566 processFlags += procflag_dtype
1567
1567
1568 if self.dataOut.flagDecodeData:
1568 if self.dataOut.flagDecodeData:
1569 processFlags += PROCFLAG.DECODE_DATA
1569 processFlags += PROCFLAG.DECODE_DATA
1570
1570
1571 if self.dataOut.flagDeflipData:
1571 if self.dataOut.flagDeflipData:
1572 processFlags += PROCFLAG.DEFLIP_DATA
1572 processFlags += PROCFLAG.DEFLIP_DATA
1573
1573
1574 if self.dataOut.code is not None:
1574 if self.dataOut.code is not None:
1575 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1575 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1576
1576
1577 if self.dataOut.nCohInt > 1:
1577 if self.dataOut.nCohInt > 1:
1578 processFlags += PROCFLAG.COHERENT_INTEGRATION
1578 processFlags += PROCFLAG.COHERENT_INTEGRATION
1579
1579
1580 if self.dataOut.type == "Spectra":
1580 if self.dataOut.type == "Spectra":
1581 if self.dataOut.nIncohInt > 1:
1581 if self.dataOut.nIncohInt > 1:
1582 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1582 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1583
1583
1584 if self.dataOut.data_dc is not None:
1584 if self.dataOut.data_dc is not None:
1585 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1585 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1586
1586
1587 if self.dataOut.flagShiftFFT:
1587 if self.dataOut.flagShiftFFT:
1588 processFlags += PROCFLAG.SHIFT_FFT_DATA
1588 processFlags += PROCFLAG.SHIFT_FFT_DATA
1589
1589
1590 return processFlags
1590 return processFlags
1591
1591
1592 def setBasicHeader(self):
1592 def setBasicHeader(self):
1593
1593
1594 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1594 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1595 self.basicHeaderObj.version = self.versionFile
1595 self.basicHeaderObj.version = self.versionFile
1596 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1596 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1597
1597
1598 utc = numpy.floor(self.dataOut.utctime)
1598 utc = numpy.floor(self.dataOut.utctime)
1599 milisecond = (self.dataOut.utctime - utc) * 1000.0
1599 milisecond = (self.dataOut.utctime - utc) * 1000.0
1600
1600
1601 self.basicHeaderObj.utc = utc
1601 self.basicHeaderObj.utc = utc
1602 self.basicHeaderObj.miliSecond = milisecond
1602 self.basicHeaderObj.miliSecond = milisecond
1603 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1603 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1604 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1604 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1605 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1605 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1606
1606
1607 def setFirstHeader(self):
1607 def setFirstHeader(self):
1608 """
1608 """
1609 Obtiene una copia del First Header
1609 Obtiene una copia del First Header
1610
1610
1611 Affected:
1611 Affected:
1612
1612
1613 self.basicHeaderObj
1613 self.basicHeaderObj
1614 self.systemHeaderObj
1614 self.systemHeaderObj
1615 self.radarControllerHeaderObj
1615 self.radarControllerHeaderObj
1616 self.processingHeaderObj self.
1616 self.processingHeaderObj self.
1617
1617
1618 Return:
1618 Return:
1619 None
1619 None
1620 """
1620 """
1621
1621
1622 raise NotImplementedError
1622 raise NotImplementedError
1623
1623
1624 def __writeFirstHeader(self):
1624 def __writeFirstHeader(self):
1625 """
1625 """
1626 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1626 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1627
1627
1628 Affected:
1628 Affected:
1629 __dataType
1629 __dataType
1630
1630
1631 Return:
1631 Return:
1632 None
1632 None
1633 """
1633 """
1634
1634
1635 # CALCULAR PARAMETROS
1635 # CALCULAR PARAMETROS
1636
1636
1637 sizeLongHeader = self.systemHeaderObj.size + \
1637 sizeLongHeader = self.systemHeaderObj.size + \
1638 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1638 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1639 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1639 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1640
1640
1641 self.basicHeaderObj.write(self.fp)
1641 self.basicHeaderObj.write(self.fp)
1642 self.systemHeaderObj.write(self.fp)
1642 self.systemHeaderObj.write(self.fp)
1643 self.radarControllerHeaderObj.write(self.fp)
1643 self.radarControllerHeaderObj.write(self.fp)
1644 self.processingHeaderObj.write(self.fp)
1644 self.processingHeaderObj.write(self.fp)
1645
1645
1646 def __setNewBlock(self):
1646 def __setNewBlock(self):
1647 """
1647 """
1648 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1648 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1649
1649
1650 Return:
1650 Return:
1651 0 : si no pudo escribir nada
1651 0 : si no pudo escribir nada
1652 1 : Si escribio el Basic el First Header
1652 1 : Si escribio el Basic el First Header
1653 """
1653 """
1654 if self.fp == None:
1654 if self.fp == None:
1655 self.setNextFile()
1655 self.setNextFile()
1656
1656
1657 if self.flagIsNewFile:
1657 if self.flagIsNewFile:
1658 return 1
1658 return 1
1659
1659
1660 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1660 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1661 self.basicHeaderObj.write(self.fp)
1661 self.basicHeaderObj.write(self.fp)
1662 return 1
1662 return 1
1663
1663
1664 if not(self.setNextFile()):
1664 if not(self.setNextFile()):
1665 return 0
1665 return 0
1666
1666
1667 return 1
1667 return 1
1668
1668
1669 def writeNextBlock(self):
1669 def writeNextBlock(self):
1670 """
1670 """
1671 Selecciona el bloque siguiente de datos y los escribe en un file
1671 Selecciona el bloque siguiente de datos y los escribe en un file
1672
1672
1673 Return:
1673 Return:
1674 0 : Si no hizo pudo escribir el bloque de datos
1674 0 : Si no hizo pudo escribir el bloque de datos
1675 1 : Si no pudo escribir el bloque de datos
1675 1 : Si no pudo escribir el bloque de datos
1676 """
1676 """
1677 if not(self.__setNewBlock()):
1677 if not(self.__setNewBlock()):
1678 return 0
1678 return 0
1679
1679
1680 self.writeBlock()
1680 self.writeBlock()
1681
1681
1682 print("[Writing] Block No. %d/%d" % (self.blockIndex,
1682 print("[Writing] Block No. %d/%d" % (self.blockIndex,
1683 self.processingHeaderObj.dataBlocksPerFile))
1683 self.processingHeaderObj.dataBlocksPerFile))
1684
1684
1685 return 1
1685 return 1
1686
1686
1687 def setNextFile(self):
1687 def setNextFile(self):
1688 """
1688 """
1689 Determina el siguiente file que sera escrito
1689 Determina el siguiente file que sera escrito
1690
1690
1691 Affected:
1691 Affected:
1692 self.filename
1692 self.filename
1693 self.subfolder
1693 self.subfolder
1694 self.fp
1694 self.fp
1695 self.setFile
1695 self.setFile
1696 self.flagIsNewFile
1696 self.flagIsNewFile
1697
1697
1698 Return:
1698 Return:
1699 0 : Si el archivo no puede ser escrito
1699 0 : Si el archivo no puede ser escrito
1700 1 : Si el archivo esta listo para ser escrito
1700 1 : Si el archivo esta listo para ser escrito
1701 """
1701 """
1702 ext = self.ext
1702 ext = self.ext
1703 path = self.path
1703 path = self.path
1704
1704
1705 if self.fp != None:
1705 if self.fp != None:
1706 self.fp.close()
1706 self.fp.close()
1707
1707
1708 timeTuple = time.localtime(self.dataOut.utctime)
1708 timeTuple = time.localtime(self.dataOut.utctime)
1709 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1709 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1710
1710
1711 fullpath = os.path.join(path, subfolder)
1711 fullpath = os.path.join(path, subfolder)
1712 setFile = self.setFile
1712 setFile = self.setFile
1713
1713
1714 if not(os.path.exists(fullpath)):
1714 if not(os.path.exists(fullpath)):
1715 os.mkdir(fullpath)
1715 os.mkdir(fullpath)
1716 setFile = -1 # inicializo mi contador de seteo
1716 setFile = -1 # inicializo mi contador de seteo
1717 else:
1717 else:
1718 filesList = os.listdir(fullpath)
1718 filesList = os.listdir(fullpath)
1719 if len(filesList) > 0:
1719 if len(filesList) > 0:
1720 filesList = sorted(filesList, key=str.lower)
1720 filesList = sorted(filesList, key=str.lower)
1721 filen = filesList[-1]
1721 filen = filesList[-1]
1722 # el filename debera tener el siguiente formato
1722 # el filename debera tener el siguiente formato
1723 # 0 1234 567 89A BCDE (hex)
1723 # 0 1234 567 89A BCDE (hex)
1724 # x YYYY DDD SSS .ext
1724 # x YYYY DDD SSS .ext
1725 if isNumber(filen[8:11]):
1725 if isNumber(filen[8:11]):
1726 # inicializo mi contador de seteo al seteo del ultimo file
1726 # inicializo mi contador de seteo al seteo del ultimo file
1727 setFile = int(filen[8:11])
1727 setFile = int(filen[8:11])
1728 else:
1728 else:
1729 setFile = -1
1729 setFile = -1
1730 else:
1730 else:
1731 setFile = -1 # inicializo mi contador de seteo
1731 setFile = -1 # inicializo mi contador de seteo
1732
1732
1733 setFile += 1
1733 setFile += 1
1734
1734
1735 # If this is a new day it resets some values
1735 # If this is a new day it resets some values
1736 if self.dataOut.datatime.date() > self.fileDate:
1736 if self.dataOut.datatime.date() > self.fileDate:
1737 setFile = 0
1737 setFile = 0
1738 self.nTotalBlocks = 0
1738 self.nTotalBlocks = 0
1739
1739
1740 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1740 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1741 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1741 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1742
1742
1743 filename = os.path.join(path, subfolder, filen)
1743 filename = os.path.join(path, subfolder, filen)
1744
1744
1745 fp = open(filename, 'wb')
1745 fp = open(filename, 'wb')
1746
1746
1747 self.blockIndex = 0
1747 self.blockIndex = 0
1748
1748
1749 # guardando atributos
1749 # guardando atributos
1750 self.filename = filename
1750 self.filename = filename
1751 self.subfolder = subfolder
1751 self.subfolder = subfolder
1752 self.fp = fp
1752 self.fp = fp
1753 self.setFile = setFile
1753 self.setFile = setFile
1754 self.flagIsNewFile = 1
1754 self.flagIsNewFile = 1
1755 self.fileDate = self.dataOut.datatime.date()
1755 self.fileDate = self.dataOut.datatime.date()
1756
1756
1757 self.setFirstHeader()
1757 self.setFirstHeader()
1758
1758
1759 print('[Writing] Opening file: %s' % self.filename)
1759 print('[Writing] Opening file: %s' % self.filename)
1760
1760
1761 self.__writeFirstHeader()
1761 self.__writeFirstHeader()
1762
1762
1763 return 1
1763 return 1
1764
1764
1765 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1765 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1766 """
1766 """
1767 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1767 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1768
1768
1769 Inputs:
1769 Inputs:
1770 path : directory where data will be saved
1770 path : directory where data will be saved
1771 profilesPerBlock : number of profiles per block
1771 profilesPerBlock : number of profiles per block
1772 set : initial file set
1772 set : initial file set
1773 datatype : An integer number that defines data type:
1773 datatype : An integer number that defines data type:
1774 0 : int8 (1 byte)
1774 0 : int8 (1 byte)
1775 1 : int16 (2 bytes)
1775 1 : int16 (2 bytes)
1776 2 : int32 (4 bytes)
1776 2 : int32 (4 bytes)
1777 3 : int64 (8 bytes)
1777 3 : int64 (8 bytes)
1778 4 : float32 (4 bytes)
1778 4 : float32 (4 bytes)
1779 5 : double64 (8 bytes)
1779 5 : double64 (8 bytes)
1780
1780
1781 Return:
1781 Return:
1782 0 : Si no realizo un buen seteo
1782 0 : Si no realizo un buen seteo
1783 1 : Si realizo un buen seteo
1783 1 : Si realizo un buen seteo
1784 """
1784 """
1785
1785
1786 if ext == None:
1786 if ext == None:
1787 ext = self.ext
1787 ext = self.ext
1788
1788
1789 self.ext = ext.lower()
1789 self.ext = ext.lower()
1790
1790
1791 self.path = path
1791 self.path = path
1792
1792
1793 if set is None:
1793 if set is None:
1794 self.setFile = -1
1794 self.setFile = -1
1795 else:
1795 else:
1796 self.setFile = set - 1
1796 self.setFile = set - 1
1797
1797
1798 self.blocksPerFile = blocksPerFile
1798 self.blocksPerFile = blocksPerFile
1799
1799
1800 self.profilesPerBlock = profilesPerBlock
1800 self.profilesPerBlock = profilesPerBlock
1801
1801
1802 self.dataOut = dataOut
1802 self.dataOut = dataOut
1803 self.fileDate = self.dataOut.datatime.date()
1803 self.fileDate = self.dataOut.datatime.date()
1804 # By default
1804 # By default
1805 self.dtype = self.dataOut.dtype
1805 self.dtype = self.dataOut.dtype
1806
1806
1807 if datatype is not None:
1807 if datatype is not None:
1808 self.dtype = get_numpy_dtype(datatype)
1808 self.dtype = get_numpy_dtype(datatype)
1809
1809
1810 if not(self.setNextFile()):
1810 if not(self.setNextFile()):
1811 print("[Writing] There isn't a next file")
1811 print("[Writing] There isn't a next file")
1812 return 0
1812 return 0
1813
1813
1814 self.setBlockDimension()
1814 self.setBlockDimension()
1815
1815
1816 return 1
1816 return 1
1817
1817
1818 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1818 def run(self, dataOut, path, blocksPerFile=100, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1819
1819
1820 if not(self.isConfig):
1820 if not(self.isConfig):
1821
1821
1822 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1822 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1823 set=set, ext=ext, datatype=datatype, **kwargs)
1823 set=set, ext=ext, datatype=datatype, **kwargs)
1824 self.isConfig = True
1824 self.isConfig = True
1825
1825
1826 self.dataOut = dataOut
1826 self.dataOut = dataOut
1827 self.putData()
1827 self.putData()
1828 return self.dataOut No newline at end of file
1828 return self.dataOut
This diff has been collapsed as it changes many lines, (607 lines changed) Show them Hide them
@@ -1,1180 +1,697
1 import os
1 import os
2 import sys
2 import sys
3 import glob
3 import glob
4 import fnmatch
4 import fnmatch
5 import datetime
5 import datetime
6 import time
6 import time
7 import re
7 import re
8 import h5py
8 import h5py
9 import numpy
9 import numpy
10
10
11 import pylab as plb
11 import pylab as plb
12 from scipy.optimize import curve_fit
12 from scipy.optimize import curve_fit
13 from scipy import asarray as ar, exp
13 from scipy import asarray as ar, exp
14 from scipy import stats
14 from scipy import stats
15
15
16 from numpy.ma.core import getdata
16 from numpy.ma.core import getdata
17
17
18 SPEED_OF_LIGHT = 299792458
18 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
19 SPEED_OF_LIGHT = 3e8
20
20
21 try:
21 try:
22 from gevent import sleep
22 from gevent import sleep
23 except:
23 except:
24 from time import sleep
24 from time import sleep
25
25
26 from schainpy.model.data.jrodata import Spectra
26 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN
30 from numpy import imag, shape, NaN
31
31
32 from .jroIO_base import JRODataReader
32 from .jroIO_base import JRODataReader
33
33
34
34
35 class Header(object):
35 class Header(object):
36
36
37 def __init__(self):
37 def __init__(self):
38 raise NotImplementedError
38 raise NotImplementedError
39
39
40 def read(self):
40 def read(self):
41
41
42 raise NotImplementedError
42 raise NotImplementedError
43
43
44 def write(self):
44 def write(self):
45
45
46 raise NotImplementedError
46 raise NotImplementedError
47
47
48 def printInfo(self):
48 def printInfo(self):
49
49
50 message = "#" * 50 + "\n"
50 message = "#" * 50 + "\n"
51 message += self.__class__.__name__.upper() + "\n"
51 message += self.__class__.__name__.upper() + "\n"
52 message += "#" * 50 + "\n"
52 message += "#" * 50 + "\n"
53
53
54 keyList = list(self.__dict__.keys())
54 keyList = list(self.__dict__.keys())
55 keyList.sort()
55 keyList.sort()
56
56
57 for key in keyList:
57 for key in keyList:
58 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
58 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
59
59
60 if "size" not in keyList:
60 if "size" not in keyList:
61 attr = getattr(self, "size")
61 attr = getattr(self, "size")
62
62
63 if attr:
63 if attr:
64 message += "%s = %s" % ("size", attr) + "\n"
64 message += "%s = %s" % ("size", attr) + "\n"
65
65
66 # print message
67
68
69 FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes
66 FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes
70 ('FileMgcNumber', '<u4'), # 0x23020100
67 ('FileMgcNumber', '<u4'), # 0x23020100
71 # No Of FDT data records in this file (0 or more)
68 # No Of FDT data records in this file (0 or more)
72 ('nFDTdataRecors', '<u4'),
69 ('nFDTdataRecors', '<u4'),
73 ('OffsetStartHeader', '<u4'),
70 ('OffsetStartHeader', '<u4'),
74 ('RadarUnitId', '<u4'),
71 ('RadarUnitId', '<u4'),
75 ('SiteName', numpy.str_, 32), # Null terminated
72 ('SiteName', numpy.str_, 32), # Null terminated
76 ])
73 ])
77
74
78
75
79 class FileHeaderBLTR(Header):
76 class FileHeaderBLTR(Header):
80
77
81 def __init__(self):
78 def __init__(self):
82
79
83 self.FileMgcNumber = 0 # 0x23020100
80 self.FileMgcNumber = 0 # 0x23020100
84 # No Of FDT data records in this file (0 or more)
81 # No Of FDT data records in this file (0 or more)
85 self.nFDTdataRecors = 0
82 self.nFDTdataRecors = 0
86 self.RadarUnitId = 0
83 self.RadarUnitId = 0
87 self.OffsetStartHeader = 0
84 self.OffsetStartHeader = 0
88 self.SiteName = ""
85 self.SiteName = ""
89 self.size = 48
86 self.size = 48
90
87
91 def FHread(self, fp):
88 def FHread(self, fp):
92 # try:
89 # try:
93 startFp = open(fp, "rb")
90 startFp = open(fp, "rb")
94
91
95 header = numpy.fromfile(startFp, FILE_STRUCTURE, 1)
92 header = numpy.fromfile(startFp, FILE_STRUCTURE, 1)
96
93
97 print(' ')
98 print('puntero file header', startFp.tell())
99 print(' ')
100
101 ''' numpy.fromfile(file, dtype, count, sep='')
102 file : file or str
103 Open file object or filename.
104
105 dtype : data-type
106 Data type of the returned array. For binary files, it is used to determine
107 the size and byte-order of the items in the file.
108
109 count : int
110 Number of items to read. -1 means all items (i.e., the complete file).
111
112 sep : str
113 Separator between items if file is a text file. Empty ("") separator means
114 the file should be treated as binary. Spaces (" ") in the separator match zero
115 or more whitespace characters. A separator consisting only of spaces must match
116 at least one whitespace.
117
118 '''
119
120 self.FileMgcNumber = hex(header['FileMgcNumber'][0])
94 self.FileMgcNumber = hex(header['FileMgcNumber'][0])
121 # No Of FDT data records in this file (0 or more)
95 # No Of FDT data records in this file (0 or more)
122 self.nFDTdataRecors = int(header['nFDTdataRecors'][0])
96 self.nFDTdataRecors = int(header['nFDTdataRecors'][0])
123 self.RadarUnitId = int(header['RadarUnitId'][0])
97 self.RadarUnitId = int(header['RadarUnitId'][0])
124 self.OffsetStartHeader = int(header['OffsetStartHeader'][0])
98 self.OffsetStartHeader = int(header['OffsetStartHeader'][0])
125 self.SiteName = str(header['SiteName'][0])
99 self.SiteName = str(header['SiteName'][0])
126
100
127 # print 'Numero de bloques', self.nFDTdataRecors
128
129 if self.size < 48:
101 if self.size < 48:
130 return 0
102 return 0
131
103
132 return 1
104 return 1
133
105
134 def write(self, fp):
106 def write(self, fp):
135
107
136 headerTuple = (self.FileMgcNumber,
108 headerTuple = (self.FileMgcNumber,
137 self.nFDTdataRecors,
109 self.nFDTdataRecors,
138 self.RadarUnitId,
110 self.RadarUnitId,
139 self.SiteName,
111 self.SiteName,
140 self.size)
112 self.size)
141
113
142 header = numpy.array(headerTuple, FILE_STRUCTURE)
114 header = numpy.array(headerTuple, FILE_STRUCTURE)
143 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
115 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
144 header.tofile(fp)
116 header.tofile(fp)
145 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
117 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
146
118
147 fid : file or str
119 fid : file or str
148 An open file object, or a string containing a filename.
120 An open file object, or a string containing a filename.
149
121
150 sep : str
122 sep : str
151 Separator between array items for text output. If "" (empty), a binary file is written,
123 Separator between array items for text output. If "" (empty), a binary file is written,
152 equivalent to file.write(a.tobytes()).
124 equivalent to file.write(a.tobytes()).
153
125
154 format : str
126 format : str
155 Format string for text file output. Each entry in the array is formatted to text by
127 Format string for text file output. Each entry in the array is formatted to text by
156 first converting it to the closest Python type, and then using "format" % item.
128 first converting it to the closest Python type, and then using "format" % item.
157
129
158 '''
130 '''
159
131
160 return 1
132 return 1
161
133
162
134
163 RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes
135 RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes
164 ('RecMgcNumber', '<u4'), # 0x23030001
136 ('RecMgcNumber', '<u4'), # 0x23030001
165 ('RecCounter', '<u4'), # Record counter(0,1, ...)
137 ('RecCounter', '<u4'), # Record counter(0,1, ...)
166 # Offset to start of next record form start of this record
138 # Offset to start of next record form start of this record
167 ('Off2StartNxtRec', '<u4'),
139 ('Off2StartNxtRec', '<u4'),
168 # Offset to start of data from start of this record
140 # Offset to start of data from start of this record
169 ('Off2StartData', '<u4'),
141 ('Off2StartData', '<u4'),
170 # Epoch time stamp of start of acquisition (seconds)
142 # Epoch time stamp of start of acquisition (seconds)
171 ('nUtime', '<i4'),
143 ('nUtime', '<i4'),
172 # Millisecond component of time stamp (0,...,999)
144 # Millisecond component of time stamp (0,...,999)
173 ('nMilisec', '<u4'),
145 ('nMilisec', '<u4'),
174 # Experiment tag name (null terminated)
146 # Experiment tag name (null terminated)
175 ('ExpTagName', numpy.str_, 32),
147 ('ExpTagName', numpy.str_, 32),
176 # Experiment comment (null terminated)
148 # Experiment comment (null terminated)
177 ('ExpComment', numpy.str_, 32),
149 ('ExpComment', numpy.str_, 32),
178 # Site latitude (from GPS) in degrees (positive implies North)
150 # Site latitude (from GPS) in degrees (positive implies North)
179 ('SiteLatDegrees', '<f4'),
151 ('SiteLatDegrees', '<f4'),
180 # Site longitude (from GPS) in degrees (positive implies East)
152 # Site longitude (from GPS) in degrees (positive implies East)
181 ('SiteLongDegrees', '<f4'),
153 ('SiteLongDegrees', '<f4'),
182 # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
154 # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
183 ('RTCgpsStatus', '<u4'),
155 ('RTCgpsStatus', '<u4'),
184 ('TransmitFrec', '<u4'), # Transmit frequency (Hz)
156 ('TransmitFrec', '<u4'), # Transmit frequency (Hz)
185 ('ReceiveFrec', '<u4'), # Receive frequency
157 ('ReceiveFrec', '<u4'), # Receive frequency
186 # First local oscillator frequency (Hz)
158 # First local oscillator frequency (Hz)
187 ('FirstOsciFrec', '<u4'),
159 ('FirstOsciFrec', '<u4'),
188 # (0="O", 1="E", 2="linear 1", 3="linear2")
160 # (0="O", 1="E", 2="linear 1", 3="linear2")
189 ('Polarisation', '<u4'),
161 ('Polarisation', '<u4'),
190 # Receiver filter settings (0,1,2,3)
162 # Receiver filter settings (0,1,2,3)
191 ('ReceiverFiltSett', '<u4'),
163 ('ReceiverFiltSett', '<u4'),
192 # Number of modes in use (1 or 2)
164 # Number of modes in use (1 or 2)
193 ('nModesInUse', '<u4'),
165 ('nModesInUse', '<u4'),
194 # Dual Mode index number for these data (0 or 1)
166 # Dual Mode index number for these data (0 or 1)
195 ('DualModeIndex', '<u4'),
167 ('DualModeIndex', '<u4'),
196 # Dual Mode range correction for these data (m)
168 # Dual Mode range correction for these data (m)
197 ('DualModeRange', '<u4'),
169 ('DualModeRange', '<u4'),
198 # Number of digital channels acquired (2*N)
170 # Number of digital channels acquired (2*N)
199 ('nDigChannels', '<u4'),
171 ('nDigChannels', '<u4'),
200 # Sampling resolution (meters)
172 # Sampling resolution (meters)
201 ('SampResolution', '<u4'),
173 ('SampResolution', '<u4'),
202 # Number of range gates sampled
174 # Number of range gates sampled
203 ('nHeights', '<u4'),
175 ('nHeights', '<u4'),
204 # Start range of sampling (meters)
176 # Start range of sampling (meters)
205 ('StartRangeSamp', '<u4'),
177 ('StartRangeSamp', '<u4'),
206 ('PRFhz', '<u4'), # PRF (Hz)
178 ('PRFhz', '<u4'), # PRF (Hz)
207 ('nCohInt', '<u4'), # Integrations
179 ('nCohInt', '<u4'), # Integrations
208 # Number of data points transformed
180 # Number of data points transformed
209 ('nProfiles', '<u4'),
181 ('nProfiles', '<u4'),
210 # Number of receive beams stored in file (1 or N)
182 # Number of receive beams stored in file (1 or N)
211 ('nChannels', '<u4'),
183 ('nChannels', '<u4'),
212 ('nIncohInt', '<u4'), # Number of spectral averages
184 ('nIncohInt', '<u4'), # Number of spectral averages
213 # FFT windowing index (0 = no window)
185 # FFT windowing index (0 = no window)
214 ('FFTwindowingInd', '<u4'),
186 ('FFTwindowingInd', '<u4'),
215 # Beam steer angle (azimuth) in degrees (clockwise from true North)
187 # Beam steer angle (azimuth) in degrees (clockwise from true North)
216 ('BeamAngleAzim', '<f4'),
188 ('BeamAngleAzim', '<f4'),
217 # Beam steer angle (zenith) in degrees (0=> vertical)
189 # Beam steer angle (zenith) in degrees (0=> vertical)
218 ('BeamAngleZen', '<f4'),
190 ('BeamAngleZen', '<f4'),
219 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
191 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
220 ('AntennaCoord0', '<f4'),
192 ('AntennaCoord0', '<f4'),
221 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
193 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
222 ('AntennaAngl0', '<f4'),
194 ('AntennaAngl0', '<f4'),
223 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
195 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
224 ('AntennaCoord1', '<f4'),
196 ('AntennaCoord1', '<f4'),
225 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
197 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
226 ('AntennaAngl1', '<f4'),
198 ('AntennaAngl1', '<f4'),
227 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
199 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
228 ('AntennaCoord2', '<f4'),
200 ('AntennaCoord2', '<f4'),
229 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
201 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
230 ('AntennaAngl2', '<f4'),
202 ('AntennaAngl2', '<f4'),
231 # Receiver phase calibration (degrees) - N values
203 # Receiver phase calibration (degrees) - N values
232 ('RecPhaseCalibr0', '<f4'),
204 ('RecPhaseCalibr0', '<f4'),
233 # Receiver phase calibration (degrees) - N values
205 # Receiver phase calibration (degrees) - N values
234 ('RecPhaseCalibr1', '<f4'),
206 ('RecPhaseCalibr1', '<f4'),
235 # Receiver phase calibration (degrees) - N values
207 # Receiver phase calibration (degrees) - N values
236 ('RecPhaseCalibr2', '<f4'),
208 ('RecPhaseCalibr2', '<f4'),
237 # Receiver amplitude calibration (ratio relative to receiver one) - N values
209 # Receiver amplitude calibration (ratio relative to receiver one) - N values
238 ('RecAmpCalibr0', '<f4'),
210 ('RecAmpCalibr0', '<f4'),
239 # Receiver amplitude calibration (ratio relative to receiver one) - N values
211 # Receiver amplitude calibration (ratio relative to receiver one) - N values
240 ('RecAmpCalibr1', '<f4'),
212 ('RecAmpCalibr1', '<f4'),
241 # Receiver amplitude calibration (ratio relative to receiver one) - N values
213 # Receiver amplitude calibration (ratio relative to receiver one) - N values
242 ('RecAmpCalibr2', '<f4'),
214 ('RecAmpCalibr2', '<f4'),
243 # Receiver gains in dB - N values
215 # Receiver gains in dB - N values
244 ('ReceiverGaindB0', '<i4'),
216 ('ReceiverGaindB0', '<i4'),
245 # Receiver gains in dB - N values
217 # Receiver gains in dB - N values
246 ('ReceiverGaindB1', '<i4'),
218 ('ReceiverGaindB1', '<i4'),
247 # Receiver gains in dB - N values
219 # Receiver gains in dB - N values
248 ('ReceiverGaindB2', '<i4'),
220 ('ReceiverGaindB2', '<i4'),
249 ])
221 ])
250
222
251
223
252 class RecordHeaderBLTR(Header):
224 class RecordHeaderBLTR(Header):
253
225
254 def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248,
226 def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248,
255 nUtime=0, nMilisec=0, ExpTagName=None,
227 nUtime=0, nMilisec=0, ExpTagName=None,
256 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0,
228 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0,
257 RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0,
229 RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0,
258 FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0,
230 FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0,
259 nModesInUse=0, DualModeIndex=0, DualModeRange=0,
231 nModesInUse=0, DualModeIndex=0, DualModeRange=0,
260 nDigChannels=0, SampResolution=0, nHeights=0,
232 nDigChannels=0, SampResolution=0, nHeights=0,
261 StartRangeSamp=0, PRFhz=0, nCohInt=0,
233 StartRangeSamp=0, PRFhz=0, nCohInt=0,
262 nProfiles=0, nChannels=0, nIncohInt=0,
234 nProfiles=0, nChannels=0, nIncohInt=0,
263 FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0,
235 FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0,
264 AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0,
236 AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0,
265 RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0,
237 RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0,
266 RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0,
238 RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0,
267 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
239 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
268 ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0):
240 ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0):
269
241
270 self.RecMgcNumber = RecMgcNumber # 0x23030001
242 self.RecMgcNumber = RecMgcNumber # 0x23030001
271 self.RecCounter = RecCounter
243 self.RecCounter = RecCounter
272 self.Off2StartNxtRec = Off2StartNxtRec
244 self.Off2StartNxtRec = Off2StartNxtRec
273 self.Off2StartData = Off2StartData
245 self.Off2StartData = Off2StartData
274 self.nUtime = nUtime
246 self.nUtime = nUtime
275 self.nMilisec = nMilisec
247 self.nMilisec = nMilisec
276 self.ExpTagName = ExpTagName
248 self.ExpTagName = ExpTagName
277 self.ExpComment = ExpComment
249 self.ExpComment = ExpComment
278 self.SiteLatDegrees = SiteLatDegrees
250 self.SiteLatDegrees = SiteLatDegrees
279 self.SiteLongDegrees = SiteLongDegrees
251 self.SiteLongDegrees = SiteLongDegrees
280 self.RTCgpsStatus = RTCgpsStatus
252 self.RTCgpsStatus = RTCgpsStatus
281 self.TransmitFrec = TransmitFrec
253 self.TransmitFrec = TransmitFrec
282 self.ReceiveFrec = ReceiveFrec
254 self.ReceiveFrec = ReceiveFrec
283 self.FirstOsciFrec = FirstOsciFrec
255 self.FirstOsciFrec = FirstOsciFrec
284 self.Polarisation = Polarisation
256 self.Polarisation = Polarisation
285 self.ReceiverFiltSett = ReceiverFiltSett
257 self.ReceiverFiltSett = ReceiverFiltSett
286 self.nModesInUse = nModesInUse
258 self.nModesInUse = nModesInUse
287 self.DualModeIndex = DualModeIndex
259 self.DualModeIndex = DualModeIndex
288 self.DualModeRange = DualModeRange
260 self.DualModeRange = DualModeRange
289 self.nDigChannels = nDigChannels
261 self.nDigChannels = nDigChannels
290 self.SampResolution = SampResolution
262 self.SampResolution = SampResolution
291 self.nHeights = nHeights
263 self.nHeights = nHeights
292 self.StartRangeSamp = StartRangeSamp
264 self.StartRangeSamp = StartRangeSamp
293 self.PRFhz = PRFhz
265 self.PRFhz = PRFhz
294 self.nCohInt = nCohInt
266 self.nCohInt = nCohInt
295 self.nProfiles = nProfiles
267 self.nProfiles = nProfiles
296 self.nChannels = nChannels
268 self.nChannels = nChannels
297 self.nIncohInt = nIncohInt
269 self.nIncohInt = nIncohInt
298 self.FFTwindowingInd = FFTwindowingInd
270 self.FFTwindowingInd = FFTwindowingInd
299 self.BeamAngleAzim = BeamAngleAzim
271 self.BeamAngleAzim = BeamAngleAzim
300 self.BeamAngleZen = BeamAngleZen
272 self.BeamAngleZen = BeamAngleZen
301 self.AntennaCoord0 = AntennaCoord0
273 self.AntennaCoord0 = AntennaCoord0
302 self.AntennaAngl0 = AntennaAngl0
274 self.AntennaAngl0 = AntennaAngl0
303 self.AntennaAngl1 = AntennaAngl1
275 self.AntennaAngl1 = AntennaAngl1
304 self.AntennaAngl2 = AntennaAngl2
276 self.AntennaAngl2 = AntennaAngl2
305 self.AntennaCoord1 = AntennaCoord1
277 self.AntennaCoord1 = AntennaCoord1
306 self.AntennaCoord2 = AntennaCoord2
278 self.AntennaCoord2 = AntennaCoord2
307 self.RecPhaseCalibr0 = RecPhaseCalibr0
279 self.RecPhaseCalibr0 = RecPhaseCalibr0
308 self.RecPhaseCalibr1 = RecPhaseCalibr1
280 self.RecPhaseCalibr1 = RecPhaseCalibr1
309 self.RecPhaseCalibr2 = RecPhaseCalibr2
281 self.RecPhaseCalibr2 = RecPhaseCalibr2
310 self.RecAmpCalibr0 = RecAmpCalibr0
282 self.RecAmpCalibr0 = RecAmpCalibr0
311 self.RecAmpCalibr1 = RecAmpCalibr1
283 self.RecAmpCalibr1 = RecAmpCalibr1
312 self.RecAmpCalibr2 = RecAmpCalibr2
284 self.RecAmpCalibr2 = RecAmpCalibr2
313 self.ReceiverGaindB0 = ReceiverGaindB0
285 self.ReceiverGaindB0 = ReceiverGaindB0
314 self.ReceiverGaindB1 = ReceiverGaindB1
286 self.ReceiverGaindB1 = ReceiverGaindB1
315 self.ReceiverGaindB2 = ReceiverGaindB2
287 self.ReceiverGaindB2 = ReceiverGaindB2
316 self.OffsetStartHeader = 48
288 self.OffsetStartHeader = 48
317
289
318 def RHread(self, fp):
290 def RHread(self, fp):
319 # print fp
320 # 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.
321 # The method tell() returns the current position of the file read/write pointer within the file.
322 startFp = open(fp, "rb")
291 startFp = open(fp, "rb")
323 # RecCounter=0
324 # Off2StartNxtRec=811248
325 OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
292 OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
326 print(' ')
327 print('puntero Record Header', startFp.tell())
328 print(' ')
329
330 startFp.seek(OffRHeader, os.SEEK_SET)
293 startFp.seek(OffRHeader, os.SEEK_SET)
331
332 print(' ')
333 print('puntero Record Header con seek', startFp.tell())
334 print(' ')
335
336 # print 'Posicion del bloque: ',OffRHeader
337
338 header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1)
294 header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1)
339
340 print(' ')
341 print('puntero Record Header con seek', startFp.tell())
342 print(' ')
343
344 print(' ')
345 #
346 # print 'puntero Record Header despues de seek', header.tell()
347 print(' ')
348
349 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001
295 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001
350 self.RecCounter = int(header['RecCounter'][0])
296 self.RecCounter = int(header['RecCounter'][0])
351 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
297 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
352 self.Off2StartData = int(header['Off2StartData'][0])
298 self.Off2StartData = int(header['Off2StartData'][0])
353 self.nUtime = header['nUtime'][0]
299 self.nUtime = header['nUtime'][0]
354 self.nMilisec = header['nMilisec'][0]
300 self.nMilisec = header['nMilisec'][0]
355 self.ExpTagName = str(header['ExpTagName'][0])
301 self.ExpTagName = str(header['ExpTagName'][0])
356 self.ExpComment = str(header['ExpComment'][0])
302 self.ExpComment = str(header['ExpComment'][0])
357 self.SiteLatDegrees = header['SiteLatDegrees'][0]
303 self.SiteLatDegrees = header['SiteLatDegrees'][0]
358 self.SiteLongDegrees = header['SiteLongDegrees'][0]
304 self.SiteLongDegrees = header['SiteLongDegrees'][0]
359 self.RTCgpsStatus = header['RTCgpsStatus'][0]
305 self.RTCgpsStatus = header['RTCgpsStatus'][0]
360 self.TransmitFrec = header['TransmitFrec'][0]
306 self.TransmitFrec = header['TransmitFrec'][0]
361 self.ReceiveFrec = header['ReceiveFrec'][0]
307 self.ReceiveFrec = header['ReceiveFrec'][0]
362 self.FirstOsciFrec = header['FirstOsciFrec'][0]
308 self.FirstOsciFrec = header['FirstOsciFrec'][0]
363 self.Polarisation = header['Polarisation'][0]
309 self.Polarisation = header['Polarisation'][0]
364 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
310 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
365 self.nModesInUse = header['nModesInUse'][0]
311 self.nModesInUse = header['nModesInUse'][0]
366 self.DualModeIndex = header['DualModeIndex'][0]
312 self.DualModeIndex = header['DualModeIndex'][0]
367 self.DualModeRange = header['DualModeRange'][0]
313 self.DualModeRange = header['DualModeRange'][0]
368 self.nDigChannels = header['nDigChannels'][0]
314 self.nDigChannels = header['nDigChannels'][0]
369 self.SampResolution = header['SampResolution'][0]
315 self.SampResolution = header['SampResolution'][0]
370 self.nHeights = header['nHeights'][0]
316 self.nHeights = header['nHeights'][0]
371 self.StartRangeSamp = header['StartRangeSamp'][0]
317 self.StartRangeSamp = header['StartRangeSamp'][0]
372 self.PRFhz = header['PRFhz'][0]
318 self.PRFhz = header['PRFhz'][0]
373 self.nCohInt = header['nCohInt'][0]
319 self.nCohInt = header['nCohInt'][0]
374 self.nProfiles = header['nProfiles'][0]
320 self.nProfiles = header['nProfiles'][0]
375 self.nChannels = header['nChannels'][0]
321 self.nChannels = header['nChannels'][0]
376 self.nIncohInt = header['nIncohInt'][0]
322 self.nIncohInt = header['nIncohInt'][0]
377 self.FFTwindowingInd = header['FFTwindowingInd'][0]
323 self.FFTwindowingInd = header['FFTwindowingInd'][0]
378 self.BeamAngleAzim = header['BeamAngleAzim'][0]
324 self.BeamAngleAzim = header['BeamAngleAzim'][0]
379 self.BeamAngleZen = header['BeamAngleZen'][0]
325 self.BeamAngleZen = header['BeamAngleZen'][0]
380 self.AntennaCoord0 = header['AntennaCoord0'][0]
326 self.AntennaCoord0 = header['AntennaCoord0'][0]
381 self.AntennaAngl0 = header['AntennaAngl0'][0]
327 self.AntennaAngl0 = header['AntennaAngl0'][0]
382 self.AntennaCoord1 = header['AntennaCoord1'][0]
328 self.AntennaCoord1 = header['AntennaCoord1'][0]
383 self.AntennaAngl1 = header['AntennaAngl1'][0]
329 self.AntennaAngl1 = header['AntennaAngl1'][0]
384 self.AntennaCoord2 = header['AntennaCoord2'][0]
330 self.AntennaCoord2 = header['AntennaCoord2'][0]
385 self.AntennaAngl2 = header['AntennaAngl2'][0]
331 self.AntennaAngl2 = header['AntennaAngl2'][0]
386 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
332 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
387 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
333 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
388 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
334 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
389 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
335 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
390 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
336 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
391 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
337 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
392 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
338 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
393 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
339 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
394 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
340 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
395
341
396 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
342 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
397
343
398 self.RHsize = 180 + 20 * self.nChannels
344 self.RHsize = 180 + 20 * self.nChannels
399 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
345 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
400 # print 'Datasize',self.Datasize
401 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
346 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
402
347
403 print('==============================================')
348
404 print('RecMgcNumber ', self.RecMgcNumber)
405 print('RecCounter ', self.RecCounter)
406 print('Off2StartNxtRec ', self.Off2StartNxtRec)
407 print('Off2StartData ', self.Off2StartData)
408 print('Range Resolution ', self.SampResolution)
409 print('First Height ', self.StartRangeSamp)
410 print('PRF (Hz) ', self.PRFhz)
411 print('Heights (K) ', self.nHeights)
412 print('Channels (N) ', self.nChannels)
413 print('Profiles (J) ', self.nProfiles)
414 print('iCoh ', self.nCohInt)
415 print('iInCoh ', self.nIncohInt)
416 print('BeamAngleAzim ', self.BeamAngleAzim)
417 print('BeamAngleZen ', self.BeamAngleZen)
418
419 # print 'ModoEnUso ',self.DualModeIndex
420 # print 'UtcTime ',self.nUtime
421 # print 'MiliSec ',self.nMilisec
422 # print 'Exp TagName ',self.ExpTagName
423 # print 'Exp Comment ',self.ExpComment
424 # print 'FFT Window Index ',self.FFTwindowingInd
425 # print 'N Dig. Channels ',self.nDigChannels
426 print('Size de bloque ', self.RHsize)
427 print('DataSize ', self.Datasize)
428 print('BeamAngleAzim ', self.BeamAngleAzim)
429 # print 'AntennaCoord0 ',self.AntennaCoord0
430 # print 'AntennaAngl0 ',self.AntennaAngl0
431 # print 'AntennaCoord1 ',self.AntennaCoord1
432 # print 'AntennaAngl1 ',self.AntennaAngl1
433 # print 'AntennaCoord2 ',self.AntennaCoord2
434 # print 'AntennaAngl2 ',self.AntennaAngl2
435 print('RecPhaseCalibr0 ', self.RecPhaseCalibr0)
436 print('RecPhaseCalibr1 ', self.RecPhaseCalibr1)
437 print('RecPhaseCalibr2 ', self.RecPhaseCalibr2)
438 print('RecAmpCalibr0 ', self.RecAmpCalibr0)
439 print('RecAmpCalibr1 ', self.RecAmpCalibr1)
440 print('RecAmpCalibr2 ', self.RecAmpCalibr2)
441 print('ReceiverGaindB0 ', self.ReceiverGaindB0)
442 print('ReceiverGaindB1 ', self.ReceiverGaindB1)
443 print('ReceiverGaindB2 ', self.ReceiverGaindB2)
444 print('==============================================')
445
446 if OffRHeader > endFp:
349 if OffRHeader > endFp:
447 sys.stderr.write(
350 sys.stderr.write(
448 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp)
351 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp)
449 return 0
352 return 0
450
353
451 if OffRHeader < endFp:
354 if OffRHeader < endFp:
452 sys.stderr.write(
355 sys.stderr.write(
453 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp)
356 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp)
454 return 0
357 return 0
455
358
456 return 1
359 return 1
457
360
458
361
459 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
362 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
460
363
461 path = None
364 path = None
462 startDate = None
365 startDate = None
463 endDate = None
366 endDate = None
464 startTime = None
367 startTime = None
465 endTime = None
368 endTime = None
466 walk = None
369 walk = None
467 isConfig = False
370 isConfig = False
468
371
469 fileList = None
372 fileList = None
470
373
471 # metadata
374 # metadata
472 TimeZone = None
375 TimeZone = None
473 Interval = None
376 Interval = None
474 heightList = None
377 heightList = None
475
378
476 # data
379 # data
477 data = None
380 data = None
478 utctime = None
381 utctime = None
479
382
480 def __init__(self, **kwargs):
383 def __init__(self, **kwargs):
481
384
482 # Eliminar de la base la herencia
385 # Eliminar de la base la herencia
483 ProcessingUnit.__init__(self, **kwargs)
386 ProcessingUnit.__init__(self, **kwargs)
484
387
485 #self.isConfig = False
388 #self.isConfig = False
486
389
487 #self.pts2read_SelfSpectra = 0
390 #self.pts2read_SelfSpectra = 0
488 #self.pts2read_CrossSpectra = 0
391 #self.pts2read_CrossSpectra = 0
489 #self.pts2read_DCchannels = 0
392 #self.pts2read_DCchannels = 0
490 #self.datablock = None
393 #self.datablock = None
491 self.utc = None
394 self.utc = None
492 self.ext = ".fdt"
395 self.ext = ".fdt"
493 self.optchar = "P"
396 self.optchar = "P"
494 self.fpFile = None
397 self.fpFile = None
495 self.fp = None
398 self.fp = None
496 self.BlockCounter = 0
399 self.BlockCounter = 0
497 self.dtype = None
400 self.dtype = None
498 self.fileSizeByHeader = None
401 self.fileSizeByHeader = None
499 self.filenameList = []
402 self.filenameList = []
500 self.fileSelector = 0
403 self.fileSelector = 0
501 self.Off2StartNxtRec = 0
404 self.Off2StartNxtRec = 0
502 self.RecCounter = 0
405 self.RecCounter = 0
503 self.flagNoMoreFiles = 0
406 self.flagNoMoreFiles = 0
504 self.data_spc = None
407 self.data_spc = None
505 self.data_cspc = None
408 self.data_cspc = None
506 self.data_output = None
409 self.data_output = None
507 self.path = None
410 self.path = None
508 self.OffsetStartHeader = 0
411 self.OffsetStartHeader = 0
509 self.Off2StartData = 0
412 self.Off2StartData = 0
510 self.ipp = 0
413 self.ipp = 0
511 self.nFDTdataRecors = 0
414 self.nFDTdataRecors = 0
512 self.blocksize = 0
415 self.blocksize = 0
513 self.dataOut = Spectra()
416 self.dataOut = Spectra()
514 self.profileIndex = 1 # Always
417 self.profileIndex = 1 # Always
515 self.dataOut.flagNoData = False
418 self.dataOut.flagNoData = False
516 self.dataOut.nRdPairs = 0
419 self.dataOut.nRdPairs = 0
517 self.dataOut.data_spc = None
420 self.dataOut.data_spc = None
518 self.dataOut.velocityX = []
421 self.dataOut.velocityX = []
519 self.dataOut.velocityY = []
422 self.dataOut.velocityY = []
520 self.dataOut.velocityV = []
423 self.dataOut.velocityV = []
521
424
522 def Files2Read(self, fp):
425 def Files2Read(self, fp):
523 '''
426 '''
524 Function that indicates the number of .fdt files that exist in the folder to be read.
427 Function that indicates the number of .fdt files that exist in the folder to be read.
525 It also creates an organized list with the names of the files to read.
428 It also creates an organized list with the names of the files to read.
526 '''
429 '''
527 # self.__checkPath()
430 # self.__checkPath()
528
431
529 # Gets the list of files within the fp address
432 # Gets the list of files within the fp address
530 ListaData = os.listdir(fp)
433 ListaData = os.listdir(fp)
531 # Sort the list of files from least to largest by names
434 # Sort the list of files from least to largest by names
532 ListaData = sorted(ListaData)
435 ListaData = sorted(ListaData)
533 nFiles = 0 # File Counter
436 nFiles = 0 # File Counter
534 FileList = [] # A list is created that will contain the .fdt files
437 FileList = [] # A list is created that will contain the .fdt files
535 for IndexFile in ListaData:
438 for IndexFile in ListaData:
536 if '.fdt' in IndexFile:
439 if '.fdt' in IndexFile:
537 FileList.append(IndexFile)
440 FileList.append(IndexFile)
538 nFiles += 1
441 nFiles += 1
539
442
540 # print 'Files2Read'
541 # print 'Existen '+str(nFiles)+' archivos .fdt'
542
543 self.filenameList = FileList # List of files from least to largest by names
443 self.filenameList = FileList # List of files from least to largest by names
544
444
545 def run(self, **kwargs):
445 def run(self, **kwargs):
546 '''
446 '''
547 This method will be the one that will initiate the data entry, will be called constantly.
447 This method will be the one that will initiate the data entry, will be called constantly.
548 You should first verify that your Setup () is set up and then continue to acquire
448 You should first verify that your Setup () is set up and then continue to acquire
549 the data to be processed with getData ().
449 the data to be processed with getData ().
550 '''
450 '''
551 if not self.isConfig:
451 if not self.isConfig:
552 self.setup(**kwargs)
452 self.setup(**kwargs)
553 self.isConfig = True
453 self.isConfig = True
554
454
555 self.getData()
455 self.getData()
556 # print 'running'
557
456
558 def setup(self, path=None,
457 def setup(self, path=None,
559 startDate=None,
458 startDate=None,
560 endDate=None,
459 endDate=None,
561 startTime=None,
460 startTime=None,
562 endTime=None,
461 endTime=None,
563 walk=True,
462 walk=True,
564 timezone='utc',
463 timezone='utc',
565 code=None,
464 code=None,
566 online=False,
465 online=False,
567 ReadMode=None,
466 ReadMode=None,
568 **kwargs):
467 **kwargs):
569
468
570 self.isConfig = True
469 self.isConfig = True
571
470
572 self.path = path
471 self.path = path
573 self.startDate = startDate
472 self.startDate = startDate
574 self.endDate = endDate
473 self.endDate = endDate
575 self.startTime = startTime
474 self.startTime = startTime
576 self.endTime = endTime
475 self.endTime = endTime
577 self.walk = walk
476 self.walk = walk
578 self.ReadMode = int(ReadMode)
477 self.ReadMode = int(ReadMode)
579
478
580 pass
479 pass
581
480
582 def getData(self):
481 def getData(self):
583 '''
482 '''
584 Before starting this function, you should check that there is still an unread file,
483 Before starting this function, you should check that there is still an unread file,
585 If there are still blocks to read or if the data block is empty.
484 If there are still blocks to read or if the data block is empty.
586
485
587 You should call the file "read".
486 You should call the file "read".
588
487
589 '''
488 '''
590
489
591 if self.flagNoMoreFiles:
490 if self.flagNoMoreFiles:
592 self.dataOut.flagNoData = True
491 self.dataOut.flagNoData = True
593 print('NoData se vuelve true')
594 return 0
492 return 0
595
493
596 self.fp = self.path
494 self.fp = self.path
597 self.Files2Read(self.fp)
495 self.Files2Read(self.fp)
598 self.readFile(self.fp)
496 self.readFile(self.fp)
599 self.dataOut.data_spc = self.data_spc
497 self.dataOut.data_spc = self.data_spc
600 self.dataOut.data_cspc = self.data_cspc
498 self.dataOut.data_cspc =self.data_cspc
601 self.dataOut.data_output = self.data_output
499 self.dataOut.data_output=self.data_output
602
500
603 print('self.dataOut.data_output', shape(self.dataOut.data_output))
501 return self.dataOut.data_spc
604
502
605 # self.removeDC()
503
606 return self.dataOut.data_spc
504 def readFile(self,fp):
607
608 def readFile(self, fp):
609 '''
505 '''
610 You must indicate if you are reading in Online or Offline mode and load the
506 You must indicate if you are reading in Online or Offline mode and load the
611 The parameters for this file reading mode.
507 The parameters for this file reading mode.
612
508
613 Then you must do 2 actions:
509 Then you must do 2 actions:
614
510
615 1. Get the BLTR FileHeader.
511 1. Get the BLTR FileHeader.
616 2. Start reading the first block.
512 2. Start reading the first block.
617 '''
513 '''
618
514
619 # The address of the folder is generated the name of the .fdt file that will be read
620 print("File: ", self.fileSelector + 1)
621
622 if self.fileSelector < len(self.filenameList):
515 if self.fileSelector < len(self.filenameList):
623
516
624 self.fpFile = str(fp) + '/' + \
517 self.fpFile = str(fp) + '/' + \
625 str(self.filenameList[self.fileSelector])
518 str(self.filenameList[self.fileSelector])
626 # print self.fpFile
627 fheader = FileHeaderBLTR()
519 fheader = FileHeaderBLTR()
628 fheader.FHread(self.fpFile) # Bltr FileHeader Reading
520 fheader.FHread(self.fpFile) # Bltr FileHeader Reading
629 self.nFDTdataRecors = fheader.nFDTdataRecors
521 self.nFDTdataRecors = fheader.nFDTdataRecors
630
522
631 self.readBlock() # Block reading
523 self.readBlock() # Block reading
632 else:
524 else:
633 print('readFile FlagNoData becomes true')
525 self.flagNoMoreFiles=True
634 self.flagNoMoreFiles = True
635 self.dataOut.flagNoData = True
526 self.dataOut.flagNoData = True
636 return 0
527 return 0
637
528
638 def getVelRange(self, extrapoints=0):
529 def getVelRange(self, extrapoints=0):
639 Lambda = SPEED_OF_LIGHT / 50000000
530 Lambda = SPEED_OF_LIGHT / 50000000
640 # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
531 # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
641 PRF = self.dataOut.PRF
532 PRF = self.dataOut.PRF
642 Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.)
533 Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.)
643 deltafreq = PRF / (self.nProfiles)
534 deltafreq = PRF / (self.nProfiles)
644 deltavel = (Vmax * 2) / (self.nProfiles)
535 deltavel = (Vmax * 2) / (self.nProfiles)
645 freqrange = deltafreq * \
536 freqrange = deltafreq * \
646 (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2
537 (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2
647 velrange = deltavel * \
538 velrange = deltavel * \
648 (numpy.arange(self.nProfiles) - self.nProfiles / 2.)
539 (numpy.arange(self.nProfiles) - self.nProfiles / 2.)
649 return velrange
540 return velrange
650
541
651 def readBlock(self):
542 def readBlock(self):
652 '''
543 '''
653 It should be checked if the block has data, if it is not passed to the next file.
544 It should be checked if the block has data, if it is not passed to the next file.
654
545
655 Then the following is done:
546 Then the following is done:
656
547
657 1. Read the RecordHeader
548 1. Read the RecordHeader
658 2. Fill the buffer with the current block number.
549 2. Fill the buffer with the current block number.
659
550
660 '''
551 '''
661
552
662 if self.BlockCounter < self.nFDTdataRecors - 2:
553 if self.BlockCounter < self.nFDTdataRecors-1:
663 print(self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
554 if self.ReadMode==1:
664 if self.ReadMode == 1:
555 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1)
665 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1)
556 elif self.ReadMode==0:
666 elif self.ReadMode == 0:
667 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
557 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
668
558
669 rheader.RHread(self.fpFile) # Bltr FileHeader Reading
559 rheader.RHread(self.fpFile) # Bltr FileHeader Reading
670
560
671 self.OffsetStartHeader = rheader.OffsetStartHeader
561 self.OffsetStartHeader = rheader.OffsetStartHeader
672 self.RecCounter = rheader.RecCounter
562 self.RecCounter = rheader.RecCounter
673 self.Off2StartNxtRec = rheader.Off2StartNxtRec
563 self.Off2StartNxtRec = rheader.Off2StartNxtRec
674 self.Off2StartData = rheader.Off2StartData
564 self.Off2StartData = rheader.Off2StartData
675 self.nProfiles = rheader.nProfiles
565 self.nProfiles = rheader.nProfiles
676 self.nChannels = rheader.nChannels
566 self.nChannels = rheader.nChannels
677 self.nHeights = rheader.nHeights
567 self.nHeights = rheader.nHeights
678 self.frequency = rheader.TransmitFrec
568 self.frequency = rheader.TransmitFrec
679 self.DualModeIndex = rheader.DualModeIndex
569 self.DualModeIndex = rheader.DualModeIndex
680
570
681 self.pairsList = [(0, 1), (0, 2), (1, 2)]
571 self.pairsList = [(0, 1), (0, 2), (1, 2)]
682 self.dataOut.pairsList = self.pairsList
572 self.dataOut.pairsList = self.pairsList
683
573
684 self.nRdPairs = len(self.dataOut.pairsList)
574 self.nRdPairs = len(self.dataOut.pairsList)
685 self.dataOut.nRdPairs = self.nRdPairs
575 self.dataOut.nRdPairs = self.nRdPairs
686
576 self.__firstHeigth=rheader.StartRangeSamp
687 self.__firstHeigth = rheader.StartRangeSamp
577 self.__deltaHeigth=rheader.SampResolution
688 self.__deltaHeigth = rheader.SampResolution
578 self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth
689 self.dataOut.heightList = self.__firstHeigth + \
579 self.dataOut.channelList = range(self.nChannels)
690 numpy.array(list(range(self.nHeights))) * self.__deltaHeigth
580 self.dataOut.nProfiles=rheader.nProfiles
691 self.dataOut.channelList = list(range(self.nChannels))
581 self.dataOut.nIncohInt=rheader.nIncohInt
692 self.dataOut.nProfiles = rheader.nProfiles
582 self.dataOut.nCohInt=rheader.nCohInt
693 self.dataOut.nIncohInt = rheader.nIncohInt
583 self.dataOut.ippSeconds= 1/float(rheader.PRFhz)
694 self.dataOut.nCohInt = rheader.nCohInt
584 self.dataOut.PRF=rheader.PRFhz
695 self.dataOut.ippSeconds = 1 / float(rheader.PRFhz)
585 self.dataOut.nFFTPoints=rheader.nProfiles
696 self.dataOut.PRF = rheader.PRFhz
586 self.dataOut.utctime=rheader.nUtime
697 self.dataOut.nFFTPoints = rheader.nProfiles
587 self.dataOut.timeZone=0
698 self.dataOut.utctime = rheader.nUtime
588 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
699 self.dataOut.timeZone = 0
589 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
700 self.dataOut.normFactor = self.dataOut.nProfiles * \
590
701 self.dataOut.nIncohInt * self.dataOut.nCohInt
591 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
702 self.dataOut.outputInterval = self.dataOut.ippSeconds * \
592 self.dataOut.velocityX=[]
703 self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
593 self.dataOut.velocityY=[]
704
594 self.dataOut.velocityV=[]
705 self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN
595
706 print('self.data_output', shape(self.data_output))
707 self.dataOut.velocityX = []
708 self.dataOut.velocityY = []
709 self.dataOut.velocityV = []
710
711 '''Block Reading, the Block Data is received and Reshape is used to give it
596 '''Block Reading, the Block Data is received and Reshape is used to give it
712 shape.
597 shape.
713 '''
598 '''
714
599
715 # Procedure to take the pointer to where the date block starts
600 # Procedure to take the pointer to where the date block starts
716 startDATA = open(self.fpFile, "rb")
601 startDATA = open(self.fpFile, "rb")
717 OffDATA = self.OffsetStartHeader + self.RecCounter * \
602 OffDATA = self.OffsetStartHeader + self.RecCounter * \
718 self.Off2StartNxtRec + self.Off2StartData
603 self.Off2StartNxtRec + self.Off2StartData
719 startDATA.seek(OffDATA, os.SEEK_SET)
604 startDATA.seek(OffDATA, os.SEEK_SET)
720
605
721 def moving_average(x, N=2):
606 def moving_average(x, N=2):
722 return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):]
607 return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):]
723
608
724 def gaus(xSamples, a, x0, sigma):
609 def gaus(xSamples, a, x0, sigma):
725 return a * exp(-(xSamples - x0)**2 / (2 * sigma**2))
610 return a * exp(-(xSamples - x0)**2 / (2 * sigma**2))
726
611
727 def Find(x, value):
612 def Find(x, value):
728 for index in range(len(x)):
613 for index in range(len(x)):
729 if x[index] == value:
614 if x[index] == value:
730 return index
615 return index
731
616
732 def pol2cart(rho, phi):
617 def pol2cart(rho, phi):
733 x = rho * numpy.cos(phi)
618 x = rho * numpy.cos(phi)
734 y = rho * numpy.sin(phi)
619 y = rho * numpy.sin(phi)
735 return(x, y)
620 return(x, y)
736
621
737 if self.DualModeIndex == self.ReadMode:
622 if self.DualModeIndex==self.ReadMode:
738
623
739 self.data_fft = numpy.fromfile(
624 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
740 startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights)
625 self.data_fft = numpy.empty(101376)
741
626
742 self.data_fft = self.data_fft.astype(numpy.dtype('complex'))
627 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
743
628
744 self.data_block = numpy.reshape(
629 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
745 self.data_fft, (self.nHeights, self.nChannels, self.nProfiles))
630
746
631 self.data_block = numpy.transpose(self.data_block, (1,2,0))
747 self.data_block = numpy.transpose(self.data_block, (1, 2, 0))
632
748
749 copy = self.data_block.copy()
633 copy = self.data_block.copy()
750 spc = copy * numpy.conjugate(copy)
634 spc = copy * numpy.conjugate(copy)
751
635
752 self.data_spc = numpy.absolute(
636 self.data_spc = numpy.absolute(
753 spc) # valor absoluto o magnitud
637 spc) # valor absoluto o magnitud
754
638
755 factor = self.dataOut.normFactor
639 factor = self.dataOut.normFactor
756
640
757 z = self.data_spc.copy() # /factor
641 z = self.data_spc.copy() # /factor
758 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
642 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
759 #zdB = 10*numpy.log10(z)
643 self.dataOut.data_spc=self.data_spc
760 print(' ')
644 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
761 print('Z: ')
762 print(shape(z))
763 print(' ')
764 print(' ')
765
766 self.dataOut.data_spc = self.data_spc
767
768 self.noise = self.dataOut.getNoise(
769 ymin_index=80, ymax_index=132) # /factor
770 #noisedB = 10*numpy.log10(self.noise)
771
645
772 ySamples = numpy.ones([3, self.nProfiles])
646 ySamples = numpy.ones([3, self.nProfiles])
773 phase = numpy.ones([3, self.nProfiles])
647 phase = numpy.ones([3, self.nProfiles])
774 CSPCSamples = numpy.ones(
648 CSPCSamples = numpy.ones(
775 [3, self.nProfiles], dtype=numpy.complex_)
649 [3, self.nProfiles], dtype=numpy.complex_)
776 coherence = numpy.ones([3, self.nProfiles])
650 coherence = numpy.ones([3, self.nProfiles])
777 PhaseSlope = numpy.ones(3)
651 PhaseSlope = numpy.ones(3)
778 PhaseInter = numpy.ones(3)
652 PhaseInter = numpy.ones(3)
779
653
780 '''****** Getting CrossSpectra ******'''
654 '''****** Getting CrossSpectra ******'''
781 cspc = self.data_block.copy()
655 cspc=self.data_block.copy()
782 self.data_cspc = self.data_block.copy()
656 self.data_cspc=self.data_block.copy()
783
657
784 xFrec = self.getVelRange(1)
658 xFrec=self.getVelRange(1)
785 VelRange = self.getVelRange(1)
659 VelRange=self.getVelRange(1)
786 self.dataOut.VelRange = VelRange
660 self.dataOut.VelRange=VelRange
787 # print ' '
661
788 # print ' '
662
789 # print 'xFrec',xFrec
663 for i in range(self.nRdPairs):
790 # print ' '
664
791 # print ' '
792 # Height=35
793 for i in range(self.nRdPairs):
794
795 chan_index0 = self.dataOut.pairsList[i][0]
665 chan_index0 = self.dataOut.pairsList[i][0]
796 chan_index1 = self.dataOut.pairsList[i][1]
666 chan_index1 = self.dataOut.pairsList[i][1]
797
667
798 self.data_cspc[i, :, :] = cspc[chan_index0, :,
668 self.data_cspc[i, :, :] = cspc[chan_index0, :,
799 :] * numpy.conjugate(cspc[chan_index1, :, :])
669 :] * numpy.conjugate(cspc[chan_index1, :, :])
800
670
801 '''Getting Eij and Nij'''
671 '''Getting Eij and Nij'''
802 (AntennaX0, AntennaY0) = pol2cart(
672 (AntennaX0, AntennaY0) = pol2cart(
803 rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180)
673 rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180)
804 (AntennaX1, AntennaY1) = pol2cart(
674 (AntennaX1, AntennaY1) = pol2cart(
805 rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180)
675 rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180)
806 (AntennaX2, AntennaY2) = pol2cart(
676 (AntennaX2, AntennaY2) = pol2cart(
807 rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180)
677 rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180)
808
678
809 E01 = AntennaX0 - AntennaX1
679 E01 = AntennaX0 - AntennaX1
810 N01 = AntennaY0 - AntennaY1
680 N01 = AntennaY0 - AntennaY1
811
681
812 E02 = AntennaX0 - AntennaX2
682 E02 = AntennaX0 - AntennaX2
813 N02 = AntennaY0 - AntennaY2
683 N02 = AntennaY0 - AntennaY2
814
684
815 E12 = AntennaX1 - AntennaX2
685 E12 = AntennaX1 - AntennaX2
816 N12 = AntennaY1 - AntennaY2
686 N12 = AntennaY1 - AntennaY2
817
687
818 self.ChanDist = numpy.array(
688 self.ChanDist = numpy.array(
819 [[E01, N01], [E02, N02], [E12, N12]])
689 [[E01, N01], [E02, N02], [E12, N12]])
820
690
821 self.dataOut.ChanDist = self.ChanDist
691 self.dataOut.ChanDist = self.ChanDist
822
692
823
693 self.BlockCounter+=2
824 # for Height in range(self.nHeights):
694
825 #
826 # for i in range(self.nRdPairs):
827 #
828 # '''****** Line of Data SPC ******'''
829 # zline=z[i,:,Height]
830 #
831 # '''****** DC is removed ******'''
832 # DC=Find(zline,numpy.amax(zline))
833 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
834 #
835 #
836 # '''****** SPC is normalized ******'''
837 # FactNorm= zline.copy() / numpy.sum(zline.copy())
838 # FactNorm= FactNorm/numpy.sum(FactNorm)
839 #
840 # SmoothSPC=moving_average(FactNorm,N=3)
841 #
842 # xSamples = ar(range(len(SmoothSPC)))
843 # ySamples[i] = SmoothSPC-self.noise[i]
844 #
845 # for i in range(self.nRdPairs):
846 #
847 # '''****** Line of Data CSPC ******'''
848 # cspcLine=self.data_cspc[i,:,Height].copy()
849 #
850 #
851 #
852 # '''****** CSPC is normalized ******'''
853 # chan_index0 = self.dataOut.pairsList[i][0]
854 # chan_index1 = self.dataOut.pairsList[i][1]
855 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
856 #
857 #
858 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
859 #
860 #
861 # CSPCSamples[i] = CSPCNorm-self.noise[i]
862 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
863 #
864 # '''****** DC is removed ******'''
865 # DC=Find(coherence[i],numpy.amax(coherence[i]))
866 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
867 # coherence[i]= moving_average(coherence[i],N=2)
868 #
869 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
870 #
871 #
872 # '''****** Getting fij width ******'''
873 #
874 # yMean=[]
875 # yMean2=[]
876 #
877 # for j in range(len(ySamples[1])):
878 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
879 #
880 # '''******* Getting fitting Gaussian ******'''
881 # meanGauss=sum(xSamples*yMean) / len(xSamples)
882 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
883 # #print 'Height',Height,'SNR', meanGauss/sigma**2
884 #
885 # if (abs(meanGauss/sigma**2) > 0.0001) :
886 #
887 # try:
888 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
889 #
890 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
891 # FitGauss=gaus(xSamples,*popt)
892 #
893 # else:
894 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
895 # print 'Verificador: Dentro', Height
896 # except RuntimeError:
897 #
898 # try:
899 # for j in range(len(ySamples[1])):
900 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
901 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
902 # FitGauss=gaus(xSamples,*popt)
903 # print 'Verificador: Exepcion1', Height
904 # except RuntimeError:
905 #
906 # try:
907 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
908 # FitGauss=gaus(xSamples,*popt)
909 # print 'Verificador: Exepcion2', Height
910 # except RuntimeError:
911 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
912 # print 'Verificador: Exepcion3', Height
913 # else:
914 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
915 # #print 'Verificador: Fuera', Height
916 #
917 #
918 #
919 # Maximun=numpy.amax(yMean)
920 # eMinus1=Maximun*numpy.exp(-1)
921 #
922 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
923 # HalfWidth= xFrec[HWpos]
924 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
925 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
926 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
927 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
928 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
929 # '''****** Getting Fij ******'''
930 #
931 # GaussCenter=xFrec[GCpos]
932 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
933 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
934 # else:
935 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
936 #
937 # '''****** Getting Frecuency range of significant data ******'''
938 #
939 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
940 #
941 # if Rangpos<GCpos:
942 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
943 # else:
944 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
945 #
946 # FrecRange=xFrec[Range[0]:Range[1]]
947 #
948 # #print 'FrecRange', FrecRange
949 # '''****** Getting SCPC Slope ******'''
950 #
951 # for i in range(self.nRdPairs):
952 #
953 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
954 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
955 #
956 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
957 # PhaseSlope[i]=slope
958 # PhaseInter[i]=intercept
959 # else:
960 # PhaseSlope[i]=0
961 # PhaseInter[i]=0
962 #
963 # # plt.figure(i+15)
964 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
965 # # plt.xlabel('Frecuencia (KHz)')
966 # # plt.ylabel('Magnitud')
967 # # #plt.subplot(311+i)
968 # # plt.plot(FrecRange,PhaseRange,'b')
969 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
970 #
971 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
972 #
973 #
974 # '''Getting constant C'''
975 # cC=(Fij*numpy.pi)**2
976 #
977 # # '''Getting Eij and Nij'''
978 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
979 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
980 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
981 # #
982 # # E01=AntennaX0-AntennaX1
983 # # N01=AntennaY0-AntennaY1
984 # #
985 # # E02=AntennaX0-AntennaX2
986 # # N02=AntennaY0-AntennaY2
987 # #
988 # # E12=AntennaX1-AntennaX2
989 # # N12=AntennaY1-AntennaY2
990 #
991 # '''****** Getting constants F and G ******'''
992 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
993 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
994 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
995 # MijResults=numpy.array([MijResult0,MijResult1])
996 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
997 #
998 # '''****** Getting constants A, B and H ******'''
999 # W01=numpy.amax(coherence[0])
1000 # W02=numpy.amax(coherence[1])
1001 # W12=numpy.amax(coherence[2])
1002 #
1003 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1004 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1005 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1006 #
1007 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1008 #
1009 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1010 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1011 #
1012 # VxVy=numpy.array([[cA,cH],[cH,cB]])
1013 #
1014 # VxVyResults=numpy.array([-cF,-cG])
1015 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1016 # Vzon = Vy
1017 # Vmer = Vx
1018 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1019 # Vang=numpy.arctan2(Vmer,Vzon)
1020 #
1021 # if abs(Vy)<100 and abs(Vy)> 0.:
1022 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
1023 # #print 'Vmag',Vmag
1024 # else:
1025 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
1026 #
1027 # if abs(Vx)<100 and abs(Vx) > 0.:
1028 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
1029 # #print 'Vang',Vang
1030 # else:
1031 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
1032 #
1033 # if abs(GaussCenter)<2:
1034 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1035 #
1036 # else:
1037 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1038 #
1039 #
1040 # # print '********************************************'
1041 # # print 'HalfWidth ', HalfWidth
1042 # # print 'Maximun ', Maximun
1043 # # print 'eMinus1 ', eMinus1
1044 # # print 'Rangpos ', Rangpos
1045 # # print 'GaussCenter ',GaussCenter
1046 # # print 'E01 ',E01
1047 # # print 'N01 ',N01
1048 # # print 'E02 ',E02
1049 # # print 'N02 ',N02
1050 # # print 'E12 ',E12
1051 # # print 'N12 ',N12
1052 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1053 # # print 'Fij ', Fij
1054 # # print 'cC ', cC
1055 # # print 'cF ', cF
1056 # # print 'cG ', cG
1057 # # print 'cA ', cA
1058 # # print 'cB ', cB
1059 # # print 'cH ', cH
1060 # # print 'Vx ', Vx
1061 # # print 'Vy ', Vy
1062 # # print 'Vmag ', Vmag
1063 # # print 'Vang ', Vang*180/numpy.pi
1064 # # print 'PhaseSlope ',PhaseSlope[0]
1065 # # print 'PhaseSlope ',PhaseSlope[1]
1066 # # print 'PhaseSlope ',PhaseSlope[2]
1067 # # print '********************************************'
1068 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1069 #
1070 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1071 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1072 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1073 #
1074 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1075 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1076 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1077 #
1078 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1079 # print ' '
1080 # print 'VmagAverage',numpy.mean(prin)
1081 # print ' '
1082 # # plt.figure(5)
1083 # # plt.subplot(211)
1084 # # plt.plot(self.dataOut.velocityX,'yo:')
1085 # # plt.subplot(212)
1086 # # plt.plot(self.dataOut.velocityY,'yo:')
1087 #
1088 # # plt.figure(1)
1089 # # # plt.subplot(121)
1090 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1091 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1092 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1093 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1094 # # # plt.legend()
1095 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1096 # #
1097 # # plt.xlabel('Frecuencia (KHz)')
1098 # # plt.ylabel('Magnitud')
1099 # # # plt.subplot(122)
1100 # # # plt.title('Fit for Time Constant')
1101 # # #plt.plot(xFrec,zline)
1102 # # #plt.plot(xFrec,SmoothSPC,'g')
1103 # # plt.plot(xFrec,FactNorm)
1104 # # plt.axis([-4, 4, 0, 0.15])
1105 # # # plt.xlabel('SelfSpectra KHz')
1106 # #
1107 # # plt.figure(10)
1108 # # # plt.subplot(121)
1109 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1110 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1111 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1112 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1113 # # plt.legend()
1114 # # plt.title('SELFSPECTRA EN CANALES')
1115 # #
1116 # # plt.xlabel('Frecuencia (KHz)')
1117 # # plt.ylabel('Magnitud')
1118 # # # plt.subplot(122)
1119 # # # plt.title('Fit for Time Constant')
1120 # # #plt.plot(xFrec,zline)
1121 # # #plt.plot(xFrec,SmoothSPC,'g')
1122 # # # plt.plot(xFrec,FactNorm)
1123 # # # plt.axis([-4, 4, 0, 0.15])
1124 # # # plt.xlabel('SelfSpectra KHz')
1125 # #
1126 # # plt.figure(9)
1127 # #
1128 # #
1129 # # plt.title('DATOS SUAVIZADOS')
1130 # # plt.xlabel('Frecuencia (KHz)')
1131 # # plt.ylabel('Magnitud')
1132 # # plt.plot(xFrec,SmoothSPC,'g')
1133 # #
1134 # # #plt.plot(xFrec,FactNorm)
1135 # # plt.axis([-4, 4, 0, 0.15])
1136 # # # plt.xlabel('SelfSpectra KHz')
1137 # # #
1138 # # plt.figure(2)
1139 # # # #plt.subplot(121)
1140 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1141 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1142 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1143 # # # #plt.plot(xFrec,phase)
1144 # # # plt.xlabel('Suavizado, promediado KHz')
1145 # # plt.title('SELFSPECTRA PROMEDIADO')
1146 # # # #plt.subplot(122)
1147 # # # #plt.plot(xSamples,zline)
1148 # # plt.xlabel('Frecuencia (KHz)')
1149 # # plt.ylabel('Magnitud')
1150 # # plt.legend()
1151 # # #
1152 # # # plt.figure(3)
1153 # # # plt.subplot(311)
1154 # # # #plt.plot(xFrec,phase[0])
1155 # # # plt.plot(xFrec,phase[0],'g')
1156 # # # plt.subplot(312)
1157 # # # plt.plot(xFrec,phase[1],'g')
1158 # # # plt.subplot(313)
1159 # # # plt.plot(xFrec,phase[2],'g')
1160 # # # #plt.plot(xFrec,phase[2])
1161 # # #
1162 # # # plt.figure(4)
1163 # # #
1164 # # # plt.plot(xSamples,coherence[0],'b')
1165 # # # plt.plot(xSamples,coherence[1],'r')
1166 # # # plt.plot(xSamples,coherence[2],'g')
1167 # # plt.show()
1168 # # #
1169 # # # plt.clf()
1170 # # # plt.cla()
1171 # # # plt.close()
1172 #
1173 # print ' '
1174
1175 self.BlockCounter += 2
1176
1177 else:
695 else:
1178 self.fileSelector += 1
696 self.fileSelector+=1
1179 self.BlockCounter = 0
697 self.BlockCounter=0
1180 print("Next File") No newline at end of file
@@ -1,1103 +1,1093
1 import numpy
1 import numpy
2 import time
2 import time
3 import os
3 import os
4 import h5py
4 import h5py
5 import re
5 import re
6 import datetime
6 import datetime
7
7
8 from schainpy.model.data.jrodata import *
8 from schainpy.model.data.jrodata import *
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
10 # from .jroIO_base import *
10 # from .jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
12 import schainpy
12 import schainpy
13 from schainpy.utils import log
13 from schainpy.utils import log
14
14
15 @MPDecorator
15 @MPDecorator
16 class ParamReader(JRODataReader,ProcessingUnit):
16 class ParamReader(JRODataReader,ProcessingUnit):
17 '''
17 '''
18 Reads HDF5 format files
18 Reads HDF5 format files
19
19
20 path
20 path
21
21
22 startDate
22 startDate
23
23
24 endDate
24 endDate
25
25
26 startTime
26 startTime
27
27
28 endTime
28 endTime
29 '''
29 '''
30
30
31 ext = ".hdf5"
31 ext = ".hdf5"
32
32
33 optchar = "D"
33 optchar = "D"
34
34
35 timezone = None
35 timezone = None
36
36
37 startTime = None
37 startTime = None
38
38
39 endTime = None
39 endTime = None
40
40
41 fileIndex = None
41 fileIndex = None
42
42
43 utcList = None #To select data in the utctime list
43 utcList = None #To select data in the utctime list
44
44
45 blockList = None #List to blocks to be read from the file
45 blockList = None #List to blocks to be read from the file
46
46
47 blocksPerFile = None #Number of blocks to be read
47 blocksPerFile = None #Number of blocks to be read
48
48
49 blockIndex = None
49 blockIndex = None
50
50
51 path = None
51 path = None
52
52
53 #List of Files
53 #List of Files
54
54
55 filenameList = None
55 filenameList = None
56
56
57 datetimeList = None
57 datetimeList = None
58
58
59 #Hdf5 File
59 #Hdf5 File
60
60
61 listMetaname = None
61 listMetaname = None
62
62
63 listMeta = None
63 listMeta = None
64
64
65 listDataname = None
65 listDataname = None
66
66
67 listData = None
67 listData = None
68
68
69 listShapes = None
69 listShapes = None
70
70
71 fp = None
71 fp = None
72
72
73 #dataOut reconstruction
73 #dataOut reconstruction
74
74
75 dataOut = None
75 dataOut = None
76
76
77
77
78 def __init__(self):#, **kwargs):
78 def __init__(self):#, **kwargs):
79 ProcessingUnit.__init__(self) #, **kwargs)
79 ProcessingUnit.__init__(self) #, **kwargs)
80 self.dataOut = Parameters()
80 self.dataOut = Parameters()
81 return
81 return
82
82
83 def setup(self, **kwargs):
83 def setup(self, **kwargs):
84
84
85 path = kwargs['path']
85 path = kwargs['path']
86 startDate = kwargs['startDate']
86 startDate = kwargs['startDate']
87 endDate = kwargs['endDate']
87 endDate = kwargs['endDate']
88 startTime = kwargs['startTime']
88 startTime = kwargs['startTime']
89 endTime = kwargs['endTime']
89 endTime = kwargs['endTime']
90 walk = kwargs['walk']
90 walk = kwargs['walk']
91 if 'ext' in kwargs:
91 if 'ext' in kwargs:
92 ext = kwargs['ext']
92 ext = kwargs['ext']
93 else:
93 else:
94 ext = '.hdf5'
94 ext = '.hdf5'
95 if 'timezone' in kwargs:
95 if 'timezone' in kwargs:
96 self.timezone = kwargs['timezone']
96 self.timezone = kwargs['timezone']
97 else:
97 else:
98 self.timezone = 'lt'
98 self.timezone = 'lt'
99
99
100 print("[Reading] Searching files in offline mode ...")
100 print("[Reading] Searching files in offline mode ...")
101 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
101 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
102 startTime=startTime, endTime=endTime,
102 startTime=startTime, endTime=endTime,
103 ext=ext, walk=walk)
103 ext=ext, walk=walk)
104
104
105 if not(filenameList):
105 if not(filenameList):
106 print("There is no files into the folder: %s"%(path))
106 print("There is no files into the folder: %s"%(path))
107 sys.exit(-1)
107 sys.exit(-1)
108
108
109 self.fileIndex = -1
109 self.fileIndex = -1
110 self.startTime = startTime
110 self.startTime = startTime
111 self.endTime = endTime
111 self.endTime = endTime
112
112
113 self.__readMetadata()
113 self.__readMetadata()
114
114
115 self.__setNextFileOffline()
115 self.__setNextFileOffline()
116
116
117 return
117 return
118
118
119 def searchFilesOffLine(self,
119 def searchFilesOffLine(self,
120 path,
120 path,
121 startDate=None,
121 startDate=None,
122 endDate=None,
122 endDate=None,
123 startTime=datetime.time(0,0,0),
123 startTime=datetime.time(0,0,0),
124 endTime=datetime.time(23,59,59),
124 endTime=datetime.time(23,59,59),
125 ext='.hdf5',
125 ext='.hdf5',
126 walk=True):
126 walk=True):
127
127
128 expLabel = ''
128 expLabel = ''
129 self.filenameList = []
129 self.filenameList = []
130 self.datetimeList = []
130 self.datetimeList = []
131
131
132 pathList = []
132 pathList = []
133
133
134 JRODataObj = JRODataReader()
134 JRODataObj = JRODataReader()
135 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
135 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
136
136
137 if dateList == []:
137 if dateList == []:
138 print("[Reading] No *%s files in %s from %s to %s)"%(ext, path,
138 print("[Reading] No *%s files in %s from %s to %s)"%(ext, path,
139 datetime.datetime.combine(startDate,startTime).ctime(),
139 datetime.datetime.combine(startDate,startTime).ctime(),
140 datetime.datetime.combine(endDate,endTime).ctime()))
140 datetime.datetime.combine(endDate,endTime).ctime()))
141
141
142 return None, None
142 return None, None
143
143
144 if len(dateList) > 1:
144 if len(dateList) > 1:
145 print("[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate))
145 print("[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate))
146 else:
146 else:
147 print("[Reading] data was found for the date %s" %(dateList[0]))
147 print("[Reading] data was found for the date %s" %(dateList[0]))
148
148
149 filenameList = []
149 filenameList = []
150 datetimeList = []
150 datetimeList = []
151
151
152 #----------------------------------------------------------------------------------
152 #----------------------------------------------------------------------------------
153
153
154 for thisPath in pathList:
154 for thisPath in pathList:
155 # thisPath = pathList[pathDict[file]]
155 # thisPath = pathList[pathDict[file]]
156
156
157 fileList = glob.glob1(thisPath, "*%s" %ext)
157 fileList = glob.glob1(thisPath, "*%s" %ext)
158 fileList.sort()
158 fileList.sort()
159
159
160 for file in fileList:
160 for file in fileList:
161
161
162 filename = os.path.join(thisPath,file)
162 filename = os.path.join(thisPath,file)
163
163
164 if not isFileInDateRange(filename, startDate, endDate):
164 if not isFileInDateRange(filename, startDate, endDate):
165 continue
165 continue
166
166
167 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
167 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
168
168
169 if not(thisDatetime):
169 if not(thisDatetime):
170 continue
170 continue
171
171
172 filenameList.append(filename)
172 filenameList.append(filename)
173 datetimeList.append(thisDatetime)
173 datetimeList.append(thisDatetime)
174
174
175 if not(filenameList):
175 if not(filenameList):
176 print("[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()))
176 print("[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()))
177 return None, None
177 return None, None
178
178
179 print("[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime))
179 print("[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime))
180 print()
180 print()
181
181
182 # for i in range(len(filenameList)):
183 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
184
185 self.filenameList = filenameList
182 self.filenameList = filenameList
186 self.datetimeList = datetimeList
183 self.datetimeList = datetimeList
187
184
188 return pathList, filenameList
185 return pathList, filenameList
189
186
190 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
187 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
191
188
192 """
189 """
193 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
190 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
194
191
195 Inputs:
192 Inputs:
196 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
193 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
197
194
198 startDate : fecha inicial del rango seleccionado en formato datetime.date
195 startDate : fecha inicial del rango seleccionado en formato datetime.date
199
196
200 endDate : fecha final del rango seleccionado en formato datetime.date
197 endDate : fecha final del rango seleccionado en formato datetime.date
201
198
202 startTime : tiempo inicial del rango seleccionado en formato datetime.time
199 startTime : tiempo inicial del rango seleccionado en formato datetime.time
203
200
204 endTime : tiempo final del rango seleccionado en formato datetime.time
201 endTime : tiempo final del rango seleccionado en formato datetime.time
205
202
206 Return:
203 Return:
207 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
204 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
208 fecha especificado, de lo contrario retorna False.
205 fecha especificado, de lo contrario retorna False.
209
206
210 Excepciones:
207 Excepciones:
211 Si el archivo no existe o no puede ser abierto
208 Si el archivo no existe o no puede ser abierto
212 Si la cabecera no puede ser leida.
209 Si la cabecera no puede ser leida.
213
210
214 """
211 """
215
212
216 try:
213 try:
217 fp = h5py.File(filename,'r')
214 fp = h5py.File(filename,'r')
218 grp1 = fp['Data']
215 grp1 = fp['Data']
219
216
220 except IOError:
217 except IOError:
221 traceback.print_exc()
218 traceback.print_exc()
222 raise IOError("The file %s can't be opened" %(filename))
219 raise IOError("The file %s can't be opened" %(filename))
223 #chino rata
220 #chino rata
224 #In case has utctime attribute
221 #In case has utctime attribute
225 grp2 = grp1['utctime']
222 grp2 = grp1['utctime']
226 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
223 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
227 thisUtcTime = grp2.value[0]
224 thisUtcTime = grp2.value[0]
228
225
229 fp.close()
226 fp.close()
230
227
231 if self.timezone == 'lt':
228 if self.timezone == 'lt':
232 thisUtcTime -= 5*3600
229 thisUtcTime -= 5*3600
233
230
234 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
231 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
235 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
232 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
236 thisDate = thisDatetime.date()
233 thisDate = thisDatetime.date()
237 thisTime = thisDatetime.time()
234 thisTime = thisDatetime.time()
238
235
239 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
236 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
240 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
237 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
241
238
242 #General case
239 #General case
243 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
240 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
244 #-----------o----------------------------o-----------
241 #-----------o----------------------------o-----------
245 # startTime endTime
242 # startTime endTime
246
243
247 if endTime >= startTime:
244 if endTime >= startTime:
248 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
245 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
249 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
246 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
250 return thisDatetime
247 return thisDatetime
251 return None
248 return None
252
249
253 #If endTime < startTime then endTime belongs to the next day
250 #If endTime < startTime then endTime belongs to the next day
254 #<<<<<<<<<<<o o>>>>>>>>>>>
251 #<<<<<<<<<<<o o>>>>>>>>>>>
255 #-----------o----------------------------o-----------
252 #-----------o----------------------------o-----------
256 # endTime startTime
253 # endTime startTime
257
254
258 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
255 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
259 return None
256 return None
260
257
261 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
258 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
262 return None
259 return None
263
260
264 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
261 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
265 return None
262 return None
266
263
267 return thisDatetime
264 return thisDatetime
268
265
269 def __setNextFileOffline(self):
266 def __setNextFileOffline(self):
270
267
271 self.fileIndex += 1
268 self.fileIndex += 1
272 idFile = self.fileIndex
269 idFile = self.fileIndex
273
270
274 if not(idFile < len(self.filenameList)):
271 if not(idFile < len(self.filenameList)):
275 print("No more Files")
272 print("No more Files")
276 return 0
273 return 0
277
274
278 filename = self.filenameList[idFile]
275 filename = self.filenameList[idFile]
279
276
280 filePointer = h5py.File(filename,'r')
277 filePointer = h5py.File(filename,'r')
281
278
282 self.filename = filename
279 self.filename = filename
283
280
284 self.fp = filePointer
281 self.fp = filePointer
285
282
286 print("Setting the file: %s"%self.filename)
283 print("Setting the file: %s"%self.filename)
287
284
288 # self.__readMetadata()
285 # self.__readMetadata()
289 self.__setBlockList()
286 self.__setBlockList()
290 self.__readData()
287 self.__readData()
291 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
288 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
292 # self.nRecords = self.fp['Data'].attrs['nRecords']
289 # self.nRecords = self.fp['Data'].attrs['nRecords']
293 self.blockIndex = 0
290 self.blockIndex = 0
294 return 1
291 return 1
295
292
296 def __setBlockList(self):
293 def __setBlockList(self):
297 '''
294 '''
298 Selects the data within the times defined
295 Selects the data within the times defined
299
296
300 self.fp
297 self.fp
301 self.startTime
298 self.startTime
302 self.endTime
299 self.endTime
303
300
304 self.blockList
301 self.blockList
305 self.blocksPerFile
302 self.blocksPerFile
306
303
307 '''
304 '''
308 fp = self.fp
305 fp = self.fp
309 startTime = self.startTime
306 startTime = self.startTime
310 endTime = self.endTime
307 endTime = self.endTime
311
308
312 grp = fp['Data']
309 grp = fp['Data']
313 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
310 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
314
311
315 #ERROOOOR
312 #ERROOOOR
316 if self.timezone == 'lt':
313 if self.timezone == 'lt':
317 thisUtcTime -= 5*3600
314 thisUtcTime -= 5*3600
318
315
319 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
316 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
320
317
321 thisDate = thisDatetime.date()
318 thisDate = thisDatetime.date()
322 thisTime = thisDatetime.time()
319 thisTime = thisDatetime.time()
323
320
324 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
321 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
325 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
322 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
326
323
327 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
324 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
328
325
329 self.blockList = ind
326 self.blockList = ind
330 self.blocksPerFile = len(ind)
327 self.blocksPerFile = len(ind)
331
328
332 return
329 return
333
330
334 def __readMetadata(self):
331 def __readMetadata(self):
335 '''
332 '''
336 Reads Metadata
333 Reads Metadata
337
334
338 self.pathMeta
335 self.pathMeta
339
336
340 self.listShapes
337 self.listShapes
341 self.listMetaname
338 self.listMetaname
342 self.listMeta
339 self.listMeta
343
340
344 '''
341 '''
345
342
346 # grp = self.fp['Data']
343 # grp = self.fp['Data']
347 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
344 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
348 #
345 #
349 # if pathMeta == self.pathMeta:
346 # if pathMeta == self.pathMeta:
350 # return
347 # return
351 # else:
348 # else:
352 # self.pathMeta = pathMeta
349 # self.pathMeta = pathMeta
353 #
350 #
354 # filePointer = h5py.File(self.pathMeta,'r')
351 # filePointer = h5py.File(self.pathMeta,'r')
355 # groupPointer = filePointer['Metadata']
352 # groupPointer = filePointer['Metadata']
356
353
357 filename = self.filenameList[0]
354 filename = self.filenameList[0]
358
355
359 fp = h5py.File(filename,'r')
356 fp = h5py.File(filename,'r')
360
357
361 gp = fp['Metadata']
358 gp = fp['Metadata']
362
359
363 listMetaname = []
360 listMetaname = []
364 listMetadata = []
361 listMetadata = []
365 for item in list(gp.items()):
362 for item in list(gp.items()):
366 name = item[0]
363 name = item[0]
367
364
368 if name=='array dimensions':
365 if name=='array dimensions':
369 table = gp[name][:]
366 table = gp[name][:]
370 listShapes = {}
367 listShapes = {}
371 for shapes in table:
368 for shapes in table:
372 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
369 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
373 else:
370 else:
374 data = gp[name].value
371 data = gp[name].value
375 listMetaname.append(name)
372 listMetaname.append(name)
376 listMetadata.append(data)
373 listMetadata.append(data)
377
374
378 # if name=='type':
375 # if name=='type':
379 # self.__initDataOut(data)
376 # self.__initDataOut(data)
380
377
381 self.listShapes = listShapes
378 self.listShapes = listShapes
382 self.listMetaname = listMetaname
379 self.listMetaname = listMetaname
383 self.listMeta = listMetadata
380 self.listMeta = listMetadata
384
381
385 fp.close()
382 fp.close()
386 return
383 return
387
384
388 def __readData(self):
385 def __readData(self):
389 grp = self.fp['Data']
386 grp = self.fp['Data']
390 listdataname = []
387 listdataname = []
391 listdata = []
388 listdata = []
392
389
393 for item in list(grp.items()):
390 for item in list(grp.items()):
394 name = item[0]
391 name = item[0]
395 listdataname.append(name)
392 listdataname.append(name)
396
393
397 array = self.__setDataArray(grp[name],self.listShapes[name])
394 array = self.__setDataArray(grp[name],self.listShapes[name])
398 listdata.append(array)
395 listdata.append(array)
399
396
400 self.listDataname = listdataname
397 self.listDataname = listdataname
401 self.listData = listdata
398 self.listData = listdata
402 return
399 return
403
400
404 def __setDataArray(self, dataset, shapes):
401 def __setDataArray(self, dataset, shapes):
405
402
406 nDims = shapes[0]
403 nDims = shapes[0]
407
404
408 nDim2 = shapes[1] #Dimension 0
405 nDim2 = shapes[1] #Dimension 0
409
406
410 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
407 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
411
408
412 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
409 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
413
410
414 mode = shapes[4] #Mode of storing
411 mode = shapes[4] #Mode of storing
415
412
416 blockList = self.blockList
413 blockList = self.blockList
417
414
418 blocksPerFile = self.blocksPerFile
415 blocksPerFile = self.blocksPerFile
419
416
420 #Depending on what mode the data was stored
417 #Depending on what mode the data was stored
421 if mode == 0: #Divided in channels
418 if mode == 0: #Divided in channels
422 arrayData = dataset.value.astype(numpy.float)[0][blockList]
419 arrayData = dataset.value.astype(numpy.float)[0][blockList]
423 if mode == 1: #Divided in parameter
420 if mode == 1: #Divided in parameter
424 strds = 'table'
421 strds = 'table'
425 nDatas = nDim1
422 nDatas = nDim1
426 newShapes = (blocksPerFile,nDim2,nDim0)
423 newShapes = (blocksPerFile,nDim2,nDim0)
427 elif mode==2: #Concatenated in a table
424 elif mode==2: #Concatenated in a table
428 strds = 'table0'
425 strds = 'table0'
429 arrayData = dataset[strds].value
426 arrayData = dataset[strds].value
430 #Selecting part of the dataset
427 #Selecting part of the dataset
431 utctime = arrayData[:,0]
428 utctime = arrayData[:,0]
432 u, indices = numpy.unique(utctime, return_index=True)
429 u, indices = numpy.unique(utctime, return_index=True)
433
430
434 if blockList.size != indices.size:
431 if blockList.size != indices.size:
435 indMin = indices[blockList[0]]
432 indMin = indices[blockList[0]]
436 if blockList[1] + 1 >= indices.size:
433 if blockList[1] + 1 >= indices.size:
437 arrayData = arrayData[indMin:,:]
434 arrayData = arrayData[indMin:,:]
438 else:
435 else:
439 indMax = indices[blockList[1] + 1]
436 indMax = indices[blockList[1] + 1]
440 arrayData = arrayData[indMin:indMax,:]
437 arrayData = arrayData[indMin:indMax,:]
441 return arrayData
438 return arrayData
442
439
443 # One dimension
440 # One dimension
444 if nDims == 0:
441 if nDims == 0:
445 arrayData = dataset.value.astype(numpy.float)[0][blockList]
442 arrayData = dataset.value.astype(numpy.float)[0][blockList]
446
443
447 # Two dimensions
444 # Two dimensions
448 elif nDims == 2:
445 elif nDims == 2:
449 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
446 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
450 newShapes = (blocksPerFile,nDim0)
447 newShapes = (blocksPerFile,nDim0)
451 nDatas = nDim1
448 nDatas = nDim1
452
449
453 for i in range(nDatas):
450 for i in range(nDatas):
454 data = dataset[strds + str(i)].value
451 data = dataset[strds + str(i)].value
455 arrayData[:,i,:] = data[blockList,:]
452 arrayData[:,i,:] = data[blockList,:]
456
453
457 # Three dimensions
454 # Three dimensions
458 else:
455 else:
459 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
456 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
460 for i in range(nDatas):
457 for i in range(nDatas):
461
458
462 data = dataset[strds + str(i)].value
459 data = dataset[strds + str(i)].value
463
460
464 for b in range(blockList.size):
461 for b in range(blockList.size):
465 arrayData[b,:,i,:] = data[:,:,blockList[b]]
462 arrayData[b,:,i,:] = data[:,:,blockList[b]]
466
463
467 return arrayData
464 return arrayData
468
465
469 def __setDataOut(self):
466 def __setDataOut(self):
470 listMeta = self.listMeta
467 listMeta = self.listMeta
471 listMetaname = self.listMetaname
468 listMetaname = self.listMetaname
472 listDataname = self.listDataname
469 listDataname = self.listDataname
473 listData = self.listData
470 listData = self.listData
474 listShapes = self.listShapes
471 listShapes = self.listShapes
475
472
476 blockIndex = self.blockIndex
473 blockIndex = self.blockIndex
477 # blockList = self.blockList
474 # blockList = self.blockList
478
475
479 for i in range(len(listMeta)):
476 for i in range(len(listMeta)):
480 setattr(self.dataOut,listMetaname[i],listMeta[i])
477 setattr(self.dataOut,listMetaname[i],listMeta[i])
481
478
482 for j in range(len(listData)):
479 for j in range(len(listData)):
483 nShapes = listShapes[listDataname[j]][0]
480 nShapes = listShapes[listDataname[j]][0]
484 mode = listShapes[listDataname[j]][4]
481 mode = listShapes[listDataname[j]][4]
485 if nShapes == 1:
482 if nShapes == 1:
486 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
483 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
487 elif nShapes > 1:
484 elif nShapes > 1:
488 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
489 elif mode==0:
486 elif mode==0:
490 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
491 #Mode Meteors
488 #Mode Meteors
492 elif mode ==2:
489 elif mode ==2:
493 selectedData = self.__selectDataMode2(listData[j], blockIndex)
490 selectedData = self.__selectDataMode2(listData[j], blockIndex)
494 setattr(self.dataOut, listDataname[j], selectedData)
491 setattr(self.dataOut, listDataname[j], selectedData)
495 return
492 return
496
493
497 def __selectDataMode2(self, data, blockIndex):
494 def __selectDataMode2(self, data, blockIndex):
498 utctime = data[:,0]
495 utctime = data[:,0]
499 aux, indices = numpy.unique(utctime, return_inverse=True)
496 aux, indices = numpy.unique(utctime, return_inverse=True)
500 selInd = numpy.where(indices == blockIndex)[0]
497 selInd = numpy.where(indices == blockIndex)[0]
501 selData = data[selInd,:]
498 selData = data[selInd,:]
502
499
503 return selData
500 return selData
504
501
505 def getData(self):
502 def getData(self):
506
503
507 # if self.flagNoMoreFiles:
508 # self.dataOut.flagNoData = True
509 # print 'Process finished'
510 # return 0
511 #
512 if self.blockIndex==self.blocksPerFile:
504 if self.blockIndex==self.blocksPerFile:
513 if not( self.__setNextFileOffline() ):
505 if not( self.__setNextFileOffline() ):
514 self.dataOut.flagNoData = True
506 self.dataOut.flagNoData = True
515 return 0
507 return 0
516
508
517 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
518 # self.dataOut.flagNoData = True
519 # return 0
520 # self.__readData()
521 self.__setDataOut()
509 self.__setDataOut()
522 self.dataOut.flagNoData = False
510 self.dataOut.flagNoData = False
523
511
524 self.blockIndex += 1
512 self.blockIndex += 1
525
513
526 return
514 return
527
515
528 def run(self, **kwargs):
516 def run(self, **kwargs):
529
517
530 if not(self.isConfig):
518 if not(self.isConfig):
531 self.setup(**kwargs)
519 self.setup(**kwargs)
532 # self.setObjProperties()
520 # self.setObjProperties()
533 self.isConfig = True
521 self.isConfig = True
534
522
535 self.getData()
523 self.getData()
536
524
537 return
525 return
538 @MPDecorator
526 @MPDecorator
539 class ParamWriter(Operation):
527 class ParamWriter(Operation):
540 '''
528 '''
541 HDF5 Writer, stores parameters data in HDF5 format files
529 HDF5 Writer, stores parameters data in HDF5 format files
542
530
543 path: path where the files will be stored
531 path: path where the files will be stored
544
532
545 blocksPerFile: number of blocks that will be saved in per HDF5 format file
533 blocksPerFile: number of blocks that will be saved in per HDF5 format file
546
534
547 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
535 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
548
536
549 metadataList: list of attributes that will be stored as metadata
537 metadataList: list of attributes that will be stored as metadata
550
538
551 dataList: list of attributes that will be stores as data
539 dataList: list of attributes that will be stores as data
552
540
553 '''
541 '''
554
542
555
543
556 ext = ".hdf5"
544 ext = ".hdf5"
557
545
558 optchar = "D"
546 optchar = "D"
559
547
560 metaoptchar = "M"
548 metaoptchar = "M"
561
549
562 metaFile = None
550 metaFile = None
563
551
564 filename = None
552 filename = None
565
553
566 path = None
554 path = None
567
555
568 setFile = None
556 setFile = None
569
557
570 fp = None
558 fp = None
571
559
572 grp = None
560 grp = None
573
561
574 ds = None
562 ds = None
575
563
576 firsttime = True
564 firsttime = True
577
565
578 #Configurations
566 #Configurations
579
567
580 blocksPerFile = None
568 blocksPerFile = None
581
569
582 blockIndex = None
570 blockIndex = None
583
571
584 dataOut = None
572 dataOut = None
585
573
586 #Data Arrays
574 #Data Arrays
587
575
588 dataList = None
576 dataList = None
589
577
590 metadataList = None
578 metadataList = None
591
579
592 # arrayDim = None
580 # arrayDim = None
593
581
594 dsList = None #List of dictionaries with dataset properties
582 dsList = None #List of dictionaries with dataset properties
595
583
596 tableDim = None
584 tableDim = None
597
585
598 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
586 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
599
587
600 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
588 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
601
589
602 currentDay = None
590 currentDay = None
603
591
604 lastTime = None
592 lastTime = None
605
593
606 def __init__(self):#, **kwargs):
594 def __init__(self):#, **kwargs):
607 Operation.__init__(self)#, **kwargs)
595 Operation.__init__(self)#, **kwargs)
608 #self.isConfig = False
596 #self.isConfig = False
609 return
597 return
610
598
611 def setup(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
599 def setup(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
612 self.path = path
600 self.path = path
613 self.blocksPerFile = blocksPerFile
601 self.blocksPerFile = blocksPerFile
614 self.metadataList = metadataList
602 self.metadataList = metadataList
615 self.dataList = dataList
603 self.dataList = dataList
616 self.dataOut = dataOut
604 self.dataOut = dataOut
617 self.mode = mode
605 self.mode = mode
618 if self.mode is not None:
606 if self.mode is not None:
619 self.mode = numpy.zeros(len(self.dataList)) + mode
607 self.mode = numpy.zeros(len(self.dataList)) + mode
620 else:
608 else:
621 #self.mode = numpy.ones(len(self.dataList),int)
609 #self.mode = numpy.ones(len(self.dataList),int)
622 self.mode = numpy.ones(len(self.dataList))
610 self.mode = numpy.ones(len(self.dataList))
623 log.error(self.mode)#yong
611 log.error(self.mode)#yong
624
612
625 arrayDim = numpy.zeros((len(self.dataList),5))
613 arrayDim = numpy.zeros((len(self.dataList),5))
626
614
627 #Table dimensions
615 #Table dimensions
628 dtype0 = self.dtype
616 dtype0 = self.dtype
629 tableList = []
617 tableList = []
630
618
631 #Dictionary and list of tables
619 #Dictionary and list of tables
632 dsList = []
620 dsList = []
633
621
634 for i in range(len(self.dataList)):
622 for i in range(len(self.dataList)):
635 dsDict = {}
623 dsDict = {}
636 dataAux = getattr(self.dataOut, self.dataList[i])
624 dataAux = getattr(self.dataOut, self.dataList[i])
637 dsDict['variable'] = self.dataList[i]
625 dsDict['variable'] = self.dataList[i]
638 #--------------------- Conditionals ------------------------
626 #--------------------- Conditionals ------------------------
639 #There is no data
627 #There is no data
628
629
640 if dataAux is None:
630 if dataAux is None:
631
641 return 0
632 return 0
642
633
643 #Not array, just a number
634 #Not array, just a number
644 #Mode 0
635 #Mode 0
645 #log.error(mode)#yong
636 #log.error(mode)#yong
646 #log.error(len(mode))#yong
637 #log.error(len(mode))#yong
647 #log.error(type(mode))#yong
638 #log.error(type(mode))#yong
648 if type(dataAux)==float or type(dataAux)==int:
639 if type(dataAux)==float or type(dataAux)==int:
649 dsDict['mode'] = 0
640 dsDict['mode'] = 0
650 dsDict['nDim'] = 0
641 dsDict['nDim'] = 0
651 arrayDim[i,0] = 0
642 arrayDim[i,0] = 0
652 dsList.append(dsDict)
643 dsList.append(dsDict)
653
644
654 #Mode 2: meteors
645 #Mode 2: meteors
655 elif self.mode[i] == 2:
646 elif self.mode[i] == 2:
656 # dsDict['nDim'] = 0
647 # dsDict['nDim'] = 0
657 dsDict['dsName'] = 'table0'
648 dsDict['dsName'] = 'table0'
658 dsDict['mode'] = 2 # Mode meteors
649 dsDict['mode'] = 2 # Mode meteors
659 dsDict['shape'] = dataAux.shape[-1]
650 dsDict['shape'] = dataAux.shape[-1]
660 dsDict['nDim'] = 0
651 dsDict['nDim'] = 0
661 dsDict['dsNumber'] = 1
652 dsDict['dsNumber'] = 1
662
653
663 arrayDim[i,3] = dataAux.shape[-1]
654 arrayDim[i,3] = dataAux.shape[-1]
664 arrayDim[i,4] = self.mode[i] #Mode the data was stored
655 arrayDim[i,4] = self.mode[i] #Mode the data was stored
665
656
666 dsList.append(dsDict)
657 dsList.append(dsDict)
667
658
668 #Mode 1
659 #Mode 1
669 else:
660 else:
670 arrayDim0 = dataAux.shape #Data dimensions
661 arrayDim0 = dataAux.shape #Data dimensions
671 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
662 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
672 arrayDim[i,4] = self.mode[i] #Mode the data was stored
663 arrayDim[i,4] = self.mode[i] #Mode the data was stored
673
664
674 strtable = 'table'
665 strtable = 'table'
675 dsDict['mode'] = 1 # Mode parameters
666 dsDict['mode'] = 1 # Mode parameters
676
667
677 # Three-dimension arrays
668 # Three-dimension arrays
678 if len(arrayDim0) == 3:
669 if len(arrayDim0) == 3:
679 arrayDim[i,1:-1] = numpy.array(arrayDim0)
670 arrayDim[i,1:-1] = numpy.array(arrayDim0)
680 nTables = int(arrayDim[i,2])
671 nTables = int(arrayDim[i,2])
681 dsDict['dsNumber'] = nTables
672 dsDict['dsNumber'] = nTables
682 dsDict['shape'] = arrayDim[i,2:4]
673 dsDict['shape'] = arrayDim[i,2:4]
683 dsDict['nDim'] = 3
674 dsDict['nDim'] = 3
684
675
685 for j in range(nTables):
676 for j in range(nTables):
686 dsDict = dsDict.copy()
677 dsDict = dsDict.copy()
687 dsDict['dsName'] = strtable + str(j)
678 dsDict['dsName'] = strtable + str(j)
688 dsList.append(dsDict)
679 dsList.append(dsDict)
689
680
690 # Two-dimension arrays
681 # Two-dimension arrays
691 elif len(arrayDim0) == 2:
682 elif len(arrayDim0) == 2:
692 arrayDim[i,2:-1] = numpy.array(arrayDim0)
683 arrayDim[i,2:-1] = numpy.array(arrayDim0)
693 nTables = int(arrayDim[i,2])
684 nTables = int(arrayDim[i,2])
694 dsDict['dsNumber'] = nTables
685 dsDict['dsNumber'] = nTables
695 dsDict['shape'] = arrayDim[i,3]
686 dsDict['shape'] = arrayDim[i,3]
696 dsDict['nDim'] = 2
687 dsDict['nDim'] = 2
697
688
698 for j in range(nTables):
689 for j in range(nTables):
699 dsDict = dsDict.copy()
690 dsDict = dsDict.copy()
700 dsDict['dsName'] = strtable + str(j)
691 dsDict['dsName'] = strtable + str(j)
701 dsList.append(dsDict)
692 dsList.append(dsDict)
702
693
703 # One-dimension arrays
694 # One-dimension arrays
704 elif len(arrayDim0) == 1:
695 elif len(arrayDim0) == 1:
705 arrayDim[i,3] = arrayDim0[0]
696 arrayDim[i,3] = arrayDim0[0]
706 dsDict['shape'] = arrayDim0[0]
697 dsDict['shape'] = arrayDim0[0]
707 dsDict['dsNumber'] = 1
698 dsDict['dsNumber'] = 1
708 dsDict['dsName'] = strtable + str(0)
699 dsDict['dsName'] = strtable + str(0)
709 dsDict['nDim'] = 1
700 dsDict['nDim'] = 1
710 dsList.append(dsDict)
701 dsList.append(dsDict)
711
702
712 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
703 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
713 tableList.append(table)
704 tableList.append(table)
714
705
715 # self.arrayDim = arrayDim
706 # self.arrayDim = arrayDim
716 self.dsList = dsList
707 self.dsList = dsList
717 self.tableDim = numpy.array(tableList, dtype = dtype0)
708 self.tableDim = numpy.array(tableList, dtype = dtype0)
718 self.blockIndex = 0
709 self.blockIndex = 0
719
710
720 timeTuple = time.localtime(dataOut.utctime)
711 timeTuple = time.localtime(dataOut.utctime)
721 self.currentDay = timeTuple.tm_yday
712 self.currentDay = timeTuple.tm_yday
722 return 1
713 return 1
723
714
724 def putMetadata(self):
715 def putMetadata(self):
725
716
726 fp = self.createMetadataFile()
717 fp = self.createMetadataFile()
727 self.writeMetadata(fp)
718 self.writeMetadata(fp)
728 fp.close()
719 fp.close()
729 return
720 return
730
721
731 def createMetadataFile(self):
722 def createMetadataFile(self):
732 ext = self.ext
723 ext = self.ext
733 path = self.path
724 path = self.path
734 setFile = self.setFile
725 setFile = self.setFile
735
726
736 timeTuple = time.localtime(self.dataOut.utctime)
727 timeTuple = time.localtime(self.dataOut.utctime)
737
728
738 subfolder = ''
729 subfolder = ''
739 fullpath = os.path.join( path, subfolder )
730 fullpath = os.path.join( path, subfolder )
740
731
741 if not( os.path.exists(fullpath) ):
732 if not( os.path.exists(fullpath) ):
742 os.mkdir(fullpath)
733 os.mkdir(fullpath)
743 setFile = -1 #inicializo mi contador de seteo
734 setFile = -1 #inicializo mi contador de seteo
744
735
745 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
736 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
746 fullpath = os.path.join( path, subfolder )
737 fullpath = os.path.join( path, subfolder )
747
738
748 if not( os.path.exists(fullpath) ):
739 if not( os.path.exists(fullpath) ):
749 os.mkdir(fullpath)
740 os.mkdir(fullpath)
750 setFile = -1 #inicializo mi contador de seteo
741 setFile = -1 #inicializo mi contador de seteo
751
742
752 else:
743 else:
753 filesList = os.listdir( fullpath )
744 filesList = os.listdir( fullpath )
754 filesList = sorted( filesList, key=str.lower )
745 filesList = sorted( filesList, key=str.lower )
755 if len( filesList ) > 0:
746 if len( filesList ) > 0:
756 filesList = [k for k in filesList if 'M' in k]
747 filesList = [k for k in filesList if 'M' in k]
757 filen = filesList[-1]
748 filen = filesList[-1]
758 # el filename debera tener el siguiente formato
749 # el filename debera tener el siguiente formato
759 # 0 1234 567 89A BCDE (hex)
750 # 0 1234 567 89A BCDE (hex)
760 # x YYYY DDD SSS .ext
751 # x YYYY DDD SSS .ext
761 if isNumber( filen[8:11] ):
752 if isNumber( filen[8:11] ):
762 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
753 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
763 else:
754 else:
764 setFile = -1
755 setFile = -1
765 else:
756 else:
766 setFile = -1 #inicializo mi contador de seteo
757 setFile = -1 #inicializo mi contador de seteo
767
758
768 if self.setType is None:
759 if self.setType is None:
769 setFile += 1
760 setFile += 1
770 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
761 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
771 timeTuple.tm_year,
762 timeTuple.tm_year,
772 timeTuple.tm_yday,
763 timeTuple.tm_yday,
773 setFile,
764 setFile,
774 ext )
765 ext )
775 else:
766 else:
776 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
767 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
777 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
768 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
778 timeTuple.tm_year,
769 timeTuple.tm_year,
779 timeTuple.tm_yday,
770 timeTuple.tm_yday,
780 setFile,
771 setFile,
781 ext )
772 ext )
782
773
783 filename = os.path.join( path, subfolder, file )
774 filename = os.path.join( path, subfolder, file )
784 self.metaFile = file
775 self.metaFile = file
785 #Setting HDF5 File
776 #Setting HDF5 File
786 fp = h5py.File(filename,'w')
777 fp = h5py.File(filename,'w')
787
778
788 return fp
779 return fp
789
780
790 def writeMetadata(self, fp):
781 def writeMetadata(self, fp):
791
782
792 grp = fp.create_group("Metadata")
783 grp = fp.create_group("Metadata")
793 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
784 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
794
785
795 for i in range(len(self.metadataList)):
786 for i in range(len(self.metadataList)):
796 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
787 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
797 return
788 return
798
789
799 def timeFlag(self):
790 def timeFlag(self):
800 currentTime = self.dataOut.utctime
791 currentTime = self.dataOut.utctime
801
792
802 if self.lastTime is None:
793 if self.lastTime is None:
803 self.lastTime = currentTime
794 self.lastTime = currentTime
804
795
805 #Day
796 #Day
806 timeTuple = time.localtime(currentTime)
797 timeTuple = time.localtime(currentTime)
807 dataDay = timeTuple.tm_yday
798 dataDay = timeTuple.tm_yday
808
799
809 #Time
800 #Time
810 timeDiff = currentTime - self.lastTime
801 timeDiff = currentTime - self.lastTime
811
802
812 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
803 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
813 if dataDay != self.currentDay:
804 if dataDay != self.currentDay:
814 self.currentDay = dataDay
805 self.currentDay = dataDay
815 return True
806 return True
816 elif timeDiff > 3*60*60:
807 elif timeDiff > 3*60*60:
817 self.lastTime = currentTime
808 self.lastTime = currentTime
818 return True
809 return True
819 else:
810 else:
820 self.lastTime = currentTime
811 self.lastTime = currentTime
821 return False
812 return False
822
813
823 def setNextFile(self):
814 def setNextFile(self):
824
815
825 ext = self.ext
816 ext = self.ext
826 path = self.path
817 path = self.path
827 setFile = self.setFile
818 setFile = self.setFile
828 mode = self.mode
819 mode = self.mode
829
820
830 timeTuple = time.localtime(self.dataOut.utctime)
821 timeTuple = time.localtime(self.dataOut.utctime)
831 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
822 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
832
823
833 fullpath = os.path.join( path, subfolder )
824 fullpath = os.path.join( path, subfolder )
834
825
835 if os.path.exists(fullpath):
826 if os.path.exists(fullpath):
836 filesList = os.listdir( fullpath )
827 filesList = os.listdir( fullpath )
837 filesList = [k for k in filesList if 'D' in k]
828 filesList = [k for k in filesList if 'D' in k]
838 if len( filesList ) > 0:
829 if len( filesList ) > 0:
839 filesList = sorted( filesList, key=str.lower )
830 filesList = sorted( filesList, key=str.lower )
840 filen = filesList[-1]
831 filen = filesList[-1]
841 # el filename debera tener el siguiente formato
832 # el filename debera tener el siguiente formato
842 # 0 1234 567 89A BCDE (hex)
833 # 0 1234 567 89A BCDE (hex)
843 # x YYYY DDD SSS .ext
834 # x YYYY DDD SSS .ext
844 if isNumber( filen[8:11] ):
835 if isNumber( filen[8:11] ):
845 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
836 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
846 else:
837 else:
847 setFile = -1
838 setFile = -1
848 else:
839 else:
849 setFile = -1 #inicializo mi contador de seteo
840 setFile = -1 #inicializo mi contador de seteo
850 else:
841 else:
851 os.makedirs(fullpath)
842 os.makedirs(fullpath)
852 setFile = -1 #inicializo mi contador de seteo
843 setFile = -1 #inicializo mi contador de seteo
853
844
854 if None is None:
845 if None is None:
855 setFile += 1
846 setFile += 1
856 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
847 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
857 timeTuple.tm_year,
848 timeTuple.tm_year,
858 timeTuple.tm_yday,
849 timeTuple.tm_yday,
859 setFile,
850 setFile,
860 ext )
851 ext )
861 else:
852 else:
862 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
853 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
863 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
854 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
864 timeTuple.tm_year,
855 timeTuple.tm_year,
865 timeTuple.tm_yday,
856 timeTuple.tm_yday,
866 setFile,
857 setFile,
867 ext )
858 ext )
868
859
869 filename = os.path.join( path, subfolder, file )
860 filename = os.path.join( path, subfolder, file )
870
861
871 #Setting HDF5 File
862 #Setting HDF5 File
872 fp = h5py.File(filename,'w')
863 fp = h5py.File(filename,'w')
873 #write metadata
864 #write metadata
874 self.writeMetadata(fp)
865 self.writeMetadata(fp)
875 #Write data
866 #Write data
876 grp = fp.create_group("Data")
867 grp = fp.create_group("Data")
877 # grp.attrs['metadata'] = self.metaFile
868 # grp.attrs['metadata'] = self.metaFile
878
869
879 # grp.attrs['blocksPerFile'] = 0
870 # grp.attrs['blocksPerFile'] = 0
880 ds = []
871 ds = []
881 data = []
872 data = []
882 dsList = self.dsList
873 dsList = self.dsList
883 i = 0
874 i = 0
884 while i < len(dsList):
875 while i < len(dsList):
885 dsInfo = dsList[i]
876 dsInfo = dsList[i]
886 #One-dimension data
877 #One-dimension data
887 if dsInfo['mode'] == 0:
878 if dsInfo['mode'] == 0:
888 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
879 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
889 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
880 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
890 ds.append(ds0)
881 ds.append(ds0)
891 data.append([])
882 data.append([])
892 i += 1
883 i += 1
893 continue
884 continue
894 # nDimsForDs.append(nDims[i])
885 # nDimsForDs.append(nDims[i])
895
886
896 elif dsInfo['mode'] == 2:
887 elif dsInfo['mode'] == 2:
897 grp0 = grp.create_group(dsInfo['variable'])
888 grp0 = grp.create_group(dsInfo['variable'])
898 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
889 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
899 ds.append(ds0)
890 ds.append(ds0)
900 data.append([])
891 data.append([])
901 i += 1
892 i += 1
902 continue
893 continue
903
894
904 elif dsInfo['mode'] == 1:
895 elif dsInfo['mode'] == 1:
905 grp0 = grp.create_group(dsInfo['variable'])
896 grp0 = grp.create_group(dsInfo['variable'])
906
897
907 for j in range(dsInfo['dsNumber']):
898 for j in range(dsInfo['dsNumber']):
908 dsInfo = dsList[i]
899 dsInfo = dsList[i]
909 tableName = dsInfo['dsName']
900 tableName = dsInfo['dsName']
910
901
911
902
912 if dsInfo['nDim'] == 3:
903 if dsInfo['nDim'] == 3:
913 shape = dsInfo['shape'].astype(int)
904 shape = dsInfo['shape'].astype(int)
914 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
905 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
915 else:
906 else:
916 shape = int(dsInfo['shape'])
907 shape = int(dsInfo['shape'])
917 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
908 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
918
909
919 ds.append(ds0)
910 ds.append(ds0)
920 data.append([])
911 data.append([])
921 i += 1
912 i += 1
922 # nDimsForDs.append(nDims[i])
913 # nDimsForDs.append(nDims[i])
923
914
924 fp.flush()
915 fp.flush()
925 fp.close()
916 fp.close()
926
917
927 # self.nDatas = nDatas
918 # self.nDatas = nDatas
928 # self.nDims = nDims
919 # self.nDims = nDims
929 # self.nDimsForDs = nDimsForDs
920 # self.nDimsForDs = nDimsForDs
930 #Saving variables
921 #Saving variables
931 print('Writing the file: %s'%filename)
922 print('Writing the file: %s'%filename)
932 self.filename = filename
923 self.filename = filename
933 # self.fp = fp
924 # self.fp = fp
934 # self.grp = grp
925 # self.grp = grp
935 # self.grp.attrs.modify('nRecords', 1)
926 # self.grp.attrs.modify('nRecords', 1)
936 self.ds = ds
927 self.ds = ds
937 self.data = data
928 self.data = data
938 # self.setFile = setFile
929 # self.setFile = setFile
939 self.firsttime = True
930 self.firsttime = True
940 self.blockIndex = 0
931 self.blockIndex = 0
941 return
932 return
942
933
943 def putData(self):
934 def putData(self):
944
935
945 if self.blockIndex == self.blocksPerFile or self.timeFlag():
936 if self.blockIndex == self.blocksPerFile or self.timeFlag():
946 self.setNextFile()
937 self.setNextFile()
947
938
948 # if not self.firsttime:
939 # if not self.firsttime:
949 self.readBlock()
940 self.readBlock()
950 self.setBlock() #Prepare data to be written
941 self.setBlock() #Prepare data to be written
951 self.writeBlock() #Write data
942 self.writeBlock() #Write data
952
943
953 return
944 return
954
945
955 def readBlock(self):
946 def readBlock(self):
956
947
957 '''
948 '''
958 data Array configured
949 data Array configured
959
950
960
951
961 self.data
952 self.data
962 '''
953 '''
963 dsList = self.dsList
954 dsList = self.dsList
964 ds = self.ds
955 ds = self.ds
965 #Setting HDF5 File
956 #Setting HDF5 File
966 fp = h5py.File(self.filename,'r+')
957 fp = h5py.File(self.filename,'r+')
967 grp = fp["Data"]
958 grp = fp["Data"]
968 ind = 0
959 ind = 0
969
960
970 # grp.attrs['blocksPerFile'] = 0
961 # grp.attrs['blocksPerFile'] = 0
971 while ind < len(dsList):
962 while ind < len(dsList):
972 dsInfo = dsList[ind]
963 dsInfo = dsList[ind]
973
964
974 if dsInfo['mode'] == 0:
965 if dsInfo['mode'] == 0:
975 ds0 = grp[dsInfo['variable']]
966 ds0 = grp[dsInfo['variable']]
976 ds[ind] = ds0
967 ds[ind] = ds0
977 ind += 1
968 ind += 1
978 else:
969 else:
979
970
980 grp0 = grp[dsInfo['variable']]
971 grp0 = grp[dsInfo['variable']]
981
972
982 for j in range(dsInfo['dsNumber']):
973 for j in range(dsInfo['dsNumber']):
983 dsInfo = dsList[ind]
974 dsInfo = dsList[ind]
984 ds0 = grp0[dsInfo['dsName']]
975 ds0 = grp0[dsInfo['dsName']]
985 ds[ind] = ds0
976 ds[ind] = ds0
986 ind += 1
977 ind += 1
987
978
988 self.fp = fp
979 self.fp = fp
989 self.grp = grp
980 self.grp = grp
990 self.ds = ds
981 self.ds = ds
991
982
992 return
983 return
993
984
994 def setBlock(self):
985 def setBlock(self):
995 '''
986 '''
996 data Array configured
987 data Array configured
997
988
998
989
999 self.data
990 self.data
1000 '''
991 '''
1001 #Creating Arrays
992 #Creating Arrays
1002 dsList = self.dsList
993 dsList = self.dsList
1003 data = self.data
994 data = self.data
1004 ind = 0
995 ind = 0
1005
996
1006 while ind < len(dsList):
997 while ind < len(dsList):
1007 dsInfo = dsList[ind]
998 dsInfo = dsList[ind]
1008 dataAux = getattr(self.dataOut, dsInfo['variable'])
999 dataAux = getattr(self.dataOut, dsInfo['variable'])
1009
1000
1010 mode = dsInfo['mode']
1001 mode = dsInfo['mode']
1011 nDim = dsInfo['nDim']
1002 nDim = dsInfo['nDim']
1012
1003
1013 if mode == 0 or mode == 2 or nDim == 1:
1004 if mode == 0 or mode == 2 or nDim == 1:
1014 data[ind] = dataAux
1005 data[ind] = dataAux
1015 ind += 1
1006 ind += 1
1016 # elif nDim == 1:
1007 # elif nDim == 1:
1017 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1008 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1018 # ind += 1
1009 # ind += 1
1019 elif nDim == 2:
1010 elif nDim == 2:
1020 for j in range(dsInfo['dsNumber']):
1011 for j in range(dsInfo['dsNumber']):
1021 data[ind] = dataAux[j,:]
1012 data[ind] = dataAux[j,:]
1022 ind += 1
1013 ind += 1
1023 elif nDim == 3:
1014 elif nDim == 3:
1024 for j in range(dsInfo['dsNumber']):
1015 for j in range(dsInfo['dsNumber']):
1025 data[ind] = dataAux[:,j,:]
1016 data[ind] = dataAux[:,j,:]
1026 ind += 1
1017 ind += 1
1027
1018
1028 self.data = data
1019 self.data = data
1029 return
1020 return
1030
1021
1031 def writeBlock(self):
1022 def writeBlock(self):
1032 '''
1023 '''
1033 Saves the block in the HDF5 file
1024 Saves the block in the HDF5 file
1034 '''
1025 '''
1035 dsList = self.dsList
1026 dsList = self.dsList
1036
1027
1037 for i in range(len(self.ds)):
1028 for i in range(len(self.ds)):
1038 dsInfo = dsList[i]
1029 dsInfo = dsList[i]
1039 nDim = dsInfo['nDim']
1030 nDim = dsInfo['nDim']
1040 mode = dsInfo['mode']
1031 mode = dsInfo['mode']
1041
1032
1042 # First time
1033 # First time
1043 if self.firsttime:
1034 if self.firsttime:
1044 # self.ds[i].resize(self.data[i].shape)
1035 # self.ds[i].resize(self.data[i].shape)
1045 # self.ds[i][self.blockIndex,:] = self.data[i]
1036 # self.ds[i][self.blockIndex,:] = self.data[i]
1046 if type(self.data[i]) == numpy.ndarray:
1037 if type(self.data[i]) == numpy.ndarray:
1047
1038
1048 if nDim == 3:
1039 if nDim == 3:
1049 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1040 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1050 self.ds[i].resize(self.data[i].shape)
1041 self.ds[i].resize(self.data[i].shape)
1051 if mode == 2:
1042 if mode == 2:
1052 self.ds[i].resize(self.data[i].shape)
1043 self.ds[i].resize(self.data[i].shape)
1053 self.ds[i][:] = self.data[i]
1044 self.ds[i][:] = self.data[i]
1054 else:
1045 else:
1055
1046
1056 # From second time
1047 # From second time
1057 # Meteors!
1048 # Meteors!
1058 if mode == 2:
1049 if mode == 2:
1059 dataShape = self.data[i].shape
1050 dataShape = self.data[i].shape
1060 dsShape = self.ds[i].shape
1051 dsShape = self.ds[i].shape
1061 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1052 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1062 self.ds[i][dsShape[0]:,:] = self.data[i]
1053 self.ds[i][dsShape[0]:,:] = self.data[i]
1063 # No dimension
1054 # No dimension
1064 elif mode == 0:
1055 elif mode == 0:
1065 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1056 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1066 self.ds[i][0,-1] = self.data[i]
1057 self.ds[i][0,-1] = self.data[i]
1067 # One dimension
1058 # One dimension
1068 elif nDim == 1:
1059 elif nDim == 1:
1069 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1060 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1070 self.ds[i][-1,:] = self.data[i]
1061 self.ds[i][-1,:] = self.data[i]
1071 # Two dimension
1062 # Two dimension
1072 elif nDim == 2:
1063 elif nDim == 2:
1073 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1064 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1074 self.ds[i][self.blockIndex,:] = self.data[i]
1065 self.ds[i][self.blockIndex,:] = self.data[i]
1075 # Three dimensions
1066 # Three dimensions
1076 elif nDim == 3:
1067 elif nDim == 3:
1077 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1068 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1078 self.ds[i][:,:,-1] = self.data[i]
1069 self.ds[i][:,:,-1] = self.data[i]
1079
1070
1080 self.firsttime = False
1071 self.firsttime = False
1081 self.blockIndex += 1
1072 self.blockIndex += 1
1082
1073
1083 #Close to save changes
1074 #Close to save changes
1084 self.fp.flush()
1075 self.fp.flush()
1085 self.fp.close()
1076 self.fp.close()
1086 return
1077 return
1087
1078
1088 def run(self, dataOut, path, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
1079 def run(self, dataOut, path, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
1089
1080
1090 if not(self.isConfig):
1081 if not(self.isConfig):
1091 flagdata = self.setup(dataOut, path=path, blocksPerFile=blocksPerFile,
1082 flagdata = self.setup(dataOut, path=path, blocksPerFile=blocksPerFile,
1092 metadataList=metadataList, dataList=dataList, mode=mode, **kwargs)
1083 metadataList=metadataList, dataList=dataList, mode=mode, **kwargs)
1093
1084
1094 if not(flagdata):
1085 if not(flagdata):
1095 return
1086 return
1096
1087
1097 self.isConfig = True
1088 self.isConfig = True
1098 # self.putMetadata()
1099 self.setNextFile()
1089 self.setNextFile()
1100
1090
1101 self.putData()
1091 self.putData()
1102 return
1092 return
1103 No newline at end of file
1093
@@ -1,679 +1,678
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import numpy
6 import numpy
7
7
8 from schainpy.model.io.jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
8 from schainpy.model.io.jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 from schainpy.model.data.jrodata import Spectra
11 from schainpy.model.data.jrodata import Spectra
12 from schainpy.utils import log
12 from schainpy.utils import log
13
13
14 @MPDecorator
14 @MPDecorator
15 class SpectraReader(JRODataReader, ProcessingUnit):
15 class SpectraReader(JRODataReader, ProcessingUnit):
16 """
16 """
17 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
17 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
18 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
18 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
19 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
19 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
20
20
21 paresCanalesIguales * alturas * perfiles (Self Spectra)
21 paresCanalesIguales * alturas * perfiles (Self Spectra)
22 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
22 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
23 canales * alturas (DC Channels)
23 canales * alturas (DC Channels)
24
24
25 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
25 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
26 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
27 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
28 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
28 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
29
29
30 Example:
30 Example:
31 dpath = "/home/myuser/data"
31 dpath = "/home/myuser/data"
32
32
33 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
33 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
34
34
35 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
35 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
36
36
37 readerObj = SpectraReader()
37 readerObj = SpectraReader()
38
38
39 readerObj.setup(dpath, startTime, endTime)
39 readerObj.setup(dpath, startTime, endTime)
40
40
41 while(True):
41 while(True):
42
42
43 readerObj.getData()
43 readerObj.getData()
44
44
45 print readerObj.data_spc
45 print readerObj.data_spc
46
46
47 print readerObj.data_cspc
47 print readerObj.data_cspc
48
48
49 print readerObj.data_dc
49 print readerObj.data_dc
50
50
51 if readerObj.flagNoMoreFiles:
51 if readerObj.flagNoMoreFiles:
52 break
52 break
53
53
54 """
54 """
55
55
56 pts2read_SelfSpectra = 0
56 pts2read_SelfSpectra = 0
57
57
58 pts2read_CrossSpectra = 0
58 pts2read_CrossSpectra = 0
59
59
60 pts2read_DCchannels = 0
60 pts2read_DCchannels = 0
61
61
62 ext = ".pdata"
62 ext = ".pdata"
63
63
64 optchar = "P"
64 optchar = "P"
65
65
66 dataOut = None
66 dataOut = None
67
67
68 nRdChannels = None
68 nRdChannels = None
69
69
70 nRdPairs = None
70 nRdPairs = None
71
71
72 rdPairList = []
72 rdPairList = []
73
73
74 def __init__(self):#, **kwargs):
74 def __init__(self):#, **kwargs):
75 """
75 """
76 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.
77
77
78 Inputs:
78 Inputs:
79 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
79 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
80 almacenar un perfil de datos cada vez que se haga un requerimiento
80 almacenar un perfil de datos cada vez que se haga un requerimiento
81 (getData). El perfil sera obtenido a partir del buffer de datos,
81 (getData). El perfil sera obtenido a partir del buffer de datos,
82 si el buffer esta vacio se hara un nuevo proceso de lectura de un
82 si el buffer esta vacio se hara un nuevo proceso de lectura de un
83 bloque de datos.
83 bloque de datos.
84 Si este parametro no es pasado se creara uno internamente.
84 Si este parametro no es pasado se creara uno internamente.
85
85
86 Affected:
86 Affected:
87 self.dataOut
87 self.dataOut
88
88
89 Return : None
89 Return : None
90 """
90 """
91
91
92 #Eliminar de la base la herencia
92 #Eliminar de la base la herencia
93 ProcessingUnit.__init__(self)#, **kwargs)
93 ProcessingUnit.__init__(self)#, **kwargs)
94
94
95 # self.isConfig = False
95 # self.isConfig = False
96
96
97 self.pts2read_SelfSpectra = 0
97 self.pts2read_SelfSpectra = 0
98
98
99 self.pts2read_CrossSpectra = 0
99 self.pts2read_CrossSpectra = 0
100
100
101 self.pts2read_DCchannels = 0
101 self.pts2read_DCchannels = 0
102
102
103 self.datablock = None
103 self.datablock = None
104
104
105 self.utc = None
105 self.utc = None
106
106
107 self.ext = ".pdata"
107 self.ext = ".pdata"
108
108
109 self.optchar = "P"
109 self.optchar = "P"
110
110
111 self.basicHeaderObj = BasicHeader(LOCALTIME)
111 self.basicHeaderObj = BasicHeader(LOCALTIME)
112
112
113 self.systemHeaderObj = SystemHeader()
113 self.systemHeaderObj = SystemHeader()
114
114
115 self.radarControllerHeaderObj = RadarControllerHeader()
115 self.radarControllerHeaderObj = RadarControllerHeader()
116
116
117 self.processingHeaderObj = ProcessingHeader()
117 self.processingHeaderObj = ProcessingHeader()
118
118
119 self.online = 0
119 self.online = 0
120
120
121 self.fp = None
121 self.fp = None
122
122
123 self.idFile = None
123 self.idFile = None
124
124
125 self.dtype = None
125 self.dtype = None
126
126
127 self.fileSizeByHeader = None
127 self.fileSizeByHeader = None
128
128
129 self.filenameList = []
129 self.filenameList = []
130
130
131 self.filename = None
131 self.filename = None
132
132
133 self.fileSize = None
133 self.fileSize = None
134
134
135 self.firstHeaderSize = 0
135 self.firstHeaderSize = 0
136
136
137 self.basicHeaderSize = 24
137 self.basicHeaderSize = 24
138
138
139 self.pathList = []
139 self.pathList = []
140
140
141 self.lastUTTime = 0
141 self.lastUTTime = 0
142
142
143 self.maxTimeStep = 30
143 self.maxTimeStep = 30
144
144
145 self.flagNoMoreFiles = 0
145 self.flagNoMoreFiles = 0
146
146
147 self.set = 0
147 self.set = 0
148
148
149 self.path = None
149 self.path = None
150
150
151 self.delay = 60 #seconds
151 self.delay = 60 #seconds
152
152
153 self.nTries = 3 #quantity tries
153 self.nTries = 3 #quantity tries
154
154
155 self.nFiles = 3 #number of files for searching
155 self.nFiles = 3 #number of files for searching
156
156
157 self.nReadBlocks = 0
157 self.nReadBlocks = 0
158
158
159 self.flagIsNewFile = 1
159 self.flagIsNewFile = 1
160
160
161 self.__isFirstTimeOnline = 1
161 self.__isFirstTimeOnline = 1
162
162
163 # self.ippSeconds = 0
163 # self.ippSeconds = 0
164
164
165 self.flagDiscontinuousBlock = 0
165 self.flagDiscontinuousBlock = 0
166
166
167 self.flagIsNewBlock = 0
167 self.flagIsNewBlock = 0
168
168
169 self.nTotalBlocks = 0
169 self.nTotalBlocks = 0
170
170
171 self.blocksize = 0
171 self.blocksize = 0
172
172
173 self.dataOut = self.createObjByDefault()
173 self.dataOut = self.createObjByDefault()
174
174
175 self.profileIndex = 1 #Always
175 self.profileIndex = 1 #Always
176
176
177
177
178 def createObjByDefault(self):
178 def createObjByDefault(self):
179
179
180 dataObj = Spectra()
180 dataObj = Spectra()
181
181
182 return dataObj
182 return dataObj
183
183
184 def __hasNotDataInBuffer(self):
184 def __hasNotDataInBuffer(self):
185 return 1
185 return 1
186
186
187
187
188 def getBlockDimension(self):
188 def getBlockDimension(self):
189 """
189 """
190 Obtiene la cantidad de puntos a leer por cada bloque de datos
190 Obtiene la cantidad de puntos a leer por cada bloque de datos
191
191
192 Affected:
192 Affected:
193 self.nRdChannels
193 self.nRdChannels
194 self.nRdPairs
194 self.nRdPairs
195 self.pts2read_SelfSpectra
195 self.pts2read_SelfSpectra
196 self.pts2read_CrossSpectra
196 self.pts2read_CrossSpectra
197 self.pts2read_DCchannels
197 self.pts2read_DCchannels
198 self.blocksize
198 self.blocksize
199 self.dataOut.nChannels
199 self.dataOut.nChannels
200 self.dataOut.nPairs
200 self.dataOut.nPairs
201
201
202 Return:
202 Return:
203 None
203 None
204 """
204 """
205 self.nRdChannels = 0
205 self.nRdChannels = 0
206 self.nRdPairs = 0
206 self.nRdPairs = 0
207 self.rdPairList = []
207 self.rdPairList = []
208
208
209 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
209 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
210 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
210 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
211 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
211 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
212 else:
212 else:
213 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
213 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
214 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
214 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
215
215
216 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
216 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
217
217
218 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
218 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
219 self.blocksize = self.pts2read_SelfSpectra
219 self.blocksize = self.pts2read_SelfSpectra
220
220
221 if self.processingHeaderObj.flag_cspc:
221 if self.processingHeaderObj.flag_cspc:
222 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
222 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
223 self.blocksize += self.pts2read_CrossSpectra
223 self.blocksize += self.pts2read_CrossSpectra
224
224
225 if self.processingHeaderObj.flag_dc:
225 if self.processingHeaderObj.flag_dc:
226 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
226 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
227 self.blocksize += self.pts2read_DCchannels
227 self.blocksize += self.pts2read_DCchannels
228
228
229 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
229 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
230
230
231
231
232 def readBlock(self):
232 def readBlock(self):
233 """
233 """
234 Lee el bloque de datos desde la posicion actual del puntero del archivo
234 Lee el bloque de datos desde la posicion actual del puntero del archivo
235 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
235 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
236 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
236 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
237 es seteado a 0
237 es seteado a 0
238
238
239 Return: None
239 Return: None
240
240
241 Variables afectadas:
241 Variables afectadas:
242
242
243 self.flagIsNewFile
243 self.flagIsNewFile
244 self.flagIsNewBlock
244 self.flagIsNewBlock
245 self.nTotalBlocks
245 self.nTotalBlocks
246 self.data_spc
246 self.data_spc
247 self.data_cspc
247 self.data_cspc
248 self.data_dc
248 self.data_dc
249
249
250 Exceptions:
250 Exceptions:
251 Si un bloque leido no es un bloque valido
251 Si un bloque leido no es un bloque valido
252 """
252 """
253 blockOk_flag = False
253 blockOk_flag = False
254 fpointer = self.fp.tell()
254 fpointer = self.fp.tell()
255
255
256 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
256 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
257 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
257 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
258
258
259 if self.processingHeaderObj.flag_cspc:
259 if self.processingHeaderObj.flag_cspc:
260 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
260 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
261 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
261 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
262
262
263 if self.processingHeaderObj.flag_dc:
263 if self.processingHeaderObj.flag_dc:
264 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
264 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
265 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
265 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
266
266
267
267
268 if not self.processingHeaderObj.shif_fft:
268 if not self.processingHeaderObj.shif_fft:
269 #desplaza a la derecha en el eje 2 determinadas posiciones
269 #desplaza a la derecha en el eje 2 determinadas posiciones
270 shift = int(self.processingHeaderObj.profilesPerBlock/2)
270 shift = int(self.processingHeaderObj.profilesPerBlock/2)
271 spc = numpy.roll( spc, shift , axis=2 )
271 spc = numpy.roll( spc, shift , axis=2 )
272
272
273 if self.processingHeaderObj.flag_cspc:
273 if self.processingHeaderObj.flag_cspc:
274 #desplaza a la derecha en el eje 2 determinadas posiciones
274 #desplaza a la derecha en el eje 2 determinadas posiciones
275 cspc = numpy.roll( cspc, shift, axis=2 )
275 cspc = numpy.roll( cspc, shift, axis=2 )
276
276
277 #Dimensions : nChannels, nProfiles, nSamples
277 #Dimensions : nChannels, nProfiles, nSamples
278 spc = numpy.transpose( spc, (0,2,1) )
278 spc = numpy.transpose( spc, (0,2,1) )
279 self.data_spc = spc
279 self.data_spc = spc
280
280
281 if self.processingHeaderObj.flag_cspc:
281 if self.processingHeaderObj.flag_cspc:
282 cspc = numpy.transpose( cspc, (0,2,1) )
282 cspc = numpy.transpose( cspc, (0,2,1) )
283 self.data_cspc = cspc['real'] + cspc['imag']*1j
283 self.data_cspc = cspc['real'] + cspc['imag']*1j
284 else:
284 else:
285 self.data_cspc = None
285 self.data_cspc = None
286
286
287 if self.processingHeaderObj.flag_dc:
287 if self.processingHeaderObj.flag_dc:
288 self.data_dc = dc['real'] + dc['imag']*1j
288 self.data_dc = dc['real'] + dc['imag']*1j
289 else:
289 else:
290 self.data_dc = None
290 self.data_dc = None
291
291
292 self.flagIsNewFile = 0
292 self.flagIsNewFile = 0
293 self.flagIsNewBlock = 1
293 self.flagIsNewBlock = 1
294
294
295 self.nTotalBlocks += 1
295 self.nTotalBlocks += 1
296 self.nReadBlocks += 1
296 self.nReadBlocks += 1
297
297
298 return 1
298 return 1
299
299
300 def getFirstHeader(self):
300 def getFirstHeader(self):
301
301
302 self.getBasicHeader()
302 self.getBasicHeader()
303
303
304 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
304 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
305
305
306 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
306 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
307
307
308 # self.dataOut.ippSeconds = self.ippSeconds
308 # self.dataOut.ippSeconds = self.ippSeconds
309
309
310 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
310 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
311
311
312 self.dataOut.dtype = self.dtype
312 self.dataOut.dtype = self.dtype
313
313
314 # self.dataOut.nPairs = self.nPairs
314 # self.dataOut.nPairs = self.nPairs
315
315
316 self.dataOut.pairsList = self.rdPairList
316 self.dataOut.pairsList = self.rdPairList
317
317
318 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
318 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
319
319
320 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
320 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
321
321
322 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
322 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
323
323
324 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
324 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
325
325
326 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
326 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
327
327
328 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
328 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
329
329
330 self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels))
330 self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels))
331
331
332 self.dataOut.flagShiftFFT = True #Data is always shifted
332 self.dataOut.flagShiftFFT = True #Data is always shifted
333
333
334 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
334 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
335
335
336 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
336 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
337
337
338 def getData(self):
338 def getData(self):
339 """
339 """
340 First method to execute before "RUN" is called.
340 First method to execute before "RUN" is called.
341
341
342 Copia el buffer de lectura a la clase "Spectra",
342 Copia el buffer de lectura a la clase "Spectra",
343 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
343 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
344 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
344 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
345
345
346 Return:
346 Return:
347 0 : Si no hay mas archivos disponibles
347 0 : Si no hay mas archivos disponibles
348 1 : Si hizo una buena copia del buffer
348 1 : Si hizo una buena copia del buffer
349
349
350 Affected:
350 Affected:
351 self.dataOut
351 self.dataOut
352
352
353 self.flagDiscontinuousBlock
353 self.flagDiscontinuousBlock
354 self.flagIsNewBlock
354 self.flagIsNewBlock
355 """
355 """
356
356
357 if self.flagNoMoreFiles:
357 if self.flagNoMoreFiles:
358 self.dataOut.flagNoData = True
358 self.dataOut.flagNoData = True
359 print('Process finished')
359 print('Process finished')
360 return 0
360 return 0
361
361
362 self.flagDiscontinuousBlock = 0
362 self.flagDiscontinuousBlock = 0
363 self.flagIsNewBlock = 0
363 self.flagIsNewBlock = 0
364
364
365 if self.__hasNotDataInBuffer():
365 if self.__hasNotDataInBuffer():
366
366
367 if not( self.readNextBlock() ):
367 if not( self.readNextBlock() ):
368 self.dataOut.flagNoData = True
368 self.dataOut.flagNoData = True
369 return 0
369 return 0
370
370
371 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
371 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
372
372
373 if self.data_spc is None:
373 if self.data_spc is None:
374 self.dataOut.flagNoData = True
374 self.dataOut.flagNoData = True
375 return 0
375 return 0
376
376
377 self.getBasicHeader()
377 self.getBasicHeader()
378
378
379 self.getFirstHeader()
379 self.getFirstHeader()
380
380
381 self.dataOut.data_spc = self.data_spc
381 self.dataOut.data_spc = self.data_spc
382
382
383 self.dataOut.data_cspc = self.data_cspc
383 self.dataOut.data_cspc = self.data_cspc
384
384
385 self.dataOut.data_dc = self.data_dc
385 self.dataOut.data_dc = self.data_dc
386
386
387 self.dataOut.flagNoData = False
387 self.dataOut.flagNoData = False
388
388
389 self.dataOut.realtime = self.online
389 self.dataOut.realtime = self.online
390
390
391 return self.dataOut.data_spc
391 return self.dataOut.data_spc
392 @MPDecorator
392 @MPDecorator
393 class SpectraWriter(JRODataWriter, Operation):
393 class SpectraWriter(JRODataWriter, Operation):
394
394
395 """
395 """
396 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
396 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
397 de los datos siempre se realiza por bloques.
397 de los datos siempre se realiza por bloques.
398 """
398 """
399
399
400 ext = ".pdata"
400 ext = ".pdata"
401
401
402 optchar = "P"
402 optchar = "P"
403
403
404 shape_spc_Buffer = None
404 shape_spc_Buffer = None
405
405
406 shape_cspc_Buffer = None
406 shape_cspc_Buffer = None
407
407
408 shape_dc_Buffer = None
408 shape_dc_Buffer = None
409
409
410 data_spc = None
410 data_spc = None
411
411
412 data_cspc = None
412 data_cspc = None
413
413
414 data_dc = None
414 data_dc = None
415
415
416 # dataOut = None
416 def __init__(self):
417
418 def __init__(self):#, **kwargs):
419 """
417 """
420 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
421
419
422 Affected:
420 Affected:
423 self.dataOut
421 self.dataOut
424 self.basicHeaderObj
422 self.basicHeaderObj
425 self.systemHeaderObj
423 self.systemHeaderObj
426 self.radarControllerHeaderObj
424 self.radarControllerHeaderObj
427 self.processingHeaderObj
425 self.processingHeaderObj
428
426
429 Return: None
427 Return: None
430 """
428 """
431
429
432 Operation.__init__(self)#, **kwargs)
430 Operation.__init__(self)
433
434 #self.isConfig = False
435
431
436 self.nTotalBlocks = 0
432 self.nTotalBlocks = 0
437
433
438 self.data_spc = None
434 self.data_spc = None
439
435
440 self.data_cspc = None
436 self.data_cspc = None
441
437
442 self.data_dc = None
438 self.data_dc = None
443
439
444 self.fp = None
440 self.fp = None
445
441
446 self.flagIsNewFile = 1
442 self.flagIsNewFile = 1
447
443
448 self.nTotalBlocks = 0
444 self.nTotalBlocks = 0
449
445
450 self.flagIsNewBlock = 0
446 self.flagIsNewBlock = 0
451
447
452 self.setFile = None
448 self.setFile = None
453
449
454 self.dtype = None
450 self.dtype = None
455
451
456 self.path = None
452 self.path = None
457
453
458 self.noMoreFiles = 0
454 self.noMoreFiles = 0
459
455
460 self.filename = None
456 self.filename = None
461
457
462 self.basicHeaderObj = BasicHeader(LOCALTIME)
458 self.basicHeaderObj = BasicHeader(LOCALTIME)
463
459
464 self.systemHeaderObj = SystemHeader()
460 self.systemHeaderObj = SystemHeader()
465
461
466 self.radarControllerHeaderObj = RadarControllerHeader()
462 self.radarControllerHeaderObj = RadarControllerHeader()
467
463
468 self.processingHeaderObj = ProcessingHeader()
464 self.processingHeaderObj = ProcessingHeader()
469
465
470
466
471 def hasAllDataInBuffer(self):
467 def hasAllDataInBuffer(self):
472 return 1
468 return 1
473
469
474
470
475 def setBlockDimension(self):
471 def setBlockDimension(self):
476 """
472 """
477 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
473 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
478
474
479 Affected:
475 Affected:
480 self.shape_spc_Buffer
476 self.shape_spc_Buffer
481 self.shape_cspc_Buffer
477 self.shape_cspc_Buffer
482 self.shape_dc_Buffer
478 self.shape_dc_Buffer
483
479
484 Return: None
480 Return: None
485 """
481 """
486 self.shape_spc_Buffer = (self.dataOut.nChannels,
482 self.shape_spc_Buffer = (self.dataOut.nChannels,
487 self.processingHeaderObj.nHeights,
483 self.processingHeaderObj.nHeights,
488 self.processingHeaderObj.profilesPerBlock)
484 self.processingHeaderObj.profilesPerBlock)
489
485
490 self.shape_cspc_Buffer = (self.dataOut.nPairs,
486 self.shape_cspc_Buffer = (self.dataOut.nPairs,
491 self.processingHeaderObj.nHeights,
487 self.processingHeaderObj.nHeights,
492 self.processingHeaderObj.profilesPerBlock)
488 self.processingHeaderObj.profilesPerBlock)
493
489
494 self.shape_dc_Buffer = (self.dataOut.nChannels,
490 self.shape_dc_Buffer = (self.dataOut.nChannels,
495 self.processingHeaderObj.nHeights)
491 self.processingHeaderObj.nHeights)
496
492
497
493
498 def writeBlock(self):
494 def writeBlock(self):
499 """
495 """processingHeaderObj
500 Escribe el buffer en el file designado
496 Escribe el buffer en el file designado
501
497
502 Affected:
498 Affected:
503 self.data_spc
499 self.data_spc
504 self.data_cspc
500 self.data_cspc
505 self.data_dc
501 self.data_dc
506 self.flagIsNewFile
502 self.flagIsNewFile
507 self.flagIsNewBlock
503 self.flagIsNewBlock
508 self.nTotalBlocks
504 self.nTotalBlocks
509 self.nWriteBlocks
505 self.nWriteBlocks
510
506
511 Return: None
507 Return: None
512 """
508 """
513
509
514 spc = numpy.transpose( self.data_spc, (0,2,1) )
510 spc = numpy.transpose( self.data_spc, (0,2,1) )
515 if not self.processingHeaderObj.shif_fft:
511 if not self.processingHeaderObj.shif_fft:
516 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
512 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
517 data = spc.reshape((-1))
513 data = spc.reshape((-1))
518 data = data.astype(self.dtype[0])
514 data = data.astype(self.dtype[0])
519 data.tofile(self.fp)
515 data.tofile(self.fp)
520
516
521 if self.data_cspc is not None:
517 if self.data_cspc is not None:
522 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
518
523 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
519 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
520 #data = numpy.zeros( numpy.shape(cspc), self.dtype )
521 #print 'data.shape', self.shape_cspc_Buffer
524 if not self.processingHeaderObj.shif_fft:
522 if not self.processingHeaderObj.shif_fft:
525 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
523 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
526 data['real'] = cspc.real
524 data['real'] = cspc.real
527 data['imag'] = cspc.imag
525 data['imag'] = cspc.imag
528 data = data.reshape((-1))
526 data = data.reshape((-1))
529 data.tofile(self.fp)
527 data.tofile(self.fp)
530
528
531 if self.data_dc is not None:
529 if self.data_dc is not None:
532 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
530
533 dc = self.data_dc
531 dc = self.data_dc
532 data = numpy.zeros( numpy.shape(dc), self.dtype )
534 data['real'] = dc.real
533 data['real'] = dc.real
535 data['imag'] = dc.imag
534 data['imag'] = dc.imag
536 data = data.reshape((-1))
535 data = data.reshape((-1))
537 data.tofile(self.fp)
536 data.tofile(self.fp)
538
537
539 # self.data_spc.fill(0)
538 # self.data_spc.fill(0)
540 #
539 #
541 # if self.data_dc is not None:
540 # if self.data_dc is not None:
542 # self.data_dc.fill(0)
541 # self.data_dc.fill(0)
543 #
542 #
544 # if self.data_cspc is not None:
543 # if self.data_cspc is not None:
545 # self.data_cspc.fill(0)
544 # self.data_cspc.fill(0)
546
545
547 self.flagIsNewFile = 0
546 self.flagIsNewFile = 0
548 self.flagIsNewBlock = 1
547 self.flagIsNewBlock = 1
549 self.nTotalBlocks += 1
548 self.nTotalBlocks += 1
550 self.nWriteBlocks += 1
549 self.nWriteBlocks += 1
551 self.blockIndex += 1
550 self.blockIndex += 1
552
551
553 # print "[Writing] Block = %d04" %self.blockIndex
552 # print "[Writing] Block = %d04" %self.blockIndex
554
553
555 def putData(self):
554 def putData(self):
556 """
555 """
557 Setea un bloque de datos y luego los escribe en un file
556 Setea un bloque de datos y luego los escribe en un file
558
557
559 Affected:
558 Affected:
560 self.data_spc
559 self.data_spc
561 self.data_cspc
560 self.data_cspc
562 self.data_dc
561 self.data_dc
563
562
564 Return:
563 Return:
565 0 : Si no hay data o no hay mas files que puedan escribirse
564 0 : Si no hay data o no hay mas files que puedan escribirse
566 1 : Si se escribio la data de un bloque en un file
565 1 : Si se escribio la data de un bloque en un file
567 """
566 """
568
567
569 if self.dataOut.flagNoData:
568 if self.dataOut.flagNoData:
570 return 0
569 return 0
571
570
572 self.flagIsNewBlock = 0
571 self.flagIsNewBlock = 0
573
572
574 if self.dataOut.flagDiscontinuousBlock:
573 if self.dataOut.flagDiscontinuousBlock:
575 self.data_spc.fill(0)
574 self.data_spc.fill(0)
576 if self.dataOut.data_cspc is not None:
575 if self.dataOut.data_cspc is not None:
577 self.data_cspc.fill(0)
576 self.data_cspc.fill(0)
578 if self.dataOut.data_dc is not None:
577 if self.dataOut.data_dc is not None:
579 self.data_dc.fill(0)
578 self.data_dc.fill(0)
580 self.setNextFile()
579 self.setNextFile()
581
580
582 if self.flagIsNewFile == 0:
581 if self.flagIsNewFile == 0:
583 self.setBasicHeader()
582 self.setBasicHeader()
584
583
585 self.data_spc = self.dataOut.data_spc.copy()
584 self.data_spc = self.dataOut.data_spc.copy()
586
585
587 if self.dataOut.data_cspc is not None:
586 if self.dataOut.data_cspc is not None:
588 self.data_cspc = self.dataOut.data_cspc.copy()
587 self.data_cspc = self.dataOut.data_cspc.copy()
589
588
590 if self.dataOut.data_dc is not None:
589 if self.dataOut.data_dc is not None:
591 self.data_dc = self.dataOut.data_dc.copy()
590 self.data_dc = self.dataOut.data_dc.copy()
592
591
593 # #self.processingHeaderObj.dataBlocksPerFile)
592 # #self.processingHeaderObj.dataBlocksPerFile)
594 if self.hasAllDataInBuffer():
593 if self.hasAllDataInBuffer():
595 # self.setFirstHeader()
594 # self.setFirstHeader()
596 self.writeNextBlock()
595 self.writeNextBlock()
597
596
598 def __getBlockSize(self):
597 def __getBlockSize(self):
599 '''
598 '''
600 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
599 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
601 '''
600 '''
602
601
603 dtype_width = self.getDtypeWidth()
602 dtype_width = self.getDtypeWidth()
604
603
605 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
604 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
606
605
607 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
606 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
608 blocksize = (pts2write_SelfSpectra*dtype_width)
607 blocksize = (pts2write_SelfSpectra*dtype_width)
609
608
610 if self.dataOut.data_cspc is not None:
609 if self.dataOut.data_cspc is not None:
611 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
610 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
612 blocksize += (pts2write_CrossSpectra*dtype_width*2)
611 blocksize += (pts2write_CrossSpectra*dtype_width*2)
613
612
614 if self.dataOut.data_dc is not None:
613 if self.dataOut.data_dc is not None:
615 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
614 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
616 blocksize += (pts2write_DCchannels*dtype_width*2)
615 blocksize += (pts2write_DCchannels*dtype_width*2)
617
616
618 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
617 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
619
618
620 return blocksize
619 return blocksize
621
620
622 def setFirstHeader(self):
621 def setFirstHeader(self):
623
622
624 """
623 """
625 Obtiene una copia del First Header
624 Obtiene una copia del First Header
626
625
627 Affected:
626 Affected:
628 self.systemHeaderObj
627 self.systemHeaderObj
629 self.radarControllerHeaderObj
628 self.radarControllerHeaderObj
630 self.dtype
629 self.dtype
631
630
632 Return:
631 Return:
633 None
632 None
634 """
633 """
635
634
636 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
635 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
637 self.systemHeaderObj.nChannels = self.dataOut.nChannels
636 self.systemHeaderObj.nChannels = self.dataOut.nChannels
638 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
637 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
639
638
640 self.processingHeaderObj.dtype = 1 # Spectra
639 self.processingHeaderObj.dtype = 1 # Spectra
641 self.processingHeaderObj.blockSize = self.__getBlockSize()
640 self.processingHeaderObj.blockSize = self.__getBlockSize()
642 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
641 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
643 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
642 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
644 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
643 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
644 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
646 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
645 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
647 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
646 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
648 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
647 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
649
648
650 if self.processingHeaderObj.totalSpectra > 0:
649 if self.processingHeaderObj.totalSpectra > 0:
651 channelList = []
650 channelList = []
652 for channel in range(self.dataOut.nChannels):
651 for channel in range(self.dataOut.nChannels):
653 channelList.append(channel)
652 channelList.append(channel)
654 channelList.append(channel)
653 channelList.append(channel)
655
654
656 pairsList = []
655 pairsList = []
657 if self.dataOut.nPairs > 0:
656 if self.dataOut.nPairs > 0:
658 for pair in self.dataOut.pairsList:
657 for pair in self.dataOut.pairsList:
659 pairsList.append(pair[0])
658 pairsList.append(pair[0])
660 pairsList.append(pair[1])
659 pairsList.append(pair[1])
661
660
662 spectraComb = channelList + pairsList
661 spectraComb = channelList + pairsList
663 spectraComb = numpy.array(spectraComb, dtype="u1")
662 spectraComb = numpy.array(spectraComb, dtype="u1")
664 self.processingHeaderObj.spectraComb = spectraComb
663 self.processingHeaderObj.spectraComb = spectraComb
665
664
666 if self.dataOut.code is not None:
665 if self.dataOut.code is not None:
667 self.processingHeaderObj.code = self.dataOut.code
666 self.processingHeaderObj.code = self.dataOut.code
668 self.processingHeaderObj.nCode = self.dataOut.nCode
667 self.processingHeaderObj.nCode = self.dataOut.nCode
669 self.processingHeaderObj.nBaud = self.dataOut.nBaud
668 self.processingHeaderObj.nBaud = self.dataOut.nBaud
670
669
671 if self.processingHeaderObj.nWindows != 0:
670 if self.processingHeaderObj.nWindows != 0:
672 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
671 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
673 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
672 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
674 self.processingHeaderObj.nHeights = self.dataOut.nHeights
673 self.processingHeaderObj.nHeights = self.dataOut.nHeights
675 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
674 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
676
675
677 self.processingHeaderObj.processFlags = self.getProcessFlags()
676 self.processingHeaderObj.processFlags = self.getProcessFlags()
678
677
679 self.setBasicHeader() No newline at end of file
678 self.setBasicHeader()
1 NO CONTENT: modified file chmod 100644 => 100755
NO CONTENT: modified file chmod 100644 => 100755
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now