source: trunk/src/STPolLinear.cpp @ 904

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

Polarimetry handling and conversion

File size: 2.8 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
122}
Note: See TracBrowser for help on using the repository browser.