astrotypes  0.0
TimeFrequency.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
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 #ifndef PSS_ASTROTYPES_TYPES_TIMEFREQUENCY_H
25 #define PSS_ASTROTYPES_TYPES_TIMEFREQUENCY_H
26 
30 #include <memory>
31 
32 namespace pss {
33 namespace astrotypes {
34 
35 template<typename SliceType>
36 class TimeFreqCommon : public SliceType
37 {
38  public:
39  typedef typename SliceType::template OperatorSliceType<units::Frequency>::type Channel;
40  typedef typename SliceType::template ConstOperatorSliceType<units::Frequency>::type ConstChannel;
41  typedef typename SliceType::template OperatorSliceType<units::Time>::type Spectra;
42  typedef typename SliceType::template ConstOperatorSliceType<units::Time>::type ConstSpectra;
43 
44  using SliceType::SliceType;
45 
46  public:
49  TimeFreqCommon(SliceType const& t);
51 
53  // @detials the type returned is a MultiArray @class Slice with all
54  // the features of that available;
55  // @example
56  // @code
57  // // create a TimeFrequency block
58  // TimeFrequency<uint16_t> tf(DimensionSize<Time>(100), DimensionSize<Frequency>(4096));
59  //
60  // // get the first channel
61  // typename TimeFrequency<uint16_t>::Channel chanel = tf.channel(0);
62  //
63  // // use the Chanel's iterator interface tp generate an increasing sequence
64  // //
65  // uint16_t n = 0;
66  // std::generate(channel.begin(), channel.end(), [&]() { return ++n; });
67  // @endcode
68  //
69  Channel channel(std::size_t channel_number);
70  ConstChannel channel(std::size_t channel_number) const;
71 
73  // @detials the type returned is a MultiArray @class Slice with all
74  // the features of that available;
75  // @example
76  // @code
77  // // create a TimeFrequency block
78  // TimeFrequency<uint16_t> tf(DimensionSize<Time>(100), DimensionSize<Frequency>(4096));
79  //
80  // // get the first spectrum
81  // typename TimeFrequency<uint16_t>::Spectra spectrum = tf.spectrum(0);
82  //
83  // // use the Spectra's iterator interface tp generate an increasing sequence
84  // std::fill(spectrum.begin(), spectra.end(), 100U);
85  //
86  // // use the [] interface to access a particular element
87  // spectrum[DimensionIndex<Frequency>(7)] += 1; // modify the 8th channel value in thie specturm
88  //
89  // @endcode
90  //
91  Spectra spectrum(std::size_t offset);
92  ConstSpectra spectrum(std::size_t offset) const;
93 
95  // @details a synonym for dimension<Frequency>()
96  std::size_t number_of_channels() const;
97 
99  // @details a synonym for dimension<Time>()
100  std::size_t number_of_spectra() const;
101 };
102 
112 template<typename T, typename Alloc=std::allocator<T>>
113 class TimeFrequency : public TimeFreqCommon<MultiArray<Alloc, T, TimeFreqCommon, units::Time, units::Frequency>>
114 {
115  private:
117 
118  public:
119  typedef typename BaseT::Channel Channel;
121  typedef typename BaseT::Spectra Spectra;
123 
124  public:
125  TimeFrequency();
128 
133  template<typename FrequencyTimeType, typename Enable=typename std::enable_if<
135  TimeFrequency(FrequencyTimeType const&);
136 
137  ~TimeFrequency();
138 };
139 
150 template<typename T, typename Alloc=std::allocator<T>>
151 class FrequencyTime : public TimeFreqCommon<MultiArray<Alloc, T, TimeFreqCommon, units::Frequency, units::Time>>
152 {
153  private:
155 
156  public:
157  typedef typename BaseT::Channel Channel;
159  typedef typename BaseT::Spectra Spectra;
161 
162  public:
163  FrequencyTime();
166 
171  template<typename TimeFrequencyType, typename Enable=typename std::enable_if<
173  FrequencyTime(TimeFrequencyType const&);
174 
175  ~FrequencyTime();
176 };
177 
178 template<typename Alloc, typename T>
179 struct has_exact_dimensions<TimeFrequency<T, Alloc>, units::Time, units::Frequency> : public std::true_type
180 {
181 };
182 
183 template<typename Alloc, typename T>
184 struct has_exact_dimensions<FrequencyTime<T, Alloc>, units::Frequency, units::Time> : public std::true_type
185 {
186 };
187 
188 template<typename Alloc, typename T>
189 struct has_dimension<TimeFrequency<T, Alloc>, units::Time> : public std::true_type
190 {
191 };
192 
193 template<typename Alloc, typename T>
194 struct has_dimension<TimeFrequency<T, Alloc>, units::Frequency> : public std::true_type
195 {
196 };
197 
198 template<typename Alloc, typename T>
199 struct has_dimension<FrequencyTime<T, Alloc>, units::Time> : public std::true_type
200 {
201 };
202 
203 template<typename Alloc, typename T>
204 struct has_dimension<FrequencyTime<T, Alloc>, units::Frequency> : public std::true_type
205 {
206 };
207 
208 } // namespace astrotypes
209 } // namespace pss
210 #include "detail/TimeFrequency.cpp"
211 
212 #endif // PSS_ASTROTYPES_TYPES_TIMEFREQUENCY_H
boost::units::time_dimension Time
Definition: Time.h:42
BaseT::ConstChannel ConstChannel
SliceType::template ConstOperatorSliceType< units::Frequency >::type ConstChannel
Definition: TimeFrequency.h:40
std::size_t number_of_channels() const
return the number of channels in the data structure
BaseT::ConstChannel ConstChannel
BaseT::ConstSpectra ConstSpectra
return true if the Dimensions provided match exactly those of the structure T (including order) ...
Definition: TypeTraits.h:107
BaseT::ConstSpectra ConstSpectra
std::size_t number_of_spectra() const
return the number of spectra in the data structure
A template class representing values associated with a time and frequecny such as Stokes values or vo...
A template class representing values associated with a time and frequecny such as Stokes values or vo...
SliceType::template ConstOperatorSliceType< units::Time >::type ConstSpectra
Definition: TimeFrequency.h:42
Channel channel(std::size_t channel_number)
retrun a single channel across all time samples
SliceType::template OperatorSliceType< units::Frequency >::type Channel
Definition: TimeFrequency.h:39
return true if the Dimension is represented in the structure
Definition: TypeTraits.h:71
SliceType::template OperatorSliceType< units::Time >::type Spectra
Definition: TimeFrequency.h:41
Spectra spectrum(std::size_t offset)
return a single spectrum from the specified offset
boost::units::frequency_dimension Frequency
Definition: Frequency.h:45