1 | //
|
---|
2 | // C++ Implementation: STPolLinear
|
---|
3 | //
|
---|
4 | // Description:
|
---|
5 | //
|
---|
6 | //
|
---|
7 | // Author: Malte Marquarding <Malte.Marquarding@csiro.au>, (C) 2006
|
---|
8 | //
|
---|
9 | // Copyright: See COPYING file that comes with this distribution
|
---|
10 | //
|
---|
11 | //
|
---|
12 |
|
---|
13 | #include <casa/Arrays/ArrayMath.h>
|
---|
14 | #include <casa/BasicMath/Math.h>
|
---|
15 | #include <casa/Exceptions/Error.h>
|
---|
16 | #include <casa/BasicSL/Constants.h>
|
---|
17 | #include "STPolLinear.h"
|
---|
18 |
|
---|
19 | using namespace casa;
|
---|
20 |
|
---|
21 | namespace asap {
|
---|
22 |
|
---|
23 | Factory<STPol,STPolLinear> STPolLinear::myFactory;
|
---|
24 |
|
---|
25 | STPolLinear::~STPolLinear()
|
---|
26 | {
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | Vector<Float> asap::STPolLinear::getStokes( uint index )
|
---|
31 | {
|
---|
32 | if ( index < 0 || index >4 ) throw(AipsError("Stokes index out of range"));
|
---|
33 | Vector<Float> out;
|
---|
34 | Float phase = getTotalPhase();
|
---|
35 | Vector<Float> q(getSpectrum(0) - getSpectrum(1));
|
---|
36 | if ( nspec() == 4 ) {
|
---|
37 | switch(index) {
|
---|
38 | case 0:
|
---|
39 | out = Vector<Float>(getSpectrum(0) + getSpectrum(1));
|
---|
40 | break;
|
---|
41 | case 1:
|
---|
42 | out = Vector<Float>(q * cos(phase) - getSpectrum(2) * sin(phase));
|
---|
43 | break;
|
---|
44 | case 2:
|
---|
45 | out = Vector<Float>(q * sin(phase) + getSpectrum(2) * cos(phase));
|
---|
46 | break;
|
---|
47 | case 3:
|
---|
48 | out = getFeedHand() * Vector<Float>(getSpectrum(3));
|
---|
49 | break;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | return out;
|
---|
53 | }
|
---|
54 |
|
---|
55 | Vector<Float> asap::STPolLinear::getLinPol( uInt index )
|
---|
56 | {
|
---|
57 | if ( index < 0 || index >4 ) throw(AipsError("LinPol index out of range"));
|
---|
58 | Vector<Float> out,q,u;
|
---|
59 | if ( nspec() == 4) {
|
---|
60 | switch(index) {
|
---|
61 | case 1:
|
---|
62 | q = getStokes(1);
|
---|
63 | u = getStokes(2);
|
---|
64 | out = Vector<Float>(sqrt(pow(q,Float(2.0))+pow(u, Float(2.0))));
|
---|
65 | break;
|
---|
66 | case 2:
|
---|
67 | q = getStokes(index);
|
---|
68 | u = getStokes(2);
|
---|
69 | out = Vector<Float>(Float(180.0/C::pi/2.0) * atan2(u,q));
|
---|
70 | break;
|
---|
71 | default:
|
---|
72 | out = getStokes(index);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | return out;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Vector<Float> asap::STPolLinear::getLinear(uInt index )
|
---|
79 | {
|
---|
80 | return getSpectrum(index);
|
---|
81 | }
|
---|
82 |
|
---|
83 | Vector<Float> asap::STPolLinear::getCircular(uInt index )
|
---|
84 | {
|
---|
85 | // convert to stokes I/ V first
|
---|
86 | //
|
---|
87 | // We use the convention
|
---|
88 | // I = (RR+LL) // definition changed
|
---|
89 |
|
---|
90 | if ( index == 2 || index ==3 ) throw(AipsError("Re/Imag RL not implemented"));
|
---|
91 | Vector<Float> I,V,out;
|
---|
92 | I = getStokes(0);
|
---|
93 | V = getStokes(3);
|
---|
94 | switch(index) {
|
---|
95 | case 0:
|
---|
96 | out = (I + V);
|
---|
97 | break;
|
---|
98 | case 1:
|
---|
99 | out = (I - V);
|
---|
100 | break;
|
---|
101 | default:
|
---|
102 | out = Vector<Float>();
|
---|
103 | }
|
---|
104 | return out;
|
---|
105 | }
|
---|
106 |
|
---|
107 | void asap::STPolLinear::rotatePhase( Float phase )
|
---|
108 | {
|
---|
109 | if (nspec() != 4) {
|
---|
110 | throw(AipsError("You must have 4 linear polarizations to run this function"));
|
---|
111 | }
|
---|
112 | Float cosVal = cos(C::pi/180.0*phase);
|
---|
113 | Float sinVal = sin(C::pi/180.0*phase);
|
---|
114 | Matrix<Float>& specs = getSpectra();
|
---|
115 | Vector<Float> R2 = specs.column(2)*cosVal - specs.column(3)*sinVal;
|
---|
116 | specs.column(3) = specs.column(2)*sinVal + specs.column(3)*cosVal;
|
---|
117 | specs.column(2) = R2;
|
---|
118 | }
|
---|
119 |
|
---|
120 | void asap::STPolLinear::invertPhase( Float phase )
|
---|
121 | {
|
---|
122 | // phase isnt used, just ro keep interface the same for all pol operations
|
---|
123 | Matrix<Float>& specs = getSpectra();
|
---|
124 | Vector<Float> I = specs.column(3);
|
---|
125 | I *= Float(-1.0);
|
---|
126 | }
|
---|
127 |
|
---|
128 | void asap::STPolLinear::rotateLinPolPhase( casa::Float phase )
|
---|
129 | {
|
---|
130 | //
|
---|
131 | // Rotate P = Q + iU but do it directly on the linear
|
---|
132 | // correlations.
|
---|
133 | //
|
---|
134 | // We are using I=(XX+YY)/2 convention
|
---|
135 | // C1 = XX; C2 = YY, C3 = Real(XY)
|
---|
136 | //
|
---|
137 | Vector<Float> I,Q,U;
|
---|
138 | I = getStokes(0);
|
---|
139 | Q = getStokes(1);
|
---|
140 | U = getStokes(2);
|
---|
141 | // Rotate Q & U (factor of 2 for polarization)
|
---|
142 | Float cosVal = cos(C::pi/180.0*2.0*phase);
|
---|
143 | Float sinVal = sin(C::pi/180.0*2.0*phase);
|
---|
144 | Vector<Float> Q2 = Q*cosVal - U*sinVal;
|
---|
145 | U = Q*sinVal + U*cosVal;
|
---|
146 | Q = Q2;
|
---|
147 | Matrix<Float>& specs = getSpectra();
|
---|
148 | specs.column(0) = I+Q;
|
---|
149 | specs.column(1) = I-Q;
|
---|
150 | specs.column(2) = U;
|
---|
151 |
|
---|
152 | }
|
---|
153 |
|
---|
154 | }
|
---|