File: applybandpass.h

package info (click to toggle)
aoflagger 3.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,868 kB
  • sloc: cpp: 52,164; python: 152; sh: 60; makefile: 17
file content (86 lines) | stat: -rw-r--r-- 2,738 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef APPLY_BANDPASS_H
#define APPLY_BANDPASS_H

#include "../../structures/timefrequencydata.h"

#include "bandpassfile.h"

#include <string>

class ApplyBandpass {
 public:
  static void Apply(TimeFrequencyData& data, BandpassFile& file,
                    const std::string& antenna1, const std::string& antenna2) {
    for (size_t i = 0; i != data.PolarizationCount(); ++i) {
      TimeFrequencyData polData = data.MakeFromPolarizationIndex(i);
      char pol1, pol2;
      switch (polData.GetPolarization(0)) {
        case aocommon::Polarization::XX:
          pol1 = 'X';
          pol2 = 'X';
          break;
        case aocommon::Polarization::XY:
          pol1 = 'X';
          pol2 = 'Y';
          break;
        case aocommon::Polarization::YX:
          pol1 = 'Y';
          pol2 = 'X';
          break;
        case aocommon::Polarization::YY:
          pol1 = 'Y';
          pol2 = 'Y';
          break;
        case aocommon::Polarization::LL:
          pol1 = 'L';
          pol2 = 'L';
          break;
        case aocommon::Polarization::LR:
          pol1 = 'L';
          pol2 = 'R';
          break;
        case aocommon::Polarization::RL:
          pol1 = 'R';
          pol2 = 'L';
          break;
        case aocommon::Polarization::RR:
          pol1 = 'R';
          pol2 = 'R';
          break;
        default:
          throw std::runtime_error("Can't apply a bandpass for polarization " +
                                   aocommon::Polarization::TypeToShortString(
                                       polData.GetPolarization(0)));
      }

      for (size_t imageIndex = 0; imageIndex != polData.ImageCount();
           ++imageIndex) {
        Image2DCPtr uncorrected = polData.GetImage(imageIndex);
        Image2DPtr newImage =
            apply(uncorrected, file, antenna1, antenna2, pol1, pol2);
        polData.SetImage(imageIndex, std::move(newImage));
      }
      data.SetPolarizationData(i, std::move(polData));
    }
  }

 private:
  static Image2DPtr apply(Image2DCPtr& uncorrected, BandpassFile& file,
                          const std::string& antenna1,
                          const std::string& antenna2, char pol1, char pol2) {
    Image2DPtr corrected =
        Image2D::MakePtr(uncorrected->Width(), uncorrected->Height());
    for (size_t ch = 0; ch != uncorrected->Height(); ++ch) {
      float val = 1.0 / (file.GetValue(antenna1, pol1, ch) *
                         file.GetValue(antenna2, pol2, ch));
      const num_t* ptrUncor = uncorrected->ValuePtr(0, ch);
      num_t* ptrCor = corrected->ValuePtr(0, ch);
      for (size_t x = 0; x != uncorrected->Width(); ++x) {
        ptrCor[x] = ptrUncor[x] * val;
      }
    }
    return corrected;
  }
};

#endif