source: trunk/src/SDPol.h @ 459

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

make templatyed function SDPolUtil::stokesData to handle stokesMask
and stokesTsys calculation. Delete the non-templated versions.

In SDStokesEngone track interface changes in Table system (some bug fixes for me)

Mo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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 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 specfied 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 STokes parameters by combining the raw correlation values
176// The output shape may change from the input shape according to
177// XX or YY          -> I
178// XX,YY             -> I
179// XX,YY,R(XY),I(XY) -> I,Q,U,V
180// Bool for mask
181// Float for TSys
182  template <class T>
183  static casa::Array<T> stokesData (casa::Array<T>& rawData, casa::Bool doLinear);
184 
185
186// Find the Stokes type for the given polarization axis (0,1,2,3)
187// You can ask for STokes or raw correltions (linear or circular)
188   static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes,
189                                                  casa::Bool linear);
190
191private:
192  static casa::Array<casa::Float> andArrays (const casa::Array<casa::Float>& in1,
193                                             const casa::Array<casa::Float>& in2)
194                                             {return (in1+in2)/casa::Float(2.0);}
195
196  static casa::Array<casa::Bool> andArrays (const casa::Array<casa::Bool>& in1,
197                                            const casa::Array<casa::Bool>& in2)
198                                            {return in1&&in2;}
199};
200
201
202
203
204
205} // namespace
206
207#endif
Note: See TracBrowser for help on using the repository browser.