File: msmetadata.h

package info (click to toggle)
aoflagger 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,476 kB
  • sloc: cpp: 51,868; python: 152; sh: 25; makefile: 17
file content (214 lines) | stat: -rw-r--r-- 4,606 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#ifndef MS_META_DATA_H
#define MS_META_DATA_H

#include "antennainfo.h"

#include <casacore/ms/MeasurementSets/MeasurementSet.h>

#include <boost/optional/optional.hpp>

#include <string>
#include <vector>
#include <utility>
#include <set>

class MSMetaData
{
public:
	class Sequence;
	
	explicit MSMetaData(const std::string &path)
		: _path(path), _isMainTableDataInitialized(false)
	{
		initializeOtherData();
	}
	
	~MSMetaData();
	
	void SetIntervalStart(size_t index) { _intervalStart = index;}
	void SetIntervalEnd(size_t index) { _intervalEnd = index; }
	
	size_t FrequencyCount(size_t bandIndex)
	{
		return _bands[bandIndex].channels.size();
	}
	
	size_t TimestepCount()
	{
		initializeMainTableData();
		return _observationTimes.size();
	}
	
	size_t TimestepCount(size_t sequenceId)
	{
		initializeMainTableData();
		return _observationTimesPerSequence[sequenceId].size();
	}
	
	size_t PolarizationCount() const
	{
		return PolarizationCount(Path());
	}
	
	static size_t PolarizationCount(const std::string &filename);
	
	size_t AntennaCount() const
	{
		return _antennas.size();
	}
	
	size_t BandCount() const
	{ 
		return _bands.size();
	}
	
	size_t FieldCount() const
	{
		return _fields.size();
	}
	
	static size_t BandCount(const std::string &filename);
	
	/**
		* Get number of sequences. A sequence is a contiguous number of scans
		* on the same field. Thus, the next sequence starts as soon as the
		* fieldId changes (possibly to a previous field)
		*/
	size_t SequenceCount()
	{
		initializeMainTableData();
		return _observationTimesPerSequence.size();
	}
	
	const AntennaInfo &GetAntennaInfo(unsigned antennaId) const
	{
		return _antennas[antennaId];
	}
	
	//static BandInfo GetBandInfo(const std::string &filename, unsigned bandIndex);
	
	const BandInfo &GetBandInfo(unsigned bandIndex) const
	{
		return _bands[bandIndex];
	}
	
	const FieldInfo &GetFieldInfo(unsigned fieldIndex) const
	{
		return _fields[fieldIndex];
	}
	
	void GetDataDescToBandVector(std::vector<size_t>& dataDescToBand);
	
	std::string Path() const { return _path; }
	
	void GetBaselines(std::vector<std::pair<size_t,size_t> > &baselines)
	{
		initializeMainTableData();
		baselines = _baselines;
	}
	
	const std::vector<Sequence> &GetSequences()
	{
		initializeMainTableData();
		return _sequences;
	}
	
	const std::set<double> &GetObservationTimesSet()
	{
		initializeMainTableData();
		return _observationTimes;
	}
	
	const std::set<double> &GetObservationTimesSet(size_t sequenceId)
	{
		initializeMainTableData();
		return _observationTimesPerSequence[sequenceId];
	}
	
	bool HasAOFlaggerHistory();
	
	void GetAOFlaggerHistory(std::ostream &stream);
	
	void AddAOFlaggerHistory(const std::string& strategy, const std::string &commandline);
	
	std::string GetStationName() const;
	
	bool IsChannelZeroRubish();
	
	const std::string &TelescopeName() const { return _telescopeName; }
	
	class Sequence
	{
	public:
		Sequence(unsigned _antenna1, unsigned _antenna2, unsigned _spw, unsigned _sequenceId, unsigned _fieldId) :
			antenna1(_antenna1), antenna2(_antenna2),
			spw(_spw), sequenceId(_sequenceId),
			fieldId(_fieldId)
		{ }
		
		unsigned antenna1, antenna2;
		unsigned spw;
		unsigned sequenceId;
		unsigned fieldId;
		
		bool operator<(const Sequence &rhs) const
		{
			if(antenna1 < rhs.antenna1) return true;
			else if(antenna1 == rhs.antenna1)
			{
				if(antenna2 < rhs.antenna2) return true;
				else if(antenna2 == rhs.antenna2)
				{
					if(spw < rhs.spw) return true;
					else if(spw == rhs.spw)
					{
						return sequenceId < rhs.sequenceId;
					}
				}
			}
			return false;
		}
		
		bool operator==(const Sequence &rhs) const
		{
			return antenna1==rhs.antenna1 && antenna2==rhs.antenna2 &&
				spw==rhs.spw && sequenceId==rhs.sequenceId;
		}
	};
	
	static std::string GetTelescopeName(casacore::MeasurementSet& ms);

private:
	void initializeMainTableData();
	
	void initializeOtherData();
	
	void initializeAntennas(casacore::MeasurementSet& ms);
	void initializeBands(casacore::MeasurementSet& ms);
	void initializeFields(casacore::MeasurementSet& ms);
	void initializeObservation(casacore::MeasurementSet& ms);

	const std::string _path;
	
	bool _isMainTableDataInitialized;
	
	std::vector<std::pair<size_t,size_t> > _baselines;
	
	std::set<double> _observationTimes;
	
	std::vector<std::set<double> > _observationTimesPerSequence;

	std::vector<AntennaInfo> _antennas;
	
	std::vector<BandInfo> _bands;
	
	std::vector<FieldInfo> _fields;
	
	std::vector<Sequence> _sequences;
	
	std::string _telescopeName;
	
	boost::optional<size_t> _intervalStart, _intervalEnd;
};

#endif