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