##// END OF EJS Templates
Filtering block by time
Miguel Valdez -
r759:7c9c0d91a0d5
parent child
Show More
@@ -83,6 +83,19 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
83
83
84 return 1
84 return 1
85
85
86 def isTimeInRange(thisTime, startTime, endTime):
87
88 if endTime >= startTime:
89 if (thisTime < startTime) or (thisTime > endTime):
90 return 0
91
92 return 1
93 else:
94 if (thisTime < startTime) and (thisTime > endTime):
95 return 0
96
97 return 1
98
86 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
99 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
87 """
100 """
88 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
101 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
@@ -115,25 +128,45 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
115 print "The file %s can't be opened" %(filename)
128 print "The file %s can't be opened" %(filename)
116 return None
129 return None
117
130
118 basicHeaderObj = BasicHeader(LOCALTIME)
131 firstBasicHeaderObj = BasicHeader(LOCALTIME)
119 sts = basicHeaderObj.read(fp)
132 systemHeaderObj = SystemHeader()
120 fp.close()
133 radarControllerHeaderObj = RadarControllerHeader()
134 processingHeaderObj = ProcessingHeader()
121
135
122 thisDatetime = basicHeaderObj.datatime
136 lastBasicHeaderObj = BasicHeader(LOCALTIME)
123 thisDate = thisDatetime.date()
137
124 thisTime = thisDatetime.time()
138 sts = firstBasicHeaderObj.read(fp)
139 sts = systemHeaderObj.read(fp)
140 sts = radarControllerHeaderObj.read(fp)
141 sts = processingHeaderObj.read(fp)
142
143 offset = processingHeaderObj.blockSize + 24 #header size
144
145 fp.seek(-offset, 2)
146
147 sts = lastBasicHeaderObj.read(fp)
148
149 fp.close()
125
150
126 if not(sts):
151 if not(sts):
127 print "Skipping the file %s because it has not a valid header" %(filename)
152 print "Skipping the file %s because it has not a valid header" %(filename)
128 return None
153 return None
129
154
155 thisDatetime = firstBasicHeaderObj.datatime
156 thisDate = thisDatetime.date()
157 thisTime_first_block = thisDatetime.time()
158
159 thisDatetime = lastBasicHeaderObj.datatime
160 thisTime_last_block = thisDatetime.time()
161
162
130 #General case
163 #General case
131 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
164 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
132 #-----------o----------------------------o-----------
165 #-----------o----------------------------o-----------
133 # startTime endTime
166 # startTime endTime
134
167
135 if endTime >= startTime:
168 if endTime >= startTime:
136 if (thisTime < startTime) or (thisTime > endTime):
169 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
137 return None
170 return None
138
171
139 return thisDatetime
172 return thisDatetime
@@ -145,13 +178,13 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
145 #-----------o----------------------------o-----------
178 #-----------o----------------------------o-----------
146 # endTime startTime
179 # endTime startTime
147
180
148 if (thisDate == startDate) and (thisTime < startTime):
181 if (thisDate == startDate) and (thisTime_last_block < startTime):
149 return None
182 return None
150
183
151 if (thisDate == endDate) and (thisTime > endTime):
184 if (thisDate == endDate) and (thisTime_first_block > endTime):
152 return None
185 return None
153
186
154 if (thisTime < startTime) and (thisTime > endTime):
187 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
155 return None
188 return None
156
189
157 return thisDatetime
190 return thisDatetime
@@ -567,16 +600,13 class JRODataReader(JRODataIO):
567 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
600 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
568
601
569 if dateList == []:
602 if dateList == []:
570 # print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
603 # print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
571 # datetime.datetime.combine(startDate,startTime).ctime(),
572 # datetime.datetime.combine(endDate,endTime).ctime())
573
574 return None, None
604 return None, None
575
605
576 if len(dateList) > 1:
606 if len(dateList) > 1:
577 print "[Reading] Data found: total days = %d, date range = %s - %s" %(len(dateList), startDate, endDate)
607 print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList))
578 else:
608 else:
579 print "[Reading] Data found: date = %s" %(dateList[0])
609 print "[Reading] Data found for date range [%s - %s]: date = %s" %(startDate, endDate, dateList[0])
580
610
581 filenameList = []
611 filenameList = []
582 datetimeList = []
612 datetimeList = []
@@ -603,7 +633,7 class JRODataReader(JRODataIO):
603 datetimeList.append(thisDatetime)
633 datetimeList.append(thisDatetime)
604
634
605 if not(filenameList):
635 if not(filenameList):
606 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
636 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" %(startTime, endTime, ext, path)
607 return None, None
637 return None, None
608
638
609 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
639 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
@@ -969,13 +999,24 class JRODataReader(JRODataIO):
969
999
970 def readNextBlock(self):
1000 def readNextBlock(self):
971
1001
972 if not(self.__setNewBlock()):
1002 #Skip block out of startTime and endTime
973 return 0
1003 while True:
974
1004 if not(self.__setNewBlock()):
975 if not(self.readBlock()):
1005 return 0
976 return 0
1006
1007 if not(self.readBlock()):
1008 return 0
1009
1010 self.getBasicHeader()
977
1011
978 self.getBasicHeader()
1012 if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime):
1013
1014 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1015 self.processingHeaderObj.dataBlocksPerFile,
1016 self.dataOut.datatime.ctime())
1017 continue
1018
1019 break
979
1020
980 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1021 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
981 self.processingHeaderObj.dataBlocksPerFile,
1022 self.processingHeaderObj.dataBlocksPerFile,
@@ -1070,6 +1111,8 class JRODataReader(JRODataIO):
1070
1111
1071 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1112 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1072
1113
1114 path_empty = True
1115
1073 dateList = []
1116 dateList = []
1074 pathList = []
1117 pathList = []
1075
1118
@@ -1087,6 +1130,8 class JRODataReader(JRODataIO):
1087 if not fileList:
1130 if not fileList:
1088 continue
1131 continue
1089
1132
1133 path_empty = False
1134
1090 fileList.sort()
1135 fileList.sort()
1091
1136
1092 for thisFile in fileList:
1137 for thisFile in fileList:
@@ -1139,9 +1184,11 class JRODataReader(JRODataIO):
1139 datapath = os.path.join(single_path, thisDir, expLabel)
1184 datapath = os.path.join(single_path, thisDir, expLabel)
1140 fileList = glob.glob1(datapath, "*"+ext)
1185 fileList = glob.glob1(datapath, "*"+ext)
1141
1186
1142 if len(fileList) < 1:
1187 if not fileList:
1143 continue
1188 continue
1144
1189
1190 path_empty = False
1191
1145 thisDate = getDateFromRadarFolder(thisDir)
1192 thisDate = getDateFromRadarFolder(thisDir)
1146
1193
1147 pathList.append(datapath)
1194 pathList.append(datapath)
@@ -1154,9 +1201,12 class JRODataReader(JRODataIO):
1154 else:
1201 else:
1155 pattern_path = multi_path[0]
1202 pattern_path = multi_path[0]
1156
1203
1157 if not dateList:
1204 if path_empty:
1158 print "[Reading] No *%s files in %s from %s to %s" %(ext, pattern_path, startDate, endDate)
1205 print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate)
1159
1206 else:
1207 if not dateList:
1208 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
1209
1160 if include_path:
1210 if include_path:
1161 return dateList, pathList
1211 return dateList, pathList
1162
1212
@@ -1240,6 +1290,8 class JRODataReader(JRODataIO):
1240 self.ext = ext
1290 self.ext = ext
1241 self.getByBlock = getblock
1291 self.getByBlock = getblock
1242 self.nTxs = nTxs
1292 self.nTxs = nTxs
1293 self.startTime = startTime
1294 self.endTime = endTime
1243
1295
1244 if not(self.setNextFile()):
1296 if not(self.setNextFile()):
1245 if (startDate!=None) and (endDate!=None):
1297 if (startDate!=None) and (endDate!=None):
General Comments 0
You need to be logged in to leave comments. Login now