Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
LastUnflaggedTest.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/LastUnflaggedTest.h"
25 #include "cheetah/rfim/policy/LastUnflagged.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 LastUnflaggedTest::LastUnflaggedTest()
37  : ::testing::Test()
38 {
39 }
40 
41 LastUnflaggedTest::~LastUnflaggedTest()
42 {
43 }
44 
45 void LastUnflaggedTest::SetUp()
46 {
47 }
48 
49 void LastUnflaggedTest::TearDown()
50 {
51 }
52 
53 TEST_F(LastUnflaggedTest, test_no_marks)
54 {
55  typedef data::TimeFrequency<Cpu, uint8_t> TimeFrequencyType;
56  typedef LastUnflagged<TimeFrequencyType> PolicyType;
57 
58  data::DimensionSize<data::Frequency> number_of_channels(10);
59  data::DimensionSize<data::Time> number_of_spectra(5);
60  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
61  std::iota(tf->begin(), tf->end(), 0);
62 
63  {
64  PolicyType policy;
65  auto adapter = policy.adapter(*tf);
66  }
67 
68  // verify the contents of the data has not changed
69  std::size_t count=0;
70  for(auto const& s : *tf) {
71  ASSERT_EQ(count, s);
72  ++count;
73  }
74 }
75 
76 TEST_F(LastUnflaggedTest, test_mark_only_bad_spectra)
77 {
78  typedef uint8_t NumericalType;
79  typedef data::TimeFrequency<Cpu, NumericalType> TimeFrequencyType;
80  typedef LastUnflagged<TimeFrequencyType> PolicyType;
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  std::iota(tf->begin(), tf->end(), 0);
86 
87  PolicyType policy;
88  auto adapter = policy.adapter(*tf);
89  for(data::DimensionIndex<data::Time> spectrum_number(0); spectrum_number < tf->dimension<data::Time>(); ++spectrum_number) {
90  adapter.mark_bad(tf->spectrum(spectrum_number));
91  }
92 
93  // verify the contents of the data has been set to zero
94  for(auto const& s : *tf) {
95  ASSERT_EQ(0, static_cast<typename panda::CharAsInt<NumericalType>::type>(s));
96  }
97 }
98 
99 TEST_F(LastUnflaggedTest, test_mark_only_bad_channels)
100 {
101  typedef uint8_t NumericalType;
102  typedef data::TimeFrequency<Cpu, NumericalType> TimeFrequencyType;
103  typedef LastUnflagged<TimeFrequencyType> PolicyType;
104 
105  data::DimensionSize<data::Frequency> number_of_channels(10);
106  data::DimensionSize<data::Time> number_of_spectra(5);
107  std::shared_ptr<TimeFrequencyType> tf = std::make_shared<TimeFrequencyType>(number_of_channels, number_of_spectra);
108  std::iota(tf->begin(), tf->end(), 0);
109 
110  PolicyType policy;
111  auto adapter = policy.adapter(*tf);
112  for(data::DimensionIndex<data::Frequency> channel_number(0); channel_number < tf->dimension<data::Frequency>(); ++channel_number) {
113  adapter.mark_bad(tf->channel(channel_number));
114  }
115 
116  // verify the contents of the data has been set to zero
117  for(auto const& s : *tf) {
118  ASSERT_EQ(0, static_cast<typename panda::CharAsInt<NumericalType>::type>(s));
119  }
120 }
121 
122 } // namespace test
123 } // namespace rfim
124 } // namespace cheetah
125 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35