source: trunk/src/SDPol.h@ 476

Last change on this file since 476 was 469, checked in by kil064, 20 years ago

new functions for the SDWriter to handle Stokes output
for SDFITS / MS. This is bit of a mess...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
RevLine 
[419]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>
[459]37#include <casa/Arrays/ArrayMath.h>
38#include <casa/Arrays/ArrayLogical.h>
[446]39#include <measures/Measures/Stokes.h>
[419]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:
[459]49 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::virtualName;
[419]50protected:
[459]51 using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::storedName;
[419]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:
[427]57 // Construct engine. The sourveColumnName holds the XX,YY,R(XY),I(XY)
58 // correlations
59 SDStokesEngine (const casa::String& virtualColumnName,
[459]60 const casa::String& sourceColumnName);
[419]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
[437]92 // Non writable
[438]93// virtual casa::Bool isWritable () const {return casa::False;}
[437]94
[419]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
[427]119 // Exception
[419]120 void putArray (casa::uInt rownr, const casa::Array<casa::Float>& array);
121
[427]122 // Compute Stokes parameters
[419]123 void computeOnGet (casa::Array<casa::Float>& array,
124 const casa::Array<casa::Float>& target);
125
[437]126 // Get shape
[427]127 virtual casa::IPosition shape (casa::uInt rownr);
[419]128
[437]129 // Convert input to output (virtual) shape
[427]130 casa::IPosition findOutputShape (const casa::IPosition& inputShape) const;
131
132
[419]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
[459]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
[469]157 // Rotate phase of Complex correlation C3+iC4 by phase (degrees)
[459]158 static void rotateXYPhase (casa::Array<casa::Float>& C3,
159 casa::Array<casa::Float>& C4,
160 casa::Float phase);
161
162// Get Stokes slices from the Array. Start and End should
163// already be setup to access the Array at the current cursor location
164// (beam, IF, Pol; see SDMemTable). The desired Stokes
[469]165// is specified in the string from "I", "Q", "U", "V"
[459]166 static casa::Array<casa::Float> getStokesSlice (casa::Array<casa::Float>& input, const casa::IPosition& start,
167 const casa::IPosition& end, const casa::String& stokes);
168
169// Compute Circular polarization RR or LL from I and V
170 static casa::Array<casa::Float> circularPolarizationFromStokes (casa::Array<casa::Float>& I,
171 casa::Array<casa::Float>& V,
172 casa::Bool doRR);
173
174
[469]175// Compute value for auxilliary spectra when converting to Stokes parameters.
176// This combines the raw correlation values, according to what was combined
177// to actually convert to Stokes parameters. The output shape may change from
178// the input shape according to
179// XX or YY -> I (1 -> 1)
180// XX,YY -> I (2 -> 1)
181// XX,YY,R(XY),I(XY) -> I,Q,U,V (4 -> 4)
182//
183// It is meant for tSys (FLoat) and masks (Bool or uChar)
184// The input array must be of shape [nBeam,nIF,nPol,nChan]
[459]185 template <class T>
186 static casa::Array<T> stokesData (casa::Array<T>& rawData, casa::Bool doLinear);
187
[469]188// Find the number of STokes parameters given the input number
189// of raw polarizations
190 static casa::uInt numberStokes (casa::uInt nPol) {casa::uInt nOut = nPol; if (nPol==2) nOut = 1; return nOut;};
191
[459]192// Find the Stokes type for the given polarization axis (0,1,2,3)
[469]193// You can ask for STokes or raw correlations (linear or circular)
[459]194 static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes,
195 casa::Bool linear);
196
[469]197
198// These two functions are explicitly for the SDWriter
199//
200// Compute value for auxilliary spectra (Tsys and flags) when converting to Stokes parameters.
201// This combines the raw correlation values, according to what was combined
202// to actually convert to Stokes parameters. The output shape may change from
203// the input shape according to
204// XX or YY -> I (1 -> 1)
205// XX,YY -> I (2 -> 1)
206// XX,YY,R(XY),I(XY) -> I,Q,U,V (4 -> 4)
207//
208// The input array must be of shape [nChan,nPol] (flags)
209// The input array must be of shape [nPol] (tSys)
210//
211 static casa::Array<casa::uChar> computeStokesFlagsForWriter (casa::Array<casa::uChar>& rawData, casa::Bool doLinear)
212 {return computeStokesDataForWriter(rawData,doLinear);};
213 static casa::Array<casa::Float> computeStokesTSysForWriter (casa::Array<casa::Float>& rawData, casa::Bool doLinear)
214 {return computeStokesDataForWriter(rawData,doLinear);};
215
216// This function is explcitrly for SDWriter. It extracts the Beam and IF slice (specified in start
217// and end - must be length 1 in beam and IF) and flips the pol and channel axes.
218 static casa::Array<casa::Float> extractStokesForWriter (casa::Array<casa::Float>& in, const casa::IPosition& start,
219 const casa::IPosition& end);
220
[459]221private:
222 static casa::Array<casa::Float> andArrays (const casa::Array<casa::Float>& in1,
223 const casa::Array<casa::Float>& in2)
224 {return (in1+in2)/casa::Float(2.0);}
225
226 static casa::Array<casa::Bool> andArrays (const casa::Array<casa::Bool>& in1,
227 const casa::Array<casa::Bool>& in2)
228 {return in1&&in2;}
[469]229 static casa::Array<casa::uChar> andArrays (const casa::Array<casa::uChar>& in1,
230 const casa::Array<casa::uChar>& in2);
231
232 template <class T>
233 static casa::Array<T> computeStokesDataForWriter (casa::Array<T>& rawData, casa::Bool doLinear);
[459]234};
235
236
237
238
239
[419]240} // namespace
241
242#endif
Note: See TracBrowser for help on using the repository browser.