-
Notifications
You must be signed in to change notification settings - Fork 2
/
aartfaac2ms.h
129 lines (109 loc) · 4 KB
/
aartfaac2ms.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef AARTFAAC2MS_H
#define AARTFAAC2MS_H
#include <aoflagger.h>
#include "aartfaacfile.h"
#include "aligned_ptr.h"
#include "antennaconfig.h"
#include "averagingwriter.h"
#include "stopwatch.h"
#include "progressbar.h"
#include "writer.h"
#include <aocommon/lane.h>
#include <aocommon/uvector.h>
#include <casacore/measures/Measures/MDirection.h>
#include <casacore/measures/Measures/MPosition.h>
#include <complex>
#include <map>
#include <memory>
#include <mutex>
#include <vector>
struct UVW { double u, v, w; };
class Aartfaac2ms
{
public:
enum OutputFormat { MSOutputFormat, FitsOutputFormat };
Aartfaac2ms();
void Run(const char* inputFilename, const char* outputFilename, const char* antennaConfFilename, AartfaacMode mode);
void SetMemPercentage(double memPercentage) { _memPercentage = memPercentage; }
void SetThreadCount(size_t nThreads) { _threadCount = nThreads; }
void SetTimeAveraging(size_t factor) { _timeAvgFactor = factor; }
void SetFrequencyAveraging(size_t factor) { _freqAvgFactor = factor; }
void SetInterval(size_t start, size_t end) { _intervalStart = start; _intervalEnd = end; }
void SetPhaseCentre(double ra, double dec) {
_manualPhaseCentre = true;
_manualPhaseCentreRA = ra;
_manualPhaseCentreDec = dec;
}
void SetRFIDetection(bool detectRFI) { _rfiDetection = detectRFI; }
void SetUseDysco(bool useDysco) { _useDysco = useDysco; }
void SetAdvancedDyscoOptions(size_t dataBitRate, size_t weightBitRate, const std::string& distribution, double distTruncation, const std::string& normalization)
{
_dyscoDataBitRate = dataBitRate;
_dyscoWeightBitRate = weightBitRate;
_dyscoDistribution = distribution;
_dyscoDistTruncation = distTruncation;
_dyscoNormalization = normalization;
}
private:
void allocateBuffers();
void processAndWriteTimestep(size_t timeIndex, size_t chunkStart);
void initializeWriter(const char* outputFilename);
void initializeWeights(float* outputWeights, double integrationTime);
void readAntennaPositions(const char* antennaConfFilename);
void baselineProcessThreadFunc(ProgressBar* progressBar);
void processBaseline(size_t baseline, aoflagger::Strategy& threadStrategy, aoflagger::QualityStatistics& threadStatistics);
void writeAartfaacFieldsToMS(const std::string& outputFilename, size_t flagWindowSize);
void setAntennas();
void setSPWs();
void setSource();
void setField();
void setObservation();
size_t NTimestepsSelected() const
{
size_t nTimesteps = _reader->NTimesteps();
if(_intervalEnd!=0 && nTimesteps>(_intervalEnd-_intervalStart))
nTimesteps = _intervalEnd - _intervalStart;
return nTimesteps;
}
std::unique_ptr<class AartfaacFile> _reader;
aoflagger::AOFlagger _flagger;
std::unique_ptr<aoflagger::QualityStatistics> _statistics;
std::unique_ptr<Writer> _writer;
std::string _strategyFile;
std::mutex _mutex;
aocommon::Lane<size_t> _baselinesToProcess;
// settings
AartfaacMode _mode;
OutputFormat _outputFormat;
bool _rfiDetection, _collectStatistics, _collectHistograms;
size_t _timeAvgFactor, _freqAvgFactor;
double _memPercentage;
size_t _intervalStart, _intervalEnd;
bool _manualPhaseCentre;
double _manualPhaseCentreRA, _manualPhaseCentreDec;
bool _useDysco;
size_t _dyscoDataBitRate;
size_t _dyscoWeightBitRate;
std::string _dyscoDistribution;
std::string _dyscoNormalization;
double _dyscoDistTruncation;
size_t _threadCount;
// data fields
size_t _nParts;
std::vector<aoflagger::ImageSet> _imageSetBuffers;
std::vector<aoflagger::FlagMask> _flagBuffers;
aoflagger::FlagMask _correlatorMask;
std::vector<double> _timestepsStart, _timestepsEnd;
std::vector<std::pair<size_t, size_t>> _baselines;
std::vector<UVW> _uvws;
std::vector<casacore::MPosition> _antennaPositions;
std::array<double, 9> _antennaAxes;
casacore::MDirection _phaseDirection;
aocommon::UVector<double> _channelFrequenciesHz;
// write buffers
aocommon::UVector<bool> _outputFlags;
aligned_ptr<std::complex<float>> _outputData;
aligned_ptr<float> _outputWeights;
Stopwatch _readWatch, _processWatch, _writeWatch;
};
#endif