source: trunk/src/SDPol.cc @ 419

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

classes to do some polarimetric processing
initially

SDPolUtil (conversion utilities)
SDStokesENgine (virtual STOKES column)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1//#---------------------------------------------------------------------------
2//# SDPol.cc: Polarimetric functionality
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
32#include "SDPol.h"
33
34#include <casa/Arrays/Array.h>
35#include <casa/Arrays/ArrayMath.h>
36#include <casa/Containers/Record.h>
37#include <casa/BasicSL/Constants.h>
38#include <casa/BasicSL/String.h>
39#include <casa/Utilities/Assert.h>
40
41#include <tables/Tables/Table.h>
42#include <tables/Tables/ScalarColumn.h>
43#include <tables/Tables/ArrayColumn.h>
44#include <tables/Tables/ColumnDesc.h>
45#include <tables/Tables/TableRecord.h>
46#include <tables/Tables/DataManError.h>
47
48
49using namespace casa;
50using namespace asap;
51
52
53
54SDStokesEngine::SDStokesEngine (const String& sourceColumnName,
55                           const String& targetColumnName)
56
57: BaseMappedArrayEngine<Float,Float> (sourceColumnName, targetColumnName)
58{}
59
60
61SDStokesEngine::SDStokesEngine (const Record& spec)
62: BaseMappedArrayEngine<Float,Float> ()
63{
64    if (spec.isDefined("SOURCENAME")  &&  spec.isDefined("TARGETNAME")) {
65        setNames (spec.asString("SOURCENAME"), spec.asString("TARGETNAME"));
66    }
67}
68
69SDStokesEngine::SDStokesEngine (const SDStokesEngine& that)
70: BaseMappedArrayEngine<Float,Float> (that)
71{}
72
73SDStokesEngine::~SDStokesEngine()
74{}
75
76
77DataManager* SDStokesEngine::clone() const
78{
79    DataManager* dmPtr = new SDStokesEngine (*this);
80    return dmPtr;
81}
82
83
84String SDStokesEngine::dataManagerType() const
85{
86    return className();
87}
88
89String SDStokesEngine::className()
90{
91    return "SDStokesEngine";
92}
93
94String SDStokesEngine::dataManagerName() const
95{
96    return sourceName();
97}
98
99Record SDStokesEngine::dataManagerSpec() const
100{
101    Record spec;
102    spec.define ("SOURCENAME", sourceName());
103    spec.define ("TARGETNAME", targetName());
104    return spec;
105}
106
107DataManager* SDStokesEngine::makeObject (const String&,
108                                                 const Record& spec)
109{
110    DataManager* dmPtr = new SDStokesEngine(spec);
111    return dmPtr;
112}
113
114
115void SDStokesEngine::registerClass()
116{
117    DataManager::registerCtor (className(), makeObject);
118}
119
120
121void SDStokesEngine::create (uInt initialNrrow)
122{
123    BaseMappedArrayEngine<Float,Float>::create (initialNrrow);
124}
125
126void SDStokesEngine::prepare()
127{
128    BaseMappedArrayEngine<Float,Float>::prepare();
129}
130
131Bool SDStokesEngine::canAccessArrayColumnCells (Bool& reask) const
132{
133    reask = False;
134    return True;
135}
136
137
138void SDStokesEngine::getArray (uInt rownr, Array<Float>& array)
139{
140    Array<Float> target(array.shape());
141    roColumn().get(rownr, target);
142//
143    computeOnGet (array, target);
144}
145
146void SDStokesEngine::putArray (uInt rownr, const Array<Float>& array)
147{
148    throw(AipsError("This Virtual Column is not writable"));
149}
150
151
152
153void SDStokesEngine::computeOnGet(Array<Float>& array,
154                                 const Array<Float>& target)
155//
156// array of shape (nBeam,nIF,nPol,nChan)
157//
158{
159   DebugAssert(target.ndim()==4,AipsError);
160   DebugAssert(array.ndim()==4,AipsError);
161
162// The silly Array slice operator does not give me back
163// a const reference so have to caste it away
164
165   Array<Float>& target2 = const_cast<Array<Float>&>(target);
166
167// uInt polAxis = asap::PolAxis;
168   uInt polAxis = 2;
169//
170   const uInt nDim = target.ndim();
171   IPosition start(nDim,0);
172   IPosition end(target.shape()-1);
173
174// Input slices
175
176   start(polAxis) = 0;
177   end(polAxis) = 0;
178   Array<Float> C1 = target2(start,end);
179//
180   start(polAxis) = 1;
181   end(polAxis) = 1;
182   Array<Float> C2 = target2(start,end);
183//
184   start(polAxis) = 2;
185   end(polAxis) = 2;
186   Array<Float> C3 = target2(start,end);
187//
188   start(polAxis) = 3;
189   end(polAxis) = 3;
190   Array<Float> C4 = target2(start,end);
191
192// Compute Output slices
193
194   start(polAxis) = 0;
195   end(polAxis) = 0;
196   Array<Float> I = array(start,end);
197   I = Float(0.5)*(C1 + C2);
198//
199   start(polAxis) = 1;
200   end(polAxis) = 1;
201   Array<Float> Q = array(start,end);
202   Q = Float(0.5)*(C1 - C2);
203//
204   start(polAxis) = 2;
205   end(polAxis) = 2;
206   Array<Float> U = array(start,end);
207   U = C3;
208//
209   start(polAxis) = 3;
210   end(polAxis) = 3;
211   Array<Float> V = array(start,end);
212   V = C4;
213}
214
215
216
217
218// SDPolUtil
219
220Array<Float> SDPolUtil::polarizedIntensity (const Array<Float>& Q,
221                                            const Array<Float>& U)
222{
223   Array<Float> t1 = pow(Q,Double(2.0));
224   Array<Float> t2 = pow(U,Double(2.0));
225   return sqrt(t1+t2);
226}
227
228
229Array<Float> SDPolUtil::positionAngle (const Array<Float>& Q,
230                                       const Array<Float>& U)
231{
232   return Float(180.0/C::pi/2.0)*atan2(Q,U);
233}
234
235
236void SDPolUtil::rotateXYPhase (Array<Float>& C3,
237                               Array<Float>& C4,
238                               Float phase)
239{
240   Float cosVal = cos(C::pi/180.0*phase);
241   Float sinVal = sin(C::pi/180.0*phase);
242//
243   C3 = C3*cosVal - C4*sinVal;
244   C4 = C3*sinVal + C4*cosVal;
245}
246
247
248 
Note: See TracBrowser for help on using the repository browser.