@@ -38,35 +38,40 class ParameterConf(): | |||
|
38 | 38 | |
|
39 | 39 | def getValue(self): |
|
40 | 40 | |
|
41 | value = self.value | |
|
42 | ||
|
41 | 43 | if self.format == 'list': |
|
42 |
strList = |
|
|
44 | strList = value.split(',') | |
|
43 | 45 | return strList |
|
44 | 46 | |
|
45 | 47 | if self.format == 'intlist': |
|
46 |
strList = |
|
|
48 | strList = value.split(',') | |
|
47 | 49 | intList = [int(x) for x in strList] |
|
48 | 50 | return intList |
|
49 | 51 | |
|
50 | 52 | if self.format == 'floatlist': |
|
51 |
strList = |
|
|
53 | strList = value.split(',') | |
|
52 | 54 | floatList = [float(x) for x in strList] |
|
53 | 55 | return floatList |
|
54 | 56 | |
|
55 | 57 | if self.format == 'date': |
|
56 |
strList = |
|
|
58 | strList = value.split('/') | |
|
57 | 59 | intList = [int(x) for x in strList] |
|
58 | 60 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
59 | 61 | return date |
|
60 | 62 | |
|
61 | 63 | if self.format == 'time': |
|
62 |
strList = |
|
|
64 | strList = value.split(':') | |
|
63 | 65 | intList = [int(x) for x in strList] |
|
64 | 66 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
65 | 67 | return time |
|
66 |
|
|
|
68 | ||
|
69 | if self.format == 'bool': | |
|
70 | value = int(value) | |
|
71 | ||
|
67 | 72 | func = eval(self.format) |
|
68 |
|
|
|
69 |
return func( |
|
|
73 | ||
|
74 | return func(value) | |
|
70 | 75 | |
|
71 | 76 | def setup(self, id, name, value, format='str'): |
|
72 | 77 | |
@@ -359,9 +364,6 class ReadUnitConf(ProcUnitConf): | |||
|
359 | 364 | endDate = None |
|
360 | 365 | startTime = None |
|
361 | 366 | endTime = None |
|
362 | online = None | |
|
363 | expLabel = None | |
|
364 | delay = None | |
|
365 | 367 | |
|
366 | 368 | ELEMENTNAME = 'ReadUnit' |
|
367 | 369 | |
@@ -379,7 +381,7 class ReadUnitConf(ProcUnitConf): | |||
|
379 | 381 | |
|
380 | 382 | return self.ELEMENTNAME |
|
381 | 383 | |
|
382 |
def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, |
|
|
384 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, **kwargs): | |
|
383 | 385 | |
|
384 | 386 | self.id = id |
|
385 | 387 | self.name = name |
@@ -390,13 +392,10 class ReadUnitConf(ProcUnitConf): | |||
|
390 | 392 | self.endDate = endDate |
|
391 | 393 | self.startTime = startTime |
|
392 | 394 | self.endTime = endTime |
|
393 | self.online = online | |
|
394 | self.expLabel = expLabel | |
|
395 | self.delay = delay | |
|
396 | 395 | |
|
397 | self.addRunOperation() | |
|
396 | self.addRunOperation(**kwargs) | |
|
398 | 397 | |
|
399 | def addRunOperation(self): | |
|
398 | def addRunOperation(self, **kwargs): | |
|
400 | 399 | |
|
401 | 400 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
402 | 401 | |
@@ -405,14 +404,14 class ReadUnitConf(ProcUnitConf): | |||
|
405 | 404 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
406 | 405 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
407 | 406 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
408 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') | |
|
409 | opObj.addParameter(name='online' , value=self.online, format='int') | |
|
410 |
opObj.addParameter(name= |
|
|
411 |
|
|
|
407 | ||
|
408 | for key, value in kwargs.items(): | |
|
409 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
|
410 | ||
|
412 | 411 | return opObj |
|
413 | 412 | |
|
414 | 413 | |
|
415 |
class |
|
|
414 | class Project(): | |
|
416 | 415 | |
|
417 | 416 | id = None |
|
418 | 417 | name = None |
@@ -420,7 +419,7 class Controller(): | |||
|
420 | 419 | # readUnitConfObjList = None |
|
421 | 420 | procUnitConfObjDict = None |
|
422 | 421 | |
|
423 |
ELEMENTNAME = ' |
|
|
422 | ELEMENTNAME = 'Project' | |
|
424 | 423 | |
|
425 | 424 | def __init__(self): |
|
426 | 425 | |
@@ -447,13 +446,13 class Controller(): | |||
|
447 | 446 | self.name = name |
|
448 | 447 | self.description = description |
|
449 | 448 | |
|
450 |
def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', |
|
|
449 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', **kwargs): | |
|
451 | 450 | |
|
452 | 451 | id = self.__getNewId() |
|
453 | 452 | name = '%sReader' %(datatype) |
|
454 | 453 | |
|
455 | 454 | readUnitConfObj = ReadUnitConf() |
|
456 |
readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, |
|
|
455 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, **kwargs) | |
|
457 | 456 | |
|
458 | 457 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
459 | 458 | |
@@ -473,7 +472,7 class Controller(): | |||
|
473 | 472 | |
|
474 | 473 | def makeXml(self): |
|
475 | 474 | |
|
476 |
projectElement = Element(' |
|
|
475 | projectElement = Element('Project') | |
|
477 | 476 | projectElement.set('id', str(self.id)) |
|
478 | 477 | projectElement.set('name', self.name) |
|
479 | 478 | projectElement.set('description', self.description) |
@@ -527,7 +526,7 class Controller(): | |||
|
527 | 526 | |
|
528 | 527 | def printattr(self): |
|
529 | 528 | |
|
530 |
print " |
|
|
529 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
|
531 | 530 | self.name, |
|
532 | 531 | self.description) |
|
533 | 532 | |
@@ -589,7 +588,7 if __name__ == '__main__': | |||
|
589 | 588 | desc = "Segundo Test" |
|
590 | 589 | filename = "schain.xml" |
|
591 | 590 | |
|
592 |
controllerObj = |
|
|
591 | controllerObj = Project() | |
|
593 | 592 | |
|
594 | 593 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
595 | 594 | |
@@ -599,7 +598,8 if __name__ == '__main__': | |||
|
599 | 598 | endDate='2012/12/31', |
|
600 | 599 | startTime='00:00:00', |
|
601 | 600 | endTime='23:59:59', |
|
602 |
online= |
|
|
601 | online=1, | |
|
602 | walk=1) | |
|
603 | 603 | |
|
604 | 604 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') |
|
605 | 605 | |
@@ -617,6 +617,8 if __name__ == '__main__': | |||
|
617 | 617 | |
|
618 | 618 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
619 | 619 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
620 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') | |
|
621 | ||
|
620 | 622 | |
|
621 | 623 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
622 | 624 | opObj11.addParameter(name='idfigure', value='1', format='int') |
@@ -624,21 +626,28 if __name__ == '__main__': | |||
|
624 | 626 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
625 | 627 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
626 | 628 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
627 | ||
|
628 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) | |
|
629 | ||
|
630 | opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') | |
|
631 | opObj12.addParameter(name='n', value='2', format='int') | |
|
632 | opObj12.addParameter(name='overlapping', value='1', format='int') | |
|
633 | 629 | |
|
634 | procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) | |
|
635 |
|
|
|
636 | ||
|
637 | opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') | |
|
638 |
opObj11.addParameter(name=' |
|
|
639 | opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') | |
|
640 | opObj11.addParameter(name='zmin', value='40', format='int') | |
|
641 | opObj11.addParameter(name='zmax', value='90', format='int') | |
|
630 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
|
631 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
|
632 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
|
633 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
|
634 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
635 | ||
|
636 | ||
|
637 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) | |
|
638 | # | |
|
639 | # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') | |
|
640 | # opObj12.addParameter(name='n', value='2', format='int') | |
|
641 | # opObj12.addParameter(name='overlapping', value='1', format='int') | |
|
642 | # | |
|
643 | # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) | |
|
644 | # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') | |
|
645 | # | |
|
646 | # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') | |
|
647 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
|
648 | # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') | |
|
649 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
|
650 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
642 | 651 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
643 | 652 | |
|
644 | 653 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
@@ -255,27 +255,10 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |||
|
255 | 255 | |
|
256 | 256 | if XAxisAsTime: |
|
257 | 257 | |
|
258 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S")) | |
|
258 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
|
259 | 259 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
260 | 260 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
261 | 261 | |
|
262 | # seconds = numpy.array([xmin, xmax]) | |
|
263 | # datesList = map(datetime.datetime.fromtimestamp, seconds) | |
|
264 | # ax.set_xlim([datesList[0],datesList[-1]]) | |
|
265 | # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) | |
|
266 | # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) | |
|
267 | # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) | |
|
268 | # xdateList = map(datetime.datetime.fromtimestamp, x) | |
|
269 | # xdate = matplotlib.dates.date2num(xdateList) | |
|
270 | # x = xdate | |
|
271 | ||
|
272 | # labels = [] | |
|
273 | # for item in ax.xaxis.get_ticklabels(): | |
|
274 | # stri = item.get_text() | |
|
275 | # text = datetime.datetime.fromtimestamp(float(stri)) | |
|
276 | # labels.append(text) | |
|
277 | # | |
|
278 | # ax.xaxis.set_ticklabels(labels) | |
|
279 | 262 | return imesh |
|
280 | 263 | |
|
281 | 264 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
@@ -290,9 +273,6 def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |||
|
290 | 273 | |
|
291 | 274 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): |
|
292 | 275 | |
|
293 | # xdateList = map(datetime.datetime.fromtimestamp, x) | |
|
294 | # xdate = matplotlib.dates.date2num(xdateList) | |
|
295 | ||
|
296 | 276 | printLabels(ax, xlabel, ylabel, title) |
|
297 | 277 | |
|
298 | 278 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
@@ -7,6 +7,7 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |||
|
7 | 7 | import os, sys |
|
8 | 8 | import copy |
|
9 | 9 | import numpy |
|
10 | import datetime | |
|
10 | 11 | |
|
11 | 12 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | 13 | |
@@ -211,6 +212,11 class JROData: | |||
|
211 | 212 | |
|
212 | 213 | def getDatatime(self): |
|
213 | 214 | |
|
215 | datatime = datetime.datetime.utcfromtimestamp(self.utctime) | |
|
216 | return datatime | |
|
217 | ||
|
218 | def getTimeRange(self): | |
|
219 | ||
|
214 | 220 | datatime = [] |
|
215 | 221 | |
|
216 | 222 | datatime.append(self.utctime) |
@@ -238,10 +244,9 class JROData: | |||
|
238 | 244 | |
|
239 | 245 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
240 | 246 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
241 | ||
|
242 | 247 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
243 | ||
|
244 | 248 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
249 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
|
245 | 250 | |
|
246 | 251 | class Voltage(JROData): |
|
247 | 252 |
@@ -74,6 +74,48 def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |||
|
74 | 74 | |
|
75 | 75 | return 1 |
|
76 | 76 | |
|
77 | def isFileinThisTime(filename, startTime, endTime): | |
|
78 | """ | |
|
79 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
|
80 | ||
|
81 | Inputs: | |
|
82 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
|
83 | ||
|
84 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
|
85 | ||
|
86 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
|
87 | ||
|
88 | Return: | |
|
89 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
|
90 | fecha especificado, de lo contrario retorna False. | |
|
91 | ||
|
92 | Excepciones: | |
|
93 | Si el archivo no existe o no puede ser abierto | |
|
94 | Si la cabecera no puede ser leida. | |
|
95 | ||
|
96 | """ | |
|
97 | ||
|
98 | ||
|
99 | try: | |
|
100 | fp = open(filename,'rb') | |
|
101 | except: | |
|
102 | raise IOError, "The file %s can't be opened" %(filename) | |
|
103 | ||
|
104 | basicHeaderObj = BasicHeader() | |
|
105 | sts = basicHeaderObj.read(fp) | |
|
106 | fp.close() | |
|
107 | ||
|
108 | thisTime = basicHeaderObj.datatime.time() | |
|
109 | ||
|
110 | if not(sts): | |
|
111 | print "Skipping the file %s because it has not a valid header" %(filename) | |
|
112 | return 0 | |
|
113 | ||
|
114 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
|
115 | return 0 | |
|
116 | ||
|
117 | return 1 | |
|
118 | ||
|
77 | 119 | def getlastFileFromPath(path, ext): |
|
78 | 120 | """ |
|
79 | 121 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
@@ -97,10 +139,13 def getlastFileFromPath(path, ext): | |||
|
97 | 139 | year = int(file[1:5]) |
|
98 | 140 | doy = int(file[5:8]) |
|
99 | 141 | |
|
100 | if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue | |
|
142 | ||
|
101 | 143 | except: |
|
102 | 144 | continue |
|
103 | ||
|
145 | ||
|
146 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |
|
147 | continue | |
|
148 | ||
|
104 | 149 | validFilelist.append(file) |
|
105 | 150 | |
|
106 | 151 | if validFilelist: |
@@ -119,6 +164,8 def checkForRealPath(path, year, doy, set, ext): | |||
|
119 | 164 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
120 | 165 | |
|
121 | 166 | Entonces la funcion prueba con las siguientes combinaciones |
|
167 | .../.../y2009307367.ext | |
|
168 | .../.../Y2009307367.ext | |
|
122 | 169 | .../.../x2009307/y2009307367.ext |
|
123 | 170 | .../.../x2009307/Y2009307367.ext |
|
124 | 171 | .../.../X2009307/y2009307367.ext |
@@ -130,25 +177,30 def checkForRealPath(path, year, doy, set, ext): | |||
|
130 | 177 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
131 | 178 | para el filename |
|
132 | 179 | """ |
|
133 |
f |
|
|
180 | fullfilename = None | |
|
134 | 181 | find_flag = False |
|
135 | 182 | filename = None |
|
136 | ||
|
183 | ||
|
184 | prefixDirList = [None,'d','D'] | |
|
137 | 185 | if ext.lower() == ".r": #voltage |
|
138 | header1 = "dD" | |
|
139 | header2 = "dD" | |
|
186 | prefixFileList = ['d','D'] | |
|
140 | 187 | elif ext.lower() == ".pdata": #spectra |
|
141 | header1 = "dD" | |
|
142 | header2 = "pP" | |
|
188 | prefixFileList = ['p','P'] | |
|
143 | 189 | else: |
|
144 | 190 | return None, filename |
|
191 | ||
|
192 | #barrido por las combinaciones posibles | |
|
193 | for prefixDir in prefixDirList: | |
|
194 | thispath = path | |
|
195 | if prefixDir != None: | |
|
196 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
|
197 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |
|
198 | ||
|
199 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
|
200 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
|
201 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
|
145 | 202 | |
|
146 | for dir in header1: #barrido por las dos combinaciones posibles de "D" | |
|
147 | for fil in header2: #barrido por las dos combinaciones posibles de "D" | |
|
148 | doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
|
149 | filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
|
150 | filepath = os.path.join( path, doypath, filename ) #formo el path completo | |
|
151 | if os.path.exists( filepath ): #verifico que exista | |
|
203 | if os.path.exists( fullfilename ): #verifico que exista | |
|
152 | 204 | find_flag = True |
|
153 | 205 | break |
|
154 | 206 | if find_flag: |
@@ -157,7 +209,7 def checkForRealPath(path, year, doy, set, ext): | |||
|
157 | 209 | if not(find_flag): |
|
158 | 210 | return None, filename |
|
159 | 211 | |
|
160 |
return f |
|
|
212 | return fullfilename, filename | |
|
161 | 213 | |
|
162 | 214 | class JRODataIO: |
|
163 | 215 | |
@@ -273,54 +325,50 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
273 | 325 | startTime=datetime.time(0,0,0), |
|
274 | 326 | endTime=datetime.time(23,59,59), |
|
275 | 327 | set=None, |
|
276 |
expLabel= |
|
|
277 |
ext= |
|
|
278 | dirList = [] | |
|
279 | for thisPath in os.listdir(path): | |
|
280 | if os.path.isdir(os.path.join(path,thisPath)): | |
|
281 | dirList.append(thisPath) | |
|
282 | ||
|
283 | if not(dirList): | |
|
284 | return None, None | |
|
285 | ||
|
286 | pathList = [] | |
|
287 | dateList = [] | |
|
328 | expLabel='', | |
|
329 | ext='.r', | |
|
330 | walk=True): | |
|
288 | 331 | |
|
289 |
this |
|
|
332 | pathList = [] | |
|
290 | 333 | |
|
291 | while(thisDate <= endDate): | |
|
292 | year = thisDate.timetuple().tm_year | |
|
293 | doy = thisDate.timetuple().tm_yday | |
|
334 | if not walk: | |
|
335 | pathList.append(path) | |
|
294 | 336 | |
|
295 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
|
296 |
|
|
|
297 | thisDate += datetime.timedelta(1) | |
|
298 | continue | |
|
337 | else: | |
|
338 | dirList = [] | |
|
339 | for thisPath in os.listdir(path): | |
|
340 | if os.path.isdir(os.path.join(path,thisPath)): | |
|
341 | dirList.append(thisPath) | |
|
342 | ||
|
343 | if not(dirList): | |
|
344 | return None, None | |
|
345 | ||
|
346 | thisDate = startDate | |
|
299 | 347 | |
|
300 | pathList.append(os.path.join(path,match[0],expLabel)) | |
|
301 | dateList.append(thisDate) | |
|
302 | thisDate += datetime.timedelta(1) | |
|
348 | while(thisDate <= endDate): | |
|
349 | year = thisDate.timetuple().tm_year | |
|
350 | doy = thisDate.timetuple().tm_yday | |
|
351 | ||
|
352 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
|
353 | if len(match) == 0: | |
|
354 | thisDate += datetime.timedelta(1) | |
|
355 | continue | |
|
356 | ||
|
357 | pathList.append(os.path.join(path,match[0],expLabel)) | |
|
358 | thisDate += datetime.timedelta(1) | |
|
359 | ||
|
303 | 360 | |
|
304 | 361 | filenameList = [] |
|
305 |
for |
|
|
362 | for thisPath in pathList: | |
|
306 | 363 | |
|
307 | thisPath = pathList[index] | |
|
308 | 364 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
309 | 365 | fileList.sort() |
|
310 | 366 | |
|
311 | #Busqueda de datos en el rango de horas indicados | |
|
312 | thisDate = dateList[index] | |
|
313 | startDT = datetime.datetime.combine(thisDate, startTime) | |
|
314 | endDT = datetime.datetime.combine(thisDate, endTime) | |
|
315 | ||
|
316 | startUtSeconds = time.mktime(startDT.timetuple()) | |
|
317 | endUtSeconds = time.mktime(endDT.timetuple()) | |
|
318 | ||
|
319 | 367 | for file in fileList: |
|
320 | 368 | |
|
321 | 369 | filename = os.path.join(thisPath,file) |
|
322 | 370 | |
|
323 |
if |
|
|
371 | if isFileinThisTime(filename, startTime, endTime): | |
|
324 | 372 | filenameList.append(filename) |
|
325 | 373 | |
|
326 | 374 | if not(filenameList): |
@@ -330,7 +378,7 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
330 | 378 | |
|
331 | 379 | return pathList, filenameList |
|
332 | 380 | |
|
333 |
def __searchFilesOnLine(self, path |
|
|
381 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): | |
|
334 | 382 | |
|
335 | 383 | """ |
|
336 | 384 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
@@ -339,21 +387,11 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
339 | 387 | Input: |
|
340 | 388 | path : carpeta donde estan contenidos los files que contiene data |
|
341 | 389 | |
|
342 | startDate : Fecha inicial. Rechaza todos los directorios donde | |
|
343 | file end time < startDate (obejto datetime.date) | |
|
344 | ||
|
345 | endDate : Fecha final. Rechaza todos los directorios donde | |
|
346 | file start time > endDate (obejto datetime.date) | |
|
347 | ||
|
348 | startTime : Tiempo inicial. Rechaza todos los archivos donde | |
|
349 | file end time < startTime (obejto datetime.time) | |
|
350 | ||
|
351 | endTime : Tiempo final. Rechaza todos los archivos donde | |
|
352 | file start time > endTime (obejto datetime.time) | |
|
353 | ||
|
354 | 390 | expLabel : Nombre del subexperimento (subfolder) |
|
355 | 391 | |
|
356 |
ext : extension de los files |
|
|
392 | ext : extension de los files | |
|
393 | ||
|
394 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
|
357 | 395 | |
|
358 | 396 | Return: |
|
359 | 397 | directory : eL directorio donde esta el file encontrado |
@@ -365,60 +403,38 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
365 | 403 | |
|
366 | 404 | """ |
|
367 | 405 | dirList = [] |
|
368 | pathList = [] | |
|
369 | directory = None | |
|
370 | 406 | |
|
371 | #Filtra solo los directorios | |
|
372 | for thisPath in os.listdir(path): | |
|
373 | if os.path.isdir(os.path.join(path, thisPath)): | |
|
374 | dirList.append(thisPath) | |
|
375 | ||
|
376 | if not(dirList): | |
|
377 | return None, None, None, None, None | |
|
378 | ||
|
379 | dirList = sorted( dirList, key=str.lower ) | |
|
380 | ||
|
381 | if startDate: | |
|
382 | startDateTime = datetime.datetime.combine(startDate, startTime) | |
|
383 | thisDateTime = startDateTime | |
|
384 | if endDate == None: endDateTime = startDateTime | |
|
385 | else: endDateTime = datetime.datetime.combine(endDate, endTime) | |
|
407 | if walk: | |
|
386 | 408 | |
|
387 | while(thisDateTime <= endDateTime): | |
|
388 | year = thisDateTime.timetuple().tm_year | |
|
389 | doy = thisDateTime.timetuple().tm_yday | |
|
390 | ||
|
391 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
|
392 |
|
|
|
393 | thisDateTime += datetime.timedelta(1) | |
|
394 | continue | |
|
395 | ||
|
396 | pathList.append(os.path.join(path,match[0], expLabel)) | |
|
397 | thisDateTime += datetime.timedelta(1) | |
|
398 | ||
|
399 | if not(pathList): | |
|
400 | print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
|
409 | #Filtra solo los directorios | |
|
410 | for thisPath in os.listdir(path): | |
|
411 | if os.path.isdir(os.path.join(path, thisPath)): | |
|
412 | dirList.append(thisPath) | |
|
413 | ||
|
414 | if not(dirList): | |
|
401 | 415 | return None, None, None, None, None |
|
402 | ||
|
403 | directory = pathList[0] | |
|
404 | ||
|
416 | ||
|
417 | dirList = sorted( dirList, key=str.lower ) | |
|
418 | ||
|
419 | doypath = dirList[-1] | |
|
420 | fullpath = os.path.join(path, doypath, expLabel) | |
|
421 | ||
|
405 | 422 | else: |
|
406 | directory = dirList[-1] | |
|
407 | directory = os.path.join(path,directory) | |
|
423 | fullpath = path | |
|
408 | 424 | |
|
409 |
filename = getlastFileFromPath( |
|
|
425 | filename = getlastFileFromPath(fullpath, ext) | |
|
410 | 426 | |
|
411 | 427 | if not(filename): |
|
412 | 428 | return None, None, None, None, None |
|
413 | 429 | |
|
414 |
if not(self.__verifyFile(os.path.join( |
|
|
430 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
|
415 | 431 | return None, None, None, None, None |
|
416 | 432 | |
|
417 | 433 | year = int( filename[1:5] ) |
|
418 | 434 | doy = int( filename[5:8] ) |
|
419 | 435 | set = int( filename[8:11] ) |
|
420 | 436 | |
|
421 |
return |
|
|
437 | return fullpath, filename, year, doy, set | |
|
422 | 438 | |
|
423 | 439 | |
|
424 | 440 | |
@@ -480,9 +496,9 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
480 | 496 | self.set += 1 |
|
481 | 497 | |
|
482 | 498 | #busca el 1er file disponible |
|
483 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
|
484 | if file: | |
|
485 | if self.__verifyFile(file, False): | |
|
499 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
|
500 | if fullfilename: | |
|
501 | if self.__verifyFile(fullfilename, False): | |
|
486 | 502 | fileOk_flag = True |
|
487 | 503 | |
|
488 | 504 | #si no encuentra un file entonces espera y vuelve a buscar |
@@ -501,9 +517,9 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
501 | 517 | else: |
|
502 | 518 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
503 | 519 | |
|
504 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
|
505 | if file: | |
|
506 | if self.__verifyFile(file): | |
|
520 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
|
521 | if fullfilename: | |
|
522 | if self.__verifyFile(fullfilename): | |
|
507 | 523 | fileOk_flag = True |
|
508 | 524 | break |
|
509 | 525 | |
@@ -520,13 +536,13 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
520 | 536 | self.doy += 1 |
|
521 | 537 | |
|
522 | 538 | if fileOk_flag: |
|
523 | self.fileSize = os.path.getsize( file ) | |
|
524 | self.filename = file | |
|
539 | self.fileSize = os.path.getsize( fullfilename ) | |
|
540 | self.filename = fullfilename | |
|
525 | 541 | self.flagIsNewFile = 1 |
|
526 | 542 | if self.fp != None: self.fp.close() |
|
527 | self.fp = open(file, 'rb') | |
|
543 | self.fp = open(fullfilename, 'rb') | |
|
528 | 544 | self.flagNoMoreFiles = 0 |
|
529 | print 'Setting the file: %s' % file | |
|
545 | print 'Setting the file: %s' % fullfilename | |
|
530 | 546 | else: |
|
531 | 547 | self.fileSize = 0 |
|
532 | 548 | self.filename = None |
@@ -555,7 +571,11 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
555 | 571 | return 1 |
|
556 | 572 | |
|
557 | 573 | def __waitNewBlock(self): |
|
558 | #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido | |
|
574 | """ | |
|
575 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
|
576 | ||
|
577 | Si el modo de lectura es OffLine siempre retorn 0 | |
|
578 | """ | |
|
559 | 579 | if not self.online: |
|
560 | 580 | return 0 |
|
561 | 581 | |
@@ -586,6 +606,7 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
586 | 606 | return 0 |
|
587 | 607 | |
|
588 | 608 | def __setNewBlock(self): |
|
609 | ||
|
589 | 610 | if self.fp == None: |
|
590 | 611 | return 0 |
|
591 | 612 | |
@@ -738,7 +759,8 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
738 | 759 | expLabel = "", |
|
739 | 760 | ext = None, |
|
740 | 761 | online = False, |
|
741 |
delay = 60 |
|
|
762 | delay = 60, | |
|
763 | walk = True): | |
|
742 | 764 | |
|
743 | 765 | if path == None: |
|
744 | 766 | raise ValueError, "The path is not valid" |
@@ -748,17 +770,17 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
748 | 770 | |
|
749 | 771 | if online: |
|
750 | 772 | print "Searching files in online mode..." |
|
751 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) | |
|
752 | ||
|
753 | if not(doypath): | |
|
754 | for nTries in range( self.nTries ): | |
|
755 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
|
756 |
|
|
|
757 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) | |
|
758 | if doypath: | |
|
759 | break | |
|
773 | ||
|
774 | for nTries in range( self.nTries ): | |
|
775 | fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) | |
|
776 | ||
|
777 | if fullpath: | |
|
778 | break | |
|
779 | ||
|
780 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
|
781 | time.sleep( self.delay ) | |
|
760 | 782 | |
|
761 |
if not( |
|
|
783 | if not(fullpath): | |
|
762 | 784 | print "There 'isn't valied files in %s" % path |
|
763 | 785 | return None |
|
764 | 786 | |
@@ -769,7 +791,10 class JRODataReader(JRODataIO, ProcessingUnit): | |||
|
769 | 791 | |
|
770 | 792 | else: |
|
771 | 793 | print "Searching files in offline mode ..." |
|
772 |
pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, |
|
|
794 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
|
795 | startTime=startTime, endTime=endTime, | |
|
796 | set=set, expLabel=expLabel, ext=ext, | |
|
797 | walk=walk) | |
|
773 | 798 | |
|
774 | 799 | if not(pathList): |
|
775 | 800 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
@@ -1000,12 +1025,12 class JRODataWriter(JRODataIO, Operation): | |||
|
1000 | 1025 | timeTuple = time.localtime( self.dataOut.dataUtcTime) |
|
1001 | 1026 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1002 | 1027 | |
|
1003 |
|
|
|
1004 |
if not( os.path.exists( |
|
|
1005 |
os.mkdir( |
|
|
1028 | fullpath = os.path.join( path, subfolder ) | |
|
1029 | if not( os.path.exists(fullpath) ): | |
|
1030 | os.mkdir(fullpath) | |
|
1006 | 1031 | self.setFile = -1 #inicializo mi contador de seteo |
|
1007 | 1032 | else: |
|
1008 |
filesList = os.listdir( |
|
|
1033 | filesList = os.listdir( fullpath ) | |
|
1009 | 1034 | if len( filesList ) > 0: |
|
1010 | 1035 | filesList = sorted( filesList, key=str.lower ) |
|
1011 | 1036 | filen = filesList[-1] |
@@ -2433,9 +2458,9 class SpectraHeisWriter(): | |||
|
2433 | 2458 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) |
|
2434 | 2459 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) |
|
2435 | 2460 | |
|
2436 |
|
|
|
2437 |
if not( os.path.exists( |
|
|
2438 |
os.mkdir( |
|
|
2461 | fullpath = os.path.join( self.wrpath, subfolder ) | |
|
2462 | if not( os.path.exists(fullpath) ): | |
|
2463 | os.mkdir(fullpath) | |
|
2439 | 2464 | self.setFile += 1 |
|
2440 | 2465 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2441 | 2466 |
@@ -6,6 +6,7 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |||
|
6 | 6 | import sys |
|
7 | 7 | import numpy |
|
8 | 8 | import copy |
|
9 | import datetime | |
|
9 | 10 | |
|
10 | 11 | class Header: |
|
11 | 12 | |
@@ -37,6 +38,7 class BasicHeader(Header): | |||
|
37 | 38 | dstFlag = None |
|
38 | 39 | errorCount = None |
|
39 | 40 | struct = None |
|
41 | datatime = None | |
|
40 | 42 | |
|
41 | 43 | def __init__(self): |
|
42 | 44 | |
@@ -72,6 +74,7 class BasicHeader(Header): | |||
|
72 | 74 | self.dstFlag = int(header['nDstflag'][0]) |
|
73 | 75 | self.errorCount = int(header['nErrorCount'][0]) |
|
74 | 76 | |
|
77 | self.datatime = datetime.datetime.utcfromtimestamp(self.utc) | |
|
75 | 78 | except Exception, e: |
|
76 | 79 | print "BasicHeader: " + e |
|
77 | 80 | return 0 |
@@ -79,6 +79,9 class CrossSpectraPlot(Figure): | |||
|
79 | 79 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
80 | 80 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
81 | 81 | |
|
82 | if pairIndexList == []: | |
|
83 | return | |
|
84 | ||
|
82 | 85 | x = dataOut.getVelRange(1) |
|
83 | 86 | y = dataOut.getHeiRange() |
|
84 | 87 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) |
@@ -104,7 +107,7 class CrossSpectraPlot(Figure): | |||
|
104 | 107 | |
|
105 | 108 | self.__isConfig = True |
|
106 | 109 | |
|
107 |
thisDatetime = |
|
|
110 | thisDatetime = dataOut.datatime | |
|
108 | 111 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
109 | 112 | xlabel = "Velocity (m/s)" |
|
110 | 113 | ylabel = "Range (Km)" |
@@ -223,7 +226,7 class RTIPlot(Figure): | |||
|
223 | 226 | |
|
224 | 227 | def __getTimeLim(self, x, xmin, xmax): |
|
225 | 228 | |
|
226 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
|
229 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) | |
|
227 | 230 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
228 | 231 | |
|
229 | 232 | #################################################### |
@@ -284,7 +287,7 class RTIPlot(Figure): | |||
|
284 | 287 | |
|
285 | 288 | tmin = None |
|
286 | 289 | tmax = None |
|
287 |
x = dataOut.get |
|
|
290 | x = dataOut.getTimeRange() | |
|
288 | 291 | y = dataOut.getHeiRange() |
|
289 | 292 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
290 | 293 | avg = numpy.average(z, axis=1) |
@@ -308,7 +311,7 class RTIPlot(Figure): | |||
|
308 | 311 | |
|
309 | 312 | self.__isConfig = True |
|
310 | 313 | |
|
311 |
thisDatetime = |
|
|
314 | thisDatetime = dataOut.datatime | |
|
312 | 315 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
313 | 316 | xlabel = "Velocity (m/s)" |
|
314 | 317 | ylabel = "Range (Km)" |
@@ -457,7 +460,7 class SpectraPlot(Figure): | |||
|
457 | 460 | |
|
458 | 461 | self.__isConfig = True |
|
459 | 462 | |
|
460 |
thisDatetime = |
|
|
463 | thisDatetime = dataOut.datatime | |
|
461 | 464 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
462 | 465 | xlabel = "Velocity (m/s)" |
|
463 | 466 | ylabel = "Range (Km)" |
@@ -564,7 +567,7 class Scope(Figure): | |||
|
564 | 567 | self.__isConfig = True |
|
565 | 568 | |
|
566 | 569 | |
|
567 |
thisDatetime = |
|
|
570 | thisDatetime = dataOut.datatime | |
|
568 | 571 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
569 | 572 | xlabel = "Range (Km)" |
|
570 | 573 | ylabel = "Intensity" |
General Comments 0
You need to be logged in to leave comments.
Login now