source: trunk/src/SDPol.h @ 492

Last change on this file since 492 was 492, checked in by kil064, 19 years ago

add function polarizationLabel

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 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 C3+iC4 by phase (degrees)
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
165// is specified in the string from "I", "Q", "U", "V"
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
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]
185  template <class T>
186  static casa::Array<T> stokesData (casa::Array<T>& rawData, casa::Bool doLinear);
187
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
192// Find the Stokes type for the given polarization axis (0,1,2,3)
193// You can ask for STokes or raw correlations (linear or circular)
194   static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes,
195                                                  casa::Bool linear);
196
197// Return a label for the given polarization index (0-3).   
198   static casa::String polarizationLabel (casa::uInt polIdx, casa::Bool linear,
199                                          casa::Bool stokes, casa::Bool linPol);
200
201
202// These two functions are explicitly for the SDWriter
203//
204// Compute value for auxilliary spectra (Tsys and flags) when converting to Stokes parameters.
205// This combines the raw correlation values, according to what was combined
206// to actually convert to Stokes parameters.   The output shape may change from
207// the input shape according to
208// XX or YY          -> I             (1 -> 1)
209// XX,YY             -> I             (2 -> 1)
210// XX,YY,R(XY),I(XY) -> I,Q,U,V       (4 -> 4)
211//
212// The input array must be of shape [nChan,nPol]  (flags)
213// The input array must be of shape [nPol]        (tSys)
214//
215  static casa::Array<casa::uChar> computeStokesFlagsForWriter (casa::Array<casa::uChar>& rawData, casa::Bool doLinear)
216                                                         {return computeStokesDataForWriter(rawData,doLinear);};
217  static casa::Array<casa::Float> computeStokesTSysForWriter (casa::Array<casa::Float>& rawData, casa::Bool doLinear)
218                                                         {return computeStokesDataForWriter(rawData,doLinear);};
219
220// This function is explcitrly for SDWriter. It extracts the Beam and IF slice (specified in start
221// and end - must be length 1 in beam and IF) and flips the pol and channel axes.
222  static casa::Array<casa::Float> extractStokesForWriter (casa::Array<casa::Float>& in, const casa::IPosition& start,
223                                                          const casa::IPosition& end);
224
225private:
226// Return a label for the given StokesType
227   static casa::String stokesString (casa::Stokes::StokesTypes stokes);
228
229// specializations
230  static casa::Array<casa::Float> andArrays (const casa::Array<casa::Float>& in1,
231                                             const casa::Array<casa::Float>& in2)
232                                             {return (in1+in2)/casa::Float(2.0);}
233  static casa::Array<casa::Bool> andArrays (const casa::Array<casa::Bool>& in1,
234                                            const casa::Array<casa::Bool>& in2)
235                                            {return in1&&in2;}
236  static casa::Array<casa::uChar> andArrays (const casa::Array<casa::uChar>& in1,
237                                            const casa::Array<casa::uChar>& in2);
238 
239  template <class T>
240  static casa::Array<T> computeStokesDataForWriter (casa::Array<T>& rawData, casa::Bool doLinear);
241};
242
243
244
245
246
247} // namespace
248
249#endif
Note: See TracBrowser for help on using the repository browser.