source: trunk/src/STPolLinear.cpp @ 911

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

added linpol rotation

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