Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
RfiDetectionPipelineTest.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/pipeline/test/RfiDetectionPipelineTest.h"
25 #include "cheetah/pipeline/RfiDetectionPipeline.h"
26 #include "cheetah/generators/GaussianNoise.h"
27 #include "cheetah/generators/GaussianNoiseConfig.h"
28 #include <mutex>
29 #include <condition_variable>
30 
31 
32 namespace ska {
33 namespace cheetah {
34 namespace pipeline {
35 namespace test {
36 
37 
38 RfiDetectionPipelineTest::RfiDetectionPipelineTest()
39  : ::testing::Test()
40 {
41 }
42 
43 RfiDetectionPipelineTest::~RfiDetectionPipelineTest()
44 {
45 }
46 
47 void RfiDetectionPipelineTest::SetUp()
48 {
49 }
50 
51 void RfiDetectionPipelineTest::TearDown()
52 {
53 }
54 
55 template<typename NumericalT>
56 struct RfiTests
57 {
59  typedef typename TimeFrequencyType::TimePointType TimePointType;
60  typedef typename TimeFrequencyType::DataType DataType;
61 
64  : _count(0) {}
65 
66  template<typename TimeFrequencyT>
67  void operator()(std::shared_ptr<TimeFrequencyT>& data) {
68  this->operator()(*data);
69  }
70 
71  template<typename TimeFrequencyT>
72  void operator()(TimeFrequencyT& data) {
73  ASSERT_LT(_start_time, data.start_time());
74  _start_time = data.start_time();
75  std::lock_guard<std::mutex> lk(_mutex);
76  ++_count;
77  _cv.notify_all();
78  PANDA_LOG_DEBUG << "test handler called: count=" << _count;
79  }
80 
81  void wait(std::size_t count) {
82  std::unique_lock<std::mutex> lk(_mutex);
83  _cv.wait(lk, [this, count]() { return _count == count; });
84  }
85 
86  private:
87  TimePointType _start_time;
88  std::mutex _mutex;
89  std::condition_variable _cv;
90  std::size_t _count;
91  };
92 
93  static void run()
94  {
95 
97  auto f_low = data::TimeFrequency<Cpu, uint8_t>::FrequencyType(1.2 * boost::units::si::giga * boost::units::si::hertz);
98  auto f_high = data::TimeFrequency<Cpu, uint8_t>::FrequencyType(1.8 * boost::units::si::giga * boost::units::si::hertz);
99  typename data::TimeFrequency<Cpu, NumericalT>::TimeType t_samp(64.0 * boost::units::si::micro * data::seconds);
100  data::DimensionSize<data::Time> number_of_samples(1<<15);
101  data::DimensionSize<data::Frequency> number_of_channels(1024);
102  typename utils::ModifiedJulianClock::time_point epoch(utils::julian_day(50000.0));
103  auto delta = (f_low - f_high)/ (double)number_of_channels;
104 
105  //Set up noise parameters for data to be passed through
106  //the pipeline
107  generators::GaussianNoiseConfig noise_config;
108  noise_config.mean(96.0);
109  noise_config.std_deviation(10.0);
110  generators::GaussianNoise<DataType> noise(noise_config);
111  BeamConfig<uint8_t> beam_config;
112 
113  RfiDetectionPipeline<NumericalT, TestOutputHandler> pipeline(config, beam_config);
114 
115  std::size_t loop_count=4;
116  for (std::size_t ii=0; ii<loop_count; ++ii)
117  {
118  auto tf = std::make_shared<data::TimeFrequency<Cpu, uint8_t>>(number_of_samples, number_of_channels);
119  tf->set_channel_frequencies_const_width( f_high, delta );
120  tf->sample_interval(t_samp);
121  tf->start_time(epoch);
122  epoch += std::chrono::duration<double>(tf->sample_interval().value()*number_of_samples);
123  noise.next(*tf);
124  pipeline(*tf);
125  }
126  pipeline.output_handler().wait(loop_count);
127  }
128 };
129 
130 TEST_F(RfiDetectionPipelineTest, uint8_t_run_test)
131 {
133 }
134 
135 } // namespace test
136 } // namespace pipeline
137 } // namespace cheetah
138 } // namespace ska
RfimOutputHandler & output_handler()
access to the output handler object
Some limits and constants for FLDO.
Definition: Brdz.h:35
NumericalT DataType
the underlying data storage type for the amplitude of the signal
Definition: TimeFrequency.h:96
Parse configuration parameters for a single beam in the pipeline instance of cheetah.
Definition: BeamConfig.h:48
void operator()(TimeFrequencyType &) override
called each time data becomes available
Pipeline that performs only RFI detection.