@@ -1,70 +1,76 | |||||
|
1 | ''' | |||
|
2 | ||||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
|
6 | ||||
1 | import os, sys |
|
7 | import os, sys | |
2 | import copy |
|
8 | import copy | |
3 | import numpy |
|
9 | import numpy | |
4 |
|
10 | |||
5 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
6 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
7 |
|
13 | |||
8 | from IO.JROHeader import SystemHeader, RadarControllerHeader |
|
14 | from IO.JROHeader import SystemHeader, RadarControllerHeader | |
9 |
|
15 | |||
10 | class JROData: |
|
16 | class JROData: | |
11 |
|
17 | |||
12 | # m_BasicHeader = BasicHeader() |
|
18 | # m_BasicHeader = BasicHeader() | |
13 | # m_ProcessingHeader = ProcessingHeader() |
|
19 | # m_ProcessingHeader = ProcessingHeader() | |
14 |
|
20 | |||
15 | systemHeaderObj = SystemHeader() |
|
21 | systemHeaderObj = SystemHeader() | |
16 |
|
22 | |||
17 | radarControllerHeaderObj = RadarControllerHeader() |
|
23 | radarControllerHeaderObj = RadarControllerHeader() | |
18 |
|
24 | |||
19 | # data = None |
|
25 | # data = None | |
20 |
|
26 | |||
21 | type = None |
|
27 | type = None | |
22 |
|
28 | |||
23 | dtype = None |
|
29 | dtype = None | |
24 |
|
30 | |||
25 | nChannels = None |
|
31 | nChannels = None | |
26 |
|
32 | |||
27 | nHeights = None |
|
33 | nHeights = None | |
28 |
|
34 | |||
29 | nProfiles = None |
|
35 | nProfiles = None | |
30 |
|
36 | |||
31 | heightList = None |
|
37 | heightList = None | |
32 |
|
38 | |||
33 | channelList = None |
|
39 | channelList = None | |
34 |
|
40 | |||
35 | channelIndexList = None |
|
41 | channelIndexList = None | |
36 |
|
42 | |||
37 | flagNoData = False |
|
43 | flagNoData = False | |
38 |
|
44 | |||
39 | flagTimeBlock = False |
|
45 | flagTimeBlock = False | |
40 |
|
46 | |||
41 | dataUtcTime = None |
|
47 | dataUtcTime = None | |
42 |
|
48 | |||
43 | nCode = None |
|
49 | nCode = None | |
44 |
|
50 | |||
45 | nBaud = None |
|
51 | nBaud = None | |
46 |
|
52 | |||
47 | code = None |
|
53 | code = None | |
48 |
|
54 | |||
49 | flagDecodeData = True #asumo q la data esta decodificada |
|
55 | flagDecodeData = True #asumo q la data esta decodificada | |
50 |
|
56 | |||
51 | flagDeflipData = True #asumo q la data esta sin flip |
|
57 | flagDeflipData = True #asumo q la data esta sin flip | |
52 |
|
58 | |||
53 | flagShiftFFT = False |
|
59 | flagShiftFFT = False | |
54 |
|
60 | |||
55 |
|
61 | |||
56 | def __init__(self): |
|
62 | def __init__(self): | |
57 |
|
63 | |||
58 | raise ValueError, "This class has not been implemented" |
|
64 | raise ValueError, "This class has not been implemented" | |
59 |
|
65 | |||
60 | def copy(self, inputObj=None): |
|
66 | def copy(self, inputObj=None): | |
61 |
|
67 | |||
62 | if inputObj == None: |
|
68 | if inputObj == None: | |
63 | return copy.deepcopy(self) |
|
69 | return copy.deepcopy(self) | |
64 |
|
70 | |||
65 | for key in inputObj.__dict__.keys(): |
|
71 | for key in inputObj.__dict__.keys(): | |
66 | self.__dict__[key] = inputObj.__dict__[key] |
|
72 | self.__dict__[key] = inputObj.__dict__[key] | |
67 |
|
73 | |||
68 | def deepcopy(self): |
|
74 | def deepcopy(self): | |
69 |
|
75 | |||
70 | return copy.deepcopy(self) No newline at end of file |
|
76 | return copy.deepcopy(self) |
@@ -1,60 +1,66 | |||||
|
1 | ''' | |||
|
2 | ||||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
|
6 | ||||
1 | import os, sys |
|
7 | import os, sys | |
2 | import numpy |
|
8 | import numpy | |
3 |
|
9 | |||
4 | path = os.path.split(os.getcwd())[0] |
|
10 | path = os.path.split(os.getcwd())[0] | |
5 | sys.path.append(path) |
|
11 | sys.path.append(path) | |
6 |
|
12 | |||
7 | from JROData import JROData |
|
13 | from JROData import JROData | |
8 | from IO.JROHeader import SystemHeader, RadarControllerHeader |
|
14 | from IO.JROHeader import SystemHeader, RadarControllerHeader | |
9 |
|
15 | |||
10 | class Spectra(JROData): |
|
16 | class Spectra(JROData): | |
11 | data_spc = None |
|
17 | data_spc = None | |
12 |
|
18 | |||
13 | data_cspc = None |
|
19 | data_cspc = None | |
14 |
|
20 | |||
15 | data_dc = None |
|
21 | data_dc = None | |
16 |
|
22 | |||
17 | nFFTPoints = None |
|
23 | nFFTPoints = None | |
18 |
|
24 | |||
19 | nPairs = None |
|
25 | nPairs = None | |
20 |
|
26 | |||
21 | pairsList = None |
|
27 | pairsList = None | |
22 |
|
28 | |||
23 | nIncohInt = None |
|
29 | nIncohInt = None | |
24 |
|
30 | |||
25 | def __init__(self): |
|
31 | def __init__(self): | |
26 | ''' |
|
32 | ''' | |
27 | Constructor |
|
33 | Constructor | |
28 | ''' |
|
34 | ''' | |
29 |
|
35 | |||
30 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
36 | self.m_RadarControllerHeader = RadarControllerHeader() | |
31 |
|
37 | |||
32 | self.m_SystemHeader = SystemHeader() |
|
38 | self.m_SystemHeader = SystemHeader() | |
33 |
|
39 | |||
34 | self.type = "Spectra" |
|
40 | self.type = "Spectra" | |
35 |
|
41 | |||
36 | #data es un numpy array de 2 dmensiones ( canales, alturas) |
|
42 | #data es un numpy array de 2 dmensiones ( canales, alturas) | |
37 | # self.data = None |
|
43 | # self.data = None | |
38 |
|
44 | |||
39 | self.dtype = None |
|
45 | self.dtype = None | |
40 |
|
46 | |||
41 | self.nChannels = 0 |
|
47 | self.nChannels = 0 | |
42 |
|
48 | |||
43 | self.nHeights = 0 |
|
49 | self.nHeights = 0 | |
44 |
|
50 | |||
45 | self.nProfiles = None |
|
51 | self.nProfiles = None | |
46 |
|
52 | |||
47 | self.heightList = None |
|
53 | self.heightList = None | |
48 |
|
54 | |||
49 | self.channelList = None |
|
55 | self.channelList = None | |
50 |
|
56 | |||
51 | self.channelIndexList = None |
|
57 | self.channelIndexList = None | |
52 |
|
58 | |||
53 | self.flagNoData = True |
|
59 | self.flagNoData = True | |
54 |
|
60 | |||
55 | self.flagTimeBlock = False |
|
61 | self.flagTimeBlock = False | |
56 |
|
62 | |||
57 | self.dataUtcTime = None |
|
63 | self.dataUtcTime = None | |
58 |
|
64 | |||
59 | self.nIncohInt = None |
|
65 | self.nIncohInt = None | |
60 | No newline at end of file |
|
66 |
@@ -1,50 +1,56 | |||||
|
1 | ''' | |||
|
2 | ||||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
|
6 | ||||
1 | import os, sys |
|
7 | import os, sys | |
2 | import numpy |
|
8 | import numpy | |
3 |
|
9 | |||
4 | path = os.path.split(os.getcwd())[0] |
|
10 | path = os.path.split(os.getcwd())[0] | |
5 | sys.path.append(path) |
|
11 | sys.path.append(path) | |
6 |
|
12 | |||
7 | from JROData import JROData |
|
13 | from JROData import JROData | |
8 | from IO.JROHeader import SystemHeader, RadarControllerHeader |
|
14 | from IO.JROHeader import SystemHeader, RadarControllerHeader | |
9 |
|
15 | |||
10 | class Voltage(JROData): |
|
16 | class Voltage(JROData): | |
11 |
|
17 | |||
12 | nCohInt = None |
|
18 | nCohInt = None | |
13 |
|
19 | |||
14 | data = None |
|
20 | data = None | |
15 |
|
21 | |||
16 | def __init__(self): |
|
22 | def __init__(self): | |
17 | ''' |
|
23 | ''' | |
18 | Constructor |
|
24 | Constructor | |
19 | ''' |
|
25 | ''' | |
20 |
|
26 | |||
21 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
27 | self.m_RadarControllerHeader = RadarControllerHeader() | |
22 |
|
28 | |||
23 | self.m_SystemHeader = SystemHeader() |
|
29 | self.m_SystemHeader = SystemHeader() | |
24 |
|
30 | |||
25 | self.type = "Voltage" |
|
31 | self.type = "Voltage" | |
26 |
|
32 | |||
27 | #data es un numpy array de 2 dmensiones ( canales, alturas) |
|
33 | #data es un numpy array de 2 dmensiones ( canales, alturas) | |
28 | self.data = None |
|
34 | self.data = None | |
29 |
|
35 | |||
30 | self.dtype = None |
|
36 | self.dtype = None | |
31 |
|
37 | |||
32 | self.nChannels = 0 |
|
38 | self.nChannels = 0 | |
33 |
|
39 | |||
34 | self.nHeights = 0 |
|
40 | self.nHeights = 0 | |
35 |
|
41 | |||
36 | self.nProfiles = None |
|
42 | self.nProfiles = None | |
37 |
|
43 | |||
38 | self.heightList = None |
|
44 | self.heightList = None | |
39 |
|
45 | |||
40 | self.channelList = None |
|
46 | self.channelList = None | |
41 |
|
47 | |||
42 | self.channelIndexList = None |
|
48 | self.channelIndexList = None | |
43 |
|
49 | |||
44 | self.flagNoData = True |
|
50 | self.flagNoData = True | |
45 |
|
51 | |||
46 | self.flagTimeBlock = False |
|
52 | self.flagTimeBlock = False | |
47 |
|
53 | |||
48 | self.dataUtcTime = None |
|
54 | self.dataUtcTime = None | |
49 |
|
55 | |||
50 | self.nCohInt = None |
|
56 | self.nCohInt = None |
@@ -1,751 +1,757 | |||||
|
1 | ''' | |||
|
2 | ||||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
|
6 | ||||
1 | import os, sys |
|
7 | import os, sys | |
2 | import glob |
|
8 | import glob | |
3 | import time |
|
9 | import time | |
4 | import numpy |
|
10 | import numpy | |
5 | import fnmatch |
|
11 | import fnmatch | |
6 | import time, datetime |
|
12 | import time, datetime | |
7 |
|
13 | |||
8 | path = os.path.split(os.getcwd())[0] |
|
14 | path = os.path.split(os.getcwd())[0] | |
9 | sys.path.append(path) |
|
15 | sys.path.append(path) | |
10 |
|
16 | |||
11 | from JROHeader import * |
|
17 | from JROHeader import * | |
12 | from Data.JROData import JROData |
|
18 | from Data.JROData import JROData | |
13 |
|
19 | |||
14 | def isNumber(str): |
|
20 | def isNumber(str): | |
15 | """ |
|
21 | """ | |
16 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
17 |
|
23 | |||
18 | Excepciones: |
|
24 | Excepciones: | |
19 | Si un determinado string no puede ser convertido a numero |
|
25 | Si un determinado string no puede ser convertido a numero | |
20 | Input: |
|
26 | Input: | |
21 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
27 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
22 |
|
28 | |||
23 | Return: |
|
29 | Return: | |
24 | True : si el string es uno numerico |
|
30 | True : si el string es uno numerico | |
25 | False : no es un string numerico |
|
31 | False : no es un string numerico | |
26 | """ |
|
32 | """ | |
27 | try: |
|
33 | try: | |
28 | float( str ) |
|
34 | float( str ) | |
29 | return True |
|
35 | return True | |
30 | except: |
|
36 | except: | |
31 | return False |
|
37 | return False | |
32 |
|
38 | |||
33 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
34 | """ |
|
40 | """ | |
35 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
36 |
|
42 | |||
37 | Inputs: |
|
43 | Inputs: | |
38 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
39 |
|
45 | |||
40 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
41 | segundos contados desde 01/01/1970. |
|
47 | segundos contados desde 01/01/1970. | |
42 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
43 | segundos contados desde 01/01/1970. |
|
49 | segundos contados desde 01/01/1970. | |
44 |
|
50 | |||
45 | Return: |
|
51 | Return: | |
46 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
47 | fecha especificado, de lo contrario retorna False. |
|
53 | fecha especificado, de lo contrario retorna False. | |
48 |
|
54 | |||
49 | Excepciones: |
|
55 | Excepciones: | |
50 | Si el archivo no existe o no puede ser abierto |
|
56 | Si el archivo no existe o no puede ser abierto | |
51 | Si la cabecera no puede ser leida. |
|
57 | Si la cabecera no puede ser leida. | |
52 |
|
58 | |||
53 | """ |
|
59 | """ | |
54 | basicHeaderObj = BasicHeader() |
|
60 | basicHeaderObj = BasicHeader() | |
55 |
|
61 | |||
56 | try: |
|
62 | try: | |
57 | fp = open(filename,'rb') |
|
63 | fp = open(filename,'rb') | |
58 | except: |
|
64 | except: | |
59 | raise IOError, "The file %s can't be opened" %(filename) |
|
65 | raise IOError, "The file %s can't be opened" %(filename) | |
60 |
|
66 | |||
61 | sts = basicHeaderObj.read(fp) |
|
67 | sts = basicHeaderObj.read(fp) | |
62 | fp.close() |
|
68 | fp.close() | |
63 |
|
69 | |||
64 | if not(sts): |
|
70 | if not(sts): | |
65 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
71 | print "Skipping the file %s because it has not a valid header" %(filename) | |
66 | return 0 |
|
72 | return 0 | |
67 |
|
73 | |||
68 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
69 | return 0 |
|
75 | return 0 | |
70 |
|
76 | |||
71 | return 1 |
|
77 | return 1 | |
72 |
|
78 | |||
73 |
|
79 | |||
74 |
|
80 | |||
75 |
|
81 | |||
76 | class JRODataIO: |
|
82 | class JRODataIO: | |
77 |
|
83 | |||
78 | c = 3E8 |
|
84 | c = 3E8 | |
79 |
|
85 | |||
80 | basicHeaderObj = BasicHeader() |
|
86 | basicHeaderObj = BasicHeader() | |
81 |
|
87 | |||
82 | systemHeaderObj = SystemHeader() |
|
88 | systemHeaderObj = SystemHeader() | |
83 |
|
89 | |||
84 | radarControllerHeaderObj = RadarControllerHeader() |
|
90 | radarControllerHeaderObj = RadarControllerHeader() | |
85 |
|
91 | |||
86 | processingHeaderObj = ProcessingHeader() |
|
92 | processingHeaderObj = ProcessingHeader() | |
87 |
|
93 | |||
88 | online = 0 |
|
94 | online = 0 | |
89 |
|
95 | |||
90 | dtype = None |
|
96 | dtype = None | |
91 |
|
97 | |||
92 | pathList = [] |
|
98 | pathList = [] | |
93 |
|
99 | |||
94 | filenameList = [] |
|
100 | filenameList = [] | |
95 |
|
101 | |||
96 | filename = None |
|
102 | filename = None | |
97 |
|
103 | |||
98 | ext = None |
|
104 | ext = None | |
99 |
|
105 | |||
100 | flagNoMoreFiles = 0 |
|
106 | flagNoMoreFiles = 0 | |
101 |
|
107 | |||
102 | flagIsNewFile = 1 |
|
108 | flagIsNewFile = 1 | |
103 |
|
109 | |||
104 | flagTimeBlock = 0 |
|
110 | flagTimeBlock = 0 | |
105 |
|
111 | |||
106 | flagIsNewBlock = 0 |
|
112 | flagIsNewBlock = 0 | |
107 |
|
113 | |||
108 | fp = None |
|
114 | fp = None | |
109 |
|
115 | |||
110 | firstHeaderSize = 0 |
|
116 | firstHeaderSize = 0 | |
111 |
|
117 | |||
112 | basicHeaderSize = 24 |
|
118 | basicHeaderSize = 24 | |
113 |
|
119 | |||
114 | versionFile = 1103 |
|
120 | versionFile = 1103 | |
115 |
|
121 | |||
116 | fileSize = None |
|
122 | fileSize = None | |
117 |
|
123 | |||
118 | ippSeconds = None |
|
124 | ippSeconds = None | |
119 |
|
125 | |||
120 | fileSizeByHeader = None |
|
126 | fileSizeByHeader = None | |
121 |
|
127 | |||
122 | fileIndex = None |
|
128 | fileIndex = None | |
123 |
|
129 | |||
124 | profileIndex = None |
|
130 | profileIndex = None | |
125 |
|
131 | |||
126 | blockIndex = None |
|
132 | blockIndex = None | |
127 |
|
133 | |||
128 | nTotalBlocks = None |
|
134 | nTotalBlocks = None | |
129 |
|
135 | |||
130 | maxTimeStep = 30 |
|
136 | maxTimeStep = 30 | |
131 |
|
137 | |||
132 | lastUTTime = None |
|
138 | lastUTTime = None | |
133 |
|
139 | |||
134 | datablock = None |
|
140 | datablock = None | |
135 |
|
141 | |||
136 | dataOutObj = None |
|
142 | dataOutObj = None | |
137 |
|
143 | |||
138 | blocksize = None |
|
144 | blocksize = None | |
139 |
|
145 | |||
140 | def __init__(self): |
|
146 | def __init__(self): | |
141 | pass |
|
147 | pass | |
142 |
|
148 | |||
143 | class JRODataReader(JRODataIO): |
|
149 | class JRODataReader(JRODataIO): | |
144 |
|
150 | |||
145 | nReadBlocks = 0 |
|
151 | nReadBlocks = 0 | |
146 |
|
152 | |||
147 | def __init__(self): |
|
153 | def __init__(self): | |
148 |
|
154 | |||
149 | pass |
|
155 | pass | |
150 |
|
156 | |||
151 | def createObjByDefault(self): |
|
157 | def createObjByDefault(self): | |
152 | """ |
|
158 | """ | |
153 |
|
159 | |||
154 | """ |
|
160 | """ | |
155 | raise ValueError, "This method has not been implemented" |
|
161 | raise ValueError, "This method has not been implemented" | |
156 |
|
162 | |||
157 | def getBlockDimension(self): |
|
163 | def getBlockDimension(self): | |
158 |
|
164 | |||
159 | raise ValueError, "No implemented" |
|
165 | raise ValueError, "No implemented" | |
160 |
|
166 | |||
161 | def __searchFilesOffLine(self, |
|
167 | def __searchFilesOffLine(self, | |
162 | path, |
|
168 | path, | |
163 | startDate, |
|
169 | startDate, | |
164 | endDate, |
|
170 | endDate, | |
165 | startTime=datetime.time(0,0,0), |
|
171 | startTime=datetime.time(0,0,0), | |
166 | endTime=datetime.time(23,59,59), |
|
172 | endTime=datetime.time(23,59,59), | |
167 | set=None, |
|
173 | set=None, | |
168 | expLabel="", |
|
174 | expLabel="", | |
169 | ext=".r"): |
|
175 | ext=".r"): | |
170 | dirList = [] |
|
176 | dirList = [] | |
171 | for thisPath in os.listdir(path): |
|
177 | for thisPath in os.listdir(path): | |
172 | if os.path.isdir(os.path.join(path,thisPath)): |
|
178 | if os.path.isdir(os.path.join(path,thisPath)): | |
173 | dirList.append(thisPath) |
|
179 | dirList.append(thisPath) | |
174 |
|
180 | |||
175 | if not(dirList): |
|
181 | if not(dirList): | |
176 | return None, None |
|
182 | return None, None | |
177 |
|
183 | |||
178 | pathList = [] |
|
184 | pathList = [] | |
179 | dateList = [] |
|
185 | dateList = [] | |
180 |
|
186 | |||
181 | thisDate = startDate |
|
187 | thisDate = startDate | |
182 |
|
188 | |||
183 | while(thisDate <= endDate): |
|
189 | while(thisDate <= endDate): | |
184 | year = thisDate.timetuple().tm_year |
|
190 | year = thisDate.timetuple().tm_year | |
185 | doy = thisDate.timetuple().tm_yday |
|
191 | doy = thisDate.timetuple().tm_yday | |
186 |
|
192 | |||
187 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
193 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
188 | if len(match) == 0: |
|
194 | if len(match) == 0: | |
189 | thisDate += datetime.timedelta(1) |
|
195 | thisDate += datetime.timedelta(1) | |
190 | continue |
|
196 | continue | |
191 |
|
197 | |||
192 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
198 | pathList.append(os.path.join(path,match[0],expLabel)) | |
193 | dateList.append(thisDate) |
|
199 | dateList.append(thisDate) | |
194 | thisDate += datetime.timedelta(1) |
|
200 | thisDate += datetime.timedelta(1) | |
195 |
|
201 | |||
196 | filenameList = [] |
|
202 | filenameList = [] | |
197 | for index in range(len(pathList)): |
|
203 | for index in range(len(pathList)): | |
198 |
|
204 | |||
199 | thisPath = pathList[index] |
|
205 | thisPath = pathList[index] | |
200 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
206 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
201 | fileList.sort() |
|
207 | fileList.sort() | |
202 |
|
208 | |||
203 | #Busqueda de datos en el rango de horas indicados |
|
209 | #Busqueda de datos en el rango de horas indicados | |
204 | thisDate = dateList[index] |
|
210 | thisDate = dateList[index] | |
205 | startDT = datetime.datetime.combine(thisDate, startTime) |
|
211 | startDT = datetime.datetime.combine(thisDate, startTime) | |
206 | endDT = datetime.datetime.combine(thisDate, endTime) |
|
212 | endDT = datetime.datetime.combine(thisDate, endTime) | |
207 |
|
213 | |||
208 | startUtSeconds = time.mktime(startDT.timetuple()) |
|
214 | startUtSeconds = time.mktime(startDT.timetuple()) | |
209 | endUtSeconds = time.mktime(endDT.timetuple()) |
|
215 | endUtSeconds = time.mktime(endDT.timetuple()) | |
210 |
|
216 | |||
211 | for file in fileList: |
|
217 | for file in fileList: | |
212 |
|
218 | |||
213 | filename = os.path.join(thisPath,file) |
|
219 | filename = os.path.join(thisPath,file) | |
214 |
|
220 | |||
215 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
221 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
216 | filenameList.append(filename) |
|
222 | filenameList.append(filename) | |
217 |
|
223 | |||
218 | if not(filenameList): |
|
224 | if not(filenameList): | |
219 | return None, None |
|
225 | return None, None | |
220 |
|
226 | |||
221 | self.filenameList = filenameList |
|
227 | self.filenameList = filenameList | |
222 |
|
228 | |||
223 | return pathList, filenameList |
|
229 | return pathList, filenameList | |
224 |
|
230 | |||
225 | def setup(self,dataOutObj=None, |
|
231 | def setup(self,dataOutObj=None, | |
226 | path=None, |
|
232 | path=None, | |
227 | startDate=None, |
|
233 | startDate=None, | |
228 | endDate=None, |
|
234 | endDate=None, | |
229 | startTime=datetime.time(0,0,0), |
|
235 | startTime=datetime.time(0,0,0), | |
230 | endTime=datetime.time(23,59,59), |
|
236 | endTime=datetime.time(23,59,59), | |
231 | set=0, |
|
237 | set=0, | |
232 | expLabel = "", |
|
238 | expLabel = "", | |
233 | ext = None, |
|
239 | ext = None, | |
234 | online = 0): |
|
240 | online = 0): | |
235 |
|
241 | |||
236 | if path == None: |
|
242 | if path == None: | |
237 | raise ValueError, "The path is not valid" |
|
243 | raise ValueError, "The path is not valid" | |
238 |
|
244 | |||
239 | if ext == None: |
|
245 | if ext == None: | |
240 | ext = self.ext |
|
246 | ext = self.ext | |
241 |
|
247 | |||
242 | if dataOutObj == None: |
|
248 | if dataOutObj == None: | |
243 | dataOutObj = self.createObjByDefault() |
|
249 | dataOutObj = self.createObjByDefault() | |
244 |
|
250 | |||
245 | self.dataOutObj = dataOutObj |
|
251 | self.dataOutObj = dataOutObj | |
246 |
|
252 | |||
247 | if online: |
|
253 | if online: | |
248 | pass |
|
254 | pass | |
249 |
|
255 | |||
250 | else: |
|
256 | else: | |
251 | print "Searching file in offline mode" |
|
257 | print "Searching file in offline mode" | |
252 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) |
|
258 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) | |
253 | if not(pathList): |
|
259 | if not(pathList): | |
254 | print "No files in range: %s - %s"%(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
260 | print "No files in range: %s - %s"%(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
255 | return None |
|
261 | return None | |
256 | self.fileIndex = -1 |
|
262 | self.fileIndex = -1 | |
257 | self.pathList = pathList |
|
263 | self.pathList = pathList | |
258 | self.filenameList = filenameList |
|
264 | self.filenameList = filenameList | |
259 |
|
265 | |||
260 | self.online = online |
|
266 | self.online = online | |
261 | ext = ext.lower() |
|
267 | ext = ext.lower() | |
262 | self.ext = ext |
|
268 | self.ext = ext | |
263 |
|
269 | |||
264 | if not(self.setNextFile()): |
|
270 | if not(self.setNextFile()): | |
265 | if (startDate!=None) and (endDate!=None): |
|
271 | if (startDate!=None) and (endDate!=None): | |
266 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
272 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
267 | elif startDate != None: |
|
273 | elif startDate != None: | |
268 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
274 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
269 | else: |
|
275 | else: | |
270 | print "No files" |
|
276 | print "No files" | |
271 |
|
277 | |||
272 | return None |
|
278 | return None | |
273 |
|
279 | |||
274 | # self.updateDataHeader() |
|
280 | # self.updateDataHeader() | |
275 |
|
281 | |||
276 | return self.dataOutObj |
|
282 | return self.dataOutObj | |
277 |
|
283 | |||
278 | def __setNextFileOffline(self): |
|
284 | def __setNextFileOffline(self): | |
279 | idFile = self.fileIndex |
|
285 | idFile = self.fileIndex | |
280 |
|
286 | |||
281 | while (True): |
|
287 | while (True): | |
282 | idFile += 1 |
|
288 | idFile += 1 | |
283 | if not(idFile < len(self.filenameList)): |
|
289 | if not(idFile < len(self.filenameList)): | |
284 | self.flagNoMoreFiles = 1 |
|
290 | self.flagNoMoreFiles = 1 | |
285 | print "No more Files" |
|
291 | print "No more Files" | |
286 | return 0 |
|
292 | return 0 | |
287 |
|
293 | |||
288 | filename = self.filenameList[idFile] |
|
294 | filename = self.filenameList[idFile] | |
289 |
|
295 | |||
290 | if not(self.__verifyFile(filename)): |
|
296 | if not(self.__verifyFile(filename)): | |
291 | continue |
|
297 | continue | |
292 |
|
298 | |||
293 | fileSize = os.path.getsize(filename) |
|
299 | fileSize = os.path.getsize(filename) | |
294 | fp = open(filename,'rb') |
|
300 | fp = open(filename,'rb') | |
295 | break |
|
301 | break | |
296 |
|
302 | |||
297 | self.flagIsNewFile = 1 |
|
303 | self.flagIsNewFile = 1 | |
298 | self.fileIndex = idFile |
|
304 | self.fileIndex = idFile | |
299 | self.filename = filename |
|
305 | self.filename = filename | |
300 | self.fileSize = fileSize |
|
306 | self.fileSize = fileSize | |
301 | self.fp = fp |
|
307 | self.fp = fp | |
302 |
|
308 | |||
303 | print "Setting the file: %s"%self.filename |
|
309 | print "Setting the file: %s"%self.filename | |
304 |
|
310 | |||
305 | return 1 |
|
311 | return 1 | |
306 |
|
312 | |||
307 |
|
313 | |||
308 |
|
314 | |||
309 | def setNextFile(self): |
|
315 | def setNextFile(self): | |
310 | if self.fp != None: |
|
316 | if self.fp != None: | |
311 | self.fp.close() |
|
317 | self.fp.close() | |
312 |
|
318 | |||
313 | if self.online: |
|
319 | if self.online: | |
314 | newFile = self.__setNextFileOnline() |
|
320 | newFile = self.__setNextFileOnline() | |
315 | else: |
|
321 | else: | |
316 | newFile = self.__setNextFileOffline() |
|
322 | newFile = self.__setNextFileOffline() | |
317 |
|
323 | |||
318 | if not(newFile): |
|
324 | if not(newFile): | |
319 | return 0 |
|
325 | return 0 | |
320 |
|
326 | |||
321 | self.__readFirstHeader() |
|
327 | self.__readFirstHeader() | |
322 | self.nReadBlocks = 0 |
|
328 | self.nReadBlocks = 0 | |
323 | return 1 |
|
329 | return 1 | |
324 |
|
330 | |||
325 | def __setNewBlock(self): |
|
331 | def __setNewBlock(self): | |
326 | if self.fp == None: |
|
332 | if self.fp == None: | |
327 | return 0 |
|
333 | return 0 | |
328 |
|
334 | |||
329 | if self.flagIsNewFile: |
|
335 | if self.flagIsNewFile: | |
330 | return 1 |
|
336 | return 1 | |
331 |
|
337 | |||
332 | self.lastUTTime = self.basicHeaderObj.utc |
|
338 | self.lastUTTime = self.basicHeaderObj.utc | |
333 | currentSize = self.fileSize - self.fp.tell() |
|
339 | currentSize = self.fileSize - self.fp.tell() | |
334 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
340 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
335 |
|
341 | |||
336 | if (currentSize >= neededSize): |
|
342 | if (currentSize >= neededSize): | |
337 | self.__rdBasicHeader() |
|
343 | self.__rdBasicHeader() | |
338 | return 1 |
|
344 | return 1 | |
339 |
|
345 | |||
340 | if not(self.setNextFile()): |
|
346 | if not(self.setNextFile()): | |
341 | return 0 |
|
347 | return 0 | |
342 |
|
348 | |||
343 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
349 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
344 |
|
350 | |||
345 | self.flagTimeBlock = 0 |
|
351 | self.flagTimeBlock = 0 | |
346 |
|
352 | |||
347 | if deltaTime > self.maxTimeStep: |
|
353 | if deltaTime > self.maxTimeStep: | |
348 | self.flagTimeBlock = 1 |
|
354 | self.flagTimeBlock = 1 | |
349 |
|
355 | |||
350 | return 1 |
|
356 | return 1 | |
351 |
|
357 | |||
352 |
|
358 | |||
353 | def readNextBlock(self): |
|
359 | def readNextBlock(self): | |
354 | if not(self.__setNewBlock()): |
|
360 | if not(self.__setNewBlock()): | |
355 | return 0 |
|
361 | return 0 | |
356 |
|
362 | |||
357 | if not(self.readBlock()): |
|
363 | if not(self.readBlock()): | |
358 | return 0 |
|
364 | return 0 | |
359 |
|
365 | |||
360 | return 1 |
|
366 | return 1 | |
361 |
|
367 | |||
362 | def __rdProcessingHeader(self, fp=None): |
|
368 | def __rdProcessingHeader(self, fp=None): | |
363 | if fp == None: |
|
369 | if fp == None: | |
364 | fp = self.fp |
|
370 | fp = self.fp | |
365 |
|
371 | |||
366 | self.processingHeaderObj.read(fp) |
|
372 | self.processingHeaderObj.read(fp) | |
367 |
|
373 | |||
368 | def __rdRadarControllerHeader(self, fp=None): |
|
374 | def __rdRadarControllerHeader(self, fp=None): | |
369 | if fp == None: |
|
375 | if fp == None: | |
370 | fp = self.fp |
|
376 | fp = self.fp | |
371 |
|
377 | |||
372 | self.radarControllerHeaderObj.read(fp) |
|
378 | self.radarControllerHeaderObj.read(fp) | |
373 |
|
379 | |||
374 | def __rdSystemHeader(self, fp=None): |
|
380 | def __rdSystemHeader(self, fp=None): | |
375 | if fp == None: |
|
381 | if fp == None: | |
376 | fp = self.fp |
|
382 | fp = self.fp | |
377 |
|
383 | |||
378 | self.systemHeaderObj.read(fp) |
|
384 | self.systemHeaderObj.read(fp) | |
379 |
|
385 | |||
380 | def __rdBasicHeader(self, fp=None): |
|
386 | def __rdBasicHeader(self, fp=None): | |
381 | if fp == None: |
|
387 | if fp == None: | |
382 | fp = self.fp |
|
388 | fp = self.fp | |
383 |
|
389 | |||
384 | self.basicHeaderObj.read(fp) |
|
390 | self.basicHeaderObj.read(fp) | |
385 |
|
391 | |||
386 |
|
392 | |||
387 | def __readFirstHeader(self): |
|
393 | def __readFirstHeader(self): | |
388 | self.__rdBasicHeader() |
|
394 | self.__rdBasicHeader() | |
389 | self.__rdSystemHeader() |
|
395 | self.__rdSystemHeader() | |
390 | self.__rdRadarControllerHeader() |
|
396 | self.__rdRadarControllerHeader() | |
391 | self.__rdProcessingHeader() |
|
397 | self.__rdProcessingHeader() | |
392 |
|
398 | |||
393 | self.firstHeaderSize = self.basicHeaderObj.size |
|
399 | self.firstHeaderSize = self.basicHeaderObj.size | |
394 |
|
400 | |||
395 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
401 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
396 | if datatype == 0: |
|
402 | if datatype == 0: | |
397 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
403 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
398 | elif datatype == 1: |
|
404 | elif datatype == 1: | |
399 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
405 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
400 | elif datatype == 2: |
|
406 | elif datatype == 2: | |
401 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
407 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
402 | elif datatype == 3: |
|
408 | elif datatype == 3: | |
403 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
409 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
404 | elif datatype == 4: |
|
410 | elif datatype == 4: | |
405 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
411 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
406 | elif datatype == 5: |
|
412 | elif datatype == 5: | |
407 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
413 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
408 | else: |
|
414 | else: | |
409 | raise ValueError, 'Data type was not defined' |
|
415 | raise ValueError, 'Data type was not defined' | |
410 |
|
416 | |||
411 | self.dtype = datatype_str |
|
417 | self.dtype = datatype_str | |
412 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
418 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
413 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
419 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
414 | # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
420 | # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
415 | # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
421 | # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
416 | self.getBlockDimension() |
|
422 | self.getBlockDimension() | |
417 |
|
423 | |||
418 |
|
424 | |||
419 | def __verifyFile(self, filename, msgFlag=True): |
|
425 | def __verifyFile(self, filename, msgFlag=True): | |
420 | msg = None |
|
426 | msg = None | |
421 | try: |
|
427 | try: | |
422 | fp = open(filename, 'rb') |
|
428 | fp = open(filename, 'rb') | |
423 | currentPosition = fp.tell() |
|
429 | currentPosition = fp.tell() | |
424 | except: |
|
430 | except: | |
425 | if msgFlag: |
|
431 | if msgFlag: | |
426 | print "The file %s can't be opened" % (filename) |
|
432 | print "The file %s can't be opened" % (filename) | |
427 | return False |
|
433 | return False | |
428 |
|
434 | |||
429 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
435 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
430 |
|
436 | |||
431 | if neededSize == 0: |
|
437 | if neededSize == 0: | |
432 | basicHeaderObj = BasicHeader() |
|
438 | basicHeaderObj = BasicHeader() | |
433 | systemHeaderObj = SystemHeader() |
|
439 | systemHeaderObj = SystemHeader() | |
434 | radarControllerHeaderObj = RadarControllerHeader() |
|
440 | radarControllerHeaderObj = RadarControllerHeader() | |
435 | processingHeaderObj = ProcessingHeader() |
|
441 | processingHeaderObj = ProcessingHeader() | |
436 |
|
442 | |||
437 | try: |
|
443 | try: | |
438 | if not( basicHeaderObj.read(fp) ): raise ValueError |
|
444 | if not( basicHeaderObj.read(fp) ): raise ValueError | |
439 | if not( systemHeaderObj.read(fp) ): raise ValueError |
|
445 | if not( systemHeaderObj.read(fp) ): raise ValueError | |
440 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError |
|
446 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError | |
441 | if not( processingHeaderObj.read(fp) ): raise ValueError |
|
447 | if not( processingHeaderObj.read(fp) ): raise ValueError | |
442 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
448 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
443 |
|
449 | |||
444 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
450 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
445 |
|
451 | |||
446 | except: |
|
452 | except: | |
447 | if msgFlag: |
|
453 | if msgFlag: | |
448 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
454 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
449 |
|
455 | |||
450 | fp.close() |
|
456 | fp.close() | |
451 | return False |
|
457 | return False | |
452 | else: |
|
458 | else: | |
453 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
459 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
454 |
|
460 | |||
455 | fp.close() |
|
461 | fp.close() | |
456 | fileSize = os.path.getsize(filename) |
|
462 | fileSize = os.path.getsize(filename) | |
457 | currentSize = fileSize - currentPosition |
|
463 | currentSize = fileSize - currentPosition | |
458 | if currentSize < neededSize: |
|
464 | if currentSize < neededSize: | |
459 | if msgFlag and (msg != None): |
|
465 | if msgFlag and (msg != None): | |
460 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
466 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
461 | return False |
|
467 | return False | |
462 |
|
468 | |||
463 | return True |
|
469 | return True | |
464 |
|
470 | |||
465 | def getData(): |
|
471 | def getData(): | |
466 | pass |
|
472 | pass | |
467 |
|
473 | |||
468 | def hasNotDataInBuffer(): |
|
474 | def hasNotDataInBuffer(): | |
469 | pass |
|
475 | pass | |
470 |
|
476 | |||
471 | def readBlock(): |
|
477 | def readBlock(): | |
472 | pass |
|
478 | pass | |
473 |
|
479 | |||
474 | class JRODataWriter(JRODataIO): |
|
480 | class JRODataWriter(JRODataIO): | |
475 |
|
481 | |||
476 | """ |
|
482 | """ | |
477 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
483 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
478 | de los datos siempre se realiza por bloques. |
|
484 | de los datos siempre se realiza por bloques. | |
479 | """ |
|
485 | """ | |
480 |
|
486 | |||
481 | blockIndex = 0 |
|
487 | blockIndex = 0 | |
482 |
|
488 | |||
483 | path = None |
|
489 | path = None | |
484 |
|
490 | |||
485 | setFile = None |
|
491 | setFile = None | |
486 |
|
492 | |||
487 | profilesPerBlock = None |
|
493 | profilesPerBlock = None | |
488 |
|
494 | |||
489 | blocksPerFile = None |
|
495 | blocksPerFile = None | |
490 |
|
496 | |||
491 | nWriteBlocks = 0 |
|
497 | nWriteBlocks = 0 | |
492 |
|
498 | |||
493 | def __init__(self, dataOutObj=None): |
|
499 | def __init__(self, dataOutObj=None): | |
494 | raise ValueError, "Not implemented" |
|
500 | raise ValueError, "Not implemented" | |
495 |
|
501 | |||
496 |
|
502 | |||
497 | def hasAllDataInBuffer(self): |
|
503 | def hasAllDataInBuffer(self): | |
498 | raise ValueError, "Not implemented" |
|
504 | raise ValueError, "Not implemented" | |
499 |
|
505 | |||
500 |
|
506 | |||
501 | def setBlockDimension(self): |
|
507 | def setBlockDimension(self): | |
502 | raise ValueError, "Not implemented" |
|
508 | raise ValueError, "Not implemented" | |
503 |
|
509 | |||
504 |
|
510 | |||
505 | def writeBlock(self): |
|
511 | def writeBlock(self): | |
506 | raise ValueError, "No implemented" |
|
512 | raise ValueError, "No implemented" | |
507 |
|
513 | |||
508 |
|
514 | |||
509 | def putData(self): |
|
515 | def putData(self): | |
510 | raise ValueError, "No implemented" |
|
516 | raise ValueError, "No implemented" | |
511 |
|
517 | |||
512 |
|
518 | |||
513 | def __writeFirstHeader(self): |
|
519 | def __writeFirstHeader(self): | |
514 | """ |
|
520 | """ | |
515 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
521 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
516 |
|
522 | |||
517 | Affected: |
|
523 | Affected: | |
518 | __dataType |
|
524 | __dataType | |
519 |
|
525 | |||
520 | Return: |
|
526 | Return: | |
521 | None |
|
527 | None | |
522 | """ |
|
528 | """ | |
523 |
|
529 | |||
524 | # CALCULAR PARAMETROS |
|
530 | # CALCULAR PARAMETROS | |
525 |
|
531 | |||
526 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
532 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
527 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
533 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
528 |
|
534 | |||
529 | self.__writeBasicHeader() |
|
535 | self.__writeBasicHeader() | |
530 | self.__wrSystemHeader() |
|
536 | self.__wrSystemHeader() | |
531 | self.__wrRadarControllerHeader() |
|
537 | self.__wrRadarControllerHeader() | |
532 | self.__wrProcessingHeader() |
|
538 | self.__wrProcessingHeader() | |
533 | self.dtype = self.dataOutObj.dtype |
|
539 | self.dtype = self.dataOutObj.dtype | |
534 |
|
540 | |||
535 |
|
541 | |||
536 | def __writeBasicHeader(self, fp=None): |
|
542 | def __writeBasicHeader(self, fp=None): | |
537 | """ |
|
543 | """ | |
538 | Escribe solo el Basic header en el file creado |
|
544 | Escribe solo el Basic header en el file creado | |
539 |
|
545 | |||
540 | Return: |
|
546 | Return: | |
541 | None |
|
547 | None | |
542 | """ |
|
548 | """ | |
543 | if fp == None: |
|
549 | if fp == None: | |
544 | fp = self.fp |
|
550 | fp = self.fp | |
545 |
|
551 | |||
546 | self.basicHeaderObj.write(fp) |
|
552 | self.basicHeaderObj.write(fp) | |
547 |
|
553 | |||
548 |
|
554 | |||
549 | def __wrSystemHeader(self, fp=None): |
|
555 | def __wrSystemHeader(self, fp=None): | |
550 | """ |
|
556 | """ | |
551 | Escribe solo el System header en el file creado |
|
557 | Escribe solo el System header en el file creado | |
552 |
|
558 | |||
553 | Return: |
|
559 | Return: | |
554 | None |
|
560 | None | |
555 | """ |
|
561 | """ | |
556 | if fp == None: |
|
562 | if fp == None: | |
557 | fp = self.fp |
|
563 | fp = self.fp | |
558 |
|
564 | |||
559 | self.systemHeaderObj.write(fp) |
|
565 | self.systemHeaderObj.write(fp) | |
560 |
|
566 | |||
561 |
|
567 | |||
562 | def __wrRadarControllerHeader(self, fp=None): |
|
568 | def __wrRadarControllerHeader(self, fp=None): | |
563 | """ |
|
569 | """ | |
564 | Escribe solo el RadarController header en el file creado |
|
570 | Escribe solo el RadarController header en el file creado | |
565 |
|
571 | |||
566 | Return: |
|
572 | Return: | |
567 | None |
|
573 | None | |
568 | """ |
|
574 | """ | |
569 | if fp == None: |
|
575 | if fp == None: | |
570 | fp = self.fp |
|
576 | fp = self.fp | |
571 |
|
577 | |||
572 | self.radarControllerHeaderObj.write(fp) |
|
578 | self.radarControllerHeaderObj.write(fp) | |
573 |
|
579 | |||
574 |
|
580 | |||
575 | def __wrProcessingHeader(self, fp=None): |
|
581 | def __wrProcessingHeader(self, fp=None): | |
576 | """ |
|
582 | """ | |
577 | Escribe solo el Processing header en el file creado |
|
583 | Escribe solo el Processing header en el file creado | |
578 |
|
584 | |||
579 | Return: |
|
585 | Return: | |
580 | None |
|
586 | None | |
581 | """ |
|
587 | """ | |
582 | if fp == None: |
|
588 | if fp == None: | |
583 | fp = self.fp |
|
589 | fp = self.fp | |
584 |
|
590 | |||
585 | self.processingHeaderObj.write(fp) |
|
591 | self.processingHeaderObj.write(fp) | |
586 |
|
592 | |||
587 |
|
593 | |||
588 | def setNextFile(self): |
|
594 | def setNextFile(self): | |
589 | """ |
|
595 | """ | |
590 | Determina el siguiente file que sera escrito |
|
596 | Determina el siguiente file que sera escrito | |
591 |
|
597 | |||
592 | Affected: |
|
598 | Affected: | |
593 | self.filename |
|
599 | self.filename | |
594 | self.subfolder |
|
600 | self.subfolder | |
595 | self.fp |
|
601 | self.fp | |
596 | self.setFile |
|
602 | self.setFile | |
597 | self.flagIsNewFile |
|
603 | self.flagIsNewFile | |
598 |
|
604 | |||
599 | Return: |
|
605 | Return: | |
600 | 0 : Si el archivo no puede ser escrito |
|
606 | 0 : Si el archivo no puede ser escrito | |
601 | 1 : Si el archivo esta listo para ser escrito |
|
607 | 1 : Si el archivo esta listo para ser escrito | |
602 | """ |
|
608 | """ | |
603 | ext = self.ext |
|
609 | ext = self.ext | |
604 | path = self.path |
|
610 | path = self.path | |
605 |
|
611 | |||
606 | if self.fp != None: |
|
612 | if self.fp != None: | |
607 | self.fp.close() |
|
613 | self.fp.close() | |
608 |
|
614 | |||
609 | timeTuple = time.localtime( self.dataOutObj.dataUtcTime) |
|
615 | timeTuple = time.localtime( self.dataOutObj.dataUtcTime) | |
610 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
616 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
611 |
|
617 | |||
612 | doypath = os.path.join( path, subfolder ) |
|
618 | doypath = os.path.join( path, subfolder ) | |
613 | if not( os.path.exists(doypath) ): |
|
619 | if not( os.path.exists(doypath) ): | |
614 | os.mkdir(doypath) |
|
620 | os.mkdir(doypath) | |
615 | self.setFile = -1 #inicializo mi contador de seteo |
|
621 | self.setFile = -1 #inicializo mi contador de seteo | |
616 | else: |
|
622 | else: | |
617 | filesList = os.listdir( doypath ) |
|
623 | filesList = os.listdir( doypath ) | |
618 | if len( filesList ) > 0: |
|
624 | if len( filesList ) > 0: | |
619 | filesList = sorted( filesList, key=str.lower ) |
|
625 | filesList = sorted( filesList, key=str.lower ) | |
620 | filen = filesList[-1] |
|
626 | filen = filesList[-1] | |
621 | # el filename debera tener el siguiente formato |
|
627 | # el filename debera tener el siguiente formato | |
622 | # 0 1234 567 89A BCDE (hex) |
|
628 | # 0 1234 567 89A BCDE (hex) | |
623 | # x YYYY DDD SSS .ext |
|
629 | # x YYYY DDD SSS .ext | |
624 | if isNumber( filen[8:11] ): |
|
630 | if isNumber( filen[8:11] ): | |
625 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
631 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
626 | else: |
|
632 | else: | |
627 | self.setFile = -1 |
|
633 | self.setFile = -1 | |
628 | else: |
|
634 | else: | |
629 | self.setFile = -1 #inicializo mi contador de seteo |
|
635 | self.setFile = -1 #inicializo mi contador de seteo | |
630 |
|
636 | |||
631 | setFile = self.setFile |
|
637 | setFile = self.setFile | |
632 | setFile += 1 |
|
638 | setFile += 1 | |
633 |
|
639 | |||
634 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
640 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
635 | timeTuple.tm_year, |
|
641 | timeTuple.tm_year, | |
636 | timeTuple.tm_yday, |
|
642 | timeTuple.tm_yday, | |
637 | setFile, |
|
643 | setFile, | |
638 | ext ) |
|
644 | ext ) | |
639 |
|
645 | |||
640 | filename = os.path.join( path, subfolder, file ) |
|
646 | filename = os.path.join( path, subfolder, file ) | |
641 |
|
647 | |||
642 | fp = open( filename,'wb' ) |
|
648 | fp = open( filename,'wb' ) | |
643 |
|
649 | |||
644 | self.blockIndex = 0 |
|
650 | self.blockIndex = 0 | |
645 |
|
651 | |||
646 | #guardando atributos |
|
652 | #guardando atributos | |
647 | self.filename = filename |
|
653 | self.filename = filename | |
648 | self.subfolder = subfolder |
|
654 | self.subfolder = subfolder | |
649 | self.fp = fp |
|
655 | self.fp = fp | |
650 | self.setFile = setFile |
|
656 | self.setFile = setFile | |
651 | self.flagIsNewFile = 1 |
|
657 | self.flagIsNewFile = 1 | |
652 |
|
658 | |||
653 | self.getDataHeader() |
|
659 | self.getDataHeader() | |
654 |
|
660 | |||
655 | print 'Writing the file: %s'%self.filename |
|
661 | print 'Writing the file: %s'%self.filename | |
656 |
|
662 | |||
657 | self.__writeFirstHeader() |
|
663 | self.__writeFirstHeader() | |
658 |
|
664 | |||
659 | return 1 |
|
665 | return 1 | |
660 |
|
666 | |||
661 |
|
667 | |||
662 | def __setNewBlock(self): |
|
668 | def __setNewBlock(self): | |
663 | """ |
|
669 | """ | |
664 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
670 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
665 |
|
671 | |||
666 | Return: |
|
672 | Return: | |
667 | 0 : si no pudo escribir nada |
|
673 | 0 : si no pudo escribir nada | |
668 | 1 : Si escribio el Basic el First Header |
|
674 | 1 : Si escribio el Basic el First Header | |
669 | """ |
|
675 | """ | |
670 | if self.fp == None: |
|
676 | if self.fp == None: | |
671 | self.setNextFile() |
|
677 | self.setNextFile() | |
672 |
|
678 | |||
673 | if self.flagIsNewFile: |
|
679 | if self.flagIsNewFile: | |
674 | return 1 |
|
680 | return 1 | |
675 |
|
681 | |||
676 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
682 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
677 | self.__writeBasicHeader() |
|
683 | self.__writeBasicHeader() | |
678 | return 1 |
|
684 | return 1 | |
679 |
|
685 | |||
680 | if not( self.setNextFile() ): |
|
686 | if not( self.setNextFile() ): | |
681 | return 0 |
|
687 | return 0 | |
682 |
|
688 | |||
683 | return 1 |
|
689 | return 1 | |
684 |
|
690 | |||
685 |
|
691 | |||
686 | def writeNextBlock(self): |
|
692 | def writeNextBlock(self): | |
687 | """ |
|
693 | """ | |
688 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
694 | Selecciona el bloque siguiente de datos y los escribe en un file | |
689 |
|
695 | |||
690 | Return: |
|
696 | Return: | |
691 | 0 : Si no hizo pudo escribir el bloque de datos |
|
697 | 0 : Si no hizo pudo escribir el bloque de datos | |
692 | 1 : Si no pudo escribir el bloque de datos |
|
698 | 1 : Si no pudo escribir el bloque de datos | |
693 | """ |
|
699 | """ | |
694 | if not( self.__setNewBlock() ): |
|
700 | if not( self.__setNewBlock() ): | |
695 | return 0 |
|
701 | return 0 | |
696 |
|
702 | |||
697 | self.writeBlock() |
|
703 | self.writeBlock() | |
698 |
|
704 | |||
699 | return 1 |
|
705 | return 1 | |
700 |
|
706 | |||
701 |
|
707 | |||
702 | def getDataHeader(self): |
|
708 | def getDataHeader(self): | |
703 | """Obtiene una copia del First Header Affected: self.basicHeaderObj self. |
|
709 | """Obtiene una copia del First Header Affected: self.basicHeaderObj self. | |
704 | systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self. |
|
710 | systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self. | |
705 | dtype Return: None |
|
711 | dtype Return: None | |
706 | """ |
|
712 | """ | |
707 |
|
713 | |||
708 | raise ValueError, "No implemented" |
|
714 | raise ValueError, "No implemented" | |
709 |
|
715 | |||
710 |
def setup(self, path, |
|
716 | def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
711 | """ |
|
717 | """ | |
712 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
718 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
713 |
|
719 | |||
714 | Inputs: |
|
720 | Inputs: | |
715 | path : el path destino en el cual se escribiran los files a crear |
|
721 | path : el path destino en el cual se escribiran los files a crear | |
716 | format : formato en el cual sera salvado un file |
|
722 | format : formato en el cual sera salvado un file | |
717 | set : el setebo del file |
|
723 | set : el setebo del file | |
718 |
|
724 | |||
719 | Return: |
|
725 | Return: | |
720 | 0 : Si no realizo un buen seteo |
|
726 | 0 : Si no realizo un buen seteo | |
721 | 1 : Si realizo un buen seteo |
|
727 | 1 : Si realizo un buen seteo | |
722 | """ |
|
728 | """ | |
723 |
|
729 | |||
724 | if ext == None: |
|
730 | if ext == None: | |
725 | ext = self.ext |
|
731 | ext = self.ext | |
726 |
|
732 | |||
727 | ext = ext.lower() |
|
733 | ext = ext.lower() | |
728 |
|
734 | |||
729 | self.ext = ext |
|
735 | self.ext = ext | |
730 |
|
736 | |||
731 | self.path = path |
|
737 | self.path = path | |
732 |
|
738 | |||
733 | self.setFile = set - 1 |
|
739 | self.setFile = set - 1 | |
734 |
|
740 | |||
735 | self.profilesPerBlock = profilesPerBlock |
|
|||
736 |
|
||||
737 | self.blocksPerFile = blocksPerFile |
|
741 | self.blocksPerFile = blocksPerFile | |
738 |
|
742 | |||
|
743 | self.profilesPerBlock = profilesPerBlock | |||
|
744 | ||||
739 | if not(self.setNextFile()): |
|
745 | if not(self.setNextFile()): | |
740 | print "There isn't a next file" |
|
746 | print "There isn't a next file" | |
741 | return 0 |
|
747 | return 0 | |
742 |
|
748 | |||
743 | self.setBlockDimension() |
|
749 | self.setBlockDimension() | |
744 |
|
750 | |||
745 | return 1 |
|
751 | return 1 | |
746 |
|
752 | |||
747 |
|
753 | |||
748 |
|
754 | |||
749 |
|
755 | |||
750 |
|
756 | |||
751 |
|
757 |
@@ -1,506 +1,505 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
|||
3 |
|
2 | |||
4 | @author $Author: vsarmiento $ |
|
3 | $Author$ | |
5 | @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $ |
|
4 | $Id$ | |
6 | ''' |
|
5 | ''' | |
7 |
|
6 | |||
8 | import numpy |
|
7 | import numpy | |
9 | import copy |
|
8 | import copy | |
10 |
|
9 | |||
11 | class Header: |
|
10 | class Header: | |
12 |
|
11 | |||
13 | def __init__(self): |
|
12 | def __init__(self): | |
14 | raise |
|
13 | raise | |
15 |
|
14 | |||
16 | def copy(self): |
|
15 | def copy(self): | |
17 | return copy.deepcopy(self) |
|
16 | return copy.deepcopy(self) | |
18 |
|
17 | |||
19 | def read(): |
|
18 | def read(): | |
20 | pass |
|
19 | pass | |
21 |
|
20 | |||
22 | def write(): |
|
21 | def write(): | |
23 | pass |
|
22 | pass | |
24 |
|
23 | |||
25 | class BasicHeader(Header): |
|
24 | class BasicHeader(Header): | |
26 |
|
25 | |||
27 | size = None |
|
26 | size = None | |
28 | version = None |
|
27 | version = None | |
29 | dataBlock = None |
|
28 | dataBlock = None | |
30 | utc = None |
|
29 | utc = None | |
31 | miliSecond = None |
|
30 | miliSecond = None | |
32 | timeZone = None |
|
31 | timeZone = None | |
33 | dstFlag = None |
|
32 | dstFlag = None | |
34 | errorCount = None |
|
33 | errorCount = None | |
35 | struct = None |
|
34 | struct = None | |
36 |
|
35 | |||
37 | def __init__(self): |
|
36 | def __init__(self): | |
38 |
|
37 | |||
39 | self.size = 0 |
|
38 | self.size = 0 | |
40 | self.version = 0 |
|
39 | self.version = 0 | |
41 | self.dataBlock = 0 |
|
40 | self.dataBlock = 0 | |
42 | self.utc = 0 |
|
41 | self.utc = 0 | |
43 | self.miliSecond = 0 |
|
42 | self.miliSecond = 0 | |
44 | self.timeZone = 0 |
|
43 | self.timeZone = 0 | |
45 | self.dstFlag = 0 |
|
44 | self.dstFlag = 0 | |
46 | self.errorCount = 0 |
|
45 | self.errorCount = 0 | |
47 | self.struct = numpy.dtype([ |
|
46 | self.struct = numpy.dtype([ | |
48 | ('nSize','<u4'), |
|
47 | ('nSize','<u4'), | |
49 | ('nVersion','<u2'), |
|
48 | ('nVersion','<u2'), | |
50 | ('nDataBlockId','<u4'), |
|
49 | ('nDataBlockId','<u4'), | |
51 | ('nUtime','<u4'), |
|
50 | ('nUtime','<u4'), | |
52 | ('nMilsec','<u2'), |
|
51 | ('nMilsec','<u2'), | |
53 | ('nTimezone','<i2'), |
|
52 | ('nTimezone','<i2'), | |
54 | ('nDstflag','<i2'), |
|
53 | ('nDstflag','<i2'), | |
55 | ('nErrorCount','<u4') |
|
54 | ('nErrorCount','<u4') | |
56 | ]) |
|
55 | ]) | |
57 |
|
56 | |||
58 |
|
57 | |||
59 | def read(self, fp): |
|
58 | def read(self, fp): | |
60 | try: |
|
59 | try: | |
61 | header = numpy.fromfile(fp, self.struct,1) |
|
60 | header = numpy.fromfile(fp, self.struct,1) | |
62 | self.size = header['nSize'][0] |
|
61 | self.size = header['nSize'][0] | |
63 | self.version = header['nVersion'][0] |
|
62 | self.version = header['nVersion'][0] | |
64 | self.dataBlock = header['nDataBlockId'][0] |
|
63 | self.dataBlock = header['nDataBlockId'][0] | |
65 | self.utc = header['nUtime'][0] |
|
64 | self.utc = header['nUtime'][0] | |
66 | self.miliSecond = header['nMilsec'][0] |
|
65 | self.miliSecond = header['nMilsec'][0] | |
67 | self.timeZone = header['nTimezone'][0] |
|
66 | self.timeZone = header['nTimezone'][0] | |
68 | self.dstFlag = header['nDstflag'][0] |
|
67 | self.dstFlag = header['nDstflag'][0] | |
69 | self.errorCount = header['nErrorCount'][0] |
|
68 | self.errorCount = header['nErrorCount'][0] | |
70 | except: |
|
69 | except: | |
71 | return 0 |
|
70 | return 0 | |
72 |
|
71 | |||
73 | return 1 |
|
72 | return 1 | |
74 |
|
73 | |||
75 | def write(self, fp): |
|
74 | def write(self, fp): | |
76 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
75 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) | |
77 | header = numpy.array(headerTuple,self.struct) |
|
76 | header = numpy.array(headerTuple,self.struct) | |
78 | header.tofile(fp) |
|
77 | header.tofile(fp) | |
79 |
|
78 | |||
80 | return 1 |
|
79 | return 1 | |
81 |
|
80 | |||
82 | class SystemHeader(Header): |
|
81 | class SystemHeader(Header): | |
83 |
|
82 | |||
84 | size = None |
|
83 | size = None | |
85 | nSamples = None |
|
84 | nSamples = None | |
86 | nProfiles = None |
|
85 | nProfiles = None | |
87 | nChannels = None |
|
86 | nChannels = None | |
88 | adcResolution = None |
|
87 | adcResolution = None | |
89 | pciDioBusWidth = None |
|
88 | pciDioBusWidth = None | |
90 | struct = None |
|
89 | struct = None | |
91 |
|
90 | |||
92 | def __init__(self): |
|
91 | def __init__(self): | |
93 | self.size = 0 |
|
92 | self.size = 0 | |
94 | self.nSamples = 0 |
|
93 | self.nSamples = 0 | |
95 | self.nProfiles = 0 |
|
94 | self.nProfiles = 0 | |
96 | self.nChannels = 0 |
|
95 | self.nChannels = 0 | |
97 | self.adcResolution = 0 |
|
96 | self.adcResolution = 0 | |
98 | self.pciDioBusWidth = 0 |
|
97 | self.pciDioBusWidth = 0 | |
99 | self.struct = numpy.dtype([ |
|
98 | self.struct = numpy.dtype([ | |
100 | ('nSize','<u4'), |
|
99 | ('nSize','<u4'), | |
101 | ('nNumSamples','<u4'), |
|
100 | ('nNumSamples','<u4'), | |
102 | ('nNumProfiles','<u4'), |
|
101 | ('nNumProfiles','<u4'), | |
103 | ('nNumChannels','<u4'), |
|
102 | ('nNumChannels','<u4'), | |
104 | ('nADCResolution','<u4'), |
|
103 | ('nADCResolution','<u4'), | |
105 | ('nPCDIOBusWidth','<u4'), |
|
104 | ('nPCDIOBusWidth','<u4'), | |
106 | ]) |
|
105 | ]) | |
107 |
|
106 | |||
108 |
|
107 | |||
109 | def read(self, fp): |
|
108 | def read(self, fp): | |
110 | try: |
|
109 | try: | |
111 | header = numpy.fromfile(fp,self.struct,1) |
|
110 | header = numpy.fromfile(fp,self.struct,1) | |
112 | self.size = header['nSize'][0] |
|
111 | self.size = header['nSize'][0] | |
113 | self.nSamples = header['nNumSamples'][0] |
|
112 | self.nSamples = header['nNumSamples'][0] | |
114 | self.nProfiles = header['nNumProfiles'][0] |
|
113 | self.nProfiles = header['nNumProfiles'][0] | |
115 | self.nChannels = header['nNumChannels'][0] |
|
114 | self.nChannels = header['nNumChannels'][0] | |
116 | self.adcResolution = header['nADCResolution'][0] |
|
115 | self.adcResolution = header['nADCResolution'][0] | |
117 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
116 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
118 | except: |
|
117 | except: | |
119 | return 0 |
|
118 | return 0 | |
120 |
|
119 | |||
121 | return 1 |
|
120 | return 1 | |
122 |
|
121 | |||
123 | def write(self, fp): |
|
122 | def write(self, fp): | |
124 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
123 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) | |
125 | header = numpy.array(headerTuple,self.struct) |
|
124 | header = numpy.array(headerTuple,self.struct) | |
126 | header.tofile(fp) |
|
125 | header.tofile(fp) | |
127 |
|
126 | |||
128 | return 1 |
|
127 | return 1 | |
129 |
|
128 | |||
130 | class RadarControllerHeader(Header): |
|
129 | class RadarControllerHeader(Header): | |
131 |
|
130 | |||
132 | size = None |
|
131 | size = None | |
133 | expType = None |
|
132 | expType = None | |
134 | nTx = None |
|
133 | nTx = None | |
135 | ipp = None |
|
134 | ipp = None | |
136 | txA = None |
|
135 | txA = None | |
137 | txB = None |
|
136 | txB = None | |
138 | nWindows = None |
|
137 | nWindows = None | |
139 | numTaus = None |
|
138 | numTaus = None | |
140 | codeType = None |
|
139 | codeType = None | |
141 | line6Function = None |
|
140 | line6Function = None | |
142 | line5Function = None |
|
141 | line5Function = None | |
143 | fClock = None |
|
142 | fClock = None | |
144 | prePulseBefore = None |
|
143 | prePulseBefore = None | |
145 | prePulserAfter = None |
|
144 | prePulserAfter = None | |
146 | rangeIpp = None |
|
145 | rangeIpp = None | |
147 | rangeTxA = None |
|
146 | rangeTxA = None | |
148 | rangeTxB = None |
|
147 | rangeTxB = None | |
149 | struct = None |
|
148 | struct = None | |
150 |
|
149 | |||
151 | def __init__(self): |
|
150 | def __init__(self): | |
152 | self.size = 0 |
|
151 | self.size = 0 | |
153 | self.expType = 0 |
|
152 | self.expType = 0 | |
154 | self.nTx = 0 |
|
153 | self.nTx = 0 | |
155 | self.ipp = 0 |
|
154 | self.ipp = 0 | |
156 | self.txA = 0 |
|
155 | self.txA = 0 | |
157 | self.txB = 0 |
|
156 | self.txB = 0 | |
158 | self.nWindows = 0 |
|
157 | self.nWindows = 0 | |
159 | self.numTaus = 0 |
|
158 | self.numTaus = 0 | |
160 | self.codeType = 0 |
|
159 | self.codeType = 0 | |
161 | self.line6Function = 0 |
|
160 | self.line6Function = 0 | |
162 | self.line5Function = 0 |
|
161 | self.line5Function = 0 | |
163 | self.fClock = 0 |
|
162 | self.fClock = 0 | |
164 | self.prePulseBefore = 0 |
|
163 | self.prePulseBefore = 0 | |
165 | self.prePulserAfter = 0 |
|
164 | self.prePulserAfter = 0 | |
166 | self.rangeIpp = 0 |
|
165 | self.rangeIpp = 0 | |
167 | self.rangeTxA = 0 |
|
166 | self.rangeTxA = 0 | |
168 | self.rangeTxB = 0 |
|
167 | self.rangeTxB = 0 | |
169 | self.struct = numpy.dtype([ |
|
168 | self.struct = numpy.dtype([ | |
170 | ('nSize','<u4'), |
|
169 | ('nSize','<u4'), | |
171 | ('nExpType','<u4'), |
|
170 | ('nExpType','<u4'), | |
172 | ('nNTx','<u4'), |
|
171 | ('nNTx','<u4'), | |
173 | ('fIpp','<f4'), |
|
172 | ('fIpp','<f4'), | |
174 | ('fTxA','<f4'), |
|
173 | ('fTxA','<f4'), | |
175 | ('fTxB','<f4'), |
|
174 | ('fTxB','<f4'), | |
176 | ('nNumWindows','<u4'), |
|
175 | ('nNumWindows','<u4'), | |
177 | ('nNumTaus','<u4'), |
|
176 | ('nNumTaus','<u4'), | |
178 | ('nCodeType','<u4'), |
|
177 | ('nCodeType','<u4'), | |
179 | ('nLine6Function','<u4'), |
|
178 | ('nLine6Function','<u4'), | |
180 | ('nLine5Function','<u4'), |
|
179 | ('nLine5Function','<u4'), | |
181 | ('fClock','<f4'), |
|
180 | ('fClock','<f4'), | |
182 | ('nPrePulseBefore','<u4'), |
|
181 | ('nPrePulseBefore','<u4'), | |
183 | ('nPrePulseAfter','<u4'), |
|
182 | ('nPrePulseAfter','<u4'), | |
184 | ('sRangeIPP','<a20'), |
|
183 | ('sRangeIPP','<a20'), | |
185 | ('sRangeTxA','<a20'), |
|
184 | ('sRangeTxA','<a20'), | |
186 | ('sRangeTxB','<a20'), |
|
185 | ('sRangeTxB','<a20'), | |
187 | ]) |
|
186 | ]) | |
188 |
|
187 | |||
189 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
188 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
190 |
|
189 | |||
191 | self.samplingWindow = None |
|
190 | self.samplingWindow = None | |
192 | self.nHeights = None |
|
191 | self.nHeights = None | |
193 | self.firstHeight = None |
|
192 | self.firstHeight = None | |
194 | self.deltaHeight = None |
|
193 | self.deltaHeight = None | |
195 | self.samplesWin = None |
|
194 | self.samplesWin = None | |
196 |
|
195 | |||
197 | self.nCode = None |
|
196 | self.nCode = None | |
198 | self.nBaud = None |
|
197 | self.nBaud = None | |
199 | self.code = None |
|
198 | self.code = None | |
200 | self.flip1 = None |
|
199 | self.flip1 = None | |
201 | self.flip2 = None |
|
200 | self.flip2 = None | |
202 |
|
201 | |||
203 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
202 | self.dynamic = numpy.array([],numpy.dtype('byte')) | |
204 |
|
203 | |||
205 |
|
204 | |||
206 | def read(self, fp): |
|
205 | def read(self, fp): | |
207 | try: |
|
206 | try: | |
208 | startFp = fp.tell() |
|
207 | startFp = fp.tell() | |
209 | header = numpy.fromfile(fp,self.struct,1) |
|
208 | header = numpy.fromfile(fp,self.struct,1) | |
210 | self.size = header['nSize'][0] |
|
209 | self.size = header['nSize'][0] | |
211 | self.expType = header['nExpType'][0] |
|
210 | self.expType = header['nExpType'][0] | |
212 | self.nTx = header['nNTx'][0] |
|
211 | self.nTx = header['nNTx'][0] | |
213 | self.ipp = header['fIpp'][0] |
|
212 | self.ipp = header['fIpp'][0] | |
214 | self.txA = header['fTxA'][0] |
|
213 | self.txA = header['fTxA'][0] | |
215 | self.txB = header['fTxB'][0] |
|
214 | self.txB = header['fTxB'][0] | |
216 | self.nWindows = header['nNumWindows'][0] |
|
215 | self.nWindows = header['nNumWindows'][0] | |
217 | self.numTaus = header['nNumTaus'][0] |
|
216 | self.numTaus = header['nNumTaus'][0] | |
218 | self.codeType = header['nCodeType'][0] |
|
217 | self.codeType = header['nCodeType'][0] | |
219 | self.line6Function = header['nLine6Function'][0] |
|
218 | self.line6Function = header['nLine6Function'][0] | |
220 | self.line5Function = header['nLine5Function'][0] |
|
219 | self.line5Function = header['nLine5Function'][0] | |
221 | self.fClock = header['fClock'][0] |
|
220 | self.fClock = header['fClock'][0] | |
222 | self.prePulseBefore = header['nPrePulseBefore'][0] |
|
221 | self.prePulseBefore = header['nPrePulseBefore'][0] | |
223 | self.prePulserAfter = header['nPrePulseAfter'][0] |
|
222 | self.prePulserAfter = header['nPrePulseAfter'][0] | |
224 | self.rangeIpp = header['sRangeIPP'][0] |
|
223 | self.rangeIpp = header['sRangeIPP'][0] | |
225 | self.rangeTxA = header['sRangeTxA'][0] |
|
224 | self.rangeTxA = header['sRangeTxA'][0] | |
226 | self.rangeTxB = header['sRangeTxB'][0] |
|
225 | self.rangeTxB = header['sRangeTxB'][0] | |
227 | # jump Dynamic Radar Controller Header |
|
226 | # jump Dynamic Radar Controller Header | |
228 | jumpFp = self.size - 116 |
|
227 | jumpFp = self.size - 116 | |
229 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
228 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) | |
230 | #pointer backward to dynamic header and read |
|
229 | #pointer backward to dynamic header and read | |
231 | backFp = fp.tell() - jumpFp |
|
230 | backFp = fp.tell() - jumpFp | |
232 | fp.seek(backFp) |
|
231 | fp.seek(backFp) | |
233 |
|
232 | |||
234 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) |
|
233 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) | |
235 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) |
|
234 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) | |
236 | self.firstHeight = self.samplingWindow['h0'] |
|
235 | self.firstHeight = self.samplingWindow['h0'] | |
237 | self.deltaHeight = self.samplingWindow['dh'] |
|
236 | self.deltaHeight = self.samplingWindow['dh'] | |
238 | self.samplesWin = self.samplingWindow['nsa'] |
|
237 | self.samplesWin = self.samplingWindow['nsa'] | |
239 |
|
238 | |||
240 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
239 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) | |
241 |
|
240 | |||
242 | if self.codeType != 0: |
|
241 | if self.codeType != 0: | |
243 | self.nCode = numpy.fromfile(fp,'<u4',1) |
|
242 | self.nCode = numpy.fromfile(fp,'<u4',1) | |
244 | self.nBaud = numpy.fromfile(fp,'<u4',1) |
|
243 | self.nBaud = numpy.fromfile(fp,'<u4',1) | |
245 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') |
|
244 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') | |
246 | tempList = [] |
|
245 | tempList = [] | |
247 | for ic in range(self.nCode): |
|
246 | for ic in range(self.nCode): | |
248 | temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.)) |
|
247 | temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.)) | |
249 | tempList.append(temp) |
|
248 | tempList.append(temp) | |
250 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] |
|
249 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] | |
251 | self.code = 2.0*self.code - 1.0 |
|
250 | self.code = 2.0*self.code - 1.0 | |
252 |
|
251 | |||
253 | if self.line5Function == RCfunction.FLIP: |
|
252 | if self.line5Function == RCfunction.FLIP: | |
254 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
253 | self.flip1 = numpy.fromfile(fp,'<u4',1) | |
255 |
|
254 | |||
256 | if self.line6Function == RCfunction.FLIP: |
|
255 | if self.line6Function == RCfunction.FLIP: | |
257 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
256 | self.flip2 = numpy.fromfile(fp,'<u4',1) | |
258 |
|
257 | |||
259 | endFp = self.size + startFp |
|
258 | endFp = self.size + startFp | |
260 | jumpFp = endFp - fp.tell() |
|
259 | jumpFp = endFp - fp.tell() | |
261 | if jumpFp > 0: |
|
260 | if jumpFp > 0: | |
262 | fp.seek(jumpFp) |
|
261 | fp.seek(jumpFp) | |
263 |
|
262 | |||
264 | except: |
|
263 | except: | |
265 | return 0 |
|
264 | return 0 | |
266 |
|
265 | |||
267 | return 1 |
|
266 | return 1 | |
268 |
|
267 | |||
269 | def write(self, fp): |
|
268 | def write(self, fp): | |
270 | headerTuple = (self.size, |
|
269 | headerTuple = (self.size, | |
271 | self.expType, |
|
270 | self.expType, | |
272 | self.nTx, |
|
271 | self.nTx, | |
273 | self.ipp, |
|
272 | self.ipp, | |
274 | self.txA, |
|
273 | self.txA, | |
275 | self.txB, |
|
274 | self.txB, | |
276 | self.nWindows, |
|
275 | self.nWindows, | |
277 | self.numTaus, |
|
276 | self.numTaus, | |
278 | self.codeType, |
|
277 | self.codeType, | |
279 | self.line6Function, |
|
278 | self.line6Function, | |
280 | self.line5Function, |
|
279 | self.line5Function, | |
281 | self.fClock, |
|
280 | self.fClock, | |
282 | self.prePulseBefore, |
|
281 | self.prePulseBefore, | |
283 | self.prePulserAfter, |
|
282 | self.prePulserAfter, | |
284 | self.rangeIpp, |
|
283 | self.rangeIpp, | |
285 | self.rangeTxA, |
|
284 | self.rangeTxA, | |
286 | self.rangeTxB) |
|
285 | self.rangeTxB) | |
287 |
|
286 | |||
288 | header = numpy.array(headerTuple,self.struct) |
|
287 | header = numpy.array(headerTuple,self.struct) | |
289 | header.tofile(fp) |
|
288 | header.tofile(fp) | |
290 |
|
289 | |||
291 | dynamic = self.dynamic |
|
290 | dynamic = self.dynamic | |
292 | dynamic.tofile(fp) |
|
291 | dynamic.tofile(fp) | |
293 |
|
292 | |||
294 | return 1 |
|
293 | return 1 | |
295 |
|
294 | |||
296 |
|
295 | |||
297 |
|
296 | |||
298 | class ProcessingHeader(Header): |
|
297 | class ProcessingHeader(Header): | |
299 |
|
298 | |||
300 | size = None |
|
299 | size = None | |
301 | dtype = None |
|
300 | dtype = None | |
302 | blockSize = None |
|
301 | blockSize = None | |
303 | profilesPerBlock = None |
|
302 | profilesPerBlock = None | |
304 | dataBlocksPerFile = None |
|
303 | dataBlocksPerFile = None | |
305 | nWindows = None |
|
304 | nWindows = None | |
306 | processFlags = None |
|
305 | processFlags = None | |
307 | nCohInt = None |
|
306 | nCohInt = None | |
308 | nIncohInt = None |
|
307 | nIncohInt = None | |
309 | totalSpectra = None |
|
308 | totalSpectra = None | |
310 | struct = None |
|
309 | struct = None | |
311 | flag_dc = None |
|
310 | flag_dc = None | |
312 | flag_cspc = None |
|
311 | flag_cspc = None | |
313 |
|
312 | |||
314 | def __init__(self): |
|
313 | def __init__(self): | |
315 | self.size = 0 |
|
314 | self.size = 0 | |
316 | self.dataType = 0 |
|
315 | self.dataType = 0 | |
317 | self.blockSize = 0 |
|
316 | self.blockSize = 0 | |
318 | self.profilesPerBlock = 0 |
|
317 | self.profilesPerBlock = 0 | |
319 | self.dataBlocksPerFile = 0 |
|
318 | self.dataBlocksPerFile = 0 | |
320 | self.nWindows = 0 |
|
319 | self.nWindows = 0 | |
321 | self.processFlags = 0 |
|
320 | self.processFlags = 0 | |
322 | self.nCohInt = 0 |
|
321 | self.nCohInt = 0 | |
323 | self.nIncohInt = 0 |
|
322 | self.nIncohInt = 0 | |
324 | self.totalSpectra = 0 |
|
323 | self.totalSpectra = 0 | |
325 | self.struct = numpy.dtype([ |
|
324 | self.struct = numpy.dtype([ | |
326 | ('nSize','<u4'), |
|
325 | ('nSize','<u4'), | |
327 | ('nDataType','<u4'), |
|
326 | ('nDataType','<u4'), | |
328 | ('nSizeOfDataBlock','<u4'), |
|
327 | ('nSizeOfDataBlock','<u4'), | |
329 | ('nProfilesperBlock','<u4'), |
|
328 | ('nProfilesperBlock','<u4'), | |
330 | ('nDataBlocksperFile','<u4'), |
|
329 | ('nDataBlocksperFile','<u4'), | |
331 | ('nNumWindows','<u4'), |
|
330 | ('nNumWindows','<u4'), | |
332 | ('nProcessFlags','<u4'), |
|
331 | ('nProcessFlags','<u4'), | |
333 | ('nCoherentIntegrations','<u4'), |
|
332 | ('nCoherentIntegrations','<u4'), | |
334 | ('nIncoherentIntegrations','<u4'), |
|
333 | ('nIncoherentIntegrations','<u4'), | |
335 | ('nTotalSpectra','<u4') |
|
334 | ('nTotalSpectra','<u4') | |
336 | ]) |
|
335 | ]) | |
337 | self.samplingWindow = 0 |
|
336 | self.samplingWindow = 0 | |
338 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
337 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
339 | self.nHeights = 0 |
|
338 | self.nHeights = 0 | |
340 | self.firstHeight = 0 |
|
339 | self.firstHeight = 0 | |
341 | self.deltaHeight = 0 |
|
340 | self.deltaHeight = 0 | |
342 | self.samplesWin = 0 |
|
341 | self.samplesWin = 0 | |
343 | self.spectraComb = 0 |
|
342 | self.spectraComb = 0 | |
344 | self.nCode = None |
|
343 | self.nCode = None | |
345 | self.code = None |
|
344 | self.code = None | |
346 | self.nBaud = None |
|
345 | self.nBaud = None | |
347 | self.shif_fft = False |
|
346 | self.shif_fft = False | |
348 | self.flag_dc = False |
|
347 | self.flag_dc = False | |
349 | self.flag_cspc = False |
|
348 | self.flag_cspc = False | |
350 |
|
349 | |||
351 | def read(self, fp): |
|
350 | def read(self, fp): | |
352 | try: |
|
351 | try: | |
353 | header = numpy.fromfile(fp,self.struct,1) |
|
352 | header = numpy.fromfile(fp,self.struct,1) | |
354 | self.size = header['nSize'][0] |
|
353 | self.size = header['nSize'][0] | |
355 | self.dataType = header['nDataType'][0] |
|
354 | self.dataType = header['nDataType'][0] | |
356 | self.blockSize = header['nSizeOfDataBlock'][0] |
|
355 | self.blockSize = header['nSizeOfDataBlock'][0] | |
357 | self.profilesPerBlock = header['nProfilesperBlock'][0] |
|
356 | self.profilesPerBlock = header['nProfilesperBlock'][0] | |
358 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] |
|
357 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] | |
359 | self.nWindows = header['nNumWindows'][0] |
|
358 | self.nWindows = header['nNumWindows'][0] | |
360 | self.processFlags = header['nProcessFlags'] |
|
359 | self.processFlags = header['nProcessFlags'] | |
361 | self.nCohInt = header['nCoherentIntegrations'][0] |
|
360 | self.nCohInt = header['nCoherentIntegrations'][0] | |
362 | self.nIncohInt = header['nIncoherentIntegrations'][0] |
|
361 | self.nIncohInt = header['nIncoherentIntegrations'][0] | |
363 | self.totalSpectra = header['nTotalSpectra'][0] |
|
362 | self.totalSpectra = header['nTotalSpectra'][0] | |
364 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) |
|
363 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) | |
365 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) |
|
364 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) | |
366 | self.firstHeight = self.samplingWindow['h0'][0] |
|
365 | self.firstHeight = self.samplingWindow['h0'][0] | |
367 | self.deltaHeight = self.samplingWindow['dh'][0] |
|
366 | self.deltaHeight = self.samplingWindow['dh'][0] | |
368 | self.samplesWin = self.samplingWindow['nsa'] |
|
367 | self.samplesWin = self.samplingWindow['nsa'] | |
369 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
368 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
370 |
|
369 | |||
371 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
370 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
372 | self.nCode = numpy.fromfile(fp,'<u4',1) |
|
371 | self.nCode = numpy.fromfile(fp,'<u4',1) | |
373 | self.nBaud = numpy.fromfile(fp,'<u4',1) |
|
372 | self.nBaud = numpy.fromfile(fp,'<u4',1) | |
374 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) |
|
373 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) | |
375 |
|
374 | |||
376 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
375 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
377 | self.shif_fft = True |
|
376 | self.shif_fft = True | |
378 | else: |
|
377 | else: | |
379 | self.shif_fft = False |
|
378 | self.shif_fft = False | |
380 |
|
379 | |||
381 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
380 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
382 | self.flag_dc = True |
|
381 | self.flag_dc = True | |
383 |
|
382 | |||
384 | nChannels = 0 |
|
383 | nChannels = 0 | |
385 | nPairs = 0 |
|
384 | nPairs = 0 | |
386 | pairList = [] |
|
385 | pairList = [] | |
387 |
|
386 | |||
388 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
387 | for i in range( 0, self.totalSpectra*2, 2 ): | |
389 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
388 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
390 | nChannels = nChannels + 1 #par de canales iguales |
|
389 | nChannels = nChannels + 1 #par de canales iguales | |
391 | else: |
|
390 | else: | |
392 | nPairs = nPairs + 1 #par de canales diferentes |
|
391 | nPairs = nPairs + 1 #par de canales diferentes | |
393 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
392 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
394 |
|
393 | |||
395 | self.flag_cspc = False |
|
394 | self.flag_cspc = False | |
396 | if nPairs > 0: |
|
395 | if nPairs > 0: | |
397 | self.flag_cspc = True |
|
396 | self.flag_cspc = True | |
398 |
|
397 | |||
399 | except: |
|
398 | except: | |
400 | return 0 |
|
399 | return 0 | |
401 |
|
400 | |||
402 | return 1 |
|
401 | return 1 | |
403 |
|
402 | |||
404 | def write(self, fp): |
|
403 | def write(self, fp): | |
405 | headerTuple = (self.size, |
|
404 | headerTuple = (self.size, | |
406 | self.dataType, |
|
405 | self.dataType, | |
407 | self.blockSize, |
|
406 | self.blockSize, | |
408 | self.profilesPerBlock, |
|
407 | self.profilesPerBlock, | |
409 | self.dataBlocksPerFile, |
|
408 | self.dataBlocksPerFile, | |
410 | self.nWindows, |
|
409 | self.nWindows, | |
411 | self.processFlags, |
|
410 | self.processFlags, | |
412 | self.nCohInt, |
|
411 | self.nCohInt, | |
413 | self.nIncohInt, |
|
412 | self.nIncohInt, | |
414 | self.totalSpectra) |
|
413 | self.totalSpectra) | |
415 |
|
414 | |||
416 | header = numpy.array(headerTuple,self.struct) |
|
415 | header = numpy.array(headerTuple,self.struct) | |
417 | header.tofile(fp) |
|
416 | header.tofile(fp) | |
418 |
|
417 | |||
419 | if self.nWindows != 0: |
|
418 | if self.nWindows != 0: | |
420 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
419 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
421 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
420 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) | |
422 | samplingWindow.tofile(fp) |
|
421 | samplingWindow.tofile(fp) | |
423 |
|
422 | |||
424 |
|
423 | |||
425 | if self.totalSpectra != 0: |
|
424 | if self.totalSpectra != 0: | |
426 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
425 | spectraComb = numpy.array([],numpy.dtype('u1')) | |
427 | spectraComb = self.spectraComb |
|
426 | spectraComb = self.spectraComb | |
428 | spectraComb.tofile(fp) |
|
427 | spectraComb.tofile(fp) | |
429 |
|
428 | |||
430 |
|
429 | |||
431 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
430 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
432 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
431 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
433 | nCode.tofile(fp) |
|
432 | nCode.tofile(fp) | |
434 |
|
433 | |||
435 | nBaud = self.nBaud |
|
434 | nBaud = self.nBaud | |
436 | nBaud.tofile(fp) |
|
435 | nBaud.tofile(fp) | |
437 |
|
436 | |||
438 | code = self.code.reshape(nCode*nBaud) |
|
437 | code = self.code.reshape(nCode*nBaud) | |
439 | code.tofile(fp) |
|
438 | code.tofile(fp) | |
440 |
|
439 | |||
441 | return 1 |
|
440 | return 1 | |
442 |
|
441 | |||
443 | class RCfunction: |
|
442 | class RCfunction: | |
444 | NONE=0 |
|
443 | NONE=0 | |
445 | FLIP=1 |
|
444 | FLIP=1 | |
446 | CODE=2 |
|
445 | CODE=2 | |
447 | SAMPLING=3 |
|
446 | SAMPLING=3 | |
448 | LIN6DIV256=4 |
|
447 | LIN6DIV256=4 | |
449 | SYNCHRO=5 |
|
448 | SYNCHRO=5 | |
450 |
|
449 | |||
451 | class nCodeType: |
|
450 | class nCodeType: | |
452 | NONE=0 |
|
451 | NONE=0 | |
453 | USERDEFINE=1 |
|
452 | USERDEFINE=1 | |
454 | BARKER2=2 |
|
453 | BARKER2=2 | |
455 | BARKER3=3 |
|
454 | BARKER3=3 | |
456 | BARKER4=4 |
|
455 | BARKER4=4 | |
457 | BARKER5=5 |
|
456 | BARKER5=5 | |
458 | BARKER7=6 |
|
457 | BARKER7=6 | |
459 | BARKER11=7 |
|
458 | BARKER11=7 | |
460 | BARKER13=8 |
|
459 | BARKER13=8 | |
461 | AC128=9 |
|
460 | AC128=9 | |
462 | COMPLEMENTARYCODE2=10 |
|
461 | COMPLEMENTARYCODE2=10 | |
463 | COMPLEMENTARYCODE4=11 |
|
462 | COMPLEMENTARYCODE4=11 | |
464 | COMPLEMENTARYCODE8=12 |
|
463 | COMPLEMENTARYCODE8=12 | |
465 | COMPLEMENTARYCODE16=13 |
|
464 | COMPLEMENTARYCODE16=13 | |
466 | COMPLEMENTARYCODE32=14 |
|
465 | COMPLEMENTARYCODE32=14 | |
467 | COMPLEMENTARYCODE64=15 |
|
466 | COMPLEMENTARYCODE64=15 | |
468 | COMPLEMENTARYCODE128=16 |
|
467 | COMPLEMENTARYCODE128=16 | |
469 | CODE_BINARY28=17 |
|
468 | CODE_BINARY28=17 | |
470 |
|
469 | |||
471 | class PROCFLAG: |
|
470 | class PROCFLAG: | |
472 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
471 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
473 | DECODE_DATA = numpy.uint32(0x00000002) |
|
472 | DECODE_DATA = numpy.uint32(0x00000002) | |
474 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
473 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
475 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
474 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
476 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
475 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
477 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
476 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
478 |
|
477 | |||
479 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
478 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
480 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
479 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
481 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
480 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
482 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
481 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
483 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
482 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
484 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
483 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
485 |
|
484 | |||
486 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
485 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
487 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
486 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
488 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
487 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
489 |
|
488 | |||
490 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
489 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
491 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
490 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
492 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
491 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
493 |
|
492 | |||
494 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
493 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
495 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
494 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
496 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
495 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
497 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
496 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
498 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
497 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
499 |
|
498 | |||
500 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
499 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
501 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
500 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
502 |
|
501 | |||
503 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
502 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
504 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
503 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
505 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
504 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
506 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
|
505 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
@@ -1,775 +1,775 | |||||
1 |
''' |
|
1 | ''' | |
2 | File: SpectraIO.py |
|
|||
3 | Created on 20/02/2012 |
|
|||
4 |
|
2 | |||
5 | @author $Author: dsuarez $ |
|
3 | $Author$ | |
6 | @version $Id: SpectraIO.py 110 2012-07-19 15:18:18Z dsuarez $ |
|
4 | $Id$ | |
7 | ''' |
|
5 | ''' | |
8 |
|
6 | |||
9 | import os, sys |
|
7 | import os, sys | |
10 | import numpy |
|
8 | import numpy | |
11 | import glob |
|
9 | import glob | |
12 | import fnmatch |
|
10 | import fnmatch | |
13 | import time, datetime |
|
11 | import time, datetime | |
14 |
|
12 | |||
15 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
16 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
17 |
|
15 | |||
18 | from IO.JROHeader import * |
|
16 | from IO.JROHeader import * | |
19 | from Data.Spectra import Spectra |
|
17 | from Data.Spectra import Spectra | |
20 |
|
18 | |||
21 | from JRODataIO import JRODataReader |
|
19 | from JRODataIO import JRODataReader | |
22 | from JRODataIO import JRODataWriter |
|
20 | from JRODataIO import JRODataWriter | |
23 | from JRODataIO import isNumber |
|
21 | from JRODataIO import isNumber | |
24 |
|
22 | |||
25 |
|
23 | |||
26 | class SpectraReader(JRODataReader): |
|
24 | class SpectraReader(JRODataReader): | |
27 | """ |
|
25 | """ | |
28 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
26 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
29 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
27 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
30 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
28 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
31 |
|
29 | |||
32 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
30 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
33 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
31 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
34 | canales * alturas (DC Channels) |
|
32 | canales * alturas (DC Channels) | |
35 |
|
33 | |||
36 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
34 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
37 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
35 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
38 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
36 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
39 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
37 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
40 |
|
38 | |||
41 | Example: |
|
39 | Example: | |
42 | dpath = "/home/myuser/data" |
|
40 | dpath = "/home/myuser/data" | |
43 |
|
41 | |||
44 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
42 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
45 |
|
43 | |||
46 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
44 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
47 |
|
45 | |||
48 | readerObj = SpectraReader() |
|
46 | readerObj = SpectraReader() | |
49 |
|
47 | |||
50 | readerObj.setup(dpath, startTime, endTime) |
|
48 | readerObj.setup(dpath, startTime, endTime) | |
51 |
|
49 | |||
52 | while(True): |
|
50 | while(True): | |
53 |
|
51 | |||
54 | readerObj.getData() |
|
52 | readerObj.getData() | |
55 |
|
53 | |||
56 | print readerObj.dataOutObj.data |
|
54 | print readerObj.dataOutObj.data | |
57 |
|
55 | |||
58 | if readerObj.flagNoMoreFiles: |
|
56 | if readerObj.flagNoMoreFiles: | |
59 | break |
|
57 | break | |
60 |
|
58 | |||
61 | """ |
|
59 | """ | |
62 |
|
60 | |||
63 | pts2read_SelfSpectra = 0 |
|
61 | pts2read_SelfSpectra = 0 | |
64 |
|
62 | |||
65 | pts2read_CrossSpectra = 0 |
|
63 | pts2read_CrossSpectra = 0 | |
66 |
|
64 | |||
67 | pts2read_DCchannels = 0 |
|
65 | pts2read_DCchannels = 0 | |
68 |
|
66 | |||
69 | ext = ".pdata" |
|
67 | ext = ".pdata" | |
70 |
|
68 | |||
71 | optchar = "P" |
|
69 | optchar = "P" | |
72 |
|
70 | |||
73 | dataOutObj = None |
|
71 | dataOutObj = None | |
74 |
|
72 | |||
75 | nRdChannels = None |
|
73 | nRdChannels = None | |
76 |
|
74 | |||
77 | nRdPairs = None |
|
75 | nRdPairs = None | |
78 |
|
76 | |||
79 | rdPairList = [] |
|
77 | rdPairList = [] | |
80 |
|
78 | |||
81 |
|
79 | |||
82 | def __init__(self, dataOutObj=None): |
|
80 | def __init__(self, dataOutObj=None): | |
83 | """ |
|
81 | """ | |
84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
82 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
85 |
|
83 | |||
86 | Inputs: |
|
84 | Inputs: | |
87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
85 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para | |
88 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
86 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
89 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
87 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
88 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
91 | bloque de datos. |
|
89 | bloque de datos. | |
92 | Si este parametro no es pasado se creara uno internamente. |
|
90 | Si este parametro no es pasado se creara uno internamente. | |
93 |
|
91 | |||
94 | Affected: |
|
92 | Affected: | |
95 | self.dataOutObj |
|
93 | self.dataOutObj | |
96 |
|
94 | |||
97 | Return : None |
|
95 | Return : None | |
98 | """ |
|
96 | """ | |
99 |
|
97 | |||
100 | self.pts2read_SelfSpectra = 0 |
|
98 | self.pts2read_SelfSpectra = 0 | |
101 |
|
99 | |||
102 | self.pts2read_CrossSpectra = 0 |
|
100 | self.pts2read_CrossSpectra = 0 | |
103 |
|
101 | |||
104 | self.pts2read_DCchannels = 0 |
|
102 | self.pts2read_DCchannels = 0 | |
105 |
|
103 | |||
106 | self.datablock = None |
|
104 | self.datablock = None | |
107 |
|
105 | |||
108 | self.utc = None |
|
106 | self.utc = None | |
109 |
|
107 | |||
110 | self.ext = ".pdata" |
|
108 | self.ext = ".pdata" | |
111 |
|
109 | |||
112 | self.optchar = "P" |
|
110 | self.optchar = "P" | |
113 |
|
111 | |||
114 | self.basicHeaderObj = BasicHeader() |
|
112 | self.basicHeaderObj = BasicHeader() | |
115 |
|
113 | |||
116 | self.systemHeaderObj = SystemHeader() |
|
114 | self.systemHeaderObj = SystemHeader() | |
117 |
|
115 | |||
118 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
116 | self.radarControllerHeaderObj = RadarControllerHeader() | |
119 |
|
117 | |||
120 | self.processingHeaderObj = ProcessingHeader() |
|
118 | self.processingHeaderObj = ProcessingHeader() | |
121 |
|
119 | |||
122 | self.online = 0 |
|
120 | self.online = 0 | |
123 |
|
121 | |||
124 | self.fp = None |
|
122 | self.fp = None | |
125 |
|
123 | |||
126 | self.idFile = None |
|
124 | self.idFile = None | |
127 |
|
125 | |||
128 | self.dtype = None |
|
126 | self.dtype = None | |
129 |
|
127 | |||
130 | self.fileSizeByHeader = None |
|
128 | self.fileSizeByHeader = None | |
131 |
|
129 | |||
132 | self.filenameList = [] |
|
130 | self.filenameList = [] | |
133 |
|
131 | |||
134 | self.filename = None |
|
132 | self.filename = None | |
135 |
|
133 | |||
136 | self.fileSize = None |
|
134 | self.fileSize = None | |
137 |
|
135 | |||
138 | self.firstHeaderSize = 0 |
|
136 | self.firstHeaderSize = 0 | |
139 |
|
137 | |||
140 | self.basicHeaderSize = 24 |
|
138 | self.basicHeaderSize = 24 | |
141 |
|
139 | |||
142 | self.pathList = [] |
|
140 | self.pathList = [] | |
143 |
|
141 | |||
144 | self.lastUTTime = 0 |
|
142 | self.lastUTTime = 0 | |
145 |
|
143 | |||
146 | self.maxTimeStep = 30 |
|
144 | self.maxTimeStep = 30 | |
147 |
|
145 | |||
148 | self.flagNoMoreFiles = 0 |
|
146 | self.flagNoMoreFiles = 0 | |
149 |
|
147 | |||
150 | self.set = 0 |
|
148 | self.set = 0 | |
151 |
|
149 | |||
152 | self.path = None |
|
150 | self.path = None | |
153 |
|
151 | |||
154 | self.delay = 3 #seconds |
|
152 | self.delay = 3 #seconds | |
155 |
|
153 | |||
156 | self.nTries = 3 #quantity tries |
|
154 | self.nTries = 3 #quantity tries | |
157 |
|
155 | |||
158 | self.nFiles = 3 #number of files for searching |
|
156 | self.nFiles = 3 #number of files for searching | |
159 |
|
157 | |||
160 | self.nReadBlocks = 0 |
|
158 | self.nReadBlocks = 0 | |
161 |
|
159 | |||
162 | self.flagIsNewFile = 1 |
|
160 | self.flagIsNewFile = 1 | |
163 |
|
161 | |||
164 | self.ippSeconds = 0 |
|
162 | self.ippSeconds = 0 | |
165 |
|
163 | |||
166 | self.flagTimeBlock = 0 |
|
164 | self.flagTimeBlock = 0 | |
167 |
|
165 | |||
168 | self.flagIsNewBlock = 0 |
|
166 | self.flagIsNewBlock = 0 | |
169 |
|
167 | |||
170 | self.nTotalBlocks = 0 |
|
168 | self.nTotalBlocks = 0 | |
171 |
|
169 | |||
172 | self.blocksize = 0 |
|
170 | self.blocksize = 0 | |
173 |
|
171 | |||
174 |
|
172 | |||
175 | def createObjByDefault(self): |
|
173 | def createObjByDefault(self): | |
176 |
|
174 | |||
177 | dataObj = Spectra() |
|
175 | dataObj = Spectra() | |
178 |
|
176 | |||
179 | return dataObj |
|
177 | return dataObj | |
180 |
|
178 | |||
181 | def __hasNotDataInBuffer(self): |
|
179 | def __hasNotDataInBuffer(self): | |
182 | return 1 |
|
180 | return 1 | |
183 |
|
181 | |||
184 |
|
182 | |||
185 | def getBlockDimension(self): |
|
183 | def getBlockDimension(self): | |
186 | """ |
|
184 | """ | |
187 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
185 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
188 |
|
186 | |||
189 | Affected: |
|
187 | Affected: | |
190 | self.nRdChannels |
|
188 | self.nRdChannels | |
191 | self.nRdPairs |
|
189 | self.nRdPairs | |
192 | self.pts2read_SelfSpectra |
|
190 | self.pts2read_SelfSpectra | |
193 | self.pts2read_CrossSpectra |
|
191 | self.pts2read_CrossSpectra | |
194 | self.pts2read_DCchannels |
|
192 | self.pts2read_DCchannels | |
195 | self.blocksize |
|
193 | self.blocksize | |
196 | self.dataOutObj.nChannels |
|
194 | self.dataOutObj.nChannels | |
197 | self.dataOutObj.nPairs |
|
195 | self.dataOutObj.nPairs | |
198 |
|
196 | |||
199 | Return: |
|
197 | Return: | |
200 | None |
|
198 | None | |
201 | """ |
|
199 | """ | |
202 | self.nRdChannels = 0 |
|
200 | self.nRdChannels = 0 | |
203 | self.nRdPairs = 0 |
|
201 | self.nRdPairs = 0 | |
204 | self.rdPairList = [] |
|
202 | self.rdPairList = [] | |
205 |
|
203 | |||
206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
204 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
205 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
206 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
209 | else: |
|
207 | else: | |
210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
208 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
209 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
212 |
|
210 | |||
213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
211 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
214 |
|
212 | |||
215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
213 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
216 | self.blocksize = self.pts2read_SelfSpectra |
|
214 | self.blocksize = self.pts2read_SelfSpectra | |
217 |
|
215 | |||
218 | if self.processingHeaderObj.flag_cspc: |
|
216 | if self.processingHeaderObj.flag_cspc: | |
219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
217 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
220 | self.blocksize += self.pts2read_CrossSpectra |
|
218 | self.blocksize += self.pts2read_CrossSpectra | |
221 |
|
219 | |||
222 | if self.processingHeaderObj.flag_dc: |
|
220 | if self.processingHeaderObj.flag_dc: | |
223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
221 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
224 | self.blocksize += self.pts2read_DCchannels |
|
222 | self.blocksize += self.pts2read_DCchannels | |
225 |
|
223 | |||
226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
224 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
227 |
|
225 | |||
228 |
|
226 | |||
229 | def readBlock(self): |
|
227 | def readBlock(self): | |
230 | """ |
|
228 | """ | |
231 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
229 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
230 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
231 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
234 | es seteado a 0 |
|
232 | es seteado a 0 | |
235 |
|
233 | |||
236 | Return: None |
|
234 | Return: None | |
237 |
|
235 | |||
238 | Variables afectadas: |
|
236 | Variables afectadas: | |
239 |
|
237 | |||
240 | self.flagIsNewFile |
|
238 | self.flagIsNewFile | |
241 | self.flagIsNewBlock |
|
239 | self.flagIsNewBlock | |
242 | self.nTotalBlocks |
|
240 | self.nTotalBlocks | |
243 | self.data_spc |
|
241 | self.data_spc | |
244 | self.data_cspc |
|
242 | self.data_cspc | |
245 | self.data_dc |
|
243 | self.data_dc | |
246 |
|
244 | |||
247 | Exceptions: |
|
245 | Exceptions: | |
248 | Si un bloque leido no es un bloque valido |
|
246 | Si un bloque leido no es un bloque valido | |
249 | """ |
|
247 | """ | |
250 | blockOk_flag = False |
|
248 | blockOk_flag = False | |
251 | fpointer = self.fp.tell() |
|
249 | fpointer = self.fp.tell() | |
252 |
|
250 | |||
253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
251 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
252 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
255 |
|
253 | |||
256 | if self.processingHeaderObj.flag_cspc: |
|
254 | if self.processingHeaderObj.flag_cspc: | |
257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
255 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
256 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
259 |
|
257 | |||
260 | if self.processingHeaderObj.flag_dc: |
|
258 | if self.processingHeaderObj.flag_dc: | |
261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
259 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
260 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
263 |
|
261 | |||
264 |
|
262 | |||
265 | if not(self.processingHeaderObj.shif_fft): |
|
263 | if not(self.processingHeaderObj.shif_fft): | |
266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
264 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
267 |
|
265 | |||
268 | if self.processingHeaderObj.flag_cspc: |
|
266 | if self.processingHeaderObj.flag_cspc: | |
269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
267 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
270 |
|
268 | |||
271 |
|
269 | |||
272 | spc = numpy.transpose( spc, (0,2,1) ) |
|
270 | spc = numpy.transpose( spc, (0,2,1) ) | |
273 | self.data_spc = spc |
|
271 | self.data_spc = spc | |
274 |
|
272 | |||
275 | if self.processingHeaderObj.flag_cspc: |
|
273 | if self.processingHeaderObj.flag_cspc: | |
276 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
274 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
277 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
275 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
278 | else: |
|
276 | else: | |
279 | self.data_cspc = None |
|
277 | self.data_cspc = None | |
280 |
|
278 | |||
281 | if self.processingHeaderObj.flag_dc: |
|
279 | if self.processingHeaderObj.flag_dc: | |
282 | self.data_dc = dc['real'] + dc['imag']*1j |
|
280 | self.data_dc = dc['real'] + dc['imag']*1j | |
283 | else: |
|
281 | else: | |
284 | self.data_dc = None |
|
282 | self.data_dc = None | |
285 |
|
283 | |||
286 | self.flagIsNewFile = 0 |
|
284 | self.flagIsNewFile = 0 | |
287 | self.flagIsNewBlock = 1 |
|
285 | self.flagIsNewBlock = 1 | |
288 |
|
286 | |||
289 | self.nTotalBlocks += 1 |
|
287 | self.nTotalBlocks += 1 | |
290 | self.nReadBlocks += 1 |
|
288 | self.nReadBlocks += 1 | |
291 |
|
289 | |||
292 | return 1 |
|
290 | return 1 | |
293 |
|
291 | |||
294 |
|
292 | |||
295 | def getData(self): |
|
293 | def getData(self): | |
296 | """ |
|
294 | """ | |
297 | Copia el buffer de lectura a la clase "Spectra", |
|
295 | Copia el buffer de lectura a la clase "Spectra", | |
298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
296 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
297 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
300 |
|
298 | |||
301 | Return: |
|
299 | Return: | |
302 | 0 : Si no hay mas archivos disponibles |
|
300 | 0 : Si no hay mas archivos disponibles | |
303 | 1 : Si hizo una buena copia del buffer |
|
301 | 1 : Si hizo una buena copia del buffer | |
304 |
|
302 | |||
305 | Affected: |
|
303 | Affected: | |
306 | self.dataOutObj |
|
304 | self.dataOutObj | |
307 |
|
305 | |||
308 | self.flagTimeBlock |
|
306 | self.flagTimeBlock | |
309 | self.flagIsNewBlock |
|
307 | self.flagIsNewBlock | |
310 | """ |
|
308 | """ | |
311 |
|
309 | |||
312 | if self.flagNoMoreFiles: return 0 |
|
310 | if self.flagNoMoreFiles: return 0 | |
313 |
|
311 | |||
314 | self.flagTimeBlock = 0 |
|
312 | self.flagTimeBlock = 0 | |
315 | self.flagIsNewBlock = 0 |
|
313 | self.flagIsNewBlock = 0 | |
316 |
|
314 | |||
317 | if self.__hasNotDataInBuffer(): |
|
315 | if self.__hasNotDataInBuffer(): | |
318 |
|
316 | |||
319 | if not( self.readNextBlock() ): |
|
317 | if not( self.readNextBlock() ): | |
320 | return 0 |
|
318 | return 0 | |
321 |
|
319 | |||
322 | # self.updateDataHeader() |
|
320 | # self.updateDataHeader() | |
323 |
|
321 | |||
324 | if self.flagNoMoreFiles == 1: |
|
322 | if self.flagNoMoreFiles == 1: | |
325 | print 'Process finished' |
|
323 | print 'Process finished' | |
326 | return 0 |
|
324 | return 0 | |
327 |
|
325 | |||
328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
326 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
329 |
|
327 | |||
330 | if self.data_dc == None: |
|
328 | if self.data_dc == None: | |
331 | self.dataOutObj.flagNoData = True |
|
329 | self.dataOutObj.flagNoData = True | |
332 | return 0 |
|
330 | return 0 | |
333 |
|
331 | |||
334 |
|
332 | |||
335 | self.dataOutObj.data_spc = self.data_spc |
|
333 | self.dataOutObj.data_spc = self.data_spc | |
336 |
|
334 | |||
337 | self.dataOutObj.data_cspc = self.data_cspc |
|
335 | self.dataOutObj.data_cspc = self.data_cspc | |
338 |
|
336 | |||
339 | self.dataOutObj.data_dc = self.data_dc |
|
337 | self.dataOutObj.data_dc = self.data_dc | |
340 |
|
338 | |||
341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
339 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
342 |
|
340 | |||
343 | self.dataOutObj.flagNoData = False |
|
341 | self.dataOutObj.flagNoData = False | |
344 |
|
342 | |||
345 | self.dataOutObj.dtype = self.dtype |
|
343 | self.dataOutObj.dtype = self.dtype | |
346 |
|
344 | |||
347 | self.dataOutObj.nChannels = self.nRdChannels |
|
345 | self.dataOutObj.nChannels = self.nRdChannels | |
348 |
|
346 | |||
349 | self.dataOutObj.nPairs = self.nRdPairs |
|
347 | self.dataOutObj.nPairs = self.nRdPairs | |
350 |
|
348 | |||
351 | self.dataOutObj.pairsList = self.rdPairList |
|
349 | self.dataOutObj.pairsList = self.rdPairList | |
352 |
|
350 | |||
353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
351 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
354 |
|
352 | |||
355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
353 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
356 |
|
354 | |||
357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
355 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
358 |
|
356 | |||
359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt |
|
357 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt | |
360 |
|
358 | |||
361 |
|
359 | |||
362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
360 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
363 |
|
361 | |||
364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
362 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
365 |
|
363 | |||
366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
364 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
367 |
|
365 | |||
368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
366 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
369 |
|
367 | |||
370 | self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc #+ self.profileIndex * self.ippSeconds |
|
368 | self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
371 |
|
369 | |||
372 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
370 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft | |
373 |
|
371 | |||
374 | # self.profileIndex += 1 |
|
372 | # self.profileIndex += 1 | |
375 |
|
373 | |||
376 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
374 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
377 |
|
375 | |||
378 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
376 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
379 |
|
377 | |||
380 | return 1 |
|
378 | return 1 | |
381 |
|
379 | |||
382 |
|
380 | |||
383 | class SpectraWriter(JRODataWriter): |
|
381 | class SpectraWriter(JRODataWriter): | |
384 |
|
382 | |||
385 | """ |
|
383 | """ | |
386 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
384 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
387 | de los datos siempre se realiza por bloques. |
|
385 | de los datos siempre se realiza por bloques. | |
388 | """ |
|
386 | """ | |
389 |
|
387 | |||
390 | ext = ".pdata" |
|
388 | ext = ".pdata" | |
391 |
|
389 | |||
392 | optchar = "P" |
|
390 | optchar = "P" | |
393 |
|
391 | |||
394 | shape_spc_Buffer = None |
|
392 | shape_spc_Buffer = None | |
395 |
|
393 | |||
396 | shape_cspc_Buffer = None |
|
394 | shape_cspc_Buffer = None | |
397 |
|
395 | |||
398 | shape_dc_Buffer = None |
|
396 | shape_dc_Buffer = None | |
399 |
|
397 | |||
400 | data_spc = None |
|
398 | data_spc = None | |
401 |
|
399 | |||
402 | data_cspc = None |
|
400 | data_cspc = None | |
403 |
|
401 | |||
404 | data_dc = None |
|
402 | data_dc = None | |
405 |
|
403 | |||
406 | wrPairList = [] |
|
404 | wrPairList = [] | |
407 |
|
405 | |||
408 | nWrPairs = 0 |
|
406 | nWrPairs = 0 | |
409 |
|
407 | |||
410 | nWrChannels = 0 |
|
408 | nWrChannels = 0 | |
411 |
|
409 | |||
412 | # dataOutObj = None |
|
410 | # dataOutObj = None | |
413 |
|
411 | |||
414 | def __init__(self, dataOutObj=None): |
|
412 | def __init__(self, dataOutObj=None): | |
415 | """ |
|
413 | """ | |
416 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
414 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
417 |
|
415 | |||
418 | Affected: |
|
416 | Affected: | |
419 | self.dataOutObj |
|
417 | self.dataOutObj | |
420 | self.basicHeaderObj |
|
418 | self.basicHeaderObj | |
421 | self.systemHeaderObj |
|
419 | self.systemHeaderObj | |
422 | self.radarControllerHeaderObj |
|
420 | self.radarControllerHeaderObj | |
423 | self.processingHeaderObj |
|
421 | self.processingHeaderObj | |
424 |
|
422 | |||
425 | Return: None |
|
423 | Return: None | |
426 | """ |
|
424 | """ | |
427 | if dataOutObj == None: |
|
425 | if dataOutObj == None: | |
428 | dataOutObj = Spectra() |
|
426 | dataOutObj = Spectra() | |
429 |
|
427 | |||
430 | if not( isinstance(dataOutObj, Spectra) ): |
|
428 | if not( isinstance(dataOutObj, Spectra) ): | |
431 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" |
|
429 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" | |
432 |
|
430 | |||
433 | self.dataOutObj = dataOutObj |
|
431 | self.dataOutObj = dataOutObj | |
434 |
|
432 | |||
435 | self.nTotalBlocks = 0 |
|
433 | self.nTotalBlocks = 0 | |
436 |
|
434 | |||
437 | self.nWrChannels = self.dataOutObj.nChannels |
|
435 | self.nWrChannels = self.dataOutObj.nChannels | |
438 |
|
436 | |||
439 | # if len(pairList) > 0: |
|
437 | # if len(pairList) > 0: | |
440 | # self.wrPairList = pairList |
|
438 | # self.wrPairList = pairList | |
441 | # |
|
439 | # | |
442 | # self.nWrPairs = len(pairList) |
|
440 | # self.nWrPairs = len(pairList) | |
443 |
|
441 | |||
444 | self.wrPairList = self.dataOutObj.pairsList |
|
442 | self.wrPairList = self.dataOutObj.pairsList | |
445 |
|
443 | |||
446 | self.nWrPairs = self.dataOutObj.nPairs |
|
444 | self.nWrPairs = self.dataOutObj.nPairs | |
447 |
|
445 | |||
448 |
|
446 | |||
449 |
|
447 | |||
450 |
|
448 | |||
451 |
|
449 | |||
452 | # self.data_spc = None |
|
450 | # self.data_spc = None | |
453 | # self.data_cspc = None |
|
451 | # self.data_cspc = None | |
454 | # self.data_dc = None |
|
452 | # self.data_dc = None | |
455 |
|
453 | |||
456 | # self.fp = None |
|
454 | # self.fp = None | |
457 |
|
455 | |||
458 | # self.flagIsNewFile = 1 |
|
456 | # self.flagIsNewFile = 1 | |
459 | # |
|
457 | # | |
460 | # self.nTotalBlocks = 0 |
|
458 | # self.nTotalBlocks = 0 | |
461 | # |
|
459 | # | |
462 | # self.flagIsNewBlock = 0 |
|
460 | # self.flagIsNewBlock = 0 | |
463 | # |
|
461 | # | |
464 | # self.flagNoMoreFiles = 0 |
|
462 | # self.flagNoMoreFiles = 0 | |
465 | # |
|
463 | # | |
466 | # self.setFile = None |
|
464 | # self.setFile = None | |
467 | # |
|
465 | # | |
468 | # self.dtype = None |
|
466 | # self.dtype = None | |
469 | # |
|
467 | # | |
470 | # self.path = None |
|
468 | # self.path = None | |
471 | # |
|
469 | # | |
472 | # self.noMoreFiles = 0 |
|
470 | # self.noMoreFiles = 0 | |
473 | # |
|
471 | # | |
474 | # self.filename = None |
|
472 | # self.filename = None | |
475 | # |
|
473 | # | |
476 | # self.basicHeaderObj = BasicHeader() |
|
474 | # self.basicHeaderObj = BasicHeader() | |
477 | # |
|
475 | # | |
478 | # self.systemHeaderObj = SystemHeader() |
|
476 | # self.systemHeaderObj = SystemHeader() | |
479 | # |
|
477 | # | |
480 | # self.radarControllerHeaderObj = RadarControllerHeader() |
|
478 | # self.radarControllerHeaderObj = RadarControllerHeader() | |
481 | # |
|
479 | # | |
482 | # self.processingHeaderObj = ProcessingHeader() |
|
480 | # self.processingHeaderObj = ProcessingHeader() | |
483 |
|
481 | |||
484 |
|
482 | |||
485 | def hasAllDataInBuffer(self): |
|
483 | def hasAllDataInBuffer(self): | |
486 | return 1 |
|
484 | return 1 | |
487 |
|
485 | |||
488 |
|
486 | |||
489 | def setBlockDimension(self): |
|
487 | def setBlockDimension(self): | |
490 | """ |
|
488 | """ | |
491 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
489 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
492 |
|
490 | |||
493 | Affected: |
|
491 | Affected: | |
494 | self.shape_spc_Buffer |
|
492 | self.shape_spc_Buffer | |
495 | self.shape_cspc_Buffer |
|
493 | self.shape_cspc_Buffer | |
496 | self.shape_dc_Buffer |
|
494 | self.shape_dc_Buffer | |
497 |
|
495 | |||
498 | Return: None |
|
496 | Return: None | |
499 | """ |
|
497 | """ | |
500 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, |
|
498 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, | |
501 | self.processingHeaderObj.nHeights, |
|
499 | self.processingHeaderObj.nHeights, | |
502 | self.processingHeaderObj.profilesPerBlock) |
|
500 | self.processingHeaderObj.profilesPerBlock) | |
503 |
|
501 | |||
504 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, |
|
502 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, | |
505 | self.processingHeaderObj.nHeights, |
|
503 | self.processingHeaderObj.nHeights, | |
506 | self.processingHeaderObj.profilesPerBlock) |
|
504 | self.processingHeaderObj.profilesPerBlock) | |
507 |
|
505 | |||
508 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, |
|
506 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, | |
509 | self.processingHeaderObj.nHeights) |
|
507 | self.processingHeaderObj.nHeights) | |
510 |
|
508 | |||
511 |
|
509 | |||
512 | def writeBlock(self): |
|
510 | def writeBlock(self): | |
513 | """ |
|
511 | """ | |
514 | Escribe el buffer en el file designado |
|
512 | Escribe el buffer en el file designado | |
515 |
|
513 | |||
516 | Affected: |
|
514 | Affected: | |
517 | self.data_spc |
|
515 | self.data_spc | |
518 | self.data_cspc |
|
516 | self.data_cspc | |
519 | self.data_dc |
|
517 | self.data_dc | |
520 | self.flagIsNewFile |
|
518 | self.flagIsNewFile | |
521 | self.flagIsNewBlock |
|
519 | self.flagIsNewBlock | |
522 | self.nTotalBlocks |
|
520 | self.nTotalBlocks | |
523 | self.nWriteBlocks |
|
521 | self.nWriteBlocks | |
524 |
|
522 | |||
525 | Return: None |
|
523 | Return: None | |
526 | """ |
|
524 | """ | |
527 |
|
525 | |||
528 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
526 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
529 | if not( self.processingHeaderObj.shif_fft ): |
|
527 | if not( self.processingHeaderObj.shif_fft ): | |
530 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
528 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
531 | data = spc.reshape((-1)) |
|
529 | data = spc.reshape((-1)) | |
532 | data.tofile(self.fp) |
|
530 | data.tofile(self.fp) | |
533 |
|
531 | |||
534 | if self.data_cspc != None: |
|
532 | if self.data_cspc != None: | |
535 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
533 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
536 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
534 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
537 | if not( self.processingHeaderObj.shif_fft ): |
|
535 | if not( self.processingHeaderObj.shif_fft ): | |
538 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
536 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
539 | data['real'] = cspc.real |
|
537 | data['real'] = cspc.real | |
540 | data['imag'] = cspc.imag |
|
538 | data['imag'] = cspc.imag | |
541 | data = data.reshape((-1)) |
|
539 | data = data.reshape((-1)) | |
542 | data.tofile(self.fp) |
|
540 | data.tofile(self.fp) | |
543 |
|
541 | |||
544 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
542 | if self.data_dc != None: | |
545 | dc = self.data_dc |
|
543 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
546 | data['real'] = dc.real |
|
544 | dc = self.data_dc | |
547 |
data[' |
|
545 | data['real'] = dc.real | |
548 | data = data.reshape((-1)) |
|
546 | data['imag'] = dc.imag | |
549 | data.tofile(self.fp) |
|
547 | data = data.reshape((-1)) | |
|
548 | data.tofile(self.fp) | |||
550 |
|
549 | |||
551 | self.data_spc.fill(0) |
|
550 | self.data_spc.fill(0) | |
552 | self.data_dc.fill(0) |
|
551 | self.data_dc.fill(0) | |
553 | if self.data_cspc != None: |
|
552 | if self.data_cspc != None: | |
554 | self.data_cspc.fill(0) |
|
553 | self.data_cspc.fill(0) | |
555 |
|
554 | |||
556 | self.flagIsNewFile = 0 |
|
555 | self.flagIsNewFile = 0 | |
557 | self.flagIsNewBlock = 1 |
|
556 | self.flagIsNewBlock = 1 | |
558 | self.nTotalBlocks += 1 |
|
557 | self.nTotalBlocks += 1 | |
559 | self.nWriteBlocks += 1 |
|
558 | self.nWriteBlocks += 1 | |
|
559 | self.blockIndex += 1 | |||
560 |
|
560 | |||
561 |
|
561 | |||
562 | def putData(self): |
|
562 | def putData(self): | |
563 | """ |
|
563 | """ | |
564 | Setea un bloque de datos y luego los escribe en un file |
|
564 | Setea un bloque de datos y luego los escribe en un file | |
565 |
|
565 | |||
566 | Affected: |
|
566 | Affected: | |
567 | self.data_spc |
|
567 | self.data_spc | |
568 | self.data_cspc |
|
568 | self.data_cspc | |
569 | self.data_dc |
|
569 | self.data_dc | |
570 |
|
570 | |||
571 | Return: |
|
571 | Return: | |
572 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
572 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
573 | 1 : Si se escribio la data de un bloque en un file |
|
573 | 1 : Si se escribio la data de un bloque en un file | |
574 | """ |
|
574 | """ | |
575 | self.flagIsNewBlock = 0 |
|
575 | self.flagIsNewBlock = 0 | |
576 |
|
576 | |||
577 | if self.dataOutObj.flagNoData: |
|
577 | if self.dataOutObj.flagNoData: | |
578 | return 0 |
|
578 | return 0 | |
579 |
|
579 | |||
580 | if self.dataOutObj.flagTimeBlock: |
|
580 | if self.dataOutObj.flagTimeBlock: | |
581 | self.data_spc.fill(0) |
|
581 | self.data_spc.fill(0) | |
582 | self.data_cspc.fill(0) |
|
582 | self.data_cspc.fill(0) | |
583 | self.data_dc.fill(0) |
|
583 | self.data_dc.fill(0) | |
584 | self.setNextFile() |
|
584 | self.setNextFile() | |
585 |
|
585 | |||
586 | if self.flagIsNewFile == 0: |
|
586 | if self.flagIsNewFile == 0: | |
587 | self.getBasicHeader() |
|
587 | self.getBasicHeader() | |
588 |
|
588 | |||
589 | self.data_spc = self.dataOutObj.data_spc |
|
589 | self.data_spc = self.dataOutObj.data_spc | |
590 | self.data_cspc = self.dataOutObj.data_cspc |
|
590 | self.data_cspc = self.dataOutObj.data_cspc | |
591 | self.data_dc = self.dataOutObj.data_dc |
|
591 | self.data_dc = self.dataOutObj.data_dc | |
592 |
|
592 | |||
593 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
593 | # #self.processingHeaderObj.dataBlocksPerFile) | |
594 | if self.hasAllDataInBuffer(): |
|
594 | if self.hasAllDataInBuffer(): | |
595 | # self.getDataHeader() |
|
595 | # self.getDataHeader() | |
596 | self.writeNextBlock() |
|
596 | self.writeNextBlock() | |
597 |
|
597 | |||
598 | if self.flagNoMoreFiles: |
|
598 | if self.flagNoMoreFiles: | |
599 | #print 'Process finished' |
|
599 | #print 'Process finished' | |
600 | return 0 |
|
600 | return 0 | |
601 |
|
601 | |||
602 | return 1 |
|
602 | return 1 | |
603 |
|
603 | |||
604 |
|
604 | |||
605 | def __getProcessFlags(self): |
|
605 | def __getProcessFlags(self): | |
606 |
|
606 | |||
607 | processFlags = 0 |
|
607 | processFlags = 0 | |
608 |
|
608 | |||
609 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
609 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
610 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
610 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
611 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
611 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
612 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
612 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
613 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
613 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
614 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
614 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
615 |
|
615 | |||
616 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
616 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
617 |
|
617 | |||
618 |
|
618 | |||
619 |
|
619 | |||
620 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
620 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
621 | PROCFLAG.DATATYPE_SHORT, |
|
621 | PROCFLAG.DATATYPE_SHORT, | |
622 | PROCFLAG.DATATYPE_LONG, |
|
622 | PROCFLAG.DATATYPE_LONG, | |
623 | PROCFLAG.DATATYPE_INT64, |
|
623 | PROCFLAG.DATATYPE_INT64, | |
624 | PROCFLAG.DATATYPE_FLOAT, |
|
624 | PROCFLAG.DATATYPE_FLOAT, | |
625 | PROCFLAG.DATATYPE_DOUBLE] |
|
625 | PROCFLAG.DATATYPE_DOUBLE] | |
626 |
|
626 | |||
627 |
|
627 | |||
628 | for index in range(len(dtypeList)): |
|
628 | for index in range(len(dtypeList)): | |
629 | if self.dataOutObj.dtype == dtypeList[index]: |
|
629 | if self.dataOutObj.dtype == dtypeList[index]: | |
630 | dtypeValue = datatypeValueList[index] |
|
630 | dtypeValue = datatypeValueList[index] | |
631 | break |
|
631 | break | |
632 |
|
632 | |||
633 | processFlags += dtypeValue |
|
633 | processFlags += dtypeValue | |
634 |
|
634 | |||
635 | if self.dataOutObj.flagDecodeData: |
|
635 | if self.dataOutObj.flagDecodeData: | |
636 | processFlags += PROCFLAG.DECODE_DATA |
|
636 | processFlags += PROCFLAG.DECODE_DATA | |
637 |
|
637 | |||
638 | if self.dataOutObj.flagDeflipData: |
|
638 | if self.dataOutObj.flagDeflipData: | |
639 | processFlags += PROCFLAG.DEFLIP_DATA |
|
639 | processFlags += PROCFLAG.DEFLIP_DATA | |
640 |
|
640 | |||
641 | if self.dataOutObj.code != None: |
|
641 | if self.dataOutObj.code != None: | |
642 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
642 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
643 |
|
643 | |||
644 | if self.dataOutObj.nIncohInt > 1: |
|
644 | if self.dataOutObj.nIncohInt > 1: | |
645 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
645 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
646 |
|
646 | |||
647 | if self.dataOutObj.data_dc != None: |
|
647 | if self.dataOutObj.data_dc != None: | |
648 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
648 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
649 |
|
649 | |||
650 | return processFlags |
|
650 | return processFlags | |
651 |
|
651 | |||
652 |
|
652 | |||
653 | def __getBlockSize(self): |
|
653 | def __getBlockSize(self): | |
654 | ''' |
|
654 | ''' | |
655 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
655 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
656 | ''' |
|
656 | ''' | |
657 |
|
657 | |||
658 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
658 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
659 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
659 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
660 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
660 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
661 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
661 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
662 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
662 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
663 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
663 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
664 |
|
664 | |||
665 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
665 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
666 | datatypeValueList = [1,2,4,8,4,8] |
|
666 | datatypeValueList = [1,2,4,8,4,8] | |
667 | for index in range(len(dtypeList)): |
|
667 | for index in range(len(dtypeList)): | |
668 | if self.dataOutObj.dtype == dtypeList[index]: |
|
668 | if self.dataOutObj.dtype == dtypeList[index]: | |
669 | datatypeValue = datatypeValueList[index] |
|
669 | datatypeValue = datatypeValueList[index] | |
670 | break |
|
670 | break | |
671 |
|
671 | |||
672 |
|
672 | |||
673 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints |
|
673 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints | |
674 |
|
674 | |||
675 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) |
|
675 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) | |
676 | blocksize = pts2write_SelfSpectra |
|
676 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
677 |
|
677 | |||
678 | if self.dataOutObj.data_cspc != None: |
|
678 | if self.dataOutObj.data_cspc != None: | |
679 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) |
|
679 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) | |
680 | blocksize += pts2write_CrossSpectra |
|
680 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
681 |
|
681 | |||
682 | if self.dataOutObj.data_dc != None: |
|
682 | if self.dataOutObj.data_dc != None: | |
683 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) |
|
683 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) | |
684 | blocksize += pts2write_DCchannels |
|
684 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
685 |
|
685 | |||
686 | blocksize = blocksize * datatypeValue * 2 |
|
686 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
687 |
|
687 | |||
688 | return blocksize |
|
688 | return blocksize | |
689 |
|
689 | |||
690 |
|
690 | |||
691 | def getBasicHeader(self): |
|
691 | def getBasicHeader(self): | |
692 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
692 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
693 | self.basicHeaderObj.version = self.versionFile |
|
693 | self.basicHeaderObj.version = self.versionFile | |
694 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
694 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
695 |
|
695 | |||
696 | utc = numpy.floor(self.dataOutObj.dataUtcTime) |
|
696 | utc = numpy.floor(self.dataOutObj.dataUtcTime) | |
697 | milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0 |
|
697 | milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0 | |
698 |
|
698 | |||
699 | self.basicHeaderObj.utc = utc |
|
699 | self.basicHeaderObj.utc = utc | |
700 | self.basicHeaderObj.miliSecond = milisecond |
|
700 | self.basicHeaderObj.miliSecond = milisecond | |
701 | self.basicHeaderObj.timeZone = 0 |
|
701 | self.basicHeaderObj.timeZone = 0 | |
702 | self.basicHeaderObj.dstFlag = 0 |
|
702 | self.basicHeaderObj.dstFlag = 0 | |
703 | self.basicHeaderObj.errorCount = 0 |
|
703 | self.basicHeaderObj.errorCount = 0 | |
704 |
|
704 | |||
705 | def getDataHeader(self): |
|
705 | def getDataHeader(self): | |
706 |
|
706 | |||
707 | """ |
|
707 | """ | |
708 | Obtiene una copia del First Header |
|
708 | Obtiene una copia del First Header | |
709 |
|
709 | |||
710 | Affected: |
|
710 | Affected: | |
711 | self.systemHeaderObj |
|
711 | self.systemHeaderObj | |
712 | self.radarControllerHeaderObj |
|
712 | self.radarControllerHeaderObj | |
713 | self.dtype |
|
713 | self.dtype | |
714 |
|
714 | |||
715 | Return: |
|
715 | Return: | |
716 | None |
|
716 | None | |
717 | """ |
|
717 | """ | |
718 |
|
718 | |||
719 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
719 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
720 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
720 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
721 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
721 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
722 |
|
722 | |||
723 | self.getBasicHeader() |
|
723 | self.getBasicHeader() | |
724 |
|
724 | |||
725 | processingHeaderSize = 40 # bytes |
|
725 | processingHeaderSize = 40 # bytes | |
726 | self.processingHeaderObj.dtype = 0 # Voltage |
|
726 | self.processingHeaderObj.dtype = 0 # Voltage | |
727 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
727 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
728 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints |
|
728 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints | |
729 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
729 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
730 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
730 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
731 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
731 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
732 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra |
|
732 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra | |
733 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt |
|
733 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt | |
734 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels |
|
734 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels | |
735 |
|
735 | |||
736 | if self.processingHeaderObj.totalSpectra > 0: |
|
736 | if self.processingHeaderObj.totalSpectra > 0: | |
737 | channelList = [] |
|
737 | channelList = [] | |
738 | for channel in range(self.dataOutObj.nChannels): |
|
738 | for channel in range(self.dataOutObj.nChannels): | |
739 | channelList.append(channel) |
|
739 | channelList.append(channel) | |
740 | channelList.append(channel) |
|
740 | channelList.append(channel) | |
741 |
|
741 | |||
742 | pairsList = [] |
|
742 | pairsList = [] | |
743 | for pair in self.dataOutObj.pairsList: |
|
743 | for pair in self.dataOutObj.pairsList: | |
744 | pairsList.append(pair[0]) |
|
744 | pairsList.append(pair[0]) | |
745 | pairsList.append(pair[1]) |
|
745 | pairsList.append(pair[1]) | |
746 | spectraComb = channelList + pairsList |
|
746 | spectraComb = channelList + pairsList | |
747 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
747 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
748 | self.processingHeaderObj.spectraComb = spectraComb |
|
748 | self.processingHeaderObj.spectraComb = spectraComb | |
749 | sizeOfSpcComb = len(spectraComb) |
|
749 | sizeOfSpcComb = len(spectraComb) | |
750 | processingHeaderSize += sizeOfSpcComb |
|
750 | processingHeaderSize += sizeOfSpcComb | |
751 |
|
751 | |||
752 | if self.dataOutObj.code != None: |
|
752 | if self.dataOutObj.code != None: | |
753 | self.processingHeaderObj.code = self.dataOutObj.code |
|
753 | self.processingHeaderObj.code = self.dataOutObj.code | |
754 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
754 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
755 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
755 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
756 | nCodeSize = 4 # bytes |
|
756 | nCodeSize = 4 # bytes | |
757 | nBaudSize = 4 # bytes |
|
757 | nBaudSize = 4 # bytes | |
758 | codeSize = 4 # bytes |
|
758 | codeSize = 4 # bytes | |
759 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
759 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
760 | processingHeaderSize += sizeOfCode |
|
760 | processingHeaderSize += sizeOfCode | |
761 |
|
761 | |||
762 | if self.processingHeaderObj.nWindows != 0: |
|
762 | if self.processingHeaderObj.nWindows != 0: | |
763 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
763 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
764 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
764 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
765 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
765 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
766 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
766 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
767 | sizeOfFirstHeight = 4 |
|
767 | sizeOfFirstHeight = 4 | |
768 | sizeOfdeltaHeight = 4 |
|
768 | sizeOfdeltaHeight = 4 | |
769 | sizeOfnHeights = 4 |
|
769 | sizeOfnHeights = 4 | |
770 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
770 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
771 | processingHeaderSize += sizeOfWindows |
|
771 | processingHeaderSize += sizeOfWindows | |
772 |
|
772 | |||
773 | self.processingHeaderObj.size = processingHeaderSize |
|
773 | self.processingHeaderObj.size = processingHeaderSize | |
774 |
|
774 | |||
775 | No newline at end of file |
|
775 |
@@ -1,585 +1,584 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
|||
3 |
|
2 | |||
4 | @author $Author: dsuarez $ |
|
3 | $Author$ | |
5 | @version $Id: VoltageIO.py 110 2012-07-19 15:18:18Z dsuarez $ |
|
4 | $Id$ | |
6 | ''' |
|
5 | ''' | |
7 |
|
6 | |||
8 | import os, sys |
|
7 | import os, sys | |
9 | import numpy |
|
8 | import numpy | |
10 | import glob |
|
9 | import glob | |
11 | import fnmatch |
|
10 | import fnmatch | |
12 | import time, datetime |
|
11 | import time, datetime | |
13 |
|
12 | |||
14 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
15 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
16 |
|
15 | |||
17 | from JROHeader import * |
|
16 | from JROHeader import * | |
18 | from JRODataIO import JRODataReader |
|
17 | from JRODataIO import JRODataReader | |
19 | from JRODataIO import JRODataWriter |
|
18 | from JRODataIO import JRODataWriter | |
20 |
|
19 | |||
21 | from Data.Voltage import Voltage |
|
20 | from Data.Voltage import Voltage | |
22 |
|
21 | |||
23 | class VoltageReader(JRODataReader): |
|
22 | class VoltageReader(JRODataReader): | |
24 | """ |
|
23 | """ | |
25 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
24 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
26 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
27 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
26 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
28 |
|
27 | |||
29 | perfiles * alturas * canales |
|
28 | perfiles * alturas * canales | |
30 |
|
29 | |||
31 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
30 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
32 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
31 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
33 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
32 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
34 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
33 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
35 |
|
34 | |||
36 | Example: |
|
35 | Example: | |
37 |
|
36 | |||
38 | dpath = "/home/myuser/data" |
|
37 | dpath = "/home/myuser/data" | |
39 |
|
38 | |||
40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
39 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
41 |
|
40 | |||
42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
41 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
43 |
|
42 | |||
44 | readerObj = VoltageReader() |
|
43 | readerObj = VoltageReader() | |
45 |
|
44 | |||
46 | readerObj.setup(dpath, startTime, endTime) |
|
45 | readerObj.setup(dpath, startTime, endTime) | |
47 |
|
46 | |||
48 | while(True): |
|
47 | while(True): | |
49 |
|
48 | |||
50 | #to get one profile |
|
49 | #to get one profile | |
51 | profile = readerObj.getData() |
|
50 | profile = readerObj.getData() | |
52 |
|
51 | |||
53 | #print the profile |
|
52 | #print the profile | |
54 | print profile |
|
53 | print profile | |
55 |
|
54 | |||
56 | #If you want to see all datablock |
|
55 | #If you want to see all datablock | |
57 | print readerObj.datablock |
|
56 | print readerObj.datablock | |
58 |
|
57 | |||
59 | if readerObj.flagNoMoreFiles: |
|
58 | if readerObj.flagNoMoreFiles: | |
60 | break |
|
59 | break | |
61 |
|
60 | |||
62 | """ |
|
61 | """ | |
63 |
|
62 | |||
64 | ext = ".r" |
|
63 | ext = ".r" | |
65 |
|
64 | |||
66 | optchar = "D" |
|
65 | optchar = "D" | |
67 | dataOutObj = None |
|
66 | dataOutObj = None | |
68 |
|
67 | |||
69 |
|
68 | |||
70 | def __init__(self, dataOutObj=None): |
|
69 | def __init__(self, dataOutObj=None): | |
71 | """ |
|
70 | """ | |
72 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
71 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
73 |
|
72 | |||
74 | Input: |
|
73 | Input: | |
75 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
74 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para | |
76 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
75 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
77 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
76 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
78 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
77 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
79 | bloque de datos. |
|
78 | bloque de datos. | |
80 | Si este parametro no es pasado se creara uno internamente. |
|
79 | Si este parametro no es pasado se creara uno internamente. | |
81 |
|
80 | |||
82 | Variables afectadas: |
|
81 | Variables afectadas: | |
83 | self.dataOutObj |
|
82 | self.dataOutObj | |
84 |
|
83 | |||
85 | Return: |
|
84 | Return: | |
86 | None |
|
85 | None | |
87 | """ |
|
86 | """ | |
88 |
|
87 | |||
89 | self.datablock = None |
|
88 | self.datablock = None | |
90 |
|
89 | |||
91 | self.utc = 0 |
|
90 | self.utc = 0 | |
92 |
|
91 | |||
93 | self.ext = ".r" |
|
92 | self.ext = ".r" | |
94 |
|
93 | |||
95 | self.optchar = "D" |
|
94 | self.optchar = "D" | |
96 |
|
95 | |||
97 | self.basicHeaderObj = BasicHeader() |
|
96 | self.basicHeaderObj = BasicHeader() | |
98 |
|
97 | |||
99 | self.systemHeaderObj = SystemHeader() |
|
98 | self.systemHeaderObj = SystemHeader() | |
100 |
|
99 | |||
101 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
100 | self.radarControllerHeaderObj = RadarControllerHeader() | |
102 |
|
101 | |||
103 | self.processingHeaderObj = ProcessingHeader() |
|
102 | self.processingHeaderObj = ProcessingHeader() | |
104 |
|
103 | |||
105 | self.online = 0 |
|
104 | self.online = 0 | |
106 |
|
105 | |||
107 | self.fp = None |
|
106 | self.fp = None | |
108 |
|
107 | |||
109 | self.idFile = None |
|
108 | self.idFile = None | |
110 |
|
109 | |||
111 | self.dtype = None |
|
110 | self.dtype = None | |
112 |
|
111 | |||
113 | self.fileSizeByHeader = None |
|
112 | self.fileSizeByHeader = None | |
114 |
|
113 | |||
115 | self.filenameList = [] |
|
114 | self.filenameList = [] | |
116 |
|
115 | |||
117 | self.filename = None |
|
116 | self.filename = None | |
118 |
|
117 | |||
119 | self.fileSize = None |
|
118 | self.fileSize = None | |
120 |
|
119 | |||
121 | self.firstHeaderSize = 0 |
|
120 | self.firstHeaderSize = 0 | |
122 |
|
121 | |||
123 | self.basicHeaderSize = 24 |
|
122 | self.basicHeaderSize = 24 | |
124 |
|
123 | |||
125 | self.pathList = [] |
|
124 | self.pathList = [] | |
126 |
|
125 | |||
127 | self.filenameList = [] |
|
126 | self.filenameList = [] | |
128 |
|
127 | |||
129 | self.lastUTTime = 0 |
|
128 | self.lastUTTime = 0 | |
130 |
|
129 | |||
131 | self.maxTimeStep = 30 |
|
130 | self.maxTimeStep = 30 | |
132 |
|
131 | |||
133 | self.flagNoMoreFiles = 0 |
|
132 | self.flagNoMoreFiles = 0 | |
134 |
|
133 | |||
135 | self.set = 0 |
|
134 | self.set = 0 | |
136 |
|
135 | |||
137 | self.path = None |
|
136 | self.path = None | |
138 |
|
137 | |||
139 | self.profileIndex = 9999 |
|
138 | self.profileIndex = 9999 | |
140 |
|
139 | |||
141 | self.delay = 3 #seconds |
|
140 | self.delay = 3 #seconds | |
142 |
|
141 | |||
143 | self.nTries = 3 #quantity tries |
|
142 | self.nTries = 3 #quantity tries | |
144 |
|
143 | |||
145 | self.nFiles = 3 #number of files for searching |
|
144 | self.nFiles = 3 #number of files for searching | |
146 |
|
145 | |||
147 | self.nReadBlocks = 0 |
|
146 | self.nReadBlocks = 0 | |
148 |
|
147 | |||
149 | self.flagIsNewFile = 1 |
|
148 | self.flagIsNewFile = 1 | |
150 |
|
149 | |||
151 | self.ippSeconds = 0 |
|
150 | self.ippSeconds = 0 | |
152 |
|
151 | |||
153 | self.flagTimeBlock = 0 |
|
152 | self.flagTimeBlock = 0 | |
154 |
|
153 | |||
155 | self.flagIsNewBlock = 0 |
|
154 | self.flagIsNewBlock = 0 | |
156 |
|
155 | |||
157 | self.nTotalBlocks = 0 |
|
156 | self.nTotalBlocks = 0 | |
158 |
|
157 | |||
159 | self.blocksize = 0 |
|
158 | self.blocksize = 0 | |
160 |
|
159 | |||
161 | def createObjByDefault(self): |
|
160 | def createObjByDefault(self): | |
162 |
|
161 | |||
163 | dataObj = Voltage() |
|
162 | dataObj = Voltage() | |
164 |
|
163 | |||
165 | return dataObj |
|
164 | return dataObj | |
166 |
|
165 | |||
167 | def __hasNotDataInBuffer(self): |
|
166 | def __hasNotDataInBuffer(self): | |
168 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
167 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
169 | return 1 |
|
168 | return 1 | |
170 | return 0 |
|
169 | return 0 | |
171 |
|
170 | |||
172 |
|
171 | |||
173 | def getBlockDimension(self): |
|
172 | def getBlockDimension(self): | |
174 | """ |
|
173 | """ | |
175 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
174 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
176 |
|
175 | |||
177 | Affected: |
|
176 | Affected: | |
178 | self.blocksize |
|
177 | self.blocksize | |
179 |
|
178 | |||
180 | Return: |
|
179 | Return: | |
181 | None |
|
180 | None | |
182 | """ |
|
181 | """ | |
183 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
182 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
184 | self.blocksize = pts2read |
|
183 | self.blocksize = pts2read | |
185 |
|
184 | |||
186 |
|
185 | |||
187 | def readBlock(self): |
|
186 | def readBlock(self): | |
188 | """ |
|
187 | """ | |
189 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
188 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
190 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
189 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
191 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
190 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
192 | es seteado a 0 |
|
191 | es seteado a 0 | |
193 |
|
192 | |||
194 | Inputs: |
|
193 | Inputs: | |
195 | None |
|
194 | None | |
196 |
|
195 | |||
197 | Return: |
|
196 | Return: | |
198 | None |
|
197 | None | |
199 |
|
198 | |||
200 | Affected: |
|
199 | Affected: | |
201 | self.profileIndex |
|
200 | self.profileIndex | |
202 | self.datablock |
|
201 | self.datablock | |
203 | self.flagIsNewFile |
|
202 | self.flagIsNewFile | |
204 | self.flagIsNewBlock |
|
203 | self.flagIsNewBlock | |
205 | self.nTotalBlocks |
|
204 | self.nTotalBlocks | |
206 |
|
205 | |||
207 | Exceptions: |
|
206 | Exceptions: | |
208 | Si un bloque leido no es un bloque valido |
|
207 | Si un bloque leido no es un bloque valido | |
209 | """ |
|
208 | """ | |
210 |
|
209 | |||
211 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
210 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
212 |
|
211 | |||
213 | try: |
|
212 | try: | |
214 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
213 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
215 | except: |
|
214 | except: | |
216 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
215 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
217 | return 0 |
|
216 | return 0 | |
218 |
|
217 | |||
219 | junk = numpy.transpose(junk, (2,0,1)) |
|
218 | junk = numpy.transpose(junk, (2,0,1)) | |
220 | self.datablock = junk['real'] + junk['imag']*1j |
|
219 | self.datablock = junk['real'] + junk['imag']*1j | |
221 |
|
220 | |||
222 | self.profileIndex = 0 |
|
221 | self.profileIndex = 0 | |
223 |
|
222 | |||
224 | self.flagIsNewFile = 0 |
|
223 | self.flagIsNewFile = 0 | |
225 | self.flagIsNewBlock = 1 |
|
224 | self.flagIsNewBlock = 1 | |
226 |
|
225 | |||
227 | self.nTotalBlocks += 1 |
|
226 | self.nTotalBlocks += 1 | |
228 | self.nReadBlocks += 1 |
|
227 | self.nReadBlocks += 1 | |
229 |
|
228 | |||
230 | return 1 |
|
229 | return 1 | |
231 |
|
230 | |||
232 |
|
231 | |||
233 | def getData(self): |
|
232 | def getData(self): | |
234 | """ |
|
233 | """ | |
235 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
236 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
235 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
237 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
236 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
238 |
|
237 | |||
239 | Ademas incrementa el contador del buffer en 1. |
|
238 | Ademas incrementa el contador del buffer en 1. | |
240 |
|
239 | |||
241 | Return: |
|
240 | Return: | |
242 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
243 | buffer. Si no hay mas archivos a leer retorna None. |
|
242 | buffer. Si no hay mas archivos a leer retorna None. | |
244 |
|
243 | |||
245 | Variables afectadas: |
|
244 | Variables afectadas: | |
246 | self.dataOutObj |
|
245 | self.dataOutObj | |
247 | self.profileIndex |
|
246 | self.profileIndex | |
248 |
|
247 | |||
249 | Affected: |
|
248 | Affected: | |
250 | self.dataOutObj |
|
249 | self.dataOutObj | |
251 | self.profileIndex |
|
250 | self.profileIndex | |
252 | self.flagTimeBlock |
|
251 | self.flagTimeBlock | |
253 | self.flagIsNewBlock |
|
252 | self.flagIsNewBlock | |
254 | """ |
|
253 | """ | |
255 | if self.flagNoMoreFiles: return 0 |
|
254 | if self.flagNoMoreFiles: return 0 | |
256 |
|
255 | |||
257 | self.flagTimeBlock = 0 |
|
256 | self.flagTimeBlock = 0 | |
258 | self.flagIsNewBlock = 0 |
|
257 | self.flagIsNewBlock = 0 | |
259 |
|
258 | |||
260 | if self.__hasNotDataInBuffer(): |
|
259 | if self.__hasNotDataInBuffer(): | |
261 |
|
260 | |||
262 | if not( self.readNextBlock() ): |
|
261 | if not( self.readNextBlock() ): | |
263 | return 0 |
|
262 | return 0 | |
264 |
|
263 | |||
265 | # self.updateDataHeader() |
|
264 | # self.updateDataHeader() | |
266 |
|
265 | |||
267 | if self.flagNoMoreFiles == 1: |
|
266 | if self.flagNoMoreFiles == 1: | |
268 | print 'Process finished' |
|
267 | print 'Process finished' | |
269 | return 0 |
|
268 | return 0 | |
270 |
|
269 | |||
271 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
272 |
|
271 | |||
273 | if self.datablock == None: |
|
272 | if self.datablock == None: | |
274 | self.dataOutObj.flagNoData = True |
|
273 | self.dataOutObj.flagNoData = True | |
275 | return 0 |
|
274 | return 0 | |
276 |
|
275 | |||
277 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] |
|
276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] | |
278 |
|
277 | |||
279 | self.dataOutObj.dtype = self.dtype |
|
278 | self.dataOutObj.dtype = self.dtype | |
280 |
|
279 | |||
281 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels |
|
280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels | |
282 |
|
281 | |||
283 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
284 |
|
283 | |||
285 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
286 |
|
285 | |||
287 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
288 |
|
287 | |||
289 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
290 |
|
289 | |||
291 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
292 |
|
291 | |||
293 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
294 |
|
293 | |||
295 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
296 |
|
295 | |||
297 | self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.profileIndex * self.ippSeconds |
|
296 | self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
298 |
|
297 | |||
299 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt |
|
298 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt | |
300 |
|
299 | |||
301 | self.dataOutObj.flagShiftFFT = False |
|
300 | self.dataOutObj.flagShiftFFT = False | |
302 |
|
301 | |||
303 | if self.processingHeaderObj.code != None: |
|
302 | if self.processingHeaderObj.code != None: | |
304 | self.dataOutObj.nCode = self.processingHeaderObj.nCode |
|
303 | self.dataOutObj.nCode = self.processingHeaderObj.nCode | |
305 |
|
304 | |||
306 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud |
|
305 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud | |
307 |
|
306 | |||
308 | self.dataOutObj.code = self.processingHeaderObj.code |
|
307 | self.dataOutObj.code = self.processingHeaderObj.code | |
309 |
|
308 | |||
310 | self.profileIndex += 1 |
|
309 | self.profileIndex += 1 | |
311 |
|
310 | |||
312 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
311 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
313 |
|
312 | |||
314 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
313 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
315 |
|
314 | |||
316 | self.dataOutObj.flagNoData = False |
|
315 | self.dataOutObj.flagNoData = False | |
317 |
|
316 | |||
318 | return 1 |
|
317 | return 1 | |
319 |
|
318 | |||
320 |
|
319 | |||
321 | class VoltageWriter(JRODataWriter): |
|
320 | class VoltageWriter(JRODataWriter): | |
322 | """ |
|
321 | """ | |
323 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
322 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
324 | de los datos siempre se realiza por bloques. |
|
323 | de los datos siempre se realiza por bloques. | |
325 | """ |
|
324 | """ | |
326 |
|
325 | |||
327 | ext = ".r" |
|
326 | ext = ".r" | |
328 |
|
327 | |||
329 | optchar = "D" |
|
328 | optchar = "D" | |
330 |
|
329 | |||
331 | shapeBuffer = None |
|
330 | shapeBuffer = None | |
332 |
|
331 | |||
333 |
|
332 | |||
334 | def __init__(self, dataOutObj=None): |
|
333 | def __init__(self, dataOutObj=None): | |
335 | """ |
|
334 | """ | |
336 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
335 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
337 |
|
336 | |||
338 | Affected: |
|
337 | Affected: | |
339 | self.dataOutObj |
|
338 | self.dataOutObj | |
340 |
|
339 | |||
341 | Return: None |
|
340 | Return: None | |
342 | """ |
|
341 | """ | |
343 | if dataOutObj == None: |
|
342 | if dataOutObj == None: | |
344 | dataOutObj = Voltage() |
|
343 | dataOutObj = Voltage() | |
345 |
|
344 | |||
346 | if not( isinstance(dataOutObj, Voltage) ): |
|
345 | if not( isinstance(dataOutObj, Voltage) ): | |
347 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" |
|
346 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" | |
348 |
|
347 | |||
349 | self.dataOutObj = dataOutObj |
|
348 | self.dataOutObj = dataOutObj | |
350 |
|
349 | |||
351 | self.nTotalBlocks = 0 |
|
350 | self.nTotalBlocks = 0 | |
352 |
|
351 | |||
353 | self.profileIndex = 0 |
|
352 | self.profileIndex = 0 | |
354 |
|
353 | |||
355 | def hasAllDataInBuffer(self): |
|
354 | def hasAllDataInBuffer(self): | |
356 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
355 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
357 | return 1 |
|
356 | return 1 | |
358 | return 0 |
|
357 | return 0 | |
359 |
|
358 | |||
360 |
|
359 | |||
361 | def setBlockDimension(self): |
|
360 | def setBlockDimension(self): | |
362 | """ |
|
361 | """ | |
363 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
362 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
364 |
|
363 | |||
365 | Affected: |
|
364 | Affected: | |
366 | self.shape_spc_Buffer |
|
365 | self.shape_spc_Buffer | |
367 | self.shape_cspc_Buffer |
|
366 | self.shape_cspc_Buffer | |
368 | self.shape_dc_Buffer |
|
367 | self.shape_dc_Buffer | |
369 |
|
368 | |||
370 | Return: None |
|
369 | Return: None | |
371 | """ |
|
370 | """ | |
372 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
371 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
373 | self.processingHeaderObj.nHeights, |
|
372 | self.processingHeaderObj.nHeights, | |
374 | self.systemHeaderObj.nChannels) |
|
373 | self.systemHeaderObj.nChannels) | |
375 |
|
374 | |||
376 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
375 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
377 | self.processingHeaderObj.profilesPerBlock, |
|
376 | self.processingHeaderObj.profilesPerBlock, | |
378 | self.processingHeaderObj.nHeights), |
|
377 | self.processingHeaderObj.nHeights), | |
379 | dtype=numpy.dtype('complex')) |
|
378 | dtype=numpy.dtype('complex')) | |
380 |
|
379 | |||
381 |
|
380 | |||
382 | def writeBlock(self): |
|
381 | def writeBlock(self): | |
383 | """ |
|
382 | """ | |
384 | Escribe el buffer en el file designado |
|
383 | Escribe el buffer en el file designado | |
385 |
|
384 | |||
386 | Affected: |
|
385 | Affected: | |
387 | self.profileIndex |
|
386 | self.profileIndex | |
388 | self.flagIsNewFile |
|
387 | self.flagIsNewFile | |
389 | self.flagIsNewBlock |
|
388 | self.flagIsNewBlock | |
390 | self.nTotalBlocks |
|
389 | self.nTotalBlocks | |
391 | self.blockIndex |
|
390 | self.blockIndex | |
392 |
|
391 | |||
393 | Return: None |
|
392 | Return: None | |
394 | """ |
|
393 | """ | |
395 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
394 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
396 |
|
395 | |||
397 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
396 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
398 |
|
397 | |||
399 | data['real'] = junk.real |
|
398 | data['real'] = junk.real | |
400 | data['imag'] = junk.imag |
|
399 | data['imag'] = junk.imag | |
401 |
|
400 | |||
402 | data = data.reshape( (-1) ) |
|
401 | data = data.reshape( (-1) ) | |
403 |
|
402 | |||
404 | data.tofile( self.fp ) |
|
403 | data.tofile( self.fp ) | |
405 |
|
404 | |||
406 | self.datablock.fill(0) |
|
405 | self.datablock.fill(0) | |
407 |
|
406 | |||
408 | self.profileIndex = 0 |
|
407 | self.profileIndex = 0 | |
409 | self.flagIsNewFile = 0 |
|
408 | self.flagIsNewFile = 0 | |
410 | self.flagIsNewBlock = 1 |
|
409 | self.flagIsNewBlock = 1 | |
411 |
|
410 | |||
412 | self.blockIndex += 1 |
|
411 | self.blockIndex += 1 | |
413 | self.nTotalBlocks += 1 |
|
412 | self.nTotalBlocks += 1 | |
414 |
|
413 | |||
415 | def putData(self): |
|
414 | def putData(self): | |
416 | """ |
|
415 | """ | |
417 | Setea un bloque de datos y luego los escribe en un file |
|
416 | Setea un bloque de datos y luego los escribe en un file | |
418 |
|
417 | |||
419 | Affected: |
|
418 | Affected: | |
420 | self.flagIsNewBlock |
|
419 | self.flagIsNewBlock | |
421 | self.profileIndex |
|
420 | self.profileIndex | |
422 |
|
421 | |||
423 | Return: |
|
422 | Return: | |
424 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
423 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
425 | 1 : Si se escribio la data de un bloque en un file |
|
424 | 1 : Si se escribio la data de un bloque en un file | |
426 | """ |
|
425 | """ | |
427 | self.flagIsNewBlock = 0 |
|
426 | self.flagIsNewBlock = 0 | |
428 |
|
427 | |||
429 | if self.dataOutObj.flagNoData: |
|
428 | if self.dataOutObj.flagNoData: | |
430 | return 0 |
|
429 | return 0 | |
431 |
|
430 | |||
432 | if self.dataOutObj.flagTimeBlock: |
|
431 | if self.dataOutObj.flagTimeBlock: | |
433 |
|
432 | |||
434 | self.datablock.fill(0) |
|
433 | self.datablock.fill(0) | |
435 | self.profileIndex = 0 |
|
434 | self.profileIndex = 0 | |
436 | self.setNextFile() |
|
435 | self.setNextFile() | |
437 |
|
436 | |||
438 | if self.profileIndex == 0: |
|
437 | if self.profileIndex == 0: | |
439 | self.getBasicHeader() |
|
438 | self.getBasicHeader() | |
440 |
|
439 | |||
441 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data |
|
440 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data | |
442 |
|
441 | |||
443 | self.profileIndex += 1 |
|
442 | self.profileIndex += 1 | |
444 |
|
443 | |||
445 | if self.hasAllDataInBuffer(): |
|
444 | if self.hasAllDataInBuffer(): | |
446 | #if self.flagIsNewFile: |
|
445 | #if self.flagIsNewFile: | |
447 | self.writeNextBlock() |
|
446 | self.writeNextBlock() | |
448 | # self.getDataHeader() |
|
447 | # self.getDataHeader() | |
449 |
|
448 | |||
450 | if self.flagNoMoreFiles: |
|
449 | if self.flagNoMoreFiles: | |
451 | #print 'Process finished' |
|
450 | #print 'Process finished' | |
452 | return 0 |
|
451 | return 0 | |
453 |
|
452 | |||
454 | return 1 |
|
453 | return 1 | |
455 |
|
454 | |||
456 | def __getProcessFlags(self): |
|
455 | def __getProcessFlags(self): | |
457 |
|
456 | |||
458 | processFlags = 0 |
|
457 | processFlags = 0 | |
459 |
|
458 | |||
460 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
459 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
461 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
460 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
462 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
461 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
463 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
462 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
464 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
463 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
465 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
464 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
466 |
|
465 | |||
467 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
466 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
468 |
|
467 | |||
469 |
|
468 | |||
470 |
|
469 | |||
471 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
470 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
472 | PROCFLAG.DATATYPE_SHORT, |
|
471 | PROCFLAG.DATATYPE_SHORT, | |
473 | PROCFLAG.DATATYPE_LONG, |
|
472 | PROCFLAG.DATATYPE_LONG, | |
474 | PROCFLAG.DATATYPE_INT64, |
|
473 | PROCFLAG.DATATYPE_INT64, | |
475 | PROCFLAG.DATATYPE_FLOAT, |
|
474 | PROCFLAG.DATATYPE_FLOAT, | |
476 | PROCFLAG.DATATYPE_DOUBLE] |
|
475 | PROCFLAG.DATATYPE_DOUBLE] | |
477 |
|
476 | |||
478 |
|
477 | |||
479 | for index in range(len(dtypeList)): |
|
478 | for index in range(len(dtypeList)): | |
480 | if self.dataOutObj.dtype == dtypeList[index]: |
|
479 | if self.dataOutObj.dtype == dtypeList[index]: | |
481 | dtypeValue = datatypeValueList[index] |
|
480 | dtypeValue = datatypeValueList[index] | |
482 | break |
|
481 | break | |
483 |
|
482 | |||
484 | processFlags += dtypeValue |
|
483 | processFlags += dtypeValue | |
485 |
|
484 | |||
486 | if self.dataOutObj.flagDecodeData: |
|
485 | if self.dataOutObj.flagDecodeData: | |
487 | processFlags += PROCFLAG.DECODE_DATA |
|
486 | processFlags += PROCFLAG.DECODE_DATA | |
488 |
|
487 | |||
489 | if self.dataOutObj.flagDeflipData: |
|
488 | if self.dataOutObj.flagDeflipData: | |
490 | processFlags += PROCFLAG.DEFLIP_DATA |
|
489 | processFlags += PROCFLAG.DEFLIP_DATA | |
491 |
|
490 | |||
492 | if self.dataOutObj.code != None: |
|
491 | if self.dataOutObj.code != None: | |
493 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
492 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
494 |
|
493 | |||
495 | if self.dataOutObj.nCohInt > 1: |
|
494 | if self.dataOutObj.nCohInt > 1: | |
496 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
495 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
497 |
|
496 | |||
498 | return processFlags |
|
497 | return processFlags | |
499 |
|
498 | |||
500 |
|
499 | |||
501 | def __getBlockSize(self): |
|
500 | def __getBlockSize(self): | |
502 | ''' |
|
501 | ''' | |
503 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
502 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
504 | ''' |
|
503 | ''' | |
505 |
|
504 | |||
506 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
505 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
507 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
506 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
508 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
507 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
509 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
508 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
510 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
509 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
511 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
510 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
512 |
|
511 | |||
513 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
512 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
514 | datatypeValueList = [1,2,4,8,4,8] |
|
513 | datatypeValueList = [1,2,4,8,4,8] | |
515 | for index in range(len(dtypeList)): |
|
514 | for index in range(len(dtypeList)): | |
516 | if self.dataOutObj.dtype == dtypeList[index]: |
|
515 | if self.dataOutObj.dtype == dtypeList[index]: | |
517 | datatypeValue = datatypeValueList[index] |
|
516 | datatypeValue = datatypeValueList[index] | |
518 | break |
|
517 | break | |
519 |
|
518 | |||
520 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) |
|
519 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) | |
521 |
|
520 | |||
522 | return blocksize |
|
521 | return blocksize | |
523 |
|
522 | |||
524 |
|
523 | |||
525 | def getBasicHeader(self): |
|
524 | def getBasicHeader(self): | |
526 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
525 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
527 | self.basicHeaderObj.version = self.versionFile |
|
526 | self.basicHeaderObj.version = self.versionFile | |
528 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
527 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
529 |
|
528 | |||
530 | utc = numpy.floor(self.dataOutObj.dataUtcTime) |
|
529 | utc = numpy.floor(self.dataOutObj.dataUtcTime) | |
531 | milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0 |
|
530 | milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0 | |
532 |
|
531 | |||
533 | self.basicHeaderObj.utc = utc |
|
532 | self.basicHeaderObj.utc = utc | |
534 | self.basicHeaderObj.miliSecond = milisecond |
|
533 | self.basicHeaderObj.miliSecond = milisecond | |
535 | self.basicHeaderObj.timeZone = 0 |
|
534 | self.basicHeaderObj.timeZone = 0 | |
536 | self.basicHeaderObj.dstFlag = 0 |
|
535 | self.basicHeaderObj.dstFlag = 0 | |
537 | self.basicHeaderObj.errorCount = 0 |
|
536 | self.basicHeaderObj.errorCount = 0 | |
538 |
|
537 | |||
539 | def getDataHeader(self): |
|
538 | def getDataHeader(self): | |
540 |
|
539 | |||
541 | """ |
|
540 | """ | |
542 | Obtiene una copia del First Header |
|
541 | Obtiene una copia del First Header | |
543 |
|
542 | |||
544 | Affected: |
|
543 | Affected: | |
545 | self.systemHeaderObj |
|
544 | self.systemHeaderObj | |
546 | self.radarControllerHeaderObj |
|
545 | self.radarControllerHeaderObj | |
547 | self.dtype |
|
546 | self.dtype | |
548 |
|
547 | |||
549 | Return: |
|
548 | Return: | |
550 | None |
|
549 | None | |
551 | """ |
|
550 | """ | |
552 |
|
551 | |||
553 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
552 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
554 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
553 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
555 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
554 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
556 |
|
555 | |||
557 | self.getBasicHeader() |
|
556 | self.getBasicHeader() | |
558 |
|
557 | |||
559 | processingHeaderSize = 40 # bytes |
|
558 | processingHeaderSize = 40 # bytes | |
560 | self.processingHeaderObj.dtype = 0 # Voltage |
|
559 | self.processingHeaderObj.dtype = 0 # Voltage | |
561 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
560 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
562 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
561 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
563 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
562 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
564 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
563 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
565 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
564 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
566 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt |
|
565 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt | |
567 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
566 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
568 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
567 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
569 |
|
568 | |||
570 | if self.dataOutObj.code != None: |
|
569 | if self.dataOutObj.code != None: | |
571 | self.processingHeaderObj.code = self.dataOutObj.code |
|
570 | self.processingHeaderObj.code = self.dataOutObj.code | |
572 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
571 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
573 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
572 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
574 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
573 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
575 | processingHeaderSize += codesize |
|
574 | processingHeaderSize += codesize | |
576 |
|
575 | |||
577 | if self.processingHeaderObj.nWindows != 0: |
|
576 | if self.processingHeaderObj.nWindows != 0: | |
578 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
577 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
579 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
578 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
580 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
579 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
581 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
580 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
582 | processingHeaderSize += 12 |
|
581 | processingHeaderSize += 12 | |
583 |
|
582 | |||
584 | self.processingHeaderObj.size = processingHeaderSize |
|
583 | self.processingHeaderObj.size = processingHeaderSize | |
585 | No newline at end of file |
|
584 |
@@ -1,388 +1,388 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
|||
3 |
|
2 | |||
4 | @author $Author: murco $ |
|
3 | $Author$ | |
5 | @version $Id: SpectraProcessor.py 119 2012-09-05 17:06:09Z murco $ |
|
4 | $Id$ | |
6 | ''' |
|
5 | ''' | |
|
6 | ||||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import time |
|
9 | import time | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Data.Spectra import Spectra |
|
14 | from Data.Spectra import Spectra | |
15 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter | |
16 | #from Graphics.SpectraPlot import Spectrum |
|
16 | #from Graphics.SpectraPlot import Spectrum | |
17 | #from JRONoise import Noise |
|
17 | #from JRONoise import Noise | |
18 |
|
18 | |||
19 | class SpectraProcessor: |
|
19 | class SpectraProcessor: | |
20 | ''' |
|
20 | ''' | |
21 | classdocs |
|
21 | classdocs | |
22 | ''' |
|
22 | ''' | |
23 |
|
23 | |||
24 | dataInObj = None |
|
24 | dataInObj = None | |
25 |
|
25 | |||
26 | dataOutObj = None |
|
26 | dataOutObj = None | |
27 |
|
27 | |||
28 | noiseObj = None |
|
28 | noiseObj = None | |
29 |
|
29 | |||
30 | integratorObjList = [] |
|
30 | integratorObjList = [] | |
31 |
|
31 | |||
32 | writerObjList = [] |
|
32 | writerObjList = [] | |
33 |
|
33 | |||
34 | integratorObjIndex = None |
|
34 | integratorObjIndex = None | |
35 |
|
35 | |||
36 | writerObjIndex = None |
|
36 | writerObjIndex = None | |
37 |
|
37 | |||
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage | |
39 |
|
39 | |||
40 | # integratorObjList = [] |
|
40 | # integratorObjList = [] | |
41 | # |
|
41 | # | |
42 | # decoderObjList = [] |
|
42 | # decoderObjList = [] | |
43 | # |
|
43 | # | |
44 | # writerObjList = [] |
|
44 | # writerObjList = [] | |
45 | # |
|
45 | # | |
46 | # plotterObjList = [] |
|
46 | # plotterObjList = [] | |
47 | # |
|
47 | # | |
48 | # integratorObjIndex = None |
|
48 | # integratorObjIndex = None | |
49 | # |
|
49 | # | |
50 | # decoderObjIndex = None |
|
50 | # decoderObjIndex = None | |
51 | # |
|
51 | # | |
52 | # writerObjIndex = None |
|
52 | # writerObjIndex = None | |
53 | # |
|
53 | # | |
54 | # plotterObjIndex = None |
|
54 | # plotterObjIndex = None | |
55 | # |
|
55 | # | |
56 | # buffer = None |
|
56 | # buffer = None | |
57 | # |
|
57 | # | |
58 | # profIndex = 0 |
|
58 | # profIndex = 0 | |
59 | # |
|
59 | # | |
60 | # nFFTPoints = None |
|
60 | # nFFTPoints = None | |
61 | # |
|
61 | # | |
62 | # nChannels = None |
|
62 | # nChannels = None | |
63 | # |
|
63 | # | |
64 | # nHeights = None |
|
64 | # nHeights = None | |
65 | # |
|
65 | # | |
66 | # nPairs = None |
|
66 | # nPairs = None | |
67 | # |
|
67 | # | |
68 | # pairList = None |
|
68 | # pairList = None | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | def __init__(self): |
|
71 | def __init__(self): | |
72 | ''' |
|
72 | ''' | |
73 | Constructor |
|
73 | Constructor | |
74 | ''' |
|
74 | ''' | |
75 |
|
75 | |||
76 | self.integratorObjIndex = None |
|
76 | self.integratorObjIndex = None | |
77 | self.writerObjIndex = None |
|
77 | self.writerObjIndex = None | |
78 | self.integratorObjList = [] |
|
78 | self.integratorObjList = [] | |
79 | self.writerObjList = [] |
|
79 | self.writerObjList = [] | |
80 | self.noiseObj = None |
|
80 | self.noiseObj = None | |
81 | self.buffer = None |
|
81 | self.buffer = None | |
82 | self.profIndex = 0 |
|
82 | self.profIndex = 0 | |
83 |
|
83 | |||
84 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
84 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): | |
85 |
|
85 | |||
86 | if dataInObj == None: |
|
86 | if dataInObj == None: | |
87 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
87 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" | |
88 |
|
88 | |||
89 | if dataInObj.type == "Voltage": |
|
89 | if dataInObj.type == "Voltage": | |
90 | if nFFTPoints == None: |
|
90 | if nFFTPoints == None: | |
91 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
91 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" | |
92 | else: |
|
92 | else: | |
93 | nFFTPoints = dataInObj.nFFTPoints |
|
93 | nFFTPoints = dataInObj.nFFTPoints | |
94 |
|
94 | |||
95 | self.dataInObj = dataInObj |
|
95 | self.dataInObj = dataInObj | |
96 |
|
96 | |||
97 | if dataOutObj == None: |
|
97 | if dataOutObj == None: | |
98 | dataOutObj = Spectra() |
|
98 | dataOutObj = Spectra() | |
99 |
|
99 | |||
100 | self.dataOutObj = dataOutObj |
|
100 | self.dataOutObj = dataOutObj | |
101 |
|
101 | |||
102 | # self.noiseObj = Noise() #aun no se incluye el objeto Noise() |
|
102 | # self.noiseObj = Noise() #aun no se incluye el objeto Noise() | |
103 |
|
103 | |||
104 | ########################################## |
|
104 | ########################################## | |
105 | # self.nFFTPoints = nFFTPoints |
|
105 | # self.nFFTPoints = nFFTPoints | |
106 | # self.nChannels = self.dataInObj.nChannels |
|
106 | # self.nChannels = self.dataInObj.nChannels | |
107 | # self.nHeights = self.dataInObj.nHeights |
|
107 | # self.nHeights = self.dataInObj.nHeights | |
108 | # self.pairList = pairList |
|
108 | # self.pairList = pairList | |
109 | # if pairList != None: |
|
109 | # if pairList != None: | |
110 | # self.nPairs = len(pairList) |
|
110 | # self.nPairs = len(pairList) | |
111 | # else: |
|
111 | # else: | |
112 | # self.nPairs = 0 |
|
112 | # self.nPairs = 0 | |
113 | # |
|
113 | # | |
114 | # self.dataOutObj.heightList = self.dataInObj.heightList |
|
114 | # self.dataOutObj.heightList = self.dataInObj.heightList | |
115 | # self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
115 | # self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
116 | # self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
116 | # self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() | |
117 | # self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
117 | # self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() | |
118 | # self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
118 | # self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() | |
119 | # self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
119 | # self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() | |
120 | # |
|
120 | # | |
121 | # self.dataOutObj.dataType = self.dataInObj.dataType |
|
121 | # self.dataOutObj.dataType = self.dataInObj.dataType | |
122 | # self.dataOutObj.nPairs = self.nPairs |
|
122 | # self.dataOutObj.nPairs = self.nPairs | |
123 | # self.dataOutObj.nChannels = self.nChannels |
|
123 | # self.dataOutObj.nChannels = self.nChannels | |
124 | # self.dataOutObj.nProfiles = self.nFFTPoints |
|
124 | # self.dataOutObj.nProfiles = self.nFFTPoints | |
125 | # self.dataOutObj.nHeights = self.nHeights |
|
125 | # self.dataOutObj.nHeights = self.nHeights | |
126 | # self.dataOutObj.nFFTPoints = self.nFFTPoints |
|
126 | # self.dataOutObj.nFFTPoints = self.nFFTPoints | |
127 | # #self.dataOutObj.data = None |
|
127 | # #self.dataOutObj.data = None | |
128 | # |
|
128 | # | |
129 | # self.dataOutObj.m_SystemHeader.numChannels = self.nChannels |
|
129 | # self.dataOutObj.m_SystemHeader.numChannels = self.nChannels | |
130 | # self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints |
|
130 | # self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints | |
131 | # |
|
131 | # | |
132 | # self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs |
|
132 | # self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs | |
133 | # self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints |
|
133 | # self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints | |
134 | # self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights |
|
134 | # self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights | |
135 | # self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
135 | # self.dataOutObj.m_ProcessingHeader.shif_fft = True | |
136 | # |
|
136 | # | |
137 | # spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) |
|
137 | # spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) | |
138 | # k = 0 |
|
138 | # k = 0 | |
139 | # for i in range( 0,self.nChannels*2,2 ): |
|
139 | # for i in range( 0,self.nChannels*2,2 ): | |
140 | # spectraComb[i] = k |
|
140 | # spectraComb[i] = k | |
141 | # spectraComb[i+1] = k |
|
141 | # spectraComb[i+1] = k | |
142 | # k += 1 |
|
142 | # k += 1 | |
143 | # |
|
143 | # | |
144 | # k *= 2 |
|
144 | # k *= 2 | |
145 | # |
|
145 | # | |
146 | # if self.pairList != None: |
|
146 | # if self.pairList != None: | |
147 | # |
|
147 | # | |
148 | # for pair in self.pairList: |
|
148 | # for pair in self.pairList: | |
149 | # spectraComb[k] = pair[0] |
|
149 | # spectraComb[k] = pair[0] | |
150 | # spectraComb[k+1] = pair[1] |
|
150 | # spectraComb[k+1] = pair[1] | |
151 | # k += 2 |
|
151 | # k += 2 | |
152 | # |
|
152 | # | |
153 | # self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
153 | # self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
154 |
|
154 | |||
155 | return self.dataOutObj |
|
155 | return self.dataOutObj | |
156 |
|
156 | |||
157 | def init(self): |
|
157 | def init(self): | |
158 | # |
|
158 | # | |
159 | # self.nHeights = self.dataInObj.nHeights |
|
159 | # self.nHeights = self.dataInObj.nHeights | |
160 | # self.dataOutObj.nHeights = self.nHeights |
|
160 | # self.dataOutObj.nHeights = self.nHeights | |
161 | # self.dataOutObj.heightList = self.dataInObj.heightList |
|
161 | # self.dataOutObj.heightList = self.dataInObj.heightList | |
162 | # |
|
162 | # | |
163 |
|
163 | |||
164 | self.integratorObjIndex = 0 |
|
164 | self.integratorObjIndex = 0 | |
165 | self.writerObjIndex = 0 |
|
165 | self.writerObjIndex = 0 | |
166 |
|
166 | |||
167 | if self.dataInObj.type == "Voltage": |
|
167 | if self.dataInObj.type == "Voltage": | |
168 |
|
168 | |||
169 | if self.buffer == None: |
|
169 | if self.buffer == None: | |
170 | self.buffer = numpy.zeros((self.nChannels, |
|
170 | self.buffer = numpy.zeros((self.nChannels, | |
171 | self.nFFTPoints, |
|
171 | self.nFFTPoints, | |
172 | self.dataInObj.nHeights), |
|
172 | self.dataInObj.nHeights), | |
173 | dtype='complex') |
|
173 | dtype='complex') | |
174 |
|
174 | |||
175 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
175 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
176 | self.profIndex += 1 |
|
176 | self.profIndex += 1 | |
177 |
|
177 | |||
178 | if self.profIndex == self.nFFTPoints: |
|
178 | if self.profIndex == self.nFFTPoints: | |
179 | self.__getFft() |
|
179 | self.__getFft() | |
180 | self.dataOutObj.flagNoData = False |
|
180 | self.dataOutObj.flagNoData = False | |
181 |
|
181 | |||
182 | self.buffer = None |
|
182 | self.buffer = None | |
183 | self.profIndex = 0 |
|
183 | self.profIndex = 0 | |
184 | return |
|
184 | return | |
185 |
|
185 | |||
186 | self.dataOutObj.flagNoData = True |
|
186 | self.dataOutObj.flagNoData = True | |
187 |
|
187 | |||
188 | return |
|
188 | return | |
189 |
|
189 | |||
190 | #Other kind of data |
|
190 | #Other kind of data | |
191 | if self.dataInObj.type == "Spectra": |
|
191 | if self.dataInObj.type == "Spectra": | |
192 | self.dataOutObj.copy(self.dataInObj) |
|
192 | self.dataOutObj.copy(self.dataInObj) | |
193 | self.dataOutObj.flagNoData = False |
|
193 | self.dataOutObj.flagNoData = False | |
194 | return |
|
194 | return | |
195 |
|
195 | |||
196 | raise ValueError, "The datatype is not valid" |
|
196 | raise ValueError, "The datatype is not valid" | |
197 |
|
197 | |||
198 | def __getFft(self): |
|
198 | def __getFft(self): | |
199 | """ |
|
199 | """ | |
200 | Convierte valores de Voltaje a Spectra |
|
200 | Convierte valores de Voltaje a Spectra | |
201 |
|
201 | |||
202 | Affected: |
|
202 | Affected: | |
203 | self.dataOutObj.data_spc |
|
203 | self.dataOutObj.data_spc | |
204 | self.dataOutObj.data_cspc |
|
204 | self.dataOutObj.data_cspc | |
205 | self.dataOutObj.data_dc |
|
205 | self.dataOutObj.data_dc | |
206 | self.dataOutObj.heightList |
|
206 | self.dataOutObj.heightList | |
207 | self.dataOutObj.m_BasicHeader |
|
207 | self.dataOutObj.m_BasicHeader | |
208 | self.dataOutObj.m_ProcessingHeader |
|
208 | self.dataOutObj.m_ProcessingHeader | |
209 | self.dataOutObj.m_RadarControllerHeader |
|
209 | self.dataOutObj.m_RadarControllerHeader | |
210 | self.dataOutObj.m_SystemHeader |
|
210 | self.dataOutObj.m_SystemHeader | |
211 | self.profIndex |
|
211 | self.profIndex | |
212 | self.buffer |
|
212 | self.buffer | |
213 | self.dataOutObj.flagNoData |
|
213 | self.dataOutObj.flagNoData | |
214 | self.dataOutObj.dataType |
|
214 | self.dataOutObj.dataType | |
215 | self.dataOutObj.nPairs |
|
215 | self.dataOutObj.nPairs | |
216 | self.dataOutObj.nChannels |
|
216 | self.dataOutObj.nChannels | |
217 | self.dataOutObj.nProfiles |
|
217 | self.dataOutObj.nProfiles | |
218 | self.dataOutObj.m_SystemHeader.numChannels |
|
218 | self.dataOutObj.m_SystemHeader.numChannels | |
219 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
219 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
220 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
220 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
221 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
221 | self.dataOutObj.m_ProcessingHeader.numHeights | |
222 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
222 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
223 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
223 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
224 | """ |
|
224 | """ | |
225 |
|
225 | |||
226 | if self.dataInObj.flagNoData: |
|
226 | if self.dataInObj.flagNoData: | |
227 | return 0 |
|
227 | return 0 | |
228 |
|
228 | |||
229 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
229 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
230 | dc = fft_volt[:,0,:] |
|
230 | dc = fft_volt[:,0,:] | |
231 |
|
231 | |||
232 | #calculo de self-spectra |
|
232 | #calculo de self-spectra | |
233 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
233 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
234 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
234 | spc = fft_volt * numpy.conjugate(fft_volt) | |
235 | spc = spc.real |
|
235 | spc = spc.real | |
236 |
|
236 | |||
237 | blocksize = 0 |
|
237 | blocksize = 0 | |
238 | blocksize += dc.size |
|
238 | blocksize += dc.size | |
239 | blocksize += spc.size |
|
239 | blocksize += spc.size | |
240 |
|
240 | |||
241 | cspc = None |
|
241 | cspc = None | |
242 | pairIndex = 0 |
|
242 | pairIndex = 0 | |
243 | if self.pairList != None: |
|
243 | if self.pairList != None: | |
244 | #calculo de cross-spectra |
|
244 | #calculo de cross-spectra | |
245 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
245 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') | |
246 | for pair in self.pairList: |
|
246 | for pair in self.pairList: | |
247 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
247 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
248 | pairIndex += 1 |
|
248 | pairIndex += 1 | |
249 | blocksize += cspc.size |
|
249 | blocksize += cspc.size | |
250 |
|
250 | |||
251 | self.dataOutObj.data_spc = spc |
|
251 | self.dataOutObj.data_spc = spc | |
252 | self.dataOutObj.data_cspc = cspc |
|
252 | self.dataOutObj.data_cspc = cspc | |
253 | self.dataOutObj.data_dc = dc |
|
253 | self.dataOutObj.data_dc = dc | |
254 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
254 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
255 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
255 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc | |
256 |
|
256 | |||
257 | # self.getNoise() |
|
257 | # self.getNoise() | |
258 |
|
258 | |||
259 |
def addWriter(self, wrpath, |
|
259 | def addWriter(self, wrpath, blocksPerFile): | |
260 | objWriter = SpectraWriter(self.dataOutObj) |
|
260 | objWriter = SpectraWriter(self.dataOutObj) | |
261 |
objWriter.setup(wrpath, |
|
261 | objWriter.setup(wrpath, blocksPerFile) | |
262 | self.writerObjList.append(objWriter) |
|
262 | self.writerObjList.append(objWriter) | |
263 |
|
263 | |||
264 | def addIntegrator(self,N,timeInterval): |
|
264 | def addIntegrator(self,N,timeInterval): | |
265 |
|
265 | |||
266 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
266 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
267 | self.integratorObjList.append(objIncohInt) |
|
267 | self.integratorObjList.append(objIncohInt) | |
268 |
|
268 | |||
269 |
def writeData(self, wrpath, |
|
269 | def writeData(self, wrpath, blocksPerFile): | |
270 | if self.dataOutObj.flagNoData: |
|
270 | if self.dataOutObj.flagNoData: | |
271 | return 0 |
|
271 | return 0 | |
272 |
|
272 | |||
273 | if len(self.writerObjList) <= self.writerObjIndex: |
|
273 | if len(self.writerObjList) <= self.writerObjIndex: | |
274 |
self.addWriter(wrpath, |
|
274 | self.addWriter(wrpath, blocksPerFile) | |
275 |
|
275 | |||
276 | self.writerObjList[self.writerObjIndex].putData() |
|
276 | self.writerObjList[self.writerObjIndex].putData() | |
277 |
|
277 | |||
278 | self.writerObjIndex += 1 |
|
278 | self.writerObjIndex += 1 | |
279 |
|
279 | |||
280 | def integrator(self, N=None, timeInterval=None): |
|
280 | def integrator(self, N=None, timeInterval=None): | |
281 |
|
281 | |||
282 | if self.dataOutObj.flagNoData: |
|
282 | if self.dataOutObj.flagNoData: | |
283 | return 0 |
|
283 | return 0 | |
284 |
|
284 | |||
285 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
285 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
286 | self.addIntegrator(N,timeInterval) |
|
286 | self.addIntegrator(N,timeInterval) | |
287 |
|
287 | |||
288 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
288 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
289 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
289 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) | |
290 |
|
290 | |||
291 | if myIncohIntObj.isReady: |
|
291 | if myIncohIntObj.isReady: | |
292 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
292 | self.dataOutObj.data_spc = myIncohIntObj.data | |
293 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
293 | self.dataOutObj.nAvg = myIncohIntObj.navg | |
294 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
294 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg | |
295 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg |
|
295 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg | |
296 | self.dataOutObj.flagNoData = False |
|
296 | self.dataOutObj.flagNoData = False | |
297 |
|
297 | |||
298 | """Calcular el ruido""" |
|
298 | """Calcular el ruido""" | |
299 | self.getNoise() |
|
299 | self.getNoise() | |
300 | else: |
|
300 | else: | |
301 | self.dataOutObj.flagNoData = True |
|
301 | self.dataOutObj.flagNoData = True | |
302 |
|
302 | |||
303 | self.integratorObjIndex += 1 |
|
303 | self.integratorObjIndex += 1 | |
304 |
|
304 | |||
305 |
|
305 | |||
306 |
|
306 | |||
307 |
|
307 | |||
308 | class IncoherentIntegration: |
|
308 | class IncoherentIntegration: | |
309 |
|
309 | |||
310 | integ_counter = None |
|
310 | integ_counter = None | |
311 | data = None |
|
311 | data = None | |
312 | navg = None |
|
312 | navg = None | |
313 | buffer = None |
|
313 | buffer = None | |
314 | nIncohInt = None |
|
314 | nIncohInt = None | |
315 |
|
315 | |||
316 | def __init__(self, N = None, timeInterval = None): |
|
316 | def __init__(self, N = None, timeInterval = None): | |
317 | """ |
|
317 | """ | |
318 | N |
|
318 | N | |
319 | timeInterval - interval time [min], integer value |
|
319 | timeInterval - interval time [min], integer value | |
320 | """ |
|
320 | """ | |
321 |
|
321 | |||
322 | self.data = None |
|
322 | self.data = None | |
323 | self.navg = None |
|
323 | self.navg = None | |
324 | self.buffer = None |
|
324 | self.buffer = None | |
325 | self.timeOut = None |
|
325 | self.timeOut = None | |
326 | self.exitCondition = False |
|
326 | self.exitCondition = False | |
327 | self.isReady = False |
|
327 | self.isReady = False | |
328 | self.nIncohInt = N |
|
328 | self.nIncohInt = N | |
329 | self.integ_counter = 0 |
|
329 | self.integ_counter = 0 | |
330 | if timeInterval!=None: |
|
330 | if timeInterval!=None: | |
331 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
331 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
332 |
|
332 | |||
333 | if ((timeInterval==None) and (N==None)): |
|
333 | if ((timeInterval==None) and (N==None)): | |
334 | print 'N = None ; timeInterval = None' |
|
334 | print 'N = None ; timeInterval = None' | |
335 | sys.exit(0) |
|
335 | sys.exit(0) | |
336 | elif timeInterval == None: |
|
336 | elif timeInterval == None: | |
337 | self.timeFlag = False |
|
337 | self.timeFlag = False | |
338 | else: |
|
338 | else: | |
339 | self.timeFlag = True |
|
339 | self.timeFlag = True | |
340 |
|
340 | |||
341 |
|
341 | |||
342 | def exe(self,data,timeOfData): |
|
342 | def exe(self,data,timeOfData): | |
343 | """ |
|
343 | """ | |
344 | data |
|
344 | data | |
345 |
|
345 | |||
346 | timeOfData [seconds] |
|
346 | timeOfData [seconds] | |
347 | """ |
|
347 | """ | |
348 |
|
348 | |||
349 | if self.timeFlag: |
|
349 | if self.timeFlag: | |
350 | if self.timeOut == None: |
|
350 | if self.timeOut == None: | |
351 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
351 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
352 |
|
352 | |||
353 | if timeOfData < self.timeOut: |
|
353 | if timeOfData < self.timeOut: | |
354 | if self.buffer == None: |
|
354 | if self.buffer == None: | |
355 | self.buffer = data |
|
355 | self.buffer = data | |
356 | else: |
|
356 | else: | |
357 | self.buffer = self.buffer + data |
|
357 | self.buffer = self.buffer + data | |
358 | self.integ_counter += 1 |
|
358 | self.integ_counter += 1 | |
359 | else: |
|
359 | else: | |
360 | self.exitCondition = True |
|
360 | self.exitCondition = True | |
361 |
|
361 | |||
362 | else: |
|
362 | else: | |
363 | if self.integ_counter < self.nIncohInt: |
|
363 | if self.integ_counter < self.nIncohInt: | |
364 | if self.buffer == None: |
|
364 | if self.buffer == None: | |
365 | self.buffer = data |
|
365 | self.buffer = data | |
366 | else: |
|
366 | else: | |
367 | self.buffer = self.buffer + data |
|
367 | self.buffer = self.buffer + data | |
368 |
|
368 | |||
369 | self.integ_counter += 1 |
|
369 | self.integ_counter += 1 | |
370 |
|
370 | |||
371 | if self.integ_counter == self.nIncohInt: |
|
371 | if self.integ_counter == self.nIncohInt: | |
372 | self.exitCondition = True |
|
372 | self.exitCondition = True | |
373 |
|
373 | |||
374 | if self.exitCondition: |
|
374 | if self.exitCondition: | |
375 | self.data = self.buffer |
|
375 | self.data = self.buffer | |
376 | self.navg = self.integ_counter |
|
376 | self.navg = self.integ_counter | |
377 | self.isReady = True |
|
377 | self.isReady = True | |
378 | self.buffer = None |
|
378 | self.buffer = None | |
379 | self.timeOut = None |
|
379 | self.timeOut = None | |
380 | self.integ_counter = 0 |
|
380 | self.integ_counter = 0 | |
381 | self.exitCondition = False |
|
381 | self.exitCondition = False | |
382 |
|
382 | |||
383 | if self.timeFlag: |
|
383 | if self.timeFlag: | |
384 | self.buffer = data |
|
384 | self.buffer = data | |
385 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
385 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
386 | else: |
|
386 | else: | |
387 | self.isReady = False |
|
387 | self.isReady = False | |
388 | No newline at end of file |
|
388 |
@@ -1,147 +1,153 | |||||
|
1 | ''' | |||
|
2 | ||||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
|
6 | ||||
1 | import os |
|
7 | import os | |
2 | import sys |
|
8 | import sys | |
3 | import numpy |
|
9 | import numpy | |
4 |
|
10 | |||
5 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
6 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
7 |
|
13 | |||
8 | from Data.Voltage import Voltage |
|
14 | from Data.Voltage import Voltage | |
9 | from IO.VoltageIO import VoltageWriter |
|
15 | from IO.VoltageIO import VoltageWriter | |
10 |
|
16 | |||
11 |
|
17 | |||
12 | class VoltageProcessor: |
|
18 | class VoltageProcessor: | |
13 | dataInObj = None |
|
19 | dataInObj = None | |
14 | dataOutObj = None |
|
20 | dataOutObj = None | |
15 | integratorObjIndex = None |
|
21 | integratorObjIndex = None | |
16 | writerObjIndex = None |
|
22 | writerObjIndex = None | |
17 | integratorObjList = None |
|
23 | integratorObjList = None | |
18 | writerObjList = None |
|
24 | writerObjList = None | |
19 |
|
25 | |||
20 | def __init__(self): |
|
26 | def __init__(self): | |
21 | self.integratorObjIndex = None |
|
27 | self.integratorObjIndex = None | |
22 | self.writerObjIndex = None |
|
28 | self.writerObjIndex = None | |
23 | self.integratorObjList = [] |
|
29 | self.integratorObjList = [] | |
24 | self.writerObjList = [] |
|
30 | self.writerObjList = [] | |
25 |
|
31 | |||
26 | def setup(self,dataInObj=None,dataOutObj=None): |
|
32 | def setup(self,dataInObj=None,dataOutObj=None): | |
27 | self.dataInObj = dataInObj |
|
33 | self.dataInObj = dataInObj | |
28 |
|
34 | |||
29 | if self.dataOutObj == None: |
|
35 | if self.dataOutObj == None: | |
30 | dataOutObj = Voltage() |
|
36 | dataOutObj = Voltage() | |
31 |
|
37 | |||
32 | self.dataOutObj = dataOutObj |
|
38 | self.dataOutObj = dataOutObj | |
33 |
|
39 | |||
34 | return self.dataOutObj |
|
40 | return self.dataOutObj | |
35 |
|
41 | |||
36 | def init(self): |
|
42 | def init(self): | |
37 | self.integratorObjIndex = 0 |
|
43 | self.integratorObjIndex = 0 | |
38 | self.writerObjIndex = 0 |
|
44 | self.writerObjIndex = 0 | |
39 |
|
45 | |||
40 | if not(self.dataInObj.flagNoData): |
|
46 | if not(self.dataInObj.flagNoData): | |
41 | self.dataOutObj.copy(self.dataInObj) |
|
47 | self.dataOutObj.copy(self.dataInObj) | |
42 | # No necesita copiar en cada init() los atributos de dataInObj |
|
48 | # No necesita copiar en cada init() los atributos de dataInObj | |
43 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
49 | # la copia deberia hacerse por cada nuevo bloque de datos | |
44 |
|
50 | |||
45 | def addIntegrator(self,N,timeInterval): |
|
51 | def addIntegrator(self,N,timeInterval): | |
46 | objCohInt = CoherentIntegrator(N,timeInterval) |
|
52 | objCohInt = CoherentIntegrator(N,timeInterval) | |
47 | self.integratorObjList.append(objCohInt) |
|
53 | self.integratorObjList.append(objCohInt) | |
48 |
|
54 | |||
49 |
def addWriter(self, wrpath, |
|
55 | def addWriter(self, wrpath, blocksPerFile, profilesPerBlock): | |
50 | objWriter = VoltageWriter(self.dataOutObj) |
|
56 | objWriter = VoltageWriter(self.dataOutObj) | |
51 |
objWriter.setup(wrpath,profilesPerBlock |
|
57 | objWriter.setup(wrpath,blocksPerFile,profilesPerBlock) | |
52 | self.writerObjList.append(objWriter) |
|
58 | self.writerObjList.append(objWriter) | |
53 |
|
59 | |||
54 |
def writeData(self, wrpath, |
|
60 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): | |
55 |
|
61 | |||
56 | if self.dataOutObj.flagNoData: |
|
62 | if self.dataOutObj.flagNoData: | |
57 | return 0 |
|
63 | return 0 | |
58 |
|
64 | |||
59 | if len(self.writerObjList) <= self.writerObjIndex: |
|
65 | if len(self.writerObjList) <= self.writerObjIndex: | |
60 |
self.addWriter(wrpath, |
|
66 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) | |
61 |
|
67 | |||
62 | self.writerObjList[self.writerObjIndex].putData() |
|
68 | self.writerObjList[self.writerObjIndex].putData() | |
63 |
|
69 | |||
64 | self.writerObjIndex += 1 |
|
70 | self.writerObjIndex += 1 | |
65 |
|
71 | |||
66 | def integrator(self, N=None, timeInterval=None): |
|
72 | def integrator(self, N=None, timeInterval=None): | |
67 | if self.dataOutObj.flagNoData: |
|
73 | if self.dataOutObj.flagNoData: | |
68 | return 0 |
|
74 | return 0 | |
69 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
75 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
70 | self.addIntegrator(N,timeInterval) |
|
76 | self.addIntegrator(N,timeInterval) | |
71 |
|
77 | |||
72 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
78 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
73 | myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None) |
|
79 | myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None) | |
74 |
|
80 | |||
75 |
|
81 | |||
76 | class CoherentIntegrator: |
|
82 | class CoherentIntegrator: | |
77 |
|
83 | |||
78 | integ_counter = None |
|
84 | integ_counter = None | |
79 | data = None |
|
85 | data = None | |
80 | navg = None |
|
86 | navg = None | |
81 | buffer = None |
|
87 | buffer = None | |
82 | nCohInt = None |
|
88 | nCohInt = None | |
83 |
|
89 | |||
84 | def __init__(self, N=None,timeInterval=None): |
|
90 | def __init__(self, N=None,timeInterval=None): | |
85 |
|
91 | |||
86 | self.data = None |
|
92 | self.data = None | |
87 | self.navg = None |
|
93 | self.navg = None | |
88 | self.buffer = None |
|
94 | self.buffer = None | |
89 | self.timeOut = None |
|
95 | self.timeOut = None | |
90 | self.exitCondition = False |
|
96 | self.exitCondition = False | |
91 | self.isReady = False |
|
97 | self.isReady = False | |
92 | self.nCohInt = N |
|
98 | self.nCohInt = N | |
93 | self.integ_counter = 0 |
|
99 | self.integ_counter = 0 | |
94 | if timeInterval!=None: |
|
100 | if timeInterval!=None: | |
95 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
101 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
96 |
|
102 | |||
97 | if ((timeInterval==None) and (N==None)): |
|
103 | if ((timeInterval==None) and (N==None)): | |
98 | raise ValueError, "N = None ; timeInterval = None" |
|
104 | raise ValueError, "N = None ; timeInterval = None" | |
99 |
|
105 | |||
100 | if timeInterval == None: |
|
106 | if timeInterval == None: | |
101 | self.timeFlag = False |
|
107 | self.timeFlag = False | |
102 | else: |
|
108 | else: | |
103 | self.timeFlag = True |
|
109 | self.timeFlag = True | |
104 |
|
110 | |||
105 | def exe(self, data, timeOfData): |
|
111 | def exe(self, data, timeOfData): | |
106 |
|
112 | |||
107 | if self.timeFlag: |
|
113 | if self.timeFlag: | |
108 | if self.timeOut == None: |
|
114 | if self.timeOut == None: | |
109 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
115 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
110 |
|
116 | |||
111 | if timeOfData < self.timeOut: |
|
117 | if timeOfData < self.timeOut: | |
112 | if self.buffer == None: |
|
118 | if self.buffer == None: | |
113 | self.buffer = data |
|
119 | self.buffer = data | |
114 | else: |
|
120 | else: | |
115 | self.buffer = self.buffer + data |
|
121 | self.buffer = self.buffer + data | |
116 | self.integ_counter += 1 |
|
122 | self.integ_counter += 1 | |
117 | else: |
|
123 | else: | |
118 | self.exitCondition = True |
|
124 | self.exitCondition = True | |
119 |
|
125 | |||
120 | else: |
|
126 | else: | |
121 | if self.integ_counter < self.nCohInt: |
|
127 | if self.integ_counter < self.nCohInt: | |
122 | if self.buffer == None: |
|
128 | if self.buffer == None: | |
123 | self.buffer = data |
|
129 | self.buffer = data | |
124 | else: |
|
130 | else: | |
125 | self.buffer = self.buffer + data |
|
131 | self.buffer = self.buffer + data | |
126 |
|
132 | |||
127 | self.integ_counter += 1 |
|
133 | self.integ_counter += 1 | |
128 |
|
134 | |||
129 | if self.integ_counter == self.nCohInt: |
|
135 | if self.integ_counter == self.nCohInt: | |
130 | self.exitCondition = True |
|
136 | self.exitCondition = True | |
131 |
|
137 | |||
132 | if self.exitCondition: |
|
138 | if self.exitCondition: | |
133 | self.data = self.buffer |
|
139 | self.data = self.buffer | |
134 | self.navg = self.integ_counter |
|
140 | self.navg = self.integ_counter | |
135 | self.isReady = True |
|
141 | self.isReady = True | |
136 | self.buffer = None |
|
142 | self.buffer = None | |
137 | self.timeOut = None |
|
143 | self.timeOut = None | |
138 | self.integ_counter = 0 |
|
144 | self.integ_counter = 0 | |
139 | self.exitCondition = False |
|
145 | self.exitCondition = False | |
140 |
|
146 | |||
141 | if self.timeFlag: |
|
147 | if self.timeFlag: | |
142 | self.buffer = data |
|
148 | self.buffer = data | |
143 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
149 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
144 | else: |
|
150 | else: | |
145 | self.isReady = False |
|
151 | self.isReady = False | |
146 |
|
152 | |||
147 |
|
153 |
@@ -1,81 +1,85 | |||||
|
1 | ''' | |||
1 |
|
2 | |||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
2 | import os, sys |
|
6 | import os, sys | |
3 | import time, datetime |
|
7 | import time, datetime | |
4 |
|
8 | |||
5 | path = os.path.split(os.getcwd())[0] |
|
9 | path = os.path.split(os.getcwd())[0] | |
6 | sys.path.append(path) |
|
10 | sys.path.append(path) | |
7 |
|
11 | |||
8 | from Data.Voltage import Voltage |
|
12 | from Data.Voltage import Voltage | |
9 | from IO.VoltageIO import * |
|
13 | from IO.VoltageIO import * | |
10 |
|
14 | |||
11 | from Processing.VoltageProcessor import * |
|
15 | from Processing.VoltageProcessor import * | |
12 |
|
16 | |||
13 |
|
17 | |||
14 |
|
18 | |||
15 | class TestSChain(): |
|
19 | class TestSChain(): | |
16 |
|
20 | |||
17 | def __init__(self): |
|
21 | def __init__(self): | |
18 | self.setValues() |
|
22 | self.setValues() | |
19 | self.createObjects() |
|
23 | self.createObjects() | |
20 | self.testSChain() |
|
24 | self.testSChain() | |
21 |
|
25 | |||
22 | def setValues(self): |
|
26 | def setValues(self): | |
23 | self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts" |
|
27 | self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts" | |
24 | self.startDate = datetime.date(2011,11,28) |
|
28 | self.startDate = datetime.date(2011,11,28) | |
25 | self.endDate = datetime.date(2011,11,30) |
|
29 | self.endDate = datetime.date(2011,11,30) | |
26 |
|
30 | |||
27 | # self.path = "/Users/danielangelsuarezmunoz/Data/Imaging_rawdata" |
|
31 | # self.path = "/Users/danielangelsuarezmunoz/Data/Imaging_rawdata" | |
28 | # self.startDate = datetime.date(2011,10,4) |
|
32 | # self.startDate = datetime.date(2011,10,4) | |
29 | # self.endDate = datetime.date(2011,10,4) |
|
33 | # self.endDate = datetime.date(2011,10,4) | |
30 |
|
34 | |||
31 | # Probando los escritos por Signal Chain |
|
35 | # Probando los escritos por Signal Chain | |
32 | self.path = "/Users/danielangelsuarezmunoz/Data/testWR" |
|
36 | self.path = "/Users/danielangelsuarezmunoz/Data/testWR" | |
33 | self.startDate = datetime.date(2011,11,28) |
|
37 | self.startDate = datetime.date(2011,11,28) | |
34 | self.endDate = datetime.date(2011,11,30) |
|
38 | self.endDate = datetime.date(2011,11,30) | |
35 |
|
39 | |||
36 | self.startTime = datetime.time(0,0,0) |
|
40 | self.startTime = datetime.time(0,0,0) | |
37 | self.endTime = datetime.time(23,59,59) |
|
41 | self.endTime = datetime.time(23,59,59) | |
38 |
|
42 | |||
39 | self.wrpath = "/Users/danielangelsuarezmunoz/Data/testWR" |
|
43 | self.wrpath = "/Users/danielangelsuarezmunoz/Data/testWR" | |
40 | self.profilesPerBlock = 40 |
|
44 | self.profilesPerBlock = 40 | |
41 | self.blocksPerFile = 50 |
|
45 | self.blocksPerFile = 50 | |
42 |
|
46 | |||
43 | def createObjects(self): |
|
47 | def createObjects(self): | |
44 |
|
48 | |||
45 | self.readerObj = VoltageReader() |
|
49 | self.readerObj = VoltageReader() | |
46 |
|
50 | |||
47 | self.voltObj1 = self.readerObj.setup( |
|
51 | self.voltObj1 = self.readerObj.setup( | |
48 | path = self.path, |
|
52 | path = self.path, | |
49 | startDate = self.startDate, |
|
53 | startDate = self.startDate, | |
50 | endDate = self.endDate, |
|
54 | endDate = self.endDate, | |
51 | startTime = self.startTime, |
|
55 | startTime = self.startTime, | |
52 | endTime = self.endTime, |
|
56 | endTime = self.endTime, | |
53 | expLabel = '', |
|
57 | expLabel = '', | |
54 | online = 0) |
|
58 | online = 0) | |
55 |
|
59 | |||
56 | self.voltObjProc = VoltageProcessor() |
|
60 | self.voltObjProc = VoltageProcessor() | |
57 |
|
61 | |||
58 | self.voltObj2 = self.voltObjProc.setup(dataInObj = self.voltObj1) |
|
62 | self.voltObj2 = self.voltObjProc.setup(dataInObj = self.voltObj1) | |
59 |
|
63 | |||
60 | def testSChain(self): |
|
64 | def testSChain(self): | |
61 |
|
65 | |||
62 | ini = time.time() |
|
66 | ini = time.time() | |
63 |
|
67 | |||
64 | while(True): |
|
68 | while(True): | |
65 | self.readerObj.getData() |
|
69 | self.readerObj.getData() | |
66 |
|
70 | |||
67 | # self.voltObjProc.init() |
|
71 | # self.voltObjProc.init() | |
68 | # |
|
72 | # | |
69 | # self.voltObjProc.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile) |
|
73 | # self.voltObjProc.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile) | |
70 |
|
74 | |||
71 | if self.readerObj.flagNoMoreFiles: |
|
75 | if self.readerObj.flagNoMoreFiles: | |
72 | break |
|
76 | break | |
73 |
|
77 | |||
74 | if self.readerObj.flagIsNewBlock: |
|
78 | if self.readerObj.flagIsNewBlock: | |
75 | # print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),) |
|
79 | # print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),) | |
76 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, |
|
80 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, | |
77 | datetime.datetime.utcfromtimestamp(self.readerObj.basicHeaderObj.utc + self.readerObj.basicHeaderObj.miliSecond/1000.0),) |
|
81 | datetime.datetime.utcfromtimestamp(self.readerObj.basicHeaderObj.utc + self.readerObj.basicHeaderObj.miliSecond/1000.0),) | |
78 |
|
82 | |||
79 |
|
83 | |||
80 | if __name__ == '__main__': |
|
84 | if __name__ == '__main__': | |
81 | TestSChain() No newline at end of file |
|
85 | TestSChain() |
@@ -1,80 +1,85 | |||||
|
1 | ''' | |||
|
2 | ||||
|
3 | $Author$ | |||
|
4 | $Id$ | |||
|
5 | ''' | |||
1 |
|
6 | |||
2 | import os, sys |
|
7 | import os, sys | |
3 | import time, datetime |
|
8 | import time, datetime | |
4 |
|
9 | |||
5 | path = os.path.split(os.getcwd())[0] |
|
10 | path = os.path.split(os.getcwd())[0] | |
6 | sys.path.append(path) |
|
11 | sys.path.append(path) | |
7 |
|
12 | |||
8 |
|
13 | |||
9 | from Data.Spectra import Spectra |
|
14 | from Data.Spectra import Spectra | |
10 | from IO.SpectraIO import * |
|
15 | from IO.SpectraIO import * | |
11 | from Processing.SpectraProcessor import * |
|
16 | from Processing.SpectraProcessor import * | |
12 |
|
17 | |||
13 |
|
18 | |||
14 |
|
19 | |||
15 | class TestSChain: |
|
20 | class TestSChain: | |
16 |
|
21 | |||
17 | def __init__(self): |
|
22 | def __init__(self): | |
18 | self.setValues() |
|
23 | self.setValues() | |
19 | self.createObjects() |
|
24 | self.createObjects() | |
20 | self.testSChain() |
|
25 | self.testSChain() | |
21 |
|
26 | |||
22 | def setValues(self): |
|
27 | def setValues(self): | |
23 | self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST" |
|
28 | # self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST" | |
24 | # self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING" |
|
29 | ## self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING" | |
25 | self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts" |
|
30 | # self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts" | |
26 | self.path = "/Users/danielangelsuarezmunoz/Data/IMAGING" |
|
31 | # self.path = "/Users/danielangelsuarezmunoz/Data/IMAGING" | |
|
32 | self.path = "/home/daniel/RadarData/IMAGING" | |||
27 |
|
33 | |||
28 | self.startDate = datetime.date(2012,3,1) |
|
34 | self.startDate = datetime.date(2012,3,1) | |
29 | self.endDate = datetime.date(2012,3,30) |
|
35 | self.endDate = datetime.date(2012,3,30) | |
30 |
|
36 | |||
31 | self.startTime = datetime.time(0,0,0) |
|
37 | self.startTime = datetime.time(0,0,0) | |
32 | self.endTime = datetime.time(14,1,1) |
|
38 | self.endTime = datetime.time(14,1,1) | |
33 |
|
39 | |||
34 | # paramatros para Escritura de Pdata |
|
40 | # paramatros para Escritura de Pdata | |
35 |
self.wrpath = "/ |
|
41 | self.wrpath = "/home/daniel/RadarData/test_wr2" | |
36 | self.profilesPerBlock = 8 |
|
|||
37 | self.blocksPerFile = 5 |
|
42 | self.blocksPerFile = 5 | |
38 | # self.pairList = [(0,1),(0,2)] |
|
43 | ||
39 |
|
44 | |||
40 |
|
45 | |||
41 | def createObjects(self): |
|
46 | def createObjects(self): | |
42 |
|
47 | |||
43 | self.readerObj = SpectraReader() |
|
48 | self.readerObj = SpectraReader() | |
44 |
|
49 | |||
45 | self.specObj1 = self.readerObj.setup( |
|
50 | self.specObj1 = self.readerObj.setup( | |
46 | path = self.path, |
|
51 | path = self.path, | |
47 | startDate = self.startDate, |
|
52 | startDate = self.startDate, | |
48 | endDate = self.endDate, |
|
53 | endDate = self.endDate, | |
49 | startTime = self.startTime, |
|
54 | startTime = self.startTime, | |
50 | endTime = self.endTime, |
|
55 | endTime = self.endTime, | |
51 | expLabel = '', |
|
56 | expLabel = '', | |
52 | online = 0) |
|
57 | online = 0) | |
53 | # new lines |
|
58 | ||
54 | self.specObjProc = SpectraProcessor() |
|
59 | self.specObjProc = SpectraProcessor() | |
55 |
|
60 | |||
56 | self.specObj2 = self.specObjProc.setup(dataInObj = self.specObj1) |
|
61 | self.specObj2 = self.specObjProc.setup(dataInObj = self.specObj1) | |
57 |
|
62 | |||
58 |
|
63 | |||
59 |
|
64 | |||
60 | def testSChain(self): |
|
65 | def testSChain(self): | |
61 |
|
66 | |||
62 | ini = time.time() |
|
67 | ini = time.time() | |
63 |
|
68 | |||
64 | while(True): |
|
69 | while(True): | |
65 | self.readerObj.getData() |
|
70 | self.readerObj.getData() | |
66 |
|
71 | |||
67 | self.specObjProc.init() |
|
72 | self.specObjProc.init() | |
68 |
|
73 | |||
69 |
self.specObjProc.writeData(self.wrpath,self. |
|
74 | self.specObjProc.writeData(self.wrpath,self.blocksPerFile) | |
70 |
|
75 | # | ||
71 | if self.readerObj.flagNoMoreFiles: |
|
76 | if self.readerObj.flagNoMoreFiles: | |
72 | break |
|
77 | break | |
73 |
|
78 | |||
74 | if self.readerObj.flagIsNewBlock: |
|
79 | if self.readerObj.flagIsNewBlock: | |
75 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, |
|
80 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, | |
76 | datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc)) |
|
81 | datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc)) | |
77 |
|
82 | |||
78 |
|
83 | |||
79 | if __name__ == '__main__': |
|
84 | if __name__ == '__main__': | |
80 | TestSChain() No newline at end of file |
|
85 | TestSChain() |
General Comments 0
You need to be logged in to leave comments.
Login now