Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCclSpeadProducerTest.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/producers/test/SpCclSpeadProducerTest.h"
25 #include "cheetah/exporters/SpCclSpeadStreamerConfig.h"
26 #include "cheetah/producers/SpCclSpeadProducer.h"
27 #include "cheetah/exporters/test/SpCclSpeadStreamerTest.h"
28 #include "cheetah/exporters/SpCclSpeadStreamer.h"
29 #include "cheetah/exporters/SpCclSpeadReader.h"
30 #include "cheetah/utils/ModifiedJulianClock.h"
31 #include <panda/ProcessingEngine.h>
32 #include <panda/ProcessingEngineConfig.h>
33 #include <vector>
34 
35 
36 namespace ska {
37 namespace cheetah {
38 namespace producers {
39 namespace test {
40 
41 template<typename T>
42 SpCclSpeadProducerTest<T>::SpCclSpeadProducerTest()
43  : ::testing::Test()
44 {
45 }
46 
47 TYPED_TEST(SpCclSpeadProducerTest, test_instantiation)
48 {
49  typedef TypeParam TimeFrequencyType;
50  typedef SpCclSpeadProducer<TimeFrequencyType> ProducerTestType;
51  typedef ska::panda::DataManager<ProducerTestType> DataManagerType;
52 
53  // setup the consumer side
54  exporters::SpCclSpeadReaderConfig reader_config;
55  ProducerTestType producer(reader_config);
56  DataManagerType data_manager(producer);
57 }
58 
59 TYPED_TEST(SpCclSpeadProducerTest, test_single_candidate_reception)
60 {
61  typedef TypeParam TimeFrequencyType;
62  typedef typename TimeFrequencyType::NumericalRep NumericalRep;
63  typedef data::SpCcl<NumericalRep> SpCclType;
64  typedef typename SpCclType::SpCandidateType Candidate;
65 
66  typedef SpCclSpeadProducer<TimeFrequencyType> ProducerTestType;
67  typedef ska::panda::DataManager<ProducerTestType> DataManagerType;
68  typedef typename ProducerTestType::SpCclType SpCandidateDataType;
69 
70  exporters::SpCclSpeadReaderConfig reader_config;
71  ProducerTestType producer(reader_config);
72  DataManagerType data_manager(producer);
73 
74 
75  // set up the data
76  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(2458179.500000));
77 
78  // Define a BlocksType called blocks
79  typename SpCclType::BlocksType blocks;
80 
81  // Generate a TF block
82  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(
83  data::DimensionSize<data::Time>(1000)
84  , data::DimensionSize<data::Frequency>(10));
85 
86  // Set start time of block
87  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
88 
89  // Set sample interval
90  block->sample_interval(0.001 * boost::units::si::seconds);
91 
92  // Add block to blocks
93  blocks.push_back(block);
94  blocks.push_back(std::make_shared<TimeFrequencyType>( data::DimensionSize<data::Time>(100)
95  , data::DimensionSize<data::Frequency>(10)));
96 
97  std::shared_ptr<data::SpCcl<NumericalRep>> data(new data::SpCcl<NumericalRep>(blocks));
98 
99  // Set duration of candidate in bins
100  std::size_t cand_duration = 40;
101 
102  // Set an end time
103  typename Candidate::MsecTimeType cand1_tend(cand_duration * block->sample_interval());
104 
105  // Set a DM
106  typename Candidate::Dm cand1_dm(00.0 * data::parsecs_per_cube_cm);
107 
108  // Set other candidate parameters
109  Candidate candidate_1( cand1_dm
110  , typename Candidate::MsecTimeType(0.0 * boost::units::si::seconds)
111  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
112  , cand1_tend
113  , 2.0
114  );
115 
116  data->push_back(candidate_1);
117 
118  ska::panda::ProcessingEngine engine(1);
120  exporters::SpCclSpeadStreamer writer(config, engine);
121  writer << *data;
122 
123  std::tuple<std::shared_ptr<SpCandidateDataType>> received_data_tuple = data_manager.next();
124  SpCandidateDataType const& received_data = *std::get<0>(received_data_tuple);
125 
126  // Test data block
127  ASSERT_LE(received_data.data_size(), data->tf_blocks()[0]->data_size());
128  ASSERT_EQ(received_data.number_of_channels(), block->number_of_channels());
129  ASSERT_EQ(received_data.sample_interval(), block->sample_interval());
130  ASSERT_EQ(received_data.number_of_spectra(), cand_duration);
131 
132  // Test candidate parameters
133  ASSERT_EQ(received_data.number_of_candidates(), data->size());
134  ASSERT_EQ(received_data.candidate(0).dm(), (*data)[0].dm());
135  ASSERT_EQ((received_data).candidate(0).sigma(), (*data)[0].sigma());
136  ASSERT_EQ(received_data.candidate(0).width(), (*data)[0].width());
137  ASSERT_EQ(received_data.candidate(0).duration(), (*data)[0].tend());
138  ASSERT_EQ(received_data.candidate(0).start_time(), block->start_time());
139 }
140 
141 
142 TYPED_TEST(SpCclSpeadProducerTest, test_multiple_candidate_reception)
143 {
144  typedef TypeParam TimeFrequencyType;
145  typedef typename TimeFrequencyType::NumericalRep NumericalRep;
146  typedef data::SpCcl<NumericalRep> SpCclType;
147  typedef typename SpCclType::SpCandidateType Candidate;
148 
149  typedef SpCclSpeadProducer<TimeFrequencyType> ProducerTestType;
150  typedef ska::panda::DataManager<ProducerTestType> DataManagerType;
151  typedef typename ProducerTestType::SpCclType SpCandidateDataType;
152 
153  exporters::SpCclSpeadReaderConfig reader_config;
154  ProducerTestType producer(reader_config);
155  DataManagerType data_manager(producer);
156 
157  // set up the data
158  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(2458179.500000));
159 
160  // Define a BlocksType called blocks
161  typename SpCclType::BlocksType blocks;
162 
163  // Generate a TF block
164  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(
165  data::DimensionSize<data::Time>(1000)
166  , data::DimensionSize<data::Frequency>(10));
167 
168  // Set start time of block
169  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
170 
171  // Set sample interval
172  block->sample_interval(0.001 * boost::units::si::seconds);
173 
174  // Add block to blocks
175  blocks.push_back(block);
176  blocks.push_back(std::make_shared<TimeFrequencyType>( data::DimensionSize<data::Time>(100)
177  , data::DimensionSize<data::Frequency>(10)));
178 
179 
180  std::shared_ptr<TimeFrequencyType> block_2 = std::make_shared<TimeFrequencyType>(
181  data::DimensionSize<data::Time>(600)
182  , data::DimensionSize<data::Frequency>(10));
183 
184  block_2->start_time(block->end_time() + block->sample_interval());
185  block_2->sample_interval(0.001 * boost::units::si::seconds);
186  blocks.push_back(block_2);
187 
188  std::shared_ptr<data::SpCcl<NumericalRep>> data(new data::SpCcl<NumericalRep>(blocks));
189 
190  std::size_t cand_duration = 40; // number of bins candidate 1 covers
191 
192  // Set an end time for candidate 1
193  typename Candidate::MsecTimeType cand1_tend(cand_duration * block->sample_interval());
194 
195  // Set a DM for candidate 1
196  typename Candidate::Dm cand1_dm(00.0 * data::parsecs_per_cube_cm);
197 
198  // Set other candidate parameters
199  Candidate candidate_1( cand1_dm
200  , typename Candidate::MsecTimeType(0.0 * boost::units::si::seconds)
201  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
202  , cand1_tend
203  , 2.0
204  );
205 
206  data->push_back(candidate_1);
207 
208  std::size_t cand2_duration = 20; // number of bins candidate 2 covers
209 
210  // Set an end time for candidate 2
211  typename Candidate::MsecTimeType cand2_tend(cand2_duration * block->sample_interval());
212 
213  // Set a DM for candidate 2
214  typename Candidate::Dm cand2_dm(10.0 * data::parsecs_per_cube_cm);
215 
216  // Set other candidate parameters
217  Candidate candidate_2( cand2_dm
218  , cand1_tend - static_cast<typename Candidate::MsecTimeType>(block->sample_interval())
219  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
220  , cand1_tend + static_cast<typename Candidate::MsecTimeType>(block->sample_interval())
221  , 2.0
222  );
223 
224  data->push_back(candidate_2);
225 
226  ska::panda::ProcessingEngine engine(1);
228  exporters::SpCclSpeadStreamer writer(config, engine);
229  writer << *data;
230 
231  std::tuple<std::shared_ptr<SpCandidateDataType>> received_data_tuple = data_manager.next();
232  SpCandidateDataType const& received_data = *std::get<0>(received_data_tuple);
233 
234  // Test data block
235  ASSERT_LE(received_data.data_size(), data->tf_blocks()[0]->data_size());
236  ASSERT_EQ(received_data.number_of_channels(), block->number_of_channels());
237  ASSERT_EQ(received_data.sample_interval(), block->sample_interval());
238  ASSERT_EQ(received_data.number_of_spectra(), cand_duration + 1);
239 
240  // Test candidate data
241  ASSERT_EQ(received_data.number_of_candidates(), data->size());
242  for(std::size_t i=0; i< received_data.number_of_candidates(); ++i) {
243  ASSERT_EQ(received_data.candidate(i).dm(), (*data)[i].dm());
244  ASSERT_EQ(received_data.candidate(i).sigma(), (*data)[i].sigma());
245  ASSERT_EQ(received_data.candidate(i).width(), (*data)[i].width());
246  ASSERT_EQ(received_data.candidate(i).duration(), (*data)[i].tend());
247  }
248  ASSERT_EQ(received_data.candidate(0).start_time(), block->start_time());
249  ASSERT_EQ(received_data.candidate(1).start_time(), data->start_time(candidate_2));
250 }
251 
252 } // namespace test
253 } // namespace producers
254 } // namespace cheetah
255 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35