WSClean
banddata.h
1 #ifndef BANDDATA_H
2 #define BANDDATA_H
3 
4 #include <stdexcept>
5 
6 #include <casacore/ms/MeasurementSets/MeasurementSet.h>
7 
8 #include <casacore/tables/Tables/ArrayColumn.h>
9 #include <casacore/tables/Tables/ScalarColumn.h>
10 
15 class BandData
16 {
17  public:
18  typedef std::reverse_iterator<double*> reverse_iterator;
19  typedef std::reverse_iterator<const double*> const_reverse_iterator;
20 
24  BandData() : _channelCount(0), _channelFrequencies(0), _frequencyStep(0.0)
25  {
26  }
27 
33  BandData(casacore::MSSpectralWindow& spwTable)
34  {
35  if(spwTable.nrow() != 1) throw std::runtime_error("Set should have exactly one spectral window");
36 
37  initFromTable(spwTable, 0);
38  }
39 
45  BandData(casacore::MSSpectralWindow& spwTable, size_t bandIndex)
46  {
47  initFromTable(spwTable, bandIndex);
48  }
49 
54  BandData(const BandData& source) : _channelCount(source._channelCount), _frequencyStep(source._frequencyStep)
55  {
56  _channelFrequencies = new double[_channelCount];
57  for(size_t index = 0; index != _channelCount; ++index)
58  {
59  _channelFrequencies[index] = source._channelFrequencies[index];
60  }
61  }
62 
69  BandData(const BandData &source, size_t startChannel, size_t endChannel) :
70  _channelCount(endChannel - startChannel), _frequencyStep(source._frequencyStep)
71  {
72  if(_channelCount == 0) throw std::runtime_error("No channels in set");
73 
74  _channelFrequencies = new double[_channelCount];
75  for(size_t index = 0; index != _channelCount; ++index)
76  {
77  _channelFrequencies[index] = source._channelFrequencies[index + startChannel];
78  }
79  }
80 
86  BandData(size_t channelCount, const double* frequencies) :
87  _channelCount(channelCount)
88  {
89  _channelFrequencies = new double[channelCount];
90  memcpy(_channelFrequencies, frequencies, sizeof(double)*channelCount);
91  if(channelCount >= 2)
92  _frequencyStep = _channelFrequencies[1] - _channelFrequencies[0];
93  else
94  _frequencyStep = 0.0;
95  }
96 
99  {
100  delete[] _channelFrequencies;
101  }
102 
104  void operator=(const BandData& source)
105  {
106  _channelCount = source._channelCount;
107  _frequencyStep = source._frequencyStep;
108  if(_channelCount != 0)
109  {
110  _channelFrequencies = new double[_channelCount];
111  for(size_t index = 0; index != _channelCount; ++index)
112  {
113  _channelFrequencies[index] = source._channelFrequencies[index];
114  }
115  }
116  else {
117  _channelFrequencies = 0;
118  }
119  }
120 
122  double* begin()
123  { return _channelFrequencies; }
125  double* end()
126  { return _channelFrequencies+_channelCount; }
128  const double* begin() const
129  { return _channelFrequencies; }
131  const double* end() const
132  { return _channelFrequencies+_channelCount; }
133 
134  std::reverse_iterator<double*> rbegin()
135  { return std::reverse_iterator<double*>(end()); }
136 
137  std::reverse_iterator<double*> rend()
138  { return std::reverse_iterator<double*>(begin()); }
139 
140  std::reverse_iterator<const double*> rbegin() const
141  { return std::reverse_iterator<const double*>(end()); }
142 
143  std::reverse_iterator<const double*> rend() const
144  { return std::reverse_iterator<const double*>(begin()); }
145 
151  void Set(size_t channelCount, const double* frequencies)
152  {
153  _channelCount = channelCount;
154  delete[] _channelFrequencies;
155  _channelFrequencies = new double[channelCount];
156  memcpy(_channelFrequencies, frequencies, sizeof(double)*channelCount);
157  }
158 
162  size_t ChannelCount() const { return _channelCount; }
163 
167  double ChannelFrequency(size_t channelIndex) const
168  {
169  return _channelFrequencies[channelIndex];
170  }
171 
175  double ChannelWavelength(size_t channelIndex) const
176  {
177  return 299792458.0L / _channelFrequencies[channelIndex];
178  }
179 
183  double HighestFrequency() const
184  {
185  return _channelFrequencies[_channelCount-1];
186  }
187 
191  double LowestFrequency() const
192  {
193  return _channelFrequencies[0];
194  }
195 
199  double CentreFrequency() const
200  {
201  return (HighestFrequency() + LowestFrequency()) * 0.5;
202  }
203 
208  static double FrequencyToLambda(double frequencyHz)
209  {
210  return 299792458.0L / frequencyHz;
211  }
212 
216  double CentreWavelength() const
217  {
218  return 299792458.0L / ((HighestFrequency() + LowestFrequency()) * 0.5);
219  }
220 
224  double FrequencyStep() const
225  {
226  return _frequencyStep;
227  }
228 
231  double LongestWavelength() const
232  {
233  return ChannelWavelength(0);
234  }
235 
238  double SmallestWavelength() const
239  {
240  return ChannelWavelength(_channelCount-1);
241  }
242 
245  double BandStart() const
246  {
247  return LowestFrequency() - FrequencyStep()*0.5;
248  }
251  double BandEnd() const
252  {
253  return HighestFrequency() + FrequencyStep()*0.5;
254  }
255 
258  double Bandwidth() const
259  {
261  }
262 
263  private:
264  void initFromTable(casacore::MSSpectralWindow& spwTable, size_t bandIndex)
265  {
266  casacore::ROScalarColumn<int> numChanCol(spwTable, casacore::MSSpectralWindow::columnName(casacore::MSSpectralWindowEnums::NUM_CHAN));
267  int temp;
268  numChanCol.get(bandIndex, temp);
269  _channelCount = temp;
270  if(_channelCount == 0) throw std::runtime_error("No channels in set");
271 
272  casacore::ROArrayColumn<double> chanFreqCol(spwTable, casacore::MSSpectralWindow::columnName(casacore::MSSpectralWindowEnums::CHAN_FREQ));
273  casacore::Array<double> channelFrequencies;
274  chanFreqCol.get(bandIndex, channelFrequencies, true);
275 
276  _channelFrequencies = new double[_channelCount];
277  size_t index = 0;
278  for(casacore::Array<double>::const_iterator i=channelFrequencies.begin();
279  i != channelFrequencies.end(); ++i)
280  {
281  _channelFrequencies[index] = *i;
282  ++index;
283  }
284  if(_channelCount > 1)
285  _frequencyStep = _channelFrequencies[1] - _channelFrequencies[0];
286  else
287  _frequencyStep = 0.0;
288  }
289 
290  size_t _channelCount;
291  double *_channelFrequencies;
292  double _frequencyStep;
293 };
294 
295 #endif
double CentreWavelength() const
Get the wavelength of the central channel.
Definition: banddata.h:216
double FrequencyStep() const
Get the distance between channels in Hz.
Definition: banddata.h:224
void Set(size_t channelCount, const double *frequencies)
Assign new frequencies to this instance.
Definition: banddata.h:151
BandData()
Construct an empty instance.
Definition: banddata.h:24
double LowestFrequency() const
Get the frequency of the first channel.
Definition: banddata.h:191
double CentreFrequency() const
Get the centre frequency.
Definition: banddata.h:199
BandData(const BandData &source, size_t startChannel, size_t endChannel)
Construct a new instance from a part of another band.
Definition: banddata.h:69
double BandStart() const
Get the start of the frequency range covered by this band.
Definition: banddata.h:245
const double * begin() const
Constant iterator over frequencies, pointing to first channel.
Definition: banddata.h:128
double HighestFrequency() const
Get the frequency of the last channel.
Definition: banddata.h:183
Contains information about a single band ("spectral window").
Definition: banddata.h:15
double BandEnd() const
Get the end of the frequency range covered by this band.
Definition: banddata.h:251
const double * end() const
Constant iterator over frequencies, pointing to last channel.
Definition: banddata.h:131
size_t ChannelCount() const
Retrieve number of channels in this band.
Definition: banddata.h:162
BandData(casacore::MSSpectralWindow &spwTable)
Construct an instance from a spectral window table.
Definition: banddata.h:33
double LongestWavelength() const
Get the wavelength of the first channel.
Definition: banddata.h:231
double * begin()
Iterator over frequencies, pointing to first channel.
Definition: banddata.h:122
double Bandwidth() const
Get the total bandwidth covered by this band.
Definition: banddata.h:258
~BandData()
Destructor.
Definition: banddata.h:98
double ChannelWavelength(size_t channelIndex) const
Get the wavelength in m of a specified channel.
Definition: banddata.h:175
BandData(size_t channelCount, const double *frequencies)
Construct a new BandData class and initialize it with an array of frequencies.
Definition: banddata.h:86
double * end()
Iterator over frequencies, pointing past last channel.
Definition: banddata.h:125
void operator=(const BandData &source)
Assignment operator.
Definition: banddata.h:104
double SmallestWavelength() const
Get the wavelength of the last channel.
Definition: banddata.h:238
BandData(casacore::MSSpectralWindow &spwTable, size_t bandIndex)
Construct an instance from a specified entry of a spectral window table.
Definition: banddata.h:45
BandData(const BandData &source)
Copy constructor.
Definition: banddata.h:54
static double FrequencyToLambda(double frequencyHz)
Convert a frequency to a wavelength.
Definition: banddata.h:208
double ChannelFrequency(size_t channelIndex) const
Get the frequency in Hz of a specified channel.
Definition: banddata.h:167