source: branches/Release-2-fixes/src/SDPol.h@ 2639

Last change on this file since 2639 was 501, checked in by kil064, 20 years ago

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1//#---------------------------------------------------------------------------
2//# SDPol.h: Polarimetric processing
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# ATNF
6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31#ifndef SDPOL_H
32#define SDPOL_H
33
34//# Includes
35#include <casa/aips.h>
36#include <casa/Arrays/Array.h>
37#include <casa/Arrays/ArrayMath.h>
38#include <casa/Arrays/ArrayLogical.h>
39#include <measures/Measures/Stokes.h>
40#include <tables/Tables/BaseMappedArrayEngine.h>
41
42
43namespace asap {
44
45class SDStokesEngine : public casa::BaseMappedArrayEngine<casa::Float, casa::Float>
46{
47 //# Make members of parent class known.
48public:
49 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::virtualName;
50protected:
51 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::storedName;
52 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::table;
53 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::roColumn;
54 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::rwColumn;
55
56public:
57 // Construct engine. The sourveColumnName holds the XX,YY,R(XY),I(XY)
58 // correlations
59 SDStokesEngine (const casa::String& virtualColumnName,
60 const casa::String& sourceColumnName);
61
62 // Construct from a record specification as created by getmanagerSpec().
63 SDStokesEngine (const casa::Record& spec);
64
65 // Destructor is mandatory.
66 ~SDStokesEngine();
67
68 // Return the type name of the engine (i.e. its class name).
69 virtual casa::String dataManagerType() const;
70
71 // Get the name given to the engine (is the source column name).
72 virtual casa::String dataManagerName() const;
73
74 // casa::Record a casa::Record containing data manager specifications.
75 virtual casa::Record dataManagerSpec() const;
76
77 // Return the name of the class.
78 // This includes the names of the template arguments.
79 static casa::String className();
80
81 // The engine can access column cells.
82 virtual casa::Bool canAccessArrayColumnCells (casa::Bool& reask) const;
83
84 // Register the class name and the static makeObject "constructor".
85 // This will make the engine known to the table system.
86 // The automatically invoked registration function in DataManReg.cc
87 // contains SDStokesEngine
88 // Any other instantiation of this class must be registered "manually"
89 // (or added to DataManReg.cc).
90 static void registerClass();
91
92 // Non writable
93// virtual casa::Bool isWritable () const {return casa::False;}
94
95private:
96 // Copy constructor is only used by clone().
97 // (so it is made private).
98 SDStokesEngine (const SDStokesEngine&);
99
100 // Assignment is not needed and therefore forbidden
101 // (so it is made private and not implemented).
102 SDStokesEngine& operator=(const SDStokesEngine&);
103
104 // Clone the engine object.
105 DataManager* clone() const;
106
107 // Initialize the object for a new table.
108 // It defines the keywords containing the engine parameters.
109 void create (casa::uInt initialNrrow);
110
111 // Preparing consists of setting the writable switch and
112 // adding the initial number of rows in case of create.
113 // Furthermore it reads the keywords containing the engine parameters.
114 void prepare();
115
116 // Get an array in the given row.
117 void getArray (casa::uInt rownr, casa::Array<casa::Float>& array);
118
119 // Exception
120 void putArray (casa::uInt rownr, const casa::Array<casa::Float>& array);
121
122 // Compute Stokes parameters
123 void computeOnGet (casa::Array<casa::Float>& array,
124 const casa::Array<casa::Float>& target);
125
126 // Get shape
127 virtual casa::IPosition shape (casa::uInt rownr);
128
129 // Convert input to output (virtual) shape
130 casa::IPosition findOutputShape (const casa::IPosition& inputShape) const;
131
132
133public:
134 //*display 4
135 // Define the "constructor" to construct this engine when a
136 // table is read back.
137 // This "constructor" has to be registered by the user of the engine.
138 // If the engine is commonly used, its registration can be added
139 // to the registerAllCtor function in DataManReg.cc.
140 // That function gets automatically invoked by the table system.
141 static DataManager* makeObject (const casa::String& dataManagerType,
142 const casa::Record& spec);
143};
144
145
146
147class SDPolUtil
148{
149 public:
150// Convert Q and U to linearly polarized intensity
151 static casa::Array<casa::Float> polarizedIntensity (const casa::Array<casa::Float>& Q,
152 const casa::Array<casa::Float>& U);
153// Convert Q and U to linearly polarized position angle (degrees)
154 static casa::Array<casa::Float> positionAngle (const casa::Array<casa::Float>& Q,
155 const casa::Array<casa::Float>& U);
156
157 // Rotate phase of Complex correlation R+iI by phase (degrees)
158 static void rotatePhase (casa::Array<casa::Float>& R,
159 casa::Array<casa::Float>& I,
160 casa::Float phase);
161
162 // Rotate phase of P=(Q+iU) by phase (degrees), but do this by applying
163 // the corrections to the raw linear polarizations
164 static void rotateLinPolPhase (casa::Array<casa::Float>& C1,
165 casa::Array<casa::Float>& C2,
166 casa::Array<casa::Float>& C3,
167 casa::Array<casa::Float>& I,
168 casa::Array<casa::Float>& Q,
169 casa::Array<casa::Float>& U,
170 casa::Float phase);
171
172// Get Stokes slices from the Array. Start and End should
173// already be setup to access the Array at the current cursor location
174// (beam, IF, Pol; see SDMemTable). The desired Stokes
175// is specified in the string from "I", "Q", "U", "V"
176 static casa::Array<casa::Float> getStokesSlice (casa::Array<casa::Float>& input, const casa::IPosition& start,
177 const casa::IPosition& end, const casa::String& stokes);
178
179// Compute Circular polarization RR or LL from I and V
180 static casa::Array<casa::Float> circularPolarizationFromStokes (casa::Array<casa::Float>& I,
181 casa::Array<casa::Float>& V,
182 casa::Bool doRR);
183
184
185// Compute value for auxilliary spectra when converting to Stokes parameters.
186// This combines the raw correlation values, according to what was combined
187// to actually convert to Stokes parameters. The output shape may change from
188// the input shape according to
189// XX or YY -> I (1 -> 1)
190// XX,YY -> I (2 -> 1)
191// XX,YY,R(XY),I(XY) -> I,Q,U,V (4 -> 4)
192//
193// It is meant for tSys (FLoat) and masks (Bool or uChar)
194// The input array must be of shape [nBeam,nIF,nPol,nChan]
195 template <class T>
196 static casa::Array<T> stokesData (casa::Array<T>& rawData, casa::Bool doLinear);
197
198// Find the number of STokes parameters given the input number
199// of raw polarizations
200 static casa::uInt numberStokes (casa::uInt nPol) {casa::uInt nOut = nPol; if (nPol==2) nOut = 1; return nOut;};
201
202// Find the Stokes type for the given polarization axis (0,1,2,3)
203// You can ask for STokes or raw correlations (linear or circular)
204 static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes,
205 casa::Bool linear);
206
207// Return a label for the given polarization index (0-3).
208 static casa::String polarizationLabel (casa::uInt polIdx, casa::Bool linear,
209 casa::Bool stokes, casa::Bool linPol);
210
211
212// These two functions are explicitly for the SDWriter
213//
214// Compute value for auxilliary spectra (Tsys and flags) when converting to Stokes parameters.
215// This combines the raw correlation values, according to what was combined
216// to actually convert to Stokes parameters. The output shape may change from
217// the input shape according to
218// XX or YY -> I (1 -> 1)
219// XX,YY -> I (2 -> 1)
220// XX,YY,R(XY),I(XY) -> I,Q,U,V (4 -> 4)
221//
222// The input array must be of shape [nChan,nPol] (flags)
223// The input array must be of shape [nPol] (tSys)
224//
225 static casa::Array<casa::uChar> computeStokesFlagsForWriter (casa::Array<casa::uChar>& rawData, casa::Bool doLinear)
226 {return computeStokesDataForWriter(rawData,doLinear);};
227 static casa::Array<casa::Float> computeStokesTSysForWriter (casa::Array<casa::Float>& rawData, casa::Bool doLinear)
228 {return computeStokesDataForWriter(rawData,doLinear);};
229
230// This function is explicitly for SDWriter. It extracts the Beam and IF slice (specified in start
231// and end - must be length 1 in beam and IF) and flips the pol and channel axes.
232 static casa::Array<casa::Float> extractStokesForWriter (casa::Array<casa::Float>& in, const casa::IPosition& start,
233 const casa::IPosition& end);
234
235private:
236// Return a label for the given StokesType
237 static casa::String stokesString (casa::Stokes::StokesTypes stokes);
238
239// specializations
240 static casa::Array<casa::Float> andArrays (const casa::Array<casa::Float>& in1,
241 const casa::Array<casa::Float>& in2)
242 {return (in1+in2)/casa::Float(2.0);}
243 static casa::Array<casa::Bool> andArrays (const casa::Array<casa::Bool>& in1,
244 const casa::Array<casa::Bool>& in2)
245 {return in1&&in2;}
246 static casa::Array<casa::uChar> andArrays (const casa::Array<casa::uChar>& in1,
247 const casa::Array<casa::uChar>& in2);
248
249 template <class T>
250 static casa::Array<T> computeStokesDataForWriter (casa::Array<T>& rawData, casa::Bool doLinear);
251};
252
253
254
255
256
257} // namespace
258
259#endif
Note: See TracBrowser for help on using the repository browser.