source: trunk/src/SDContainer.cc@ 117

Last change on this file since 117 was 104, checked in by mar637, 20 years ago

added azimuth,elevation,parangle,refbeam,fieldname,tcal,tcaltime

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
RevLine 
[2]1//#---------------------------------------------------------------------------
2//# SDContainer.cc: A container class for single dish integrations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# Malte Marquarding, 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//#---------------------------------------------------------------------------
[104]31#include <casa/Exceptions.h>
[81]32#include <tables/Tables/Table.h>
33#include <casa/Arrays/IPosition.h>
34#include <casa/Arrays/ArrayAccessor.h>
35#include <casa/Arrays/Matrix.h>
36#include <casa/Quanta/MVTime.h>
[2]37
38#include "SDContainer.h"
39
[83]40using namespace asap;
[2]41
[18]42void SDHeader::print() const {
43 MVTime mvt(this->utc);
[47]44 mvt.setFormat(MVTime::YMD);
[18]45 cout << "Observer: " << this->observer << endl
46 << "Project: " << this->project << endl
47 << "Obstype: " << this->obstype << endl
48 << "Antenna: " << this->antennaname << endl
49 << "Ant. Position: " << this->antennaposition << endl
50 << "Equinox: " << this->equinox << endl
51 << "Freq. ref.: " << this->freqref << endl
52 << "Ref. frequency: " << this->reffreq << endl
53 << "Bandwidth: " << this->bandwidth << endl
54 << "Time (utc): "
[47]55 << mvt
[18]56 << endl;
57 //setprecision(10) << this->utc << endl;
58}
59
60
[16]61SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nPol, uInt nChan)
[2]62 : nBeam_(nBeam),
[16]63 nIF_(nIF),
64 nPol_(nPol),
65 nChan_(nChan),
66 spectrum_(IPosition(4,nBeam,nIF,nPol,nChan)),
67 flags_(IPosition(4,nBeam,nIF,nPol,nChan)),
[34]68 tsys_(IPosition(4,nBeam,nIF,nPol,nChan)),
[79]69 freqidx_(nIF),
70 direction_(IPosition(2,nBeam,2)) {
[2]71 uChar x = 0;
72 flags_ = ~x;
[104]73 tcal.resize(2);
[2]74}
75
[16]76SDContainer::SDContainer(IPosition shp)
77 : nBeam_(shp(0)),
78 nIF_(shp(1)),
79 nPol_(shp(2)),
80 nChan_(shp(3)),
81 spectrum_(shp),
82 flags_(shp),
[34]83 tsys_(shp),
[79]84 freqidx_(shp(1)) {
85 IPosition ip(2,shp(0),2);
86 direction_.resize(ip);
[16]87 uChar x = 0;
88 flags_ = ~x;
[104]89 tcal.resize(2);
[16]90}
91
[2]92SDContainer::~SDContainer() {
93}
94
[47]95Bool SDContainer::resize(IPosition shp) {
96 nBeam_ = shp(0);
97 nIF_ = shp(1);
98 nPol_ = shp(2);
99 nChan_ = shp(3);
100 spectrum_.resize(shp);
101 flags_.resize(shp);
102 tsys_.resize(shp);
103 freqidx_.resize(shp(1));
[79]104 IPosition ip(2,shp(0),2);
105 direction_.resize(ip);
[47]106}
107
[2]108Bool SDContainer::putSpectrum(const Array<Float>& spec) {
109 spectrum_ = spec;
110}
[7]111Bool SDContainer::putFlags(const Array<uChar>& flag) {
112 flags_ = flag;
[2]113}
[7]114Bool SDContainer::putTsys(const Array<Float>& tsys) {
115 tsys_ = tsys;
[2]116}
117
118Bool SDContainer::setSpectrum(const Matrix<Float>& spec,
119 uInt whichBeam, uInt whichIF) {
120
121 ArrayAccessor<Float, Axis<0> > aa0(spectrum_);
122 aa0.reset(aa0.begin(whichBeam));
123 ArrayAccessor<Float, Axis<1> > aa1(aa0);
124 aa1.reset(aa1.begin(whichIF));
125
[14]126 //Vector<Float> pols(nPol);
[16]127 ArrayAccessor<Float, Axis<1> > j(spec);
[14]128 IPosition shp0 = spectrum_.shape();
129 IPosition shp1 = spec.shape();
[16]130 if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
[104]131 throw(AipsError("Arrays not conformant"));
[14]132 return False;
133 }
[2]134 // assert dimensions are the same....
135 for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
[16]136 ArrayAccessor<Float, Axis<0> > jj(j);
[2]137 for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) {
[14]138 (*ii) = (*jj);
139 jj++;
[2]140 }
[14]141 j++;
[2]142 }
143 // unset flags for this spectrum, they might be set again by the
144 // setFlags method
[14]145
[2]146 IPosition shp = flags_.shape();
147 IPosition start(4,whichBeam,whichIF,0,0);
148 IPosition end(4,whichBeam,whichIF,shp(2)-1,shp(3)-1);
149 Array<uChar> arr(flags_(start,end));
150 arr = uChar(0);
151}
152
153Bool SDContainer::setFlags(const Matrix<uChar>& flag,
154 uInt whichBeam, uInt whichIF) {
155
156 ArrayAccessor<uChar, Axis<0> > aa0(flags_);
157 aa0.reset(aa0.begin(whichBeam));
158 ArrayAccessor<uChar, Axis<1> > aa1(aa0);
159 aa1.reset(aa1.begin(whichIF));
160
[16]161 ArrayAccessor<uChar, Axis<1> > j(flag);
[14]162 IPosition shp0 = flags_.shape();
163 IPosition shp1 = flag.shape();
[16]164 if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
[14]165 cerr << "Arrays not conformant" << endl;
166 return False;
167 }
168
[2]169 // assert dimensions are the same....
170 for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) {
[16]171 ArrayAccessor<uChar, Axis<0> > jj(j);
[2]172 for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) {
[14]173 (*ii) = (*jj);
174 jj++;
[2]175 }
[14]176 j++;
[2]177 }
[16]178 return True;
[2]179}
180
181Bool SDContainer::setTsys(const Vector<Float>& tsys,
182 uInt whichBeam, uInt whichIF) {
183 ArrayAccessor<Float, Axis<0> > aa0(tsys_);
184 aa0.reset(aa0.begin(whichBeam));
185 ArrayAccessor<Float, Axis<1> > aa1(aa0);
186 aa1.reset(aa1.begin(whichIF));
187 // assert dimensions are the same....
[16]188 for (ArrayAccessor<Float, Axis<3> > i(aa1);i != i.end(); ++i) {
[14]189 ArrayAccessor<Float, Axis<0> > j(tsys);
[16]190 for (ArrayAccessor<Float, Axis<2> > ii(i);ii != ii.end(); ++ii) {
[14]191 (*ii) = (*j);
192 j++;
[7]193 }
194 }
[2]195}
[27]196
[67]197Array<Float> SDContainer::getSpectrum(uInt whichBeam, uInt whichIF) const {
[27]198 Matrix<Float> spectra(nChan_, nPol_);
199
200 // Beam.
201 ArrayAccessor<Float, Axis<0> > i0(spectrum_);
202 i0.reset(i0.begin(whichBeam));
203
204 // IF.
205 ArrayAccessor<Float, Axis<1> > i1(i0);
206 i1.reset(i1.begin(whichIF));
207
208 // Polarization.
209 ArrayAccessor<Float, Axis<2> > i2(i1);
210 ArrayAccessor<Float, Axis<1> > o1(spectra);
211
212 while (i2 != i2.end()) {
213 // Channel.
214 ArrayAccessor<Float, Axis<3> > i3(i2);
215 ArrayAccessor<Float, Axis<0> > o0(o1);
216
217 while (i3 != i3.end()) {
218 *o0 = *i3;
219
220 i3++;
221 o0++;
222 }
223
224 i2++;
225 o1++;
226 }
227
[67]228 return spectra.copy();
[27]229}
230
[67]231Array<uChar> SDContainer::getFlags(uInt whichBeam, uInt whichIF) const
[27]232{
233 Matrix<uChar> flagtra(nChan_, nPol_);
234
235 // Beam.
236 ArrayAccessor<uChar, Axis<0> > i0(flags_);
237 i0.reset(i0.begin(whichBeam));
238
239 // IF.
240 ArrayAccessor<uChar, Axis<1> > i1(i0);
241 i1.reset(i1.begin(whichIF));
242
243 // Polarization.
244 ArrayAccessor<uChar, Axis<2> > i2(i1);
245 ArrayAccessor<uChar, Axis<1> > o1(flagtra);
246
247 while (i2 != i2.end()) {
248 // Channel.
249 ArrayAccessor<uChar, Axis<3> > i3(i2);
250 ArrayAccessor<uChar, Axis<0> > o0(o1);
251
252 while (i3 != i3.end()) {
253 *o0 = *i3;
254
255 i3++;
256 o0++;
257 }
258
259 i2++;
260 o1++;
261 }
262
[67]263 return flagtra.copy();
[27]264}
265
[67]266Array<Float> SDContainer::getTsys(uInt whichBeam, uInt whichIF) const
[27]267{
268 Vector<Float> tsys(nPol_);
269
270 // Beam.
271 ArrayAccessor<Float, Axis<0> > i0(tsys_);
272 i0.reset(i0.begin(whichBeam));
273
274 // IF.
275 ArrayAccessor<Float, Axis<1> > i1(i0);
276 i1.reset(i1.begin(whichIF));
277
278 // Channel.
279 ArrayAccessor<Float, Axis<3> > i3(i1);
280
281 // Polarization.
282 ArrayAccessor<Float, Axis<2> > i2(i3);
283 ArrayAccessor<Float, Axis<0> > o0(tsys);
284
285 while (i2 != i2.end()) {
286 *o0 = *i2;
287
288 i2++;
289 o0++;
290 }
[67]291 return tsys.copy();
[27]292}
[34]293
[79]294Array<Double> SDContainer::getDirection(uInt whichBeam) const {
295 Vector<Double> direct(2);
296 ArrayAccessor<Double, Axis<0> > i0(direction_);
297 i0.reset(i0.begin(whichBeam));
298 ArrayAccessor<Double, Axis<0> > o0(direct);
299 ArrayAccessor<Double, Axis<1> > i1(i0);
300 while (i1 != i1.end()) {
301 *o0 = *i1;
302 i1++;
303 o0++;
304 }
305 return direct.copy();
306}
307
308
[34]309Bool SDContainer::setFrequencyMap(uInt freqslot, uInt whichIF) {
310 freqidx_[whichIF] = freqslot;
311 return True;
312}
313
314Bool SDContainer::putFreqMap(const Vector<uInt>& freqs) {
315 freqidx_.resize();
316 freqidx_ = freqs;
317 return True;
318}
319
[79]320Bool SDContainer::setDirection(const Vector<Double>& point, uInt whichBeam) {
321 if (point.nelements() != 2) return False;
322 ArrayAccessor<Double, Axis<0> > aa0(direction_);
323 aa0.reset(aa0.begin(whichBeam));
324 ArrayAccessor<Double, Axis<0> > jj(point);
325 for (ArrayAccessor<Double, Axis<1> > i(aa0);i != i.end(); ++i) {
326
327 (*i) = (*jj);
328 jj++;
329 }
330 return True;
331}
332
333Bool SDContainer::putDirection(const Array<Double>& dir) {
334 direction_.resize();
335 direction_ = dir;
336 return True;
337}
338
[34]339Int SDFrequencyTable::addFrequency(Int refPix, Double refVal, Double inc) {
340 Int idx = -1;
341 Bool addit = False;
342 if (length() > 0) {
343 for (uInt i=0; i< length();++i) {
344 if ( refVal == refVal_[i] ) { // probably check with tolerance
345 if ( refPix == refPix_[i] )
346 if ( inc == increment_[i] )
347 idx = Int(i);
348 }
349 }
350 if (idx >= 0) {
351 return idx;
352 }
353 }
354 nFreq_ += 1;
355 refPix_.resize(nFreq_,True);
356 refVal_.resize(nFreq_,True);
357 increment_.resize(nFreq_,True);
358 refPix_[nFreq_-1] = refPix;
359 refVal_[nFreq_-1] = refVal;
360 increment_[nFreq_-1] = inc;
361 idx = nFreq_-1;
362 return idx;
363}
364
Note: See TracBrowser for help on using the repository browser.