Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
RfiScenario.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/generators/RfiScenario.h"
25 #include <random>
26 
27 
28 namespace ska {
29 namespace cheetah {
30 namespace generators {
31 
32 
33 // -------------------- Scenario 0 ---------------------
34 template<typename T>
35 RfiScenario<0, T>::RfiScenario()
36 {
37 }
38 
39 template<typename T>
40 RfiScenario<0, T>::~RfiScenario()
41 {
42 }
43 
44 template<typename T>
45 void RfiScenario<0, T>::next(FlaggedDataType&)
46 {
47 }
48 
49 template<typename T>
50 constexpr char RfiScenario<0,T>::description[];
51 
52 // -------------------- Scenario 1 ---------------------
53 template<typename T>
54 RfiScenario<1, T>::RfiScenario()
55 {
56 }
57 
58 template<typename T>
59 RfiScenario<1, T>::~RfiScenario()
60 {
61 }
62 
63 template<typename T>
64 constexpr char RfiScenario<1,T>::description[];
65 
66 template<typename T>
67 void RfiScenario<1, T>::next(FlaggedDataType& data)
68 {
69  unsigned factor = 4;
70  std::size_t min_channel = data.number_of_channels()/factor;
71  std::size_t max_channel = (factor - 1) * min_channel;
72  std::size_t min_sample = data.number_of_spectra()/factor;
73  std::size_t max_sample = (factor - 1) * min_sample;
74 
75  this->rfi_ramp_block(data, min_channel, max_channel, min_sample, max_sample);
76 }
77 
78 
79 
80 
81 // -------------------- Scenario 2 ---------------------
82 template<typename T>
83 RfiScenario<2, T>::RfiScenario()
84 {
85 }
86 
87 template<typename T>
88 RfiScenario<2, T>::~RfiScenario()
89 {
90 }
91 
92 template<typename T>
93 constexpr char RfiScenario<2,T>::description[];
94 
95 template<typename T>
96 void RfiScenario<2, T>::next(FlaggedDataType& data)
97 {
98  std::size_t pulse_channel_centre = data.number_of_channels()/2;
99  std::size_t pulse_sample_centre = data.number_of_spectra()/2;
100  unsigned channel_range = data.number_of_channels()/4;
101  unsigned sample_range = data.number_of_spectra()/2;
102  if(channel_range>32) channel_range=32;
103  if(sample_range>64) sample_range=64;
104  std::size_t min_channel = pulse_channel_centre-channel_range;
105  std::size_t max_channel = pulse_channel_centre+channel_range;
106  std::size_t min_sample = pulse_sample_centre-sample_range;
107  std::size_t max_sample = pulse_sample_centre+sample_range;
108 
109  this->rfi_gaussian_block(data, min_channel, max_channel, min_sample, max_sample,6.0);
110 }
111 
112 // -------------------- Scenario 3 ---------------------
113 template<typename T>
114 RfiScenario<3, T>::RfiScenario()
115 {
116 }
117 
118 template<typename T>
119 RfiScenario<3, T>::~RfiScenario()
120 {
121 }
122 
123 template<typename T>
124 constexpr char RfiScenario<3,T>::description[];
125 
126 template<typename T>
127 void RfiScenario<3, T>::next(FlaggedDataType& data)
128 {
129  unsigned channel_range = data.number_of_channels()/4;
130  unsigned sample_range = data.number_of_spectra()/2;
131  if(channel_range>32) channel_range = 32;
132  if(sample_range>64) sample_range = 64;
133 
134  std::random_device rd;
135  std::mt19937 mt(rd());
136  std::uniform_int_distribution<int> dist(sample_range, data.number_of_spectra()-sample_range);
137 
138  std::size_t pulse_channel_centre = data.number_of_channels()/4;
139  std::size_t min_channel = pulse_channel_centre-channel_range;
140  std::size_t max_channel = pulse_channel_centre+channel_range;
141  for(int i=0;i<4;++i)
142  {
143  if(i==2)
144  {
145  pulse_channel_centre = 3*data.number_of_channels()/4;
146  min_channel = pulse_channel_centre-channel_range;
147  max_channel = pulse_channel_centre+channel_range;
148  }
149  std::size_t pulse_sample_centre = dist(mt);
150 
151  std::size_t min_sample = pulse_sample_centre-sample_range;
152  std::size_t max_sample = pulse_sample_centre+sample_range;
153  this->rfi_gaussian_block(data, min_channel, max_channel, min_sample, max_sample,6.0);
154  }
155 }
156 
157 // -------------------- Scenario 4 ---------------------
158 template<typename T>
159 RfiScenario<4, T>::RfiScenario()
160 {
161 }
162 
163 template<typename T>
164 RfiScenario<4, T>::~RfiScenario()
165 {
166 }
167 
168 template<typename T>
169 constexpr char RfiScenario<4,T>::description[];
170 
171 template<typename T>
172 void RfiScenario<4, T>::next(FlaggedDataType& data)
173 {
174  unsigned channel_range = data.number_of_channels()/4;
175  unsigned sample_range = data.number_of_spectra()/2;
176  if(channel_range>32) channel_range = 32;
177  if(sample_range>128) sample_range = 128;
178 
179  std::random_device rd;
180  std::mt19937 mt(rd());
181  std::uniform_int_distribution<int> sample_dist(sample_range, data.number_of_spectra()-sample_range);
182  std::uniform_int_distribution<int> channel_dist(channel_range, data.number_of_channels()-channel_range);
183  std::uniform_int_distribution<int> sample_width_dist(sample_range/8, 2*sample_range);
184  std::uniform_int_distribution<int> channel_width_dist(channel_range/4, 2*channel_range);
185  unsigned number_of_pulses = 8;
186  for(unsigned i=0;i<number_of_pulses;++i)
187  {
188  std::size_t pulse_channel_width = channel_width_dist(mt);
189  std::size_t pulse_sample_width = sample_width_dist(mt);
190 
191  std::size_t pulse_channel_centre = channel_dist(mt);
192  std::size_t min_channel = pulse_channel_centre-pulse_channel_width/2;
193  std::size_t max_channel = pulse_channel_centre+pulse_channel_width/2;
194 
195  std::size_t pulse_sample_centre = sample_dist(mt);
196 
197  std::size_t min_sample = pulse_sample_centre-pulse_sample_width/2;
198  std::size_t max_sample = pulse_sample_centre+pulse_sample_width/2;
199  this->rfi_gaussian_block(data, min_channel, max_channel, min_sample, max_sample,6.0);
200  }
201 }
202 
203 // -------------------- Scenario 5 ---------------------
204 template<typename T>
205 RfiScenario<5, T>::RfiScenario()
206 {
207 }
208 
209 template<typename T>
210 RfiScenario<5, T>::~RfiScenario()
211 {
212 }
213 
214 template<typename T>
215 constexpr char RfiScenario<5,T>::description[];
216 
217 template<typename T>
218 void RfiScenario<5, T>::next(FlaggedDataType& data)
219 {
220  // choose a channel approx in the middle
221  data::DimensionIndex<data::Frequency> channel_number(data.template dimension<data::Frequency>()/2);
222 
223  auto channel = data.tf_data().channel(channel_number);
224  std::fill(channel.begin(), channel.end(), std::numeric_limits<T>::max());
225  auto flag_channel = data.rfi_flags().overlay(channel);
226  std::fill(flag_channel.begin(), flag_channel.end(), true);
227 }
228 
229 #ifdef NDEBUG
230 // -------------------- Scenario 6 ---------------------
231 template<typename T>
232 RfiScenario<6, T>::RfiScenario()
233 {
234 }
235 
236 template<typename T>
237 RfiScenario<6, T>::~RfiScenario()
238 {
239 }
240 
241 template<typename T>
242 constexpr char RfiScenario<6,T>::description[];
243 
244 template<typename T>
245 void RfiScenario<6, T>::next(FlaggedDataType& data)
246 {
247  unsigned min_channel = data.number_of_channels()/2 - data.number_of_channels()/16;
248  unsigned max_channel = data.number_of_channels()/2 + data.number_of_channels()/16;
249 
250  unsigned factor = 128;
251  unsigned sample_stride = data.number_of_spectra()/(4*factor);
252 
253  std::size_t min_sample = 1*sample_stride;
254  std::size_t max_sample = 3*sample_stride;
255 
256  for(unsigned i=0; i<factor-1; ++i)
257  {
258  min_sample += 4*sample_stride;
259  max_sample += 4*sample_stride;
260 
261  this->rfi_gaussian_block(data, min_channel, max_channel, min_sample, max_sample,6.0);
262  }
263 }
264 
265 // -------------------- Scenario 7 ---------------------
266 template<typename T>
267 RfiScenario<7, T>::RfiScenario()
268 {
269 }
270 
271 template<typename T>
272 RfiScenario<7, T>::~RfiScenario()
273 {
274 }
275 
276 template<typename T>
277 constexpr char RfiScenario<7,T>::description[];
278 
279 template<typename T>
280 void RfiScenario<7, T>::next(FlaggedDataType& data)
281 {
282  unsigned sample_range = data.number_of_spectra()/4;
283  if(sample_range>8) sample_range = 8;
284 
285  std::size_t min_sample = data.number_of_spectra()/2 - sample_range;
286  std::size_t max_sample = data.number_of_spectra()/2 + sample_range;
287 
288  this->rfi_broadband_block(data, min_sample, max_sample,6.0);
289 }
290 
291 // -------------------- Scenario 8 ---------------------
292 template<typename T>
293 RfiScenario<8, T>::RfiScenario()
294 {
295 }
296 
297 template<typename T>
298 RfiScenario<8, T>::~RfiScenario()
299 {
300 }
301 
302 template<typename T>
303 constexpr char RfiScenario<8,T>::description[];
304 
305 template<typename T>
306 void RfiScenario<8, T>::next(FlaggedDataType& data)
307 {
308  unsigned min_channel = data.number_of_channels()/2 - data.number_of_channels()/16;
309  unsigned max_channel = data.number_of_channels()/2 + data.number_of_channels()/16;
310 
311  unsigned factor = 128;
312  unsigned sample_stride = data.number_of_spectra()/(4*factor);
313 
314  std::size_t min_sample = 1*sample_stride;
315  std::size_t max_sample = 3*sample_stride;
316 
317  for(unsigned i=0; i<factor-1; ++i)
318  {
319  min_sample += 4*sample_stride;
320  max_sample += 4*sample_stride;
321 
322  this->rfi_gaussian_block(data, min_channel, max_channel, min_sample, max_sample,4.0);
323  }
324 }
325 
326 // -------------------- Scenario 9 ---------------------
327 template<typename T>
328 RfiScenario<9, T>::RfiScenario()
329 {
330 }
331 
332 template<typename T>
333 RfiScenario<9, T>::~RfiScenario()
334 {
335 }
336 
337 template<typename T>
338 constexpr char RfiScenario<9,T>::description[];
339 
340 template<typename T>
341 void RfiScenario<9, T>::next(FlaggedDataType& data)
342 {
343  unsigned min_channel = 0;
344  unsigned max_channel = data.number_of_channels()-1;
345 
346  unsigned sample_range = data.number_of_spectra()/4;
347  if(sample_range>8) sample_range = 8;
348 
349  std::size_t min_sample = data.number_of_spectra()/2 - sample_range;
350  std::size_t max_sample = data.number_of_spectra()/2 + sample_range;
351 
352  this->rfi_gaussian_block(data, min_channel, max_channel, min_sample, max_sample,4.0);
353 }
354 
355 // -------------------- Scenario 10 ---------------------
356 template<typename T>
357 RfiScenario<10, T>::RfiScenario()
358 {
359 }
360 
361 template<typename T>
362 RfiScenario<10, T>::~RfiScenario()
363 {
364 }
365 
366 template<typename T>
367 constexpr char RfiScenario<10,T>::description[];
368 
369 template<typename T>
370 void RfiScenario<10, T>::next(FlaggedDataType& data)
371 {
372  unsigned factor = 128;
373  unsigned sample_stride = data.number_of_spectra()/(4*factor);
374 
375  std::size_t min_sample = 1*sample_stride;
376  std::size_t max_sample = 3*sample_stride;
377 
378  for(unsigned i=0; i<factor-1; ++i)
379  {
380  min_sample += 4*sample_stride;
381  max_sample += 4*sample_stride;
382 
383  this->rfi_broadband_block(data, min_sample, max_sample,5.0);
384  }
385 }
386 #endif // NDEBUG
387 
388 } // namespace generators
389 } // namespace cheetah
390 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35