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