casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StokesVector.h
Go to the documentation of this file.
1 //# StokesVector.h: A fast casacore::RigidVector with casacore::Stokes conversions
2 //# Copyright (C) 1996,1999,2001,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be adressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef MSVIS_STOKESVECTOR_H
30 #define MSVIS_STOKESVECTOR_H
31 
32 #include <casa/aips.h>
33 #include <casa/IO/AipsIO.h>
34 //#include <tables/Tables/TableRecord.h>
35 #include <casa/BasicSL/Complex.h>
36 #include <casa/Arrays/Vector.h>
37 #include <casa/Arrays/Matrix.h>
38 #include <casa/Arrays/MatrixMath.h>
41 #include <casa/Arrays/IPosition.h>
42 #include <casa/BasicMath/Math.h>
43 #include <casa/iostream.h>
44 
45 namespace casa { //# NAMESPACE CASA - BEGIN
46 
47 //# Forward Declarations
48 class StokesVector;
49 // <summary>
50 // Two specialized 4-vector classes for polarization handling
51 // </summary>
52 
53 // <use visibility=export>
54 
55 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
56 // </reviewed>
57 // <prerequisite>
58 // <li> RigidVector
59 // <li> Stokes
60 // </prerequisite>
61 //
62 // <etymology>
63 // StokesVector and CStokesVector (casacore::Complex StokesVector) are two classes
64 // designed to handle a 4-vector of polarization values (I,Q,U,V or
65 // e.g., RR,RL,LR,LL).
66 // </etymology>
67 //
68 // <synopsis>
69 // StokesVectors are RigidVectors of length 4. They have a few special
70 // member functions to do polarization conversions efficiently.
71 // CStokesVector also has a real() member function to get at the real
72 // part of the components.
73 // </synopsis>
74 //
75 // <example>
76 // <srcblock>
77 // // Create a real valued I,Q,U,V StokesVector
78 // StokesVector pixel(4.0,2.0,1.0,0.1);
79 // // convert to a casacore::Complex valued vector of linear polarizations
80 // CStokesVector cohVec=applySlin(pixel);
81 // // convert back to I,Q,U,V
82 // cohVec.applySlinInv();
83 // // Write out the real part
84 // cout<< cohVec.real() <<endl;
85 // </srcblock>
86 // </example>
87 //
88 // <motivation>
89 // Full polarization processing of interferometry data uses real and complex
90 // valued 4-vectors. The StokesVector specialization handles this more
91 // efficiently than a standard casacore::Vector of size 4.
92 // </motivation>
93 //
94 // <thrown>
95 // <li> No exceptions
96 // </thrown>
97 //
98 // <todo asof="1996/11/07">
99 // <li> we may want to add Stokesvector Eigenvalues
100 // </todo>
101 
102 
103 class CStokesVector:public casacore::RigidVector<casacore::Complex,4> {
104 public:
105 
106  static casacore::String dataTypeId() {return "CStokesVector";};
107  // CStokesVector(casacore::Int n):RigidVector<casacore::Complex,4>(n) {}
108  // The casacore::Complex data members are automatically initialized to 0.
110  // Construct from scalar, setting all values to a constant.
112  // Construct with four values specified.
114  const casacore::Complex& v2, const casacore::Complex& v3):
115  casacore::RigidVector<casacore::Complex,4>(v0,v1,v2,v3) {}
116  // Construct from c-array
118  // Construct from casacore::Vector (should have length 4)
119 // CStokesVector(const casacore::Vector<casacore::Complex> & v):RigidVector<casacore::Complex,4>(v) {}
120  // Copy constructor with copy semantics.
122  // Construct from RigidVector
123 // CStokesVector(const casacore::RigidVector<casacore::Complex,4>& v):RigidVector<casacore::Complex,4>(v) {}
124  // Assignment
127  }
128  // Assign from a Vector
131  }
132  // Assign from a scalar, setting all values to a constant
135  }
136  // Negation
139  }
140  // Addition
143  }
144  // Subtraction
147  }
150  }
151  // casacore::Matrix multiplication - v*=m is equivalent to v=m*v
154  }
156  v_p[0]*=f; v_p[1]*=f; v_p[2]*=f; v_p[3]*=f; return *this;
157  }
158  // Equality
160  return (v_p[0]==v.v_p[0] && v_p[1]==v.v_p[1] &&
161  v_p[2]==v.v_p[2] && v_p[3]==v.v_p[3]);
162  }
163  // Inequality
165  return (v_p[0]!=v.v_p[0] || v_p[1]!=v.v_p[1] ||
166  v_p[2]!=v.v_p[2] || v_p[3]!=v.v_p[3]);
167  }
168 
169  // Apply conversion matrix from casacore::Stokes to linear, in place.
171  casacore::Complex i=v_p[0],q=v_p[1], u=v_p[2],iv=v_p[3]*casacore::Complex(0,1);
172  v_p[0]=(i+q); v_p[1]=(u+iv);
173  v_p[2]=(u-iv); v_p[3]=(i-q);
174  return *this;
175  }
176  // Apply conversion matrix from casacore::Stokes to circular, in place
178  casacore::Complex i=v_p[0],q=v_p[1],iu=v_p[2]*casacore::Complex(0,1),v=v_p[3];
179  v_p[0]=(i+v); v_p[1]=(q+iu);
180  v_p[2]=(q-iu); v_p[3]=(i-v);
181  return *this;
182  }
183  // Apply conversion matrix from linear to casacore::Stokes, in place
185  using namespace casacore;
186  casacore::Complex xx=v_p[0],xy=v_p[1],yx=v_p[2],yy=v_p[3];
187  v_p[0]=(xx+yy)/2; v_p[1]=(xx-yy)/2;
188  v_p[2]=(xy+yx)/2; v_p[3]=casacore::Complex(0,1)*(yx-xy)/2;
189  return *this;
190  }
191  // Apply conversion matrix from circular to casacore::Stokes, in place
193  using namespace casacore;
194  casacore::Complex rr=v_p[0],rl=v_p[1],lr=v_p[2],ll=v_p[3];
195  v_p[0]=(rr+ll)/2; v_p[3]=(rr-ll)/2;
196  v_p[1]=(rl+lr)/2; v_p[2]=casacore::Complex(0,1)*(lr-rl)/2;
197  return *this;
198  }
199  // Return a StokesVector with the real part.
200 // StokesVector real();
201  // inner product of two complex vectors
203  const CStokesVector& r) {
204  return l.v_p[0]*conj(r.v_p[0])+ l.v_p[1]*conj(r.v_p[1])+
205  l.v_p[2]*conj(r.v_p[2])+ l.v_p[3]*conj(r.v_p[3]);
206  }
207  friend double norm(const CStokesVector& l) {
208  using namespace casacore;
209  return ::sqrt(square(l.v_p[0].real())+square(l.v_p[0].imag())+
210  square(l.v_p[1].real())+square(l.v_p[1].imag())+
211  square(l.v_p[2].real())+square(l.v_p[2].imag())+
212  square(l.v_p[3].real())+square(l.v_p[3].imag()));
213 }
214  // Write out a CStokesVector using the casacore::Vector output method.
215  friend std::ostream& operator<<(std::ostream& os, const CStokesVector& v) {
216  os << v.vector();
217  return os;
218  }
219 };
220 
221 // Multiplication of CStokesVector by a casacore::Complex SquareMatrix
223  const CStokesVector& v) {
224  CStokesVector result(v);
225  return result*=m;
226 }
227 
228 inline void defaultValue(CStokesVector& v) {
229  v=casacore::Complex(0.0,0.0);
230 }
231 
232 class StokesVector:public casacore::RigidVector<casacore::Float,4> {
233 
234 public:
235  static casacore::String dataTypeId() {return "StokesVector";};
236  // StokesVector(casacore::Int n):RigidVector<casacore::Float,4>(n) {}
237  // Default constructor zeroes vector.
239  // Construct from scalar, setting all values to a constant.
241  // Construct with four values specified.
243  // Construct from casacore::Vector (should have length 4)
244 // StokesVector(const casacore::Vector<casacore::Float> & v):RigidVector<casacore::Float,4>(v) {}
245  // Copy constructor with copy semantics.
247  // Construct from RigidVector
248 // StokesVector(const casacore::RigidVector<casacore::Float,4>& v):RigidVector<casacore::Float,4>(v) {}
249  // Assignment
252  }
253  // Assign from a Vector
256  }
257  // Assign from a scalar, setting all values to a constant
260  }
261  // Negation
264  }
265  // Addition
268  }
269  // Subtraction
272  }
275  }
278  }
279  // casacore::Matrix multiplication - v*=m is equivalent to v=m*v
282  }
283  // Equality
285  return (v_p[0]==v.v_p[0] && v_p[1]==v.v_p[1] &&
286  v_p[2]==v.v_p[2] && v_p[3]==v.v_p[3]);
287  }
288  // Inequality
290  return (v_p[0]!=v.v_p[0] || v_p[1]!=v.v_p[1] ||
291  v_p[2]!=v.v_p[2] || v_p[3]!=v.v_p[3]);
292  }
293  // Compute the maximum EigenValue
294  casacore::Float maxEigenValue() const;
295  // Compute the minimum EigenValue
296  casacore::Float minEigenValue() const;
297  // Compute the determinant of the coherence matrix
299 
300  // The innerproduct of 2 StokesVectors
302  return l.v_p[0]*r.v_p[0]+ l.v_p[1]*r.v_p[1]+
303  l.v_p[2]*r.v_p[2]+ l.v_p[3]*r.v_p[3];
304  }
305  // Write out a StokesVector using the casacore::Vector output method.
306  friend std::ostream& operator<<(std::ostream& os, const StokesVector& v) {
307  os << v.vector();
308  return os;
309  }
310 
311 };
312 
313 inline void defaultValue(StokesVector& v) {
314  v=0.0f;
315 }
316 
317 // Multiply by a scalar
319  StokesVector r(v);
320  return r*=f;
321 }
322 // Multiply by a scalar
324  StokesVector r(v);
325  return r*=f;
326 }
327 
328 // Multiplication of StokesVector by a SquareMatrix
330  const StokesVector& v) {
331  StokesVector result(v);
332  return result*=m;
333 }
334 
335 // Apply conversion matrix from casacore::Stokes to linear(returns result)
337  const StokesVector& v) {
339  result(0)=v(0)+v(1);
340  result(1)=v(2)+t;
341  result(2)=v(2)-t;
342  result(3)=v(0)-v(1);
343  return result;
344 }
345 // Apply conversion matrix from casacore::Stokes to linear.
347  CStokesVector result;
348  return applySlin(result,v);
349 }
350 // Apply conversion matrix from casacore::Stokes to circular.
352  const StokesVector& v) {
353  casacore::Complex t=casacore::Complex(0.,1.0)*v(2);
354  result(0)=v(0)+v(3);
355  result(1)=v(1)+t;
356  result(2)=v(1)-t;
357  result(3)=v(0)-v(3);
358  return result;
359 }
360 // Apply conversion matrix from casacore::Stokes to circular.
362  CStokesVector result;
363  return applyScirc(result,v);
364 }
365 
366 // Apply conversion matrix from linear to Stokes.
368  using namespace casacore;
369  result(0)=real(v(0)+v(3))/2;
370  result(1)=real(v(0)-v(3))/2;
371  result(2)=real(v(1)+v(2))/2;
372  result(3)=real(casacore::Complex(0.,1.0)*(v(2)-v(1))/2);
373  return result;
374 }
375 
376 // Apply conversion matrix from linear to Stokes.
378  StokesVector result;
379  return applySlinInv(result,v);
380 }
381 
382 // Apply conversion matrix from circular to Stokes.
384  using namespace casacore;
385  result(0)=real(v(0)+v(3))/2;
386  result(1)=real(v(1)+v(2))/2;
387  result(2)=real(casacore::Complex(0.,1.0)*(v(2)-v(1))/2);
388  result(3)=real(v(0)-v(3))/2;
389  return result;
390 }
391 
392 // Apply conversion matrix from circular to Stokes.
394  StokesVector result;
395  return applyScircInv(result,v);
396 }
397 
398 // The following are needed until Image no longer has
399 // sigma images
400 //StokesVector& sqrt(const StokesVector& v);
401 
402 //CStokesVector& sqrt(const CStokesVector& v);
403 
404 
405 } //# NAMESPACE CASA - END
406 
407 #endif
StokesVector()
StokesVector(casacore::Int n):RigidVector&lt;casacore::Float,4&gt;(n) {} Default constructor zeroes vector...
Definition: StokesVector.h:238
StokesVector & operator*=(const StokesVector &v)
Definition: StokesVector.h:276
CStokesVector & operator=(const casacore::Vector< casacore::Complex > &v)
Assign from a Vector.
Definition: StokesVector.h:129
CStokesVector & applySlin()
Apply conversion matrix from casacore::Stokes to linear, in place.
Definition: StokesVector.h:170
CStokesVector(const casacore::Complex v[4])
Construct from c-array.
Definition: StokesVector.h:117
Two specialized 4-vector classes for polarization handling.
Definition: StokesVector.h:103
CStokesVector & operator=(const CStokesVector &v)
Construct from RigidVector CStokesVector(const casacore::RigidVector&lt;casacore::Complex,4&gt;&amp; v):RigidVector&lt;casacore::Complex,4&gt;(v) {} Assignment.
Definition: StokesVector.h:125
casacore::Bool operator!=(const StokesVector &v) const
Inequality.
Definition: StokesVector.h:289
CStokesVector & operator-()
Negation.
Definition: StokesVector.h:137
friend casacore::Float innerProduct(const StokesVector &l, const StokesVector &r)
The innerproduct of 2 StokesVectors.
Definition: StokesVector.h:301
CStokesVector & operator*=(const casacore::SquareMatrix< casacore::Complex, 4 > &m)
casacore::Matrix multiplication - v*=m is equivalent to v=m*v
Definition: StokesVector.h:152
friend casacore::Complex operator*(const RigidVector< casacore::Complex, n > &l, const RigidVector< casacore::Complex, n > &r)
The innerproduct of 2 RigidVectors.
Definition: RigidVector.h:118
CStokesVector(const casacore::Complex &v0, const casacore::Complex &v1, const casacore::Complex &v2, const casacore::Complex &v3)
Construct with four values specified.
Definition: StokesVector.h:113
StokesVector(casacore::Float v0, casacore::Float v1, casacore::Float v2, casacore::Float v3)
Construct with four values specified.
Definition: StokesVector.h:242
CStokesVector & operator=(const casacore::Complex &c)
Assign from a scalar, setting all values to a constant.
Definition: StokesVector.h:133
RigidVector< T, n > & operator=(const RigidVector< T, n > &v)
Assign from a RigidVector.
Definition: RigidVector.h:194
StokesVector & operator-=(const StokesVector &v)
Subtraction.
Definition: StokesVector.h:270
friend std::ostream & operator<<(std::ostream &os, const CStokesVector &v)
Write out a CStokesVector using the casacore::Vector output method.
Definition: StokesVector.h:215
RigidVector< T, n > & operator+=(const RigidVector< T, n > &v)
Addition.
Definition: RigidVector.h:214
CStokesVector()
CStokesVector(casacore::Int n):RigidVector&lt;casacore::Complex,4&gt;(n) {} The casacore::Complex data memb...
Definition: StokesVector.h:109
StokesVector & operator+=(const StokesVector &v)
Addition.
Definition: StokesVector.h:266
CStokesVector & operator+=(const CStokesVector &v)
Addition.
Definition: StokesVector.h:141
CStokesVector & applyScirc()
Apply conversion matrix from casacore::Stokes to circular, in place.
Definition: StokesVector.h:177
LatticeExprNode conj(const LatticeExprNode &expr)
Fast Vector classes with fixed (templated) length.
friend casacore::Complex innerProduct(const CStokesVector &l, const CStokesVector &r)
Return a StokesVector with the real part.
Definition: StokesVector.h:202
StokesVector & operator=(const StokesVector &v)
Construct from RigidVector StokesVector(const casacore::RigidVector&lt;casacore::Float,4&gt;&amp; v):RigidVector&lt;casacore::Float,4&gt;(v) {} Assignment.
Definition: StokesVector.h:250
casacore::Bool operator==(const CStokesVector &v) const
Equality.
Definition: StokesVector.h:159
Fast Square Matrix class with fixed (templated) size.
T determinant(const casacore::Matrix< T > &A)
The determinant of a matrix; Note: The LU decomposition of the matrix is a hidden calculation; ...
friend std::ostream & operator<<(std::ostream &os, const StokesVector &v)
Write out a StokesVector using the casacore::Vector output method.
Definition: StokesVector.h:306
static casacore::String dataTypeId()
Definition: StokesVector.h:235
StokesVector(casacore::Float f)
Construct from scalar, setting all values to a constant.
Definition: StokesVector.h:240
LatticeExprNode sqrt(const LatticeExprNode &expr)
CStokesVector & operator-=(const CStokesVector &v)
Subtraction.
Definition: StokesVector.h:145
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Vector< T > vector() const
Convert to a regular Vector.
Definition: RigidVector.h:242
StokesVector & operator=(casacore::Float f)
Assign from a scalar, setting all values to a constant.
Definition: StokesVector.h:258
RigidVector< T, n > & operator*=(const RigidVector< T, n > &v)
Definition: RigidVector.h:218
casacore::Complex v_p[n]
// The following are needed for Image&lt;RigidVector&gt;
Definition: RigidVector.h:267
CStokesVector & operator*=(const CStokesVector &v)
Definition: StokesVector.h:148
StokesVector & operator-()
Negation.
Definition: StokesVector.h:262
float Float
Definition: aipstype.h:54
casacore::Bool operator!=(const CStokesVector &v) const
Inequality.
Definition: StokesVector.h:164
casacore::Bool operator==(const StokesVector &v) const
Equality.
Definition: StokesVector.h:284
CStokesVector & operator*=(casacore::Float f)
Definition: StokesVector.h:155
StokesVector & operator*=(casacore::Float f)
Definition: StokesVector.h:273
StokesVector(const StokesVector &v)
Construct from casacore::Vector (should have length 4) StokesVector(const casacore::Vector&lt;casacore::...
Definition: StokesVector.h:246
friend double norm(const CStokesVector &l)
Definition: StokesVector.h:207
CStokesVector & applySlinInv()
Apply conversion matrix from linear to casacore::Stokes, in place.
Definition: StokesVector.h:184
RigidVector< T, n > & operator-=(const RigidVector< T, n > &v)
Subtraction.
Definition: RigidVector.h:223
CStokesVector(const CStokesVector &v)
Construct from casacore::Vector (should have length 4) CStokesVector(const casacore::Vector&lt;casacore:...
Definition: StokesVector.h:121
const Double c
Fundamental physical constants (SI units):
TableExprNode square(const TableExprNode &node)
Definition: ExprNode.h:1303
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void defaultValue(CStokesVector &v)
Definition: StokesVector.h:228
static casacore::String dataTypeId()
Definition: StokesVector.h:106
StokesVector & operator=(const casacore::Vector< casacore::Float > &v)
Assign from a Vector.
Definition: StokesVector.h:254
LatticeExprNode real(const LatticeExprNode &expr)
CStokesVector(const casacore::Complex &c)
Construct from scalar, setting all values to a constant.
Definition: StokesVector.h:111
RigidVector< T, n > & operator-()
Negation.
Definition: RigidVector.h:209
StokesVector & operator*=(const casacore::SquareMatrix< casacore::Float, 4 > &m)
casacore::Matrix multiplication - v*=m is equivalent to v=m*v
Definition: StokesVector.h:280
CStokesVector & applyScircInv()
Apply conversion matrix from circular to casacore::Stokes, in place.
Definition: StokesVector.h:192
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42