@@ -83,6 +83,19 def isFileInEpoch(filename, startUTSeconds, endUTSeconds): | |||
|
83 | 83 | |
|
84 | 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 | 99 | def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): |
|
87 | 100 | """ |
|
88 | 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 | 128 | print "The file %s can't be opened" %(filename) |
|
116 | 129 | return None |
|
117 | 130 | |
|
118 |
|
|
|
119 | sts = basicHeaderObj.read(fp) | |
|
120 | fp.close() | |
|
131 | firstBasicHeaderObj = BasicHeader(LOCALTIME) | |
|
132 | systemHeaderObj = SystemHeader() | |
|
133 | radarControllerHeaderObj = RadarControllerHeader() | |
|
134 | processingHeaderObj = ProcessingHeader() | |
|
121 | 135 | |
|
122 | thisDatetime = basicHeaderObj.datatime | |
|
123 | thisDate = thisDatetime.date() | |
|
124 | thisTime = thisDatetime.time() | |
|
136 | lastBasicHeaderObj = BasicHeader(LOCALTIME) | |
|
137 | ||
|
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 | 151 | if not(sts): |
|
127 | 152 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
128 | 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 | 163 | #General case |
|
131 | 164 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o |
|
132 | 165 | #-----------o----------------------------o----------- |
|
133 | 166 | # startTime endTime |
|
134 | 167 | |
|
135 | 168 | if endTime >= startTime: |
|
136 | if (thisTime < startTime) or (thisTime > endTime): | |
|
169 | if (thisTime_last_block < startTime) or (thisTime_first_block > endTime): | |
|
137 | 170 | return None |
|
138 | 171 | |
|
139 | 172 | return thisDatetime |
@@ -145,13 +178,13 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
145 | 178 | #-----------o----------------------------o----------- |
|
146 | 179 | # endTime startTime |
|
147 | 180 | |
|
148 | if (thisDate == startDate) and (thisTime < startTime): | |
|
181 | if (thisDate == startDate) and (thisTime_last_block < startTime): | |
|
149 | 182 | return None |
|
150 | 183 | |
|
151 | if (thisDate == endDate) and (thisTime > endTime): | |
|
184 | if (thisDate == endDate) and (thisTime_first_block > endTime): | |
|
152 | 185 | return None |
|
153 | 186 | |
|
154 | if (thisTime < startTime) and (thisTime > endTime): | |
|
187 | if (thisTime_last_block < startTime) and (thisTime_first_block > endTime): | |
|
155 | 188 | return None |
|
156 | 189 | |
|
157 | 190 | return thisDatetime |
@@ -567,16 +600,13 class JRODataReader(JRODataIO): | |||
|
567 | 600 | dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True) |
|
568 | 601 | |
|
569 | 602 | if dateList == []: |
|
570 |
# print "[Reading] No *%s files in %s |
|
|
571 | # datetime.datetime.combine(startDate,startTime).ctime(), | |
|
572 | # datetime.datetime.combine(endDate,endTime).ctime()) | |
|
573 | ||
|
603 | # print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path) | |
|
574 | 604 | return None, None |
|
575 | 605 | |
|
576 | 606 | if len(dateList) > 1: |
|
577 |
print "[Reading] Data found |
|
|
607 | print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList)) | |
|
578 | 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 | 611 | filenameList = [] |
|
582 | 612 | datetimeList = [] |
@@ -603,7 +633,7 class JRODataReader(JRODataIO): | |||
|
603 | 633 | datetimeList.append(thisDatetime) |
|
604 | 634 | |
|
605 | 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 | 637 | return None, None |
|
608 | 638 | |
|
609 | 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 | 1000 | def readNextBlock(self): |
|
971 | 1001 | |
|
972 | if not(self.__setNewBlock()): | |
|
973 | return 0 | |
|
974 | ||
|
975 | if not(self.readBlock()): | |
|
976 | return 0 | |
|
1002 | #Skip block out of startTime and endTime | |
|
1003 | while True: | |
|
1004 | if not(self.__setNewBlock()): | |
|
1005 | 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 | 1021 | print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, |
|
981 | 1022 | self.processingHeaderObj.dataBlocksPerFile, |
@@ -1070,6 +1111,8 class JRODataReader(JRODataIO): | |||
|
1070 | 1111 | |
|
1071 | 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 | 1116 | dateList = [] |
|
1074 | 1117 | pathList = [] |
|
1075 | 1118 | |
@@ -1087,6 +1130,8 class JRODataReader(JRODataIO): | |||
|
1087 | 1130 | if not fileList: |
|
1088 | 1131 | continue |
|
1089 | 1132 | |
|
1133 | path_empty = False | |
|
1134 | ||
|
1090 | 1135 | fileList.sort() |
|
1091 | 1136 | |
|
1092 | 1137 | for thisFile in fileList: |
@@ -1139,9 +1184,11 class JRODataReader(JRODataIO): | |||
|
1139 | 1184 | datapath = os.path.join(single_path, thisDir, expLabel) |
|
1140 | 1185 | fileList = glob.glob1(datapath, "*"+ext) |
|
1141 | 1186 | |
|
1142 |
if |
|
|
1187 | if not fileList: | |
|
1143 | 1188 | continue |
|
1144 | 1189 | |
|
1190 | path_empty = False | |
|
1191 | ||
|
1145 | 1192 | thisDate = getDateFromRadarFolder(thisDir) |
|
1146 | 1193 | |
|
1147 | 1194 | pathList.append(datapath) |
@@ -1154,9 +1201,12 class JRODataReader(JRODataIO): | |||
|
1154 | 1201 | else: |
|
1155 | 1202 | pattern_path = multi_path[0] |
|
1156 | 1203 | |
|
1157 |
if |
|
|
1158 |
print "[Reading] No *%s files in %s f |
|
|
1159 | ||
|
1204 | if path_empty: | |
|
1205 | print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate) | |
|
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 | 1210 | if include_path: |
|
1161 | 1211 | return dateList, pathList |
|
1162 | 1212 | |
@@ -1240,6 +1290,8 class JRODataReader(JRODataIO): | |||
|
1240 | 1290 | self.ext = ext |
|
1241 | 1291 | self.getByBlock = getblock |
|
1242 | 1292 | self.nTxs = nTxs |
|
1293 | self.startTime = startTime | |
|
1294 | self.endTime = endTime | |
|
1243 | 1295 | |
|
1244 | 1296 | if not(self.setNextFile()): |
|
1245 | 1297 | if (startDate!=None) and (endDate!=None): |
General Comments 0
You need to be logged in to leave comments.
Login now