Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpSiftTest.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/spsift/test/SpSiftTest.h"
25 
26 namespace ska {
27 namespace cheetah {
28 namespace spsift {
29 namespace test {
30 
31 
32 SpSiftTest::SpSiftTest()
33  : ::testing::Test()
34 {
35 }
36 
37 SpSiftTest::~SpSiftTest()
38 {
39 }
40 
41 void SpSiftTest::SetUp()
42 {
43 }
44 
45 void SpSiftTest::TearDown()
46 {
47 }
48 
49 TEST_F(SpSiftTest, test_sift_dm)
50 {
51  typedef data::SpCcl<uint8_t>::BlocksType::value_type::element_type TimeFrequencyType;
52 
53  std::size_t idx;
54 
55  //Create new SpCcl<uint8_t> instance
56  data::SpCcl<uint8_t> cand_list;
57 
58  ASSERT_EQ(cand_list.tf_blocks().size(),std::size_t(0));
59 
60  //set single pulse candidate dispersion measure
61  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
62  //set the single pulse candidate width to 1.0 ms
63  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
64  //set the single pulse start time to 2.0 seconds
65  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
66  //set the candidate significance
67  float sigma = 10.0;
68 
69  for (idx=0; idx<10; ++idx)
70  {
71  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
72  cand_list.push_back(candidate);
73  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(1.0*boost::units::si::seconds);
74  dm += typename Config::Dm(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
75  }
76 
77 
78  // Generate SpSift Config and construct SpSift object
79  Config config;
80  typename Config::Dm dm_thresh(17.0 * pss::astrotypes::units::parsecs_per_cube_cm);
81  typename Config::MsecTimeType width_thresh(0.025 * boost::units::si::seconds);
82  float sigma_threshold = 8.0;
83  config.dm_threshold(dm_thresh);
84  config.pulse_width_threshold(width_thresh);
85  config.sigma_threshold(sigma_threshold);
86 
87  SpSift sifter(config);
88 
89  sifter(cand_list);
90 
91  ASSERT_EQ(cand_list.size(), 5U);
92 
93  for (std::uint8_t ii = 0 ; ii < cand_list.size(); ++ii)
94  {
95  ASSERT_LE(dm_thresh.value() , cand_list[ii].dm().value());
96  }
97 }
98 
99 TEST_F(SpSiftTest, test_sift_width)
100 {
101  typedef data::SpCcl<uint8_t>::BlocksType::value_type::element_type TimeFrequencyType;
102 
103  std::size_t idx;
104 
105  //Create new SpCcl<uint8_t> instance
106  data::SpCcl<uint8_t> cand_list;
107 
108  ASSERT_EQ(cand_list.tf_blocks().size(),std::size_t(0));
109 
110  //set single pulse candidate dispersion measure
111  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
112  //set the single pulse candidate width to 1.0 ms
113  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
114  //set the single pulse start time to 2.0 seconds
115  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
116  //set the candidate significance
117  float sigma = 10.0;
118 
119  for(idx=0; idx<10; ++idx)
120  {
121  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
122  cand_list.push_back(candidate);
123  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(1.0*boost::units::si::seconds);
124  width += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.005 * boost::units::si::seconds);
125  }
126 
127 
128  // Generate SpSift Config and construct SpSift object
129  Config config;
130  typename Config::Dm dm_thresh(10.0 * pss::astrotypes::units::parsecs_per_cube_cm);
131  typename Config::MsecTimeType width_thresh(0.025 * boost::units::si::seconds);
132  float sigma_threshold = 8.0;
133  config.dm_threshold(dm_thresh);
134  config.pulse_width_threshold(width_thresh);
135  config.sigma_threshold(sigma_threshold);
136 
137  SpSift sifter(config);
138 
139  sifter(cand_list);
140 
141  ASSERT_EQ(cand_list.size(), 5U);
142 
143  for(std::uint8_t ii = 0; ii < cand_list.size(); ++ii)
144  {
145  ASSERT_GT(width_thresh, cand_list[ii].width());
146  }
147 
148 }
149 
150 TEST_F(SpSiftTest, test_sift_sigma)
151 {
152  typedef data::SpCcl<uint8_t>::BlocksType::value_type::element_type TimeFrequencyType;
153 
154  std::size_t idx;
155 
156  //Create new SpCcl<uint8_t> instance
157  data::SpCcl<uint8_t> cand_list;
158 
159  ASSERT_EQ(cand_list.tf_blocks().size(),std::size_t(0));
160 
161  //set single pulse candidate dispersion measure
162  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
163  //set the single pulse candidate width to 1.0 ms
164  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
165  //set the single pulse start time to 2.0 seconds
166  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
167  //set the candidate significance
168  float sigma = 10.0;
169 
170  for(idx=0; idx<10; ++idx)
171  {
172  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
173  cand_list.push_back(candidate);
174  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(1.0*boost::units::si::seconds);
175  sigma += 1.0;
176  }
177 
178 
179  // Generate SpSift Config and construct SpSift object
180  Config config;
181  typename Config::Dm dm_thresh(10.0 * pss::astrotypes::units::parsecs_per_cube_cm);
182  typename Config::MsecTimeType width_thresh(0.025 * boost::units::si::seconds);
183  float sigma_threshold = 15.0;
184  config.dm_threshold(dm_thresh);
185  config.pulse_width_threshold(width_thresh);
186  config.sigma_threshold(sigma_threshold);
187 
188  SpSift sifter(config);
189 
190  sifter(cand_list);
191 
192  ASSERT_EQ(cand_list.size(), 5U);
193 
194  for (std::uint8_t ii = 0; ii < cand_list.size(); ++ii)
195  {
196  ASSERT_LE(sigma_threshold, (float) cand_list[ii].sigma());
197  }
198 
199 }
200 
201 TEST_F(SpSiftTest, test_sift_many_candidates)
202 {
203  typedef data::SpCcl<uint8_t>::BlocksType::value_type::element_type TimeFrequencyType;
204 
205  //Create new SpCcl<uint8_t> instance
206  data::SpCcl<uint8_t> cand_list;
207 
208  ASSERT_EQ(cand_list.tf_blocks().size(),std::size_t(0));
209 
210  //set single pulse candidate dispersion measure
211  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
212  //set the single pulse candidate width to 1.0 ms
213  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
214  //set the single pulse start time to 2.0 seconds
215  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
216  //set the candidate significance
217  float sigma = 16.0;
218 
219  for(std::size_t idx=0; idx<100000; ++idx)
220  {
221  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
222  cand_list.push_back(candidate);
223  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(1.0*boost::units::si::seconds);
224  sigma += 1.0;
225  }
226 
227 
228  // Generate SpSift Config and construct SpSift object
229  Config config;
230  typename Config::Dm dm_thresh(10.0 * pss::astrotypes::units::parsecs_per_cube_cm);
231  typename Config::MsecTimeType width_thresh(0.025 * boost::units::si::seconds);
232  float sigma_threshold = 15.0;
233  config.dm_threshold(dm_thresh);
234  config.pulse_width_threshold(width_thresh);
235  config.sigma_threshold(sigma_threshold);
236  config.maximum_candidates(50000);
237 
238  SpSift sifter(config);
239 
240  sifter(cand_list);
241 
242  ASSERT_EQ(cand_list.size(), 50000U);
243 }
244 
245 TEST_F(SpSiftTest, test_sift_many_candidates_0threshold)
246 {
247  typedef data::SpCcl<uint8_t>::BlocksType::value_type::element_type TimeFrequencyType;
248 
249  //Create new SpCcl<uint8_t> instance
250  data::SpCcl<uint8_t> cand_list;
251 
252  ASSERT_EQ(cand_list.tf_blocks().size(),std::size_t(0));
253 
254  //set single pulse candidate dispersion measure
255  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
256  //set the single pulse candidate width to 1.0 ms
257  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
258  //set the single pulse start time to 2.0 seconds
259  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
260  //set the candidate significance
261  float sigma = 10.0;
262 
263  for(std::size_t idx=0; idx<100000; ++idx)
264  {
265  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
266  cand_list.push_back(candidate);
267  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(1.0*boost::units::si::seconds);
268  sigma += 1.0;
269  }
270 
271 
272  // Generate SpSift Config and construct SpSift object
273  Config config;
274  typename Config::Dm dm_thresh(10.0 * pss::astrotypes::units::parsecs_per_cube_cm);
275  typename Config::MsecTimeType width_thresh(0.025 * boost::units::si::seconds);
276  float sigma_threshold = 0.0;
277  config.dm_threshold(dm_thresh);
278  config.pulse_width_threshold(width_thresh);
279  config.sigma_threshold(sigma_threshold);
280  config.maximum_candidates(0);
281 
282  SpSift sifter(config);
283 
284  sifter(cand_list);
285 
286  ASSERT_EQ(cand_list.size(), 100000U);
287 }
288 
289 } // namespace test
290 } // namespace spsift
291 } // namespace cheetah
292 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35