source: trunk/src/SDContainer.cc@ 127

Last change on this file since 127 was 125, checked in by mar637, 20 years ago

Moved to casa namespace.
Adjusted the copyright to be ATNF.

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