@@ -1,779 +1,779 | |||||
1 | ''' |
|
1 | ''' | |
2 | New Plots Operations |
|
2 | New Plots Operations | |
3 |
|
3 | |||
4 | @author: juan.espinoza@jro.igp.gob.pe |
|
4 | @author: juan.espinoza@jro.igp.gob.pe | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | import time |
|
8 | import time | |
9 | import datetime |
|
9 | import datetime | |
10 | import numpy |
|
10 | import numpy | |
11 |
|
11 | |||
12 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
12 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
13 | from schainpy.utils import log |
|
13 | from schainpy.utils import log | |
14 |
|
14 | |||
15 | EARTH_RADIUS = 6.3710e3 |
|
15 | EARTH_RADIUS = 6.3710e3 | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | def ll2xy(lat1, lon1, lat2, lon2): |
|
18 | def ll2xy(lat1, lon1, lat2, lon2): | |
19 |
|
19 | |||
20 | p = 0.017453292519943295 |
|
20 | p = 0.017453292519943295 | |
21 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
21 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
22 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
22 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
23 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
23 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
24 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
24 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
25 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
25 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
26 | theta = -theta + numpy.pi/2 |
|
26 | theta = -theta + numpy.pi/2 | |
27 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
27 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | def km2deg(km): |
|
30 | def km2deg(km): | |
31 | ''' |
|
31 | ''' | |
32 | Convert distance in km to degrees |
|
32 | Convert distance in km to degrees | |
33 | ''' |
|
33 | ''' | |
34 |
|
34 | |||
35 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
35 | return numpy.rad2deg(km/EARTH_RADIUS) | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | class SpectraPlot(Plot): |
|
38 | class SpectraPlot(Plot): | |
39 | ''' |
|
39 | ''' | |
40 | Plot for Spectra data |
|
40 | Plot for Spectra data | |
41 | ''' |
|
41 | ''' | |
42 |
|
42 | |||
43 | CODE = 'spc' |
|
43 | CODE = 'spc' | |
44 | colormap = 'jro' |
|
44 | colormap = 'jro' | |
45 | plot_name = 'Spectra' |
|
45 | plot_name = 'Spectra' | |
46 | plot_type = 'pcolor' |
|
46 | plot_type = 'pcolor' | |
47 |
|
47 | |||
48 | def setup(self): |
|
48 | def setup(self): | |
49 | self.nplots = len(self.data.channels) |
|
49 | self.nplots = len(self.data.channels) | |
50 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
50 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
51 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
|
51 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
52 | self.width = 3.4 * self.ncols |
|
52 | self.width = 3.4 * self.ncols | |
53 | self.height = 3 * self.nrows |
|
53 | self.height = 3 * self.nrows | |
54 | self.cb_label = 'dB' |
|
54 | self.cb_label = 'dB' | |
55 | if self.showprofile: |
|
55 | if self.showprofile: | |
56 | self.width += 0.8 * self.ncols |
|
56 | self.width += 0.8 * self.ncols | |
57 |
|
57 | |||
58 | self.ylabel = 'Range [km]' |
|
58 | self.ylabel = 'Range [km]' | |
59 |
|
59 | |||
60 | def plot(self): |
|
60 | def plot(self): | |
61 | if self.xaxis == "frequency": |
|
61 | if self.xaxis == "frequency": | |
62 | x = self.data.xrange[0] |
|
62 | x = self.data.xrange[0] | |
63 | self.xlabel = "Frequency (kHz)" |
|
63 | self.xlabel = "Frequency (kHz)" | |
64 | elif self.xaxis == "time": |
|
64 | elif self.xaxis == "time": | |
65 | x = self.data.xrange[1] |
|
65 | x = self.data.xrange[1] | |
66 | self.xlabel = "Time (ms)" |
|
66 | self.xlabel = "Time (ms)" | |
67 | else: |
|
67 | else: | |
68 | x = self.data.xrange[2] |
|
68 | x = self.data.xrange[2] | |
69 | self.xlabel = "Velocity (m/s)" |
|
69 | self.xlabel = "Velocity (m/s)" | |
70 |
|
70 | |||
71 | if self.CODE == 'spc_moments': |
|
71 | if self.CODE == 'spc_moments': | |
72 | x = self.data.xrange[2] |
|
72 | x = self.data.xrange[2] | |
73 | self.xlabel = "Velocity (m/s)" |
|
73 | self.xlabel = "Velocity (m/s)" | |
74 |
|
74 | |||
75 | self.titles = [] |
|
75 | self.titles = [] | |
76 |
|
76 | |||
77 | y = self.data.heights |
|
77 | y = self.data.heights | |
78 | self.y = y |
|
78 | self.y = y | |
79 | z = self.data['spc'] |
|
79 | z = self.data['spc'] | |
80 |
|
80 | |||
81 | for n, ax in enumerate(self.axes): |
|
81 | for n, ax in enumerate(self.axes): | |
82 | noise = self.data['noise'][n][-1] |
|
82 | noise = self.data['noise'][n][-1] | |
83 | if self.CODE == 'spc_moments': |
|
83 | if self.CODE == 'spc_moments': | |
84 | mean = self.data['moments'][n, :, 1, :][-1] |
|
84 | mean = self.data['moments'][n, :, 1, :][-1] | |
85 | if ax.firsttime: |
|
85 | if ax.firsttime: | |
86 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
86 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
87 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
87 | self.xmin = self.xmin if self.xmin else -self.xmax | |
88 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
88 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
89 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
89 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |
90 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
90 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
91 | vmin=self.zmin, |
|
91 | vmin=self.zmin, | |
92 | vmax=self.zmax, |
|
92 | vmax=self.zmax, | |
93 | cmap=plt.get_cmap(self.colormap) |
|
93 | cmap=plt.get_cmap(self.colormap) | |
94 | ) |
|
94 | ) | |
95 |
|
95 | |||
96 | if self.showprofile: |
|
96 | if self.showprofile: | |
97 | ax.plt_profile = self.pf_axes[n].plot( |
|
97 | ax.plt_profile = self.pf_axes[n].plot( | |
98 | self.data['rti'][n][-1], y)[0] |
|
98 | self.data['rti'][n][-1], y)[0] | |
99 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, |
|
99 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
100 | color="k", linestyle="dashed", lw=1)[0] |
|
100 | color="k", linestyle="dashed", lw=1)[0] | |
101 | if self.CODE == 'spc_moments': |
|
101 | if self.CODE == 'spc_moments': | |
102 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
102 | ax.plt_mean = ax.plot(mean, y, color='k')[0] | |
103 | else: |
|
103 | else: | |
104 | ax.plt.set_array(z[n].T.ravel()) |
|
104 | ax.plt.set_array(z[n].T.ravel()) | |
105 | if self.showprofile: |
|
105 | if self.showprofile: | |
106 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) |
|
106 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) | |
107 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) |
|
107 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |
108 | if self.CODE == 'spc_moments': |
|
108 | if self.CODE == 'spc_moments': | |
109 | ax.plt_mean.set_data(mean, y) |
|
109 | ax.plt_mean.set_data(mean, y) | |
110 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
110 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | class CrossSpectraPlot(Plot): |
|
113 | class CrossSpectraPlot(Plot): | |
114 |
|
114 | |||
115 | CODE = 'cspc' |
|
115 | CODE = 'cspc' | |
116 | colormap = 'jet' |
|
116 | colormap = 'jet' | |
117 | plot_name = 'CrossSpectra' |
|
117 | plot_name = 'CrossSpectra' | |
118 | plot_type = 'pcolor' |
|
118 | plot_type = 'pcolor' | |
119 | zmin_coh = None |
|
119 | zmin_coh = None | |
120 | zmax_coh = None |
|
120 | zmax_coh = None | |
121 | zmin_phase = None |
|
121 | zmin_phase = None | |
122 | zmax_phase = None |
|
122 | zmax_phase = None | |
123 |
|
123 | |||
124 | def setup(self): |
|
124 | def setup(self): | |
125 |
|
125 | |||
126 | self.ncols = 4 |
|
126 | self.ncols = 4 | |
127 | self.nrows = len(self.data.pairs) |
|
127 | self.nrows = len(self.data.pairs) | |
128 | self.nplots = self.nrows * 4 |
|
128 | self.nplots = self.nrows * 4 | |
129 | self.width = 3.4 * self.ncols |
|
129 | self.width = 3.4 * self.ncols | |
130 | self.height = 3 * self.nrows |
|
130 | self.height = 3 * self.nrows | |
131 | self.ylabel = 'Range [km]' |
|
131 | self.ylabel = 'Range [km]' | |
132 | self.showprofile = False |
|
132 | self.showprofile = False | |
133 |
|
133 | |||
134 | def plot(self): |
|
134 | def plot(self): | |
135 |
|
135 | |||
136 | if self.xaxis == "frequency": |
|
136 | if self.xaxis == "frequency": | |
137 | x = self.data.xrange[0] |
|
137 | x = self.data.xrange[0] | |
138 | self.xlabel = "Frequency (kHz)" |
|
138 | self.xlabel = "Frequency (kHz)" | |
139 | elif self.xaxis == "time": |
|
139 | elif self.xaxis == "time": | |
140 | x = self.data.xrange[1] |
|
140 | x = self.data.xrange[1] | |
141 | self.xlabel = "Time (ms)" |
|
141 | self.xlabel = "Time (ms)" | |
142 | else: |
|
142 | else: | |
143 | x = self.data.xrange[2] |
|
143 | x = self.data.xrange[2] | |
144 | self.xlabel = "Velocity (m/s)" |
|
144 | self.xlabel = "Velocity (m/s)" | |
145 |
|
145 | |||
146 | self.titles = [] |
|
146 | self.titles = [] | |
147 |
|
147 | |||
148 | y = self.data.heights |
|
148 | y = self.data.heights | |
149 | self.y = y |
|
149 | self.y = y | |
150 | spc = self.data['spc'] |
|
150 | spc = self.data['spc'] | |
151 | cspc = self.data['cspc'] |
|
151 | cspc = self.data['cspc'] | |
152 |
|
152 | |||
153 | for n in range(self.nrows): |
|
153 | for n in range(self.nrows): | |
154 | noise = self.data['noise'][n][-1] |
|
154 | noise = self.data['noise'][n][-1] | |
155 | pair = self.data.pairs[n] |
|
155 | pair = self.data.pairs[n] | |
156 | ax = self.axes[4 * n] |
|
156 | ax = self.axes[4 * n] | |
157 | spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor) |
|
157 | spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor) | |
158 | if ax.firsttime: |
|
158 | if ax.firsttime: | |
159 |
self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
159 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
160 |
self.xmin = self.xmin if self.xmin else -self.xmax |
|
160 | self.xmin = self.xmin if self.xmin else -self.xmax | |
161 |
self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) |
|
161 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) | |
162 |
self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) |
|
162 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
163 | ax.plt = ax.pcolormesh(x , y , spc0.T, |
|
163 | ax.plt = ax.pcolormesh(x , y , spc0.T, | |
164 | vmin=self.zmin, |
|
164 | vmin=self.zmin, | |
165 | vmax=self.zmax, |
|
165 | vmax=self.zmax, | |
166 | cmap=plt.get_cmap(self.colormap) |
|
166 | cmap=plt.get_cmap(self.colormap) | |
167 |
) |
|
167 | ) | |
168 | else: |
|
168 | else: | |
169 | ax.plt.set_array(spc0.T.ravel()) |
|
169 | ax.plt.set_array(spc0.T.ravel()) | |
170 | self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise)) |
|
170 | self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise)) | |
171 |
|
171 | |||
172 | ax = self.axes[4 * n + 1] |
|
172 | ax = self.axes[4 * n + 1] | |
173 | spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor) |
|
173 | spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor) | |
174 | if ax.firsttime: |
|
174 | if ax.firsttime: | |
175 | ax.plt = ax.pcolormesh(x , y, spc1.T, |
|
175 | ax.plt = ax.pcolormesh(x , y, spc1.T, | |
176 | vmin=self.zmin, |
|
176 | vmin=self.zmin, | |
177 | vmax=self.zmax, |
|
177 | vmax=self.zmax, | |
178 | cmap=plt.get_cmap(self.colormap) |
|
178 | cmap=plt.get_cmap(self.colormap) | |
179 | ) |
|
179 | ) | |
180 |
else: |
|
180 | else: | |
181 | ax.plt.set_array(spc1.T.ravel()) |
|
181 | ax.plt.set_array(spc1.T.ravel()) | |
182 | self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise)) |
|
182 | self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise)) | |
183 |
|
183 | |||
184 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) |
|
184 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) | |
185 | coh = numpy.abs(out) |
|
185 | coh = numpy.abs(out) | |
186 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi |
|
186 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi | |
187 |
|
187 | |||
188 | ax = self.axes[4 * n + 2] |
|
188 | ax = self.axes[4 * n + 2] | |
189 | if ax.firsttime: |
|
189 | if ax.firsttime: | |
190 | ax.plt = ax.pcolormesh(x, y, coh.T, |
|
190 | ax.plt = ax.pcolormesh(x, y, coh.T, | |
191 | vmin=0, |
|
191 | vmin=0, | |
192 | vmax=1, |
|
192 | vmax=1, | |
193 | cmap=plt.get_cmap(self.colormap_coh) |
|
193 | cmap=plt.get_cmap(self.colormap_coh) | |
194 | ) |
|
194 | ) | |
195 | else: |
|
195 | else: | |
196 | ax.plt.set_array(coh.T.ravel()) |
|
196 | ax.plt.set_array(coh.T.ravel()) | |
197 | self.titles.append( |
|
197 | self.titles.append( | |
198 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) |
|
198 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
199 |
|
199 | |||
200 | ax = self.axes[4 * n + 3] |
|
200 | ax = self.axes[4 * n + 3] | |
201 | if ax.firsttime: |
|
201 | if ax.firsttime: | |
202 | ax.plt = ax.pcolormesh(x, y, phase.T, |
|
202 | ax.plt = ax.pcolormesh(x, y, phase.T, | |
203 | vmin=-180, |
|
203 | vmin=-180, | |
204 | vmax=180, |
|
204 | vmax=180, | |
205 |
cmap=plt.get_cmap(self.colormap_phase) |
|
205 | cmap=plt.get_cmap(self.colormap_phase) | |
206 | ) |
|
206 | ) | |
207 | else: |
|
207 | else: | |
208 | ax.plt.set_array(phase.T.ravel()) |
|
208 | ax.plt.set_array(phase.T.ravel()) | |
209 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) |
|
209 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |
210 |
|
210 | |||
211 |
|
211 | |||
212 | class SpectralMomentsPlot(SpectraPlot): |
|
212 | class SpectralMomentsPlot(SpectraPlot): | |
213 | ''' |
|
213 | ''' | |
214 | Plot for Spectral Moments |
|
214 | Plot for Spectral Moments | |
215 | ''' |
|
215 | ''' | |
216 | CODE = 'spc_moments' |
|
216 | CODE = 'spc_moments' | |
217 | colormap = 'jro' |
|
217 | colormap = 'jro' | |
218 | plot_name = 'SpectralMoments' |
|
218 | plot_name = 'SpectralMoments' | |
219 | plot_type = 'pcolor' |
|
219 | plot_type = 'pcolor' | |
220 |
|
220 | |||
221 |
|
221 | |||
222 | class RTIPlot(Plot): |
|
222 | class RTIPlot(Plot): | |
223 | ''' |
|
223 | ''' | |
224 | Plot for RTI data |
|
224 | Plot for RTI data | |
225 | ''' |
|
225 | ''' | |
226 |
|
226 | |||
227 | CODE = 'rti' |
|
227 | CODE = 'rti' | |
228 | colormap = 'jro' |
|
228 | colormap = 'jro' | |
229 | plot_name = 'RTI' |
|
229 | plot_name = 'RTI' | |
230 | plot_type = 'pcolorbuffer' |
|
230 | plot_type = 'pcolorbuffer' | |
231 |
|
231 | |||
232 | def setup(self): |
|
232 | def setup(self): | |
233 | self.xaxis = 'time' |
|
233 | self.xaxis = 'time' | |
234 | self.ncols = 1 |
|
234 | self.ncols = 1 | |
235 | self.nrows = len(self.data.channels) |
|
235 | self.nrows = len(self.data.channels) | |
236 | self.nplots = len(self.data.channels) |
|
236 | self.nplots = len(self.data.channels) | |
237 | self.ylabel = 'Range [km]' |
|
237 | self.ylabel = 'Range [km]' | |
238 | self.cb_label = 'dB' |
|
238 | self.cb_label = 'dB' | |
239 | self.titles = ['{} Channel {}'.format( |
|
239 | self.titles = ['{} Channel {}'.format( | |
240 | self.CODE.upper(), x) for x in range(self.nrows)] |
|
240 | self.CODE.upper(), x) for x in range(self.nrows)] | |
241 |
|
241 | |||
242 | def plot(self): |
|
242 | def plot(self): | |
243 | self.x = self.data.times |
|
243 | self.x = self.data.times | |
244 | self.y = self.data.heights |
|
244 | self.y = self.data.heights | |
245 | self.z = self.data[self.CODE] |
|
245 | self.z = self.data[self.CODE] | |
246 | self.z = numpy.ma.masked_invalid(self.z) |
|
246 | self.z = numpy.ma.masked_invalid(self.z) | |
247 |
|
247 | |||
248 | if self.decimation is None: |
|
248 | if self.decimation is None: | |
249 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
249 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
250 | else: |
|
250 | else: | |
251 | x, y, z = self.fill_gaps(*self.decimate()) |
|
251 | x, y, z = self.fill_gaps(*self.decimate()) | |
252 |
|
252 | |||
253 | for n, ax in enumerate(self.axes): |
|
253 | for n, ax in enumerate(self.axes): | |
254 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) |
|
254 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
255 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) |
|
255 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |
256 | if ax.firsttime: |
|
256 | if ax.firsttime: | |
257 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
257 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
258 | vmin=self.zmin, |
|
258 | vmin=self.zmin, | |
259 | vmax=self.zmax, |
|
259 | vmax=self.zmax, | |
260 | cmap=plt.get_cmap(self.colormap) |
|
260 | cmap=plt.get_cmap(self.colormap) | |
261 | ) |
|
261 | ) | |
262 | if self.showprofile: |
|
262 | if self.showprofile: | |
263 | ax.plot_profile = self.pf_axes[n].plot( |
|
263 | ax.plot_profile = self.pf_axes[n].plot( | |
264 | self.data['rti'][n][-1], self.y)[0] |
|
264 | self.data['rti'][n][-1], self.y)[0] | |
265 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, |
|
265 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, | |
266 | color="k", linestyle="dashed", lw=1)[0] |
|
266 | color="k", linestyle="dashed", lw=1)[0] | |
267 | else: |
|
267 | else: | |
268 | ax.collections.remove(ax.collections[0]) |
|
268 | ax.collections.remove(ax.collections[0]) | |
269 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
269 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
270 | vmin=self.zmin, |
|
270 | vmin=self.zmin, | |
271 | vmax=self.zmax, |
|
271 | vmax=self.zmax, | |
272 | cmap=plt.get_cmap(self.colormap) |
|
272 | cmap=plt.get_cmap(self.colormap) | |
273 | ) |
|
273 | ) | |
274 | if self.showprofile: |
|
274 | if self.showprofile: | |
275 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) |
|
275 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |
276 | ax.plot_noise.set_data(numpy.repeat( |
|
276 | ax.plot_noise.set_data(numpy.repeat( | |
277 | self.data['noise'][n][-1], len(self.y)), self.y) |
|
277 | self.data['noise'][n][-1], len(self.y)), self.y) | |
278 |
|
278 | |||
279 |
|
279 | |||
280 | class CoherencePlot(RTIPlot): |
|
280 | class CoherencePlot(RTIPlot): | |
281 | ''' |
|
281 | ''' | |
282 | Plot for Coherence data |
|
282 | Plot for Coherence data | |
283 | ''' |
|
283 | ''' | |
284 |
|
284 | |||
285 | CODE = 'coh' |
|
285 | CODE = 'coh' | |
286 | plot_name = 'Coherence' |
|
286 | plot_name = 'Coherence' | |
287 |
|
287 | |||
288 | def setup(self): |
|
288 | def setup(self): | |
289 | self.xaxis = 'time' |
|
289 | self.xaxis = 'time' | |
290 | self.ncols = 1 |
|
290 | self.ncols = 1 | |
291 | self.nrows = len(self.data.pairs) |
|
291 | self.nrows = len(self.data.pairs) | |
292 | self.nplots = len(self.data.pairs) |
|
292 | self.nplots = len(self.data.pairs) | |
293 | self.ylabel = 'Range [km]' |
|
293 | self.ylabel = 'Range [km]' | |
294 | if self.CODE == 'coh': |
|
294 | if self.CODE == 'coh': | |
295 | self.cb_label = '' |
|
295 | self.cb_label = '' | |
296 | self.titles = [ |
|
296 | self.titles = [ | |
297 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
297 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
298 | else: |
|
298 | else: | |
299 | self.cb_label = 'Degrees' |
|
299 | self.cb_label = 'Degrees' | |
300 | self.titles = [ |
|
300 | self.titles = [ | |
301 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
301 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
302 |
|
302 | |||
303 |
|
303 | |||
304 | class PhasePlot(CoherencePlot): |
|
304 | class PhasePlot(CoherencePlot): | |
305 | ''' |
|
305 | ''' | |
306 | Plot for Phase map data |
|
306 | Plot for Phase map data | |
307 | ''' |
|
307 | ''' | |
308 |
|
308 | |||
309 | CODE = 'phase' |
|
309 | CODE = 'phase' | |
310 | colormap = 'seismic' |
|
310 | colormap = 'seismic' | |
311 | plot_name = 'Phase' |
|
311 | plot_name = 'Phase' | |
312 |
|
312 | |||
313 |
|
313 | |||
314 | class NoisePlot(Plot): |
|
314 | class NoisePlot(Plot): | |
315 | ''' |
|
315 | ''' | |
316 |
Plot for noise |
|
316 | Plot for noise | |
317 | ''' |
|
317 | ''' | |
318 |
|
318 | |||
319 | CODE = 'noise' |
|
319 | CODE = 'noise' | |
320 | plot_name = 'Noise' |
|
320 | plot_name = 'Noise' | |
321 | plot_type = 'scatterbuffer' |
|
321 | plot_type = 'scatterbuffer' | |
322 |
|
322 | |||
323 |
|
323 | |||
324 | def setup(self): |
|
324 | def setup(self): | |
325 | self.xaxis = 'time' |
|
325 | self.xaxis = 'time' | |
326 | self.ncols = 1 |
|
326 | self.ncols = 1 | |
327 | self.nrows = 1 |
|
327 | self.nrows = 1 | |
328 | self.nplots = 1 |
|
328 | self.nplots = 1 | |
329 | self.ylabel = 'Intensity [dB]' |
|
329 | self.ylabel = 'Intensity [dB]' | |
330 | self.titles = ['Noise'] |
|
330 | self.titles = ['Noise'] | |
331 | self.colorbar = False |
|
331 | self.colorbar = False | |
332 |
|
332 | |||
333 | def plot(self): |
|
333 | def plot(self): | |
334 |
|
334 | |||
335 | x = self.data.times |
|
335 | x = self.data.times | |
336 | xmin = self.data.min_time |
|
336 | xmin = self.data.min_time | |
337 | xmax = xmin + self.xrange * 60 * 60 |
|
337 | xmax = xmin + self.xrange * 60 * 60 | |
338 | Y = self.data[self.CODE] |
|
338 | Y = self.data[self.CODE] | |
339 |
|
339 | |||
340 | if self.axes[0].firsttime: |
|
340 | if self.axes[0].firsttime: | |
341 | for ch in self.data.channels: |
|
341 | for ch in self.data.channels: | |
342 | y = Y[ch] |
|
342 | y = Y[ch] | |
343 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
343 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
344 | plt.legend() |
|
344 | plt.legend() | |
345 | else: |
|
345 | else: | |
346 | for ch in self.data.channels: |
|
346 | for ch in self.data.channels: | |
347 | y = Y[ch] |
|
347 | y = Y[ch] | |
348 | self.axes[0].lines[ch].set_data(x, y) |
|
348 | self.axes[0].lines[ch].set_data(x, y) | |
349 |
|
349 | |||
350 | self.ymin = numpy.nanmin(Y) - 5 |
|
350 | self.ymin = numpy.nanmin(Y) - 5 | |
351 | self.ymax = numpy.nanmax(Y) + 5 |
|
351 | self.ymax = numpy.nanmax(Y) + 5 | |
352 |
|
352 | |||
353 |
|
353 | |||
354 | class SnrPlot(RTIPlot): |
|
354 | class SnrPlot(RTIPlot): | |
355 | ''' |
|
355 | ''' | |
356 | Plot for SNR Data |
|
356 | Plot for SNR Data | |
357 | ''' |
|
357 | ''' | |
358 |
|
358 | |||
359 | CODE = 'snr' |
|
359 | CODE = 'snr' | |
360 | colormap = 'jet' |
|
360 | colormap = 'jet' | |
361 | plot_name = 'SNR' |
|
361 | plot_name = 'SNR' | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | class DopplerPlot(RTIPlot): |
|
364 | class DopplerPlot(RTIPlot): | |
365 | ''' |
|
365 | ''' | |
366 | Plot for DOPPLER Data (1st moment) |
|
366 | Plot for DOPPLER Data (1st moment) | |
367 | ''' |
|
367 | ''' | |
368 |
|
368 | |||
369 | CODE = 'dop' |
|
369 | CODE = 'dop' | |
370 | colormap = 'jet' |
|
370 | colormap = 'jet' | |
371 | plot_name = 'DopplerShift' |
|
371 | plot_name = 'DopplerShift' | |
372 |
|
372 | |||
373 |
|
373 | |||
374 | class PowerPlot(RTIPlot): |
|
374 | class PowerPlot(RTIPlot): | |
375 | ''' |
|
375 | ''' | |
376 | Plot for Power Data (0 moment) |
|
376 | Plot for Power Data (0 moment) | |
377 | ''' |
|
377 | ''' | |
378 |
|
378 | |||
379 | CODE = 'pow' |
|
379 | CODE = 'pow' | |
380 | colormap = 'jet' |
|
380 | colormap = 'jet' | |
381 | plot_name = 'TotalPower' |
|
381 | plot_name = 'TotalPower' | |
382 |
|
382 | |||
383 |
|
383 | |||
384 | class SpectralWidthPlot(RTIPlot): |
|
384 | class SpectralWidthPlot(RTIPlot): | |
385 | ''' |
|
385 | ''' | |
386 | Plot for Spectral Width Data (2nd moment) |
|
386 | Plot for Spectral Width Data (2nd moment) | |
387 | ''' |
|
387 | ''' | |
388 |
|
388 | |||
389 | CODE = 'width' |
|
389 | CODE = 'width' | |
390 | colormap = 'jet' |
|
390 | colormap = 'jet' | |
391 | plot_name = 'SpectralWidth' |
|
391 | plot_name = 'SpectralWidth' | |
392 |
|
392 | |||
393 |
|
393 | |||
394 | class SkyMapPlot(Plot): |
|
394 | class SkyMapPlot(Plot): | |
395 | ''' |
|
395 | ''' | |
396 | Plot for meteors detection data |
|
396 | Plot for meteors detection data | |
397 | ''' |
|
397 | ''' | |
398 |
|
398 | |||
399 | CODE = 'param' |
|
399 | CODE = 'param' | |
400 |
|
400 | |||
401 | def setup(self): |
|
401 | def setup(self): | |
402 |
|
402 | |||
403 | self.ncols = 1 |
|
403 | self.ncols = 1 | |
404 | self.nrows = 1 |
|
404 | self.nrows = 1 | |
405 | self.width = 7.2 |
|
405 | self.width = 7.2 | |
406 | self.height = 7.2 |
|
406 | self.height = 7.2 | |
407 | self.nplots = 1 |
|
407 | self.nplots = 1 | |
408 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
408 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
409 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
409 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
410 | self.polar = True |
|
410 | self.polar = True | |
411 | self.ymin = -180 |
|
411 | self.ymin = -180 | |
412 | self.ymax = 180 |
|
412 | self.ymax = 180 | |
413 | self.colorbar = False |
|
413 | self.colorbar = False | |
414 |
|
414 | |||
415 | def plot(self): |
|
415 | def plot(self): | |
416 |
|
416 | |||
417 | arrayParameters = numpy.concatenate(self.data['param']) |
|
417 | arrayParameters = numpy.concatenate(self.data['param']) | |
418 | error = arrayParameters[:, -1] |
|
418 | error = arrayParameters[:, -1] | |
419 | indValid = numpy.where(error == 0)[0] |
|
419 | indValid = numpy.where(error == 0)[0] | |
420 | finalMeteor = arrayParameters[indValid, :] |
|
420 | finalMeteor = arrayParameters[indValid, :] | |
421 | finalAzimuth = finalMeteor[:, 3] |
|
421 | finalAzimuth = finalMeteor[:, 3] | |
422 | finalZenith = finalMeteor[:, 4] |
|
422 | finalZenith = finalMeteor[:, 4] | |
423 |
|
423 | |||
424 | x = finalAzimuth * numpy.pi / 180 |
|
424 | x = finalAzimuth * numpy.pi / 180 | |
425 | y = finalZenith |
|
425 | y = finalZenith | |
426 |
|
426 | |||
427 | ax = self.axes[0] |
|
427 | ax = self.axes[0] | |
428 |
|
428 | |||
429 | if ax.firsttime: |
|
429 | if ax.firsttime: | |
430 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
430 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
431 | else: |
|
431 | else: | |
432 | ax.plot.set_data(x, y) |
|
432 | ax.plot.set_data(x, y) | |
433 |
|
433 | |||
434 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
434 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') | |
435 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
435 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') | |
436 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
436 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
437 | dt2, |
|
437 | dt2, | |
438 | len(x)) |
|
438 | len(x)) | |
439 | self.titles[0] = title |
|
439 | self.titles[0] = title | |
440 |
|
440 | |||
441 |
|
441 | |||
442 | class ParametersPlot(RTIPlot): |
|
442 | class ParametersPlot(RTIPlot): | |
443 | ''' |
|
443 | ''' | |
444 | Plot for data_param object |
|
444 | Plot for data_param object | |
445 | ''' |
|
445 | ''' | |
446 |
|
446 | |||
447 | CODE = 'param' |
|
447 | CODE = 'param' | |
448 | colormap = 'seismic' |
|
448 | colormap = 'seismic' | |
449 | plot_name = 'Parameters' |
|
449 | plot_name = 'Parameters' | |
450 |
|
450 | |||
451 | def setup(self): |
|
451 | def setup(self): | |
452 | self.xaxis = 'time' |
|
452 | self.xaxis = 'time' | |
453 | self.ncols = 1 |
|
453 | self.ncols = 1 | |
454 | self.nrows = self.data.shape(self.CODE)[0] |
|
454 | self.nrows = self.data.shape(self.CODE)[0] | |
455 | self.nplots = self.nrows |
|
455 | self.nplots = self.nrows | |
456 | if self.showSNR: |
|
456 | if self.showSNR: | |
457 | self.nrows += 1 |
|
457 | self.nrows += 1 | |
458 | self.nplots += 1 |
|
458 | self.nplots += 1 | |
459 |
|
459 | |||
460 | self.ylabel = 'Height [km]' |
|
460 | self.ylabel = 'Height [km]' | |
461 | if not self.titles: |
|
461 | if not self.titles: | |
462 | self.titles = self.data.parameters \ |
|
462 | self.titles = self.data.parameters \ | |
463 | if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] |
|
463 | if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] | |
464 | if self.showSNR: |
|
464 | if self.showSNR: | |
465 | self.titles.append('SNR') |
|
465 | self.titles.append('SNR') | |
466 |
|
466 | |||
467 | def plot(self): |
|
467 | def plot(self): | |
468 | self.data.normalize_heights() |
|
468 | self.data.normalize_heights() | |
469 | self.x = self.data.times |
|
469 | self.x = self.data.times | |
470 | self.y = self.data.heights |
|
470 | self.y = self.data.heights | |
471 | if self.showSNR: |
|
471 | if self.showSNR: | |
472 | self.z = numpy.concatenate( |
|
472 | self.z = numpy.concatenate( | |
473 | (self.data[self.CODE], self.data['snr']) |
|
473 | (self.data[self.CODE], self.data['snr']) | |
474 | ) |
|
474 | ) | |
475 | else: |
|
475 | else: | |
476 | self.z = self.data[self.CODE] |
|
476 | self.z = self.data[self.CODE] | |
477 |
|
477 | |||
478 | self.z = numpy.ma.masked_invalid(self.z) |
|
478 | self.z = numpy.ma.masked_invalid(self.z) | |
479 |
|
479 | |||
480 | if self.decimation is None: |
|
480 | if self.decimation is None: | |
481 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
481 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
482 | else: |
|
482 | else: | |
483 | x, y, z = self.fill_gaps(*self.decimate()) |
|
483 | x, y, z = self.fill_gaps(*self.decimate()) | |
484 |
|
484 | |||
485 | for n, ax in enumerate(self.axes): |
|
485 | for n, ax in enumerate(self.axes): | |
486 |
|
486 | |||
487 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
487 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
488 | self.z[n]) |
|
488 | self.z[n]) | |
489 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
489 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
490 | self.z[n]) |
|
490 | self.z[n]) | |
491 |
|
491 | |||
492 | if ax.firsttime: |
|
492 | if ax.firsttime: | |
493 | if self.zlimits is not None: |
|
493 | if self.zlimits is not None: | |
494 | self.zmin, self.zmax = self.zlimits[n] |
|
494 | self.zmin, self.zmax = self.zlimits[n] | |
495 |
|
495 | |||
496 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
496 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
497 | vmin=self.zmin, |
|
497 | vmin=self.zmin, | |
498 | vmax=self.zmax, |
|
498 | vmax=self.zmax, | |
499 | cmap=self.cmaps[n] |
|
499 | cmap=self.cmaps[n] | |
500 | ) |
|
500 | ) | |
501 | else: |
|
501 | else: | |
502 | if self.zlimits is not None: |
|
502 | if self.zlimits is not None: | |
503 | self.zmin, self.zmax = self.zlimits[n] |
|
503 | self.zmin, self.zmax = self.zlimits[n] | |
504 | ax.collections.remove(ax.collections[0]) |
|
504 | ax.collections.remove(ax.collections[0]) | |
505 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
505 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
506 | vmin=self.zmin, |
|
506 | vmin=self.zmin, | |
507 | vmax=self.zmax, |
|
507 | vmax=self.zmax, | |
508 | cmap=self.cmaps[n] |
|
508 | cmap=self.cmaps[n] | |
509 | ) |
|
509 | ) | |
510 |
|
510 | |||
511 |
|
511 | |||
512 | class OutputPlot(ParametersPlot): |
|
512 | class OutputPlot(ParametersPlot): | |
513 | ''' |
|
513 | ''' | |
514 | Plot data_output object |
|
514 | Plot data_output object | |
515 | ''' |
|
515 | ''' | |
516 |
|
516 | |||
517 | CODE = 'output' |
|
517 | CODE = 'output' | |
518 | colormap = 'seismic' |
|
518 | colormap = 'seismic' | |
519 | plot_name = 'Output' |
|
519 | plot_name = 'Output' | |
520 |
|
520 | |||
521 |
|
521 | |||
522 | class PolarMapPlot(Plot): |
|
522 | class PolarMapPlot(Plot): | |
523 | ''' |
|
523 | ''' | |
524 | Plot for weather radar |
|
524 | Plot for weather radar | |
525 | ''' |
|
525 | ''' | |
526 |
|
526 | |||
527 | CODE = 'param' |
|
527 | CODE = 'param' | |
528 | colormap = 'seismic' |
|
528 | colormap = 'seismic' | |
529 |
|
529 | |||
530 | def setup(self): |
|
530 | def setup(self): | |
531 | self.ncols = 1 |
|
531 | self.ncols = 1 | |
532 | self.nrows = 1 |
|
532 | self.nrows = 1 | |
533 | self.width = 9 |
|
533 | self.width = 9 | |
534 | self.height = 8 |
|
534 | self.height = 8 | |
535 | self.mode = self.data.meta['mode'] |
|
535 | self.mode = self.data.meta['mode'] | |
536 | if self.channels is not None: |
|
536 | if self.channels is not None: | |
537 | self.nplots = len(self.channels) |
|
537 | self.nplots = len(self.channels) | |
538 | self.nrows = len(self.channels) |
|
538 | self.nrows = len(self.channels) | |
539 | else: |
|
539 | else: | |
540 | self.nplots = self.data.shape(self.CODE)[0] |
|
540 | self.nplots = self.data.shape(self.CODE)[0] | |
541 | self.nrows = self.nplots |
|
541 | self.nrows = self.nplots | |
542 | self.channels = list(range(self.nplots)) |
|
542 | self.channels = list(range(self.nplots)) | |
543 | if self.mode == 'E': |
|
543 | if self.mode == 'E': | |
544 | self.xlabel = 'Longitude' |
|
544 | self.xlabel = 'Longitude' | |
545 | self.ylabel = 'Latitude' |
|
545 | self.ylabel = 'Latitude' | |
546 | else: |
|
546 | else: | |
547 | self.xlabel = 'Range (km)' |
|
547 | self.xlabel = 'Range (km)' | |
548 | self.ylabel = 'Height (km)' |
|
548 | self.ylabel = 'Height (km)' | |
549 | self.bgcolor = 'white' |
|
549 | self.bgcolor = 'white' | |
550 | self.cb_labels = self.data.meta['units'] |
|
550 | self.cb_labels = self.data.meta['units'] | |
551 | self.lat = self.data.meta['latitude'] |
|
551 | self.lat = self.data.meta['latitude'] | |
552 | self.lon = self.data.meta['longitude'] |
|
552 | self.lon = self.data.meta['longitude'] | |
553 | self.xmin, self.xmax = float( |
|
553 | self.xmin, self.xmax = float( | |
554 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) |
|
554 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | |
555 | self.ymin, self.ymax = float( |
|
555 | self.ymin, self.ymax = float( | |
556 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) |
|
556 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) | |
557 | # self.polar = True |
|
557 | # self.polar = True | |
558 |
|
558 | |||
559 | def plot(self): |
|
559 | def plot(self): | |
560 |
|
560 | |||
561 | for n, ax in enumerate(self.axes): |
|
561 | for n, ax in enumerate(self.axes): | |
562 | data = self.data['param'][self.channels[n]] |
|
562 | data = self.data['param'][self.channels[n]] | |
563 |
|
563 | |||
564 | zeniths = numpy.linspace( |
|
564 | zeniths = numpy.linspace( | |
565 | 0, self.data.meta['max_range'], data.shape[1]) |
|
565 | 0, self.data.meta['max_range'], data.shape[1]) | |
566 | if self.mode == 'E': |
|
566 | if self.mode == 'E': | |
567 | azimuths = -numpy.radians(self.data.heights)+numpy.pi/2 |
|
567 | azimuths = -numpy.radians(self.data.heights)+numpy.pi/2 | |
568 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
568 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
569 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
569 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( | |
570 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
570 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) | |
571 | x = km2deg(x) + self.lon |
|
571 | x = km2deg(x) + self.lon | |
572 | y = km2deg(y) + self.lat |
|
572 | y = km2deg(y) + self.lat | |
573 | else: |
|
573 | else: | |
574 | azimuths = numpy.radians(self.data.heights) |
|
574 | azimuths = numpy.radians(self.data.heights) | |
575 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
575 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
576 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
576 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |
577 | self.y = zeniths |
|
577 | self.y = zeniths | |
578 |
|
578 | |||
579 | if ax.firsttime: |
|
579 | if ax.firsttime: | |
580 | if self.zlimits is not None: |
|
580 | if self.zlimits is not None: | |
581 | self.zmin, self.zmax = self.zlimits[n] |
|
581 | self.zmin, self.zmax = self.zlimits[n] | |
582 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
582 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
583 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
583 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
584 | vmin=self.zmin, |
|
584 | vmin=self.zmin, | |
585 | vmax=self.zmax, |
|
585 | vmax=self.zmax, | |
586 | cmap=self.cmaps[n]) |
|
586 | cmap=self.cmaps[n]) | |
587 | else: |
|
587 | else: | |
588 | if self.zlimits is not None: |
|
588 | if self.zlimits is not None: | |
589 | self.zmin, self.zmax = self.zlimits[n] |
|
589 | self.zmin, self.zmax = self.zlimits[n] | |
590 | ax.collections.remove(ax.collections[0]) |
|
590 | ax.collections.remove(ax.collections[0]) | |
591 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
591 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
592 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
592 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
593 | vmin=self.zmin, |
|
593 | vmin=self.zmin, | |
594 | vmax=self.zmax, |
|
594 | vmax=self.zmax, | |
595 | cmap=self.cmaps[n]) |
|
595 | cmap=self.cmaps[n]) | |
596 |
|
596 | |||
597 | if self.mode == 'A': |
|
597 | if self.mode == 'A': | |
598 | continue |
|
598 | continue | |
599 |
|
599 | |||
600 | # plot district names |
|
600 | # plot district names | |
601 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
601 | f = open('/data/workspace/schain_scripts/distrito.csv') | |
602 | for line in f: |
|
602 | for line in f: | |
603 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
603 | label, lon, lat = [s.strip() for s in line.split(',') if s] | |
604 | lat = float(lat) |
|
604 | lat = float(lat) | |
605 | lon = float(lon) |
|
605 | lon = float(lon) | |
606 | # ax.plot(lon, lat, '.b', ms=2) |
|
606 | # ax.plot(lon, lat, '.b', ms=2) | |
607 | ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
607 | ax.text(lon, lat, label.decode('utf8'), ha='center', | |
608 | va='bottom', size='8', color='black') |
|
608 | va='bottom', size='8', color='black') | |
609 |
|
609 | |||
610 | # plot limites |
|
610 | # plot limites | |
611 | limites = [] |
|
611 | limites = [] | |
612 | tmp = [] |
|
612 | tmp = [] | |
613 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
613 | for line in open('/data/workspace/schain_scripts/lima.csv'): | |
614 | if '#' in line: |
|
614 | if '#' in line: | |
615 | if tmp: |
|
615 | if tmp: | |
616 | limites.append(tmp) |
|
616 | limites.append(tmp) | |
617 | tmp = [] |
|
617 | tmp = [] | |
618 | continue |
|
618 | continue | |
619 | values = line.strip().split(',') |
|
619 | values = line.strip().split(',') | |
620 | tmp.append((float(values[0]), float(values[1]))) |
|
620 | tmp.append((float(values[0]), float(values[1]))) | |
621 | for points in limites: |
|
621 | for points in limites: | |
622 | ax.add_patch( |
|
622 | ax.add_patch( | |
623 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) |
|
623 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |
624 |
|
624 | |||
625 | # plot Cuencas |
|
625 | # plot Cuencas | |
626 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
626 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): | |
627 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
627 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) | |
628 | values = [line.strip().split(',') for line in f] |
|
628 | values = [line.strip().split(',') for line in f] | |
629 | points = [(float(s[0]), float(s[1])) for s in values] |
|
629 | points = [(float(s[0]), float(s[1])) for s in values] | |
630 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
630 | ax.add_patch(Polygon(points, ec='b', fc='none')) | |
631 |
|
631 | |||
632 | # plot grid |
|
632 | # plot grid | |
633 | for r in (15, 30, 45, 60): |
|
633 | for r in (15, 30, 45, 60): | |
634 | ax.add_artist(plt.Circle((self.lon, self.lat), |
|
634 | ax.add_artist(plt.Circle((self.lon, self.lat), | |
635 | km2deg(r), color='0.6', fill=False, lw=0.2)) |
|
635 | km2deg(r), color='0.6', fill=False, lw=0.2)) | |
636 | ax.text( |
|
636 | ax.text( | |
637 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
637 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), | |
638 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
638 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), | |
639 | '{}km'.format(r), |
|
639 | '{}km'.format(r), | |
640 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
640 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') | |
641 |
|
641 | |||
642 | if self.mode == 'E': |
|
642 | if self.mode == 'E': | |
643 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
643 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) | |
644 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
644 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) | |
645 | else: |
|
645 | else: | |
646 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
646 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) | |
647 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
647 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) | |
648 |
|
648 | |||
649 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
649 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
650 | self.titles = ['{} {}'.format( |
|
650 | self.titles = ['{} {}'.format( | |
651 | self.data.parameters[x], title) for x in self.channels] |
|
651 | self.data.parameters[x], title) for x in self.channels] | |
652 |
|
652 | |||
653 |
|
653 | |||
654 | class ScopePlot(Plot): |
|
654 | class ScopePlot(Plot): | |
655 |
|
655 | |||
656 | ''' |
|
656 | ''' | |
657 | Plot for Scope |
|
657 | Plot for Scope | |
658 |
''' |
|
658 | ''' | |
659 |
|
659 | |||
660 | CODE = 'scope' |
|
660 | CODE = 'scope' | |
661 | plot_name = 'Scope' |
|
661 | plot_name = 'Scope' | |
662 | plot_type = 'scatter' |
|
662 | plot_type = 'scatter' | |
663 |
|
663 | |||
664 | def setup(self): |
|
664 | def setup(self): | |
665 |
|
665 | |||
666 | self.xaxis = 'Range (Km)' |
|
666 | self.xaxis = 'Range (Km)' | |
667 | self.ncols = 1 |
|
667 | self.ncols = 1 | |
668 | self.nrows = 1 |
|
668 | self.nrows = 1 | |
669 | self.nplots = 1 |
|
669 | self.nplots = 1 | |
670 | self.ylabel = 'Intensity [dB]' |
|
670 | self.ylabel = 'Intensity [dB]' | |
671 | self.titles = ['Scope'] |
|
671 | self.titles = ['Scope'] | |
672 | self.colorbar = False |
|
672 | self.colorbar = False | |
673 | colspan = 3 |
|
673 | colspan = 3 | |
674 | rowspan = 1 |
|
674 | rowspan = 1 | |
675 |
|
675 | |||
676 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
676 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): | |
677 |
|
677 | |||
678 | yreal = y[channelIndexList,:].real |
|
678 | yreal = y[channelIndexList,:].real | |
679 | yimag = y[channelIndexList,:].imag |
|
679 | yimag = y[channelIndexList,:].imag | |
680 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
680 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
681 | self.xlabel = "Range (Km)" |
|
681 | self.xlabel = "Range (Km)" | |
682 | self.ylabel = "Intensity - IQ" |
|
682 | self.ylabel = "Intensity - IQ" | |
683 |
|
683 | |||
684 | self.y = yreal |
|
684 | self.y = yreal | |
685 | self.x = x |
|
685 | self.x = x | |
686 | self.xmin = min(x) |
|
686 | self.xmin = min(x) | |
687 | self.xmax = max(x) |
|
687 | self.xmax = max(x) | |
688 |
|
||||
689 |
|
688 | |||
690 | self.titles[0] = title |
|
689 | ||
|
690 | self.titles[0] = title | |||
691 |
|
691 | |||
692 | for i,ax in enumerate(self.axes): |
|
692 | for i,ax in enumerate(self.axes): | |
693 | title = "Channel %d" %(i) |
|
693 | title = "Channel %d" %(i) | |
694 | if ax.firsttime: |
|
694 | if ax.firsttime: | |
695 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] |
|
695 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] | |
696 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] |
|
696 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] | |
697 | else: |
|
697 | else: | |
698 | #pass |
|
698 | #pass | |
699 | ax.plt_r.set_data(x, yreal[i,:]) |
|
699 | ax.plt_r.set_data(x, yreal[i,:]) | |
700 | ax.plt_i.set_data(x, yimag[i,:]) |
|
700 | ax.plt_i.set_data(x, yimag[i,:]) | |
701 |
|
701 | |||
702 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
702 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): | |
703 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
703 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | |
704 | yreal = y.real |
|
704 | yreal = y.real | |
705 | self.y = yreal |
|
705 | self.y = yreal | |
706 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
706 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
707 | self.xlabel = "Range (Km)" |
|
707 | self.xlabel = "Range (Km)" | |
708 | self.ylabel = "Intensity" |
|
708 | self.ylabel = "Intensity" | |
709 | self.xmin = min(x) |
|
709 | self.xmin = min(x) | |
710 | self.xmax = max(x) |
|
710 | self.xmax = max(x) | |
711 |
|
711 | |||
712 |
|
712 | |||
713 | self.titles[0] = title |
|
713 | self.titles[0] = title | |
714 |
|
714 | |||
715 | for i,ax in enumerate(self.axes): |
|
715 | for i,ax in enumerate(self.axes): | |
716 | title = "Channel %d" %(i) |
|
716 | title = "Channel %d" %(i) | |
717 |
|
717 | |||
718 | ychannel = yreal[i,:] |
|
718 | ychannel = yreal[i,:] | |
719 |
|
719 | |||
720 |
if ax.firsttime: |
|
720 | if ax.firsttime: | |
721 | ax.plt_r = ax.plot(x, ychannel)[0] |
|
721 | ax.plt_r = ax.plot(x, ychannel)[0] | |
722 | else: |
|
722 | else: | |
723 | #pass |
|
723 | #pass | |
724 | ax.plt_r.set_data(x, ychannel) |
|
724 | ax.plt_r.set_data(x, ychannel) | |
725 |
|
725 | |||
726 |
|
726 | |||
727 | def plot(self): |
|
727 | def plot(self): | |
728 |
|
728 | |||
729 | if self.channels: |
|
729 | if self.channels: | |
730 | channels = self.channels |
|
730 | channels = self.channels | |
731 | else: |
|
731 | else: | |
732 | channels = self.data.channels |
|
732 | channels = self.data.channels | |
733 |
|
733 | |||
734 |
|
734 | |||
735 |
|
735 | |||
736 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) |
|
736 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) | |
737 |
|
737 | |||
738 | scope = self.data['scope'] |
|
738 | scope = self.data['scope'] | |
739 |
|
739 | |||
740 |
|
740 | |||
741 | if self.data.flagDataAsBlock: |
|
741 | if self.data.flagDataAsBlock: | |
742 |
|
742 | |||
743 | for i in range(self.data.nProfiles): |
|
743 | for i in range(self.data.nProfiles): | |
744 |
|
744 | |||
745 | wintitle1 = " [Profile = %d] " %i |
|
745 | wintitle1 = " [Profile = %d] " %i | |
746 |
|
746 | |||
747 | if self.type == "power": |
|
747 | if self.type == "power": | |
748 |
self.plot_power(self.data.heights, |
|
748 | self.plot_power(self.data.heights, | |
749 |
scope[:,i,:], |
|
749 | scope[:,i,:], | |
750 | channels, |
|
750 | channels, | |
751 |
thisDatetime, |
|
751 | thisDatetime, | |
752 | wintitle1 |
|
752 | wintitle1 | |
753 | ) |
|
753 | ) | |
754 |
|
754 | |||
755 | if self.type == "iq": |
|
755 | if self.type == "iq": | |
756 |
self.plot_iq(self.data.heights, |
|
756 | self.plot_iq(self.data.heights, | |
757 | scope[:,i,:], |
|
757 | scope[:,i,:], | |
758 | channels, |
|
758 | channels, | |
759 |
thisDatetime, |
|
759 | thisDatetime, | |
760 |
wintitle1 |
|
760 | wintitle1 | |
761 | ) |
|
761 | ) | |
762 | else: |
|
762 | else: | |
763 | wintitle = " [Profile = %d] " %self.data.profileIndex |
|
763 | wintitle = " [Profile = %d] " %self.data.profileIndex | |
764 |
|
764 | |||
765 | if self.type == "power": |
|
765 | if self.type == "power": | |
766 |
self.plot_power(self.data.heights, |
|
766 | self.plot_power(self.data.heights, | |
767 | scope, |
|
767 | scope, | |
768 | channels, |
|
768 | channels, | |
769 | thisDatetime, |
|
769 | thisDatetime, | |
770 | wintitle |
|
770 | wintitle | |
771 | ) |
|
771 | ) | |
772 |
|
772 | |||
773 | if self.type == "iq": |
|
773 | if self.type == "iq": | |
774 |
self.plot_iq(self.data.heights, |
|
774 | self.plot_iq(self.data.heights, | |
775 | scope, |
|
775 | scope, | |
776 | channels, |
|
776 | channels, | |
777 | thisDatetime, |
|
777 | thisDatetime, | |
778 | wintitle |
|
778 | wintitle | |
779 | ) |
|
779 | ) |
@@ -1,649 +1,650 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Set 9, 2015 |
|
2 | Created on Set 9, 2015 | |
3 |
|
3 | |||
4 | @author: roj-idl71 Karim Kuyeng |
|
4 | @author: roj-idl71 Karim Kuyeng | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os |
|
7 | import os | |
8 | import sys |
|
8 | import sys | |
9 | import glob |
|
9 | import glob | |
10 | import fnmatch |
|
10 | import fnmatch | |
11 | import datetime |
|
11 | import datetime | |
12 | import time |
|
12 | import time | |
13 | import re |
|
13 | import re | |
14 | import h5py |
|
14 | import h5py | |
15 | import numpy |
|
15 | import numpy | |
16 |
|
16 | |||
17 | try: |
|
17 | try: | |
18 | from gevent import sleep |
|
18 | from gevent import sleep | |
19 | except: |
|
19 | except: | |
20 | from time import sleep |
|
20 | from time import sleep | |
21 |
|
21 | |||
22 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
22 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
23 | from schainpy.model.data.jrodata import Voltage |
|
23 | from schainpy.model.data.jrodata import Voltage | |
24 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
24 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
25 | from numpy import imag |
|
25 | from numpy import imag | |
26 |
|
26 | |||
27 | @MPDecorator |
|
27 | @MPDecorator | |
28 | class AMISRReader(ProcessingUnit): |
|
28 | class AMISRReader(ProcessingUnit): | |
29 | ''' |
|
29 | ''' | |
30 | classdocs |
|
30 | classdocs | |
31 | ''' |
|
31 | ''' | |
32 |
|
32 | |||
33 | def __init__(self): |
|
33 | def __init__(self): | |
34 | ''' |
|
34 | ''' | |
35 | Constructor |
|
35 | Constructor | |
36 | ''' |
|
36 | ''' | |
37 |
|
37 | |||
38 | ProcessingUnit.__init__(self) |
|
38 | ProcessingUnit.__init__(self) | |
39 |
|
39 | |||
40 | self.set = None |
|
40 | self.set = None | |
41 | self.subset = None |
|
41 | self.subset = None | |
42 | self.extension_file = '.h5' |
|
42 | self.extension_file = '.h5' | |
43 | self.dtc_str = 'dtc' |
|
43 | self.dtc_str = 'dtc' | |
44 | self.dtc_id = 0 |
|
44 | self.dtc_id = 0 | |
45 | self.status = True |
|
45 | self.status = True | |
46 | self.isConfig = False |
|
46 | self.isConfig = False | |
47 | self.dirnameList = [] |
|
47 | self.dirnameList = [] | |
48 | self.filenameList = [] |
|
48 | self.filenameList = [] | |
49 | self.fileIndex = None |
|
49 | self.fileIndex = None | |
50 | self.flagNoMoreFiles = False |
|
50 | self.flagNoMoreFiles = False | |
51 | self.flagIsNewFile = 0 |
|
51 | self.flagIsNewFile = 0 | |
52 | self.filename = '' |
|
52 | self.filename = '' | |
53 | self.amisrFilePointer = None |
|
53 | self.amisrFilePointer = None | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | #self.dataset = None |
|
56 | #self.dataset = None | |
57 |
|
57 | |||
58 |
|
58 | |||
59 |
|
59 | |||
60 |
|
60 | |||
61 | self.profileIndex = 0 |
|
61 | self.profileIndex = 0 | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | self.beamCodeByFrame = None |
|
64 | self.beamCodeByFrame = None | |
65 | self.radacTimeByFrame = None |
|
65 | self.radacTimeByFrame = None | |
66 |
|
66 | |||
67 | self.dataset = None |
|
67 | self.dataset = None | |
68 |
|
68 | |||
69 |
|
69 | |||
70 |
|
70 | |||
71 |
|
71 | |||
72 | self.__firstFile = True |
|
72 | self.__firstFile = True | |
73 |
|
73 | |||
74 | self.buffer = None |
|
74 | self.buffer = None | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | self.timezone = 'ut' |
|
77 | self.timezone = 'ut' | |
78 |
|
78 | |||
79 | self.__waitForNewFile = 20 |
|
79 | self.__waitForNewFile = 20 | |
80 | self.__filename_online = None |
|
80 | self.__filename_online = None | |
81 | #Is really necessary create the output object in the initializer |
|
81 | #Is really necessary create the output object in the initializer | |
82 | self.dataOut = Voltage() |
|
82 | self.dataOut = Voltage() | |
83 | self.dataOut.error=False |
|
83 | self.dataOut.error=False | |
84 |
|
84 | |||
85 | def setup(self,path=None, |
|
85 | def setup(self,path=None, | |
86 | startDate=None, |
|
86 | startDate=None, | |
87 | endDate=None, |
|
87 | endDate=None, | |
88 | startTime=None, |
|
88 | startTime=None, | |
89 | endTime=None, |
|
89 | endTime=None, | |
90 | walk=True, |
|
90 | walk=True, | |
91 | timezone='ut', |
|
91 | timezone='ut', | |
92 | all=0, |
|
92 | all=0, | |
93 | code = None, |
|
93 | code = None, | |
94 | nCode = 0, |
|
94 | nCode = 0, | |
95 | nBaud = 0, |
|
95 | nBaud = 0, | |
96 | online=False): |
|
96 | online=False): | |
97 |
|
97 | |||
98 | #print ("T",path) |
|
98 | #print ("T",path) | |
99 |
|
99 | |||
100 | self.timezone = timezone |
|
100 | self.timezone = timezone | |
101 | self.all = all |
|
101 | self.all = all | |
102 | self.online = online |
|
102 | self.online = online | |
103 |
|
103 | |||
104 | self.code = code |
|
104 | self.code = code | |
105 | self.nCode = int(nCode) |
|
105 | self.nCode = int(nCode) | |
106 | self.nBaud = int(nBaud) |
|
106 | self.nBaud = int(nBaud) | |
107 |
|
107 | |||
108 |
|
108 | |||
109 |
|
109 | |||
110 | #self.findFiles() |
|
110 | #self.findFiles() | |
111 | if not(online): |
|
111 | if not(online): | |
112 | #Busqueda de archivos offline |
|
112 | #Busqueda de archivos offline | |
113 | self.searchFilesOffLine(path, startDate, endDate, startTime, endTime, walk) |
|
113 | self.searchFilesOffLine(path, startDate, endDate, startTime, endTime, walk) | |
114 | else: |
|
114 | else: | |
115 | self.searchFilesOnLine(path, startDate, endDate, startTime,endTime,walk) |
|
115 | self.searchFilesOnLine(path, startDate, endDate, startTime,endTime,walk) | |
116 |
|
116 | |||
117 | if not(self.filenameList): |
|
117 | if not(self.filenameList): | |
118 | print("There is no files into the folder: %s"%(path)) |
|
118 | print("There is no files into the folder: %s"%(path)) | |
119 | sys.exit(-1) |
|
119 | sys.exit(-1) | |
120 |
|
120 | |||
121 | self.fileIndex = -1 |
|
121 | self.fileIndex = -1 | |
122 |
|
122 | |||
123 | self.readNextFile(online) |
|
123 | self.readNextFile(online) | |
124 |
|
124 | |||
125 | ''' |
|
125 | ''' | |
126 | Add code |
|
126 | Add code | |
127 | ''' |
|
127 | ''' | |
128 | self.isConfig = True |
|
128 | self.isConfig = True | |
129 |
|
129 | |||
130 | pass |
|
130 | pass | |
131 |
|
131 | |||
132 |
|
132 | |||
133 | def readAMISRHeader(self,fp): |
|
133 | def readAMISRHeader(self,fp): | |
134 | header = 'Raw11/Data/RadacHeader' |
|
134 | header = 'Raw11/Data/RadacHeader' | |
135 | self.beamCodeByPulse = fp.get(header+'/BeamCode') # LIST OF BEAMS PER PROFILE, TO BE USED ON REARRANGE |
|
135 | self.beamCodeByPulse = fp.get(header+'/BeamCode') # LIST OF BEAMS PER PROFILE, TO BE USED ON REARRANGE | |
136 | self.beamCode = fp.get('Raw11/Data/Beamcodes') # NUMBER OF CHANNELS AND IDENTIFY POSITION TO CREATE A FILE WITH THAT INFO |
|
136 | self.beamCode = fp.get('Raw11/Data/Beamcodes') # NUMBER OF CHANNELS AND IDENTIFY POSITION TO CREATE A FILE WITH THAT INFO | |
137 | #self.code = fp.get(header+'/Code') # NOT USE FOR THIS |
|
137 | #self.code = fp.get(header+'/Code') # NOT USE FOR THIS | |
138 | self.frameCount = fp.get(header+'/FrameCount')# NOT USE FOR THIS |
|
138 | self.frameCount = fp.get(header+'/FrameCount')# NOT USE FOR THIS | |
139 | self.modeGroup = fp.get(header+'/ModeGroup')# NOT USE FOR THIS |
|
139 | self.modeGroup = fp.get(header+'/ModeGroup')# NOT USE FOR THIS | |
140 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse')# TO GET NSA OR USING DATA FOR THAT |
|
140 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse')# TO GET NSA OR USING DATA FOR THAT | |
141 | self.pulseCount = fp.get(header+'/PulseCount')# NOT USE FOR THIS |
|
141 | self.pulseCount = fp.get(header+'/PulseCount')# NOT USE FOR THIS | |
142 | self.radacTime = fp.get(header+'/RadacTime')# 1st TIME ON FILE ANDE CALCULATE THE REST WITH IPP*nindexprofile |
|
142 | self.radacTime = fp.get(header+'/RadacTime')# 1st TIME ON FILE ANDE CALCULATE THE REST WITH IPP*nindexprofile | |
143 | self.timeCount = fp.get(header+'/TimeCount')# NOT USE FOR THIS |
|
143 | self.timeCount = fp.get(header+'/TimeCount')# NOT USE FOR THIS | |
144 | self.timeStatus = fp.get(header+'/TimeStatus')# NOT USE FOR THIS |
|
144 | self.timeStatus = fp.get(header+'/TimeStatus')# NOT USE FOR THIS | |
145 | self.rangeFromFile = fp.get('Raw11/Data/Samples/Range') |
|
145 | self.rangeFromFile = fp.get('Raw11/Data/Samples/Range') | |
146 | self.frequency = fp.get('Rx/Frequency') |
|
146 | self.frequency = fp.get('Rx/Frequency') | |
147 | txAus = fp.get('Raw11/Data/Pulsewidth') |
|
147 | txAus = fp.get('Raw11/Data/Pulsewidth') | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | self.nblocks = self.pulseCount.shape[0] #nblocks |
|
150 | self.nblocks = self.pulseCount.shape[0] #nblocks | |
151 |
|
151 | |||
152 | self.nprofiles = self.pulseCount.shape[1] #nprofile |
|
152 | self.nprofiles = self.pulseCount.shape[1] #nprofile | |
153 | self.nsa = self.nsamplesPulse[0,0] #ngates |
|
153 | self.nsa = self.nsamplesPulse[0,0] #ngates | |
154 | self.nchannels = self.beamCode.shape[1] |
|
154 | self.nchannels = self.beamCode.shape[1] | |
155 | self.ippSeconds = (self.radacTime[0][1] -self.radacTime[0][0]) #Ipp in seconds |
|
155 | self.ippSeconds = (self.radacTime[0][1] -self.radacTime[0][0]) #Ipp in seconds | |
156 | #self.__waitForNewFile = self.nblocks # wait depending on the number of blocks since each block is 1 sec |
|
156 | #self.__waitForNewFile = self.nblocks # wait depending on the number of blocks since each block is 1 sec | |
157 | self.__waitForNewFile = self.nblocks * self.nprofiles * self.ippSeconds # wait until new file is created |
|
157 | self.__waitForNewFile = self.nblocks * self.nprofiles * self.ippSeconds # wait until new file is created | |
158 |
|
158 | |||
159 | #filling radar controller header parameters |
|
159 | #filling radar controller header parameters | |
160 | self.__ippKm = self.ippSeconds *.15*1e6 # in km |
|
160 | self.__ippKm = self.ippSeconds *.15*1e6 # in km | |
161 | self.__txA = (txAus.value)*.15 #(ipp[us]*.15km/1us) in km |
|
161 | self.__txA = (txAus.value)*.15 #(ipp[us]*.15km/1us) in km | |
162 | self.__txB = 0 |
|
162 | self.__txB = 0 | |
163 | nWindows=1 |
|
163 | nWindows=1 | |
164 | self.__nSamples = self.nsa |
|
164 | self.__nSamples = self.nsa | |
165 | self.__firstHeight = self.rangeFromFile[0][0]/1000 #in km |
|
165 | self.__firstHeight = self.rangeFromFile[0][0]/1000 #in km | |
166 | self.__deltaHeight = (self.rangeFromFile[0][1] - self.rangeFromFile[0][0])/1000 |
|
166 | self.__deltaHeight = (self.rangeFromFile[0][1] - self.rangeFromFile[0][0])/1000 | |
167 |
|
167 | |||
168 | #for now until understand why the code saved is different (code included even though code not in tuf file) |
|
168 | #for now until understand why the code saved is different (code included even though code not in tuf file) | |
169 | #self.__codeType = 0 |
|
169 | #self.__codeType = 0 | |
170 | # self.__nCode = None |
|
170 | # self.__nCode = None | |
171 | # self.__nBaud = None |
|
171 | # self.__nBaud = None | |
172 | self.__code = self.code |
|
172 | self.__code = self.code | |
173 | self.__codeType = 0 |
|
173 | self.__codeType = 0 | |
174 | if self.code != None: |
|
174 | if self.code != None: | |
175 | self.__codeType = 1 |
|
175 | self.__codeType = 1 | |
176 | self.__nCode = self.nCode |
|
176 | self.__nCode = self.nCode | |
177 | self.__nBaud = self.nBaud |
|
177 | self.__nBaud = self.nBaud | |
178 | #self.__code = 0 |
|
178 | #self.__code = 0 | |
179 |
|
179 | |||
180 | #filling system header parameters |
|
180 | #filling system header parameters | |
181 | self.__nSamples = self.nsa |
|
181 | self.__nSamples = self.nsa | |
182 | self.newProfiles = self.nprofiles/self.nchannels |
|
182 | self.newProfiles = self.nprofiles/self.nchannels | |
183 | self.__channelList = list(range(self.nchannels)) |
|
183 | self.__channelList = list(range(self.nchannels)) | |
184 |
|
184 | |||
185 | self.__frequency = self.frequency[0][0] |
|
185 | self.__frequency = self.frequency[0][0] | |
186 |
|
186 | |||
187 |
|
187 | |||
188 |
|
188 | |||
189 | def createBuffers(self): |
|
189 | def createBuffers(self): | |
190 |
|
190 | |||
191 | pass |
|
191 | pass | |
192 |
|
192 | |||
193 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
193 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): | |
194 | self.path = path |
|
194 | self.path = path | |
195 | self.startDate = startDate |
|
195 | self.startDate = startDate | |
196 | self.endDate = endDate |
|
196 | self.endDate = endDate | |
197 | self.startTime = startTime |
|
197 | self.startTime = startTime | |
198 | self.endTime = endTime |
|
198 | self.endTime = endTime | |
199 | self.walk = walk |
|
199 | self.walk = walk | |
200 |
|
200 | |||
201 | def __checkPath(self): |
|
201 | def __checkPath(self): | |
202 | if os.path.exists(self.path): |
|
202 | if os.path.exists(self.path): | |
203 | self.status = 1 |
|
203 | self.status = 1 | |
204 | else: |
|
204 | else: | |
205 | self.status = 0 |
|
205 | self.status = 0 | |
206 | print('Path:%s does not exists'%self.path) |
|
206 | print('Path:%s does not exists'%self.path) | |
207 |
|
207 | |||
208 | return |
|
208 | return | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | def __selDates(self, amisr_dirname_format): |
|
211 | def __selDates(self, amisr_dirname_format): | |
212 | try: |
|
212 | try: | |
213 | year = int(amisr_dirname_format[0:4]) |
|
213 | year = int(amisr_dirname_format[0:4]) | |
214 | month = int(amisr_dirname_format[4:6]) |
|
214 | month = int(amisr_dirname_format[4:6]) | |
215 | dom = int(amisr_dirname_format[6:8]) |
|
215 | dom = int(amisr_dirname_format[6:8]) | |
216 | thisDate = datetime.date(year,month,dom) |
|
216 | thisDate = datetime.date(year,month,dom) | |
217 |
|
217 | |||
218 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
218 | if (thisDate>=self.startDate and thisDate <= self.endDate): | |
219 | return amisr_dirname_format |
|
219 | return amisr_dirname_format | |
220 | except: |
|
220 | except: | |
221 | return None |
|
221 | return None | |
222 |
|
222 | |||
223 |
|
223 | |||
224 | def __findDataForDates(self,online=False): |
|
224 | def __findDataForDates(self,online=False): | |
225 |
|
225 | |||
226 | if not(self.status): |
|
226 | if not(self.status): | |
227 | return None |
|
227 | return None | |
228 |
|
228 | |||
229 | pat = '\d+.\d+' |
|
229 | pat = '\d+.\d+' | |
230 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
230 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] | |
231 | dirnameList = [x for x in dirnameList if x!=None] |
|
231 | dirnameList = [x for x in dirnameList if x!=None] | |
232 | dirnameList = [x.string for x in dirnameList] |
|
232 | dirnameList = [x.string for x in dirnameList] | |
233 | if not(online): |
|
233 | if not(online): | |
234 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
234 | dirnameList = [self.__selDates(x) for x in dirnameList] | |
235 | dirnameList = [x for x in dirnameList if x!=None] |
|
235 | dirnameList = [x for x in dirnameList if x!=None] | |
236 | if len(dirnameList)>0: |
|
236 | if len(dirnameList)>0: | |
237 | self.status = 1 |
|
237 | self.status = 1 | |
238 | self.dirnameList = dirnameList |
|
238 | self.dirnameList = dirnameList | |
239 | self.dirnameList.sort() |
|
239 | self.dirnameList.sort() | |
240 | else: |
|
240 | else: | |
241 | self.status = 0 |
|
241 | self.status = 0 | |
242 | return None |
|
242 | return None | |
243 |
|
243 | |||
244 | def __getTimeFromData(self): |
|
244 | def __getTimeFromData(self): | |
245 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
245 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) | |
246 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
246 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) | |
247 |
|
247 | |||
248 | print('Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader)) |
|
248 | print('Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader)) | |
249 | print('........................................') |
|
249 | print('........................................') | |
250 | filter_filenameList = [] |
|
250 | filter_filenameList = [] | |
251 | self.filenameList.sort() |
|
251 | self.filenameList.sort() | |
252 | #for i in range(len(self.filenameList)-1): |
|
252 | #for i in range(len(self.filenameList)-1): | |
253 | for i in range(len(self.filenameList)): |
|
253 | for i in range(len(self.filenameList)): | |
254 | filename = self.filenameList[i] |
|
254 | filename = self.filenameList[i] | |
255 | fp = h5py.File(filename,'r') |
|
255 | fp = h5py.File(filename,'r') | |
256 | time_str = fp.get('Time/RadacTimeString') |
|
256 | time_str = fp.get('Time/RadacTimeString') | |
257 |
|
257 | |||
258 | startDateTimeStr_File = time_str[0][0].decode('UTF-8').split('.')[0] |
|
258 | startDateTimeStr_File = time_str[0][0].decode('UTF-8').split('.')[0] | |
259 | #startDateTimeStr_File = "2019-12-16 09:21:11" |
|
259 | #startDateTimeStr_File = "2019-12-16 09:21:11" | |
260 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
260 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
261 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
261 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
262 |
|
262 | |||
263 | #endDateTimeStr_File = "2019-12-16 11:10:11" |
|
263 | #endDateTimeStr_File = "2019-12-16 11:10:11" | |
264 | endDateTimeStr_File = time_str[-1][-1].decode('UTF-8').split('.')[0] |
|
264 | endDateTimeStr_File = time_str[-1][-1].decode('UTF-8').split('.')[0] | |
265 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
265 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
266 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
266 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
267 |
|
267 | |||
268 | fp.close() |
|
268 | fp.close() | |
269 |
|
269 | |||
270 | #print("check time", startDateTime_File) |
|
270 | #print("check time", startDateTime_File) | |
271 | if self.timezone == 'lt': |
|
271 | if self.timezone == 'lt': | |
272 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
272 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) | |
273 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) |
|
273 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) | |
274 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): |
|
274 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): | |
275 | #self.filenameList.remove(filename) |
|
275 | #self.filenameList.remove(filename) | |
276 | filter_filenameList.append(filename) |
|
276 | filter_filenameList.append(filename) | |
277 |
|
277 | |||
278 | if (endDateTime_File>=endDateTime_Reader): |
|
278 | if (endDateTime_File>=endDateTime_Reader): | |
279 | break |
|
279 | break | |
280 |
|
280 | |||
281 |
|
281 | |||
282 | filter_filenameList.sort() |
|
282 | filter_filenameList.sort() | |
283 | self.filenameList = filter_filenameList |
|
283 | self.filenameList = filter_filenameList | |
284 | return 1 |
|
284 | return 1 | |
285 |
|
285 | |||
286 | def __filterByGlob1(self, dirName): |
|
286 | def __filterByGlob1(self, dirName): | |
287 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
287 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) | |
288 | filter_files.sort() |
|
288 | filter_files.sort() | |
289 | filterDict = {} |
|
289 | filterDict = {} | |
290 | filterDict.setdefault(dirName) |
|
290 | filterDict.setdefault(dirName) | |
291 | filterDict[dirName] = filter_files |
|
291 | filterDict[dirName] = filter_files | |
292 | return filterDict |
|
292 | return filterDict | |
293 |
|
293 | |||
294 | def __getFilenameList(self, fileListInKeys, dirList): |
|
294 | def __getFilenameList(self, fileListInKeys, dirList): | |
295 | for value in fileListInKeys: |
|
295 | for value in fileListInKeys: | |
296 | dirName = list(value.keys())[0] |
|
296 | dirName = list(value.keys())[0] | |
297 | for file in value[dirName]: |
|
297 | for file in value[dirName]: | |
298 | filename = os.path.join(dirName, file) |
|
298 | filename = os.path.join(dirName, file) | |
299 | self.filenameList.append(filename) |
|
299 | self.filenameList.append(filename) | |
300 |
|
300 | |||
301 |
|
301 | |||
302 | def __selectDataForTimes(self, online=False): |
|
302 | def __selectDataForTimes(self, online=False): | |
303 | #aun no esta implementado el filtro for tiempo |
|
303 | #aun no esta implementado el filtro for tiempo | |
304 | if not(self.status): |
|
304 | if not(self.status): | |
305 | return None |
|
305 | return None | |
306 |
|
306 | |||
307 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
307 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] | |
308 |
|
308 | |||
309 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
309 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] | |
310 |
|
310 | |||
311 | self.__getFilenameList(fileListInKeys, dirList) |
|
311 | self.__getFilenameList(fileListInKeys, dirList) | |
312 | if not(online): |
|
312 | if not(online): | |
313 | #filtro por tiempo |
|
313 | #filtro por tiempo | |
314 | if not(self.all): |
|
314 | if not(self.all): | |
315 | self.__getTimeFromData() |
|
315 | self.__getTimeFromData() | |
316 |
|
316 | |||
317 | if len(self.filenameList)>0: |
|
317 | if len(self.filenameList)>0: | |
318 | self.status = 1 |
|
318 | self.status = 1 | |
319 | self.filenameList.sort() |
|
319 | self.filenameList.sort() | |
320 | else: |
|
320 | else: | |
321 | self.status = 0 |
|
321 | self.status = 0 | |
322 | return None |
|
322 | return None | |
323 |
|
323 | |||
324 | else: |
|
324 | else: | |
325 | #get the last file - 1 |
|
325 | #get the last file - 1 | |
326 | self.filenameList = [self.filenameList[-2]] |
|
326 | self.filenameList = [self.filenameList[-2]] | |
327 |
|
||||
328 | new_dirnameList = [] |
|
327 | new_dirnameList = [] | |
329 | for dirname in self.dirnameList: |
|
328 | for dirname in self.dirnameList: | |
330 | junk = numpy.array([dirname in x for x in self.filenameList]) |
|
329 | junk = numpy.array([dirname in x for x in self.filenameList]) | |
331 | junk_sum = junk.sum() |
|
330 | junk_sum = junk.sum() | |
332 | if junk_sum > 0: |
|
331 | if junk_sum > 0: | |
333 | new_dirnameList.append(dirname) |
|
332 | new_dirnameList.append(dirname) | |
334 | self.dirnameList = new_dirnameList |
|
333 | self.dirnameList = new_dirnameList | |
335 | return 1 |
|
334 | return 1 | |
336 |
|
335 | |||
337 | def searchFilesOnLine(self, path, startDate, endDate, startTime=datetime.time(0,0,0), |
|
336 | def searchFilesOnLine(self, path, startDate, endDate, startTime=datetime.time(0,0,0), | |
338 | endTime=datetime.time(23,59,59),walk=True): |
|
337 | endTime=datetime.time(23,59,59),walk=True): | |
339 |
|
338 | |||
340 | if endDate ==None: |
|
339 | if endDate ==None: | |
341 | startDate = datetime.datetime.utcnow().date() |
|
340 | startDate = datetime.datetime.utcnow().date() | |
342 | endDate = datetime.datetime.utcnow().date() |
|
341 | endDate = datetime.datetime.utcnow().date() | |
343 |
|
342 | |||
344 | self.__setParameters(path=path, startDate=startDate, endDate=endDate,startTime = startTime,endTime=endTime, walk=walk) |
|
343 | self.__setParameters(path=path, startDate=startDate, endDate=endDate,startTime = startTime,endTime=endTime, walk=walk) | |
345 |
|
344 | |||
346 | self.__checkPath() |
|
345 | self.__checkPath() | |
347 |
|
346 | |||
348 | self.__findDataForDates(online=True) |
|
347 | self.__findDataForDates(online=True) | |
349 |
|
348 | |||
350 | self.dirnameList = [self.dirnameList[-1]] |
|
349 | self.dirnameList = [self.dirnameList[-1]] | |
351 |
|
350 | |||
352 | self.__selectDataForTimes(online=True) |
|
351 | self.__selectDataForTimes(online=True) | |
353 |
|
352 | |||
354 | return |
|
353 | return | |
355 |
|
354 | |||
356 |
|
355 | |||
357 | def searchFilesOffLine(self, |
|
356 | def searchFilesOffLine(self, | |
358 | path, |
|
357 | path, | |
359 | startDate, |
|
358 | startDate, | |
360 | endDate, |
|
359 | endDate, | |
361 | startTime=datetime.time(0,0,0), |
|
360 | startTime=datetime.time(0,0,0), | |
362 | endTime=datetime.time(23,59,59), |
|
361 | endTime=datetime.time(23,59,59), | |
363 | walk=True): |
|
362 | walk=True): | |
364 |
|
363 | |||
365 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
364 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
366 |
|
365 | |||
367 | self.__checkPath() |
|
366 | self.__checkPath() | |
368 |
|
367 | |||
369 | self.__findDataForDates() |
|
368 | self.__findDataForDates() | |
370 |
|
369 | |||
371 | self.__selectDataForTimes() |
|
370 | self.__selectDataForTimes() | |
372 |
|
371 | |||
373 | for i in range(len(self.filenameList)): |
|
372 | for i in range(len(self.filenameList)): | |
374 | print("%s" %(self.filenameList[i])) |
|
373 | print("%s" %(self.filenameList[i])) | |
375 |
|
374 | |||
376 | return |
|
375 | return | |
377 |
|
376 | |||
378 | def __setNextFileOffline(self): |
|
377 | def __setNextFileOffline(self): | |
379 | idFile = self.fileIndex |
|
378 | idFile = self.fileIndex | |
380 |
|
379 | |||
381 | while (True): |
|
380 | while (True): | |
382 | idFile += 1 |
|
381 | idFile += 1 | |
383 | if not(idFile < len(self.filenameList)): |
|
382 | if not(idFile < len(self.filenameList)): | |
384 | self.flagNoMoreFiles = 1 |
|
383 | self.flagNoMoreFiles = 1 | |
385 | print("No more Files") |
|
384 | print("No more Files") | |
386 | self.dataOut.error = True |
|
|||
387 | return 0 |
|
385 | return 0 | |
388 |
|
386 | |||
389 | filename = self.filenameList[idFile] |
|
387 | filename = self.filenameList[idFile] | |
390 |
|
388 | |||
391 | amisrFilePointer = h5py.File(filename,'r') |
|
389 | amisrFilePointer = h5py.File(filename,'r') | |
392 |
|
390 | |||
393 | break |
|
391 | break | |
394 |
|
392 | |||
395 | self.flagIsNewFile = 1 |
|
393 | self.flagIsNewFile = 1 | |
396 | self.fileIndex = idFile |
|
394 | self.fileIndex = idFile | |
397 | self.filename = filename |
|
395 | self.filename = filename | |
398 |
|
396 | |||
399 | self.amisrFilePointer = amisrFilePointer |
|
397 | self.amisrFilePointer = amisrFilePointer | |
400 |
|
398 | |||
401 | print("Setting the file: %s"%self.filename) |
|
399 | print("Setting the file: %s"%self.filename) | |
402 |
|
400 | |||
403 | return 1 |
|
401 | return 1 | |
404 |
|
402 | |||
405 |
|
403 | |||
406 | def __setNextFileOnline(self): |
|
404 | def __setNextFileOnline(self): | |
407 | filename = self.filenameList[0] |
|
405 | filename = self.filenameList[0] | |
408 | if self.__filename_online != None: |
|
406 | if self.__filename_online != None: | |
409 | self.__selectDataForTimes(online=True) |
|
407 | self.__selectDataForTimes(online=True) | |
410 | filename = self.filenameList[0] |
|
408 | filename = self.filenameList[0] | |
411 | wait = 0 |
|
409 | wait = 0 | |
|
410 | #self.__waitForNewFile=5 ## DEBUG: | |||
412 | while self.__filename_online == filename: |
|
411 | while self.__filename_online == filename: | |
413 | print('waiting %d seconds to get a new file...'%(self.__waitForNewFile)) |
|
412 | print('waiting %d seconds to get a new file...'%(self.__waitForNewFile)) | |
414 | if wait == 5: |
|
413 | if wait == 5: | |
|
414 | self.flagNoMoreFiles = 1 | |||
415 | return 0 |
|
415 | return 0 | |
416 | sleep(self.__waitForNewFile) |
|
416 | sleep(self.__waitForNewFile) | |
417 | self.__selectDataForTimes(online=True) |
|
417 | self.__selectDataForTimes(online=True) | |
418 | filename = self.filenameList[0] |
|
418 | filename = self.filenameList[0] | |
419 | wait += 1 |
|
419 | wait += 1 | |
420 |
|
420 | |||
421 | self.__filename_online = filename |
|
421 | self.__filename_online = filename | |
422 |
|
422 | |||
423 | self.amisrFilePointer = h5py.File(filename,'r') |
|
423 | self.amisrFilePointer = h5py.File(filename,'r') | |
424 | self.flagIsNewFile = 1 |
|
424 | self.flagIsNewFile = 1 | |
425 | self.filename = filename |
|
425 | self.filename = filename | |
426 | print("Setting the file: %s"%self.filename) |
|
426 | print("Setting the file: %s"%self.filename) | |
427 | return 1 |
|
427 | return 1 | |
428 |
|
428 | |||
429 |
|
429 | |||
430 | def readData(self): |
|
430 | def readData(self): | |
431 | buffer = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
431 | buffer = self.amisrFilePointer.get('Raw11/Data/Samples/Data') | |
432 | re = buffer[:,:,:,0] |
|
432 | re = buffer[:,:,:,0] | |
433 | im = buffer[:,:,:,1] |
|
433 | im = buffer[:,:,:,1] | |
434 | dataset = re + im*1j |
|
434 | dataset = re + im*1j | |
435 |
|
435 | |||
436 | self.radacTime = self.amisrFilePointer.get('Raw11/Data/RadacHeader/RadacTime') |
|
436 | self.radacTime = self.amisrFilePointer.get('Raw11/Data/RadacHeader/RadacTime') | |
437 | timeset = self.radacTime[:,0] |
|
437 | timeset = self.radacTime[:,0] | |
438 |
|
438 | |||
439 | return dataset,timeset |
|
439 | return dataset,timeset | |
440 |
|
440 | |||
441 | def reshapeData(self): |
|
441 | def reshapeData(self): | |
442 | #self.beamCodeByPulse, self.beamCode, self.nblocks, self.nprofiles, self.nsa, |
|
442 | #self.beamCodeByPulse, self.beamCode, self.nblocks, self.nprofiles, self.nsa, | |
443 | channels = self.beamCodeByPulse[0,:] |
|
443 | channels = self.beamCodeByPulse[0,:] | |
444 | nchan = self.nchannels |
|
444 | nchan = self.nchannels | |
445 | #self.newProfiles = self.nprofiles/nchan #must be defined on filljroheader |
|
445 | #self.newProfiles = self.nprofiles/nchan #must be defined on filljroheader | |
446 | nblocks = self.nblocks |
|
446 | nblocks = self.nblocks | |
447 | nsamples = self.nsa |
|
447 | nsamples = self.nsa | |
448 |
|
448 | |||
449 | #Dimensions : nChannels, nProfiles, nSamples |
|
449 | #Dimensions : nChannels, nProfiles, nSamples | |
450 | new_block = numpy.empty((nblocks, nchan, numpy.int_(self.newProfiles), nsamples), dtype="complex64") |
|
450 | new_block = numpy.empty((nblocks, nchan, numpy.int_(self.newProfiles), nsamples), dtype="complex64") | |
451 | ############################################ |
|
451 | ############################################ | |
452 |
|
452 | |||
453 | for thisChannel in range(nchan): |
|
453 | for thisChannel in range(nchan): | |
454 | new_block[:,thisChannel,:,:] = self.dataset[:,numpy.where(channels==self.beamCode[0][thisChannel])[0],:] |
|
454 | new_block[:,thisChannel,:,:] = self.dataset[:,numpy.where(channels==self.beamCode[0][thisChannel])[0],:] | |
455 |
|
455 | |||
456 |
|
456 | |||
457 | new_block = numpy.transpose(new_block, (1,0,2,3)) |
|
457 | new_block = numpy.transpose(new_block, (1,0,2,3)) | |
458 | new_block = numpy.reshape(new_block, (nchan,-1, nsamples)) |
|
458 | new_block = numpy.reshape(new_block, (nchan,-1, nsamples)) | |
459 |
|
459 | |||
460 | return new_block |
|
460 | return new_block | |
461 |
|
461 | |||
462 | def updateIndexes(self): |
|
462 | def updateIndexes(self): | |
463 |
|
463 | |||
464 | pass |
|
464 | pass | |
465 |
|
465 | |||
466 | def fillJROHeader(self): |
|
466 | def fillJROHeader(self): | |
467 |
|
467 | |||
468 | #fill radar controller header |
|
468 | #fill radar controller header | |
469 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ipp=self.__ippKm, |
|
469 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ipp=self.__ippKm, | |
470 | txA=self.__txA, |
|
470 | txA=self.__txA, | |
471 | txB=0, |
|
471 | txB=0, | |
472 | nWindows=1, |
|
472 | nWindows=1, | |
473 | nHeights=self.__nSamples, |
|
473 | nHeights=self.__nSamples, | |
474 | firstHeight=self.__firstHeight, |
|
474 | firstHeight=self.__firstHeight, | |
475 | deltaHeight=self.__deltaHeight, |
|
475 | deltaHeight=self.__deltaHeight, | |
476 | codeType=self.__codeType, |
|
476 | codeType=self.__codeType, | |
477 | nCode=self.__nCode, nBaud=self.__nBaud, |
|
477 | nCode=self.__nCode, nBaud=self.__nBaud, | |
478 | code = self.__code, |
|
478 | code = self.__code, | |
479 | fClock=1) |
|
479 | fClock=1) | |
480 |
|
480 | |||
481 | #fill system header |
|
481 | #fill system header | |
482 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, |
|
482 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
483 | nProfiles=self.newProfiles, |
|
483 | nProfiles=self.newProfiles, | |
484 | nChannels=len(self.__channelList), |
|
484 | nChannels=len(self.__channelList), | |
485 | adcResolution=14, |
|
485 | adcResolution=14, | |
486 | pciDioBusWidth=32) |
|
486 | pciDioBusWidth=32) | |
487 |
|
487 | |||
488 | self.dataOut.type = "Voltage" |
|
488 | self.dataOut.type = "Voltage" | |
489 |
|
489 | |||
490 | self.dataOut.data = None |
|
490 | self.dataOut.data = None | |
491 |
|
491 | |||
492 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
492 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
493 |
|
493 | |||
494 | # self.dataOut.nChannels = 0 |
|
494 | # self.dataOut.nChannels = 0 | |
495 |
|
495 | |||
496 | # self.dataOut.nHeights = 0 |
|
496 | # self.dataOut.nHeights = 0 | |
497 |
|
497 | |||
498 | self.dataOut.nProfiles = self.newProfiles*self.nblocks |
|
498 | self.dataOut.nProfiles = self.newProfiles*self.nblocks | |
499 |
|
499 | |||
500 | #self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth |
|
500 | #self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth | |
501 | ranges = numpy.reshape(self.rangeFromFile.value,(-1)) |
|
501 | ranges = numpy.reshape(self.rangeFromFile.value,(-1)) | |
502 | self.dataOut.heightList = ranges/1000.0 #km |
|
502 | self.dataOut.heightList = ranges/1000.0 #km | |
503 |
|
503 | |||
504 |
|
504 | |||
505 | self.dataOut.channelList = self.__channelList |
|
505 | self.dataOut.channelList = self.__channelList | |
506 |
|
506 | |||
507 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
507 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
508 |
|
508 | |||
509 | # self.dataOut.channelIndexList = None |
|
509 | # self.dataOut.channelIndexList = None | |
510 |
|
510 | |||
511 | self.dataOut.flagNoData = True |
|
511 | self.dataOut.flagNoData = True | |
512 |
|
512 | |||
513 | #Set to TRUE if the data is discontinuous |
|
513 | #Set to TRUE if the data is discontinuous | |
514 | self.dataOut.flagDiscontinuousBlock = False |
|
514 | self.dataOut.flagDiscontinuousBlock = False | |
515 |
|
515 | |||
516 | self.dataOut.utctime = None |
|
516 | self.dataOut.utctime = None | |
517 |
|
517 | |||
518 | #self.dataOut.timeZone = -5 #self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime |
|
518 | #self.dataOut.timeZone = -5 #self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime | |
519 | if self.timezone == 'lt': |
|
519 | if self.timezone == 'lt': | |
520 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes |
|
520 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes | |
521 | else: |
|
521 | else: | |
522 | self.dataOut.timeZone = 0 #by default time is UTC |
|
522 | self.dataOut.timeZone = 0 #by default time is UTC | |
523 |
|
523 | |||
524 | self.dataOut.dstFlag = 0 |
|
524 | self.dataOut.dstFlag = 0 | |
525 |
|
525 | |||
526 | self.dataOut.errorCount = 0 |
|
526 | self.dataOut.errorCount = 0 | |
527 |
|
527 | |||
528 | self.dataOut.nCohInt = 1 |
|
528 | self.dataOut.nCohInt = 1 | |
529 |
|
529 | |||
530 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada |
|
530 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada | |
531 |
|
531 | |||
532 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip |
|
532 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip | |
533 |
|
533 | |||
534 | self.dataOut.flagShiftFFT = False |
|
534 | self.dataOut.flagShiftFFT = False | |
535 |
|
535 | |||
536 | self.dataOut.ippSeconds = self.ippSeconds |
|
536 | self.dataOut.ippSeconds = self.ippSeconds | |
537 |
|
537 | |||
538 | #Time interval between profiles |
|
538 | #Time interval between profiles | |
539 | #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
539 | #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
540 |
|
540 | |||
541 | self.dataOut.frequency = self.__frequency |
|
541 | self.dataOut.frequency = self.__frequency | |
542 | self.dataOut.realtime = self.online |
|
542 | self.dataOut.realtime = self.online | |
543 | pass |
|
543 | pass | |
544 |
|
544 | |||
545 | def readNextFile(self,online=False): |
|
545 | def readNextFile(self,online=False): | |
546 |
|
546 | |||
547 | if not(online): |
|
547 | if not(online): | |
548 | newFile = self.__setNextFileOffline() |
|
548 | newFile = self.__setNextFileOffline() | |
549 | else: |
|
549 | else: | |
550 | newFile = self.__setNextFileOnline() |
|
550 | newFile = self.__setNextFileOnline() | |
551 |
|
551 | |||
552 | if not(newFile): |
|
552 | if not(newFile): | |
|
553 | self.dataOut.error = True | |||
553 | return 0 |
|
554 | return 0 | |
554 | #if self.__firstFile: |
|
555 | #if self.__firstFile: | |
555 | self.readAMISRHeader(self.amisrFilePointer) |
|
556 | self.readAMISRHeader(self.amisrFilePointer) | |
556 |
|
557 | |||
557 | self.createBuffers() |
|
558 | self.createBuffers() | |
558 |
|
559 | |||
559 | self.fillJROHeader() |
|
560 | self.fillJROHeader() | |
560 |
|
561 | |||
561 | #self.__firstFile = False |
|
562 | #self.__firstFile = False | |
562 |
|
563 | |||
563 |
|
564 | |||
564 |
|
565 | |||
565 | self.dataset,self.timeset = self.readData() |
|
566 | self.dataset,self.timeset = self.readData() | |
566 |
|
567 | |||
567 | if self.endDate!=None: |
|
568 | if self.endDate!=None: | |
568 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
569 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) | |
569 | time_str = self.amisrFilePointer.get('Time/RadacTimeString') |
|
570 | time_str = self.amisrFilePointer.get('Time/RadacTimeString') | |
570 | startDateTimeStr_File = time_str[0][0].decode('UTF-8').split('.')[0] |
|
571 | startDateTimeStr_File = time_str[0][0].decode('UTF-8').split('.')[0] | |
571 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
572 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
572 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
573 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
573 | if self.timezone == 'lt': |
|
574 | if self.timezone == 'lt': | |
574 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
575 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) | |
575 | if (startDateTime_File>endDateTime_Reader): |
|
576 | if (startDateTime_File>endDateTime_Reader): | |
576 | return 0 |
|
577 | return 0 | |
577 |
|
578 | |||
578 | self.jrodataset = self.reshapeData() |
|
579 | self.jrodataset = self.reshapeData() | |
579 | #----self.updateIndexes() |
|
580 | #----self.updateIndexes() | |
580 | self.profileIndex = 0 |
|
581 | self.profileIndex = 0 | |
581 |
|
582 | |||
582 | return 1 |
|
583 | return 1 | |
583 |
|
584 | |||
584 |
|
585 | |||
585 | def __hasNotDataInBuffer(self): |
|
586 | def __hasNotDataInBuffer(self): | |
586 | if self.profileIndex >= (self.newProfiles*self.nblocks): |
|
587 | if self.profileIndex >= (self.newProfiles*self.nblocks): | |
587 | return 1 |
|
588 | return 1 | |
588 | return 0 |
|
589 | return 0 | |
589 |
|
590 | |||
590 |
|
591 | |||
591 | def getData(self): |
|
592 | def getData(self): | |
592 |
|
593 | |||
593 | if self.flagNoMoreFiles: |
|
594 | if self.flagNoMoreFiles: | |
594 | self.dataOut.flagNoData = True |
|
595 | self.dataOut.flagNoData = True | |
595 | return 0 |
|
596 | return 0 | |
596 |
|
597 | |||
597 | if self.__hasNotDataInBuffer(): |
|
598 | if self.__hasNotDataInBuffer(): | |
598 | if not (self.readNextFile(self.online)): |
|
599 | if not (self.readNextFile(self.online)): | |
599 | return 0 |
|
600 | return 0 | |
600 |
|
601 | |||
601 |
|
602 | |||
602 | if self.dataset is None: # setear esta condicion cuando no hayan datos por leer |
|
603 | if self.dataset is None: # setear esta condicion cuando no hayan datos por leer | |
603 | self.dataOut.flagNoData = True |
|
604 | self.dataOut.flagNoData = True | |
604 | return 0 |
|
605 | return 0 | |
605 |
|
606 | |||
606 | #self.dataOut.data = numpy.reshape(self.jrodataset[self.profileIndex,:],(1,-1)) |
|
607 | #self.dataOut.data = numpy.reshape(self.jrodataset[self.profileIndex,:],(1,-1)) | |
607 |
|
608 | |||
608 | self.dataOut.data = self.jrodataset[:,self.profileIndex,:] |
|
609 | self.dataOut.data = self.jrodataset[:,self.profileIndex,:] | |
609 |
|
610 | |||
610 | #print("R_t",self.timeset) |
|
611 | #print("R_t",self.timeset) | |
611 |
|
612 | |||
612 | #self.dataOut.utctime = self.jrotimeset[self.profileIndex] |
|
613 | #self.dataOut.utctime = self.jrotimeset[self.profileIndex] | |
613 | #verificar basic header de jro data y ver si es compatible con este valor |
|
614 | #verificar basic header de jro data y ver si es compatible con este valor | |
614 | #self.dataOut.utctime = self.timeset + (self.profileIndex * self.ippSeconds * self.nchannels) |
|
615 | #self.dataOut.utctime = self.timeset + (self.profileIndex * self.ippSeconds * self.nchannels) | |
615 | indexprof = numpy.mod(self.profileIndex, self.newProfiles) |
|
616 | indexprof = numpy.mod(self.profileIndex, self.newProfiles) | |
616 | indexblock = self.profileIndex/self.newProfiles |
|
617 | indexblock = self.profileIndex/self.newProfiles | |
617 | #print (indexblock, indexprof) |
|
618 | #print (indexblock, indexprof) | |
618 | diffUTC = 1.8e4 #UTC diference from peru in seconds --Joab |
|
619 | diffUTC = 1.8e4 #UTC diference from peru in seconds --Joab | |
619 | diffUTC = 0 |
|
620 | diffUTC = 0 | |
620 | t_comp = (indexprof * self.ippSeconds * self.nchannels) + diffUTC # |
|
621 | t_comp = (indexprof * self.ippSeconds * self.nchannels) + diffUTC # | |
621 | #cambio posible 18/02/2020 |
|
622 | #cambio posible 18/02/2020 | |
622 |
|
623 | |||
623 |
|
624 | |||
624 |
|
625 | |||
625 | #print("utc :",indexblock," __ ",t_comp) |
|
626 | #print("utc :",indexblock," __ ",t_comp) | |
626 | #print(numpy.shape(self.timeset)) |
|
627 | #print(numpy.shape(self.timeset)) | |
627 | self.dataOut.utctime = self.timeset[numpy.int_(indexblock)] + t_comp |
|
628 | self.dataOut.utctime = self.timeset[numpy.int_(indexblock)] + t_comp | |
628 | #self.dataOut.utctime = self.timeset[self.profileIndex] + t_comp |
|
629 | #self.dataOut.utctime = self.timeset[self.profileIndex] + t_comp | |
629 | #print(self.dataOut.utctime) |
|
630 | #print(self.dataOut.utctime) | |
630 | self.dataOut.profileIndex = self.profileIndex |
|
631 | self.dataOut.profileIndex = self.profileIndex | |
631 | self.dataOut.flagNoData = False |
|
632 | self.dataOut.flagNoData = False | |
632 | # if indexprof == 0: |
|
633 | # if indexprof == 0: | |
633 | # print self.dataOut.utctime |
|
634 | # print self.dataOut.utctime | |
634 |
|
635 | |||
635 | self.profileIndex += 1 |
|
636 | self.profileIndex += 1 | |
636 |
|
637 | |||
637 | return self.dataOut.data |
|
638 | return self.dataOut.data | |
638 |
|
639 | |||
639 |
|
640 | |||
640 | def run(self, **kwargs): |
|
641 | def run(self, **kwargs): | |
641 | ''' |
|
642 | ''' | |
642 | This method will be called many times so here you should put all your code |
|
643 | This method will be called many times so here you should put all your code | |
643 | ''' |
|
644 | ''' | |
644 |
|
645 | |||
645 | if not self.isConfig: |
|
646 | if not self.isConfig: | |
646 | self.setup(**kwargs) |
|
647 | self.setup(**kwargs) | |
647 | self.isConfig = True |
|
648 | self.isConfig = True | |
648 |
|
649 | |||
649 | self.getData() |
|
650 | self.getData() |
General Comments 0
You need to be logged in to leave comments.
Login now