Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpsClusteringTest.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/SpsClusteringTest.h"
25 #include "cheetah/sps_clustering/SpsClustering.h"
26 #include "cheetah/sps_clustering/Fof.h"
27 
28 namespace ska {
29 namespace cheetah {
30 namespace sps_clustering {
31 namespace test {
32 
33 
34 SpsClusteringTest::SpsClusteringTest()
35  : ::testing::Test()
36 {
37 }
38 
39 SpsClusteringTest::~SpsClusteringTest()
40 {
41 }
42 
43 void SpsClusteringTest::SetUp()
44 {
45 }
46 
47 void SpsClusteringTest::TearDown()
48 {
49 }
50 
51 TEST_F(SpsClusteringTest, test_sps_clustering_no_tf_blocks)
52 {
53  /* The test should verify that no clustering happens when no TF blocks are available */
54  //Create new SpCcl<uint8_t> instance
55  std::shared_ptr<data::SpCcl<uint8_t>> cand_list = std::make_shared<data::SpCcl<uint8_t>>();
56 
57  ASSERT_EQ(cand_list->tf_blocks().size(),std::size_t(0));
58 
59  //set single pulse candidate dispersion measure
60  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
61  //set the single pulse candidate width to 1.0 ms
62  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
63  //set the single pulse start time to 2.0 seconds
64  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
65  //set the candidate significance
66  float sigma = 10.0;
67 
68  for (std::size_t idx=0; idx<10; ++idx)
69  {
70  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
71  cand_list->push_back(candidate);
72  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.05*boost::units::si::seconds);
73  dm += typename Config::Dm(1.0 * pss::astrotypes::units::parsecs_per_cube_cm);
74  }
75 
76  // Generate SpSift Config and construct SpSift object
77  Config config;
78  typename Config::Dm dm_tolerance(2.0 * pss::astrotypes::units::parsecs_per_cube_cm);
79  typename Config::MsecTimeType width_tolerance(0.01 * boost::units::si::seconds);
80  typename Config::MsecTimeType time_tolerance(0.01 * boost::units::si::seconds);
81  config.dm_tolerance(dm_tolerance);
82  config.pulse_width_tolerance(width_tolerance);
83  config.time_tolerance(time_tolerance);
84  config.linking_length(1.732);
85  // Run clustering
86  SpsClustering merger(config);
87  ASSERT_NO_THROW(merger(cand_list));
88 
89  // Check if it has done the right things
90  ASSERT_EQ(cand_list->size(),10U);
91 }
92 
93 TEST_F(SpsClusteringTest, test_sps_clustering_clustering_one_candidate)
94 {
95  /* The test should verify that no clustering happens when no TF blocks are available */
96 
97  data::TimeFrequency<Cpu, uint8_t> tf1(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
98 
99  tf1.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
100 
101  data::SpCcl<uint8_t>::BlocksType tf_v;
102  // fill data
103  std::fill(tf1.begin(),tf1.end(),0);
104 
105  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf1));
106 
107  std::shared_ptr<data::SpCcl<uint8_t>> cand_list = std::make_shared<data::SpCcl<uint8_t>>(tf_v);
108 
109  //set single pulse candidate dispersion measure
110  typename Config::Dm dm(12.0 * pss::astrotypes::units::parsecs_per_cube_cm);
111  //set the single pulse candidate width to 1.0 ms
112  typename Config::MsecTimeType width(0.001 * boost::units::si::seconds);
113  //set the single pulse start time to 2.0 seconds
114  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
115  //set the candidate significance
116  float sigma = 10.0;
117 
118  for (std::size_t idx=0; idx<5; ++idx)
119  {
120  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
121  cand_list->push_back(candidate);
122  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.001*boost::units::si::seconds);
123  dm += 0.5 * pss::astrotypes::units::parsecs_per_cube_cm;
124  sigma += 1.0;
125  }
126 
127  // Generate SpSift Config and construct SpSift object
128  Config config;
129  typename Config::Dm dm_tolerance(5.0 * pss::astrotypes::units::parsecs_per_cube_cm);
130  typename Config::MsecTimeType width_tolerance(0.01 * boost::units::si::seconds);
131  typename Config::MsecTimeType time_tolerance(1.0 * boost::units::si::seconds);
132  config.dm_tolerance(dm_tolerance);
133  config.pulse_width_tolerance(width_tolerance);
134  config.time_tolerance(time_tolerance);
135  config.linking_length(1);
136  // Run clustering
137  SpsClustering merger(config);
138  auto grouped_cands = merger(cand_list);
139 
140  // Check if it has done the right things
141  ASSERT_EQ(grouped_cands->size(), 1U);
142 }
143 
144 TEST_F(SpsClusteringTest, test_sps_clustering_multiple_candidates_within_limits)
145 {
146 
147  data::SpCcl<uint8_t>::BlocksType tf_v;
148  data::TimeFrequency<Cpu, uint8_t> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
149  tf1.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
150  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf1));
151 
152 
153  // Generate SpCcl instance
154  std::shared_ptr<data::SpCcl<uint8_t>> cand_list = std::make_shared<data::SpCcl<uint8_t>>(tf_v);
155 
156  //set single pulse candidate dispersion measure
157  typename Config::Dm dm(5000.0 * pss::astrotypes::units::parsecs_per_cube_cm);
158  //set the single pulse candidate width to 1.0 ms
159  typename Config::MsecTimeType width(0.256 * boost::units::si::seconds);
160  //set the single pulse start time to 2.0 seconds
161  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
162  //set the candidate significance
163  float sigma = 10.0;
164 
165  for (std::size_t idx=0; idx<10; ++idx)
166  {
167  for (std::size_t ind=0; ind < 50; ++ind)
168  {
169  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
170  cand_list->push_back(candidate);
171  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.002*boost::units::si::seconds);
172  width += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.002*boost::units::si::seconds);
173  dm += 10.0 * pss::astrotypes::units::parsecs_per_cube_cm;
174  sigma += 1.0;
175  }
176  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.1*boost::units::si::seconds);
177 
178  }
179 
180  // Generate SpSift Config and construct SpSift object
181  Config config;
182  typename Config::Dm dm_tolerance(20.0 * pss::astrotypes::units::parsecs_per_cube_cm);
183  typename Config::MsecTimeType width_tolerance(0.002 * boost::units::si::seconds);
184  typename Config::MsecTimeType time_tolerance(0.1 * boost::units::si::seconds);
185  config.dm_tolerance(dm_tolerance);
186  config.pulse_width_tolerance(width_tolerance);
187  config.time_tolerance(time_tolerance);
188  config.linking_length(1.5);
189 
190  SpsClustering merger(config);
191  auto grouped_cands = merger(cand_list);
192 
193  // Check if it has done the right things
194  ASSERT_EQ(grouped_cands->size(),1U);
195 }
196 
197 TEST_F(SpsClusteringTest, test_sps_clustering_multiple_candidates_beyond_limits)
198 {
199 
200  data::SpCcl<uint8_t>::BlocksType tf_v;
201  data::TimeFrequency<Cpu, uint8_t> tf1(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(16));
202  tf1.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1 * boost::units::si::milli * boost::units::si::seconds));
203  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf1));
204 
205 
206  // Generate SpCcl instance
207  std::shared_ptr<data::SpCcl<uint8_t>> cand_list = std::make_shared<data::SpCcl<uint8_t>>(tf_v);
208 
209  //set single pulse candidate dispersion measure
210  typename Config::Dm dm(5000.0 * pss::astrotypes::units::parsecs_per_cube_cm);
211  //set the single pulse candidate width to 1.0 ms
212  typename Config::MsecTimeType width(0.256 * boost::units::si::seconds);
213  //set the single pulse start time to 2.0 seconds
214  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
215  //set the candidate significance
216  float sigma = 10.0;
217 
218  for (std::size_t idx=0; idx<10; ++idx)
219  {
220  for (std::size_t ind=0; ind < 50; ++ind)
221  {
222  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
223  cand_list->push_back(candidate);
224  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.002*boost::units::si::seconds);
225  width += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.002*boost::units::si::seconds);
226  dm += 10.0 * pss::astrotypes::units::parsecs_per_cube_cm;
227  sigma += 1.0;
228  }
229  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(0.5*boost::units::si::seconds);
230 
231  }
232 
233  // Generate SpSift Config and construct SpSift object
234  Config config;
235  typename Config::Dm dm_tolerance(20.0 * pss::astrotypes::units::parsecs_per_cube_cm);
236  typename Config::MsecTimeType width_tolerance(0.002 * boost::units::si::seconds);
237  typename Config::MsecTimeType time_tolerance(0.1 * boost::units::si::seconds);
238  config.dm_tolerance(dm_tolerance);
239  config.pulse_width_tolerance(width_tolerance);
240  config.time_tolerance(time_tolerance);
241  config.linking_length(1.5);
242 
243  SpsClustering merger(config);
244  auto grouped_cands = merger(cand_list);
245 
246  // Check if it has done the right things
247  ASSERT_EQ(grouped_cands->size(),10U);
248 }
249 
250 } // namespace test
251 } // namespace spsift
252 } // namespace cheetah
253 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35