File: antennainfo.h

package info (click to toggle)
aoflagger 2.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,232 kB
  • sloc: cpp: 61,805; python: 60; sh: 23; makefile: 8
file content (319 lines) | stat: -rw-r--r-- 7,920 bytes parent folder | download | duplicates (2)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#ifndef ANTENNAINFO_H
#define ANTENNAINFO_H

#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <vector>

#include "types.h"

#include "../util/serializable.h"

class EarthPosition {
public:
	EarthPosition() : x(0.0), y(0.0), z(0.0) { }
	
	double x, y, z;
	std::string ToString() {
		std::stringstream s;
		s.setf(std::ios::fixed,std::ios::floatfield);
		s.width(16);
		s.precision(16);
		s << x << "," << y << "," << z << " (alt " << sqrtl(x*x+y*y+z*z) << "), or "
		<< "N" << Latitude()*180/M_PI << " E" << Longitude()*180/M_PI;
		return s.str();
	}
	EarthPosition FromITRS(long double x, long double y, long double z);
	
	double Longitude() const
	{
		return atan2l(y, x);
	}
	
	long double LongitudeL() const
	{
		return atan2l(y, x);
	}

	double Latitude() const
	{
		return atan2l(z, sqrtl((long double) x*x + y*y));
	}
	
	long double LatitudeL() const
	{
		return atan2l(z, sqrtl((long double) x*x + y*y));
	}
	
	double Altitude() const
	{
		return sqrtl((long double) x*x+y*y+z*z);
	}
	
	double AltitudeL() const
	{
		return sqrtl((long double) x*x+y*y+z*z);
	}

	void Serialize(std::ostream &stream) const
	{
		Serializable::SerializeToDouble(stream, x);
		Serializable::SerializeToDouble(stream, y);
		Serializable::SerializeToDouble(stream, z);
	}
	
	void Unserialize(std::istream &stream)
	{
		x = Serializable::UnserializeDouble(stream);
		y = Serializable::UnserializeDouble(stream);
		z = Serializable::UnserializeDouble(stream);
	}
	
	double Distance(const EarthPosition& other) const
	{
		return sqrt(DistanceSquared(other));
	}
	
	double DistanceSquared(const EarthPosition& other) const
	{
		double dx = x-other.x, dy = y-other.y, dz = z-other.z;
		return dx*dx + dy*dy + dz*dz;
	}
};

class UVW {
public:
	UVW() : u(0.0), v(0.0), w(0.0) { }
	UVW(num_t _u, num_t _v, num_t _w) : u(_u), v(_v), w(_w) { }
	num_t u, v, w;
};

class AntennaInfo {
public:
	AntennaInfo() { }

	unsigned id;
	EarthPosition position;
	std::string name;
	double diameter;
	std::string mount;
	std::string station;
	
	void Serialize(std::ostream &stream) const
	{
		Serializable::SerializeToUInt32(stream, id);
		position.Serialize(stream);
		Serializable::SerializeToString(stream, name);
		Serializable::SerializeToDouble(stream, diameter);
		Serializable::SerializeToString(stream, mount);
		Serializable::SerializeToString(stream, station);
	}
	
	void Unserialize(std::istream &stream)
	{
		id = Serializable::UnserializeUInt32(stream);
		position.Unserialize(stream);
		Serializable::UnserializeString(stream, name);
		diameter = Serializable::UnserializeDouble(stream);
		Serializable::UnserializeString(stream, mount);
		Serializable::UnserializeString(stream, station);
	}
};

class ChannelInfo {
public:
	unsigned frequencyIndex;
	double frequencyHz;
	double channelWidthHz;
	double effectiveBandWidthHz;
	double resolutionHz;
	
	double MetersToLambda(double meters) const
	{
		return meters * frequencyHz / 299792458.0L;
	}
	void Serialize(std::ostream &stream) const
	{
		Serializable::SerializeToUInt32(stream, frequencyIndex);
		Serializable::SerializeToDouble(stream, frequencyHz);
		Serializable::SerializeToDouble(stream, channelWidthHz);
		Serializable::SerializeToDouble(stream, effectiveBandWidthHz);
		Serializable::SerializeToDouble(stream, resolutionHz);
	}
	
	void Unserialize(std::istream &stream)
	{
		frequencyIndex = Serializable::UnserializeUInt32(stream);
		frequencyHz = Serializable::UnserializeDouble(stream);
		channelWidthHz = Serializable::UnserializeDouble(stream);
		effectiveBandWidthHz = Serializable::UnserializeDouble(stream);
		resolutionHz = Serializable::UnserializeDouble(stream);
	}
};

class BandInfo {
public:
	unsigned windowIndex;
	std::vector<ChannelInfo> channels;

	BandInfo() : windowIndex(0) { }

	num_t CenterFrequencyHz() const
	{
		num_t total = 0.0;
		for(std::vector<ChannelInfo>::const_iterator i=channels.begin();i!=channels.end();++i)
			total += i->frequencyHz;
		return total / channels.size();
	}
	void Serialize(std::ostream &stream) const
	{
		Serializable::SerializeToUInt32(stream, windowIndex);
		Serializable::SerializeToUInt32(stream, channels.size());
		for(std::vector<ChannelInfo>::const_iterator i=channels.begin();i!=channels.end();++i)
			i->Serialize(stream);
	}
	
	void Unserialize(std::istream &stream)
	{
		windowIndex = Serializable::UnserializeUInt32(stream);
		size_t channelCount = Serializable::UnserializeUInt32(stream);
		channels.resize(channelCount);
		for(size_t i=0;i<channelCount;++i)
			channels[i].Unserialize(stream);
	}
};

class FieldInfo {
public:
	FieldInfo() { }
	FieldInfo(const FieldInfo &source) :
		fieldId(source.fieldId),
		delayDirectionRA(source.delayDirectionRA),
		delayDirectionDec(source.delayDirectionDec),
		name(source.name)
	{ }
	FieldInfo &operator=(const FieldInfo &source)
	{
		fieldId = source.fieldId;
		delayDirectionRA = source.delayDirectionRA;
		delayDirectionDec = source.delayDirectionDec;
		name = source.name;
		return *this;
	}
	
	unsigned fieldId;
	num_t delayDirectionRA;
	num_t delayDirectionDec;
	std::string name;
};

class Baseline {
public:
	EarthPosition antenna1, antenna2;
	Baseline()
		: antenna1(), antenna2() { }
	Baseline(const AntennaInfo& _antenna1, const AntennaInfo &_antenna2)
		: antenna1(_antenna1.position), antenna2(_antenna2.position) { }
	Baseline(const EarthPosition& _antenna1, const EarthPosition& _antenna2)
		: antenna1(_antenna1), antenna2(_antenna2) { }

	num_t Distance() const {
		num_t dx = antenna1.x-antenna2.x;
		num_t dy = antenna1.y-antenna2.y;
		num_t dz = antenna1.z-antenna2.z;
		return sqrtn(dx*dx+dy*dy+dz*dz);
	}
	num_t Angle() const {
		num_t dz = antenna1.z-antenna2.z;
 		// baseline is either orthogonal to the earths axis, or
		// the length of the baseline is zero. 
		if(dz == 0.0) return 0.0;
		num_t transf = 1.0/(antenna1.z-antenna2.z);
		num_t dx = (antenna1.x-antenna2.x)*transf;
		num_t dy = (antenna1.y-antenna2.y)*transf;
		num_t length = sqrtn(dx*dx + dy*dy + 1.0);
		return acosn(1.0/length);
	}
	num_t DeltaX() const { return antenna2.x-antenna1.x; }
	num_t DeltaY() const { return antenna2.y-antenna1.y; }
	num_t DeltaZ() const { return antenna2.z-antenna1.z; }
};

class Frequency {
public:
	static std::string ToString(num_t value)
	{
		std::stringstream s;
		if(fabs(value) >= 1000000000.0L)
			s << round(value/10000000.0L)/100.0L << " GHz";
		else if(fabs(value) >= 1000000.0L)
			s << round(value/10000.0L)/100.0L << " MHz";
		else if(fabs(value) >= 1000.0L)
			s << round(value/10.0L)/100.0L << " KHz";
		else
			s << value << " Hz";
		return s.str();
	}
};

class RightAscension {
public:
	static std::string ToString(numl_t value)
	{
		value = fmod(value, 2.0*M_PInl);
		if(value < 0.0) value += 2.0*M_PInl;
		std::stringstream s;
		s << (int) floorn(value*12.0/M_PInl) << ':';
		int d2 = (int) floornl(fmodnl(value*12.0*60.0/M_PInl, 60.0));
		if(d2 < 10) s << '0';
		s << d2 << ':';
		numl_t d3 = fmodnl(value*12.0*60.0*60.0/M_PInl, 60.0);
		if(d3 < 10.0) s << '0';
		s << d3;
		return s.str();
	}
};

class Declination {
public:
	static std::string ToString(numl_t value)
	{
		value = fmod(value, 2.0*M_PInl);
		if(value < 0.0) value += 2.0*M_PInl;
		if(value > M_PInl*0.5) value = M_PInl - value;
		std::stringstream s;
		if(value > 0.0)
			s << '+';
		else
			s << '-';
		value = fabsnl(value);
		s << (int) floornl(value*180.0/M_PIn) << '.';
		int d2 = (int) fmodnl(value*180.0*60.0/M_PIn, 60.0);
		if(d2 < 10) s << '0';
		s << d2 << '.';
		numl_t d3 = fmodnl(value*180.0*60.0*60.0/M_PIn, 60.0);
		if(d3 < 10.0) s << '0';
		s << d3;
		return s.str();
	}
};

class Angle {
public:
	static std::string ToString(numl_t valueRad)
	{
		std::stringstream s;
		numl_t deg = valueRad * 180.0/M_PI;
		if(std::abs(deg) > 3)
			s << deg << " deg";
		else if(std::abs(deg) > 3.0/60.0)
			s << (deg / 60.0) << " arcmin";
		else
			s << (deg / 3600.0) << " arcsec";
		return s.str();
	}
};

#endif