Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DispersedPulse.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/generators/DispersedPulse.h"
25 #include <limits>
26 #include <algorithm>
27 #include <cmath>
28 
29 namespace ska {
30 namespace cheetah {
31 namespace generators {
32 
33 
34 template<typename NumericalRep>
35 DispersedPulse<NumericalRep>::DispersedPulse()
36  : BaseT()
37  , _dm_constant(4.1493775933609e3) // s_mhz_squared_cm_cubed_per_pc
38  , _dm_measure(500.0 * pss::astrotypes::units::parsecs_per_cube_cm)
39  , _pulse_width(3.0 * boost::units::si::milli * boost::units::si::seconds)
40  , _delta(1)
41 {
42 }
43 
44 template<typename NumericalRep>
45 DispersedPulse<NumericalRep>::DispersedPulse(DispersedPulseConfig const& config)
46  : BaseT()
47  , _dm_constant(4.1493775933609e3) // s_mhz_squared_cm_cubed_per_pc
48  , _dm_measure(config.dispersion_measure())
49  , _pulse_width(config.pulse_width())
50  , _delta(std::max(config.delta(), (double)std::numeric_limits<NumericalRep>::max()))
51 {
52 }
53 
54 template<typename NumericalRep>
55 DispersedPulse<NumericalRep>::~DispersedPulse()
56 {
57 }
58 
59 template<typename NumericalRep>
60 void DispersedPulse<NumericalRep>::next(DataType& data)
61 {
62  std::size_t bin_width = _pulse_width/data.sample_interval();
63  std::vector<data::FrequencyType> const& channel_freqs = data.channel_frequencies();
64  typename data::FrequencyType freq_top = *std::max_element(channel_freqs.begin(), channel_freqs.end());
65  std::vector<float> delays;
66  for (auto const& freq: channel_freqs)
67  {
68  delays.push_back(_dm_constant * _dm_measure.value()
69  * (1.0/(freq.value()*freq.value()) - 1.0/(freq_top.value()*freq_top.value())) / data.sample_interval().value());
70  }
71 
72  std::size_t const number_of_channels = data.template dimension<data::Frequency>();
73  for(std::size_t ii=0; ii < number_of_channels; ++ii)
74  {
75  typename DataType::Channel ts = data.channel(ii);
76  std::size_t delay = std::size_t(std::round(delays[ii]));
77 
78  // add signal to each appropraite bin
79  for(std::size_t offset=0; offset < bin_width; ++offset) {
80  //auto index = delay + offset;
81  pss::astrotypes::DimensionIndex<pss::astrotypes::units::Time> const index(delay + offset);
82  if( index >= ts.template size<data::Time>() ) continue;
83  // avoid wrap-around when we add the delta
84  if(std::numeric_limits<NumericalRep>::max() - ts[index] <= _delta)
85  {
86  ts[index] = std::numeric_limits<NumericalRep>::max();
87  }
88  else {
89  ts[index] += _delta;
90  }
91  }
92  }
93 }
94 
95 } // namespace generators
96 } // namespace cheetah
97 } // namespace ska
Definition: Units.h:112
Some limits and constants for FLDO.
Definition: Brdz.h:35