Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCclSigProcTest.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/exporters/test/SpCclSigProcTest.h"
25 #include"cheetah/exporters/SpCclSigProc.h"
26 #include"cheetah/utils/JulianClock.h"
27 #include"panda/test/TestDir.h"
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace exporters {
33 namespace test {
34 
35 
36 SpCclSigProcTest::SpCclSigProcTest()
37  : ::testing::Test()
38 {
39 }
40 
41 SpCclSigProcTest::~SpCclSigProcTest()
42 {
43 }
44 
45 void SpCclSigProcTest::SetUp()
46 {
47 }
48 
49 void SpCclSigProcTest::TearDown()
50 {
51 }
52 
53 TEST_F(SpCclSigProcTest,test_cand_write)
54 {
55  // create a tmp directoy name
56  panda::test::TestDir tmp_dir;
57  ASSERT_NO_THROW(tmp_dir.create());
58  typedef typename data::SpCcl<uint8_t>::TimeFrequencyType TimeFrequencyType;
59  data::TimeFrequency<Cpu, uint8_t>::TimeType interval(1.0 * boost::units::si::milli * boost::units::si::seconds);
60  data::SpCcl<uint8_t>::BlocksType blocks;
61  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(100000)
62  ,data::DimensionSize<data::Frequency>(10));
63  (*block).sample_interval(interval);
64  //block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
65  blocks.push_back(block);
66  blocks.push_back(std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(10)));
67  data::SpCcl<uint8_t> d1(blocks);
68  typename data::SpCcl<uint8_t>::SpCandidateType::Dm dm(12.0 * data::parsecs_per_cube_cm);
69  //set the single pulse candidate width to 1.24 ms
70  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType width(0.001 * boost::units::si::seconds);
71  //set the single pulse start time to 2.23 seconds
72  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
73  //set the candidate significance
74  float sigma = 20.0;
75 
76  for (auto idx=0; idx<10; ++idx)
77  {
78  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
79  candidate.duration_end(2000 * boost::units::si::milli * boost::units::si::seconds);
80  d1.push_back(candidate);
81  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(4.5 * boost::units::si::seconds);
82  }
83 
84  data::CandidateWindowConfig candconfig;
85 
86  data::CandidateWindow& window = candconfig.window();
87 
88  window.ms_before(150.5 * boost::units::si::milli * boost::units::si::seconds);
89  window.ms_after(150.5 * boost::units::si::milli * boost::units::si::seconds);
90 
91  SpCclSigProcConfig sigprocconfig;
92  sigprocconfig.window_config(candconfig);
93  sigprocconfig.dir(tmp_dir.dir_name());
94 
95  SpCclSigProc<uint8_t> sigproc(sigprocconfig);
96  ASSERT_NO_THROW(sigproc << d1);
97  sync();
98  boost::filesystem::directory_iterator it_end;
99  auto it = boost::filesystem::directory_iterator(tmp_dir.path());
100  auto count = 0;
101  ASSERT_FALSE(it == boost::filesystem::directory_iterator());
102  while (it != it_end)
103  {
104  boost::filesystem::path file = *it;
105  ASSERT_EQ(file.extension().string(), ".fil");
106  it++;
107  count ++;
108  }
109 
110  // check if the number of files are equal to the number of candidates
111  ASSERT_EQ(d1.size(),count);
112 
113 }
114 
115 TEST_F(SpCclSigProcTest, test_one_candidates_sigproc_file_spanning_many_blocks)
116 {
121  panda::test::TestDir tmp_dir;
122  ASSERT_NO_THROW(tmp_dir.create());
123  typedef data::SpCandidate<Cpu, float> SpCandidateType;
124  typedef data::SpCcl<uint8_t>::BlocksType::value_type::element_type TimeFreqType;
125  data::TimeFrequency<Cpu, uint8_t> tf1(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
126  data::TimeFrequency<Cpu, uint8_t> tf2(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
127  data::TimeFrequency<Cpu, uint8_t> tf3(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
128  data::TimeFrequency<Cpu, uint8_t> tf4(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
129  data::TimeFrequency<Cpu, uint8_t> tf5(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
130  data::TimeFrequency<Cpu, uint8_t> tf6(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(16));
131 
132 
133  tf1.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1000 * boost::units::si::milli * boost::units::si::seconds));
134  tf2.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1000 * boost::units::si::milli * boost::units::si::seconds));
135  tf3.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1000 * boost::units::si::milli * boost::units::si::seconds));
136  tf4.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1000 * boost::units::si::milli * boost::units::si::seconds));
137  tf5.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1000 * boost::units::si::milli * boost::units::si::seconds));
138  tf6.sample_interval(data::TimeFrequency<Cpu, uint8_t>::TimeType(1000 * boost::units::si::milli * boost::units::si::seconds));
139 
140 
141  data::SpCcl<uint8_t>::BlocksType tf_v;
142  // fill data
143  std::fill(tf1.begin(),tf1.end(),0);
144  std::fill(tf2.begin(),tf2.end(),1);
145  std::fill(tf3.begin(),tf3.end(),2);
146  std::fill(tf4.begin(),tf4.end(),0);
147  std::fill(tf5.begin(),tf5.end(),1);
148  std::fill(tf6.begin(),tf6.end(),2);
149 
150 
151  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf1));
152  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf2));
153  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf3));
154  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf4));
155  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf5));
156  tf_v.push_back(std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(tf6));
157 
158 
159  // Generate SpCcl instance
160  data::SpCcl<uint8_t> d1(tf_v);
161 
162  // Generate Candidates
163  typename SpCandidateType::Dm dm(100.0 * data::parsecs_per_cube_cm);
164  //set the single pulse candidate width to 1.24 ms
165  SpCandidateType::MsecTimeType width(1 * boost::units::si::milli * boost::units::si::seconds);
166  //set the single pulse start time to 2.23 seconds
167  SpCandidateType::MsecTimeType tstart(5 * boost::units::si::seconds);
168  //set the candidate significance
169  float sigma = 20.0;
170  //set end time
171  SpCandidateType::MsecTimeType tend(2000 * boost::units::si::milli * boost::units::si::seconds);
172  // Generate Candidates
173  typename SpCandidateType::Dm dm1(100.0 * data::parsecs_per_cube_cm);
174  //set the single pulse candidate width to 1.24 ms
175  SpCandidateType::MsecTimeType width1(1 * boost::units::si::milli * boost::units::si::seconds);
176  //set the single pulse start time to 2.23 seconds
177  SpCandidateType::MsecTimeType tstart1(305 * boost::units::si::seconds);
178  //set the candidate significance
179  float sigma1 = 20.0;
180  //set end time
181  SpCandidateType::MsecTimeType tend1(2000 * boost::units::si::milli * boost::units::si::seconds);
182 
183 
184  SpCandidateType candidate(dm, tstart, width, sigma, 1);
185  SpCandidateType candidate1(dm1, tstart1, width1, sigma1, 2);
186 
187  candidate.duration_end(tend);
188  candidate1.duration_end(tend1);
189  d1.push_back(candidate);
190  d1.push_back(candidate1);
191 
192  data::CandidateWindowConfig candconfig;
193 
194  data::CandidateWindow& window = candconfig.window();
195 
196  window.ms_before(2000 * boost::units::si::milli * boost::units::si::seconds);
197  window.ms_after(200000 * boost::units::si::milli * boost::units::si::seconds);
198 
199  SpCclSigProcConfig sigprocconfig;
200  sigprocconfig.window_config(candconfig);
201  sigprocconfig.dir(tmp_dir.dir_name());
202 
203  SpCclSigProc<uint8_t> sigproc(sigprocconfig);
204  ASSERT_NO_THROW(sigproc << d1);
205  sync();
206  boost::filesystem::directory_iterator it_end;
207  auto it = boost::filesystem::directory_iterator(tmp_dir.path());
208  auto count = 0;
209  ASSERT_FALSE(it == boost::filesystem::directory_iterator());
210  while (it != it_end)
211  {
212  boost::filesystem::path file = *it;
213  ASSERT_EQ(file.extension().string(), ".fil");
214  it++;
215  count++;
216  }
217  ASSERT_EQ(d1.size(),count);
218 }
219 
220 }// namespace test
221 }// namespace exporters
222 }// namespace cheetah
223 }// namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35