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" 52 void SpsTest::TearDown()
57 typedef sps::CommonTypes<sps::Config, uint8_t> TestSpsTraits;
60 TEST_F(SpsTest, test_instantiation)
63 Sps<TestSpsTraits> testsps(config);
66 TEST_F(SpsTest, test_candidate_bounds)
68 panda::PoolResource<cheetah::Cpu> cpu(0);
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);
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;
82 typedef typename SpsType::TimeFrequencyType TimeFrequencyType;
84 utils::ModifiedJulianClock::time_point start_time(utils::ModifiedJulianClock::duration(6000));
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));
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));
96 for (data::DimensionIndex<data::Time> offset(0); offset < data->number_of_spectra() - 1; ++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());
102 buffer.offset_first_block(offset * data->number_of_channels());
103 typedef data::DmTrials<Cpu,float> DmTrialType;
104 typedef data::SpCcl<NumericalRep> SpType;
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);
112 ASSERT_NE(sp_data_returned.get(),
nullptr);
115 ASSERT_EQ(sp_data_returned->start_time(), start_time + offset_time);
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());
122 ASSERT_EQ(sp_data_returned->size(), 10);
125 for (
auto const& cand : *sp_data_returned)
129 ASSERT_GE(sp_data_returned->start_time(cand), start_time + offset_time);
130 ASSERT_GE(sp_data_returned->start_time(cand), start_time);
133 ASSERT_GE(data->start_time() + block_end, sp_data_returned->start_time(cand));
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();
144 template<
typename NumericalT>
146 ,typename sps::emulator::Sps<sps::CommonTypes<sps::Config, NumericalT>>::Architecture>
150 typedef typename BaseT::Arch Arch;
152 BaseT::configure(config);
153 auto& emulator_config = config.emulator_config();
156 emulator_config.candidate_rate(10);
171 typedef ::testing::Types<sps::emulator::test::EmulatorTraits<uint8_t>> EmulatorTraitsTypes;
172 INSTANTIATE_TYPED_TEST_CASE_P(Emulator, SpsTester, EmulatorTraitsTypes);
all non-templated options for the sps module
void activate()
activate the algorithm
Produces a stream of random SpCandidate's.
bool dm_handler_called() const
return true if the dm_handler has been called
Some limits and constants for FLDO.