source: trunk/src/SDPol.cc@ 427

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

Now handle 1,2 or 4 input polarizations in SDStokesEngine

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
RevLine 
[419]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"
[427]33#include "SDDefs.h"
[419]34
35#include <casa/Arrays/Array.h>
36#include <casa/Arrays/ArrayMath.h>
37#include <casa/Containers/Record.h>
38#include <casa/BasicSL/Constants.h>
39#include <casa/BasicSL/String.h>
40#include <casa/Utilities/Assert.h>
41
42#include <tables/Tables/Table.h>
43#include <tables/Tables/ScalarColumn.h>
44#include <tables/Tables/ArrayColumn.h>
45#include <tables/Tables/ColumnDesc.h>
46#include <tables/Tables/TableRecord.h>
47#include <tables/Tables/DataManError.h>
48
49
50using namespace casa;
51using namespace asap;
52
53
54
[427]55SDStokesEngine::SDStokesEngine (const String& outputColumnName,
56 const String& inputColumnName)
57: BaseMappedArrayEngine<Float,Float> (outputColumnName, inputColumnName)
[419]58{}
59
60
61SDStokesEngine::SDStokesEngine (const Record& spec)
62: BaseMappedArrayEngine<Float,Float> ()
63{
[427]64 if (spec.isDefined("OUTPUTNAME") && spec.isDefined("INPUTNAME")) {
65 setNames (spec.asString("OUTPUTNAME"), spec.asString("INPUTNAME"));
[419]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;
[427]102 spec.define ("OUTPUTNAME", sourceName()); // Ger uses opposite meaning for source/target
103 spec.define ("INPUTNAME", targetName());
[419]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
[427]138void SDStokesEngine::getArray (uInt rownr, Array<Float>& output)
[419]139{
[427]140 IPosition inputShape = findInputShape (output.shape());
141 Array<Float> input(inputShape);
142 roColumn().get(rownr, input);
[419]143//
[427]144 computeOnGet (output, input);
[419]145}
146
[427]147void SDStokesEngine::putArray (uInt rownr, const Array<Float>& input)
[419]148{
149 throw(AipsError("This Virtual Column is not writable"));
150}
151
152
153
[427]154void SDStokesEngine::setShape (uInt rownr, const IPosition& outputShape)
155{
156 BaseMappedArrayEngine<Float,Float>::setShape (rownr, findInputShape(outputShape));
157}
158
159void SDStokesEngine::setShapeColumn (const IPosition& outputShape)
160{
161 BaseMappedArrayEngine<Float,Float>::setShapeColumn (findInputShape(outputShape));
162}
163
164
165IPosition SDStokesEngine::shape (uInt rownr)
166{
167 IPosition inputShape = roColumn().shape (rownr);
168 return findOutputShape(inputShape);
169}
170
171
172
173void SDStokesEngine::computeOnGet(Array<Float>& output,
174 const Array<Float>& input)
[419]175//
176// array of shape (nBeam,nIF,nPol,nChan)
177//
178{
[427]179
180// Checks
181
182 const uInt nDim = input.ndim();
183 DebugAssert(nDim==4,AipsError);
[419]184 DebugAssert(array.ndim()==4,AipsError);
[427]185 const IPosition inputShape = input.shape();
186 const uInt polAxis = asap::PolAxis;
187 const uInt nPol = inputShape(polAxis);
188 DebugAssert(nPol==1 || nPol==2 || nPol==3, AipsError);
[419]189
190// The silly Array slice operator does not give me back
191// a const reference so have to caste it away
192
[427]193 Array<Float>& input2 = const_cast<Array<Float>&>(input);
[419]194
[427]195// Slice coordnates
196
[419]197 IPosition start(nDim,0);
[427]198 IPosition end(input.shape()-1);
[419]199
[427]200// Generate Slices
[419]201
202 start(polAxis) = 0;
203 end(polAxis) = 0;
[427]204 Array<Float> C1 = input2(start,end); // Input : C1
[419]205//
[427]206 start(polAxis) = 0;
207 end(polAxis) = 0;
208 Array<Float> I = output(start,end); // Output : I
209//
210 if (nPol==1) {
211 I = C1;
212 return;
213 }
214//
[419]215 start(polAxis) = 1;
216 end(polAxis) = 1;
[427]217 Array<Float> C2 = input2(start,end); // Input : C1
[419]218//
[427]219 I = Float(0.5)*(C1 + C2);
220 if (nPol <= 2) return;
221//
[419]222 start(polAxis) = 2;
223 end(polAxis) = 2;
[427]224 Array<Float> C3 = input2(start,end); // Input : C3
[419]225//
226 start(polAxis) = 3;
227 end(polAxis) = 3;
[427]228 Array<Float> C4 = input2(start,end); // Input : C4
[419]229//
230 start(polAxis) = 1;
231 end(polAxis) = 1;
[427]232 Array<Float> Q = output(start,end); // Output : Q
[419]233 Q = Float(0.5)*(C1 - C2);
234//
235 start(polAxis) = 2;
236 end(polAxis) = 2;
[427]237 Array<Float> U = output(start,end); // Output : U
[419]238 U = C3;
239//
240 start(polAxis) = 3;
241 end(polAxis) = 3;
[427]242 Array<Float> V = output(start,end); // Output : V
[419]243 V = C4;
244}
245
246
247
[427]248IPosition SDStokesEngine::findInputShape (const IPosition& outputShape) const
249//
250// Don't know how to handle the degeneracy that both
251// XX -> I
252// XX,YY -> I
253//
254{
255 uInt axis = asap::PolAxis;
256 uInt nPol = outputShape(axis);
257 IPosition inputShape = outputShape;
258 if (nPol==1) {
259 inputShape(axis) = 2; // XX YY -> I
260 } else if (nPol==4) {
261 inputShape(axis) = 4; // XX YY R(XY) I(XY) -> I Q U V
262 }
263 return inputShape;
264}
[419]265
[427]266IPosition SDStokesEngine::findOutputShape (const IPosition& inputShape) const
267{
268 uInt axis = 2;
269 uInt nPol = inputShape(axis);
270 IPosition outputShape = inputShape;
271 if (nPol==1) {
272 outputShape(axis) = 1; // XX -> I
273 } else if (nPol==2) {
274 outputShape(axis) = 1; // XX YY -> I
275 } else if (nPol==4) {
276 outputShape(axis) = 4; // XX YY R(XY) I(XY) -> I Q U V
277 }
278 return outputShape;
279}
280
281
282
[419]283// SDPolUtil
284
285Array<Float> SDPolUtil::polarizedIntensity (const Array<Float>& Q,
286 const Array<Float>& U)
287{
288 Array<Float> t1 = pow(Q,Double(2.0));
289 Array<Float> t2 = pow(U,Double(2.0));
290 return sqrt(t1+t2);
291}
292
293
294Array<Float> SDPolUtil::positionAngle (const Array<Float>& Q,
295 const Array<Float>& U)
296{
[426]297 return Float(180.0/C::pi/2.0)*atan2(Q,U); // Degrees
[419]298}
299
300
301void SDPolUtil::rotateXYPhase (Array<Float>& C3,
302 Array<Float>& C4,
303 Float phase)
304{
305 Float cosVal = cos(C::pi/180.0*phase);
306 Float sinVal = sin(C::pi/180.0*phase);
307//
308 C3 = C3*cosVal - C4*sinVal;
309 C4 = C3*sinVal + C4*cosVal;
310}
311
312
313
Note: See TracBrowser for help on using the repository browser.