[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 | |
---|
| 19 | using namespace casa; |
---|
| 20 | |
---|
| 21 | namespace asap { |
---|
| 22 | |
---|
| 23 | Factory<STPol,STPolLinear> STPolLinear::myFactory; |
---|
| 24 | |
---|
| 25 | STPolLinear::~STPolLinear() |
---|
| 26 | { |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | Vector<Float> asap::STPolLinear::getStokes( uint index ) |
---|
| 31 | { |
---|
| 32 | if ( index < 0 || index >4 ) throw(AipsError("Stokes index out of range")); |
---|
| 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: |
---|
[957] | 42 | out = Vector<Float>(q * cos(phase) - getSpectrum(2) * sin(phase)); |
---|
[904] | 43 | break; |
---|
[957] | 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; |
---|
[904] | 51 | } |
---|
| 52 | } |
---|
| 53 | return out; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | Vector<Float> asap::STPolLinear::getLinPol( uInt index ) |
---|
| 57 | { |
---|
| 58 | if ( index < 0 || index >4 ) throw(AipsError("LinPol index out of range")); |
---|
[957] | 59 | Vector<Float> out,q,u; |
---|
[904] | 60 | if ( nspec() == 4) { |
---|
| 61 | switch(index) { |
---|
| 62 | case 1: |
---|
[957] | 63 | q = getStokes(1); |
---|
| 64 | u = getStokes(2); |
---|
| 65 | out = Vector<Float>(sqrt(pow(q,Float(2.0))+pow(u, Float(2.0)))); |
---|
[904] | 66 | break; |
---|
| 67 | case 2: |
---|
| 68 | q = getStokes(index); |
---|
[957] | 69 | u = getStokes(2); |
---|
| 70 | out = Vector<Float>(Float(180.0/C::pi/2.0) * atan2(u,q)); |
---|
[904] | 71 | break; |
---|
| 72 | default: |
---|
| 73 | out = getStokes(index); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | return out; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | Vector<Float> asap::STPolLinear::getLinear(uInt index ) |
---|
| 80 | { |
---|
| 81 | return getSpectrum(index); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | Vector<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: |
---|
[957] | 97 | out = (I + V); |
---|
[904] | 98 | break; |
---|
| 99 | case 1: |
---|
[957] | 100 | out = (I - V); |
---|
[904] | 101 | break; |
---|
| 102 | default: |
---|
| 103 | out = Vector<Float>(); |
---|
| 104 | } |
---|
| 105 | return out; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | void 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 | |
---|
| 121 | void 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 | |
---|
[911] | 129 | void 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 | |
---|
[904] | 153 | } |
---|
[911] | 154 | |
---|
| 155 | } |
---|