source: trunk/src/STPolLinear.cpp@ 2456

Last change on this file since 2456 was 2163, checked in by Malte Marquarding, 14 years ago

Remove various compiler warnings

File size: 4.2 KB
RevLine 
[904]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{
[2163]32 if ( index > 4 ) throw(AipsError("Stokes index out of range"));
[904]33 Vector<Float> out;
[957]34 Float phase = getTotalPhase();
35 Vector<Float> q(getSpectrum(0) - getSpectrum(1));
[904]36 if ( nspec() == 4 ) {
37 switch(index) {
38 case 0:
[957]39 out = Vector<Float>(getSpectrum(0) + getSpectrum(1));
[904]40 break;
41 case 1:
[1007]42 out = Vector<Float>(q * cos(phase) - Float(2.0)*getSpectrum(2) * sin(phase));
[904]43 break;
[957]44 case 2:
[1007]45 out = Vector<Float>(q * sin(phase) + Float(2.0)*getSpectrum(2) * cos(phase));
[957]46 break;
47 case 3:
[1007]48 out = getFeedHand() * Float(2.0) * Vector<Float>(getSpectrum(3));
[957]49 break;
[904]50 }
[1189]51 } else if (nspec() == 2) {
52 if ( index == 0 )
53 out = Vector<Float>(getSpectrum(0) + getSpectrum(1));
[904]54 }
55 return out;
56}
57
58Vector<Float> asap::STPolLinear::getLinPol( uInt index )
59{
[1189]60 if (nspec() != 4) {
61 throw(AipsError("You must have 4 linear polarizations to run this function"));
62 }
[2163]63 if ( index >4 ) throw(AipsError("LinPol index out of range"));
[957]64 Vector<Float> out,q,u;
[904]65 if ( nspec() == 4) {
66 switch(index) {
67 case 1:
[957]68 q = getStokes(1);
69 u = getStokes(2);
70 out = Vector<Float>(sqrt(pow(q,Float(2.0))+pow(u, Float(2.0))));
[904]71 break;
72 case 2:
[965]73 q = getStokes(1);
[957]74 u = getStokes(2);
75 out = Vector<Float>(Float(180.0/C::pi/2.0) * atan2(u,q));
[904]76 break;
77 default:
78 out = getStokes(index);
79 }
80 }
81 return out;
82}
83
84Vector<Float> asap::STPolLinear::getLinear(uInt index )
85{
86 return getSpectrum(index);
87}
88
89Vector<Float> asap::STPolLinear::getCircular(uInt index )
90{
91 // convert to stokes I/ V first
92 //
93 // We use the convention
94 // I = (RR+LL) // definition changed
[1189]95 if (nspec() != 4) {
96 throw(AipsError("You must have 4 linear polarizations to run this function"));
97 }
[904]98 if ( index == 2 || index ==3 ) throw(AipsError("Re/Imag RL not implemented"));
99 Vector<Float> I,V,out;
100 I = getStokes(0);
101 V = getStokes(3);
102 switch(index) {
103 case 0:
[1007]104 out = (I + V)/Float(2.0);
[904]105 break;
106 case 1:
[1007]107 out = (I - V)/Float(2.0);
[904]108 break;
109 default:
110 out = Vector<Float>();
111 }
112 return out;
113}
114
115void asap::STPolLinear::rotatePhase( Float phase )
116{
117 if (nspec() != 4) {
118 throw(AipsError("You must have 4 linear polarizations to run this function"));
119 }
120 Float cosVal = cos(C::pi/180.0*phase);
121 Float sinVal = sin(C::pi/180.0*phase);
122 Matrix<Float>& specs = getSpectra();
123 Vector<Float> R2 = specs.column(2)*cosVal - specs.column(3)*sinVal;
124 specs.column(3) = specs.column(2)*sinVal + specs.column(3)*cosVal;
125 specs.column(2) = R2;
126}
127
128void asap::STPolLinear::invertPhase( Float phase )
129{
130 // phase isnt used, just ro keep interface the same for all pol operations
[2163]131 (void) phase;
[1189]132 if (nspec() != 4) {
133 throw(AipsError("You must have 4 linear polarizations to run this function"));
134 }
[904]135 Matrix<Float>& specs = getSpectra();
136 Vector<Float> I = specs.column(3);
137 I *= Float(-1.0);
138}
139
[911]140void asap::STPolLinear::rotateLinPolPhase( casa::Float phase )
141{
142//
143// Rotate P = Q + iU but do it directly on the linear
144// correlations.
145//
146// We are using I=(XX+YY)/2 convention
147// C1 = XX; C2 = YY, C3 = Real(XY)
148//
[1189]149 if (nspec() != 4) {
150 throw(AipsError("You must have 4 linear polarizations to run this function"));
151 }
[911]152 Vector<Float> I,Q,U;
153 I = getStokes(0);
154 Q = getStokes(1);
155 U = getStokes(2);
156 // Rotate Q & U (factor of 2 for polarization)
157 Float cosVal = cos(C::pi/180.0*2.0*phase);
158 Float sinVal = sin(C::pi/180.0*2.0*phase);
159 Vector<Float> Q2 = Q*cosVal - U*sinVal;
160 U = Q*sinVal + U*cosVal;
161 Q = Q2;
162 Matrix<Float>& specs = getSpectra();
[1007]163 specs.column(0) = (I+Q)/Float(2.0);
164 specs.column(1) = (I-Q)/Float(2.0);
165 specs.column(2) = U/Float(2.0);
[911]166
[904]167}
[911]168
169}
Note: See TracBrowser for help on using the repository browser.