source: trunk/src/STPolLinear.cpp @ 957

Last change on this file since 957 was 957, checked in by mar637, 18 years ago

Polarisation changes according to Ticket #8; Fix Ticket #10

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