Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
TimeFrequencyMetadata.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/data/TimeFrequencyMetadata.h"
25 
26 namespace ska {
27 namespace cheetah {
28 namespace data {
29 
30 
31 TimeFrequencyMetadata::TimeFrequencyMetadata()
32 {
33 }
34 
35 TimeFrequencyMetadata::TimeFrequencyMetadata(TimeFrequencyMetadata const& metadata)
36  : _frequency_index(metadata.channel_frequencies())
37  , _sample_interval(metadata.sample_interval())
38  , _start_time(metadata.start_time())
39 {
40 }
41 
42 TimeFrequencyMetadata& TimeFrequencyMetadata::operator=(TimeFrequencyMetadata const& copy)
43 {
44  _frequency_index = copy.channel_frequencies();
45  _sample_interval = copy.sample_interval();
46  _start_time = copy.start_time();
47  return *this;
48 }
49 
50 TimeFrequencyMetadata::TimeIntervalType const& TimeFrequencyMetadata::sample_interval() const
51 {
52  return _sample_interval;
53 }
54 
55 void TimeFrequencyMetadata::sample_interval(TimeFrequencyMetadata::TimeIntervalType dt)
56 {
57  this->_sample_interval = dt;
58 }
59 
60 std::vector<typename TimeFrequencyMetadata::FrequencyType> const& TimeFrequencyMetadata::channel_frequencies() const
61 {
62  return this->_frequency_index;
63 }
64 
65 std::pair<FrequencyType, FrequencyType> TimeFrequencyMetadata::low_high_frequencies() const
66 {
67  if(_frequency_index.empty())
68  return std::pair<FrequencyType, FrequencyType>(FrequencyType(0.0 * hz) , FrequencyType(0.0 * hz) );
69  if(this->_frequency_index[0] > this->_frequency_index.back()) {
70  return std::make_pair(_frequency_index.back(), _frequency_index.front());
71  } else {
72  return std::make_pair(_frequency_index[0], _frequency_index.back());
73  }
74 }
75 
76 void TimeFrequencyMetadata::channel_frequencies_const_width(TimeFrequencyMetadata::FrequencyType const& start
77  , TimeFrequencyMetadata::FrequencyType const& delta
78  , pss::astrotypes::DimensionSize<Frequency> number_of_channels)
79 {
80  _frequency_index.resize(number_of_channels);
81  for(unsigned i=0U; i < number_of_channels; ++i) {
82  _frequency_index[i]= start + delta * (double)i;
83  }
84 }
85 
86 typename TimeFrequencyMetadata::TimePointType const& TimeFrequencyMetadata::start_time() const
87 {
88  return this->_start_time;
89 }
90 
91 typename TimeFrequencyMetadata::TimePointType TimeFrequencyMetadata::start_time(std::size_t offset) const
92 {
93  return this->_start_time + std::chrono::duration<double>(sample_interval().value() * offset);
94 }
95 
97 {
98  this->_start_time = start_time;
99 }
100 
101 } // namespace data
102 } // namespace cheetah
103 } // namespace ska
std::vector< FrequencyType > const & channel_frequencies() const
std::pair< FrequencyType, FrequencyType > low_high_frequencies() const
TimeIntervalType const & sample_interval() const
Some limits and constants for FLDO.
Definition: Brdz.h:35
void channel_frequencies_const_width(FrequencyType const &start, FrequencyType const &delta, pss::astrotypes::DimensionSize< Frequency >)
Set the frequency index based on evenly spaced channels.