Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
FofTest.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/sps_clustering/test/FofTest.h"
25 
26 
27 namespace ska {
28 namespace cheetah {
29 namespace sps_clustering {
30 namespace test {
31 
32 
33 FofTest::FofTest()
34  : ::testing::Test()
35 {
36 }
37 
38 FofTest::~FofTest()
39 {
40 }
41 
42 void FofTest::SetUp()
43 {
44 }
45 
46 void FofTest::TearDown()
47 {
48 }
49 
50 TEST_F(FofTest, test_constructor)
51 {
52  // Generate SpSift Config and construct SpSift object
53  Config config;
54  typename Config::Dm dm_tolerance(17.0 * pss::astrotypes::units::parsecs_per_cube_cm);
55  typename Config::MsecTimeType width_tolerance(0.025 * boost::units::si::seconds);
56  typename Config::MsecTimeType time_tolerance(10 * boost::units::si::seconds);
57  config.dm_tolerance(dm_tolerance);
58  config.pulse_width_tolerance(width_tolerance);
59  config.time_tolerance(time_tolerance);
60  Fof another_clusterer(config);
61 }
62 
63 TEST_F(FofTest, test_empty_list)
64 {
65  // Generate SpSift Config and construct SpSift object
66  Config config;
67  typename Config::Dm dm_tolerance(17.0 * pss::astrotypes::units::parsecs_per_cube_cm);
68  typename Config::MsecTimeType width_tolerance(0.025 * boost::units::si::seconds);
69  typename Config::MsecTimeType time_tolerance(10 * boost::units::si::seconds);
70  config.dm_tolerance(dm_tolerance);
71  config.pulse_width_tolerance(width_tolerance);
72  config.time_tolerance(time_tolerance);
73 
74  Fof clusterer(config);
75  clusterer.linking_length(0.414);
76 
77  data::SpCcl<NumericalRep> cand_list;
78  ASSERT_NO_THROW(clusterer(cand_list));
79  auto groups = clusterer(cand_list);
80  ASSERT_EQ(groups.size(),0U);
81 }
82 
83 
84 
85 
86 TEST_F(FofTest, test_group_one_candidate)
87 {
88 
89  data::SpCcl<NumericalRep>::BlocksType tf_v;
90  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
91  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
92  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
93 
94  // Generate SpCcl instance
95  data::SpCcl<NumericalRep> cand_list(tf_v);
96 
97  //set single pulse candidate dispersion measure
98  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
99  //set the single pulse candidate width to 1.0 ms
100  typename Config::MsecTimeType width(0.005 * boost::units::si::seconds);
101  //set the single pulse start time to 2.0 seconds
102  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
103  //set the candidate significance
104  float sigma = 10.0;
105 
106  for (std::size_t idx=0; idx<1; ++idx)
107  {
108  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
109  cand_list.push_back(candidate);
110  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
111  dm += typename Config::Dm(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
112  }
113 
114  // Generate SpSift Config and construct SpSift object
115  Config config;
116  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
117  typename Config::MsecTimeType width_tolerance(0.01 * boost::units::si::seconds);
118  typename Config::MsecTimeType time_tolerance(0.001 * boost::units::si::seconds);
119  config.dm_tolerance(dm_tolerance);
120  config.pulse_width_tolerance(width_tolerance);
121  config.time_tolerance(time_tolerance);
122  config.linking_length(10);
123  config.num_threads(1);
124  Fof clusterer(config);
125  auto groups = clusterer(cand_list);
126  ASSERT_EQ(groups.size(),1U);
127  ASSERT_EQ(groups[0].size(),1U);
128 }
129 
130 TEST_F(FofTest, test_group_two_candidates)
131 {
132 
133  data::SpCcl<NumericalRep>::BlocksType tf_v;
134  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
135  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
136  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
137 
138 
139  // Generate SpCcl instance
140  data::SpCcl<NumericalRep> cand_list(tf_v);
141 
142  //set single pulse candidate dispersion measure
143  typename Config::Dm dm(1000.0 * pss::astrotypes::units::parsecs_per_cube_cm);
144  //set the single pulse candidate width to 1.0 ms
145  typename Config::MsecTimeType width(0.256 * boost::units::si::seconds);
146  //set the single pulse start time to 2.0 seconds
147  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
148  //set the candidate significance
149  float sigma = 10.0;
150 
151  for (std::size_t idx=0; idx<2; ++idx)
152  {
153  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
154  cand_list.push_back(candidate);
155  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
156  }
157 
158  // Generate SpSift Config and construct SpSift object
159  Config config;
160  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
161  typename Config::MsecTimeType width_tolerance(0.002 * boost::units::si::seconds);
162  typename Config::MsecTimeType time_tolerance(0.01 * boost::units::si::seconds);
163  config.dm_tolerance(dm_tolerance);
164  config.pulse_width_tolerance(width_tolerance);
165  config.time_tolerance(time_tolerance);
166  config.linking_length(5);
167  Fof clusterer(config);
168  auto groups = clusterer(cand_list);
169  ASSERT_EQ(groups.size(),1U);
170  ASSERT_EQ(groups[0].size(),2U);
171 
172 }
173 
174 TEST_F(FofTest, test_dm_grouping)
175 {
176 
177  data::SpCcl<NumericalRep>::BlocksType tf_v;
178  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
179  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
180  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
181 
182 
183  // Generate SpCcl instance
184  data::SpCcl<NumericalRep> cand_list(tf_v);
185 
186  //set single pulse candidate dispersion measure
187  data::SpCcl<NumericalRep>::SpCandidateType::Dm dm(200.234 * pss::astrotypes::units::parsecs_per_cube_cm);
188  //set the single pulse candidate width to 1.0 ms
189  typename Config::MsecTimeType width(0.00734 * boost::units::si::seconds);
190  //set the single pulse start time to 2.0 seconds
191  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
192  //set the candidate significance
193  float sigma = 10.0;
194 
195  for (std::size_t idx=0; idx<10; ++idx)
196  {
197  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
198  cand_list.push_back(candidate);
199  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.00001*boost::units::si::seconds);
200  dm += typename Config::Dm(0.0001 * pss::astrotypes::units::parsecs_per_cube_cm);
201  }
202 
203 
204  data::SpCcl<NumericalRep>::SpCandidateType::Dm dm2(263.245 * pss::astrotypes::units::parsecs_per_cube_cm);
205  for (std::size_t idx=0; idx<10; ++idx)
206  {
207  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm2, tstart, width, sigma, idx);
208  cand_list.push_back(candidate);
209  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.00001*boost::units::si::seconds);
210  dm2 += typename Config::Dm(0.0001 * pss::astrotypes::units::parsecs_per_cube_cm);
211  }
212 
213 
214 
215  // Generate SpSift Config and construct SpSift object
216  Config config;
217  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
218  typename Config::MsecTimeType width_tolerance(0.002 * boost::units::si::seconds);
219  typename Config::MsecTimeType time_tolerance(0.01 * boost::units::si::seconds);
220  config.dm_tolerance(dm_tolerance);
221  config.pulse_width_tolerance(width_tolerance);
222  config.time_tolerance(time_tolerance);
223  config.linking_length(1.717);
224  Fof clusterer(config);
225  auto groups = clusterer(cand_list);
226  ASSERT_EQ(groups.size(),2U);
227 }
228 
229 TEST_F(FofTest, test_group_multiple_candidates)
230 {
231 
232  data::SpCcl<NumericalRep>::BlocksType tf_v;
233  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
234  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
235  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
236 
237 
238  // Generate SpCcl instance
239  data::SpCcl<NumericalRep> cand_list(tf_v);
240 
241  //set single pulse candidate dispersion measure
242  typename Config::Dm dm(1000.0 * pss::astrotypes::units::parsecs_per_cube_cm);
243  //set the single pulse candidate width to 1.0 ms
244  typename Config::MsecTimeType width(0.256 * boost::units::si::seconds);
245  //set the single pulse start time to 2.0 seconds
246  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
247  //set the candidate significance
248  float sigma = 10.0;
249 
250  for (std::size_t idx=0; idx<500; ++idx)
251  {
252  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
253  cand_list.push_back(candidate);
254  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
255  }
256 
257  // Generate SpSift Config and construct SpSift object
258  Config config;
259  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
260  typename Config::MsecTimeType width_tolerance(0.002 * boost::units::si::seconds);
261  typename Config::MsecTimeType time_tolerance(0.01 * boost::units::si::seconds);
262  config.dm_tolerance(dm_tolerance);
263  config.pulse_width_tolerance(width_tolerance);
264  config.time_tolerance(time_tolerance);
265  config.linking_length(5);
266  Fof clusterer(config);
267  auto groups = clusterer(cand_list);
268  ASSERT_EQ(groups.size(),1U);
269  ASSERT_EQ(groups[0].size(),500U);
270 
271 }
272 
273 TEST_F(FofTest, test_width_negative_index)
274 {
275 
276  /* Tests that negative width index does not have any issues */
277  data::SpCcl<NumericalRep>::BlocksType tf_v;
278  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
279  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
280  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
281 
282  // Generate SpCcl instance
283  data::SpCcl<NumericalRep> cand_list(tf_v);
284 
285  //set single pulse candidate dispersion measure
286  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
287  //set the single pulse candidate width to 1.0 ms
288  typename Config::MsecTimeType width(0.002 * boost::units::si::seconds);
289  //set the single pulse start time to 2.0 seconds
290  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
291  //set the candidate significance
292  float sigma = 10.0;
293 
294  for (std::size_t idx=0; idx<5; ++idx)
295  {
296  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
297  cand_list.push_back(candidate);
298  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
299  }
300 
301  // Generate SpSift Config and construct SpSift object
302  Config config;
303  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
304  typename Config::MsecTimeType width_tolerance(0.01 * boost::units::si::seconds);
305  typename Config::MsecTimeType time_tolerance(0.001 * boost::units::si::seconds);
306  config.dm_tolerance(dm_tolerance);
307  config.pulse_width_tolerance(width_tolerance);
308  config.time_tolerance(time_tolerance);
309  config.linking_length(10);
310  Fof clusterer(config);
311  auto groups = clusterer(cand_list);
312  ASSERT_EQ(groups.size(),1U);
313  ASSERT_EQ(groups[0].size(),5U);
314 }
315 
316 TEST_F(FofTest, test_dm_negative_index)
317 {
318 
319  /* Test that negative dm index will not have any issues */
320 
321  data::SpCcl<NumericalRep>::BlocksType tf_v;
322  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
323  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
324  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
325 
326  // Generate SpCcl instance
327  data::SpCcl<NumericalRep> cand_list(tf_v);
328 
329  //set single pulse candidate dispersion measure
330  typename Config::Dm dm(0.0 * pss::astrotypes::units::parsecs_per_cube_cm);
331  //set the single pulse candidate width to 1.0 ms
332  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
333  //set the single pulse start time to 2.0 seconds
334  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
335  //set the candidate significance
336  float sigma = 10.0;
337 
338  for (std::size_t idx=0; idx<5; ++idx)
339  {
340  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
341  cand_list.push_back(candidate);
342  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
343  }
344 
345  // Generate SpSift Config and construct SpSift object
346  Config config;
347  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
348  typename Config::MsecTimeType width_tolerance(0.01 * boost::units::si::seconds);
349  typename Config::MsecTimeType time_tolerance(0.001 * boost::units::si::seconds);
350  config.dm_tolerance(dm_tolerance);
351  config.pulse_width_tolerance(width_tolerance);
352  config.time_tolerance(time_tolerance);
353  config.linking_length(10);
354  Fof clusterer(config);
355  auto groups = clusterer(cand_list);
356  ASSERT_EQ(groups.size(),1U);
357  ASSERT_EQ(groups[0].size(),5U);
358 }
359 
360 TEST_F(FofTest, test_time_negative_index)
361 {
362 
363  /* Test that negative time index will not have any problems */
364 
365  data::SpCcl<NumericalRep>::BlocksType tf_v;
366  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
367  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
368  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
369 
370  // Generate SpCcl instance
371  data::SpCcl<NumericalRep> cand_list(tf_v);
372 
373  //set single pulse candidate dispersion measure
374  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
375  //set the single pulse candidate width to 1.0 ms
376  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
377  //set the single pulse start time to 2.0 seconds
378  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(0.0 * boost::units::si::seconds);
379  //set the candidate significance
380  float sigma = 10.0;
381 
382  for (std::size_t idx=0; idx<5; ++idx)
383  {
384  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
385  cand_list.push_back(candidate);
386  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
387  }
388 
389  // Generate SpSift Config and construct SpSift object
390  Config config;
391  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
392  typename Config::MsecTimeType width_tolerance(0.01 * boost::units::si::seconds);
393  typename Config::MsecTimeType time_tolerance(0.001 * boost::units::si::seconds);
394  config.dm_tolerance(dm_tolerance);
395  config.pulse_width_tolerance(width_tolerance);
396  config.time_tolerance(time_tolerance);
397  config.linking_length(10);
398  Fof clusterer(config);
399  auto groups = clusterer(cand_list);
400  ASSERT_EQ(groups.size(),1U);
401  ASSERT_EQ(groups[0].size(),5U);
402 }
403 
404 TEST_F(FofTest, test_group_multiple_candidates_all_parameters)
405 {
406 
407  data::SpCcl<NumericalRep>::BlocksType tf_v;
408  data::TimeFrequency<Cpu, NumericalRep> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
409  tf1.sample_interval(data::TimeFrequency<Cpu, NumericalRep>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
410  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, NumericalRep>>(tf1));
411 
412 
413  // Generate SpCcl instance
414  data::SpCcl<NumericalRep> cand_list(tf_v);
415 
416  //set single pulse candidate dispersion measure
417  typename Config::Dm dm(50.0 * pss::astrotypes::units::parsecs_per_cube_cm);
418  //set the single pulse candidate width to 1.0 ms
419  typename Config::MsecTimeType width(0.256 * boost::units::si::seconds);
420  //set the single pulse start time to 2.0 seconds
421  data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
422  //set the candidate significance
423  float sigma = 10.0;
424 
425  for (std::size_t idx=0; idx<10; ++idx)
426  {
427  for (std::size_t ind=0; ind < 50; ++ind)
428  {
429  data::SpCcl<NumericalRep>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
430  cand_list.push_back(candidate);
431  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.002*boost::units::si::seconds);
432  width += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.002*boost::units::si::seconds);
433  dm += 1.0 * pss::astrotypes::units::parsecs_per_cube_cm;
434  }
435  tstart += data::SpCcl<NumericalRep>::SpCandidateType::MsecTimeType(0.1*boost::units::si::seconds);
436  }
437 
438  // Generate SpsClustering Config and construct SpsClustering object
439  Config config;
440  typename Config::Dm dm_tolerance(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
441  typename Config::MsecTimeType width_tolerance(0.002 * boost::units::si::seconds);
442  typename Config::MsecTimeType time_tolerance(0.01 * boost::units::si::seconds);
443  config.dm_tolerance(dm_tolerance);
444  config.pulse_width_tolerance(width_tolerance);
445  config.time_tolerance(time_tolerance);
446  config.linking_length(1.5);
447  Fof clusterer(config);
448  auto groups = clusterer(cand_list);
449  ASSERT_EQ(groups.size(),10U);
450  ASSERT_EQ(groups[0].size(),50U);
451 
452 }
453 
454 } // namespace test
455 } // namespace sps_clustering
456 } // namespace cheetah
457 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35