##// END OF EJS Templates
Miguel Valdez -
r11:0b04e9cb0675
parent child
Show More
@@ -0,0 +1,17
1 '''
2 Created on Feb 7, 2012
3
4 @author: roj-idl71
5 '''
6
7 class VoltagePlot(object):
8 '''
9 classdocs
10 '''
11
12
13 def __init__(self):
14 '''
15 Constructor
16 '''
17 pass No newline at end of file
@@ -1,213 +1,227
1 import numpy
1 import numpy
2 import plplot
2 import plplot
3
3
4 from BasicGraph import *
4 from BasicGraph import *
5
5
6 class Spectrum:
6 class Spectrum:
7
7
8 graphObjDict = {}
8 graphObjDict = {}
9 showColorbar = False
9 showColorbar = False
10 showPowerProfile = True
10 showPowerProfile = True
11
11
12 __szchar = 0.7
12 __szchar = 0.7
13 __xrange = None
14 __yrange = None
15 __zrange = None
16 specObj = BasicGraph()
17
13
18
14 def __init__(self):
19 def __init__(self):
15
20
16 key = "spec"
21 key = "spec"
17
22
18 specObj = BasicGraph()
23 specObj = BasicGraph()
19 specObj.setName(key)
24 specObj.setName(key)
20
25
21 self.graphObjDict[key] = specObj
26 self.graphObjDict[key] = specObj
22
27
23
28
24 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False):
29 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False):
25 """
30 """
26 """
31 """
27
32
28 xi = 0.12; xw = 0.78; xf = xi + xw
33 xi = 0.12; xw = 0.78; xf = xi + xw
29 yi = 0.14; yw = 0.80; yf = yi + yw
34 yi = 0.14; yw = 0.80; yf = yi + yw
30
35
31 xcmapi = xcmapf = 0.; xpowi = xpowf = 0.
36 xcmapi = xcmapf = 0.; xpowi = xpowf = 0.
32
37
33 key = "spec"
38 key = "spec"
34 specObj = self.graphObjDict[key]
39 specObj = self.graphObjDict[key]
35 specObj.setSubpage(subpage)
40 specObj.setSubpage(subpage)
36 specObj.setSzchar(self.__szchar)
41 specObj.setSzchar(self.__szchar)
37 specObj.setOpt("bcnts","bcnts")
42 specObj.setOpt("bcnts","bcnts")
38 specObj.setup(title,
43 specObj.setup(title,
39 xlabel,
44 xlabel,
40 ylabel,
45 ylabel,
41 colormap)
46 colormap)
42
47
43 if showColorbar:
48 if showColorbar:
44 key = "colorbar"
49 key = "colorbar"
45
50
46 cmapObj = BasicGraph()
51 cmapObj = BasicGraph()
47 cmapObj.setName(key)
52 cmapObj.setName(key)
48 cmapObj.setSubpage(subpage)
53 cmapObj.setSubpage(subpage)
49 cmapObj.setSzchar(self.__szchar)
54 cmapObj.setSzchar(self.__szchar)
50 cmapObj.setOpt("bc","bcmt")
55 cmapObj.setOpt("bc","bcmt")
51 cmapObj.setup(title="dBs",
56 cmapObj.setup(title="dBs",
52 xlabel="",
57 xlabel="",
53 ylabel="",
58 ylabel="",
54 colormap=colormap)
59 colormap=colormap)
55
60
56 self.graphObjDict[key] = cmapObj
61 self.graphObjDict[key] = cmapObj
57
62
58 xcmapi = 0.
63 xcmapi = 0.
59 xcmapw = 0.05
64 xcmapw = 0.05
60 xw -= xcmapw
65 xw -= xcmapw
61
66
62 if showPowerProfile:
67 if showPowerProfile:
63 key = "powerprof"
68 key = "powerprof"
64
69
65 powObj = BasicGraph()
70 powObj = BasicGraph()
66 powObj.setName(key)
71 powObj.setName(key)
67 powObj.setSubpage(subpage)
72 powObj.setSubpage(subpage)
68 powObj.setSzchar(self.__szchar)
73 powObj.setSzchar(self.__szchar)
69 plplot.pllsty(2)
74 plplot.pllsty(2)
70 powObj.setOpt("bcntg","bc")
75 powObj.setOpt("bcntg","bc")
71 plplot.pllsty(1)
76 plplot.pllsty(1)
72 powObj.setup(title="Power Profile",
77 powObj.setup(title="Power Profile",
73 xlabel="dBs",
78 xlabel="dBs",
74 ylabel="")
79 ylabel="")
75
80
76 self.graphObjDict[key] = powObj
81 self.graphObjDict[key] = powObj
77
82
78 xpowi = 0.
83 xpowi = 0.
79 xpoww = 0.24
84 xpoww = 0.24
80 xw -= xpoww
85 xw -= xpoww
81
86
82 xf = xi + xw
87 xf = xi + xw
83 yf = yi + yw
88 yf = yi + yw
84 xcmapf = xf
89 xcmapf = xf
85
90
86 specObj.setScreenPos([xi, xf], [yi, yf])
91 specObj.setScreenPos([xi, xf], [yi, yf])
87
92
88 if showColorbar:
93 if showColorbar:
89 xcmapi = xf + 0.02
94 xcmapi = xf + 0.02
90 xcmapf = xcmapi + xcmapw
95 xcmapf = xcmapi + xcmapw
91 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
96 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
92
97
93 if showPowerProfile:
98 if showPowerProfile:
94 xpowi = xcmapf + 0.06
99 xpowi = xcmapf + 0.06
95 xpowf = xpowi + xpoww
100 xpowf = xpowi + xpoww
96 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
101 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
97
102
98
103
99 # specObj.initSubpage()
104 # specObj.initSubpage()
100 #
105 #
101 # if showColorbar:
106 # if showColorbar:
102 # cmapObj.initPlot()
107 # cmapObj.initPlot()
103 #
108 #
104 # if showPowerProfile:
109 # if showPowerProfile:
105 # powObj.initPlot()
110 # powObj.initPlot()
106
111
107 self.showColorbar = showColorbar
112 self.showColorbar = showColorbar
108 self.showPowerProfile = showPowerProfile
113 self.showPowerProfile = showPowerProfile
109
114
110 def setRanges(self, xrange, yrange, zrange):
115 def setRanges(self, xrange, yrange, zrange):
111
116
112 key = "spec"
117 key = "spec"
113 specObj = self.graphObjDict[key]
118 specObj = self.graphObjDict[key]
114 specObj.setRanges(xrange, yrange, zrange)
119 specObj.setRanges(xrange, yrange, zrange)
115
120
116 keyList = self.graphObjDict.keys()
121 keyList = self.graphObjDict.keys()
117
122
118 key = "colorbar"
123 key = "colorbar"
119 if key in keyList:
124 if key in keyList:
120 cmapObj = self.graphObjDict[key]
125 cmapObj = self.graphObjDict[key]
121 cmapObj.setRanges([0., 1.], zrange)
126 cmapObj.setRanges([0., 1.], zrange)
122
127
123 key = "powerprof"
128 key = "powerprof"
124 if key in keyList:
129 if key in keyList:
125 powObj = self.graphObjDict[key]
130 powObj = self.graphObjDict[key]
126 powObj.setRanges(zrange, yrange)
131 powObj.setRanges(zrange, yrange)
127
132
128 def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
133 def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
129
134
130 key = "spec"
135 key = "spec"
131 specObj = self.graphObjDict[key]
136 specObj = self.graphObjDict[key]
132 specObj.initSubpage()
137 specObj.initSubpage()
133
138
134 if xmin == None:
139 if xmin == None:
135 xmin = 0.
140 xmin = 0.
136
141
137 if xmax == None:
142 if xmax == None:
138 xmax = 1.
143 xmax = 1.
139
144
140 if ymin == None:
145 if ymin == None:
141 ymin = 0.
146 ymin = 0.
142
147
143 if ymax == None:
148 if ymax == None:
144 ymax = 1.
149 ymax = 1.
145
150
146 if zmin == None:
151 if zmin == None:
147 zmin = numpy.nanmin(data)
152 zmin = numpy.nanmin(data)
148
153
149 if zmax == None:
154 if zmax == None:
150 zmax = numpy.nanmax(data)
155 zmax = numpy.nanmax(data)
151
156
152 if not(specObj.hasRange):
157 if not(specObj.hasRange):
153 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
158 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
154
159
155 specObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, specObj.zrange[0], specObj.zrange[1])
160 specObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, specObj.zrange[0], specObj.zrange[1])
156
161
157 if self.showColorbar:
162 if self.showColorbar:
158 key = "colorbar"
163 key = "colorbar"
159 cmapObj = self.graphObjDict[key]
164 cmapObj = self.graphObjDict[key]
160 cmapObj.colorbarPlot()
165 cmapObj.colorbarPlot()
161
166
162 if self.showPowerProfile:
167 if self.showPowerProfile:
163 power = numpy.average(data, axis=1)
168 power = numpy.average(data, axis=1)
164
169
165 step = (ymax - ymin)/(power.shape[0]-1)
170 step = (ymax - ymin)/(power.shape[0]-1)
166 heis = numpy.arange(ymin, ymax + step, step)
171 heis = numpy.arange(ymin, ymax + step, step)
167
172
168 key = "powerprof"
173 key = "powerprof"
169 powObj = self.graphObjDict[key]
174 powObj = self.graphObjDict[key]
170 powObj.basicXYPlot(power, heis)
175 powObj.basicXYPlot(power, heis)
171
176
172 class CrossSpectrum:
177 class CrossSpectrum:
173 graphObjDict = {}
178 graphObjDict = {}
174 showColorbar = False
179 showColorbar = False
175 showPowerProfile = True
180 showPowerProfile = True
176
181
177 __szchar = 0.7
182 __szchar = 0.7
183 __showPhase = False
184 __xrange = None
185 __yrange = None
186 __zrange = None
187 m_BasicGraph= BasicGraph()
188
178 def __init__(self):
189 def __init__(self):
179 pass
190 pass
180
191
181 def setup(self):
192 def setup(self, subpage, title, xlabel, ylabel, colormap, showColorbar, showPowerProfile):
182 pass
193 pass
183
194
184 def plotData(self):
195 def setRanges(self, xrange, yrange, zrange):
196 pass
197
198 def plotData(self, data, xmin, xmax, ymin, ymax, zmin, zmax):
185 pass
199 pass
186
200
187 if __name__ == '__main__':
201 if __name__ == '__main__':
188
202
189 import numpy
203 import numpy
190 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
204 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
191 plplot.plsdev("xcairo")
205 plplot.plsdev("xcairo")
192 plplot.plscolbg(255,255,255)
206 plplot.plscolbg(255,255,255)
193 plplot.plscol0(1,0,0,0)
207 plplot.plscol0(1,0,0,0)
194 plplot.plinit()
208 plplot.plinit()
195 plplot.plssub(2, 2)
209 plplot.plssub(2, 2)
196
210
197 nx = 64
211 nx = 64
198 ny = 100
212 ny = 100
199
213
200 data = numpy.random.uniform(-50,50,(nx,ny))
214 data = numpy.random.uniform(-50,50,(nx,ny))
201
215
202 specObj = Spectrum()
216 specObj = Spectrum()
203 specObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False)
217 specObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False)
204 specObj.plotData(data)
218 specObj.plotData(data)
205
219
206 data = numpy.random.uniform(-50,50,(nx,ny))
220 data = numpy.random.uniform(-50,50,(nx,ny))
207
221
208 spec2Obj = Spectrum()
222 spec2Obj = Spectrum()
209 spec2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True)
223 spec2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True)
210 spec2Obj.plotData(data)
224 spec2Obj.plotData(data)
211
225
212 plplot.plend()
226 plplot.plend()
213 exit(0) No newline at end of file
227 exit(0)
@@ -1,31 +1,34
1 '''
1 '''
2 Created on 23/01/2012
2 Created on 23/01/2012
3
3
4 @author: danielangelsuarezmunoz
4 @author: danielangelsuarezmunoz
5 '''
5 '''
6
6
7 import VoltageReader
7 import Voltage
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 objReader = VoltageReader.VoltageReader()
11 objReader = Voltage.VoltageReader()
12
12
13 path = '/Users/danielangelsuarezmunoz/Documents/Projects'
13
14 startDateTime = datetime.datetime(2007,1,1,16,0,0)
14 path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/'
15 endDateTime = datetime.datetime(2007,12,1,17,1,0)
15 startDateTime = datetime.datetime(2011,3,11,16,0,0)
16 endDateTime = datetime.datetime(2011,3,11,20,1,0)
16 set = None
17 set = None
17 expLabel = ''
18 expLabel = ''
18 ext = '*.r'
19 ext = '*.r'
19
20
20 t0 = time.time()
21 t0 = time.time()
21 objReader.setup(path, startDateTime, endDateTime, set, expLabel, ext)
22 objReader.setup(path, startDateTime, endDateTime)
22 print time.time() - t0
23 #print time.time() - t0
23
24
24
25
25 while(not(objReader.noMoreFiles)):
26 while(not(objReader.noMoreFiles)):
26
27
27 objReader.getData()
28 objReader.getData()
29 # if objReader.flagIsNewFile:
30 # print objReader.m_BasicHeader.dataBlock
28 #print objReader.objStructShortHeader.dataBlock
31 #print objReader.objStructShortHeader.dataBlock
29 #print time.localtime(objReader.objStructShortHeader.universalTime)
32 #print time.localtime(objReader.m_BasicHeader.utc)
30
33
31 No newline at end of file
34
@@ -1,414 +1,425
1 '''
1 '''
2 Created on 23/01/2012
2 Created on 23/01/2012
3
3
4 @author: danielangelsuarezmunoz
4 @author: danielangelsuarezmunoz
5 '''
5 '''
6
6
7
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10 import glob
10 import glob
11 import fnmatch
11 import fnmatch
12 import time
12 import time
13 import datetime
13 import datetime
14
14
15 from Header import *
15 from Header import *
16 from Data import DataReader
16 from Data import DataReader
17 from Data import DataWriter
17 from Data import DataWriter
18
18
19 path = os.path.split(os.getcwd())[0]
19 path = os.path.split(os.getcwd())[0]
20 sys.path.append(os.path.join(path,"Model"))
20 sys.path.append(path)
21
21
22 from Voltage import Voltage
22 from Model.Voltage import Voltage
23
23
24 class VoltageReader(DataReader):
24 class VoltageReader(DataReader):
25
25
26 __idFile = 0
26 __idFile = None
27
27
28 __fp = 0
28 __fp = None
29
29
30 __startDateTime = 0
30 __startDateTime = None
31
31
32 __endDateTime = 0
32 __endDateTime = None
33
33
34 __dataType = 0
34 __dataType = None
35
35
36 __sizeOfFileByHeader = 0
36 __fileSizeByHeader = 0
37
37
38 __pathList = []
38 __pathList = []
39
39
40 filenameList = []
40 filenameList = []
41
41
42 __lastUTTime = 0
42 __lastUTTime = 0
43
43
44 __maxTimeStep = 5
44 __maxTimeStep = 5
45
45
46 flagResetProcessing = 0
46 flagResetProcessing = 0
47
47
48 __flagIsNewFile = 0
48 __flagIsNewFile = 0
49
49
50 noMoreFiles = 0
50 noMoreFiles = 0
51
51
52 online = 0
52 online = 0
53
53
54 filename = ''
54 filename = None
55
55
56 fileSize = 0
56 fileSize = None
57
57
58 firstHeaderSize = 0
58 firstHeaderSize = 0
59
59
60 basicHeaderSize = 24
60 basicHeaderSize = 24
61
61
62 m_BasicHeader = BasicHeader()
62 m_BasicHeader = BasicHeader()
63
63
64 m_SystemHeader = SystemHeader()
64 m_SystemHeader = SystemHeader()
65
65
66 m_RadarControllerHeader = RadarControllerHeader()
66 m_RadarControllerHeader = RadarControllerHeader()
67
67
68 m_ProcessingHeader = ProcessingHeader()
68 m_ProcessingHeader = ProcessingHeader()
69
69
70 m_Voltage = None
70 m_Voltage = None
71
71
72 __buffer = 0
72 __buffer = 0
73
73
74 __buffer_id = 9999
74 __buffer_id = 9999
75
75
76 def __init__(self, m_Voltage):
76 def __init__(self, m_Voltage = None):
77
77
78 if m_Voltage == None:
79 m_Voltage = Voltage()
80
78 self.m_Voltage = m_Voltage
81 self.m_Voltage = m_Voltage
79
82
80 def __rdSystemHeader(self,fp=None):
83 def __rdSystemHeader(self,fp=None):
81 if fp == None:
84 if fp == None:
82 fp = self.__fp
85 fp = self.__fp
83
86
84 self.m_SystemHeader.read(fp)
87 self.m_SystemHeader.read(fp)
85
88
86 def __rdRadarControllerHeader(self,fp=None):
89 def __rdRadarControllerHeader(self,fp=None):
87 if fp == None:
90 if fp == None:
88 fp = self.__fp
91 fp = self.__fp
89
92
90 self.m_RadarControllerHeader.read(fp)
93 self.m_RadarControllerHeader.read(fp)
91
94
92 def __rdProcessingHeader(self,fp=None):
95 def __rdProcessingHeader(self,fp=None):
93 if fp == None:
96 if fp == None:
94 fp = self.__fp
97 fp = self.__fp
95
98
96 self.m_ProcessingHeader.read(fp)
99 self.m_ProcessingHeader.read(fp)
97
100
98 def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = "*.r"):
101 def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"):
102
103 print "Searching files ..."
99
104
100 startUtSeconds = time.mktime(startDateTime.timetuple())
105 startUtSeconds = time.mktime(startDateTime.timetuple())
101 endUtSeconds = time.mktime(endDateTime.timetuple())
106 endUtSeconds = time.mktime(endDateTime.timetuple())
102
107
103 startYear = startDateTime.timetuple().tm_year
108 startYear = startDateTime.timetuple().tm_year
104 endYear = endDateTime.timetuple().tm_year
109 endYear = endDateTime.timetuple().tm_year
105
110
106 startDoy = startDateTime.timetuple().tm_yday
111 startDoy = startDateTime.timetuple().tm_yday
107 endDoy = endDateTime.timetuple().tm_yday
112 endDoy = endDateTime.timetuple().tm_yday
108
113
109 rangeOfYears = range(startYear,endYear+1)
114 yearRange = range(startYear,endYear+1)
110
115
111 listOfListDoys = []
116 doyDoubleList = []
112 if startYear == endYear:
117 if startYear == endYear:
113 doyList = range(startDoy,endDoy+1)
118 doyList = range(startDoy,endDoy+1)
114 else:
119 else:
115 for year in rangeOfYears:
120 for year in yearRange:
116 if (year == startYear):
121 if (year == startYear):
117 listOfListDoys.append(range(startDoy,365+1))
122 doyDoubleList.append(range(startDoy,365+1))
118 elif (year == endYear):
123 elif (year == endYear):
119 listOfListDoys.append(range(1,endDoy+1))
124 doyDoubleList.append(range(1,endDoy+1))
120 else:
125 else:
121 listOfListDoys.append(range(1,365+1))
126 doyDoubleList.append(range(1,365+1))
122 doyList = []
127 doyList = []
123 for list in listOfListDoys:
128 for list in doyDoubleList:
124 doyList = doyList + list
129 doyList = doyList + list
125
130
126 folders = []
131 doyPathList = []
127 for thisPath in os.listdir(path):
132 for thisPath in os.listdir(path):
128 if os.path.isdir(os.path.join(path,thisPath)):
133 if os.path.isdir(os.path.join(path,thisPath)):
129 #folders.append(os.path.join(path,thisPath))
134 #doyPathList.append(os.path.join(path,thisPath))
130 folders.append(thisPath)
135 doyPathList.append(thisPath)
131
136
132 pathList = []
137 pathList = []
133 dicOfPath = {}
138 pathDict = {}
134 for year in rangeOfYears:
139 for year in yearRange:
135 for doy in doyList:
140 for doy in doyList:
136 tmp = fnmatch.filter(folders, 'D' + '%4.4d%3.3d' % (year,doy))
141 match = fnmatch.filter(doyPathList, 'D' + '%4.4d%3.3d' % (year,doy))
137 if len(tmp) == 0:
142 if len(match) == 0:
138 continue
143 match = fnmatch.filter(doyPathList, 'd' + '%4.4d%3.3d' % (year,doy))
144 if len(match) == 0: continue
139 if expLabel == '':
145 if expLabel == '':
140 pathList.append(os.path.join(path,tmp[0]))
146 pathList.append(os.path.join(path,match[0]))
141 dicOfPath.setdefault(os.path.join(path,tmp[0]))
147 pathDict.setdefault(os.path.join(path,match[0]))
142 dicOfPath[os.path.join(path,tmp[0])] = []
148 pathDict[os.path.join(path,match[0])] = []
143 else:
149 else:
144 pathList.append(os.path.join(path,os.path.join(tmp[0],expLabel)))
150 pathList.append(os.path.join(path,os.path.join(match[0],expLabel)))
145 dicOfPath.setdefault(os.path.join(path,os.path.join(tmp[0],expLabel)))
151 pathDict.setdefault(os.path.join(path,os.path.join(match[0],expLabel)))
146 dicOfPath[os.path.join(path,os.path.join(tmp[0],expLabel))] = []
152 pathDict[os.path.join(path,os.path.join(match[0],expLabel))] = []
147
153
148
154
149 filenameList = []
155 filenameList = []
150 for thisPath in pathList:
156 for thisPath in pathList:
151 fileList = glob.glob1(thisPath, ext)
157 fileList = glob.glob1(thisPath, "*%s" %ext)
152 #dicOfPath[thisPath].append(fileList)
158 #pathDict[thisPath].append(fileList)
153 fileList.sort()
159 fileList.sort()
154 for file in fileList:
160 for file in fileList:
155 filename = os.path.join(thisPath,file)
161 filename = os.path.join(thisPath,file)
156 if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds):
162 if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds):
157 filenameList.append(filename)
163 filenameList.append(filename)
158
164
159 self.filenameList = filenameList
165 self.filenameList = filenameList
160
166
161 return pathList, filenameList
167 return pathList, filenameList
162
168
163 def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None):
169 def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None):
164
170
165 try:
171 try:
166 fp = open(filename,'rb')
172 fp = open(filename,'rb')
167 except:
173 except:
168 raise IOError, "The file %s can't be opened" %(filename)
174 raise IOError, "The file %s can't be opened" %(filename)
169
175
170 if startUTSeconds==None:
176 if startUTSeconds==None:
171 startUTSeconds = self.startUTCSeconds
177 startUTSeconds = self.startUTCSeconds
172
178
173 if endUTSeconds==None:
179 if endUTSeconds==None:
174 endUTSeconds = self.endUTCSeconds
180 endUTSeconds = self.endUTCSeconds
175
181
176 m_BasicHeader = BasicHeader()
182 m_BasicHeader = BasicHeader()
177
183
178 if not(m_BasicHeader.read(fp)):
184 if not(m_BasicHeader.read(fp)):
179 return 0
185 return 0
180
186
181 fp.close()
187 fp.close()
182
188
183 if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)):
189 if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)):
184 return 0
190 return 0
185
191
186 return 1
192 return 1
187
193
188 def __readBasicHeader(self, fp=None):
194 def __readBasicHeader(self, fp=None):
189
195
190 if fp == None:
196 if fp == None:
191 fp = self.__fp
197 fp = self.__fp
192
198
193 self.m_BasicHeader.read(fp)
199 self.m_BasicHeader.read(fp)
194
200
195 def __readFirstHeader(self):
201 def __readFirstHeader(self):
196
202
197 self.__readBasicHeader()
203 self.__readBasicHeader()
198 self.__rdSystemHeader()
204 self.__rdSystemHeader()
199 self.__rdRadarControllerHeader()
205 self.__rdRadarControllerHeader()
200 self.__rdProcessingHeader()
206 self.__rdProcessingHeader()
201 self.firstHeaderSize = self.m_BasicHeader.size
207 self.firstHeaderSize = self.m_BasicHeader.size
202
208
203 data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
209 data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
204 if data_type == 0:
210 if data_type == 0:
205 tmp=numpy.dtype([('real','<i1'),('imag','<i1')])
211 tmp=numpy.dtype([('real','<i1'),('imag','<i1')])
206 elif data_type == 1:
212 elif data_type == 1:
207 tmp=numpy.dtype([('real','<i2'),('imag','<i2')])
213 tmp=numpy.dtype([('real','<i2'),('imag','<i2')])
208 elif data_type == 2:
214 elif data_type == 2:
209 tmp=numpy.dtype([('real','<i4'),('imag','<i4')])
215 tmp=numpy.dtype([('real','<i4'),('imag','<i4')])
210 elif data_type == 3:
216 elif data_type == 3:
211 tmp=numpy.dtype([('real','<i8'),('imag','<i8')])
217 tmp=numpy.dtype([('real','<i8'),('imag','<i8')])
212 elif data_type == 4:
218 elif data_type == 4:
213 tmp=numpy.dtype([('real','<f4'),('imag','<f4')])
219 tmp=numpy.dtype([('real','<f4'),('imag','<f4')])
214 elif data_type == 5:
220 elif data_type == 5:
215 tmp=numpy.dtype([('real','<f8'),('imag','<f8')])
221 tmp=numpy.dtype([('real','<f8'),('imag','<f8')])
216 else:
222 else:
217 print 'no define data type'
223 print 'no define data type'
218 tmp = 0
224 tmp = 0
219
225
220 self.__dataType = tmp
226 self.__dataType = tmp
221 self.__sizeOfFileByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
227 self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
222
228
223 def __setNextFileOnline(self):
229 def __setNextFileOnline(self):
224 return 0
230 return 0
225
231
226 def __setNextFileOffline(self):
232 def __setNextFileOffline(self):
227
233
228 idFile = self.__idFile
234 idFile = self.__idFile
229 while(True):
235 while(True):
230
236
231 idFile += 1
237 idFile += 1
232
238
233 if not(idFile < len(self.filenameList)):
239 if not(idFile < len(self.filenameList)):
234 self.noMoreFiles = 1
240 self.noMoreFiles = 1
235 return 0
241 return 0
236
242
237 filename = self.filenameList[idFile]
243 filename = self.filenameList[idFile]
238 fileSize = os.path.getsize(filename)
244 fileSize = os.path.getsize(filename)
239 fp = open(filename,'rb')
245 fp = open(filename,'rb')
240
246
241 currentSize = fileSize - fp.tell()
247 currentSize = fileSize - fp.tell()
242 neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize
248 neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize
243
249
244 if (currentSize < neededSize):
250 if (currentSize < neededSize):
245 continue
251 continue
246
252
247 break
253 break
248
254
249 self.__flagIsNewFile = 1
255 self.__flagIsNewFile = 1
250 self.__idFile = idFile
256 self.__idFile = idFile
251 self.filename = filename
257 self.filename = filename
252 self.fileSize = fileSize
258 self.fileSize = fileSize
253 self.__fp = fp
259 self.__fp = fp
254
260
255 print 'Setting the file: %s'%self.filename
261 print 'Setting the file: %s'%self.filename
256
262
257 return 1
263 return 1
258
264
259 def __setNextFile(self):
265 def __setNextFile(self):
260
266
261 if self.online:
267 if self.online:
262 return self.__setNextFileOnline()
268 return self.__setNextFileOnline()
263 else:
269 else:
264 return self.__setNextFileOffline()
270 return self.__setNextFileOffline()
265
271
266 def __setNewBlock(self):
272 def __setNewBlock(self):
267
273
274 if self.__fp == None:
275 return 0
276
268 if self.__flagIsNewFile:
277 if self.__flagIsNewFile:
269 return 1
278 return 1
270
279
271 currentSize = self.fileSize - self.__fp.tell()
280 currentSize = self.fileSize - self.__fp.tell()
272 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
281 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
273
282
274 # Bloque Completo
283 # Bloque Completo
275 if (currentSize >= neededSize):
284 if (currentSize >= neededSize):
276 self.__readBasicHeader()
285 self.__readBasicHeader()
277 return 1
286 return 1
278
287
279 if not(self.__setNextFile()):
288 if not(self.__setNextFile()):
280 return 0
289 return 0
281
290
282 self.__readFirstHeader()
291 self.__readFirstHeader()
283
292
284 deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this
293 deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this
285
294
286 self.flagResetProcessing = 0
295 self.flagResetProcessing = 0
287 if deltaTime > self.__maxTimeStep:
296 if deltaTime > self.__maxTimeStep:
288 self.flagResetProcessing = 1
297 self.flagResetProcessing = 1
289
298
290 return 1
299 return 1
291
300
292 def __readBlock(self):
301 def __readBlock(self):
293 """Lee el bloque de datos desde la posicion actual del puntero del archivo y
302 """Lee el bloque de datos desde la posicion actual del puntero del archivo y
294 actualiza todos los parametros relacionados al bloque de datos (data, time,
303 actualiza todos los parametros relacionados al bloque de datos (data, time,
295 etc). La data leida es almacenada en el buffer y el contador de datos leidos es
304 etc). La data leida es almacenada en el buffer y el contador de datos leidos es
296 seteado a 0
305 seteado a 0
297 """
306 """
298
307
299 pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels
308 pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels
300
309
301 data = numpy.fromfile(self.__fp,self.__dataType,pts2read)
310 data = numpy.fromfile(self.__fp,self.__dataType,pts2read)
302
311
303 data = data.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels))
312 data = data.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels))
304
313
305 self.__flagIsNewFile = 0
314 self.__flagIsNewFile = 0
306
315
307 self.__buffer = data
316 self.__buffer = data
308
317
309 self.__buffer_id = 0
318 self.__buffer_id = 0
310
319
311 def readNextBlock(self):
320 def readNextBlock(self):
312
321
313 if not(self.__setNewBlock()):
322 if not(self.__setNewBlock()):
314 return 0
323 return 0
315
324
316 self.__readBlock()
325 self.__readBlock()
317
326
318 self.__lastUTTime = self.m_BasicHeader.utc
327 self.__lastUTTime = self.m_BasicHeader.utc
319
328
320 return 1
329 return 1
321
330
322 def __hasNotDataInBuffer(self):
331 def __hasNotDataInBuffer(self):
323 if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock:
332 if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock:
324 return 1
333 return 1
325
334
326 return 0
335 return 0
327
336
328 def getData(self):
337 def getData(self):
329 """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Data"
338 """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Data"
330 con todos los parametros asociados a este. cuando no hay datos en el buffer de
339 con todos los parametros asociados a este. cuando no hay datos en el buffer de
331 lectura es necesario hacer una nueva lectura de los bloques de datos
340 lectura es necesario hacer una nueva lectura de los bloques de datos
332 "__readBlock"
341 "__readBlock"
333 """
342 """
334 self.flagResetProcessing = 0
343 self.flagResetProcessing = 0
335
344
336 if self.__hasNotDataInBuffer():
345 if self.__hasNotDataInBuffer():
337 self.readNextBlock()
346 self.readNextBlock()
338
347
339 if self.noMoreFiles == 1:
348 if self.noMoreFiles == 1:
340 print 'read finished'
349 print 'Process finished'
341 return None
350 return None
342
351
343 data = self.__buffer[self.__buffer_id,:,:]
352 data = self.__buffer[self.__buffer_id,:,:]
344 time = 111
353 time = 111
345
354
346 self.m_Voltage.data = data
355 # self.m_Voltage.data = data
347 self.m_Voltage.timeProfile = time
356 # self.m_Voltage.timeProfile = time
348 self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy()
357 # self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy()
349 self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy()
358 # self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy()
350 self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
359 # self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
351 self.m_Voltage.m_SystemHeader = self.m_systemHeader.copy()
360 # self.m_Voltage.m_SystemHeader = self.m_systemHeader.copy()
352
361
353 self.__buffer_id += 1
362 self.__buffer_id += 1
354
363
355 #call setData - to Data Object
364 #call setData - to Data Object
356
365
357 return data
366 return data
358
367
359
368
360 def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0):
369 def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0):
361
370
362 if online == 0:
371 if online == 0:
363 pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext)
372 pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext)
364
373
365 if len(filenameList) == 0:
374 if len(filenameList) == 0:
375 self.__fp = None
376 self.noMoreFiles = 1
366 print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime())
377 print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime())
367 return 0
378 return 0
368
379
369 # for thisFile in filenameList:
380 # for thisFile in filenameList:
370 # print thisFile
381 # print thisFile
371
382
372 self.__idFile = -1
383 self.__idFile = -1
373
384
374 if not(self.__setNextFile()):
385 if not(self.__setNextFile()):
375 print "No more files"
386 print "No more files"
376 return 0
387 return 0
377
388
378 self.__readFirstHeader()
389 self.__readFirstHeader()
379
390
380 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
391 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
381 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
392 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
382
393
383 self.startYear = startDateTime.timetuple().tm_year
394 self.startYear = startDateTime.timetuple().tm_year
384 self.endYear = endDateTime.timetuple().tm_year
395 self.endYear = endDateTime.timetuple().tm_year
385
396
386 self.startDoy = startDateTime.timetuple().tm_yday
397 self.startDoy = startDateTime.timetuple().tm_yday
387 self.endDoy = endDateTime.timetuple().tm_yday
398 self.endDoy = endDateTime.timetuple().tm_yday
388 #call fillHeaderValues() - to Data Object
399 #call fillHeaderValues() - to Data Object
389
400
390 self.__pathList = pathList
401 self.__pathList = pathList
391 self.filenameList = filenameList
402 self.filenameList = filenameList
392 self.online = online
403 self.online = online
393
404
394 class VoltageWriter(DataWriter):
405 class VoltageWriter(DataWriter):
395
406
396 m_BasicHeader= BasicHeader()
407 m_BasicHeader= BasicHeader()
397
408
398
409
399 m_SystemHeader = SystemHeader()
410 m_SystemHeader = SystemHeader()
400
411
401
412
402 m_RadarControllerHeader = RadarControllerHeader()
413 m_RadarControllerHeader = RadarControllerHeader()
403
414
404
415
405 m_ProcessingHeader = ProcessingHeader()
416 m_ProcessingHeader = ProcessingHeader()
406
417
407 m_Voltage = None
418 m_Voltage = None
408
419
409 def __init__(self, m_Voltage):
420 def __init__(self, m_Voltage):
410
421
411 self.m_Voltage = m_Voltage
422 self.m_Voltage = m_Voltage
412
423
413
424
414 No newline at end of file
425
@@ -1,30 +1,37
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os, sys
7
8 path = os.path.split(os.getcwd())[0]
9 sys.path.append(path)
10
11 from Model.Data import Data
12 from IO.Header import *
6
13
7 class Voltage(Data):
14 class Voltage(Data):
8 '''
15 '''
9 classdocs
16 classdocs
10 '''
17 '''
11
18
12
19
13 m_RadarControllerHeader= RadarControllerHeader()
20 m_RadarControllerHeader= RadarControllerHeader()
14
21
15 m_ProcessingHeader= ProcessingHeader()
22 m_ProcessingHeader= ProcessingHeader()
16
23
17 m_SystemHeader= SystemHeader()
24 m_SystemHeader= SystemHeader()
18
25
19 m_BasicHeader= BasicHeader()
26 m_BasicHeader= BasicHeader()
20
27
21
28
22 def __init__(self):
29 def __init__(self):
23 '''
30 '''
24 Constructor
31 Constructor
25 '''
32 '''
26 pass
33 pass
27
34
28 def copy(self):
35 def copy(self):
29 pass
36 pass
30 No newline at end of file
37
General Comments 0
You need to be logged in to leave comments. Login now