File: msselection.cpp

package info (click to toggle)
wsclean 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,968 kB
  • sloc: cpp: 85,742; python: 3,526; sh: 245; makefile: 21
file content (53 lines) | stat: -rw-r--r-- 1,951 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "msselection.h"

#include <algorithm>

#include <aocommon/logger.h>
#include <aocommon/multibanddata.h>

using schaapcommon::reordering::ChannelRange;

namespace wsclean {

ChannelRange SelectMsChannels(const aocommon::MultiBandData& ms_bands,
                              size_t data_desc_id, double lowest_frequency,
                              double highest_frequency) {
  const aocommon::BandData& band = ms_bands[data_desc_id];
  double first_channel = band.ChannelFrequency(0);
  double last_channel = band.ChannelFrequency(band.ChannelCount() - 1);
  // Some mses have decreasing (i.e. reversed) channel frequencies in them
  bool is_reversed = false;
  if (first_channel > last_channel) {
    std::swap(first_channel, last_channel);
    is_reversed = true;
    aocommon::Logger::Debug
        << "Warning: MS has reversed channel frequencies.\n";
  }
  if (band.ChannelCount() != 0 && lowest_frequency <= last_channel &&
      highest_frequency >= first_channel) {
    size_t range_start, range_end;
    if (is_reversed) {
      aocommon::BandData::const_reverse_iterator low_ptr =
          std::lower_bound(band.rbegin(), band.rend(), lowest_frequency);
      aocommon::BandData::const_reverse_iterator high_ptr =
          std::upper_bound(low_ptr, band.rend(), highest_frequency);

      range_start = band.ChannelCount() - (high_ptr - band.rbegin());
      range_end = band.ChannelCount() - (low_ptr - band.rbegin());
    } else {
      const aocommon::BandData::const_iterator low_ptr =
          std::lower_bound(band.begin(), band.end(), lowest_frequency);
      aocommon::BandData::const_iterator high_ptr =
          std::upper_bound(low_ptr, band.end(), highest_frequency);

      range_start = low_ptr - band.begin();
      range_end = high_ptr - band.begin();
    }

    return ChannelRange{data_desc_id, range_start, range_end};
  } else {
    return ChannelRange(data_desc_id, 0, 0);
  }
}

}  // namespace wsclean