source: branches/hpc34/src/STPolLinear.cpp@ 2582

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

Remove various compiler warnings

File size: 4.2 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 > 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 } else if (nspec() == 2) {
52 if ( index == 0 )
53 out = Vector<Float>(getSpectrum(0) + getSpectrum(1));
54 }
55 return out;
56}
57
58Vector<Float> asap::STPolLinear::getLinPol( uInt index )
59{
60 if (nspec() != 4) {
61 throw(AipsError("You must have 4 linear polarizations to run this function"));
62 }
63 if ( index >4 ) throw(AipsError("LinPol index out of range"));
64 Vector<Float> out,q,u;
65 if ( nspec() == 4) {
66 switch(index) {
67 case 1:
68 q = getStokes(1);
69 u = getStokes(2);
70 out = Vector<Float>(sqrt(pow(q,Float(2.0))+pow(u, Float(2.0))));
71 break;
72 case 2:
73 q = getStokes(1);
74 u = getStokes(2);
75 out = Vector<Float>(Float(180.0/C::pi/2.0) * atan2(u,q));
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
95 if (nspec() != 4) {
96 throw(AipsError("You must have 4 linear polarizations to run this function"));
97 }
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:
104 out = (I + V)/Float(2.0);
105 break;
106 case 1:
107 out = (I - V)/Float(2.0);
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
131 (void) phase;
132 if (nspec() != 4) {
133 throw(AipsError("You must have 4 linear polarizations to run this function"));
134 }
135 Matrix<Float>& specs = getSpectra();
136 Vector<Float> I = specs.column(3);
137 I *= Float(-1.0);
138}
139
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//
149 if (nspec() != 4) {
150 throw(AipsError("You must have 4 linear polarizations to run this function"));
151 }
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();
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);
166
167}
168
169}
Note: See TracBrowser for help on using the repository browser.