The requested changes are too big and content was truncated. Show full diff
@@ -0,0 +1,14 | |||||
|
1 | import numpy | |||
|
2 | a= numpy.array([0,1,2,3,4,5,10,11,12,18,19,20,21,22,23,24,25,26,27,28]) | |||
|
3 | print(a) | |||
|
4 | list=[] | |||
|
5 | list2=[] | |||
|
6 | for i in reversed(range(1,len(a))): | |||
|
7 | dif=int(a[i])-int(a[i-1]) | |||
|
8 | print(i,a[i],dif ) | |||
|
9 | if dif>1: | |||
|
10 | list.append(i-1) | |||
|
11 | list2.append(dif-1) | |||
|
12 | print("result") | |||
|
13 | print(list) | |||
|
14 | print(list2) |
@@ -0,0 +1,44 | |||||
|
1 | #!/usr/bin/python | |||
|
2 | ||||
|
3 | from schainpy.controller import Project | |||
|
4 | ||||
|
5 | path ="/home/soporte/Downloads/" | |||
|
6 | ||||
|
7 | prj = Project() | |||
|
8 | ||||
|
9 | read_unit = prj.addReadUnit( | |||
|
10 | datatype='Spectra', | |||
|
11 | path=path, | |||
|
12 | startDate='2013/01/01', | |||
|
13 | endDate='2013/12/31', | |||
|
14 | startTime='00:00:00', | |||
|
15 | endTime='23:59:59', | |||
|
16 | online=0, | |||
|
17 | walk=0 | |||
|
18 | ) | |||
|
19 | ||||
|
20 | proc_unit = prj.addProcUnit( | |||
|
21 | datatype='Spectra', | |||
|
22 | inputId=read_unit.getId() | |||
|
23 | ) | |||
|
24 | ||||
|
25 | ||||
|
26 | op = proc_unit.addOperation(name='IncohInt') | |||
|
27 | op.addParameter(name='n', value='2') | |||
|
28 | ||||
|
29 | op = proc_unit.addOperation(name='selectChannels') | |||
|
30 | op.addParameter(name='channelList', value='0,1') | |||
|
31 | ||||
|
32 | op = proc_unit.addOperation(name='selectHeights') | |||
|
33 | op.addParameter(name='minHei', value='80') | |||
|
34 | op.addParameter(name='maxHei', value='200') | |||
|
35 | ||||
|
36 | #op = proc_unit.addOperation(name='removeDC') | |||
|
37 | ||||
|
38 | op = proc_unit.addOperation(name='SpectraPlot') | |||
|
39 | op.addParameter(name='wintitle', value='Spectra', format='str') | |||
|
40 | ||||
|
41 | op = proc_unit.addOperation(name='RTIPlot') | |||
|
42 | op.addParameter(name='wintitle', value='RTI', format='str') | |||
|
43 | ||||
|
44 | prj.start() |
@@ -0,0 +1,55 | |||||
|
1 | #!/usr/bin/python | |||
|
2 | ||||
|
3 | from schainpy.controller import Project | |||
|
4 | ||||
|
5 | path ="/home/soporte/Downloads/" | |||
|
6 | ||||
|
7 | prj = Project() | |||
|
8 | ||||
|
9 | read_unit = prj.addReadUnit( | |||
|
10 | datatype='Voltage', | |||
|
11 | path=path, | |||
|
12 | startDate='2015/01/01', | |||
|
13 | endDate='2015/12/31', | |||
|
14 | startTime='00:00:00', | |||
|
15 | endTime='23:59:59', | |||
|
16 | online=0, | |||
|
17 | walk=0 | |||
|
18 | ) | |||
|
19 | ||||
|
20 | proc_unit1 = prj.addProcUnit( | |||
|
21 | datatype='Voltage', | |||
|
22 | inputId=read_unit.getId() | |||
|
23 | ) | |||
|
24 | ||||
|
25 | #op = proc_unit1.addOperation(name='ProfileSelector') | |||
|
26 | #op.addParameter( name='rangeList', value="(0,19),(100,119)") | |||
|
27 | ||||
|
28 | op = proc_unit1.addOperation(name='MyAverage') | |||
|
29 | op.addParameter(name='n', value='10') | |||
|
30 | ||||
|
31 | #op = proc_unit1.addOperation(name='CohInt') | |||
|
32 | #op.addParameter(name='n', value='10') | |||
|
33 | ||||
|
34 | #op = proc_unit1.addOperation(name='Decoder') | |||
|
35 | #op.addParameter(name='times', value='10') | |||
|
36 | ||||
|
37 | ||||
|
38 | op = proc_unit1.addOperation(name='ScopePlot') | |||
|
39 | op.addParameter(name='wintitle', value='Scope', format='str') | |||
|
40 | ||||
|
41 | ''' | |||
|
42 | proc_unit2 = prj.addProcUnit( | |||
|
43 | datatype='Spectra', | |||
|
44 | inputId=proc_unit1.getId() | |||
|
45 | ) | |||
|
46 | proc_unit2.addParameter(name='nFFTPoints', value='64') | |||
|
47 | ||||
|
48 | ||||
|
49 | op = proc_unit2.addOperation(name='SpectraPlot') | |||
|
50 | op.addParameter(name='wintitle', value='Spectra', format='str') | |||
|
51 | ||||
|
52 | op = proc_unit2.addOperation(name='RTIPlot') | |||
|
53 | op.addParameter(name='wintitle', value='RTI', format='str') | |||
|
54 | ''' | |||
|
55 | prj.start() |
@@ -1,648 +1,703 | |||||
1 | import os |
|
1 | import os | |
2 | import time |
|
2 | import time | |
3 | import datetime |
|
3 | import datetime | |
4 |
|
4 | |||
5 | import numpy |
|
5 | import numpy | |
6 | import h5py |
|
6 | import h5py | |
7 |
|
7 | |||
8 | import schainpy.admin |
|
8 | import schainpy.admin | |
9 | from schainpy.model.data.jrodata import * |
|
9 | from schainpy.model.data.jrodata import * | |
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
11 | from schainpy.model.io.jroIO_base import * |
|
11 | from schainpy.model.io.jroIO_base import * | |
12 | from schainpy.utils import log |
|
12 | from schainpy.utils import log | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | class HDFReader(Reader, ProcessingUnit): |
|
15 | class HDFReader(Reader, ProcessingUnit): | |
16 | """Processing unit to read HDF5 format files |
|
16 | """Processing unit to read HDF5 format files | |
17 |
|
17 | |||
18 | This unit reads HDF5 files created with `HDFWriter` operation contains |
|
18 | This unit reads HDF5 files created with `HDFWriter` operation contains | |
19 | by default two groups Data and Metadata all variables would be saved as `dataOut` |
|
19 | by default two groups Data and Metadata all variables would be saved as `dataOut` | |
20 | attributes. |
|
20 | attributes. | |
21 | It is possible to read any HDF5 file by given the structure in the `description` |
|
21 | It is possible to read any HDF5 file by given the structure in the `description` | |
22 | parameter, also you can add extra values to metadata with the parameter `extras`. |
|
22 | parameter, also you can add extra values to metadata with the parameter `extras`. | |
23 |
|
23 | |||
24 | Parameters: |
|
24 | Parameters: | |
25 | ----------- |
|
25 | ----------- | |
26 | path : str |
|
26 | path : str | |
27 | Path where files are located. |
|
27 | Path where files are located. | |
28 | startDate : date |
|
28 | startDate : date | |
29 | Start date of the files |
|
29 | Start date of the files | |
30 | endDate : list |
|
30 | endDate : list | |
31 | End date of the files |
|
31 | End date of the files | |
32 | startTime : time |
|
32 | startTime : time | |
33 | Start time of the files |
|
33 | Start time of the files | |
34 | endTime : time |
|
34 | endTime : time | |
35 | End time of the files |
|
35 | End time of the files | |
36 | description : dict, optional |
|
36 | description : dict, optional | |
37 | Dictionary with the description of the HDF5 file |
|
37 | Dictionary with the description of the HDF5 file | |
38 | extras : dict, optional |
|
38 | extras : dict, optional | |
39 | Dictionary with extra metadata to be be added to `dataOut` |
|
39 | Dictionary with extra metadata to be be added to `dataOut` | |
40 |
|
40 | |||
41 | Examples |
|
41 | Examples | |
42 | -------- |
|
42 | -------- | |
43 |
|
43 | |||
44 | desc = { |
|
44 | desc = { | |
45 | 'Data': { |
|
45 | 'Data': { | |
46 | 'data_output': ['u', 'v', 'w'], |
|
46 | 'data_output': ['u', 'v', 'w'], | |
47 | 'utctime': 'timestamps', |
|
47 | 'utctime': 'timestamps', | |
48 | } , |
|
48 | } , | |
49 | 'Metadata': { |
|
49 | 'Metadata': { | |
50 | 'heightList': 'heights' |
|
50 | 'heightList': 'heights' | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | desc = { |
|
54 | desc = { | |
55 | 'Data': { |
|
55 | 'Data': { | |
56 | 'data_output': 'winds', |
|
56 | 'data_output': 'winds', | |
57 | 'utctime': 'timestamps' |
|
57 | 'utctime': 'timestamps' | |
58 | }, |
|
58 | }, | |
59 | 'Metadata': { |
|
59 | 'Metadata': { | |
60 | 'heightList': 'heights' |
|
60 | 'heightList': 'heights' | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | extras = { |
|
64 | extras = { | |
65 | 'timeZone': 300 |
|
65 | 'timeZone': 300 | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | reader = project.addReadUnit( |
|
68 | reader = project.addReadUnit( | |
69 | name='HDFReader', |
|
69 | name='HDFReader', | |
70 | path='/path/to/files', |
|
70 | path='/path/to/files', | |
71 | startDate='2019/01/01', |
|
71 | startDate='2019/01/01', | |
72 | endDate='2019/01/31', |
|
72 | endDate='2019/01/31', | |
73 | startTime='00:00:00', |
|
73 | startTime='00:00:00', | |
74 | endTime='23:59:59', |
|
74 | endTime='23:59:59', | |
75 | # description=json.dumps(desc), |
|
75 | # description=json.dumps(desc), | |
76 | # extras=json.dumps(extras), |
|
76 | # extras=json.dumps(extras), | |
77 | ) |
|
77 | ) | |
78 |
|
78 | |||
79 | """ |
|
79 | """ | |
80 |
|
80 | |||
81 | __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'description', 'extras'] |
|
81 | __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'description', 'extras'] | |
82 |
|
82 | |||
83 | def __init__(self): |
|
83 | def __init__(self): | |
84 | ProcessingUnit.__init__(self) |
|
84 | ProcessingUnit.__init__(self) | |
85 | self.dataOut = Parameters() |
|
85 | self.dataOut = Parameters() | |
86 | self.ext = ".hdf5" |
|
86 | self.ext = ".hdf5" | |
87 | self.optchar = "D" |
|
87 | self.optchar = "D" | |
88 | self.meta = {} |
|
88 | self.meta = {} | |
89 | self.data = {} |
|
89 | self.data = {} | |
90 | self.open_file = h5py.File |
|
90 | self.open_file = h5py.File | |
91 | self.open_mode = 'r' |
|
91 | self.open_mode = 'r' | |
92 | self.description = {} |
|
92 | self.description = {} | |
93 | self.extras = {} |
|
93 | self.extras = {} | |
94 | self.filefmt = "*%Y%j***" |
|
94 | self.filefmt = "*%Y%j***" | |
95 | self.folderfmt = "*%Y%j" |
|
95 | self.folderfmt = "*%Y%j" | |
96 | self.utcoffset = 0 |
|
96 | self.utcoffset = 0 | |
97 |
|
97 | |||
98 | def setup(self, **kwargs): |
|
98 | def setup(self, **kwargs): | |
99 |
|
99 | |||
100 | self.set_kwargs(**kwargs) |
|
100 | self.set_kwargs(**kwargs) | |
101 | if not self.ext.startswith('.'): |
|
101 | if not self.ext.startswith('.'): | |
102 | self.ext = '.{}'.format(self.ext) |
|
102 | self.ext = '.{}'.format(self.ext) | |
103 |
|
103 | |||
104 | if self.online: |
|
104 | if self.online: | |
105 | log.log("Searching files in online mode...", self.name) |
|
105 | log.log("Searching files in online mode...", self.name) | |
106 |
|
106 | |||
107 | for nTries in range(self.nTries): |
|
107 | for nTries in range(self.nTries): | |
108 | fullpath = self.searchFilesOnLine(self.path, self.startDate, |
|
108 | fullpath = self.searchFilesOnLine(self.path, self.startDate, | |
109 | self.endDate, self.expLabel, self.ext, self.walk, |
|
109 | self.endDate, self.expLabel, self.ext, self.walk, | |
110 | self.filefmt, self.folderfmt) |
|
110 | self.filefmt, self.folderfmt) | |
111 | try: |
|
111 | try: | |
112 | fullpath = next(fullpath) |
|
112 | fullpath = next(fullpath) | |
113 | except: |
|
113 | except: | |
114 | fullpath = None |
|
114 | fullpath = None | |
115 |
|
115 | |||
116 | if fullpath: |
|
116 | if fullpath: | |
117 | break |
|
117 | break | |
118 |
|
118 | |||
119 | log.warning( |
|
119 | log.warning( | |
120 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( |
|
120 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( | |
121 | self.delay, self.path, nTries + 1), |
|
121 | self.delay, self.path, nTries + 1), | |
122 | self.name) |
|
122 | self.name) | |
123 | time.sleep(self.delay) |
|
123 | time.sleep(self.delay) | |
124 |
|
124 | |||
125 | if not(fullpath): |
|
125 | if not(fullpath): | |
126 | raise schainpy.admin.SchainError( |
|
126 | raise schainpy.admin.SchainError( | |
127 | 'There isn\'t any valid file in {}'.format(self.path)) |
|
127 | 'There isn\'t any valid file in {}'.format(self.path)) | |
128 |
|
128 | |||
129 | pathname, filename = os.path.split(fullpath) |
|
129 | pathname, filename = os.path.split(fullpath) | |
130 | self.year = int(filename[1:5]) |
|
130 | self.year = int(filename[1:5]) | |
131 | self.doy = int(filename[5:8]) |
|
131 | self.doy = int(filename[5:8]) | |
132 | self.set = int(filename[8:11]) - 1 |
|
132 | self.set = int(filename[8:11]) - 1 | |
133 | else: |
|
133 | else: | |
134 | log.log("Searching files in {}".format(self.path), self.name) |
|
134 | log.log("Searching files in {}".format(self.path), self.name) | |
135 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, |
|
135 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
136 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) |
|
136 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
137 |
|
137 | |||
138 | self.setNextFile() |
|
138 | self.setNextFile() | |
139 |
|
139 | |||
140 | return |
|
140 | return | |
141 |
|
141 | |||
142 | def readFirstHeader(self): |
|
142 | def readFirstHeader(self): | |
143 | '''Read metadata and data''' |
|
143 | '''Read metadata and data''' | |
144 |
|
144 | |||
145 | self.__readMetadata() |
|
145 | self.__readMetadata() | |
146 | self.__readData() |
|
146 | self.__readData() | |
147 | self.__setBlockList() |
|
147 | self.__setBlockList() | |
148 |
|
148 | |||
149 | if 'type' in self.meta: |
|
149 | if 'type' in self.meta: | |
150 | self.dataOut = eval(self.meta['type'])() |
|
150 | self.dataOut = eval(self.meta['type'])() | |
151 |
|
151 | |||
152 | for attr in self.meta: |
|
152 | for attr in self.meta: | |
153 | setattr(self.dataOut, attr, self.meta[attr]) |
|
153 | setattr(self.dataOut, attr, self.meta[attr]) | |
154 |
|
154 | |||
155 | self.blockIndex = 0 |
|
155 | self.blockIndex = 0 | |
156 |
|
156 | |||
157 | return |
|
157 | return | |
158 |
|
158 | |||
159 | def __setBlockList(self): |
|
159 | def __setBlockList(self): | |
160 | ''' |
|
160 | ''' | |
161 | Selects the data within the times defined |
|
161 | Selects the data within the times defined | |
162 |
|
162 | |||
163 | self.fp |
|
163 | self.fp | |
164 | self.startTime |
|
164 | self.startTime | |
165 | self.endTime |
|
165 | self.endTime | |
166 | self.blockList |
|
166 | self.blockList | |
167 | self.blocksPerFile |
|
167 | self.blocksPerFile | |
168 |
|
168 | |||
169 | ''' |
|
169 | ''' | |
170 |
|
170 | |||
171 | startTime = self.startTime |
|
171 | startTime = self.startTime | |
172 | endTime = self.endTime |
|
172 | endTime = self.endTime | |
173 | thisUtcTime = self.data['utctime'] + self.utcoffset |
|
173 | thisUtcTime = self.data['utctime'] + self.utcoffset | |
174 | self.interval = numpy.min(thisUtcTime[1:] - thisUtcTime[:-1]) |
|
174 | self.interval = numpy.min(thisUtcTime[1:] - thisUtcTime[:-1]) | |
175 | thisDatetime = datetime.datetime.utcfromtimestamp(thisUtcTime[0]) |
|
175 | thisDatetime = datetime.datetime.utcfromtimestamp(thisUtcTime[0]) | |
176 |
|
176 | |||
177 | thisDate = thisDatetime.date() |
|
177 | thisDate = thisDatetime.date() | |
178 | thisTime = thisDatetime.time() |
|
178 | thisTime = thisDatetime.time() | |
179 |
|
179 | |||
180 | startUtcTime = (datetime.datetime.combine(thisDate, startTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
180 | startUtcTime = (datetime.datetime.combine(thisDate, startTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
181 | endUtcTime = (datetime.datetime.combine(thisDate, endTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
181 | endUtcTime = (datetime.datetime.combine(thisDate, endTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
182 |
|
182 | |||
183 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] |
|
183 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] | |
184 |
|
184 | |||
185 | self.blockList = ind |
|
185 | self.blockList = ind | |
186 | self.blocksPerFile = len(ind) |
|
186 | self.blocksPerFile = len(ind) | |
187 | return |
|
187 | return | |
188 |
|
188 | |||
189 | def __readMetadata(self): |
|
189 | def __readMetadata(self): | |
190 | ''' |
|
190 | ''' | |
191 | Reads Metadata |
|
191 | Reads Metadata | |
192 | ''' |
|
192 | ''' | |
193 |
|
193 | |||
194 | meta = {} |
|
194 | meta = {} | |
195 |
|
195 | |||
196 | if self.description: |
|
196 | if self.description: | |
197 | for key, value in self.description['Metadata'].items(): |
|
197 | for key, value in self.description['Metadata'].items(): | |
198 | meta[key] = self.fp[value][()] |
|
198 | meta[key] = self.fp[value][()] | |
199 | else: |
|
199 | else: | |
200 | grp = self.fp['Metadata'] |
|
200 | grp = self.fp['Metadata'] | |
201 | for name in grp: |
|
201 | for name in grp: | |
202 | meta[name] = grp[name][()] |
|
202 | meta[name] = grp[name][()] | |
203 |
|
203 | |||
204 | if self.extras: |
|
204 | if self.extras: | |
205 | for key, value in self.extras.items(): |
|
205 | for key, value in self.extras.items(): | |
206 | meta[key] = value |
|
206 | meta[key] = value | |
207 | self.meta = meta |
|
207 | self.meta = meta | |
208 |
|
208 | |||
209 | return |
|
209 | return | |
210 |
|
210 | |||
211 | def __readData(self): |
|
211 | def __readData(self): | |
212 |
|
212 | |||
213 | data = {} |
|
213 | data = {} | |
214 |
|
214 | |||
215 | if self.description: |
|
215 | if self.description: | |
216 | for key, value in self.description['Data'].items(): |
|
216 | for key, value in self.description['Data'].items(): | |
217 | if isinstance(value, str): |
|
217 | if isinstance(value, str): | |
218 | if isinstance(self.fp[value], h5py.Dataset): |
|
218 | if isinstance(self.fp[value], h5py.Dataset): | |
219 | data[key] = self.fp[value][()] |
|
219 | data[key] = self.fp[value][()] | |
220 | elif isinstance(self.fp[value], h5py.Group): |
|
220 | elif isinstance(self.fp[value], h5py.Group): | |
221 | array = [] |
|
221 | array = [] | |
222 | for ch in self.fp[value]: |
|
222 | for ch in self.fp[value]: | |
223 | array.append(self.fp[value][ch][()]) |
|
223 | array.append(self.fp[value][ch][()]) | |
224 | data[key] = numpy.array(array) |
|
224 | data[key] = numpy.array(array) | |
225 | elif isinstance(value, list): |
|
225 | elif isinstance(value, list): | |
226 | array = [] |
|
226 | array = [] | |
227 | for ch in value: |
|
227 | for ch in value: | |
228 | array.append(self.fp[ch][()]) |
|
228 | array.append(self.fp[ch][()]) | |
229 | data[key] = numpy.array(array) |
|
229 | data[key] = numpy.array(array) | |
230 | else: |
|
230 | else: | |
231 | grp = self.fp['Data'] |
|
231 | grp = self.fp['Data'] | |
232 | for name in grp: |
|
232 | for name in grp: | |
233 | if isinstance(grp[name], h5py.Dataset): |
|
233 | if isinstance(grp[name], h5py.Dataset): | |
234 | array = grp[name][()] |
|
234 | array = grp[name][()] | |
235 | elif isinstance(grp[name], h5py.Group): |
|
235 | elif isinstance(grp[name], h5py.Group): | |
236 | array = [] |
|
236 | array = [] | |
237 | for ch in grp[name]: |
|
237 | for ch in grp[name]: | |
238 | array.append(grp[name][ch][()]) |
|
238 | array.append(grp[name][ch][()]) | |
239 | array = numpy.array(array) |
|
239 | array = numpy.array(array) | |
240 | else: |
|
240 | else: | |
241 | log.warning('Unknown type: {}'.format(name)) |
|
241 | log.warning('Unknown type: {}'.format(name)) | |
242 |
|
242 | |||
243 | if name in self.description: |
|
243 | if name in self.description: | |
244 | key = self.description[name] |
|
244 | key = self.description[name] | |
245 | else: |
|
245 | else: | |
246 | key = name |
|
246 | key = name | |
247 | data[key] = array |
|
247 | data[key] = array | |
248 |
|
248 | |||
249 | self.data = data |
|
249 | self.data = data | |
250 | return |
|
250 | return | |
251 |
|
251 | |||
252 | def getData(self): |
|
252 | def getData(self): | |
253 |
|
253 | |||
254 | for attr in self.data: |
|
254 | for attr in self.data: | |
255 | if self.data[attr].ndim == 1: |
|
255 | if self.data[attr].ndim == 1: | |
256 | setattr(self.dataOut, attr, self.data[attr][self.blockIndex]) |
|
256 | setattr(self.dataOut, attr, self.data[attr][self.blockIndex]) | |
257 | else: |
|
257 | else: | |
258 | setattr(self.dataOut, attr, self.data[attr][:, self.blockIndex]) |
|
258 | setattr(self.dataOut, attr, self.data[attr][:, self.blockIndex]) | |
259 |
|
259 | |||
260 | self.dataOut.flagNoData = False |
|
260 | self.dataOut.flagNoData = False | |
261 | self.blockIndex += 1 |
|
261 | self.blockIndex += 1 | |
262 |
|
262 | |||
263 | log.log("Block No. {}/{} -> {}".format( |
|
263 | log.log("Block No. {}/{} -> {}".format( | |
264 | self.blockIndex, |
|
264 | self.blockIndex, | |
265 | self.blocksPerFile, |
|
265 | self.blocksPerFile, | |
266 | self.dataOut.datatime.ctime()), self.name) |
|
266 | self.dataOut.datatime.ctime()), self.name) | |
267 |
|
267 | |||
268 | return |
|
268 | return | |
269 |
|
269 | |||
270 | def run(self, **kwargs): |
|
270 | def run(self, **kwargs): | |
271 |
|
271 | |||
272 | if not(self.isConfig): |
|
272 | if not(self.isConfig): | |
273 | self.setup(**kwargs) |
|
273 | self.setup(**kwargs) | |
274 | self.isConfig = True |
|
274 | self.isConfig = True | |
275 |
|
275 | |||
276 | if self.blockIndex == self.blocksPerFile: |
|
276 | if self.blockIndex == self.blocksPerFile: | |
277 | self.setNextFile() |
|
277 | self.setNextFile() | |
278 |
|
278 | |||
279 | self.getData() |
|
279 | self.getData() | |
280 |
|
280 | |||
281 | return |
|
281 | return | |
282 |
|
282 | |||
283 | @MPDecorator |
|
283 | @MPDecorator | |
284 | class HDFWriter(Operation): |
|
284 | class HDFWriter(Operation): | |
285 | """Operation to write HDF5 files. |
|
285 | """Operation to write HDF5 files. | |
286 |
|
286 | |||
287 | The HDF5 file contains by default two groups Data and Metadata where |
|
287 | The HDF5 file contains by default two groups Data and Metadata where | |
288 | you can save any `dataOut` attribute specified by `dataList` and `metadataList` |
|
288 | you can save any `dataOut` attribute specified by `dataList` and `metadataList` | |
289 | parameters, data attributes are normaly time dependent where the metadata |
|
289 | parameters, data attributes are normaly time dependent where the metadata | |
290 | are not. |
|
290 | are not. | |
291 | It is possible to customize the structure of the HDF5 file with the |
|
291 | It is possible to customize the structure of the HDF5 file with the | |
292 | optional description parameter see the examples. |
|
292 | optional description parameter see the examples. | |
293 |
|
293 | |||
294 | Parameters: |
|
294 | Parameters: | |
295 | ----------- |
|
295 | ----------- | |
296 | path : str |
|
296 | path : str | |
297 | Path where files will be saved. |
|
297 | Path where files will be saved. | |
298 | blocksPerFile : int |
|
298 | blocksPerFile : int | |
299 | Number of blocks per file |
|
299 | Number of blocks per file | |
300 | metadataList : list |
|
300 | metadataList : list | |
301 | List of the dataOut attributes that will be saved as metadata |
|
301 | List of the dataOut attributes that will be saved as metadata | |
302 | dataList : int |
|
302 | dataList : int | |
303 | List of the dataOut attributes that will be saved as data |
|
303 | List of the dataOut attributes that will be saved as data | |
304 | setType : bool |
|
304 | setType : bool | |
305 | If True the name of the files corresponds to the timestamp of the data |
|
305 | If True the name of the files corresponds to the timestamp of the data | |
306 | description : dict, optional |
|
306 | description : dict, optional | |
307 | Dictionary with the desired description of the HDF5 file |
|
307 | Dictionary with the desired description of the HDF5 file | |
308 |
|
308 | |||
309 | Examples |
|
309 | Examples | |
310 | -------- |
|
310 | -------- | |
311 |
|
311 | |||
312 | desc = { |
|
312 | desc = { | |
313 | 'data_output': {'winds': ['z', 'w', 'v']}, |
|
313 | 'data_output': {'winds': ['z', 'w', 'v']}, | |
314 | 'utctime': 'timestamps', |
|
314 | 'utctime': 'timestamps', | |
315 | 'heightList': 'heights' |
|
315 | 'heightList': 'heights' | |
316 | } |
|
316 | } | |
317 | desc = { |
|
317 | desc = { | |
318 | 'data_output': ['z', 'w', 'v'], |
|
318 | 'data_output': ['z', 'w', 'v'], | |
319 | 'utctime': 'timestamps', |
|
319 | 'utctime': 'timestamps', | |
320 | 'heightList': 'heights' |
|
320 | 'heightList': 'heights' | |
321 | } |
|
321 | } | |
322 | desc = { |
|
322 | desc = { | |
323 | 'Data': { |
|
323 | 'Data': { | |
324 | 'data_output': 'winds', |
|
324 | 'data_output': 'winds', | |
325 | 'utctime': 'timestamps' |
|
325 | 'utctime': 'timestamps' | |
326 | }, |
|
326 | }, | |
327 | 'Metadata': { |
|
327 | 'Metadata': { | |
328 | 'heightList': 'heights' |
|
328 | 'heightList': 'heights' | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | writer = proc_unit.addOperation(name='HDFWriter') |
|
332 | writer = proc_unit.addOperation(name='HDFWriter') | |
333 | writer.addParameter(name='path', value='/path/to/file') |
|
333 | writer.addParameter(name='path', value='/path/to/file') | |
334 | writer.addParameter(name='blocksPerFile', value='32') |
|
334 | writer.addParameter(name='blocksPerFile', value='32') | |
335 | writer.addParameter(name='metadataList', value='heightList,timeZone') |
|
335 | writer.addParameter(name='metadataList', value='heightList,timeZone') | |
336 | writer.addParameter(name='dataList',value='data_output,utctime') |
|
336 | writer.addParameter(name='dataList',value='data_output,utctime') | |
337 | # writer.addParameter(name='description',value=json.dumps(desc)) |
|
337 | # writer.addParameter(name='description',value=json.dumps(desc)) | |
338 |
|
338 | |||
339 | """ |
|
339 | """ | |
340 |
|
340 | |||
341 | ext = ".hdf5" |
|
341 | ext = ".hdf5" | |
342 | optchar = "D" |
|
342 | optchar = "D" | |
343 | filename = None |
|
343 | filename = None | |
344 | path = None |
|
344 | path = None | |
345 | setFile = None |
|
345 | setFile = None | |
346 | fp = None |
|
346 | fp = None | |
347 | firsttime = True |
|
347 | firsttime = True | |
348 | #Configurations |
|
348 | #Configurations | |
349 | blocksPerFile = None |
|
349 | blocksPerFile = None | |
350 | blockIndex = None |
|
350 | blockIndex = None | |
351 | dataOut = None |
|
351 | dataOut = None | |
352 | #Data Arrays |
|
352 | #Data Arrays | |
353 | dataList = None |
|
353 | dataList = None | |
354 | metadataList = None |
|
354 | metadataList = None | |
355 | currentDay = None |
|
355 | currentDay = None | |
356 | lastTime = None |
|
356 | lastTime = None | |
357 | last_Azipos = None |
|
357 | last_Azipos = None | |
358 | last_Elepos = None |
|
358 | last_Elepos = None | |
359 | mode = None |
|
359 | mode = None | |
|
360 | #----------------------- | |||
|
361 | Typename = None | |||
360 |
|
362 | |||
361 |
|
363 | |||
362 |
|
364 | |||
363 | def __init__(self): |
|
365 | def __init__(self): | |
364 |
|
366 | |||
365 | Operation.__init__(self) |
|
367 | Operation.__init__(self) | |
366 | return |
|
368 | return | |
367 |
|
369 | |||
|
370 | ||||
|
371 | def set_kwargs(self, **kwargs): | |||
|
372 | ||||
|
373 | for key, value in kwargs.items(): | |||
|
374 | setattr(self, key, value) | |||
|
375 | ||||
|
376 | def set_kwargs_obj(self,obj, **kwargs): | |||
|
377 | ||||
|
378 | for key, value in kwargs.items(): | |||
|
379 | setattr(obj, key, value) | |||
|
380 | ||||
368 | def generalFlag(self): |
|
381 | def generalFlag(self): | |
369 | ####rint("GENERALFLAG") |
|
382 | ####rint("GENERALFLAG") | |
370 | if self.mode== "weather": |
|
383 | if self.mode== "weather": | |
371 | if self.last_Azipos == None: |
|
384 | if self.last_Azipos == None: | |
372 | tmp = self.dataOut.azimuth |
|
385 | tmp = self.dataOut.azimuth | |
373 | ####print("ang azimuth writer",tmp) |
|
386 | ####print("ang azimuth writer",tmp) | |
374 | self.last_Azipos = tmp |
|
387 | self.last_Azipos = tmp | |
375 | flag = False |
|
388 | flag = False | |
376 | return flag |
|
389 | return flag | |
377 | ####print("ang_azimuth writer",self.dataOut.azimuth) |
|
390 | ####print("ang_azimuth writer",self.dataOut.azimuth) | |
378 | result = self.dataOut.azimuth - self.last_Azipos |
|
391 | result = self.dataOut.azimuth - self.last_Azipos | |
379 | self.last_Azipos = self.dataOut.azimuth |
|
392 | self.last_Azipos = self.dataOut.azimuth | |
380 | if result<0: |
|
393 | if result<0: | |
381 | flag = True |
|
394 | flag = True | |
382 | return flag |
|
395 | return flag | |
383 |
|
396 | |||
384 | def setup(self, path=None, blocksPerFile=10, metadataList=None, dataList=None, setType=None, description=None): |
|
397 | def setup(self, path=None, blocksPerFile=10, metadataList=None, dataList=None, setType=None, description=None,type_data=None,**kwargs): | |
385 | self.path = path |
|
398 | self.path = path | |
386 | self.blocksPerFile = blocksPerFile |
|
399 | self.blocksPerFile = blocksPerFile | |
387 | self.metadataList = metadataList |
|
400 | self.metadataList = metadataList | |
388 | self.dataList = [s.strip() for s in dataList] |
|
401 | self.dataList = [s.strip() for s in dataList] | |
389 |
self. |
|
402 | if self.mode == "weather": | |
|
403 | self.setType = "weather" | |||
|
404 | #---------------------------------------- | |||
|
405 | self.set_kwargs(**kwargs) | |||
|
406 | self.set_kwargs_obj(self.dataOut,**kwargs) | |||
|
407 | #print("-----------------------------------------------------------",self.Typename) | |||
|
408 | #print("hola",self.ContactInformation) | |||
|
409 | ||||
390 | self.description = description |
|
410 | self.description = description | |
|
411 | self.type_data=type_data | |||
391 |
|
412 | |||
392 | if self.metadataList is None: |
|
413 | if self.metadataList is None: | |
393 | self.metadataList = self.dataOut.metadata_list |
|
414 | self.metadataList = self.dataOut.metadata_list | |
394 |
|
415 | |||
395 | tableList = [] |
|
416 | tableList = [] | |
396 | dsList = [] |
|
417 | dsList = [] | |
397 |
|
418 | |||
398 | for i in range(len(self.dataList)): |
|
419 | for i in range(len(self.dataList)): | |
399 | dsDict = {} |
|
420 | dsDict = {} | |
400 | if hasattr(self.dataOut, self.dataList[i]): |
|
421 | if hasattr(self.dataOut, self.dataList[i]): | |
401 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
422 | dataAux = getattr(self.dataOut, self.dataList[i]) | |
402 | dsDict['variable'] = self.dataList[i] |
|
423 | dsDict['variable'] = self.dataList[i] | |
403 | else: |
|
424 | else: | |
404 | log.warning('Attribute {} not found in dataOut', self.name) |
|
425 | log.warning('Attribute {} not found in dataOut', self.name) | |
405 | continue |
|
426 | continue | |
406 |
|
427 | |||
407 | if dataAux is None: |
|
428 | if dataAux is None: | |
408 | continue |
|
429 | continue | |
409 | elif isinstance(dataAux, (int, float, numpy.integer, numpy.float)): |
|
430 | elif isinstance(dataAux, (int, float, numpy.integer, numpy.float)): | |
410 | dsDict['nDim'] = 0 |
|
431 | dsDict['nDim'] = 0 | |
411 | else: |
|
432 | else: | |
412 | dsDict['nDim'] = len(dataAux.shape) |
|
433 | dsDict['nDim'] = len(dataAux.shape) | |
413 | dsDict['shape'] = dataAux.shape |
|
434 | dsDict['shape'] = dataAux.shape | |
414 | dsDict['dsNumber'] = dataAux.shape[0] |
|
435 | dsDict['dsNumber'] = dataAux.shape[0] | |
415 | dsDict['dtype'] = dataAux.dtype |
|
436 | dsDict['dtype'] = dataAux.dtype | |
416 |
|
437 | |||
417 | dsList.append(dsDict) |
|
438 | dsList.append(dsDict) | |
418 |
|
439 | |||
419 | self.dsList = dsList |
|
440 | self.dsList = dsList | |
420 | self.currentDay = self.dataOut.datatime.date() |
|
441 | self.currentDay = self.dataOut.datatime.date() | |
421 |
|
442 | |||
422 | def timeFlag(self): |
|
443 | def timeFlag(self): | |
423 | currentTime = self.dataOut.utctime |
|
444 | currentTime = self.dataOut.utctime | |
424 | timeTuple = time.localtime(currentTime) |
|
445 | timeTuple = time.localtime(currentTime) | |
425 | dataDay = timeTuple.tm_yday |
|
446 | dataDay = timeTuple.tm_yday | |
426 |
|
447 | |||
427 | if self.lastTime is None: |
|
448 | if self.lastTime is None: | |
428 | self.lastTime = currentTime |
|
449 | self.lastTime = currentTime | |
429 | self.currentDay = dataDay |
|
450 | self.currentDay = dataDay | |
430 | return False |
|
451 | return False | |
431 |
|
452 | |||
432 | timeDiff = currentTime - self.lastTime |
|
453 | timeDiff = currentTime - self.lastTime | |
433 |
|
454 | |||
434 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora |
|
455 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora | |
435 | if dataDay != self.currentDay: |
|
456 | if dataDay != self.currentDay: | |
436 | self.currentDay = dataDay |
|
457 | self.currentDay = dataDay | |
437 | return True |
|
458 | return True | |
438 | elif timeDiff > 3*60*60: |
|
459 | elif timeDiff > 3*60*60: | |
439 | self.lastTime = currentTime |
|
460 | self.lastTime = currentTime | |
440 | return True |
|
461 | return True | |
441 | else: |
|
462 | else: | |
442 | self.lastTime = currentTime |
|
463 | self.lastTime = currentTime | |
443 | return False |
|
464 | return False | |
444 |
|
465 | |||
445 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, |
|
466 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, | |
446 | dataList=[], setType=None, description={},mode= None): |
|
467 | dataList=[], setType=None, description={},mode= None,type_data=None,**kwargs): | |
447 |
|
468 | |||
|
469 | ###print("VOY A ESCRIBIR----------------------") | |||
|
470 | #print("CHECKTHIS------------------------------------------------------------------*****---",**kwargs) | |||
448 | self.dataOut = dataOut |
|
471 | self.dataOut = dataOut | |
449 | self.mode = mode |
|
472 | self.mode = mode | |
450 | if not(self.isConfig): |
|
473 | if not(self.isConfig): | |
451 | self.setup(path=path, blocksPerFile=blocksPerFile, |
|
474 | self.setup(path=path, blocksPerFile=blocksPerFile, | |
452 | metadataList=metadataList, dataList=dataList, |
|
475 | metadataList=metadataList, dataList=dataList, | |
453 | setType=setType, description=description) |
|
476 | setType=setType, description=description,type_data=type_data,**kwargs) | |
454 |
|
477 | |||
455 | self.isConfig = True |
|
478 | self.isConfig = True | |
456 | self.setNextFile() |
|
479 | self.setNextFile() | |
457 |
|
480 | |||
458 | self.putData() |
|
481 | self.putData() | |
459 | return |
|
482 | return | |
460 |
|
483 | |||
461 | def setNextFile(self): |
|
484 | def setNextFile(self): | |
462 |
|
485 | ###print("HELLO WORLD--------------------------------") | ||
463 | ext = self.ext |
|
486 | ext = self.ext | |
464 | path = self.path |
|
487 | path = self.path | |
465 | setFile = self.setFile |
|
488 | setFile = self.setFile | |
|
489 | type_data = self.type_data | |||
466 |
|
490 | |||
467 | timeTuple = time.localtime(self.dataOut.utctime) |
|
491 | timeTuple = time.localtime(self.dataOut.utctime) | |
468 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
492 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
469 | fullpath = os.path.join(path, subfolder) |
|
493 | fullpath = os.path.join(path, subfolder) | |
470 |
|
494 | |||
471 | if os.path.exists(fullpath): |
|
495 | if os.path.exists(fullpath): | |
472 | filesList = os.listdir(fullpath) |
|
496 | filesList = os.listdir(fullpath) | |
473 | filesList = [k for k in filesList if k.startswith(self.optchar)] |
|
497 | filesList = [k for k in filesList if k.startswith(self.optchar)] | |
474 | if len( filesList ) > 0: |
|
498 | if len( filesList ) > 0: | |
475 | filesList = sorted(filesList, key=str.lower) |
|
499 | filesList = sorted(filesList, key=str.lower) | |
476 | filen = filesList[-1] |
|
500 | filen = filesList[-1] | |
477 | # el filename debera tener el siguiente formato |
|
501 | # el filename debera tener el siguiente formato | |
478 | # 0 1234 567 89A BCDE (hex) |
|
502 | # 0 1234 567 89A BCDE (hex) | |
479 | # x YYYY DDD SSS .ext |
|
503 | # x YYYY DDD SSS .ext | |
480 | if isNumber(filen[8:11]): |
|
504 | if isNumber(filen[8:11]): | |
481 | setFile = int(filen[8:11]) #inicializo mi contador de seteo al seteo del ultimo file |
|
505 | setFile = int(filen[8:11]) #inicializo mi contador de seteo al seteo del ultimo file | |
482 | else: |
|
506 | else: | |
483 | setFile = -1 |
|
507 | setFile = -1 | |
484 | else: |
|
508 | else: | |
485 | setFile = -1 #inicializo mi contador de seteo |
|
509 | setFile = -1 #inicializo mi contador de seteo | |
486 | else: |
|
510 | else: | |
487 | os.makedirs(fullpath) |
|
511 | os.makedirs(fullpath) | |
488 | setFile = -1 #inicializo mi contador de seteo |
|
512 | setFile = -1 #inicializo mi contador de seteo | |
489 |
|
513 | |||
|
514 | ###print("**************************",self.setType) | |||
490 | if self.setType is None: |
|
515 | if self.setType is None: | |
491 | setFile += 1 |
|
516 | setFile += 1 | |
492 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, |
|
517 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, | |
493 | timeTuple.tm_year, |
|
518 | timeTuple.tm_year, | |
494 | timeTuple.tm_yday, |
|
519 | timeTuple.tm_yday, | |
495 | setFile, |
|
520 | setFile, | |
496 | ext ) |
|
521 | ext ) | |
|
522 | elif self.setType == "weather": | |||
|
523 | print("HOLA AMIGOS") | |||
|
524 | wr_exp = self.dataOut.wr_exp | |||
|
525 | if wr_exp== "PPI": | |||
|
526 | wr_type = 'E' | |||
|
527 | ang_ = numpy.mean(self.dataOut.elevation) | |||
|
528 | else: | |||
|
529 | wr_type = 'A' | |||
|
530 | ang_ = numpy.mean(self.dataOut.azimuth) | |||
|
531 | ||||
|
532 | wr_writer = '%s%s%2.1f%s'%('-', | |||
|
533 | wr_type, | |||
|
534 | ang_, | |||
|
535 | '-') | |||
|
536 | ###print("wr_writer********************",wr_writer) | |||
|
537 | file = '%s%4.4d%2.2d%2.2d%s%2.2d%2.2d%2.2d%s%s%s' % (self.optchar, | |||
|
538 | timeTuple.tm_year, | |||
|
539 | timeTuple.tm_mon, | |||
|
540 | timeTuple.tm_mday, | |||
|
541 | '-', | |||
|
542 | timeTuple.tm_hour, | |||
|
543 | timeTuple.tm_min, | |||
|
544 | timeTuple.tm_sec, | |||
|
545 | wr_writer, | |||
|
546 | type_data, | |||
|
547 | ext ) | |||
|
548 | ###print("FILENAME", file) | |||
|
549 | ||||
|
550 | ||||
497 | else: |
|
551 | else: | |
498 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min |
|
552 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min | |
499 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, |
|
553 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, | |
500 | timeTuple.tm_year, |
|
554 | timeTuple.tm_year, | |
501 | timeTuple.tm_yday, |
|
555 | timeTuple.tm_yday, | |
502 | setFile, |
|
556 | setFile, | |
503 | ext ) |
|
557 | ext ) | |
504 |
|
558 | |||
505 | self.filename = os.path.join( path, subfolder, file ) |
|
559 | self.filename = os.path.join( path, subfolder, file ) | |
506 |
|
560 | |||
507 | #Setting HDF5 File |
|
561 | #Setting HDF5 File | |
|
562 | ||||
508 | self.fp = h5py.File(self.filename, 'w') |
|
563 | self.fp = h5py.File(self.filename, 'w') | |
509 | #write metadata |
|
564 | #write metadata | |
510 | self.writeMetadata(self.fp) |
|
565 | self.writeMetadata(self.fp) | |
511 | #Write data |
|
566 | #Write data | |
512 | self.writeData(self.fp) |
|
567 | self.writeData(self.fp) | |
513 |
|
568 | |||
514 | def getLabel(self, name, x=None): |
|
569 | def getLabel(self, name, x=None): | |
515 |
|
570 | |||
516 | if x is None: |
|
571 | if x is None: | |
517 | if 'Data' in self.description: |
|
572 | if 'Data' in self.description: | |
518 | data = self.description['Data'] |
|
573 | data = self.description['Data'] | |
519 | if 'Metadata' in self.description: |
|
574 | if 'Metadata' in self.description: | |
520 | data.update(self.description['Metadata']) |
|
575 | data.update(self.description['Metadata']) | |
521 | else: |
|
576 | else: | |
522 | data = self.description |
|
577 | data = self.description | |
523 | if name in data: |
|
578 | if name in data: | |
524 | if isinstance(data[name], str): |
|
579 | if isinstance(data[name], str): | |
525 | return data[name] |
|
580 | return data[name] | |
526 | elif isinstance(data[name], list): |
|
581 | elif isinstance(data[name], list): | |
527 | return None |
|
582 | return None | |
528 | elif isinstance(data[name], dict): |
|
583 | elif isinstance(data[name], dict): | |
529 | for key, value in data[name].items(): |
|
584 | for key, value in data[name].items(): | |
530 | return key |
|
585 | return key | |
531 | return name |
|
586 | return name | |
532 | else: |
|
587 | else: | |
533 | if 'Metadata' in self.description: |
|
588 | if 'Metadata' in self.description: | |
534 | meta = self.description['Metadata'] |
|
589 | meta = self.description['Metadata'] | |
535 | else: |
|
590 | else: | |
536 | meta = self.description |
|
591 | meta = self.description | |
537 | if name in meta: |
|
592 | if name in meta: | |
538 | if isinstance(meta[name], list): |
|
593 | if isinstance(meta[name], list): | |
539 | return meta[name][x] |
|
594 | return meta[name][x] | |
540 | elif isinstance(meta[name], dict): |
|
595 | elif isinstance(meta[name], dict): | |
541 | for key, value in meta[name].items(): |
|
596 | for key, value in meta[name].items(): | |
542 | return value[x] |
|
597 | return value[x] | |
543 | if 'cspc' in name: |
|
598 | if 'cspc' in name: | |
544 | return 'pair{:02d}'.format(x) |
|
599 | return 'pair{:02d}'.format(x) | |
545 | else: |
|
600 | else: | |
546 | return 'channel{:02d}'.format(x) |
|
601 | return 'channel{:02d}'.format(x) | |
547 |
|
602 | |||
548 | def writeMetadata(self, fp): |
|
603 | def writeMetadata(self, fp): | |
549 |
|
604 | |||
550 | if self.description: |
|
605 | if self.description: | |
551 | if 'Metadata' in self.description: |
|
606 | if 'Metadata' in self.description: | |
552 | grp = fp.create_group('Metadata') |
|
607 | grp = fp.create_group('Metadata') | |
553 | else: |
|
608 | else: | |
554 | grp = fp |
|
609 | grp = fp | |
555 | else: |
|
610 | else: | |
556 | grp = fp.create_group('Metadata') |
|
611 | grp = fp.create_group('Metadata') | |
557 |
|
612 | |||
558 | for i in range(len(self.metadataList)): |
|
613 | for i in range(len(self.metadataList)): | |
559 | if not hasattr(self.dataOut, self.metadataList[i]): |
|
614 | if not hasattr(self.dataOut, self.metadataList[i]): | |
560 | log.warning('Metadata: `{}` not found'.format(self.metadataList[i]), self.name) |
|
615 | log.warning('Metadata: `{}` not found'.format(self.metadataList[i]), self.name) | |
561 | continue |
|
616 | continue | |
562 | value = getattr(self.dataOut, self.metadataList[i]) |
|
617 | value = getattr(self.dataOut, self.metadataList[i]) | |
563 | if isinstance(value, bool): |
|
618 | if isinstance(value, bool): | |
564 | if value is True: |
|
619 | if value is True: | |
565 | value = 1 |
|
620 | value = 1 | |
566 | else: |
|
621 | else: | |
567 | value = 0 |
|
622 | value = 0 | |
568 | grp.create_dataset(self.getLabel(self.metadataList[i]), data=value) |
|
623 | grp.create_dataset(self.getLabel(self.metadataList[i]), data=value) | |
569 | return |
|
624 | return | |
570 |
|
625 | |||
571 | def writeData(self, fp): |
|
626 | def writeData(self, fp): | |
572 |
|
627 | |||
573 | if self.description: |
|
628 | if self.description: | |
574 | if 'Data' in self.description: |
|
629 | if 'Data' in self.description: | |
575 | grp = fp.create_group('Data') |
|
630 | grp = fp.create_group('Data') | |
576 | else: |
|
631 | else: | |
577 | grp = fp |
|
632 | grp = fp | |
578 | else: |
|
633 | else: | |
579 | grp = fp.create_group('Data') |
|
634 | grp = fp.create_group('Data') | |
580 |
|
635 | |||
581 | dtsets = [] |
|
636 | dtsets = [] | |
582 | data = [] |
|
637 | data = [] | |
583 |
|
638 | |||
584 | for dsInfo in self.dsList: |
|
639 | for dsInfo in self.dsList: | |
585 | if dsInfo['nDim'] == 0: |
|
640 | if dsInfo['nDim'] == 0: | |
586 | ds = grp.create_dataset( |
|
641 | ds = grp.create_dataset( | |
587 | self.getLabel(dsInfo['variable']), |
|
642 | self.getLabel(dsInfo['variable']), | |
588 | (self.blocksPerFile, ), |
|
643 | (self.blocksPerFile, ), | |
589 | chunks=True, |
|
644 | chunks=True, | |
590 | dtype=numpy.float64) |
|
645 | dtype=numpy.float64) | |
591 | dtsets.append(ds) |
|
646 | dtsets.append(ds) | |
592 | data.append((dsInfo['variable'], -1)) |
|
647 | data.append((dsInfo['variable'], -1)) | |
593 | else: |
|
648 | else: | |
594 | label = self.getLabel(dsInfo['variable']) |
|
649 | label = self.getLabel(dsInfo['variable']) | |
595 | if label is not None: |
|
650 | if label is not None: | |
596 | sgrp = grp.create_group(label) |
|
651 | sgrp = grp.create_group(label) | |
597 | else: |
|
652 | else: | |
598 | sgrp = grp |
|
653 | sgrp = grp | |
599 | for i in range(dsInfo['dsNumber']): |
|
654 | for i in range(dsInfo['dsNumber']): | |
600 | ds = sgrp.create_dataset( |
|
655 | ds = sgrp.create_dataset( | |
601 | self.getLabel(dsInfo['variable'], i), |
|
656 | self.getLabel(dsInfo['variable'], i), | |
602 | (self.blocksPerFile, ) + dsInfo['shape'][1:], |
|
657 | (self.blocksPerFile, ) + dsInfo['shape'][1:], | |
603 | chunks=True, |
|
658 | chunks=True, | |
604 | dtype=dsInfo['dtype']) |
|
659 | dtype=dsInfo['dtype']) | |
605 | dtsets.append(ds) |
|
660 | dtsets.append(ds) | |
606 | data.append((dsInfo['variable'], i)) |
|
661 | data.append((dsInfo['variable'], i)) | |
607 | fp.flush() |
|
662 | fp.flush() | |
608 |
|
663 | |||
609 | log.log('Creating file: {}'.format(fp.filename), self.name) |
|
664 | log.log('Creating file: {}'.format(fp.filename), self.name) | |
610 |
|
665 | |||
611 | self.ds = dtsets |
|
666 | self.ds = dtsets | |
612 | self.data = data |
|
667 | self.data = data | |
613 | self.firsttime = True |
|
668 | self.firsttime = True | |
614 | self.blockIndex = 0 |
|
669 | self.blockIndex = 0 | |
615 | return |
|
670 | return | |
616 |
|
671 | |||
617 | def putData(self): |
|
672 | def putData(self): | |
618 |
### |
|
673 | ###print("**************************PUT DATA***************************************************") | |
619 | if (self.blockIndex == self.blocksPerFile) or self.timeFlag() or self.generalFlag(): |
|
674 | if (self.blockIndex == self.blocksPerFile) or self.timeFlag() or self.generalFlag(): | |
620 | self.closeFile() |
|
675 | self.closeFile() | |
621 | self.setNextFile() |
|
676 | self.setNextFile() | |
622 |
|
677 | |||
623 | for i, ds in enumerate(self.ds): |
|
678 | for i, ds in enumerate(self.ds): | |
624 | attr, ch = self.data[i] |
|
679 | attr, ch = self.data[i] | |
625 | if ch == -1: |
|
680 | if ch == -1: | |
626 | ds[self.blockIndex] = getattr(self.dataOut, attr) |
|
681 | ds[self.blockIndex] = getattr(self.dataOut, attr) | |
627 | else: |
|
682 | else: | |
628 | ds[self.blockIndex] = getattr(self.dataOut, attr)[ch] |
|
683 | ds[self.blockIndex] = getattr(self.dataOut, attr)[ch] | |
629 |
|
684 | |||
630 | self.fp.flush() |
|
685 | self.fp.flush() | |
631 | self.blockIndex += 1 |
|
686 | self.blockIndex += 1 | |
632 | log.log('Block No. {}/{}'.format(self.blockIndex, self.blocksPerFile), self.name) |
|
687 | log.log('Block No. {}/{}'.format(self.blockIndex, self.blocksPerFile), self.name) | |
633 |
|
688 | |||
634 | return |
|
689 | return | |
635 |
|
690 | |||
636 | def closeFile(self): |
|
691 | def closeFile(self): | |
637 |
|
692 | |||
638 | if self.blockIndex != self.blocksPerFile: |
|
693 | if self.blockIndex != self.blocksPerFile: | |
639 | for ds in self.ds: |
|
694 | for ds in self.ds: | |
640 | ds.resize(self.blockIndex, axis=0) |
|
695 | ds.resize(self.blockIndex, axis=0) | |
641 |
|
696 | |||
642 | if self.fp: |
|
697 | if self.fp: | |
643 | self.fp.flush() |
|
698 | self.fp.flush() | |
644 | self.fp.close() |
|
699 | self.fp.close() | |
645 |
|
700 | |||
646 | def close(self): |
|
701 | def close(self): | |
647 |
|
702 | |||
648 | self.closeFile() |
|
703 | self.closeFile() |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,1626 +1,1633 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy,math |
|
2 | import numpy,math | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon |
|
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon | |
6 | from schainpy.utils import log |
|
6 | from schainpy.utils import log | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 |
|
9 | |||
10 |
|
10 | |||
11 | class VoltageProc(ProcessingUnit): |
|
11 | class VoltageProc(ProcessingUnit): | |
12 |
|
12 | |||
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 |
|
14 | |||
15 | ProcessingUnit.__init__(self) |
|
15 | ProcessingUnit.__init__(self) | |
16 |
|
16 | |||
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 | self.setupReq = False |
|
19 | self.setupReq = False | |
20 |
|
20 | |||
21 | def run(self): |
|
21 | def run(self): | |
22 |
|
22 | |||
23 | if self.dataIn.type == 'AMISR': |
|
23 | if self.dataIn.type == 'AMISR': | |
24 | self.__updateObjFromAmisrInput() |
|
24 | self.__updateObjFromAmisrInput() | |
25 |
|
25 | |||
26 | if self.dataIn.type == 'Voltage': |
|
26 | if self.dataIn.type == 'Voltage': | |
27 | self.dataOut.copy(self.dataIn) |
|
27 | self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | def __updateObjFromAmisrInput(self): |
|
29 | def __updateObjFromAmisrInput(self): | |
30 |
|
30 | |||
31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
31 | self.dataOut.timeZone = self.dataIn.timeZone | |
32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
32 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
33 | self.dataOut.errorCount = self.dataIn.errorCount | |
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
35 |
|
35 | |||
36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
36 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
37 | self.dataOut.data = self.dataIn.data |
|
37 | self.dataOut.data = self.dataIn.data | |
38 | self.dataOut.utctime = self.dataIn.utctime |
|
38 | self.dataOut.utctime = self.dataIn.utctime | |
39 | self.dataOut.channelList = self.dataIn.channelList |
|
39 | self.dataOut.channelList = self.dataIn.channelList | |
40 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
40 | #self.dataOut.timeInterval = self.dataIn.timeInterval | |
41 | self.dataOut.heightList = self.dataIn.heightList |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
42 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
43 |
|
43 | |||
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
46 | self.dataOut.frequency = self.dataIn.frequency |
|
46 | self.dataOut.frequency = self.dataIn.frequency | |
47 |
|
47 | |||
48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
48 | self.dataOut.azimuth = self.dataIn.azimuth | |
49 | self.dataOut.zenith = self.dataIn.zenith |
|
49 | self.dataOut.zenith = self.dataIn.zenith | |
50 |
|
50 | |||
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | class selectChannels(Operation): |
|
56 | class selectChannels(Operation): | |
57 |
|
57 | |||
58 | def run(self, dataOut, channelList): |
|
58 | def run(self, dataOut, channelList): | |
59 |
|
59 | |||
60 | channelIndexList = [] |
|
60 | channelIndexList = [] | |
61 | self.dataOut = dataOut |
|
61 | self.dataOut = dataOut | |
62 | for channel in channelList: |
|
62 | for channel in channelList: | |
63 | if channel not in self.dataOut.channelList: |
|
63 | if channel not in self.dataOut.channelList: | |
64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) | |
65 |
|
65 | |||
66 | index = self.dataOut.channelList.index(channel) |
|
66 | index = self.dataOut.channelList.index(channel) | |
67 | channelIndexList.append(index) |
|
67 | channelIndexList.append(index) | |
68 | self.selectChannelsByIndex(channelIndexList) |
|
68 | self.selectChannelsByIndex(channelIndexList) | |
69 | return self.dataOut |
|
69 | return self.dataOut | |
70 |
|
70 | |||
71 | def selectChannelsByIndex(self, channelIndexList): |
|
71 | def selectChannelsByIndex(self, channelIndexList): | |
72 | """ |
|
72 | """ | |
73 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
73 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
74 |
|
74 | |||
75 | Input: |
|
75 | Input: | |
76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
77 |
|
77 | |||
78 | Affected: |
|
78 | Affected: | |
79 | self.dataOut.data |
|
79 | self.dataOut.data | |
80 | self.dataOut.channelIndexList |
|
80 | self.dataOut.channelIndexList | |
81 | self.dataOut.nChannels |
|
81 | self.dataOut.nChannels | |
82 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
82 | self.dataOut.m_ProcessingHeader.totalSpectra | |
83 | self.dataOut.systemHeaderObj.numChannels |
|
83 | self.dataOut.systemHeaderObj.numChannels | |
84 | self.dataOut.m_ProcessingHeader.blockSize |
|
84 | self.dataOut.m_ProcessingHeader.blockSize | |
85 |
|
85 | |||
86 | Return: |
|
86 | Return: | |
87 | None |
|
87 | None | |
88 | """ |
|
88 | """ | |
89 |
|
89 | |||
90 | for channelIndex in channelIndexList: |
|
90 | for channelIndex in channelIndexList: | |
91 | if channelIndex not in self.dataOut.channelIndexList: |
|
91 | if channelIndex not in self.dataOut.channelIndexList: | |
92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) | |
93 |
|
93 | |||
94 | if self.dataOut.type == 'Voltage': |
|
94 | if self.dataOut.type == 'Voltage': | |
95 | if self.dataOut.flagDataAsBlock: |
|
95 | if self.dataOut.flagDataAsBlock: | |
96 | """ |
|
96 | """ | |
97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
98 | """ |
|
98 | """ | |
99 | data = self.dataOut.data[channelIndexList,:,:] |
|
99 | data = self.dataOut.data[channelIndexList,:,:] | |
100 | else: |
|
100 | else: | |
101 | data = self.dataOut.data[channelIndexList,:] |
|
101 | data = self.dataOut.data[channelIndexList,:] | |
102 |
|
102 | |||
103 | self.dataOut.data = data |
|
103 | self.dataOut.data = data | |
104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
105 | self.dataOut.channelList = range(len(channelIndexList)) |
|
105 | self.dataOut.channelList = range(len(channelIndexList)) | |
106 |
|
106 | |||
107 | elif self.dataOut.type == 'Spectra': |
|
107 | elif self.dataOut.type == 'Spectra': | |
108 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
108 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
109 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
109 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
110 |
|
110 | |||
111 | self.dataOut.data_spc = data_spc |
|
111 | self.dataOut.data_spc = data_spc | |
112 | self.dataOut.data_dc = data_dc |
|
112 | self.dataOut.data_dc = data_dc | |
113 |
|
113 | |||
114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
115 | self.dataOut.channelList = range(len(channelIndexList)) |
|
115 | self.dataOut.channelList = range(len(channelIndexList)) | |
116 | self.__selectPairsByChannel(channelIndexList) |
|
116 | self.__selectPairsByChannel(channelIndexList) | |
117 |
|
117 | |||
118 | return 1 |
|
118 | return 1 | |
119 |
|
119 | |||
120 | def __selectPairsByChannel(self, channelList=None): |
|
120 | def __selectPairsByChannel(self, channelList=None): | |
121 |
|
121 | |||
122 | if channelList == None: |
|
122 | if channelList == None: | |
123 | return |
|
123 | return | |
124 |
|
124 | |||
125 | pairsIndexListSelected = [] |
|
125 | pairsIndexListSelected = [] | |
126 | for pairIndex in self.dataOut.pairsIndexList: |
|
126 | for pairIndex in self.dataOut.pairsIndexList: | |
127 | # First pair |
|
127 | # First pair | |
128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
129 | continue |
|
129 | continue | |
130 | # Second pair |
|
130 | # Second pair | |
131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
132 | continue |
|
132 | continue | |
133 |
|
133 | |||
134 | pairsIndexListSelected.append(pairIndex) |
|
134 | pairsIndexListSelected.append(pairIndex) | |
135 |
|
135 | |||
136 | if not pairsIndexListSelected: |
|
136 | if not pairsIndexListSelected: | |
137 | self.dataOut.data_cspc = None |
|
137 | self.dataOut.data_cspc = None | |
138 | self.dataOut.pairsList = [] |
|
138 | self.dataOut.pairsList = [] | |
139 | return |
|
139 | return | |
140 |
|
140 | |||
141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
143 | for i in pairsIndexListSelected] |
|
143 | for i in pairsIndexListSelected] | |
144 |
|
144 | |||
145 | return |
|
145 | return | |
146 |
|
146 | |||
147 | class selectHeights(Operation): |
|
147 | class selectHeights(Operation): | |
148 |
|
148 | |||
149 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): |
|
149 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): | |
150 | """ |
|
150 | """ | |
151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
152 | minHei <= height <= maxHei |
|
152 | minHei <= height <= maxHei | |
153 |
|
153 | |||
154 | Input: |
|
154 | Input: | |
155 | minHei : valor minimo de altura a considerar |
|
155 | minHei : valor minimo de altura a considerar | |
156 | maxHei : valor maximo de altura a considerar |
|
156 | maxHei : valor maximo de altura a considerar | |
157 |
|
157 | |||
158 | Affected: |
|
158 | Affected: | |
159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
160 |
|
160 | |||
161 | Return: |
|
161 | Return: | |
162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
163 | """ |
|
163 | """ | |
164 |
|
164 | |||
165 | self.dataOut = dataOut |
|
165 | self.dataOut = dataOut | |
166 |
|
166 | |||
167 | if minHei and maxHei: |
|
167 | if minHei and maxHei: | |
168 |
|
168 | |||
169 | if (minHei < self.dataOut.heightList[0]): |
|
169 | if (minHei < self.dataOut.heightList[0]): | |
170 | minHei = self.dataOut.heightList[0] |
|
170 | minHei = self.dataOut.heightList[0] | |
171 |
|
171 | |||
172 | if (maxHei > self.dataOut.heightList[-1]): |
|
172 | if (maxHei > self.dataOut.heightList[-1]): | |
173 | maxHei = self.dataOut.heightList[-1] |
|
173 | maxHei = self.dataOut.heightList[-1] | |
174 |
|
174 | |||
175 | minIndex = 0 |
|
175 | minIndex = 0 | |
176 | maxIndex = 0 |
|
176 | maxIndex = 0 | |
177 | heights = self.dataOut.heightList |
|
177 | heights = self.dataOut.heightList | |
178 |
|
178 | |||
179 | inda = numpy.where(heights >= minHei) |
|
179 | inda = numpy.where(heights >= minHei) | |
180 | indb = numpy.where(heights <= maxHei) |
|
180 | indb = numpy.where(heights <= maxHei) | |
181 |
|
181 | |||
182 | try: |
|
182 | try: | |
183 | minIndex = inda[0][0] |
|
183 | minIndex = inda[0][0] | |
184 | except: |
|
184 | except: | |
185 | minIndex = 0 |
|
185 | minIndex = 0 | |
186 |
|
186 | |||
187 | try: |
|
187 | try: | |
188 | maxIndex = indb[0][-1] |
|
188 | maxIndex = indb[0][-1] | |
189 | except: |
|
189 | except: | |
190 | maxIndex = len(heights) |
|
190 | maxIndex = len(heights) | |
191 |
|
191 | |||
192 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
192 | self.selectHeightsByIndex(minIndex, maxIndex) | |
193 |
|
193 | |||
194 | return self.dataOut |
|
194 | return self.dataOut | |
195 |
|
195 | |||
196 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
196 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
197 | """ |
|
197 | """ | |
198 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
198 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
199 | minIndex <= index <= maxIndex |
|
199 | minIndex <= index <= maxIndex | |
200 |
|
200 | |||
201 | Input: |
|
201 | Input: | |
202 | minIndex : valor de indice minimo de altura a considerar |
|
202 | minIndex : valor de indice minimo de altura a considerar | |
203 | maxIndex : valor de indice maximo de altura a considerar |
|
203 | maxIndex : valor de indice maximo de altura a considerar | |
204 |
|
204 | |||
205 | Affected: |
|
205 | Affected: | |
206 | self.dataOut.data |
|
206 | self.dataOut.data | |
207 | self.dataOut.heightList |
|
207 | self.dataOut.heightList | |
208 |
|
208 | |||
209 | Return: |
|
209 | Return: | |
210 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
210 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
211 | """ |
|
211 | """ | |
212 |
|
212 | |||
213 | if self.dataOut.type == 'Voltage': |
|
213 | if self.dataOut.type == 'Voltage': | |
214 | if (minIndex < 0) or (minIndex > maxIndex): |
|
214 | if (minIndex < 0) or (minIndex > maxIndex): | |
215 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
215 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
216 |
|
216 | |||
217 | if (maxIndex >= self.dataOut.nHeights): |
|
217 | if (maxIndex >= self.dataOut.nHeights): | |
218 | maxIndex = self.dataOut.nHeights |
|
218 | maxIndex = self.dataOut.nHeights | |
219 |
|
219 | |||
220 | #voltage |
|
220 | #voltage | |
221 | if self.dataOut.flagDataAsBlock: |
|
221 | if self.dataOut.flagDataAsBlock: | |
222 | """ |
|
222 | """ | |
223 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
223 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
224 | """ |
|
224 | """ | |
225 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
225 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
226 | else: |
|
226 | else: | |
227 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
227 | data = self.dataOut.data[:, minIndex:maxIndex] | |
228 |
|
228 | |||
229 | # firstHeight = self.dataOut.heightList[minIndex] |
|
229 | # firstHeight = self.dataOut.heightList[minIndex] | |
230 |
|
230 | |||
231 | self.dataOut.data = data |
|
231 | self.dataOut.data = data | |
232 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
232 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
233 |
|
233 | |||
234 | if self.dataOut.nHeights <= 1: |
|
234 | if self.dataOut.nHeights <= 1: | |
235 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
235 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) | |
236 | elif self.dataOut.type == 'Spectra': |
|
236 | elif self.dataOut.type == 'Spectra': | |
237 | if (minIndex < 0) or (minIndex > maxIndex): |
|
237 | if (minIndex < 0) or (minIndex > maxIndex): | |
238 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
238 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
239 | minIndex, maxIndex)) |
|
239 | minIndex, maxIndex)) | |
240 |
|
240 | |||
241 | if (maxIndex >= self.dataOut.nHeights): |
|
241 | if (maxIndex >= self.dataOut.nHeights): | |
242 | maxIndex = self.dataOut.nHeights - 1 |
|
242 | maxIndex = self.dataOut.nHeights - 1 | |
243 |
|
243 | |||
244 | # Spectra |
|
244 | # Spectra | |
245 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
245 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
246 |
|
246 | |||
247 | data_cspc = None |
|
247 | data_cspc = None | |
248 | if self.dataOut.data_cspc is not None: |
|
248 | if self.dataOut.data_cspc is not None: | |
249 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
249 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
250 |
|
250 | |||
251 | data_dc = None |
|
251 | data_dc = None | |
252 | if self.dataOut.data_dc is not None: |
|
252 | if self.dataOut.data_dc is not None: | |
253 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
253 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
254 |
|
254 | |||
255 | self.dataOut.data_spc = data_spc |
|
255 | self.dataOut.data_spc = data_spc | |
256 | self.dataOut.data_cspc = data_cspc |
|
256 | self.dataOut.data_cspc = data_cspc | |
257 | self.dataOut.data_dc = data_dc |
|
257 | self.dataOut.data_dc = data_dc | |
258 |
|
258 | |||
259 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
259 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
260 |
|
260 | |||
261 | return 1 |
|
261 | return 1 | |
262 |
|
262 | |||
263 |
|
263 | |||
264 | class filterByHeights(Operation): |
|
264 | class filterByHeights(Operation): | |
265 |
|
265 | |||
266 | def run(self, dataOut, window): |
|
266 | def run(self, dataOut, window): | |
267 |
|
267 | |||
268 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
268 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
269 |
|
269 | |||
270 | if window == None: |
|
270 | if window == None: | |
271 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
271 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
272 |
|
272 | |||
273 | newdelta = deltaHeight * window |
|
273 | newdelta = deltaHeight * window | |
274 | r = dataOut.nHeights % window |
|
274 | r = dataOut.nHeights % window | |
275 | newheights = (dataOut.nHeights-r)/window |
|
275 | newheights = (dataOut.nHeights-r)/window | |
276 |
|
276 | |||
277 | if newheights <= 1: |
|
277 | if newheights <= 1: | |
278 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
278 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) | |
279 |
|
279 | |||
280 | if dataOut.flagDataAsBlock: |
|
280 | if dataOut.flagDataAsBlock: | |
281 | """ |
|
281 | """ | |
282 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
282 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
283 | """ |
|
283 | """ | |
284 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
284 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] | |
285 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
285 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) | |
286 | buffer = numpy.sum(buffer,3) |
|
286 | buffer = numpy.sum(buffer,3) | |
287 |
|
287 | |||
288 | else: |
|
288 | else: | |
289 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
289 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] | |
290 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
290 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) | |
291 | buffer = numpy.sum(buffer,2) |
|
291 | buffer = numpy.sum(buffer,2) | |
292 |
|
292 | |||
293 | dataOut.data = buffer |
|
293 | dataOut.data = buffer | |
294 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
294 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
295 | dataOut.windowOfFilter = window |
|
295 | dataOut.windowOfFilter = window | |
296 |
|
296 | |||
297 | return dataOut |
|
297 | return dataOut | |
298 |
|
298 | |||
299 |
|
299 | |||
300 | class setH0(Operation): |
|
300 | class setH0(Operation): | |
301 |
|
301 | |||
302 | def run(self, dataOut, h0, deltaHeight = None): |
|
302 | def run(self, dataOut, h0, deltaHeight = None): | |
303 |
|
303 | |||
304 | if not deltaHeight: |
|
304 | if not deltaHeight: | |
305 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
305 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
306 |
|
306 | |||
307 | nHeights = dataOut.nHeights |
|
307 | nHeights = dataOut.nHeights | |
308 |
|
308 | |||
309 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
309 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
310 |
|
310 | |||
311 | dataOut.heightList = newHeiRange |
|
311 | dataOut.heightList = newHeiRange | |
312 |
|
312 | |||
313 | return dataOut |
|
313 | return dataOut | |
314 |
|
314 | |||
315 |
|
315 | |||
316 | class deFlip(Operation): |
|
316 | class deFlip(Operation): | |
317 |
|
317 | |||
318 | def run(self, dataOut, channelList = []): |
|
318 | def run(self, dataOut, channelList = []): | |
319 |
|
319 | |||
320 | data = dataOut.data.copy() |
|
320 | data = dataOut.data.copy() | |
321 |
|
321 | |||
322 | if dataOut.flagDataAsBlock: |
|
322 | if dataOut.flagDataAsBlock: | |
323 | flip = self.flip |
|
323 | flip = self.flip | |
324 | profileList = list(range(dataOut.nProfiles)) |
|
324 | profileList = list(range(dataOut.nProfiles)) | |
325 |
|
325 | |||
326 | if not channelList: |
|
326 | if not channelList: | |
327 | for thisProfile in profileList: |
|
327 | for thisProfile in profileList: | |
328 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
328 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
329 | flip *= -1.0 |
|
329 | flip *= -1.0 | |
330 | else: |
|
330 | else: | |
331 | for thisChannel in channelList: |
|
331 | for thisChannel in channelList: | |
332 | if thisChannel not in dataOut.channelList: |
|
332 | if thisChannel not in dataOut.channelList: | |
333 | continue |
|
333 | continue | |
334 |
|
334 | |||
335 | for thisProfile in profileList: |
|
335 | for thisProfile in profileList: | |
336 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
336 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
337 | flip *= -1.0 |
|
337 | flip *= -1.0 | |
338 |
|
338 | |||
339 | self.flip = flip |
|
339 | self.flip = flip | |
340 |
|
340 | |||
341 | else: |
|
341 | else: | |
342 | if not channelList: |
|
342 | if not channelList: | |
343 | data[:,:] = data[:,:]*self.flip |
|
343 | data[:,:] = data[:,:]*self.flip | |
344 | else: |
|
344 | else: | |
345 | for thisChannel in channelList: |
|
345 | for thisChannel in channelList: | |
346 | if thisChannel not in dataOut.channelList: |
|
346 | if thisChannel not in dataOut.channelList: | |
347 | continue |
|
347 | continue | |
348 |
|
348 | |||
349 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
349 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
350 |
|
350 | |||
351 | self.flip *= -1. |
|
351 | self.flip *= -1. | |
352 |
|
352 | |||
353 | dataOut.data = data |
|
353 | dataOut.data = data | |
354 |
|
354 | |||
355 | return dataOut |
|
355 | return dataOut | |
356 |
|
356 | |||
357 |
|
357 | |||
358 | class setAttribute(Operation): |
|
358 | class setAttribute(Operation): | |
359 | ''' |
|
359 | ''' | |
360 | Set an arbitrary attribute(s) to dataOut |
|
360 | Set an arbitrary attribute(s) to dataOut | |
361 | ''' |
|
361 | ''' | |
362 |
|
362 | |||
363 | def __init__(self): |
|
363 | def __init__(self): | |
364 |
|
364 | |||
365 | Operation.__init__(self) |
|
365 | Operation.__init__(self) | |
366 | self._ready = False |
|
366 | self._ready = False | |
367 |
|
367 | |||
368 | def run(self, dataOut, **kwargs): |
|
368 | def run(self, dataOut, **kwargs): | |
369 |
|
369 | |||
370 | for key, value in kwargs.items(): |
|
370 | for key, value in kwargs.items(): | |
371 | setattr(dataOut, key, value) |
|
371 | setattr(dataOut, key, value) | |
372 |
|
372 | |||
373 | return dataOut |
|
373 | return dataOut | |
374 |
|
374 | |||
375 |
|
375 | |||
376 | @MPDecorator |
|
376 | @MPDecorator | |
377 | class printAttribute(Operation): |
|
377 | class printAttribute(Operation): | |
378 | ''' |
|
378 | ''' | |
379 | Print an arbitrary attribute of dataOut |
|
379 | Print an arbitrary attribute of dataOut | |
380 | ''' |
|
380 | ''' | |
381 |
|
381 | |||
382 | def __init__(self): |
|
382 | def __init__(self): | |
383 |
|
383 | |||
384 | Operation.__init__(self) |
|
384 | Operation.__init__(self) | |
385 |
|
385 | |||
386 | def run(self, dataOut, attributes): |
|
386 | def run(self, dataOut, attributes): | |
387 |
|
387 | |||
388 | if isinstance(attributes, str): |
|
388 | if isinstance(attributes, str): | |
389 | attributes = [attributes] |
|
389 | attributes = [attributes] | |
390 | for attr in attributes: |
|
390 | for attr in attributes: | |
391 | if hasattr(dataOut, attr): |
|
391 | if hasattr(dataOut, attr): | |
392 | log.log(getattr(dataOut, attr), attr) |
|
392 | log.log(getattr(dataOut, attr), attr) | |
393 |
|
393 | |||
394 |
|
394 | |||
395 | class interpolateHeights(Operation): |
|
395 | class interpolateHeights(Operation): | |
396 |
|
396 | |||
397 | def run(self, dataOut, topLim, botLim): |
|
397 | def run(self, dataOut, topLim, botLim): | |
398 | #69 al 72 para julia |
|
398 | #69 al 72 para julia | |
399 | #82-84 para meteoros |
|
399 | #82-84 para meteoros | |
400 | if len(numpy.shape(dataOut.data))==2: |
|
400 | if len(numpy.shape(dataOut.data))==2: | |
401 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
401 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 | |
402 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
402 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
403 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
403 | #dataOut.data[:,botLim:limSup+1] = sampInterp | |
404 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
404 | dataOut.data[:,botLim:topLim+1] = sampInterp | |
405 | else: |
|
405 | else: | |
406 | nHeights = dataOut.data.shape[2] |
|
406 | nHeights = dataOut.data.shape[2] | |
407 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
407 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
408 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
408 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] | |
409 | f = interpolate.interp1d(x, y, axis = 2) |
|
409 | f = interpolate.interp1d(x, y, axis = 2) | |
410 | xnew = numpy.arange(botLim,topLim+1) |
|
410 | xnew = numpy.arange(botLim,topLim+1) | |
411 | ynew = f(xnew) |
|
411 | ynew = f(xnew) | |
412 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
412 | dataOut.data[:,:,botLim:topLim+1] = ynew | |
413 |
|
413 | |||
414 | return dataOut |
|
414 | return dataOut | |
415 |
|
415 | |||
416 |
|
416 | |||
417 | class CohInt(Operation): |
|
417 | class CohInt(Operation): | |
418 |
|
418 | |||
419 | isConfig = False |
|
419 | isConfig = False | |
420 | __profIndex = 0 |
|
420 | __profIndex = 0 | |
421 | __byTime = False |
|
421 | __byTime = False | |
422 | __initime = None |
|
422 | __initime = None | |
423 | __lastdatatime = None |
|
423 | __lastdatatime = None | |
424 | __integrationtime = None |
|
424 | __integrationtime = None | |
425 | __buffer = None |
|
425 | __buffer = None | |
426 | __bufferStride = [] |
|
426 | __bufferStride = [] | |
427 | __dataReady = False |
|
427 | __dataReady = False | |
428 | __profIndexStride = 0 |
|
428 | __profIndexStride = 0 | |
429 | __dataToPutStride = False |
|
429 | __dataToPutStride = False | |
430 | n = None |
|
430 | n = None | |
431 |
|
431 | |||
432 | def __init__(self, **kwargs): |
|
432 | def __init__(self, **kwargs): | |
433 |
|
433 | |||
434 | Operation.__init__(self, **kwargs) |
|
434 | Operation.__init__(self, **kwargs) | |
435 |
|
435 | |||
436 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
436 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
437 | """ |
|
437 | """ | |
438 | Set the parameters of the integration class. |
|
438 | Set the parameters of the integration class. | |
439 |
|
439 | |||
440 | Inputs: |
|
440 | Inputs: | |
441 |
|
441 | |||
442 | n : Number of coherent integrations |
|
442 | n : Number of coherent integrations | |
443 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
443 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
444 | overlapping : |
|
444 | overlapping : | |
445 | """ |
|
445 | """ | |
446 |
|
446 | |||
447 | self.__initime = None |
|
447 | self.__initime = None | |
448 | self.__lastdatatime = 0 |
|
448 | self.__lastdatatime = 0 | |
449 | self.__buffer = None |
|
449 | self.__buffer = None | |
450 | self.__dataReady = False |
|
450 | self.__dataReady = False | |
451 | self.byblock = byblock |
|
451 | self.byblock = byblock | |
452 | self.stride = stride |
|
452 | self.stride = stride | |
453 |
|
453 | |||
454 | if n == None and timeInterval == None: |
|
454 | if n == None and timeInterval == None: | |
455 | raise ValueError("n or timeInterval should be specified ...") |
|
455 | raise ValueError("n or timeInterval should be specified ...") | |
456 |
|
456 | |||
457 | if n != None: |
|
457 | if n != None: | |
458 | self.n = n |
|
458 | self.n = n | |
459 | self.__byTime = False |
|
459 | self.__byTime = False | |
460 | else: |
|
460 | else: | |
461 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
461 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
462 | self.n = 9999 |
|
462 | self.n = 9999 | |
463 | self.__byTime = True |
|
463 | self.__byTime = True | |
464 |
|
464 | |||
465 | if overlapping: |
|
465 | if overlapping: | |
466 | self.__withOverlapping = True |
|
466 | self.__withOverlapping = True | |
467 | self.__buffer = None |
|
467 | self.__buffer = None | |
468 | else: |
|
468 | else: | |
469 | self.__withOverlapping = False |
|
469 | self.__withOverlapping = False | |
470 | self.__buffer = 0 |
|
470 | self.__buffer = 0 | |
471 |
|
471 | |||
472 | self.__profIndex = 0 |
|
472 | self.__profIndex = 0 | |
473 |
|
473 | |||
474 | def putData(self, data): |
|
474 | def putData(self, data): | |
475 |
|
475 | |||
476 | """ |
|
476 | """ | |
477 | Add a profile to the __buffer and increase in one the __profileIndex |
|
477 | Add a profile to the __buffer and increase in one the __profileIndex | |
478 |
|
478 | |||
479 | """ |
|
479 | """ | |
480 |
|
480 | |||
481 | if not self.__withOverlapping: |
|
481 | if not self.__withOverlapping: | |
482 | self.__buffer += data.copy() |
|
482 | self.__buffer += data.copy() | |
483 | self.__profIndex += 1 |
|
483 | self.__profIndex += 1 | |
484 | return |
|
484 | return | |
485 |
|
485 | |||
486 | #Overlapping data |
|
486 | #Overlapping data | |
487 | nChannels, nHeis = data.shape |
|
487 | nChannels, nHeis = data.shape | |
488 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
488 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
489 |
|
489 | |||
490 | #If the buffer is empty then it takes the data value |
|
490 | #If the buffer is empty then it takes the data value | |
491 | if self.__buffer is None: |
|
491 | if self.__buffer is None: | |
492 | self.__buffer = data |
|
492 | self.__buffer = data | |
493 | self.__profIndex += 1 |
|
493 | self.__profIndex += 1 | |
494 | return |
|
494 | return | |
495 |
|
495 | |||
496 | #If the buffer length is lower than n then stakcing the data value |
|
496 | #If the buffer length is lower than n then stakcing the data value | |
497 | if self.__profIndex < self.n: |
|
497 | if self.__profIndex < self.n: | |
498 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
498 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
499 | self.__profIndex += 1 |
|
499 | self.__profIndex += 1 | |
500 | return |
|
500 | return | |
501 |
|
501 | |||
502 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
502 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
503 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
503 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
504 | self.__buffer[self.n-1] = data |
|
504 | self.__buffer[self.n-1] = data | |
505 | self.__profIndex = self.n |
|
505 | self.__profIndex = self.n | |
506 | return |
|
506 | return | |
507 |
|
507 | |||
508 |
|
508 | |||
509 | def pushData(self): |
|
509 | def pushData(self): | |
510 | """ |
|
510 | """ | |
511 | Return the sum of the last profiles and the profiles used in the sum. |
|
511 | Return the sum of the last profiles and the profiles used in the sum. | |
512 |
|
512 | |||
513 | Affected: |
|
513 | Affected: | |
514 |
|
514 | |||
515 | self.__profileIndex |
|
515 | self.__profileIndex | |
516 |
|
516 | |||
517 | """ |
|
517 | """ | |
518 |
|
518 | |||
519 | if not self.__withOverlapping: |
|
519 | if not self.__withOverlapping: | |
520 | data = self.__buffer |
|
520 | data = self.__buffer | |
521 | n = self.__profIndex |
|
521 | n = self.__profIndex | |
522 |
|
522 | |||
523 | self.__buffer = 0 |
|
523 | self.__buffer = 0 | |
524 | self.__profIndex = 0 |
|
524 | self.__profIndex = 0 | |
525 |
|
525 | |||
526 | return data, n |
|
526 | return data, n | |
527 |
|
527 | |||
528 | #Integration with Overlapping |
|
528 | #Integration with Overlapping | |
529 | data = numpy.sum(self.__buffer, axis=0) |
|
529 | data = numpy.sum(self.__buffer, axis=0) | |
530 | # print data |
|
530 | # print data | |
531 | # raise |
|
531 | # raise | |
532 | n = self.__profIndex |
|
532 | n = self.__profIndex | |
533 |
|
533 | |||
534 | return data, n |
|
534 | return data, n | |
535 |
|
535 | |||
536 | def byProfiles(self, data): |
|
536 | def byProfiles(self, data): | |
537 |
|
537 | |||
538 | self.__dataReady = False |
|
538 | self.__dataReady = False | |
539 | avgdata = None |
|
539 | avgdata = None | |
540 | # n = None |
|
540 | # n = None | |
541 | # print data |
|
541 | # print data | |
542 | # raise |
|
542 | # raise | |
543 | self.putData(data) |
|
543 | self.putData(data) | |
544 |
|
544 | |||
545 | if self.__profIndex == self.n: |
|
545 | if self.__profIndex == self.n: | |
546 | avgdata, n = self.pushData() |
|
546 | avgdata, n = self.pushData() | |
547 | self.__dataReady = True |
|
547 | self.__dataReady = True | |
548 |
|
548 | |||
549 | return avgdata |
|
549 | return avgdata | |
550 |
|
550 | |||
551 | def byTime(self, data, datatime): |
|
551 | def byTime(self, data, datatime): | |
552 |
|
552 | |||
553 | self.__dataReady = False |
|
553 | self.__dataReady = False | |
554 | avgdata = None |
|
554 | avgdata = None | |
555 | n = None |
|
555 | n = None | |
556 |
|
556 | |||
557 | self.putData(data) |
|
557 | self.putData(data) | |
558 |
|
558 | |||
559 | if (datatime - self.__initime) >= self.__integrationtime: |
|
559 | if (datatime - self.__initime) >= self.__integrationtime: | |
560 | avgdata, n = self.pushData() |
|
560 | avgdata, n = self.pushData() | |
561 | self.n = n |
|
561 | self.n = n | |
562 | self.__dataReady = True |
|
562 | self.__dataReady = True | |
563 |
|
563 | |||
564 | return avgdata |
|
564 | return avgdata | |
565 |
|
565 | |||
566 | def integrateByStride(self, data, datatime): |
|
566 | def integrateByStride(self, data, datatime): | |
567 | # print data |
|
567 | # print data | |
568 | if self.__profIndex == 0: |
|
568 | if self.__profIndex == 0: | |
569 | self.__buffer = [[data.copy(), datatime]] |
|
569 | self.__buffer = [[data.copy(), datatime]] | |
570 | else: |
|
570 | else: | |
571 | self.__buffer.append([data.copy(),datatime]) |
|
571 | self.__buffer.append([data.copy(),datatime]) | |
572 | self.__profIndex += 1 |
|
572 | self.__profIndex += 1 | |
573 | self.__dataReady = False |
|
573 | self.__dataReady = False | |
574 |
|
574 | |||
575 | if self.__profIndex == self.n * self.stride : |
|
575 | if self.__profIndex == self.n * self.stride : | |
576 | self.__dataToPutStride = True |
|
576 | self.__dataToPutStride = True | |
577 | self.__profIndexStride = 0 |
|
577 | self.__profIndexStride = 0 | |
578 | self.__profIndex = 0 |
|
578 | self.__profIndex = 0 | |
579 | self.__bufferStride = [] |
|
579 | self.__bufferStride = [] | |
580 | for i in range(self.stride): |
|
580 | for i in range(self.stride): | |
581 | current = self.__buffer[i::self.stride] |
|
581 | current = self.__buffer[i::self.stride] | |
582 | data = numpy.sum([t[0] for t in current], axis=0) |
|
582 | data = numpy.sum([t[0] for t in current], axis=0) | |
583 | avgdatatime = numpy.average([t[1] for t in current]) |
|
583 | avgdatatime = numpy.average([t[1] for t in current]) | |
584 | # print data |
|
584 | # print data | |
585 | self.__bufferStride.append((data, avgdatatime)) |
|
585 | self.__bufferStride.append((data, avgdatatime)) | |
586 |
|
586 | |||
587 | if self.__dataToPutStride: |
|
587 | if self.__dataToPutStride: | |
588 | self.__dataReady = True |
|
588 | self.__dataReady = True | |
589 | self.__profIndexStride += 1 |
|
589 | self.__profIndexStride += 1 | |
590 | if self.__profIndexStride == self.stride: |
|
590 | if self.__profIndexStride == self.stride: | |
591 | self.__dataToPutStride = False |
|
591 | self.__dataToPutStride = False | |
592 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
592 | # print self.__bufferStride[self.__profIndexStride - 1] | |
593 | # raise |
|
593 | # raise | |
594 | return self.__bufferStride[self.__profIndexStride - 1] |
|
594 | return self.__bufferStride[self.__profIndexStride - 1] | |
595 |
|
595 | |||
596 |
|
596 | |||
597 | return None, None |
|
597 | return None, None | |
598 |
|
598 | |||
599 | def integrate(self, data, datatime=None): |
|
599 | def integrate(self, data, datatime=None): | |
600 |
|
600 | |||
601 | if self.__initime == None: |
|
601 | if self.__initime == None: | |
602 | self.__initime = datatime |
|
602 | self.__initime = datatime | |
603 |
|
603 | |||
604 | if self.__byTime: |
|
604 | if self.__byTime: | |
605 | avgdata = self.byTime(data, datatime) |
|
605 | avgdata = self.byTime(data, datatime) | |
606 | else: |
|
606 | else: | |
607 | avgdata = self.byProfiles(data) |
|
607 | avgdata = self.byProfiles(data) | |
608 |
|
608 | |||
609 |
|
609 | |||
610 | self.__lastdatatime = datatime |
|
610 | self.__lastdatatime = datatime | |
611 |
|
611 | |||
612 | if avgdata is None: |
|
612 | if avgdata is None: | |
613 | return None, None |
|
613 | return None, None | |
614 |
|
614 | |||
615 | avgdatatime = self.__initime |
|
615 | avgdatatime = self.__initime | |
616 |
|
616 | |||
617 | deltatime = datatime - self.__lastdatatime |
|
617 | deltatime = datatime - self.__lastdatatime | |
618 |
|
618 | |||
619 | if not self.__withOverlapping: |
|
619 | if not self.__withOverlapping: | |
620 | self.__initime = datatime |
|
620 | self.__initime = datatime | |
621 | else: |
|
621 | else: | |
622 | self.__initime += deltatime |
|
622 | self.__initime += deltatime | |
623 |
|
623 | |||
624 | return avgdata, avgdatatime |
|
624 | return avgdata, avgdatatime | |
625 |
|
625 | |||
626 | def integrateByBlock(self, dataOut): |
|
626 | def integrateByBlock(self, dataOut): | |
627 |
|
627 | |||
628 | times = int(dataOut.data.shape[1]/self.n) |
|
628 | times = int(dataOut.data.shape[1]/self.n) | |
629 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
629 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
630 |
|
630 | |||
631 | id_min = 0 |
|
631 | id_min = 0 | |
632 | id_max = self.n |
|
632 | id_max = self.n | |
633 |
|
633 | |||
634 | for i in range(times): |
|
634 | for i in range(times): | |
635 | junk = dataOut.data[:,id_min:id_max,:] |
|
635 | junk = dataOut.data[:,id_min:id_max,:] | |
636 | avgdata[:,i,:] = junk.sum(axis=1) |
|
636 | avgdata[:,i,:] = junk.sum(axis=1) | |
637 | id_min += self.n |
|
637 | id_min += self.n | |
638 | id_max += self.n |
|
638 | id_max += self.n | |
639 |
|
639 | |||
640 | timeInterval = dataOut.ippSeconds*self.n |
|
640 | timeInterval = dataOut.ippSeconds*self.n | |
641 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
641 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
642 | self.__dataReady = True |
|
642 | self.__dataReady = True | |
643 | return avgdata, avgdatatime |
|
643 | return avgdata, avgdatatime | |
644 |
|
644 | |||
645 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
645 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
646 |
|
646 | |||
647 | if not self.isConfig: |
|
647 | if not self.isConfig: | |
648 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
648 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
649 | self.isConfig = True |
|
649 | self.isConfig = True | |
650 |
|
650 | |||
651 | if dataOut.flagDataAsBlock: |
|
651 | if dataOut.flagDataAsBlock: | |
652 | """ |
|
652 | """ | |
653 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
653 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
654 | """ |
|
654 | """ | |
655 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
655 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
656 | dataOut.nProfiles /= self.n |
|
656 | dataOut.nProfiles /= self.n | |
657 | else: |
|
657 | else: | |
658 | if stride is None: |
|
658 | if stride is None: | |
659 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
659 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
660 | else: |
|
660 | else: | |
661 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
661 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
662 |
|
662 | |||
663 |
|
663 | |||
664 | # dataOut.timeInterval *= n |
|
664 | # dataOut.timeInterval *= n | |
665 | dataOut.flagNoData = True |
|
665 | dataOut.flagNoData = True | |
666 |
|
666 | |||
667 | if self.__dataReady: |
|
667 | if self.__dataReady: | |
668 | dataOut.data = avgdata |
|
668 | dataOut.data = avgdata | |
669 | if not dataOut.flagCohInt: |
|
669 | if not dataOut.flagCohInt: | |
670 | dataOut.nCohInt *= self.n |
|
670 | dataOut.nCohInt *= self.n | |
671 | dataOut.flagCohInt = True |
|
671 | dataOut.flagCohInt = True | |
672 | dataOut.utctime = avgdatatime |
|
672 | dataOut.utctime = avgdatatime | |
673 | # print avgdata, avgdatatime |
|
673 | # print avgdata, avgdatatime | |
674 | # raise |
|
674 | # raise | |
675 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
675 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
676 | dataOut.flagNoData = False |
|
676 | dataOut.flagNoData = False | |
677 | return dataOut |
|
677 | return dataOut | |
678 |
|
678 | |||
679 | class Decoder(Operation): |
|
679 | class Decoder(Operation): | |
680 |
|
680 | |||
681 | isConfig = False |
|
681 | isConfig = False | |
682 | __profIndex = 0 |
|
682 | __profIndex = 0 | |
683 |
|
683 | |||
684 | code = None |
|
684 | code = None | |
685 |
|
685 | |||
686 | nCode = None |
|
686 | nCode = None | |
687 | nBaud = None |
|
687 | nBaud = None | |
688 |
|
688 | |||
689 | def __init__(self, **kwargs): |
|
689 | def __init__(self, **kwargs): | |
690 |
|
690 | |||
691 | Operation.__init__(self, **kwargs) |
|
691 | Operation.__init__(self, **kwargs) | |
692 |
|
692 | |||
693 | self.times = None |
|
693 | self.times = None | |
694 | self.osamp = None |
|
694 | self.osamp = None | |
695 | # self.__setValues = False |
|
695 | # self.__setValues = False | |
696 | self.isConfig = False |
|
696 | self.isConfig = False | |
697 | self.setupReq = False |
|
697 | self.setupReq = False | |
698 | def setup(self, code, osamp, dataOut): |
|
698 | def setup(self, code, osamp, dataOut): | |
699 |
|
699 | |||
700 | self.__profIndex = 0 |
|
700 | self.__profIndex = 0 | |
701 |
|
701 | |||
702 | self.code = code |
|
702 | self.code = code | |
703 |
|
703 | |||
704 | self.nCode = len(code) |
|
704 | self.nCode = len(code) | |
705 | self.nBaud = len(code[0]) |
|
705 | self.nBaud = len(code[0]) | |
706 |
|
706 | |||
707 | if (osamp != None) and (osamp >1): |
|
707 | if (osamp != None) and (osamp >1): | |
708 | self.osamp = osamp |
|
708 | self.osamp = osamp | |
709 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
709 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
710 | self.nBaud = self.nBaud*self.osamp |
|
710 | self.nBaud = self.nBaud*self.osamp | |
711 |
|
711 | |||
712 | self.__nChannels = dataOut.nChannels |
|
712 | self.__nChannels = dataOut.nChannels | |
713 | self.__nProfiles = dataOut.nProfiles |
|
713 | self.__nProfiles = dataOut.nProfiles | |
714 | self.__nHeis = dataOut.nHeights |
|
714 | self.__nHeis = dataOut.nHeights | |
715 |
|
715 | |||
716 | if self.__nHeis < self.nBaud: |
|
716 | if self.__nHeis < self.nBaud: | |
717 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
717 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
718 |
|
718 | |||
719 | #Frequency |
|
719 | #Frequency | |
720 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
720 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
721 |
|
721 | |||
722 | __codeBuffer[:,0:self.nBaud] = self.code |
|
722 | __codeBuffer[:,0:self.nBaud] = self.code | |
723 |
|
723 | |||
724 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
724 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
725 |
|
725 | |||
726 | if dataOut.flagDataAsBlock: |
|
726 | if dataOut.flagDataAsBlock: | |
727 |
|
727 | |||
728 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
728 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
729 |
|
729 | |||
730 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
730 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
731 |
|
731 | |||
732 | else: |
|
732 | else: | |
733 |
|
733 | |||
734 | #Time |
|
734 | #Time | |
735 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
735 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
736 |
|
736 | |||
737 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
737 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
738 |
|
738 | |||
739 | def __convolutionInFreq(self, data): |
|
739 | def __convolutionInFreq(self, data): | |
740 |
|
740 | |||
741 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
741 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
742 |
|
742 | |||
743 | fft_data = numpy.fft.fft(data, axis=1) |
|
743 | fft_data = numpy.fft.fft(data, axis=1) | |
744 |
|
744 | |||
745 | conv = fft_data*fft_code |
|
745 | conv = fft_data*fft_code | |
746 |
|
746 | |||
747 | data = numpy.fft.ifft(conv,axis=1) |
|
747 | data = numpy.fft.ifft(conv,axis=1) | |
748 |
|
748 | |||
749 | return data |
|
749 | return data | |
750 |
|
750 | |||
751 | def __convolutionInFreqOpt(self, data): |
|
751 | def __convolutionInFreqOpt(self, data): | |
752 |
|
752 | |||
753 | raise NotImplementedError |
|
753 | raise NotImplementedError | |
754 |
|
754 | |||
755 | def __convolutionInTime(self, data): |
|
755 | def __convolutionInTime(self, data): | |
756 |
|
756 | |||
757 | code = self.code[self.__profIndex] |
|
757 | code = self.code[self.__profIndex] | |
758 | for i in range(self.__nChannels): |
|
758 | for i in range(self.__nChannels): | |
759 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
759 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
760 |
|
760 | |||
761 | return self.datadecTime |
|
761 | return self.datadecTime | |
762 |
|
762 | |||
763 | def __convolutionByBlockInTime(self, data): |
|
763 | def __convolutionByBlockInTime(self, data): | |
764 |
|
764 | |||
765 | repetitions = int(self.__nProfiles / self.nCode) |
|
765 | repetitions = int(self.__nProfiles / self.nCode) | |
766 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
766 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
767 | junk = junk.flatten() |
|
767 | junk = junk.flatten() | |
768 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
768 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
769 | profilesList = range(self.__nProfiles) |
|
769 | profilesList = range(self.__nProfiles) | |
770 |
|
770 | |||
771 | for i in range(self.__nChannels): |
|
771 | for i in range(self.__nChannels): | |
772 | for j in profilesList: |
|
772 | for j in profilesList: | |
773 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
773 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
774 | return self.datadecTime |
|
774 | return self.datadecTime | |
775 |
|
775 | |||
776 | def __convolutionByBlockInFreq(self, data): |
|
776 | def __convolutionByBlockInFreq(self, data): | |
777 |
|
777 | |||
778 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
778 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
779 |
|
779 | |||
780 |
|
780 | |||
781 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
781 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
782 |
|
782 | |||
783 | fft_data = numpy.fft.fft(data, axis=2) |
|
783 | fft_data = numpy.fft.fft(data, axis=2) | |
784 |
|
784 | |||
785 | conv = fft_data*fft_code |
|
785 | conv = fft_data*fft_code | |
786 |
|
786 | |||
787 | data = numpy.fft.ifft(conv,axis=2) |
|
787 | data = numpy.fft.ifft(conv,axis=2) | |
788 |
|
788 | |||
789 | return data |
|
789 | return data | |
790 |
|
790 | |||
791 |
|
791 | |||
792 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
792 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
793 |
|
793 | |||
794 | if dataOut.flagDecodeData: |
|
794 | if dataOut.flagDecodeData: | |
795 | print("This data is already decoded, recoding again ...") |
|
795 | print("This data is already decoded, recoding again ...") | |
796 |
|
796 | |||
797 | if not self.isConfig: |
|
797 | if not self.isConfig: | |
798 |
|
798 | |||
799 | if code is None: |
|
799 | if code is None: | |
800 | if dataOut.code is None: |
|
800 | if dataOut.code is None: | |
801 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
801 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
802 |
|
802 | |||
803 | code = dataOut.code |
|
803 | code = dataOut.code | |
804 | else: |
|
804 | else: | |
805 | code = numpy.array(code).reshape(nCode,nBaud) |
|
805 | code = numpy.array(code).reshape(nCode,nBaud) | |
806 | self.setup(code, osamp, dataOut) |
|
806 | self.setup(code, osamp, dataOut) | |
807 |
|
807 | |||
808 | self.isConfig = True |
|
808 | self.isConfig = True | |
809 |
|
809 | |||
810 | if mode == 3: |
|
810 | if mode == 3: | |
811 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
811 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
812 |
|
812 | |||
813 | if times != None: |
|
813 | if times != None: | |
814 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
814 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
815 |
|
815 | |||
816 | if self.code is None: |
|
816 | if self.code is None: | |
817 | print("Fail decoding: Code is not defined.") |
|
817 | print("Fail decoding: Code is not defined.") | |
818 | return |
|
818 | return | |
819 |
|
819 | |||
820 | self.__nProfiles = dataOut.nProfiles |
|
820 | self.__nProfiles = dataOut.nProfiles | |
821 | datadec = None |
|
821 | datadec = None | |
822 |
|
822 | |||
823 | if mode == 3: |
|
823 | if mode == 3: | |
824 | mode = 0 |
|
824 | mode = 0 | |
825 |
|
825 | |||
826 | if dataOut.flagDataAsBlock: |
|
826 | if dataOut.flagDataAsBlock: | |
827 | """ |
|
827 | """ | |
828 | Decoding when data have been read as block, |
|
828 | Decoding when data have been read as block, | |
829 | """ |
|
829 | """ | |
830 |
|
830 | |||
831 | if mode == 0: |
|
831 | if mode == 0: | |
832 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
832 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
833 | if mode == 1: |
|
833 | if mode == 1: | |
834 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
834 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
835 | else: |
|
835 | else: | |
836 | """ |
|
836 | """ | |
837 | Decoding when data have been read profile by profile |
|
837 | Decoding when data have been read profile by profile | |
838 | """ |
|
838 | """ | |
839 | if mode == 0: |
|
839 | if mode == 0: | |
840 | datadec = self.__convolutionInTime(dataOut.data) |
|
840 | datadec = self.__convolutionInTime(dataOut.data) | |
841 |
|
841 | |||
842 | if mode == 1: |
|
842 | if mode == 1: | |
843 | datadec = self.__convolutionInFreq(dataOut.data) |
|
843 | datadec = self.__convolutionInFreq(dataOut.data) | |
844 |
|
844 | |||
845 | if mode == 2: |
|
845 | if mode == 2: | |
846 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
846 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
847 |
|
847 | |||
848 | if datadec is None: |
|
848 | if datadec is None: | |
849 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
849 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
850 |
|
850 | |||
851 | dataOut.code = self.code |
|
851 | dataOut.code = self.code | |
852 | dataOut.nCode = self.nCode |
|
852 | dataOut.nCode = self.nCode | |
853 | dataOut.nBaud = self.nBaud |
|
853 | dataOut.nBaud = self.nBaud | |
854 |
|
854 | |||
855 | dataOut.data = datadec |
|
855 | dataOut.data = datadec | |
856 |
|
856 | |||
857 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
857 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
858 |
|
858 | |||
859 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
859 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
860 |
|
860 | |||
861 | if self.__profIndex == self.nCode-1: |
|
861 | if self.__profIndex == self.nCode-1: | |
862 | self.__profIndex = 0 |
|
862 | self.__profIndex = 0 | |
863 | return dataOut |
|
863 | return dataOut | |
864 |
|
864 | |||
865 | self.__profIndex += 1 |
|
865 | self.__profIndex += 1 | |
866 |
|
866 | |||
867 | return dataOut |
|
867 | return dataOut | |
868 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
868 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
869 |
|
869 | |||
870 |
|
870 | |||
871 | class ProfileConcat(Operation): |
|
871 | class ProfileConcat(Operation): | |
872 |
|
872 | |||
873 | isConfig = False |
|
873 | isConfig = False | |
874 | buffer = None |
|
874 | buffer = None | |
875 |
|
875 | |||
876 | def __init__(self, **kwargs): |
|
876 | def __init__(self, **kwargs): | |
877 |
|
877 | |||
878 | Operation.__init__(self, **kwargs) |
|
878 | Operation.__init__(self, **kwargs) | |
879 | self.profileIndex = 0 |
|
879 | self.profileIndex = 0 | |
880 |
|
880 | |||
881 | def reset(self): |
|
881 | def reset(self): | |
882 | self.buffer = numpy.zeros_like(self.buffer) |
|
882 | self.buffer = numpy.zeros_like(self.buffer) | |
883 | self.start_index = 0 |
|
883 | self.start_index = 0 | |
884 | self.times = 1 |
|
884 | self.times = 1 | |
885 |
|
885 | |||
886 | def setup(self, data, m, n=1): |
|
886 | def setup(self, data, m, n=1): | |
887 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
887 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
888 | self.nHeights = data.shape[1]#.nHeights |
|
888 | self.nHeights = data.shape[1]#.nHeights | |
889 | self.start_index = 0 |
|
889 | self.start_index = 0 | |
890 | self.times = 1 |
|
890 | self.times = 1 | |
891 |
|
891 | |||
892 | def concat(self, data): |
|
892 | def concat(self, data): | |
893 |
|
893 | |||
894 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
894 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
895 | self.start_index = self.start_index + self.nHeights |
|
895 | self.start_index = self.start_index + self.nHeights | |
896 |
|
896 | |||
897 | def run(self, dataOut, m): |
|
897 | def run(self, dataOut, m): | |
898 | dataOut.flagNoData = True |
|
898 | dataOut.flagNoData = True | |
899 |
|
899 | |||
900 | if not self.isConfig: |
|
900 | if not self.isConfig: | |
901 | self.setup(dataOut.data, m, 1) |
|
901 | self.setup(dataOut.data, m, 1) | |
902 | self.isConfig = True |
|
902 | self.isConfig = True | |
903 |
|
903 | |||
904 | if dataOut.flagDataAsBlock: |
|
904 | if dataOut.flagDataAsBlock: | |
905 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
905 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
906 |
|
906 | |||
907 | else: |
|
907 | else: | |
908 | self.concat(dataOut.data) |
|
908 | self.concat(dataOut.data) | |
909 | self.times += 1 |
|
909 | self.times += 1 | |
910 | if self.times > m: |
|
910 | if self.times > m: | |
911 | dataOut.data = self.buffer |
|
911 | dataOut.data = self.buffer | |
912 | self.reset() |
|
912 | self.reset() | |
913 | dataOut.flagNoData = False |
|
913 | dataOut.flagNoData = False | |
914 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
914 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
915 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
915 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
916 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
916 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
917 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
917 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
918 | dataOut.ippSeconds *= m |
|
918 | dataOut.ippSeconds *= m | |
919 | return dataOut |
|
919 | return dataOut | |
920 |
|
920 | |||
921 | class ProfileSelector(Operation): |
|
921 | class ProfileSelector(Operation): | |
922 |
|
922 | |||
923 | profileIndex = None |
|
923 | profileIndex = None | |
924 | # Tamanho total de los perfiles |
|
924 | # Tamanho total de los perfiles | |
925 | nProfiles = None |
|
925 | nProfiles = None | |
926 |
|
926 | |||
927 | def __init__(self, **kwargs): |
|
927 | def __init__(self, **kwargs): | |
928 |
|
928 | |||
929 | Operation.__init__(self, **kwargs) |
|
929 | Operation.__init__(self, **kwargs) | |
930 | self.profileIndex = 0 |
|
930 | self.profileIndex = 0 | |
931 |
|
931 | |||
932 | def incProfileIndex(self): |
|
932 | def incProfileIndex(self): | |
933 |
|
933 | |||
934 | self.profileIndex += 1 |
|
934 | self.profileIndex += 1 | |
935 |
|
935 | |||
936 | if self.profileIndex >= self.nProfiles: |
|
936 | if self.profileIndex >= self.nProfiles: | |
937 | self.profileIndex = 0 |
|
937 | self.profileIndex = 0 | |
938 |
|
938 | |||
939 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
939 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
940 |
|
940 | |||
941 | if profileIndex < minIndex: |
|
941 | if profileIndex < minIndex: | |
942 | return False |
|
942 | return False | |
943 |
|
943 | |||
944 | if profileIndex > maxIndex: |
|
944 | if profileIndex > maxIndex: | |
945 | return False |
|
945 | return False | |
946 |
|
946 | |||
947 | return True |
|
947 | return True | |
948 |
|
948 | |||
949 | def isThisProfileInList(self, profileIndex, profileList): |
|
949 | def isThisProfileInList(self, profileIndex, profileList): | |
950 |
|
950 | |||
951 | if profileIndex not in profileList: |
|
951 | if profileIndex not in profileList: | |
952 | return False |
|
952 | return False | |
953 |
|
953 | |||
954 | return True |
|
954 | return True | |
955 |
|
955 | |||
956 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
956 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
957 |
|
957 | |||
958 | """ |
|
958 | """ | |
959 | ProfileSelector: |
|
959 | ProfileSelector: | |
960 |
|
960 | |||
961 | Inputs: |
|
961 | Inputs: | |
962 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
962 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
963 |
|
963 | |||
964 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
964 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
965 |
|
965 | |||
966 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
966 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
967 |
|
967 | |||
968 | """ |
|
968 | """ | |
969 |
|
969 | |||
970 | if rangeList is not None: |
|
970 | if rangeList is not None: | |
971 | if type(rangeList[0]) not in (tuple, list): |
|
971 | if type(rangeList[0]) not in (tuple, list): | |
972 | rangeList = [rangeList] |
|
972 | rangeList = [rangeList] | |
973 |
|
973 | |||
974 | dataOut.flagNoData = True |
|
974 | dataOut.flagNoData = True | |
975 |
|
975 | |||
976 | if dataOut.flagDataAsBlock: |
|
976 | if dataOut.flagDataAsBlock: | |
977 | """ |
|
977 | """ | |
978 | data dimension = [nChannels, nProfiles, nHeis] |
|
978 | data dimension = [nChannels, nProfiles, nHeis] | |
979 | """ |
|
979 | """ | |
980 | if profileList != None: |
|
980 | if profileList != None: | |
981 | dataOut.data = dataOut.data[:,profileList,:] |
|
981 | dataOut.data = dataOut.data[:,profileList,:] | |
982 |
|
982 | |||
983 | if profileRangeList != None: |
|
983 | if profileRangeList != None: | |
984 | minIndex = profileRangeList[0] |
|
984 | minIndex = profileRangeList[0] | |
985 | maxIndex = profileRangeList[1] |
|
985 | maxIndex = profileRangeList[1] | |
986 | profileList = list(range(minIndex, maxIndex+1)) |
|
986 | profileList = list(range(minIndex, maxIndex+1)) | |
987 |
|
987 | |||
988 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
988 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
989 |
|
989 | |||
990 | if rangeList != None: |
|
990 | if rangeList != None: | |
991 |
|
991 | |||
992 | profileList = [] |
|
992 | profileList = [] | |
993 |
|
993 | |||
994 | for thisRange in rangeList: |
|
994 | for thisRange in rangeList: | |
995 | minIndex = thisRange[0] |
|
995 | minIndex = thisRange[0] | |
996 | maxIndex = thisRange[1] |
|
996 | maxIndex = thisRange[1] | |
997 |
|
997 | |||
998 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
998 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
999 |
|
999 | |||
1000 | dataOut.data = dataOut.data[:,profileList,:] |
|
1000 | dataOut.data = dataOut.data[:,profileList,:] | |
1001 |
|
1001 | |||
1002 | dataOut.nProfiles = len(profileList) |
|
1002 | dataOut.nProfiles = len(profileList) | |
1003 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
1003 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
1004 | dataOut.flagNoData = False |
|
1004 | dataOut.flagNoData = False | |
1005 |
|
1005 | |||
1006 | return dataOut |
|
1006 | return dataOut | |
1007 |
|
1007 | |||
1008 | """ |
|
1008 | """ | |
1009 | data dimension = [nChannels, nHeis] |
|
1009 | data dimension = [nChannels, nHeis] | |
1010 | """ |
|
1010 | """ | |
1011 |
|
1011 | |||
1012 | if profileList != None: |
|
1012 | if profileList != None: | |
1013 |
|
1013 | |||
1014 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1014 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
1015 |
|
1015 | |||
1016 | self.nProfiles = len(profileList) |
|
1016 | self.nProfiles = len(profileList) | |
1017 | dataOut.nProfiles = self.nProfiles |
|
1017 | dataOut.nProfiles = self.nProfiles | |
1018 | dataOut.profileIndex = self.profileIndex |
|
1018 | dataOut.profileIndex = self.profileIndex | |
1019 | dataOut.flagNoData = False |
|
1019 | dataOut.flagNoData = False | |
1020 |
|
1020 | |||
1021 | self.incProfileIndex() |
|
1021 | self.incProfileIndex() | |
1022 | return dataOut |
|
1022 | return dataOut | |
1023 |
|
1023 | |||
1024 | if profileRangeList != None: |
|
1024 | if profileRangeList != None: | |
1025 |
|
1025 | |||
1026 | minIndex = profileRangeList[0] |
|
1026 | minIndex = profileRangeList[0] | |
1027 | maxIndex = profileRangeList[1] |
|
1027 | maxIndex = profileRangeList[1] | |
1028 |
|
1028 | |||
1029 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1029 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1030 |
|
1030 | |||
1031 | self.nProfiles = maxIndex - minIndex + 1 |
|
1031 | self.nProfiles = maxIndex - minIndex + 1 | |
1032 | dataOut.nProfiles = self.nProfiles |
|
1032 | dataOut.nProfiles = self.nProfiles | |
1033 | dataOut.profileIndex = self.profileIndex |
|
1033 | dataOut.profileIndex = self.profileIndex | |
1034 | dataOut.flagNoData = False |
|
1034 | dataOut.flagNoData = False | |
1035 |
|
1035 | |||
1036 | self.incProfileIndex() |
|
1036 | self.incProfileIndex() | |
1037 | return dataOut |
|
1037 | return dataOut | |
1038 |
|
1038 | |||
1039 | if rangeList != None: |
|
1039 | if rangeList != None: | |
1040 |
|
1040 | |||
1041 | nProfiles = 0 |
|
1041 | nProfiles = 0 | |
1042 |
|
1042 | |||
1043 | for thisRange in rangeList: |
|
1043 | for thisRange in rangeList: | |
1044 | minIndex = thisRange[0] |
|
1044 | minIndex = thisRange[0] | |
1045 | maxIndex = thisRange[1] |
|
1045 | maxIndex = thisRange[1] | |
1046 |
|
1046 | |||
1047 | nProfiles += maxIndex - minIndex + 1 |
|
1047 | nProfiles += maxIndex - minIndex + 1 | |
1048 |
|
1048 | |||
1049 | for thisRange in rangeList: |
|
1049 | for thisRange in rangeList: | |
1050 |
|
1050 | |||
1051 | minIndex = thisRange[0] |
|
1051 | minIndex = thisRange[0] | |
1052 | maxIndex = thisRange[1] |
|
1052 | maxIndex = thisRange[1] | |
1053 |
|
1053 | |||
1054 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1054 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1055 |
|
1055 | |||
1056 | self.nProfiles = nProfiles |
|
1056 | self.nProfiles = nProfiles | |
1057 | dataOut.nProfiles = self.nProfiles |
|
1057 | dataOut.nProfiles = self.nProfiles | |
1058 | dataOut.profileIndex = self.profileIndex |
|
1058 | dataOut.profileIndex = self.profileIndex | |
1059 | dataOut.flagNoData = False |
|
1059 | dataOut.flagNoData = False | |
1060 |
|
1060 | |||
1061 | self.incProfileIndex() |
|
1061 | self.incProfileIndex() | |
1062 |
|
1062 | |||
1063 | break |
|
1063 | break | |
1064 |
|
1064 | |||
1065 | return dataOut |
|
1065 | return dataOut | |
1066 |
|
1066 | |||
1067 |
|
1067 | |||
1068 | if beam != None: #beam is only for AMISR data |
|
1068 | if beam != None: #beam is only for AMISR data | |
1069 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1069 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
1070 | dataOut.flagNoData = False |
|
1070 | dataOut.flagNoData = False | |
1071 | dataOut.profileIndex = self.profileIndex |
|
1071 | dataOut.profileIndex = self.profileIndex | |
1072 |
|
1072 | |||
1073 | self.incProfileIndex() |
|
1073 | self.incProfileIndex() | |
1074 |
|
1074 | |||
1075 | return dataOut |
|
1075 | return dataOut | |
1076 |
|
1076 | |||
1077 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1077 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
1078 |
|
1078 | |||
1079 |
|
1079 | |||
1080 | class Reshaper(Operation): |
|
1080 | class Reshaper(Operation): | |
1081 |
|
1081 | |||
1082 | def __init__(self, **kwargs): |
|
1082 | def __init__(self, **kwargs): | |
1083 |
|
1083 | |||
1084 | Operation.__init__(self, **kwargs) |
|
1084 | Operation.__init__(self, **kwargs) | |
1085 |
|
1085 | |||
1086 | self.__buffer = None |
|
1086 | self.__buffer = None | |
1087 | self.__nitems = 0 |
|
1087 | self.__nitems = 0 | |
1088 |
|
1088 | |||
1089 | def __appendProfile(self, dataOut, nTxs): |
|
1089 | def __appendProfile(self, dataOut, nTxs): | |
1090 |
|
1090 | |||
1091 | if self.__buffer is None: |
|
1091 | if self.__buffer is None: | |
1092 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1092 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
1093 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1093 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
1094 |
|
1094 | |||
1095 | ini = dataOut.nHeights * self.__nitems |
|
1095 | ini = dataOut.nHeights * self.__nitems | |
1096 | end = ini + dataOut.nHeights |
|
1096 | end = ini + dataOut.nHeights | |
1097 |
|
1097 | |||
1098 | self.__buffer[:, ini:end] = dataOut.data |
|
1098 | self.__buffer[:, ini:end] = dataOut.data | |
1099 |
|
1099 | |||
1100 | self.__nitems += 1 |
|
1100 | self.__nitems += 1 | |
1101 |
|
1101 | |||
1102 | return int(self.__nitems*nTxs) |
|
1102 | return int(self.__nitems*nTxs) | |
1103 |
|
1103 | |||
1104 | def __getBuffer(self): |
|
1104 | def __getBuffer(self): | |
1105 |
|
1105 | |||
1106 | if self.__nitems == int(1./self.__nTxs): |
|
1106 | if self.__nitems == int(1./self.__nTxs): | |
1107 |
|
1107 | |||
1108 | self.__nitems = 0 |
|
1108 | self.__nitems = 0 | |
1109 |
|
1109 | |||
1110 | return self.__buffer.copy() |
|
1110 | return self.__buffer.copy() | |
1111 |
|
1111 | |||
1112 | return None |
|
1112 | return None | |
1113 |
|
1113 | |||
1114 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1114 | def __checkInputs(self, dataOut, shape, nTxs): | |
1115 |
|
1115 | |||
1116 | if shape is None and nTxs is None: |
|
1116 | if shape is None and nTxs is None: | |
1117 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1117 | raise ValueError("Reshaper: shape of factor should be defined") | |
1118 |
|
1118 | |||
1119 | if nTxs: |
|
1119 | if nTxs: | |
1120 | if nTxs < 0: |
|
1120 | if nTxs < 0: | |
1121 | raise ValueError("nTxs should be greater than 0") |
|
1121 | raise ValueError("nTxs should be greater than 0") | |
1122 |
|
1122 | |||
1123 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1123 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1124 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1124 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
1125 |
|
1125 | |||
1126 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1126 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1127 |
|
1127 | |||
1128 | return shape, nTxs |
|
1128 | return shape, nTxs | |
1129 |
|
1129 | |||
1130 | if len(shape) != 2 and len(shape) != 3: |
|
1130 | if len(shape) != 2 and len(shape) != 3: | |
1131 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) |
|
1131 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) | |
1132 |
|
1132 | |||
1133 | if len(shape) == 2: |
|
1133 | if len(shape) == 2: | |
1134 | shape_tuple = [dataOut.nChannels] |
|
1134 | shape_tuple = [dataOut.nChannels] | |
1135 | shape_tuple.extend(shape) |
|
1135 | shape_tuple.extend(shape) | |
1136 | else: |
|
1136 | else: | |
1137 | shape_tuple = list(shape) |
|
1137 | shape_tuple = list(shape) | |
1138 |
|
1138 | |||
1139 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1139 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1140 |
|
1140 | |||
1141 | return shape_tuple, nTxs |
|
1141 | return shape_tuple, nTxs | |
1142 |
|
1142 | |||
1143 | def run(self, dataOut, shape=None, nTxs=None): |
|
1143 | def run(self, dataOut, shape=None, nTxs=None): | |
1144 |
|
1144 | |||
1145 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1145 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1146 |
|
1146 | |||
1147 | dataOut.flagNoData = True |
|
1147 | dataOut.flagNoData = True | |
1148 | profileIndex = None |
|
1148 | profileIndex = None | |
1149 |
|
1149 | |||
1150 | if dataOut.flagDataAsBlock: |
|
1150 | if dataOut.flagDataAsBlock: | |
1151 |
|
1151 | |||
1152 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1152 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1153 | dataOut.flagNoData = False |
|
1153 | dataOut.flagNoData = False | |
1154 |
|
1154 | |||
1155 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1155 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1156 |
|
1156 | |||
1157 | else: |
|
1157 | else: | |
1158 |
|
1158 | |||
1159 | if self.__nTxs < 1: |
|
1159 | if self.__nTxs < 1: | |
1160 |
|
1160 | |||
1161 | self.__appendProfile(dataOut, self.__nTxs) |
|
1161 | self.__appendProfile(dataOut, self.__nTxs) | |
1162 | new_data = self.__getBuffer() |
|
1162 | new_data = self.__getBuffer() | |
1163 |
|
1163 | |||
1164 | if new_data is not None: |
|
1164 | if new_data is not None: | |
1165 | dataOut.data = new_data |
|
1165 | dataOut.data = new_data | |
1166 | dataOut.flagNoData = False |
|
1166 | dataOut.flagNoData = False | |
1167 |
|
1167 | |||
1168 | profileIndex = dataOut.profileIndex*nTxs |
|
1168 | profileIndex = dataOut.profileIndex*nTxs | |
1169 |
|
1169 | |||
1170 | else: |
|
1170 | else: | |
1171 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1171 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
1172 |
|
1172 | |||
1173 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1173 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1174 |
|
1174 | |||
1175 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1175 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1176 |
|
1176 | |||
1177 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1177 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1178 |
|
1178 | |||
1179 | dataOut.profileIndex = profileIndex |
|
1179 | dataOut.profileIndex = profileIndex | |
1180 |
|
1180 | |||
1181 | dataOut.ippSeconds /= self.__nTxs |
|
1181 | dataOut.ippSeconds /= self.__nTxs | |
1182 |
|
1182 | |||
1183 | return dataOut |
|
1183 | return dataOut | |
1184 |
|
1184 | |||
1185 | class SplitProfiles(Operation): |
|
1185 | class SplitProfiles(Operation): | |
1186 |
|
1186 | |||
1187 | def __init__(self, **kwargs): |
|
1187 | def __init__(self, **kwargs): | |
1188 |
|
1188 | |||
1189 | Operation.__init__(self, **kwargs) |
|
1189 | Operation.__init__(self, **kwargs) | |
1190 |
|
1190 | |||
1191 | def run(self, dataOut, n): |
|
1191 | def run(self, dataOut, n): | |
1192 |
|
1192 | |||
1193 | dataOut.flagNoData = True |
|
1193 | dataOut.flagNoData = True | |
1194 | profileIndex = None |
|
1194 | profileIndex = None | |
1195 |
|
1195 | |||
1196 | if dataOut.flagDataAsBlock: |
|
1196 | if dataOut.flagDataAsBlock: | |
1197 |
|
1197 | |||
1198 | #nchannels, nprofiles, nsamples |
|
1198 | #nchannels, nprofiles, nsamples | |
1199 | shape = dataOut.data.shape |
|
1199 | shape = dataOut.data.shape | |
1200 |
|
1200 | |||
1201 | if shape[2] % n != 0: |
|
1201 | if shape[2] % n != 0: | |
1202 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1202 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
1203 |
|
1203 | |||
1204 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1204 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
1205 |
|
1205 | |||
1206 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1206 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1207 | dataOut.flagNoData = False |
|
1207 | dataOut.flagNoData = False | |
1208 |
|
1208 | |||
1209 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1209 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1210 |
|
1210 | |||
1211 | else: |
|
1211 | else: | |
1212 |
|
1212 | |||
1213 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1213 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
1214 |
|
1214 | |||
1215 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1215 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1216 |
|
1216 | |||
1217 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1217 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1218 |
|
1218 | |||
1219 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1219 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1220 |
|
1220 | |||
1221 | dataOut.profileIndex = profileIndex |
|
1221 | dataOut.profileIndex = profileIndex | |
1222 |
|
1222 | |||
1223 | dataOut.ippSeconds /= n |
|
1223 | dataOut.ippSeconds /= n | |
1224 |
|
1224 | |||
1225 | return dataOut |
|
1225 | return dataOut | |
1226 |
|
1226 | |||
1227 | class CombineProfiles(Operation): |
|
1227 | class CombineProfiles(Operation): | |
1228 | def __init__(self, **kwargs): |
|
1228 | def __init__(self, **kwargs): | |
1229 |
|
1229 | |||
1230 | Operation.__init__(self, **kwargs) |
|
1230 | Operation.__init__(self, **kwargs) | |
1231 |
|
1231 | |||
1232 | self.__remData = None |
|
1232 | self.__remData = None | |
1233 | self.__profileIndex = 0 |
|
1233 | self.__profileIndex = 0 | |
1234 |
|
1234 | |||
1235 | def run(self, dataOut, n): |
|
1235 | def run(self, dataOut, n): | |
1236 |
|
1236 | |||
1237 | dataOut.flagNoData = True |
|
1237 | dataOut.flagNoData = True | |
1238 | profileIndex = None |
|
1238 | profileIndex = None | |
1239 |
|
1239 | |||
1240 | if dataOut.flagDataAsBlock: |
|
1240 | if dataOut.flagDataAsBlock: | |
1241 |
|
1241 | |||
1242 | #nchannels, nprofiles, nsamples |
|
1242 | #nchannels, nprofiles, nsamples | |
1243 | shape = dataOut.data.shape |
|
1243 | shape = dataOut.data.shape | |
1244 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1244 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1245 |
|
1245 | |||
1246 | if shape[1] % n != 0: |
|
1246 | if shape[1] % n != 0: | |
1247 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1247 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
1248 |
|
1248 | |||
1249 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1249 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1250 | dataOut.flagNoData = False |
|
1250 | dataOut.flagNoData = False | |
1251 |
|
1251 | |||
1252 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1252 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1253 |
|
1253 | |||
1254 | else: |
|
1254 | else: | |
1255 |
|
1255 | |||
1256 | #nchannels, nsamples |
|
1256 | #nchannels, nsamples | |
1257 | if self.__remData is None: |
|
1257 | if self.__remData is None: | |
1258 | newData = dataOut.data |
|
1258 | newData = dataOut.data | |
1259 | else: |
|
1259 | else: | |
1260 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1260 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1261 |
|
1261 | |||
1262 | self.__profileIndex += 1 |
|
1262 | self.__profileIndex += 1 | |
1263 |
|
1263 | |||
1264 | if self.__profileIndex < n: |
|
1264 | if self.__profileIndex < n: | |
1265 | self.__remData = newData |
|
1265 | self.__remData = newData | |
1266 | #continue |
|
1266 | #continue | |
1267 | return |
|
1267 | return | |
1268 |
|
1268 | |||
1269 | self.__profileIndex = 0 |
|
1269 | self.__profileIndex = 0 | |
1270 | self.__remData = None |
|
1270 | self.__remData = None | |
1271 |
|
1271 | |||
1272 | dataOut.data = newData |
|
1272 | dataOut.data = newData | |
1273 | dataOut.flagNoData = False |
|
1273 | dataOut.flagNoData = False | |
1274 |
|
1274 | |||
1275 | profileIndex = dataOut.profileIndex/n |
|
1275 | profileIndex = dataOut.profileIndex/n | |
1276 |
|
1276 | |||
1277 |
|
1277 | |||
1278 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1278 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1279 |
|
1279 | |||
1280 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1280 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1281 |
|
1281 | |||
1282 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1282 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1283 |
|
1283 | |||
1284 | dataOut.profileIndex = profileIndex |
|
1284 | dataOut.profileIndex = profileIndex | |
1285 |
|
1285 | |||
1286 | dataOut.ippSeconds *= n |
|
1286 | dataOut.ippSeconds *= n | |
1287 |
|
1287 | |||
1288 | return dataOut |
|
1288 | return dataOut | |
1289 |
|
1289 | |||
1290 | class PulsePair(Operation): |
|
1290 | class PulsePair(Operation): | |
1291 | ''' |
|
1291 | ''' | |
1292 | Function PulsePair(Signal Power, Velocity) |
|
1292 | Function PulsePair(Signal Power, Velocity) | |
1293 | The real component of Lag[0] provides Intensity Information |
|
1293 | The real component of Lag[0] provides Intensity Information | |
1294 | The imag component of Lag[1] Phase provides Velocity Information |
|
1294 | The imag component of Lag[1] Phase provides Velocity Information | |
1295 |
|
1295 | |||
1296 | Configuration Parameters: |
|
1296 | Configuration Parameters: | |
1297 | nPRF = Number of Several PRF |
|
1297 | nPRF = Number of Several PRF | |
1298 | theta = Degree Azimuth angel Boundaries |
|
1298 | theta = Degree Azimuth angel Boundaries | |
1299 |
|
1299 | |||
1300 | Input: |
|
1300 | Input: | |
1301 | self.dataOut |
|
1301 | self.dataOut | |
1302 | lag[N] |
|
1302 | lag[N] | |
1303 | Affected: |
|
1303 | Affected: | |
1304 | self.dataOut.spc |
|
1304 | self.dataOut.spc | |
1305 | ''' |
|
1305 | ''' | |
1306 | isConfig = False |
|
1306 | isConfig = False | |
1307 | __profIndex = 0 |
|
1307 | __profIndex = 0 | |
1308 | __initime = None |
|
1308 | __initime = None | |
1309 | __lastdatatime = None |
|
1309 | __lastdatatime = None | |
1310 | __buffer = None |
|
1310 | __buffer = None | |
1311 | noise = None |
|
1311 | noise = None | |
1312 | __dataReady = False |
|
1312 | __dataReady = False | |
1313 | n = None |
|
1313 | n = None | |
1314 | __nch = 0 |
|
1314 | __nch = 0 | |
1315 | __nHeis = 0 |
|
1315 | __nHeis = 0 | |
1316 | removeDC = False |
|
1316 | removeDC = False | |
1317 | ipp = None |
|
1317 | ipp = None | |
1318 | lambda_ = 0 |
|
1318 | lambda_ = 0 | |
1319 |
|
1319 | |||
1320 | def __init__(self,**kwargs): |
|
1320 | def __init__(self,**kwargs): | |
1321 | Operation.__init__(self,**kwargs) |
|
1321 | Operation.__init__(self,**kwargs) | |
1322 |
|
1322 | |||
1323 | def setup(self, dataOut, n = None, removeDC=False): |
|
1323 | def setup(self, dataOut, n = None, removeDC=False): | |
1324 | ''' |
|
1324 | ''' | |
1325 | n= Numero de PRF's de entrada |
|
1325 | n= Numero de PRF's de entrada | |
1326 | ''' |
|
1326 | ''' | |
1327 | self.__initime = None |
|
1327 | self.__initime = None | |
1328 | ####print("[INICIO]-setup del METODO PULSE PAIR") |
|
1328 | ####print("[INICIO]-setup del METODO PULSE PAIR") | |
1329 | self.__lastdatatime = 0 |
|
1329 | self.__lastdatatime = 0 | |
1330 | self.__dataReady = False |
|
1330 | self.__dataReady = False | |
1331 | self.__buffer = 0 |
|
1331 | self.__buffer = 0 | |
1332 | self.__profIndex = 0 |
|
1332 | self.__profIndex = 0 | |
1333 | self.noise = None |
|
1333 | self.noise = None | |
1334 | self.__nch = dataOut.nChannels |
|
1334 | self.__nch = dataOut.nChannels | |
1335 | self.__nHeis = dataOut.nHeights |
|
1335 | self.__nHeis = dataOut.nHeights | |
1336 | self.removeDC = removeDC |
|
1336 | self.removeDC = removeDC | |
1337 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1337 | self.lambda_ = 3.0e8/(9345.0e6) | |
1338 | self.ippSec = dataOut.ippSeconds |
|
1338 | self.ippSec = dataOut.ippSeconds | |
1339 | self.nCohInt = dataOut.nCohInt |
|
1339 | self.nCohInt = dataOut.nCohInt | |
1340 | ####print("IPPseconds",dataOut.ippSeconds) |
|
1340 | ####print("IPPseconds",dataOut.ippSeconds) | |
1341 | ####print("ELVALOR DE n es:", n) |
|
1341 | ####print("ELVALOR DE n es:", n) | |
1342 | if n == None: |
|
1342 | if n == None: | |
1343 | raise ValueError("n should be specified.") |
|
1343 | raise ValueError("n should be specified.") | |
1344 |
|
1344 | |||
1345 | if n != None: |
|
1345 | if n != None: | |
1346 | if n<2: |
|
1346 | if n<2: | |
1347 | raise ValueError("n should be greater than 2") |
|
1347 | raise ValueError("n should be greater than 2") | |
1348 |
|
1348 | |||
1349 | self.n = n |
|
1349 | self.n = n | |
1350 | self.__nProf = n |
|
1350 | self.__nProf = n | |
1351 |
|
1351 | |||
1352 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1352 | self.__buffer = numpy.zeros((dataOut.nChannels, | |
1353 | n, |
|
1353 | n, | |
1354 | dataOut.nHeights), |
|
1354 | dataOut.nHeights), | |
1355 | dtype='complex') |
|
1355 | dtype='complex') | |
1356 |
|
1356 | |||
1357 | def putData(self,data): |
|
1357 | def putData(self,data): | |
1358 | ''' |
|
1358 | ''' | |
1359 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1359 | Add a profile to he __buffer and increase in one the __profiel Index | |
1360 | ''' |
|
1360 | ''' | |
1361 | self.__buffer[:,self.__profIndex,:]= data |
|
1361 | self.__buffer[:,self.__profIndex,:]= data | |
1362 | self.__profIndex += 1 |
|
1362 | self.__profIndex += 1 | |
1363 | return |
|
1363 | return | |
1364 |
|
1364 | |||
1365 | def pushData(self,dataOut): |
|
1365 | def pushData(self,dataOut): | |
1366 | ''' |
|
1366 | ''' | |
1367 | Return the PULSEPAIR and the profiles used in the operation |
|
1367 | Return the PULSEPAIR and the profiles used in the operation | |
1368 | Affected : self.__profileIndex |
|
1368 | Affected : self.__profileIndex | |
1369 | ''' |
|
1369 | ''' | |
1370 | #----------------- Remove DC----------------------------------- |
|
1370 | #----------------- Remove DC----------------------------------- | |
1371 | if self.removeDC==True: |
|
1371 | if self.removeDC==True: | |
1372 | mean = numpy.mean(self.__buffer,1) |
|
1372 | mean = numpy.mean(self.__buffer,1) | |
1373 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1373 | tmp = mean.reshape(self.__nch,1,self.__nHeis) | |
1374 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1374 | dc= numpy.tile(tmp,[1,self.__nProf,1]) | |
1375 | self.__buffer = self.__buffer - dc |
|
1375 | self.__buffer = self.__buffer - dc | |
1376 | #------------------Calculo de Potencia ------------------------ |
|
1376 | #------------------Calculo de Potencia ------------------------ | |
1377 | pair0 = self.__buffer*numpy.conj(self.__buffer) |
|
1377 | pair0 = self.__buffer*numpy.conj(self.__buffer) | |
1378 | pair0 = pair0.real |
|
1378 | pair0 = pair0.real | |
1379 | lag_0 = numpy.sum(pair0,1) |
|
1379 | lag_0 = numpy.sum(pair0,1) | |
|
1380 | #-----------------Calculo de Cscp------------------------------ New | |||
|
1381 | cspc_pair01 = self.__buffer[0]*__self.buffer[1] | |||
1380 | #------------------Calculo de Ruido x canal-------------------- |
|
1382 | #------------------Calculo de Ruido x canal-------------------- | |
1381 | self.noise = numpy.zeros(self.__nch) |
|
1383 | self.noise = numpy.zeros(self.__nch) | |
1382 | for i in range(self.__nch): |
|
1384 | for i in range(self.__nch): | |
1383 | daux = numpy.sort(pair0[i,:,:],axis= None) |
|
1385 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
1384 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) |
|
1386 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) | |
1385 |
|
1387 | |||
1386 | self.noise = self.noise.reshape(self.__nch,1) |
|
1388 | self.noise = self.noise.reshape(self.__nch,1) | |
1387 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) |
|
1389 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
1388 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) |
|
1390 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
1389 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) |
|
1391 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
1390 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
1392 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- | |
1391 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
1393 | #------------------ P= S+N ,P=lag_0/N --------------------------------- | |
1392 | #-------------------- Power -------------------------------------------------- |
|
1394 | #-------------------- Power -------------------------------------------------- | |
1393 | data_power = lag_0/(self.n*self.nCohInt) |
|
1395 | data_power = lag_0/(self.n*self.nCohInt) | |
1394 |
#------------------ |
|
1396 | #--------------------CCF------------------------------------------------------ | |
|
1397 | data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt) | |||
|
1398 | #------------------ Senal -------------------------------------------------- | |||
1395 | data_intensity = pair0 - noise_buffer |
|
1399 | data_intensity = pair0 - noise_buffer | |
1396 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) |
|
1400 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
1397 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
1401 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
1398 | for i in range(self.__nch): |
|
1402 | for i in range(self.__nch): | |
1399 | for j in range(self.__nHeis): |
|
1403 | for j in range(self.__nHeis): | |
1400 | if data_intensity[i][j] < 0: |
|
1404 | if data_intensity[i][j] < 0: | |
1401 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
1405 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
1402 |
|
1406 | |||
1403 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
1407 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- | |
1404 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1408 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) | |
1405 | lag_1 = numpy.sum(pair1,1) |
|
1409 | lag_1 = numpy.sum(pair1,1) | |
1406 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) |
|
1410 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
1407 | data_velocity = (self.lambda_/2.0)*data_freq |
|
1411 | data_velocity = (self.lambda_/2.0)*data_freq | |
1408 |
|
1412 | |||
1409 | #---------------- Potencia promedio estimada de la Senal----------- |
|
1413 | #---------------- Potencia promedio estimada de la Senal----------- | |
1410 | lag_0 = lag_0/self.n |
|
1414 | lag_0 = lag_0/self.n | |
1411 | S = lag_0-self.noise |
|
1415 | S = lag_0-self.noise | |
1412 |
|
1416 | |||
1413 | #---------------- Frecuencia Doppler promedio --------------------- |
|
1417 | #---------------- Frecuencia Doppler promedio --------------------- | |
1414 | lag_1 = lag_1/(self.n-1) |
|
1418 | lag_1 = lag_1/(self.n-1) | |
1415 | R1 = numpy.abs(lag_1) |
|
1419 | R1 = numpy.abs(lag_1) | |
1416 |
|
1420 | |||
1417 | #---------------- Calculo del SNR---------------------------------- |
|
1421 | #---------------- Calculo del SNR---------------------------------- | |
1418 | data_snrPP = S/self.noise |
|
1422 | data_snrPP = S/self.noise | |
1419 | for i in range(self.__nch): |
|
1423 | for i in range(self.__nch): | |
1420 | for j in range(self.__nHeis): |
|
1424 | for j in range(self.__nHeis): | |
1421 | if data_snrPP[i][j] < 1.e-20: |
|
1425 | if data_snrPP[i][j] < 1.e-20: | |
1422 | data_snrPP[i][j] = 1.e-20 |
|
1426 | data_snrPP[i][j] = 1.e-20 | |
1423 |
|
1427 | |||
1424 | #----------------- Calculo del ancho espectral ---------------------- |
|
1428 | #----------------- Calculo del ancho espectral ---------------------- | |
1425 | L = S/R1 |
|
1429 | L = S/R1 | |
1426 | L = numpy.where(L<0,1,L) |
|
1430 | L = numpy.where(L<0,1,L) | |
1427 | L = numpy.log(L) |
|
1431 | L = numpy.log(L) | |
1428 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1432 | tmp = numpy.sqrt(numpy.absolute(L)) | |
1429 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) |
|
1433 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
1430 | n = self.__profIndex |
|
1434 | n = self.__profIndex | |
1431 |
|
1435 | |||
1432 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1436 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') | |
1433 | self.__profIndex = 0 |
|
1437 | self.__profIndex = 0 | |
1434 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n |
|
1438 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n | |
1435 |
|
1439 | |||
1436 |
|
1440 | |||
1437 | def pulsePairbyProfiles(self,dataOut): |
|
1441 | def pulsePairbyProfiles(self,dataOut): | |
1438 |
|
1442 | |||
1439 | self.__dataReady = False |
|
1443 | self.__dataReady = False | |
1440 | data_power = None |
|
1444 | data_power = None | |
1441 | data_intensity = None |
|
1445 | data_intensity = None | |
1442 | data_velocity = None |
|
1446 | data_velocity = None | |
1443 | data_specwidth = None |
|
1447 | data_specwidth = None | |
1444 | data_snrPP = None |
|
1448 | data_snrPP = None | |
|
1449 | data_ccf = None | |||
1445 | self.putData(data=dataOut.data) |
|
1450 | self.putData(data=dataOut.data) | |
1446 | if self.__profIndex == self.n: |
|
1451 | if self.__profIndex == self.n: | |
1447 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) |
|
1452 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut) | |
1448 | self.__dataReady = True |
|
1453 | self.__dataReady = True | |
1449 |
|
1454 | |||
1450 |
return data_power, data_intensity, data_velocity, data_snrPP, |
|
1455 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf | |
1451 |
|
1456 | |||
1452 |
|
1457 | |||
1453 | def pulsePairOp(self, dataOut, datatime= None): |
|
1458 | def pulsePairOp(self, dataOut, datatime= None): | |
1454 |
|
1459 | |||
1455 | if self.__initime == None: |
|
1460 | if self.__initime == None: | |
1456 | self.__initime = datatime |
|
1461 | self.__initime = datatime | |
1457 |
data_power, data_intensity, data_velocity, data_snrPP, |
|
1462 | data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut) | |
1458 | self.__lastdatatime = datatime |
|
1463 | self.__lastdatatime = datatime | |
1459 |
|
1464 | |||
1460 | if data_power is None: |
|
1465 | if data_power is None: | |
1461 | return None, None, None,None,None,None |
|
1466 | return None, None, None,None,None,None | |
1462 |
|
1467 | |||
1463 | avgdatatime = self.__initime |
|
1468 | avgdatatime = self.__initime | |
1464 | deltatime = datatime - self.__lastdatatime |
|
1469 | deltatime = datatime - self.__lastdatatime | |
1465 | self.__initime = datatime |
|
1470 | self.__initime = datatime | |
1466 |
|
1471 | |||
1467 |
return data_power, data_intensity, data_velocity, data_snrPP, |
|
1472 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime | |
1468 |
|
1473 | |||
1469 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1474 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): | |
1470 |
|
1475 | |||
1471 | if not self.isConfig: |
|
1476 | if not self.isConfig: | |
1472 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1477 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) | |
1473 | self.isConfig = True |
|
1478 | self.isConfig = True | |
1474 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) |
|
1479 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
1475 | dataOut.flagNoData = True |
|
1480 | dataOut.flagNoData = True | |
1476 |
|
1481 | |||
1477 | if self.__dataReady: |
|
1482 | if self.__dataReady: | |
|
1483 | ###print("READY ----------------------------------") | |||
1478 | dataOut.nCohInt *= self.n |
|
1484 | dataOut.nCohInt *= self.n | |
1479 | dataOut.dataPP_POW = data_intensity # S |
|
1485 | dataOut.dataPP_POW = data_intensity # S | |
1480 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO |
|
1486 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO | |
1481 | dataOut.dataPP_DOP = data_velocity |
|
1487 | dataOut.dataPP_DOP = data_velocity | |
1482 | dataOut.dataPP_SNR = data_snrPP |
|
1488 | dataOut.dataPP_SNR = data_snrPP | |
1483 | dataOut.dataPP_WIDTH = data_specwidth |
|
1489 | dataOut.dataPP_WIDTH = data_specwidth | |
|
1490 | dataOut.dataPP_CCF = data_ccf | |||
1484 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1491 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. | |
1485 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1492 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1486 | dataOut.utctime = avgdatatime |
|
1493 | dataOut.utctime = avgdatatime | |
1487 | dataOut.flagNoData = False |
|
1494 | dataOut.flagNoData = False | |
1488 | return dataOut |
|
1495 | return dataOut | |
1489 |
|
1496 | |||
1490 |
|
1497 | |||
1491 |
|
1498 | |||
1492 | # import collections |
|
1499 | # import collections | |
1493 | # from scipy.stats import mode |
|
1500 | # from scipy.stats import mode | |
1494 | # |
|
1501 | # | |
1495 | # class Synchronize(Operation): |
|
1502 | # class Synchronize(Operation): | |
1496 | # |
|
1503 | # | |
1497 | # isConfig = False |
|
1504 | # isConfig = False | |
1498 | # __profIndex = 0 |
|
1505 | # __profIndex = 0 | |
1499 | # |
|
1506 | # | |
1500 | # def __init__(self, **kwargs): |
|
1507 | # def __init__(self, **kwargs): | |
1501 | # |
|
1508 | # | |
1502 | # Operation.__init__(self, **kwargs) |
|
1509 | # Operation.__init__(self, **kwargs) | |
1503 | # # self.isConfig = False |
|
1510 | # # self.isConfig = False | |
1504 | # self.__powBuffer = None |
|
1511 | # self.__powBuffer = None | |
1505 | # self.__startIndex = 0 |
|
1512 | # self.__startIndex = 0 | |
1506 | # self.__pulseFound = False |
|
1513 | # self.__pulseFound = False | |
1507 | # |
|
1514 | # | |
1508 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1515 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1509 | # |
|
1516 | # | |
1510 | # #Read data |
|
1517 | # #Read data | |
1511 | # |
|
1518 | # | |
1512 | # powerdB = dataOut.getPower(channel = channel) |
|
1519 | # powerdB = dataOut.getPower(channel = channel) | |
1513 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1520 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1514 | # |
|
1521 | # | |
1515 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1522 | # self.__powBuffer.extend(powerdB.flatten()) | |
1516 | # |
|
1523 | # | |
1517 | # dataArray = numpy.array(self.__powBuffer) |
|
1524 | # dataArray = numpy.array(self.__powBuffer) | |
1518 | # |
|
1525 | # | |
1519 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1526 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1520 | # |
|
1527 | # | |
1521 | # maxValue = numpy.nanmax(filteredPower) |
|
1528 | # maxValue = numpy.nanmax(filteredPower) | |
1522 | # |
|
1529 | # | |
1523 | # if maxValue < noisedB + 10: |
|
1530 | # if maxValue < noisedB + 10: | |
1524 | # #No se encuentra ningun pulso de transmision |
|
1531 | # #No se encuentra ningun pulso de transmision | |
1525 | # return None |
|
1532 | # return None | |
1526 | # |
|
1533 | # | |
1527 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1534 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1528 | # |
|
1535 | # | |
1529 | # if len(maxValuesIndex) < 2: |
|
1536 | # if len(maxValuesIndex) < 2: | |
1530 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1537 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1531 | # return None |
|
1538 | # return None | |
1532 | # |
|
1539 | # | |
1533 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1540 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1534 | # |
|
1541 | # | |
1535 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1542 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1536 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1543 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1537 | # |
|
1544 | # | |
1538 | # if len(pulseIndex) < 2: |
|
1545 | # if len(pulseIndex) < 2: | |
1539 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1546 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1540 | # return None |
|
1547 | # return None | |
1541 | # |
|
1548 | # | |
1542 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1549 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1543 | # |
|
1550 | # | |
1544 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1551 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1545 | # #(No deberian existir IPP menor a 10 unidades) |
|
1552 | # #(No deberian existir IPP menor a 10 unidades) | |
1546 | # |
|
1553 | # | |
1547 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1554 | # realIndex = numpy.where(spacing > 10 )[0] | |
1548 | # |
|
1555 | # | |
1549 | # if len(realIndex) < 2: |
|
1556 | # if len(realIndex) < 2: | |
1550 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1557 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1551 | # return None |
|
1558 | # return None | |
1552 | # |
|
1559 | # | |
1553 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1560 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1554 | # realPulseIndex = pulseIndex[realIndex] |
|
1561 | # realPulseIndex = pulseIndex[realIndex] | |
1555 | # |
|
1562 | # | |
1556 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1563 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1557 | # |
|
1564 | # | |
1558 | # print "IPP = %d samples" %period |
|
1565 | # print "IPP = %d samples" %period | |
1559 | # |
|
1566 | # | |
1560 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1567 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1561 | # self.__startIndex = int(realPulseIndex[0]) |
|
1568 | # self.__startIndex = int(realPulseIndex[0]) | |
1562 | # |
|
1569 | # | |
1563 | # return 1 |
|
1570 | # return 1 | |
1564 | # |
|
1571 | # | |
1565 | # |
|
1572 | # | |
1566 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1573 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1567 | # |
|
1574 | # | |
1568 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1575 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1569 | # maxlen = buffer_size*nSamples) |
|
1576 | # maxlen = buffer_size*nSamples) | |
1570 | # |
|
1577 | # | |
1571 | # bufferList = [] |
|
1578 | # bufferList = [] | |
1572 | # |
|
1579 | # | |
1573 | # for i in range(nChannels): |
|
1580 | # for i in range(nChannels): | |
1574 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1581 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1575 | # maxlen = buffer_size*nSamples) |
|
1582 | # maxlen = buffer_size*nSamples) | |
1576 | # |
|
1583 | # | |
1577 | # bufferList.append(bufferByChannel) |
|
1584 | # bufferList.append(bufferByChannel) | |
1578 | # |
|
1585 | # | |
1579 | # self.__nSamples = nSamples |
|
1586 | # self.__nSamples = nSamples | |
1580 | # self.__nChannels = nChannels |
|
1587 | # self.__nChannels = nChannels | |
1581 | # self.__bufferList = bufferList |
|
1588 | # self.__bufferList = bufferList | |
1582 | # |
|
1589 | # | |
1583 | # def run(self, dataOut, channel = 0): |
|
1590 | # def run(self, dataOut, channel = 0): | |
1584 | # |
|
1591 | # | |
1585 | # if not self.isConfig: |
|
1592 | # if not self.isConfig: | |
1586 | # nSamples = dataOut.nHeights |
|
1593 | # nSamples = dataOut.nHeights | |
1587 | # nChannels = dataOut.nChannels |
|
1594 | # nChannels = dataOut.nChannels | |
1588 | # self.setup(nSamples, nChannels) |
|
1595 | # self.setup(nSamples, nChannels) | |
1589 | # self.isConfig = True |
|
1596 | # self.isConfig = True | |
1590 | # |
|
1597 | # | |
1591 | # #Append new data to internal buffer |
|
1598 | # #Append new data to internal buffer | |
1592 | # for thisChannel in range(self.__nChannels): |
|
1599 | # for thisChannel in range(self.__nChannels): | |
1593 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1600 | # bufferByChannel = self.__bufferList[thisChannel] | |
1594 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1601 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1595 | # |
|
1602 | # | |
1596 | # if self.__pulseFound: |
|
1603 | # if self.__pulseFound: | |
1597 | # self.__startIndex -= self.__nSamples |
|
1604 | # self.__startIndex -= self.__nSamples | |
1598 | # |
|
1605 | # | |
1599 | # #Finding Tx Pulse |
|
1606 | # #Finding Tx Pulse | |
1600 | # if not self.__pulseFound: |
|
1607 | # if not self.__pulseFound: | |
1601 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1608 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1602 | # |
|
1609 | # | |
1603 | # if indexFound == None: |
|
1610 | # if indexFound == None: | |
1604 | # dataOut.flagNoData = True |
|
1611 | # dataOut.flagNoData = True | |
1605 | # return |
|
1612 | # return | |
1606 | # |
|
1613 | # | |
1607 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1614 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1608 | # self.__pulseFound = True |
|
1615 | # self.__pulseFound = True | |
1609 | # self.__startIndex = indexFound |
|
1616 | # self.__startIndex = indexFound | |
1610 | # |
|
1617 | # | |
1611 | # #If pulse was found ... |
|
1618 | # #If pulse was found ... | |
1612 | # for thisChannel in range(self.__nChannels): |
|
1619 | # for thisChannel in range(self.__nChannels): | |
1613 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1620 | # bufferByChannel = self.__bufferList[thisChannel] | |
1614 | # #print self.__startIndex |
|
1621 | # #print self.__startIndex | |
1615 | # x = numpy.array(bufferByChannel) |
|
1622 | # x = numpy.array(bufferByChannel) | |
1616 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1623 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1617 | # |
|
1624 | # | |
1618 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1625 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1619 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1626 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1620 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1627 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1621 | # |
|
1628 | # | |
1622 | # dataOut.data = self.__arrayBuffer |
|
1629 | # dataOut.data = self.__arrayBuffer | |
1623 | # |
|
1630 | # | |
1624 | # self.__startIndex += self.__newNSamples |
|
1631 | # self.__startIndex += self.__newNSamples | |
1625 | # |
|
1632 | # | |
1626 | # return |
|
1633 | # return |
@@ -1,133 +1,184 | |||||
1 | # Ing. AVP |
|
1 | # Ing. AVP | |
2 | # 04/01/2022 |
|
2 | # 04/01/2022 | |
3 | # ARCHIVO DE LECTURA |
|
3 | # ARCHIVO DE LECTURA | |
4 | import os, sys |
|
4 | import os, sys | |
5 | import datetime |
|
5 | import datetime | |
6 | import time |
|
6 | import time | |
7 | import numpy |
|
7 | import numpy | |
|
8 | import json | |||
8 | from ext_met import getfirstFilefromPath,getDatavaluefromDirFilename |
|
9 | from ext_met import getfirstFilefromPath,getDatavaluefromDirFilename | |
9 | from schainpy.controller import Project |
|
10 | from schainpy.controller import Project | |
10 | #----------------------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------------------- | |
|
12 | # path_ped = "/DATA_RM/TEST_PEDESTAL/P20211110-171003" | |||
|
13 | ## print("PATH PEDESTAL :",path_ped) | |||
|
14 | ||||
11 | print("[SETUP]-RADAR METEOROLOGICO-") |
|
15 | print("[SETUP]-RADAR METEOROLOGICO-") | |
12 |
path_ped = "/DATA_RM/TEST_PEDESTAL/P2021111 |
|
16 | path_ped = "/DATA_RM/TEST_PEDESTAL/P20211111-173856" | |
13 | print("PATH PEDESTAL :",path_ped) |
|
17 | print("PATH PEDESTAL :",path_ped) | |
14 |
path_adq = "/DATA_RM/1 |
|
18 | path_adq = "/DATA_RM/11" | |
15 | print("PATH DATA :",path_adq) |
|
19 | print("PATH DATA :",path_adq) | |
|
20 | ||||
|
21 | ||||
16 | figpath_pp_rti = "/home/soporte/Pictures/TEST_PP_RTI" |
|
22 | figpath_pp_rti = "/home/soporte/Pictures/TEST_PP_RTI" | |
17 | print("PATH PP RTI :",figpath_pp_rti) |
|
23 | print("PATH PP RTI :",figpath_pp_rti) | |
18 | figpath_pp_ppi = "/home/soporte/Pictures/TEST_PP_PPI" |
|
24 | figpath_pp_ppi = "/home/soporte/Pictures/TEST_PP_PPI" | |
19 | print("PATH PP PPI :",figpath_pp_ppi) |
|
25 | print("PATH PP PPI :",figpath_pp_ppi) | |
20 |
path_pp_save_int = "/DATA_RM/TEST_ |
|
26 | path_pp_save_int = "/DATA_RM/TEST_NEW_FORMAT" | |
21 | print("PATH SAVE PP INT :",path_pp_save_int) |
|
27 | print("PATH SAVE PP INT :",path_pp_save_int) | |
22 | print(" ") |
|
28 | print(" ") | |
23 | #------------------------------------------------------------------------------------------- |
|
29 | #------------------------------------------------------------------------------------------- | |
24 | print("SELECCIONAR MODO: PPI (0) O RHI (1)") |
|
30 | print("SELECCIONAR MODO: PPI (0) O RHI (1)") | |
25 | mode_wr = 0 |
|
31 | mode_wr = 0 | |
26 | if mode_wr==0: |
|
32 | if mode_wr==0: | |
27 | print("[ ON ] MODE PPI") |
|
33 | print("[ ON ] MODE PPI") | |
28 | list_ped = getfirstFilefromPath(path=path_ped,meta="PE",ext=".hdf5") |
|
34 | list_ped = getfirstFilefromPath(path=path_ped,meta="PE",ext=".hdf5") | |
29 | ff_pedestal = list_ped[2] |
|
35 | ff_pedestal = list_ped[2] | |
30 | azi_vel = getDatavaluefromDirFilename(path=path_ped,file=ff_pedestal,value="azi_vel") |
|
36 | azi_vel = getDatavaluefromDirFilename(path=path_ped,file=ff_pedestal,value="azi_vel") | |
31 | V = round(azi_vel[0]) |
|
37 | V = round(azi_vel[0]) | |
32 | print("VELOCIDAD AZI :", int(numpy.mean(azi_vel)),"Β°/seg") |
|
38 | print("VELOCIDAD AZI :", int(numpy.mean(azi_vel)),"Β°/seg") | |
33 | else: |
|
39 | else: | |
34 | print("[ ON ] MODE RHI") |
|
40 | print("[ ON ] MODE RHI") | |
35 | list_ped = getfirstFilefromPath(path=path_ped,meta="PE",ext=".hdf5") |
|
41 | list_ped = getfirstFilefromPath(path=path_ped,meta="PE",ext=".hdf5") | |
36 | ff_pedestal = list_ped[2] |
|
42 | ff_pedestal = list_ped[2] | |
37 | V = round(ele_vel[0]) |
|
43 | V = round(ele_vel[0]) | |
38 | ele_vel = getDatavaluefromDirFilename(path=path_ped,file=ff_pedestal,value="ele_vel") |
|
44 | ele_vel = getDatavaluefromDirFilename(path=path_ped,file=ff_pedestal,value="ele_vel") | |
39 | print("VELOCIDAD ELE :", int(numpy.mean(ele_vel)),"Β°/seg") |
|
45 | print("VELOCIDAD ELE :", int(numpy.mean(ele_vel)),"Β°/seg") | |
40 | print(" ") |
|
46 | print(" ") | |
41 | #--------------------------------------------------------------------------------------- |
|
47 | #--------------------------------------------------------------------------------------- | |
42 | print("SELECCIONAR MODO: PULSE PAIR (0) O FREQUENCY (1)") |
|
48 | print("SELECCIONAR MODO: PULSE PAIR (0) O FREQUENCY (1)") | |
43 | mode_proc = 0 |
|
49 | mode_proc = 0 | |
44 | if mode_proc==0: |
|
50 | if mode_proc==0: | |
45 | print("[ ON ] MODE PULSEPAIR") |
|
51 | print("[ ON ] MODE PULSEPAIR") | |
46 | else: |
|
52 | else: | |
47 | print("[ ON ] MODE FREQUENCY") |
|
53 | print("[ ON ] MODE FREQUENCY") | |
48 | ipp = 60.0 |
|
54 | ipp = 60.0 | |
49 | print("IPP(Km.) : %1.2f"%ipp) |
|
55 | print("IPP(Km.) : %1.2f"%ipp) | |
50 | ipp_sec = (ipp*1.0e3/150.0)*1.0e-6 |
|
56 | ipp_sec = (ipp*1.0e3/150.0)*1.0e-6 | |
51 | print("IPP(useg.) : %1.2f"%(ipp_sec*(1.0e6))) |
|
57 | print("IPP(useg.) : %1.2f"%(ipp_sec*(1.0e6))) | |
52 | VEL=V |
|
58 | VEL=V | |
53 | n= int(1/(VEL*ipp_sec)) |
|
59 | n= int(1/(VEL*ipp_sec)) | |
54 | print("NΒ° Profiles : ", n) |
|
60 | print("NΒ° Profiles : ", n) | |
55 | #--------------------------------------------------------------------------------------- |
|
61 | #--------------------------------------------------------------------------------------- | |
56 | plot_rti = 0 |
|
62 | plot_rti = 0 | |
57 |
plot_ppi = |
|
63 | plot_ppi = 0 | |
58 | integration = 1 |
|
64 | integration = 1 | |
59 |
save = |
|
65 | save = 1 | |
60 | #---------------------------RANGO DE PLOTEO---------------------------------- |
|
66 | #---------------------------RANGO DE PLOTEO---------------------------------- | |
61 | dBmin = '1' |
|
67 | dBmin = '1' | |
62 | dBmax = '85' |
|
68 | dBmax = '85' | |
63 |
xmin = '1 |
|
69 | xmin = '14' | |
64 |
xmax = '1 |
|
70 | xmax = '16' | |
65 | ymin = '0' |
|
71 | ymin = '0' | |
66 | ymax = '600' |
|
72 | ymax = '600' | |
67 | #---------------------------------------------------------------------------- |
|
73 | #---------------------------------------------------------------------------- | |
68 | time.sleep(3) |
|
74 | time.sleep(3) | |
69 | #---------------------SIGNAL CHAIN ------------------------------------ |
|
75 | #---------------------SIGNAL CHAIN ------------------------------------ | |
|
76 | desc_wr= { | |||
|
77 | 'Data': { | |||
|
78 | 'dataPP_POW': 'Power', | |||
|
79 | 'utctime': 'Time', | |||
|
80 | 'azimuth': 'az', | |||
|
81 | 'elevation':'el' | |||
|
82 | }, | |||
|
83 | 'Metadata': { | |||
|
84 | 'heightList': 'range', | |||
|
85 | 'channelList': 'Channels' | |||
|
86 | } | |||
|
87 | } | |||
|
88 | ||||
|
89 | ||||
70 | desc = "USRP_WEATHER_RADAR" |
|
90 | desc = "USRP_WEATHER_RADAR" | |
71 | filename = "USRP_processing.xml" |
|
91 | filename = "USRP_processing.xml" | |
72 | controllerObj = Project() |
|
92 | controllerObj = Project() | |
73 | controllerObj.setup(id = '191', name='Test_USRP', description=desc) |
|
93 | controllerObj.setup(id = '191', name='Test_USRP', description=desc) | |
74 | #---------------------UNIDAD DE LECTURA-------------------------------- |
|
94 | #---------------------UNIDAD DE LECTURA-------------------------------- | |
75 | readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader', |
|
95 | readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader', | |
76 | path=path_adq, |
|
96 | path=path_adq, | |
77 |
startDate="2021/11/1 |
|
97 | startDate="2021/11/11",#today, | |
78 | endDate="2021/12/30",#today, |
|
98 | endDate="2021/12/30",#today, | |
79 |
startTime='17: |
|
99 | startTime='17:39:17', | |
80 | endTime='23:59:59', |
|
100 | endTime='23:59:59', | |
81 | delay=0, |
|
101 | delay=0, | |
82 | #set=0, |
|
102 | #set=0, | |
83 | online=0, |
|
103 | online=0, | |
84 | walk=1, |
|
104 | walk=1, | |
85 | ippKm=ipp) |
|
105 | ippKm=ipp) | |
86 |
|
106 | |||
87 | procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc',inputId=readUnitConfObj.getId()) |
|
107 | procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc',inputId=readUnitConfObj.getId()) | |
88 |
|
108 | |||
89 | opObj11 = procUnitConfObjA.addOperation(name='selectHeights') |
|
109 | opObj11 = procUnitConfObjA.addOperation(name='selectHeights') | |
90 | opObj11.addParameter(name='minIndex', value='1', format='int') |
|
110 | opObj11.addParameter(name='minIndex', value='1', format='int') | |
91 | # opObj11.addParameter(name='maxIndex', value='10000', format='int') |
|
111 | # opObj11.addParameter(name='maxIndex', value='10000', format='int') | |
92 | opObj11.addParameter(name='maxIndex', value='400', format='int') |
|
112 | opObj11.addParameter(name='maxIndex', value='400', format='int') | |
93 |
|
113 | |||
94 | if mode_proc==0: |
|
114 | if mode_proc==0: | |
95 | opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other') |
|
115 | opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other') | |
96 | opObj11.addParameter(name='n', value=int(n), format='int') |
|
116 | opObj11.addParameter(name='n', value=int(n), format='int') | |
97 | procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId()) |
|
117 | procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId()) | |
98 | # REVISAR EL test_sim00013.py |
|
118 | # REVISAR EL test_sim00013.py | |
99 | if plot_rti==1: |
|
119 | if plot_rti==1: | |
100 | opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external') |
|
120 | opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external') | |
101 | opObj11.addParameter(name='attr_data', value='dataPP_POW') |
|
121 | opObj11.addParameter(name='attr_data', value='dataPP_POW') | |
102 | opObj11.addParameter(name='colormap', value='jet') |
|
122 | opObj11.addParameter(name='colormap', value='jet') | |
103 | opObj11.addParameter(name='xmin', value=xmin) |
|
123 | opObj11.addParameter(name='xmin', value=xmin) | |
104 | opObj11.addParameter(name='xmax', value=xmax) |
|
124 | opObj11.addParameter(name='xmax', value=xmax) | |
105 | opObj11.addParameter(name='zmin', value=dBmin) |
|
125 | opObj11.addParameter(name='zmin', value=dBmin) | |
106 | opObj11.addParameter(name='zmax', value=dBmax) |
|
126 | opObj11.addParameter(name='zmax', value=dBmax) | |
107 | opObj11.addParameter(name='save', value=figpath_pp_rti) |
|
127 | opObj11.addParameter(name='save', value=figpath_pp_rti) | |
108 | opObj11.addParameter(name='showprofile', value=0) |
|
128 | opObj11.addParameter(name='showprofile', value=0) | |
109 | opObj11.addParameter(name='save_period', value=50) |
|
129 | opObj11.addParameter(name='save_period', value=50) | |
110 | if integration==1: |
|
130 | if integration==1: | |
111 | opObj11 = procUnitConfObjB.addOperation(name='PedestalInformation') |
|
131 | opObj11 = procUnitConfObjB.addOperation(name='PedestalInformation') | |
112 | opObj11.addParameter(name='path_ped', value=path_ped) |
|
132 | opObj11.addParameter(name='path_ped', value=path_ped) | |
113 | opObj11.addParameter(name='t_Interval_p', value='0.01', format='float') |
|
133 | opObj11.addParameter(name='t_Interval_p', value='0.01', format='float') | |
114 |
|
134 | opObj11.addParameter(name='wr_exp', value='PPI') | ||
|
135 | #------------------------------------------------------------------------------ | |||
|
136 | ''' | |||
|
137 | opObj11.addParameter(name='Datatype', value='RadialSet') | |||
|
138 | opObj11.addParameter(name='Scantype', value='PPI') | |||
|
139 | opObj11.addParameter(name='Latitude', value='-11.96') | |||
|
140 | opObj11.addParameter(name='Longitud', value='-76.54') | |||
|
141 | opObj11.addParameter(name='Heading', value='293') | |||
|
142 | opObj11.addParameter(name='Height', value='293') | |||
|
143 | opObj11.addParameter(name='Waveform', value='OFM') | |||
|
144 | opObj11.addParameter(name='PRF', value='2000') | |||
|
145 | opObj11.addParameter(name='CreatedBy', value='WeatherRadarJROTeam') | |||
|
146 | opObj11.addParameter(name='ContactInformation', value='avaldez@igp.gob.pe') | |||
|
147 | ''' | |||
115 | if plot_ppi==1: |
|
148 | if plot_ppi==1: | |
116 | opObj11 = procUnitConfObjB.addOperation(name='Block360') |
|
149 | opObj11 = procUnitConfObjB.addOperation(name='Block360') | |
117 | opObj11.addParameter(name='n', value='10', format='int') |
|
150 | opObj11.addParameter(name='n', value='10', format='int') | |
118 | opObj11.addParameter(name='mode', value=mode_proc, format='int') |
|
151 | opObj11.addParameter(name='mode', value=mode_proc, format='int') | |
119 | # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180 |
|
152 | # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180 | |
120 | opObj11= procUnitConfObjB.addOperation(name='WeatherPlot',optype='other') |
|
153 | opObj11= procUnitConfObjB.addOperation(name='WeatherPlot',optype='other') | |
121 | opObj11.addParameter(name='save', value=figpath_pp_ppi) |
|
154 | opObj11.addParameter(name='save', value=figpath_pp_ppi) | |
122 | opObj11.addParameter(name='save_period', value=1) |
|
155 | opObj11.addParameter(name='save_period', value=1) | |
123 |
|
156 | |||
124 | if save==1: |
|
157 | if save==1: | |
125 | opObj10 = procUnitConfObjB.addOperation(name='HDFWriter') |
|
158 | opObj10 = procUnitConfObjB.addOperation(name='HDFWriter') | |
126 | opObj10.addParameter(name='path',value=path_pp_save_int) |
|
159 | opObj10.addParameter(name='path',value=path_pp_save_int) | |
127 | opObj10.addParameter(name='mode',value="weather") |
|
160 | opObj10.addParameter(name='mode',value="weather") | |
|
161 | opObj10.addParameter(name='type_data',value='F') | |||
128 | opObj10.addParameter(name='blocksPerFile',value='360',format='int') |
|
162 | opObj10.addParameter(name='blocksPerFile',value='360',format='int') | |
129 |
opObj10.addParameter(name='metadataList',value='utctimeInit, |
|
163 | #opObj10.addParameter(name='metadataList',value='utctimeInit,paramInterval,channelList,heightList,flagDataAsBlock',format='list') | |
130 | opObj10.addParameter(name='dataList',value='dataPP_POW,dataPP_DOP,azimuth,elevation,utctime',format='list')#,format='list' |
|
164 | opObj10.addParameter(name='metadataList',value='heightList,channelList,Typename,Datatype,Scantype,Latitude,Longitud,Heading,Height,Waveform,PRF,CreatedBy,ContactInformation',format='list') | |
|
165 | #-------------------- | |||
|
166 | opObj10.addParameter(name='Typename', value='Differential_Reflectivity') | |||
|
167 | opObj10.addParameter(name='Datatype', value='RadialSet') | |||
|
168 | opObj10.addParameter(name='Scantype', value='PPI') | |||
|
169 | opObj10.addParameter(name='Latitude', value='-11.96') | |||
|
170 | opObj10.addParameter(name='Longitud', value='-76.54') | |||
|
171 | opObj10.addParameter(name='Heading', value='293') | |||
|
172 | opObj10.addParameter(name='Height', value='293') | |||
|
173 | opObj10.addParameter(name='Waveform', value='OFM') | |||
|
174 | opObj10.addParameter(name='PRF', value='2000') | |||
|
175 | opObj10.addParameter(name='CreatedBy', value='WeatherRadarJROTeam') | |||
|
176 | opObj10.addParameter(name='ContactInformation', value='avaldez@igp.gob.pe') | |||
|
177 | #--------------------------------------------------- | |||
|
178 | #opObj10.addParameter(name='dataList',value='dataPP_POW,dataPP_DOP,azimuth,elevation,utctime',format='list')#,format='list' | |||
|
179 | #opObj10.addParameter(name='metadataList',value='utctimeInit,timeZone,paramInterval,profileIndex,channelList,heightList,flagDataAsBlock',format='list') | |||
131 |
|
180 | |||
|
181 | opObj10.addParameter(name='dataList',value='dataPP_POW,azimuth,elevation,utctime',format='list')#,format='list' | |||
|
182 | opObj10.addParameter(name='description',value=json.dumps(desc_wr)) | |||
132 |
|
183 | |||
133 | controllerObj.start() |
|
184 | controllerObj.start() |
General Comments 0
You need to be logged in to leave comments.
Login now