casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StokesUtil.h
Go to the documentation of this file.
1 //# StokesUtil.h:
2 //# Copyright (C) 1996,1999,2001
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 addressed 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 SYNTHESIS_STOKESUTIL_H
30 #define SYNTHESIS_STOKESUTIL_H
31 
32 
33 #include <casa/aips.h>
34 #include <casa/Arrays/Array.h>
36 
37 namespace casa { //# NAMESPACE CASA - BEGIN
38 
39 // <summary>
40 // for use with StokesVectors and related classes
41 // </summary>
42 
43 // <use visibility=export>
44 
45 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
46 // </reviewed>
47 
48 // <prerequisite> <li> StokesVector </prerequisite>
49 //
50 // <synopsis>
51 // Global Functions to operate on StokesVectors. Currently this includes
52 // functions to convert arrays from/to arrays of StokesVectors and some
53 // miscellaneous mathematical operations.
54 
55 // The {un,re}packStokes functions convert between an casacore::Array of StokesVector
56 // or CStokesvector into an casacore::Array of casacore::Float/casacore::Double or casacore::Complex/DComplex. The
57 // casacore::Float/casacore::Double array has one more dimension than the corresponding
58 // StokesVector array, and this extra dimension (always the slowest moving
59 // or last one) has a length of 4. The output array is always resized to the
60 // appropriate size.
61 
62 // The StokesVector comparison functions use the the "length" of the
63 // StokesVector (ie. sqrt(I^2+Q^2+U^2+V^2)) to make a comparison. In
64 // particular the abs() function returns the "length" of the
65 // StokesVector. It is called abs rather than say length() to allow
66 // StokesVectors to utilise other globals functions (like allNearAbs())
67 // which expect the absolute value function to be defined.
68 
69 // </synopsis>
70 //
71 // <motivation>
72 // g++ does not like templated and non-templated code in the same file. So
73 // the templated stuff was split off and put into this file. Later this
74 // became a convient place to put all the global functions, and the
75 // non-templated global functions are also defined here (and the
76 // implementation is put in a separate .cc file)
77 // </motivation>
78 //
79 //
80 // <thrown>
81 // <li> repackStokes()::AipsError
82 // </thrown>
83 //
84 // <todo asof="yyyy/mm/dd">
85 // <li> I am uncertain how efficient any of these functions are.
86 // </todo>
87 
88 // <linkfrom anchor="StokesVector ancillary functions" classes="StokesVector CStokesVector">
89 // <here>StokesVector ancillary functions</here> -- Ancillary functions
90 // used to manipulate StokesVector and related classes
91 // </linkfrom>
92 
93 
94 // <group name="StokesVector ancillary Functions">
95 // <group>
96 // Convert an casacore::Array of StokesVectors to an array of Floats or Doubles
97 // (depending on the templates). The same function can be used to convert an
98 // array of CStokesVectors to a casacore::Complex or casacore::DComplex Array. I have not
99 // tested if this works for other template types.
100 template<class T, class U> void
101 unpackStokes(casacore::Array<U>& output, const casacore::Array<T>& input);
102 
103 // Convert an casacore::Array of Floats or Doubles to an casacore::Array of StokesVectors. The
104 // same function can be used to convert a casacore::Complex/casacore::DComplex array to an array
105 // of CStokesVector. The last non-degenerate axis on the input array MUST be
106 // of length 4
107 template<class T, class U> void
108 repackStokes(casacore::Array<U>& output, const casacore::Array<T>& input);
109 // </group>
110 
111 // These Functions to multiply a StokesVector by an casacore::Array of Floats. The
112 // result is an casacore::Array of StokesVectors that is the same size as the casacore::Array of
113 // Floats with each polarization being the casacore::Array of floats multiplied by the
114 // corresponding component in the supplied StokesVector.
115 // <group>
117  const StokesVector & sv);
119  const casacore::Array<casacore::Float> & farray){
120  return farray*sv;
121 }
122 // </group>
123 
124 // Functions to compare stokesVectors with each other. They are all based on
125 // the norm derived using the "length" of the vector in 4-space.
126 // <group>
127 inline casacore::Float abs(const StokesVector& sv){
128  return sqrt(innerProduct(sv,sv));
129 }
130 
131 casacore::Bool operator>(const StokesVector& left,const StokesVector& right);
132 
133 inline casacore::Bool operator<(const StokesVector& left, const StokesVector& right){
134  return !(left>right);
135 }
136 
137 // </group>
138 
139 // Functions to determine if one StokesVector is near another
140 // <group>
141 casacore::Bool nearAbs(const StokesVector& val1, const StokesVector& val2,
142  casacore::Double tol = 1.0e-5);
143 
144 casacore::Bool near(const StokesVector& val1, const StokesVector& val2,
145  casacore::Double tol = 1.0e-5);
146 // </group>
147 
148 
149 // </group>
150 
151 } //# NAMESPACE CASA - END
152 
153 #ifndef AIPS_NO_TEMPLATE_SRC
154 #include <synthesis/MeasurementEquations/StokesUtil.tcc>
155 #endif //# AIPS_NO_TEMPLATE_SRC
156 #endif
bool nearAbs(const SpectralElement &s1, const SpectralElement &s2, const casacore::Double tol)
casacore::Bool operator<(const StokesVector &left, const StokesVector &right)
Definition: StokesUtil.h:133
CStokesVector operator*(const casacore::SquareMatrix< casacore::Complex, 4 > &m, const CStokesVector &v)
Multiplication of CStokesVector by a casacore::Complex SquareMatrix.
Definition: StokesVector.h:222
T innerProduct(const casacore::Vector< T > &x, const casacore::Vector< T > &y)
double Double
Definition: aipstype.h:55
LatticeExprNode sqrt(const LatticeExprNode &expr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
float Float
Definition: aipstype.h:54
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
LatticeExprNode operator>(const LatticeExprNode &left, const LatticeExprNode &right)
casacore::Float abs(const StokesVector &sv)
Functions to compare stokesVectors with each other.
Definition: StokesUtil.h:127
const Double e
e and functions thereof:
bool near(const SpectralElement &s1, const SpectralElement &s2, const casacore::Double tol)