[2] | 1 | //#---------------------------------------------------------------------------
|
---|
| 2 | //# SDContainer.cc: A container class for single dish integrations
|
---|
| 3 | //#---------------------------------------------------------------------------
|
---|
| 4 | //# Copyright (C) 2004
|
---|
[125] | 5 | //# ATNF
|
---|
[2] | 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 | //#---------------------------------------------------------------------------
|
---|
[125] | 31 | #include <casa/aips.h>
|
---|
[104] | 32 | #include <casa/Exceptions.h>
|
---|
[81] | 33 | #include <tables/Tables/Table.h>
|
---|
| 34 | #include <casa/Arrays/IPosition.h>
|
---|
[125] | 35 | #include <casa/Arrays/Matrix.h>
|
---|
[81] | 36 | #include <casa/Arrays/ArrayAccessor.h>
|
---|
| 37 | #include <casa/Quanta/MVTime.h>
|
---|
[2] | 38 |
|
---|
| 39 | #include "SDContainer.h"
|
---|
| 40 |
|
---|
[125] | 41 | using namespace casa;
|
---|
[83] | 42 | using namespace asap;
|
---|
[2] | 43 |
|
---|
[18] | 44 | void SDHeader::print() const {
|
---|
| 45 | MVTime mvt(this->utc);
|
---|
[47] | 46 | mvt.setFormat(MVTime::YMD);
|
---|
[18] | 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): "
|
---|
[47] | 57 | << mvt
|
---|
[18] | 58 | << endl;
|
---|
| 59 | //setprecision(10) << this->utc << endl;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
[16] | 63 | SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nPol, uInt nChan)
|
---|
[2] | 64 | : nBeam_(nBeam),
|
---|
[16] | 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)),
|
---|
[34] | 70 | tsys_(IPosition(4,nBeam,nIF,nPol,nChan)),
|
---|
[79] | 71 | freqidx_(nIF),
|
---|
| 72 | direction_(IPosition(2,nBeam,2)) {
|
---|
[2] | 73 | uChar x = 0;
|
---|
| 74 | flags_ = ~x;
|
---|
[104] | 75 | tcal.resize(2);
|
---|
[2] | 76 | }
|
---|
| 77 |
|
---|
[16] | 78 | SDContainer::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),
|
---|
[34] | 85 | tsys_(shp),
|
---|
[79] | 86 | freqidx_(shp(1)) {
|
---|
| 87 | IPosition ip(2,shp(0),2);
|
---|
| 88 | direction_.resize(ip);
|
---|
[16] | 89 | uChar x = 0;
|
---|
| 90 | flags_ = ~x;
|
---|
[104] | 91 | tcal.resize(2);
|
---|
[16] | 92 | }
|
---|
| 93 |
|
---|
[2] | 94 | SDContainer::~SDContainer() {
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[47] | 97 | Bool 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));
|
---|
[79] | 106 | IPosition ip(2,shp(0),2);
|
---|
| 107 | direction_.resize(ip);
|
---|
[47] | 108 | }
|
---|
| 109 |
|
---|
[2] | 110 | Bool SDContainer::putSpectrum(const Array<Float>& spec) {
|
---|
| 111 | spectrum_ = spec;
|
---|
| 112 | }
|
---|
[7] | 113 | Bool SDContainer::putFlags(const Array<uChar>& flag) {
|
---|
| 114 | flags_ = flag;
|
---|
[2] | 115 | }
|
---|
[7] | 116 | Bool SDContainer::putTsys(const Array<Float>& tsys) {
|
---|
| 117 | tsys_ = tsys;
|
---|
[2] | 118 | }
|
---|
| 119 |
|
---|
| 120 | Bool 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 |
|
---|
[14] | 128 | //Vector<Float> pols(nPol);
|
---|
[16] | 129 | ArrayAccessor<Float, Axis<1> > j(spec);
|
---|
[14] | 130 | IPosition shp0 = spectrum_.shape();
|
---|
| 131 | IPosition shp1 = spec.shape();
|
---|
[16] | 132 | if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
|
---|
[104] | 133 | throw(AipsError("Arrays not conformant"));
|
---|
[14] | 134 | return False;
|
---|
| 135 | }
|
---|
[2] | 136 | // assert dimensions are the same....
|
---|
| 137 | for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
|
---|
[16] | 138 | ArrayAccessor<Float, Axis<0> > jj(j);
|
---|
[2] | 139 | for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) {
|
---|
[14] | 140 | (*ii) = (*jj);
|
---|
| 141 | jj++;
|
---|
[2] | 142 | }
|
---|
[14] | 143 | j++;
|
---|
[2] | 144 | }
|
---|
| 145 | // unset flags for this spectrum, they might be set again by the
|
---|
| 146 | // setFlags method
|
---|
[14] | 147 |
|
---|
[2] | 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 |
|
---|
| 155 | Bool 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 |
|
---|
[16] | 163 | ArrayAccessor<uChar, Axis<1> > j(flag);
|
---|
[14] | 164 | IPosition shp0 = flags_.shape();
|
---|
| 165 | IPosition shp1 = flag.shape();
|
---|
[16] | 166 | if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
|
---|
[14] | 167 | cerr << "Arrays not conformant" << endl;
|
---|
| 168 | return False;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[2] | 171 | // assert dimensions are the same....
|
---|
| 172 | for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) {
|
---|
[16] | 173 | ArrayAccessor<uChar, Axis<0> > jj(j);
|
---|
[2] | 174 | for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) {
|
---|
[14] | 175 | (*ii) = (*jj);
|
---|
| 176 | jj++;
|
---|
[2] | 177 | }
|
---|
[14] | 178 | j++;
|
---|
[2] | 179 | }
|
---|
[16] | 180 | return True;
|
---|
[2] | 181 | }
|
---|
| 182 |
|
---|
| 183 | Bool 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....
|
---|
[16] | 190 | for (ArrayAccessor<Float, Axis<3> > i(aa1);i != i.end(); ++i) {
|
---|
[14] | 191 | ArrayAccessor<Float, Axis<0> > j(tsys);
|
---|
[16] | 192 | for (ArrayAccessor<Float, Axis<2> > ii(i);ii != ii.end(); ++ii) {
|
---|
[14] | 193 | (*ii) = (*j);
|
---|
| 194 | j++;
|
---|
[7] | 195 | }
|
---|
| 196 | }
|
---|
[2] | 197 | }
|
---|
[27] | 198 |
|
---|
[125] | 199 | Array<Float> SDContainer::getSpectrum(uInt whichBeam, uInt whichIF) const
|
---|
| 200 | {
|
---|
[27] | 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 |
|
---|
[67] | 231 | return spectra.copy();
|
---|
[27] | 232 | }
|
---|
| 233 |
|
---|
[125] | 234 |
|
---|
[67] | 235 | Array<uChar> SDContainer::getFlags(uInt whichBeam, uInt whichIF) const
|
---|
[27] | 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 |
|
---|
[67] | 267 | return flagtra.copy();
|
---|
[27] | 268 | }
|
---|
| 269 |
|
---|
[67] | 270 | Array<Float> SDContainer::getTsys(uInt whichBeam, uInt whichIF) const
|
---|
[27] | 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 | }
|
---|
[67] | 295 | return tsys.copy();
|
---|
[27] | 296 | }
|
---|
[34] | 297 |
|
---|
[79] | 298 | Array<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 |
|
---|
[34] | 313 | Bool SDContainer::setFrequencyMap(uInt freqslot, uInt whichIF) {
|
---|
| 314 | freqidx_[whichIF] = freqslot;
|
---|
| 315 | return True;
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | Bool SDContainer::putFreqMap(const Vector<uInt>& freqs) {
|
---|
| 319 | freqidx_.resize();
|
---|
| 320 | freqidx_ = freqs;
|
---|
| 321 | return True;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[79] | 324 | Bool 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 |
|
---|
| 337 | Bool SDContainer::putDirection(const Array<Double>& dir) {
|
---|
| 338 | direction_.resize();
|
---|
| 339 | direction_ = dir;
|
---|
| 340 | return True;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[34] | 343 | Int 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 |
|
---|