Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
TdaoTester.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 
25 #include "cheetah/tdao/test_utils/TdaoTester.h"
26 #include "cheetah/data/TimeSeries.h"
27 #include "cheetah/utils/Architectures.h"
28 #include "cheetah/data/DedispersionMeasure.h"
29 #include "panda/Log.h"
30 
31 #include <boost/units/quantity.hpp>
32 #include <boost/units/systems/si/codata_constants.hpp>
33 
34 namespace ska {
35 namespace cheetah {
36 namespace tdao {
37 namespace test {
38 
39 template<typename ArchitectureTag, typename ArchitectureCapability>
40 TdaoTesterTraits<ArchitectureTag,ArchitectureCapability>::TdaoTesterTraits()
41  :_api(_config)
42 {
43 }
44 
45 template<typename ArchitectureTag, typename ArchitectureCapability>
46 tdao::Tdao& TdaoTesterTraits<ArchitectureTag,ArchitectureCapability>::api()
47 {
48  return _api;
49 }
50 
51 template<typename ArchitectureTag, typename ArchitectureCapability>
52 tdao::Config& TdaoTesterTraits<ArchitectureTag,ArchitectureCapability>::config()
53 {
54  return _config;
55 }
56 
57 template <typename DeviceType, typename DataType>
59 {
60  inline static void test(DeviceType& device, tdao::Tdao& api, tdao::Config& config)
61  {
62  struct Signal
63  {
64  std::size_t bin;
65  float strength;
66  Signal(std::size_t bin,float strength)
67  :bin(bin),strength(strength){}
68  };
69 
70  config.minimum_frequency(0.0 * data::hz);
71  config.maximum_frequency(5000.0 * data::hz);
72 
73  std::vector<Signal> test_signals;
74  test_signals.push_back(Signal(50,10.0));
75  test_signals.push_back(Signal(123,100.0));
76  test_signals.push_back(Signal(3333,1000.0));
77  DataType input(0.001 * data::hz);
78  input.resize(10000,0.0);
79  auto power_threshold = input.equiv_sigma_to_power(config.significance_threshold());
80 
81  std::size_t expected_candidates = 0;
82  for (auto& signal: test_signals)
83  {
84  input[signal.bin] = signal.strength;
85  if (signal.strength > power_threshold)
86  ++expected_candidates;
87  }
88 
89  data::Ccl output;
90  data::DedispersionMeasureType<float> dm = 0.0f * data::parsecs_per_cube_cm;
91  data::AccelerationType acc = 30.0 * data::metres_per_second_squared;
92  api.process(device,input,output,dm,acc,1);
93 
94  float accel_fact = (acc.value() / (input.frequency_step().value() * boost::units::si::constants::codata::c)).value();
95  ASSERT_EQ(output.size(),expected_candidates);
96 
97  std::size_t cand_idx = 0;
98  for (auto& signal : test_signals)
99  {
100  if (signal.strength > power_threshold)
101  {
102  ASSERT_NEAR(output[cand_idx].period().value()/1000.0, input.bin_to_period(signal.bin).value(), 0.00001);
103  ASSERT_NEAR(output[cand_idx].pdot().value(), input.bin_to_period(signal.bin).value() * accel_fact, 0.00001);
104  ++cand_idx;
105  }
106  }
107  }
108 };
109 
110 template <typename TestTraits>
113 {
114 }
115 
116 template <typename TestTraits>
118 {
119 }
120 
121 template<typename TestTraits>
123 {
124 
125 }
126 
127 template<typename TestTraits>
129 {
130 }
131 
132 ALGORITHM_TYPED_TEST_P(TdaoTester, test_execution)
133 {
134  TypeParam traits;
137 }
138 
139 // each test defined by ALGORITHM_TYPED_TEST_P must be added to the
140 // test register (each one as an element of the comma seperated list)
141 REGISTER_TYPED_TEST_CASE_P(TdaoTester, test_execution);
142 
143 } // namespace test
144 } // namespace tdao
145 } // namespace cheetah
146 } // namespace ska
data::FourierFrequencyType maximum_frequency() const
The maximum frequency to search for candidates at.
Definition: Config.cpp:69
std::size_t size() const
Retrieve the size of the underlying vector.
Definition: VectorLike.cpp:61
float significance_threshold() const
The significance threshold for candidates.
Definition: Config.cpp:49
void process(panda::PoolResource< Arch > &resource, data::PowerSeries< Arch, T, Alloc > const &input, data::Ccl &output, data::DedispersionMeasureType< float >const &dm, data::AccelerationType const &acc, std::size_t nharmonics, Args &&... args)
Find significant peaks in a power series.
Definition: Tdao.cpp:34
data::FourierFrequencyType minimum_frequency() const
The minumum frequency to search for candidates at.
Definition: Config.cpp:59
Some limits and constants for FLDO.
Definition: Brdz.h:35
Candidate list.
Definition: Ccl.h:45
Time Domain Spectral Peak Detection and Candidate List Output.
Definition: Tdao.h:53