source: trunk/src/STPolLinear.cpp@ 1156

Last change on this file since 1156 was 1007, checked in by mar637, 19 years ago

Fixed computiaons of stokes and back after discussions with Jim Caswell.

File size: 3.7 KB
Line 
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
19using namespace casa;
20
21namespace asap {
22
23Factory<STPol,STPolLinear> STPolLinear::myFactory;
24
25STPolLinear::~STPolLinear()
26{
27}
28
29
30Vector<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) - Float(2.0)*getSpectrum(2) * sin(phase));
43 break;
44 case 2:
45 out = Vector<Float>(q * sin(phase) + Float(2.0)*getSpectrum(2) * cos(phase));
46 break;
47 case 3:
48 out = getFeedHand() * Float(2.0) * Vector<Float>(getSpectrum(3));
49 break;
50 }
51 }
52 return out;
53}
54
55Vector<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(1);
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
78Vector<Float> asap::STPolLinear::getLinear(uInt index )
79{
80 return getSpectrum(index);
81}
82
83Vector<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)/Float(2.0);
97 break;
98 case 1:
99 out = (I - V)/Float(2.0);
100 break;
101 default:
102 out = Vector<Float>();
103 }
104 return out;
105}
106
107void 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
120void 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
128void 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)/Float(2.0);
149 specs.column(1) = (I-Q)/Float(2.0);
150 specs.column(2) = U/Float(2.0);
151
152}
153
154}
Note: See TracBrowser for help on using the repository browser.