Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpsTest.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/emulator/test/SpsTest.h"
25 #include "cheetah/sps/emulator/Sps.h"
26 #include "cheetah/sps/test_utils/SpsTester.h"
27 #include "cheetah/generators/GaussianNoiseConfig.h"
28 #include "cheetah/generators/GaussianNoise.h"
29 #include "cheetah/generators/DispersedPulse.h"
30 #include "cheetah/utils/ModifiedJulianClock.h"
31 
32 namespace ska {
33 namespace cheetah {
34 namespace sps {
35 namespace emulator {
36 namespace test {
37 
38 
39 SpsTest::SpsTest()
40  : ::testing::Test()
41 {
42 }
43 
44 SpsTest::~SpsTest()
45 {
46 }
47 
48 void SpsTest::SetUp()
49 {
50 }
51 
52 void SpsTest::TearDown()
53 {
54 }
55 
56 namespace {
57 typedef sps::CommonTypes<sps::Config, uint8_t> TestSpsTraits;
58 } // namepsace
59 
60 TEST_F(SpsTest, test_instantiation)
61 {
62  sps::Config config; // Make config object
63  Sps<TestSpsTraits> testsps(config);
64 }
65 
66 TEST_F(SpsTest, test_candidate_bounds)
67 {
68  panda::PoolResource<cheetah::Cpu> cpu(0);
69 
70  sps::Config config;
71  typedef data::DedispersionMeasureType<float> Dm;
72  config.add_dm_range(Dm(0.0 * data::parsecs_per_cube_cm),Dm(1000.0 * data::parsecs_per_cube_cm), Dm(25.0 * data::parsecs_per_cube_cm));
73  typedef Sps<TestSpsTraits> SpsType;
74  typedef typename TestSpsTraits::value_type NumericalRep;
75  SpsType testsps(config);
76 
77  typename SpsType::BufferType buffer(3000);
78  typedef typename SpsType::TimeFrequencyType TimeFrequencyType;
79  data::DimensionSize<data::Frequency> number_of_channels(64);
80  std::size_t chunk_samples=buffer.capacity()/number_of_channels;
81 
82  typedef typename SpsType::TimeFrequencyType TimeFrequencyType;
83 
84  utils::ModifiedJulianClock::time_point start_time(utils::ModifiedJulianClock::duration(6000)); // = utils::ModifiedJulianClock::now();
85 
86  auto data = TimeFrequencyType::make_shared(data::DimensionSize<data::Time>(chunk_samples), number_of_channels);
87  data->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
88  data->sample_interval(TimeFrequencyType::TimeType(0.0000640000 * boost::units::si::seconds));
89  data->set_channel_frequencies_const_width(data::FrequencyType(1000.0 * boost::units::si::mega * data::hz), data::FrequencyType(-1.0 * boost::units::si::mega * data::hz));
90 
91 
92  config.emulator_config().candidate_rate(3397);
93  auto it = data->begin();
94  buffer.insert(it, data->end(), std::const_pointer_cast<const TimeFrequencyType>(data));
95 
96  for (data::DimensionIndex<data::Time> offset(0); offset < data->number_of_spectra() - 1; ++offset)
97  {
98  SCOPED_TRACE(offset);
99  boost::units::quantity<data::MilliSeconds,double> offset_time((double)offset * data->sample_interval());
100  boost::units::quantity<data::MilliSeconds,double> block_end(data->number_of_spectra() * data->sample_interval());
101 
102  buffer.offset_first_block(offset * data->number_of_channels());
103  typedef data::DmTrials<Cpu,float> DmTrialType;
104  typedef data::SpCcl<NumericalRep> SpType;
105  bool dm_handler_called = false;
106  std::shared_ptr<SpType> sp_data_returned;
107  auto dm_handler = [&](std::shared_ptr<DmTrialType>) {dm_handler_called = true;};
108  auto sp_handler = [&](std::shared_ptr<SpType> sp_data) {sp_data_returned = sp_data;};
109  testsps(cpu, buffer, dm_handler, sp_handler);
110 
111  // Test that the sp_data_returned_object exists
112  ASSERT_NE(sp_data_returned.get(), nullptr);
113 
114  // Test that the start time of the block is start_time (in MJD)
115  ASSERT_EQ(sp_data_returned->start_time(), start_time + offset_time);
116 
117  // Check that the offset times are the same
118  ASSERT_DOUBLE_EQ(sp_data_returned->offset_time().value(), offset_time.value());
119  ASSERT_DOUBLE_EQ(sp_data_returned->offset_time().value(), offset_time.value());
120 
121  // Check that the number of candidates returned is correct
122  ASSERT_EQ(sp_data_returned->size(), 10);
123 
124  // For each cand object in sp_data_returned
125  for (auto const& cand : *sp_data_returned)
126  {
127  // Test that the start time of each candidate generated (in MJD)
128  // is greater than the start time of the block
129  ASSERT_GE(sp_data_returned->start_time(cand), start_time + offset_time);
130  ASSERT_GE(sp_data_returned->start_time(cand), start_time);
131 
132  // Test that the start time of the candidate occurs inside the block
133  ASSERT_GE(data->start_time() + block_end, sp_data_returned->start_time(cand));
134 
135  // Test the DM range
136  std::vector<Dm> dm_trials = config.dm_trials();
137  auto dm_it = std::find (dm_trials.begin(), dm_trials.end(), cand.dm());
138  ASSERT_NE(dm_it, dm_trials.end()) << "CAND DM " << cand.dm() << "SIZE " << dm_trials.size();
139  }
140 
141  }
142 }
143 
144 template<typename NumericalT>
145 struct EmulatorTraits : public sps::test::SpsTesterTraits<typename sps::emulator::Sps<sps::CommonTypes<sps::Config, NumericalT>>::Architecture
146  ,typename sps::emulator::Sps<sps::CommonTypes<sps::Config, NumericalT>>::Architecture>
147 {
150  typedef typename BaseT::Arch Arch;
151  void configure(sps::Config& config) override {
152  BaseT::configure(config);
153  auto& emulator_config = config.emulator_config();
154  emulator_config.activate();
155 
156  emulator_config.candidate_rate(10);
157  }
158 };
159 
160 } // namespace test
161 } // namespace emulator
162 } // namespace sps
163 } // namespace cheetah
164 } // namespace ska
165 
166 namespace ska {
167 namespace cheetah {
168 namespace sps {
169 namespace test {
170 
171 typedef ::testing::Types<sps::emulator::test::EmulatorTraits<uint8_t>> EmulatorTraitsTypes;
172 INSTANTIATE_TYPED_TEST_CASE_P(Emulator, SpsTester, EmulatorTraitsTypes);
173 
174 } // namespace test
175 } // namespace sps
176 } // namespace cheetah
177 } // namespace ska
all non-templated options for the sps module
Definition: Config.h:52
void activate()
activate the algorithm
Definition: Config.cpp:66
Produces a stream of random SpCandidate&#39;s.
Definition: Sps.h:44
Some limits and constants for FLDO.
Definition: Brdz.h:35