Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
FlagPolicyTest.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/rfim/policy/test/FlagPolicyTest.h"
25 #include "cheetah/rfim/policy/FlagPolicy.h"
26 #include "panda/CharAsInt.h"
27 #include <numeric>
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace rfim {
33 namespace test {
34 
35 
36 FlagPolicyTest::FlagPolicyTest()
37  : ::testing::Test()
38 {
39 }
40 
41 FlagPolicyTest::~FlagPolicyTest()
42 {
43 }
44 
45 void FlagPolicyTest::SetUp()
46 {
47 }
48 
49 void FlagPolicyTest::TearDown()
50 {
51 }
52 
53 TEST_F(FlagPolicyTest, test_no_marks)
54 {
55  // Use case: contructed and data extracted, but no bad marks are made
56  typedef data::TimeFrequency<Cpu, uint8_t> TimeFrequencyType;
57  typedef FlagPolicy<TimeFrequencyType> FlagPolicyType;
58 
59  data::DimensionSize<data::Frequency> number_of_channels(10);
60  data::DimensionSize<data::Time> number_of_spectra(5);
61  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
62 
63  const FlagPolicyType policy;
64  auto adapter = policy.adapter(*tf);
65  std::shared_ptr<data::RfimFlaggedData<TimeFrequencyType>> data=adapter.data();
66  TimeFrequencyType& output_data = static_cast<TimeFrequencyType&>(*data);
67  ASSERT_EQ(&output_data, tf.get()); // make sure we get the same data out we put in
68 
69  // check all is marked good
70  for(auto const sample : data->rfi_flags())
71  {
72  ASSERT_EQ(false, (bool)sample);
73  }
74 }
75 
76 TEST_F(FlagPolicyTest, test_const_tf_data)
77 {
78  // Use case: adapter contructed with a const TF data block
79  typedef const data::TimeFrequency<Cpu, uint8_t> TimeFrequencyType;
80  typedef FlagPolicy<TimeFrequencyType> FlagPolicyType;
81 
82  data::DimensionSize<data::Frequency> number_of_channels(10);
83  data::DimensionSize<data::Time> number_of_spectra(5);
84  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
85 
86  const FlagPolicyType policy;
87  auto adapter = policy.adapter(*tf);
88  std::shared_ptr<data::RfimFlaggedData<TimeFrequencyType>> data=adapter.data();
89  TimeFrequencyType const& output_data = static_cast<TimeFrequencyType const&>(*data);
90  ASSERT_EQ(&output_data, tf.get()); // make sure we get the same data out we put in
91 }
92 
93 TEST_F(FlagPolicyTest, test_mark_bad_channels)
94 {
95  typedef uint8_t NumericalType;
96  typedef const data::TimeFrequency<Cpu, NumericalType> TimeFrequencyType;
97  typedef FlagPolicy<TimeFrequencyType> FlagPolicyType;
98 
99  data::DimensionSize<data::Frequency> number_of_channels(10);
100  data::DimensionSize<data::Time> number_of_spectra(5);
101  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
102  TimeFrequencyType tf_copy = *tf;
103 
104  const FlagPolicyType policy;
105  auto adapter = policy.adapter(*tf);
106 
107  // Usw cases - bad channels
108  for(std::size_t channel_number=0; channel_number < tf->dimension<data::Frequency>(); ++channel_number) {
109  adapter.mark_bad(tf->channel(channel_number));
110  }
111 
112  // verify the contents of the data has not been changed
113  auto tf_copy_it=tf_copy.begin();
114  for(auto const& s : *tf) {
115  ASSERT_EQ(static_cast<typename panda::CharAsInt<NumericalType>::type>(*tf_copy_it), static_cast<typename panda::CharAsInt<NumericalType>::type>(s));
116  ++tf_copy_it;
117  }
118 }
119 
120 TEST_F(FlagPolicyTest, test_mark_bad_spectra)
121 {
122  typedef uint8_t NumericalType;
123  typedef data::TimeFrequency<Cpu, NumericalType> TimeFrequencyType;
124  typedef FlagPolicy<TimeFrequencyType> FlagPolicyType;
125 
126  data::DimensionSize<data::Frequency> number_of_channels(10);
127  data::DimensionSize<data::Time> number_of_spectra(5);
128  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
129  std::iota(tf->begin(), tf->end(), 0);
130 
131  const FlagPolicyType policy;
132  auto adapter = policy.adapter(*tf);
133 
134  // Usw cases - bad channels
135  for(std::size_t spectrum_number=0; spectrum_number < tf->dimension<data::Time>(); ++spectrum_number) {
136  adapter.mark_bad(tf->spectrum(spectrum_number));
137  }
138 
139  // verify the contents of the data has not been changed
140  typename panda::CharAsInt<NumericalType>::type i=0;
141  for(auto const& s : *tf) {
142  ASSERT_EQ(i, static_cast<typename panda::CharAsInt<NumericalType>::type>(s));
143  ++i;
144  }
145 }
146 
147 TEST_F(FlagPolicyTest, test_mark_only_bad_channels)
148 {
149  typedef uint8_t NumericalType;
150  typedef data::TimeFrequency<Cpu, NumericalType> TimeFrequencyType;
151  typedef FlagPolicy<TimeFrequencyType> PolicyType;
152 
153  data::DimensionSize<data::Frequency> number_of_channels(10);
154  data::DimensionSize<data::Time> number_of_spectra(5);
155  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
156  std::iota(tf->begin(), tf->end(), 0);
157 
158  PolicyType policy;
159  auto adapter = policy.adapter(*tf);
160  for(data::DimensionIndex<data::Frequency> channel_number(0); channel_number < tf->dimension<data::Frequency>(); ++channel_number) {
161  adapter.mark_bad(tf->channel(channel_number));
162  }
163 
164  // verify the contents of the data has not been changed
165  typename panda::CharAsInt<NumericalType>::type i=0;
166  for(auto const& s : *tf) {
167  ASSERT_EQ(i, static_cast<typename panda::CharAsInt<NumericalType>::type>(s));
168  ++i;
169  }
170 
171  std::shared_ptr<data::RfimFlaggedData<TimeFrequencyType>> data=adapter.data();
172  for(auto const& flag : data->rfi_flags()) {
173  ASSERT_TRUE(flag);
174  }
175 }
176 
177 } // namespace test
178 } // namespace rfim
179 } // namespace cheetah
180 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35