Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DedispersionPlan.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/ddtr/cpu/DedispersionPlan.h"
25 
26 namespace ska {
27 namespace cheetah {
28 namespace ddtr {
29 namespace cpu {
30 
31 template <typename DdtrTraits>
33  : _algo_config(config)
34  , _memory(memory)
35 {
36 }
37 
38 template <typename DdtrTraits>
40 {
41 }
42 
43 template <typename DdtrTraits>
44 data::DimensionSize<data::Time> DedispersionPlan<DdtrTraits>::reset(TimeFrequencyType const& data)
45 {
46  Dm max_dm = this->_algo_config.max_dm();
47 
48  FrequencyListType const& channel_freqs = data.channel_frequencies();
49  auto freq_pair = data.low_high_frequencies();
50  FrequencyType freq_top = freq_pair.second;
51  FrequencyType freq_bottom = freq_pair.first;
52  _max_delay = std::size_t((this->_algo_config.dm_constant().value()
53  * (1.0/(freq_bottom*freq_bottom) - 1.0/(freq_top*freq_top))
54  * max_dm / data.sample_interval()).value()) + 1;
55  for (auto freq: channel_freqs)
56  {
57  double factor = (this->_algo_config.dm_constant().value() * (1.0/(freq*freq) - 1.0/(freq_top*freq_top)) / data.sample_interval()).value();
58  PANDA_LOG_DEBUG << "Frequency: " << freq << " Reference: " << freq_top << " DM constant: "
59  << this->_algo_config.dm_constant() << " Sampling interval: " << data.sample_interval() << " DM factor: " << factor;
60  _dm_factors.push_back(factor);
61  }
62 
63  _number_of_spectra = std::min(_memory/data.number_of_channels(), this->_algo_config.dedispersion_samples());
64  if (_number_of_spectra < _max_delay * 2)
65  {
66  PANDA_LOG_WARN << "Requested number of samples to dedisperse ("
67  << this->_number_of_spectra
68  << ") is less than twice the max dispersion delay ("
69  << 2 * _max_delay << ")";
70  }
71  _dm_trial_metadata = this->_algo_config.generate_dmtrials_metadata(data.sample_interval(), _number_of_spectra, _max_delay);
72  return data::DimensionSize<data::Time>(_number_of_spectra);
73 }
74 
75 template <typename DdtrTraits>
76 std::vector<typename DedispersionPlan<DdtrTraits>::Dm> const& DedispersionPlan<DdtrTraits>::dm_trials() const
77 {
78  return _algo_config.dm_trials();
79 }
80 
81 template <typename DdtrTraits>
82 std::vector<double> const& DedispersionPlan<DdtrTraits>::dm_factors() const
83 {
84  return _dm_factors;
85 }
86 
87 template <typename DdtrTraits>
88 data::DimensionSize<data::Time> DedispersionPlan<DdtrTraits>::buffer_overlap() const
89 {
90  return data::DimensionSize<data::Time>(_max_delay);
91 }
92 
93 template <typename DdtrTraits>
94 void DedispersionPlan<DdtrTraits>::reset(data::DimensionSize<data::Time> const& spectra)
95 {
96  _number_of_spectra = spectra;
97 }
98 
99 template <typename DdtrTraits>
100 data::DimensionSize<data::Time> DedispersionPlan<DdtrTraits>::number_of_spectra() const
101 {
102  return data::DimensionSize<data::Time>(_number_of_spectra);
103 }
104 
105 template <typename DdtrTraits>
106 std::shared_ptr<data::DmTrialsMetadata> DedispersionPlan<DdtrTraits>::generate_dmtrials_metadata(typename DedispersionPlan<DdtrTraits>::TimeType sample_interval, data::DimensionSize<data::Time> nspectra, std::size_t nsamples) const
107 {
108  return _algo_config.generate_dmtrials_metadata(sample_interval, nspectra, nsamples);
109 }
110 
111 template <typename DdtrTraits>
112 std::shared_ptr<data::DmTrialsMetadata> DedispersionPlan<DdtrTraits>::dm_trials_metadata(data::TimeFrequencyMetadata const& tf_info, data::DimensionSize<data::Time> number_of_spectra)
113 {
114  if (number_of_spectra != _number_of_spectra) {
115  _dm_trial_metadata = this->generate_dmtrials_metadata(tf_info.sample_interval(), number_of_spectra, _max_delay);
116  _number_of_spectra = number_of_spectra;
117  }
118  return _dm_trial_metadata;
119 }
120 
121 } // namespace cpu
122 } // namespace ddtr
123 } // namespace cheetah
124 } // namespace ska
std::vector< Dm > const & dm_trials() const
return algo specific dm_trials
data::DimensionSize< data::Time > reset(TimeFrequencyType const &)
reset the plan to be compatible with the TimeFrequency metadata
std::size_t dedispersion_samples() const
number of samples to dedisperse
Definition: Config.cpp:81
data::DimensionSize< data::Time > buffer_overlap() const
return the number of spectra in the overlap buffer
std::vector< double > const & dm_factors() const
return algo specific dm_factors
TimeIntervalType const & sample_interval() const
Some limits and constants for FLDO.
Definition: Brdz.h:35
DedispersionPlan(ConfigType const &config, std::size_t max_data_elements)
data::DimensionSize< data::Time > number_of_spectra() const
return the number of spectra currently configured
std::shared_ptr< data::DmTrialsMetadata > dm_trials_metadata(data::TimeFrequencyMetadata const &tf_info, data::DimensionSize< data::Time > number_of_spectra)
return a DmTrialsMetadata block consistent with the plan and the incoming data parameters ...
Metadata for TimeFrequency and FrequencyTime classes.