[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 | //#--------------------------------------------------------------------------- |
---|
| 31 | #include <aips/Tables/Table.h> |
---|
| 32 | #include <aips/Arrays/IPosition.h> |
---|
| 33 | #include <aips/Arrays/ArrayAccessor.h> |
---|
| 34 | #include <aips/Arrays/Matrix.h> |
---|
[18] | 35 | #include <aips/Quanta/MVTime.h> |
---|
[2] | 36 | |
---|
| 37 | #include "SDContainer.h" |
---|
| 38 | |
---|
| 39 | using namespace atnf_sd; |
---|
| 40 | |
---|
[18] | 41 | void SDHeader::print() const { |
---|
| 42 | MVTime mvt(this->utc); |
---|
[47] | 43 | mvt.setFormat(MVTime::YMD); |
---|
[18] | 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): " |
---|
[47] | 54 | << mvt |
---|
[18] | 55 | << endl; |
---|
| 56 | //setprecision(10) << this->utc << endl; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
[16] | 60 | SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nPol, uInt nChan) |
---|
[2] | 61 | : nBeam_(nBeam), |
---|
[16] | 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)), |
---|
[34] | 67 | tsys_(IPosition(4,nBeam,nIF,nPol,nChan)), |
---|
| 68 | freqidx_(nIF) { |
---|
[2] | 69 | uChar x = 0; |
---|
| 70 | flags_ = ~x; |
---|
| 71 | } |
---|
| 72 | |
---|
[16] | 73 | SDContainer::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), |
---|
[34] | 80 | tsys_(shp), |
---|
| 81 | freqidx_(shp(1)){ |
---|
[16] | 82 | uChar x = 0; |
---|
| 83 | flags_ = ~x; |
---|
| 84 | } |
---|
| 85 | |
---|
[2] | 86 | SDContainer::~SDContainer() { |
---|
| 87 | } |
---|
| 88 | |
---|
[47] | 89 | Bool 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 | |
---|
[2] | 100 | Bool SDContainer::putSpectrum(const Array<Float>& spec) { |
---|
| 101 | spectrum_ = spec; |
---|
| 102 | } |
---|
[7] | 103 | Bool SDContainer::putFlags(const Array<uChar>& flag) { |
---|
| 104 | flags_ = flag; |
---|
[2] | 105 | } |
---|
[7] | 106 | Bool SDContainer::putTsys(const Array<Float>& tsys) { |
---|
| 107 | tsys_ = tsys; |
---|
[2] | 108 | } |
---|
| 109 | |
---|
| 110 | Bool 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 | |
---|
[14] | 118 | //Vector<Float> pols(nPol); |
---|
[16] | 119 | ArrayAccessor<Float, Axis<1> > j(spec); |
---|
[14] | 120 | IPosition shp0 = spectrum_.shape(); |
---|
| 121 | IPosition shp1 = spec.shape(); |
---|
[16] | 122 | if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) { |
---|
[14] | 123 | cerr << "Arrays not conformant" << endl; |
---|
| 124 | return False; |
---|
| 125 | } |
---|
[2] | 126 | // assert dimensions are the same.... |
---|
| 127 | for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) { |
---|
[16] | 128 | ArrayAccessor<Float, Axis<0> > jj(j); |
---|
[2] | 129 | for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) { |
---|
[14] | 130 | (*ii) = (*jj); |
---|
| 131 | jj++; |
---|
[2] | 132 | } |
---|
[14] | 133 | j++; |
---|
[2] | 134 | } |
---|
| 135 | // unset flags for this spectrum, they might be set again by the |
---|
| 136 | // setFlags method |
---|
[14] | 137 | |
---|
[2] | 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 | |
---|
| 145 | Bool 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 | |
---|
[16] | 153 | ArrayAccessor<uChar, Axis<1> > j(flag); |
---|
[14] | 154 | IPosition shp0 = flags_.shape(); |
---|
| 155 | IPosition shp1 = flag.shape(); |
---|
[16] | 156 | if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) { |
---|
[14] | 157 | cerr << "Arrays not conformant" << endl; |
---|
| 158 | return False; |
---|
| 159 | } |
---|
| 160 | |
---|
[2] | 161 | // assert dimensions are the same.... |
---|
| 162 | for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) { |
---|
[16] | 163 | ArrayAccessor<uChar, Axis<0> > jj(j); |
---|
[2] | 164 | for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) { |
---|
[14] | 165 | (*ii) = (*jj); |
---|
| 166 | jj++; |
---|
[2] | 167 | } |
---|
[14] | 168 | j++; |
---|
[2] | 169 | } |
---|
[16] | 170 | return True; |
---|
[2] | 171 | } |
---|
| 172 | |
---|
| 173 | Bool 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.... |
---|
[16] | 180 | for (ArrayAccessor<Float, Axis<3> > i(aa1);i != i.end(); ++i) { |
---|
[14] | 181 | ArrayAccessor<Float, Axis<0> > j(tsys); |
---|
[16] | 182 | for (ArrayAccessor<Float, Axis<2> > ii(i);ii != ii.end(); ++ii) { |
---|
[14] | 183 | (*ii) = (*j); |
---|
| 184 | j++; |
---|
[7] | 185 | } |
---|
| 186 | } |
---|
[2] | 187 | } |
---|
[27] | 188 | |
---|
[67] | 189 | Array<Float> SDContainer::getSpectrum(uInt whichBeam, uInt whichIF) const { |
---|
[27] | 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 | |
---|
[67] | 220 | return spectra.copy(); |
---|
[27] | 221 | } |
---|
| 222 | |
---|
[67] | 223 | Array<uChar> SDContainer::getFlags(uInt whichBeam, uInt whichIF) const |
---|
[27] | 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 | |
---|
[67] | 255 | return flagtra.copy(); |
---|
[27] | 256 | } |
---|
| 257 | |
---|
[67] | 258 | Array<Float> SDContainer::getTsys(uInt whichBeam, uInt whichIF) const |
---|
[27] | 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 | } |
---|
[67] | 283 | return tsys.copy(); |
---|
[27] | 284 | } |
---|
[34] | 285 | |
---|
| 286 | Bool SDContainer::setFrequencyMap(uInt freqslot, uInt whichIF) { |
---|
| 287 | freqidx_[whichIF] = freqslot; |
---|
| 288 | return True; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | Bool SDContainer::putFreqMap(const Vector<uInt>& freqs) { |
---|
| 292 | freqidx_.resize(); |
---|
| 293 | freqidx_ = freqs; |
---|
| 294 | return True; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | Int 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 | |
---|