source: trunk/src/SDContainer.cc @ 34

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

Added frequency information handling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 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
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.string()
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::putSpectrum(const Array<Float>& spec) {
90  spectrum_ = spec;
91}
92Bool SDContainer::putFlags(const Array<uChar>& flag) {
93  flags_ = flag;
94}
95Bool SDContainer::putTsys(const Array<Float>& tsys) {
96  tsys_ = tsys;
97}
98
99Bool SDContainer::setSpectrum(const Matrix<Float>& spec,
100                              uInt whichBeam, uInt whichIF) {
101
102  ArrayAccessor<Float, Axis<0> > aa0(spectrum_);
103  aa0.reset(aa0.begin(whichBeam));
104  ArrayAccessor<Float, Axis<1> > aa1(aa0);
105  aa1.reset(aa1.begin(whichIF));
106 
107  //Vector<Float> pols(nPol);
108  ArrayAccessor<Float, Axis<1> > j(spec);
109  IPosition shp0 = spectrum_.shape();
110  IPosition shp1 = spec.shape();
111  if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
112    cerr << "Arrays not conformant" << endl;     
113    return False;
114  }
115  // assert dimensions are the same....
116  for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
117    ArrayAccessor<Float, Axis<0> > jj(j);
118    for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) {
119      (*ii) = (*jj);
120      jj++;
121    }
122    j++;
123  }
124  // unset flags for this spectrum, they might be set again by the
125  // setFlags method
126
127  IPosition shp = flags_.shape();
128  IPosition start(4,whichBeam,whichIF,0,0);
129  IPosition end(4,whichBeam,whichIF,shp(2)-1,shp(3)-1);
130  Array<uChar> arr(flags_(start,end));
131  arr = uChar(0);
132}
133
134Bool SDContainer::setFlags(const Matrix<uChar>& flag,
135                           uInt whichBeam, uInt whichIF) {
136
137  ArrayAccessor<uChar, Axis<0> > aa0(flags_);
138  aa0.reset(aa0.begin(whichBeam));
139  ArrayAccessor<uChar, Axis<1> > aa1(aa0);
140  aa1.reset(aa1.begin(whichIF));
141 
142  ArrayAccessor<uChar, Axis<1> > j(flag);
143  IPosition shp0 = flags_.shape();
144  IPosition shp1 = flag.shape();
145  if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
146    cerr << "Arrays not conformant" << endl;     
147    return False;
148  }
149
150  // assert dimensions are the same....
151  for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) {
152    ArrayAccessor<uChar, Axis<0> > jj(j);
153    for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) {
154      (*ii) = (*jj);
155      jj++;
156    }
157    j++;
158  }
159  return True;
160}
161
162Bool SDContainer::setTsys(const Vector<Float>& tsys,
163                          uInt whichBeam, uInt whichIF) {
164  ArrayAccessor<Float, Axis<0> > aa0(tsys_);
165  aa0.reset(aa0.begin(whichBeam));
166  ArrayAccessor<Float, Axis<1> > aa1(aa0);
167  aa1.reset(aa1.begin(whichIF));
168  // assert dimensions are the same....
169  for (ArrayAccessor<Float, Axis<3> > i(aa1);i != i.end(); ++i) {   
170    ArrayAccessor<Float, Axis<0> > j(tsys);
171    for (ArrayAccessor<Float, Axis<2> > ii(i);ii != ii.end(); ++ii) {
172      (*ii) = (*j);
173      j++;
174    }
175  }
176}
177
178const Array<Float>& SDContainer::getSpectrum(uInt whichBeam, uInt whichIF) const {
179  Matrix<Float> spectra(nChan_, nPol_);
180
181  // Beam.
182  ArrayAccessor<Float, Axis<0> > i0(spectrum_);
183  i0.reset(i0.begin(whichBeam));
184
185  // IF.
186  ArrayAccessor<Float, Axis<1> > i1(i0);
187  i1.reset(i1.begin(whichIF));
188
189  // Polarization.
190  ArrayAccessor<Float, Axis<2> > i2(i1);
191  ArrayAccessor<Float, Axis<1> > o1(spectra);
192
193  while (i2 != i2.end()) {
194    // Channel.
195    ArrayAccessor<Float, Axis<3> > i3(i2);
196    ArrayAccessor<Float, Axis<0> > o0(o1);
197
198    while (i3 != i3.end()) {
199      *o0 = *i3;
200
201      i3++;
202      o0++;
203    }
204
205    i2++;
206    o1++;
207  }
208
209  return spectra;
210}
211
212const Array<uChar>& SDContainer::getFlags(uInt whichBeam, uInt whichIF) const
213{
214  Matrix<uChar> flagtra(nChan_, nPol_);
215
216  // Beam.
217  ArrayAccessor<uChar, Axis<0> > i0(flags_);
218  i0.reset(i0.begin(whichBeam));
219
220  // IF.
221  ArrayAccessor<uChar, Axis<1> > i1(i0);
222  i1.reset(i1.begin(whichIF));
223
224  // Polarization.
225  ArrayAccessor<uChar, Axis<2> > i2(i1);
226  ArrayAccessor<uChar, Axis<1> > o1(flagtra);
227
228  while (i2 != i2.end()) {
229    // Channel.
230    ArrayAccessor<uChar, Axis<3> > i3(i2);
231    ArrayAccessor<uChar, Axis<0> > o0(o1);
232
233    while (i3 != i3.end()) {
234      *o0 = *i3;
235
236      i3++;
237      o0++;
238    }
239
240    i2++;
241    o1++;
242  }
243
244  return flagtra;
245}
246
247const Array<Float>& SDContainer::getTsys(uInt whichBeam, uInt whichIF) const
248{
249  Vector<Float> tsys(nPol_);
250
251  // Beam.
252  ArrayAccessor<Float, Axis<0> > i0(tsys_);
253  i0.reset(i0.begin(whichBeam));
254
255  // IF.
256  ArrayAccessor<Float, Axis<1> > i1(i0);
257  i1.reset(i1.begin(whichIF));
258
259  // Channel.
260  ArrayAccessor<Float, Axis<3> > i3(i1);
261
262  // Polarization.
263  ArrayAccessor<Float, Axis<2> > i2(i3);
264  ArrayAccessor<Float, Axis<0> > o0(tsys);
265
266  while (i2 != i2.end()) {
267    *o0 = *i2;
268
269    i2++;
270    o0++;
271  }
272  return tsys;
273}
274
275Bool SDContainer::setFrequencyMap(uInt freqslot, uInt whichIF) {
276  freqidx_[whichIF] = freqslot;
277  return True;
278}
279
280Bool SDContainer::putFreqMap(const Vector<uInt>& freqs) {
281  freqidx_.resize();
282  freqidx_ = freqs;
283  return True;
284}
285
286Int SDFrequencyTable::addFrequency(Int refPix, Double refVal, Double inc) {
287  Int idx = -1;
288  Bool addit = False;
289  if (length() > 0) {
290    for (uInt i=0; i< length();++i) {
291      if ( refVal == refVal_[i] ) { // probably check with tolerance
292        if ( refPix == refPix_[i] )
293          if ( inc == increment_[i] )
294            idx = Int(i);
295      }
296    }
297    if (idx >= 0) {
298      return idx;
299    }
300  }
301  nFreq_ += 1;
302  refPix_.resize(nFreq_,True);
303  refVal_.resize(nFreq_,True);
304  increment_.resize(nFreq_,True);
305  refPix_[nFreq_-1] = refPix;
306  refVal_[nFreq_-1] = refVal;
307  increment_[nFreq_-1] = inc;
308  idx = nFreq_-1;
309  return idx;
310}
311
Note: See TracBrowser for help on using the repository browser.