Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DedispersionTrialPlan.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/DedispersionTrialPlan.h"
25 
26 
27 namespace ska {
28 namespace cheetah {
29 namespace ddtr {
30 
31 static std::string const& dedispersion_tag()
32 {
33  static std::string var("dedispersion");
34  return var;
35 }
36 
37 DedispersionTrialPlan::DedispersionTrialPlan(std::string const& tag_name)
38  : BaseT(tag_name)
39  , _dm_constant(data::dm_constant::s_mhz::dm_constant)
40  , _max_dm(0.0 * data::parsecs_per_cube_cm)
41 {
42  add_factory(dedispersion_tag(), []()
43  {
44  return new ddtr::DedispersionConfig();
45  });
46 }
47 
48 DedispersionTrialPlan::~DedispersionTrialPlan()
49 {
50 }
51 
52 void DedispersionTrialPlan::add_options(OptionsDescriptionEasyInit& add_options)
53 {
54  add_options
55  ("dm_constant", boost::program_options::value<double>()->default_value(_dm_constant.value())->notifier([this](double v) { _dm_constant = v * data::dm_constant::s_mhz_squared_cm_cubed_per_pc; }), "the dedispersion constant to use (in MHz^2 sec cm^3 per parsec");
56 }
57 
58 std::vector<DedispersionTrialPlan::Dm> const& DedispersionTrialPlan::dm_trials() const
59 {
60  if(_dm_trials.empty()) {
61  auto it = subsection(dedispersion_tag());
62  while (it != subsection_end())
63  {
64  ddtr::DedispersionConfig const& c = static_cast<ddtr::DedispersionConfig const&>(*it);
65  for (Dm dm = c.dm_start(); dm <= c.dm_end(); dm += c.dm_step())
66  {
67  if(dm > _max_dm) _max_dm = dm;
68  _dm_trials.push_back(dm);
69  }
70  ++it;
71  }
72  }
73  return _dm_trials;
74 }
75 
76 void DedispersionTrialPlan::add_dm_range(Dm start, Dm end, Dm step)
77 {
78  DedispersionConfig& dm_config = static_cast<DedispersionConfig&>(*generate_section(dedispersion_tag()));
79  dm_config.dm_start(start);
80  dm_config.dm_end(end);
81  dm_config.dm_step(step);
82  _dm_trials.clear();
83 }
84 
86 {
87  add(dedispersion_tag(), config);
88  _dm_trials.clear();
89 }
90 
91 std::shared_ptr<data::DmTrialsMetadata> DedispersionTrialPlan::generate_dmtrials_metadata(TimeType sample_interval, std::size_t nspectra, std::size_t overlap) const
92 {
93  if (nspectra < overlap) {
94  panda::Error e("Overlap exceeds number of spectra: ");
95  e << overlap << " > " << nspectra;
96  throw e;
97  }
98  std::shared_ptr<data::DmTrialsMetadata> meta_data(new data::DmTrialsMetadata(sample_interval, nspectra - overlap));
99  for (auto dm : dm_trials())
100  {
101  meta_data->emplace_back(dm, 1);
102  }
103  return meta_data;
104 }
105 
106 DedispersionTrialPlan::DmConstantType DedispersionTrialPlan::dm_constant() const
107 {
108  return _dm_constant;
109 }
110 
111 DedispersionTrialPlan::Dm DedispersionTrialPlan::max_dm() const
112 {
113  dm_trials();
114  return _max_dm;
115 }
116 
117 void DedispersionTrialPlan::dm_constant(DedispersionTrialPlan::DmConstantType dm_const)
118 {
119  _dm_constant = dm_const;
120 }
121 
122 typename DedispersionTrialPlan::TimeType DedispersionTrialPlan::maximum_delay(FrequencyType freq_low, FrequencyType freq_high) const
123 {
124  dm_trials();
125  return TimeType((this->dm_constant().value() * (1.0/(freq_low*freq_low) - 1.0/(freq_high*freq_high)) * _max_dm).value() * boost::units::si::second);
126 }
127 
128 DedispersionTrialPlan::RangeIterator DedispersionTrialPlan::begin_range() const
129 {
130  return this->subsection(dedispersion_tag());
131 }
132 
133 DedispersionTrialPlan::RangeIterator DedispersionTrialPlan::end_range() const
134 {
135  return this->subsection_end();
136 }
137 
138 } // namespace ddtr
139 } // namespace cheetah
140 } // namespace ska
std::shared_ptr< data::DmTrialsMetadata > generate_dmtrials_metadata(TimeType sample_interval, std::size_t nspectra, std::size_t nsamples) const
Generate metadata based on dedispersion plan.
Dm dm_start() const
the first dm condidate to try
void dedispersion_config(DedispersionConfig &config)
add a Dedispersion Configuration Element
std::vector< Dm > const & dm_trials() const
list of DM trials
describes dedispersion configuration
void add_dm_range(Dm start, Dm end, Dm step)
get range of DM values
Some limits and constants for FLDO.
Definition: Brdz.h:35
Dm dm_end() const
the last dm condidate to try
Container for metadata that describes a set of dispersion measure trials.
DmConstantType dm_constant() const
get DM constant
TimeType maximum_delay(FrequencyType freq_low, FrequencyType freq_high) const
the maximum delay time for a signal at the maximum Dm in the plan
Dm max_dm() const
the largest Dm value specified
Dm dm_step() const
the step size to take in generating dm trials between start and end