source: trunk/src/SDContainer.cc@ 62

Last change on this file since 62 was 47, checked in by mmarquar, 20 years ago

Added resize function.

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