Changeset 832
- Timestamp:
- 02/17/06 16:06:45 (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDContainer.cc
r685 r832 35 35 #include <casa/Exceptions.h> 36 36 #include <casa/Utilities/Assert.h> 37 #include <tables/Tables/Table.h>38 37 #include <casa/Arrays/IPosition.h> 39 #include <casa/Arrays/Matrix.h>40 #include <casa/Arrays/VectorIter.h>41 #include <casa/Arrays/ArrayMath.h>42 #include <casa/BasicMath/Math.h>43 38 #include <casa/Quanta/MVTime.h> 44 39 45 40 46 41 47 #include "S DDefs.h"42 #include "STDefs.h" 48 43 #include "SDContainer.h" 49 44 … … 54 49 MVTime mvt(this->utc); 55 50 mvt.setFormat(MVTime::YMD); 56 cout << "Observer: " << this->observer << endl 51 cout << "Observer: " << this->observer << endl 57 52 << "Project: " << this->project << endl 58 53 << "Obstype: " << this->obstype << endl … … 63 58 << "Ref. frequency: " << this->reffreq << endl 64 59 << "Bandwidth: " << this->bandwidth << endl 65 << "Time (utc): " 60 << "Time (utc): " 66 61 << mvt 67 62 << endl; … … 69 64 } 70 65 71 72 SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nPol, uInt nChan)73 : nBeam_(nBeam),74 nIF_(nIF),75 nPol_(nPol),76 nChan_(nChan),77 spectrum_(IPosition(4,nBeam,nIF,nPol,nChan)),78 flags_(IPosition(4,nBeam,nIF,nPol,nChan)),79 tsys_(IPosition(4,nBeam,nIF,nPol,nChan)),80 freqidx_(nIF),81 restfreqidx_(nIF),82 direction_(IPosition(2,nBeam,2)) {83 uChar x = 0;84 flags_ = ~x;85 tcal.resize(2);86 }87 88 SDContainer::SDContainer(IPosition shp)89 : nBeam_(shp(asap::BeamAxis)),90 nIF_(shp(asap::IFAxis)),91 nPol_(shp(asap::PolAxis)),92 nChan_(shp(asap::ChanAxis)),93 spectrum_(shp),94 flags_(shp),95 tsys_(shp),96 freqidx_(shp(asap::IFAxis)),97 restfreqidx_(shp(asap::IFAxis)) {98 IPosition ip(2,shp(asap::BeamAxis),2);99 direction_.resize(ip);100 uChar x = 0;101 flags_ = ~x;102 tcal.resize(2);103 }104 105 SDContainer::~SDContainer() {106 }107 108 Bool SDContainer::resize(IPosition shp) {109 nBeam_ = shp(asap::BeamAxis);110 nIF_ = shp(asap::IFAxis);111 nPol_ = shp(asap::PolAxis);112 nChan_ = shp(asap::ChanAxis);113 spectrum_.resize(shp);114 flags_.resize(shp);115 tsys_.resize(shp);116 freqidx_.resize(shp(asap::IFAxis));117 restfreqidx_.resize(shp(asap::IFAxis));118 IPosition ip(2,shp(asap::BeamAxis),2);119 direction_.resize(ip);120 }121 122 Bool SDContainer::putSpectrum(const Array<Float>& spec) {123 spectrum_ = spec;124 }125 Bool SDContainer::putFlags(const Array<uChar>& flag) {126 flags_ = flag;127 }128 Bool SDContainer::putTsys(const Array<Float>& tsys) {129 tsys_ = tsys;130 }131 132 Bool SDContainer::setSpectrum(const Matrix<Float>& spec,133 const Vector<Complex>& cSpec,134 uInt whichBeam, uInt whichIF)135 //136 // spec is [nChan,nPol]137 // cspec is [nChan]138 // spectrum_ is [,,,nChan]139 //140 // nPOl_ = 4 - xx, yy, real(xy), imag(xy)141 //142 {143 AlwaysAssert(nPol_==4,AipsError);144 145 // Get slice and check dim146 147 Bool tSys = False;148 Bool xPol = True;149 IPosition start, end;150 setSlice(start, end, spec.shape(), spectrum_.shape(),151 whichBeam, whichIF, tSys, xPol);152 153 // Get a reference to the Pol/Chan slice we are interested in154 155 Array<Float> subArr = spectrum_(start,end);156 157 // Iterate through pol-chan plane and fill158 159 ReadOnlyVectorIterator<Float> inIt(spec,0);160 VectorIterator<Float> outIt(subArr,asap::ChanAxis);161 while (!outIt.pastEnd()) {162 const IPosition& pos = outIt.pos();163 if (pos(asap::PolAxis)<2) {164 outIt.vector() = inIt.vector();165 inIt.next();166 } else if (pos(asap::PolAxis)==2) {167 outIt.vector() = real(cSpec);168 } else if (pos(asap::PolAxis)==3) {169 outIt.vector() = imag(cSpec);170 }171 //172 outIt.next();173 }174 175 // unset flags for this spectrum, they might be set again by the176 // setFlags method177 178 Array<uChar> arr(flags_(start,end));179 arr = uChar(0);180 //181 return True;182 }183 184 185 Bool SDContainer::setSpectrum(const Matrix<Float>& spec,186 uInt whichBeam, uInt whichIF)187 //188 // spec is [nChan,nPol]189 // spectrum_ is [,,,nChan]190 // How annoying.191 {192 193 // Get slice and check dim194 195 IPosition start, end;196 setSlice(start, end, spec.shape(), spectrum_.shape(),197 whichBeam, whichIF, False, False);198 199 // Get a reference to the Pol/Chan slice we are interested in200 201 Array<Float> subArr = spectrum_(start,end);202 203 // Iterate through it and fill204 205 ReadOnlyVectorIterator<Float> inIt(spec,0);206 VectorIterator<Float> outIt(subArr,asap::ChanAxis);207 while (!outIt.pastEnd()) {208 outIt.vector() = inIt.vector();209 //210 inIt.next();211 outIt.next();212 }213 214 // unset flags for this spectrum, they might be set again by the215 // setFlags method216 217 Array<uChar> arr(flags_(start,end));218 arr = uChar(0);219 //220 return True;221 }222 223 Bool SDContainer::setFlags(const Matrix<uChar>& flags,224 uInt whichBeam, uInt whichIF,225 Bool hasXPol)226 //227 // flags is [nChan,nPol]228 // flags_ is [nBeam,nIF,nPol,nChan]229 //230 // Note that there are no separate flags for the XY cross polarization so we make231 // them up from the X and Y which is all the silly code below. This means232 // that nPol==2 on input but 4 on output233 //234 {235 if (hasXPol) AlwaysAssert(nPol_==4,AipsError);236 237 // Get slice and check dim238 239 IPosition start, end;240 setSlice(start, end, flags.shape(), flags_.shape(),241 whichBeam, whichIF, False, hasXPol);242 243 // Get a reference to the Pol/Chan slice we are interested in244 245 Array<uChar> subArr = flags_(start,end);246 247 // Iterate through pol/chan plane and fill248 249 ReadOnlyVectorIterator<uChar> inIt(flags,0);250 VectorIterator<uChar> outIt(subArr,asap::ChanAxis);251 //252 Vector<uChar> maskPol0;253 Vector<uChar> maskPol1;254 Vector<uChar> maskPol01;255 while (!outIt.pastEnd()) {256 const IPosition& pos = outIt.pos();257 if (pos(asap::PolAxis)<2) {258 outIt.vector() = inIt.vector();259 //260 if (hasXPol) {261 if (pos(asap::PolAxis)==0) {262 maskPol0 = inIt.vector();263 } else if (pos(asap::PolAxis)==1) {264 maskPol1 = inIt.vector();265 //266 maskPol01.resize(maskPol0.nelements());267 for (uInt i=0; i<maskPol01.nelements(); i++) maskPol01[i] = maskPol0[i]&maskPol1[i];268 }269 }270 inIt.next();271 } else if (pos(asap::PolAxis)==2) {272 if (hasXPol) {273 outIt.vector() = maskPol01;274 } else {275 outIt.vector() = inIt.vector();276 inIt.next();277 }278 279 } else if (pos(asap::PolAxis)==3) {280 if (hasXPol) {281 outIt.vector() = maskPol01;282 } else {283 outIt.vector() = inIt.vector();284 inIt.next();285 }286 }287 outIt.next();288 }289 //290 return True;291 }292 293 294 Bool SDContainer::setTsys(const Vector<Float>& tsys,295 uInt whichBeam, uInt whichIF,296 Bool hasXpol)297 //298 // TSys shape is [nPol]299 // Tsys does not depend upon channel but is replicated300 // for simplicity of use.301 // There is no Tsys measurement for the cross polarization302 // so I have set TSys for XY to sqrt(Tx*Ty)303 //304 {305 306 // Get slice and check dim307 308 IPosition start, end;309 setSlice(start, end, tsys.shape(), tsys_.shape(),310 whichBeam, whichIF, True, hasXpol);311 312 // Get a reference to the Pol/Chan slice we are interested in313 314 Array<Float> subArr = tsys_(start,end);315 316 // Iterate through it and fill317 318 VectorIterator<Float> outIt(subArr,asap::ChanAxis);319 uInt i=0;320 while (!outIt.pastEnd()) {321 const IPosition& pos = outIt.pos();322 //323 if (pos(asap::PolAxis)<2) {324 outIt.vector() = tsys(i++);325 } else {326 if (hasXpol) {327 outIt.vector() = sqrt(tsys[0]*tsys[1]);328 } else {329 outIt.vector() = tsys(i++);330 }331 }332 //333 outIt.next();334 }335 }336 337 Array<Float> SDContainer::getSpectrum(uInt whichBeam, uInt whichIF)338 //339 // non-const function because of Array(start,end) slicer340 //341 // Input [nBeam,nIF,nPol,nChan]342 // Output [nChan,nPol]343 //344 {345 346 // Get reference to slice and check dim347 348 IPosition start, end;349 setSlice(start, end, spectrum_.shape(), whichBeam, whichIF);350 //351 Array<Float> dataIn = spectrum_(start,end);352 Array<Float> dataOut(IPosition(2, nChan_, nPol_));353 //354 ReadOnlyVectorIterator<Float> itIn(dataIn, asap::ChanAxis);355 VectorIterator<Float> itOut(dataOut, 0);356 while (!itOut.pastEnd()) {357 itOut.vector() = itIn.vector();358 //359 itIn.next();360 itOut.next();361 }362 //363 return dataOut.copy();364 }365 366 Array<uChar> SDContainer::getFlags(uInt whichBeam, uInt whichIF)367 //368 // non-const function because of Array(start,end) slicer369 //370 // Input [nBeam,nIF,nPol,nChan]371 // Output [nChan,nPol]372 //373 {374 375 // Get reference to slice and check dim376 377 IPosition start, end;378 setSlice(start, end, flags_.shape(), whichBeam, whichIF);379 //380 Array<uChar> dataIn = flags_(start,end);381 Array<uChar> dataOut(IPosition(2, nChan_, nPol_));382 //383 ReadOnlyVectorIterator<uChar> itIn(dataIn, asap::ChanAxis);384 VectorIterator<uChar> itOut(dataOut, 0);385 while (!itOut.pastEnd()) {386 itOut.vector() = itIn.vector();387 //388 itIn.next();389 itOut.next();390 }391 //392 return dataOut.copy();393 }394 395 Array<Float> SDContainer::getTsys(uInt whichBeam, uInt whichIF)396 //397 // Input [nBeam,nIF,nPol,nChan]398 // Output [nPol] (drop channel dependency and select first value only)399 //400 {401 // Get reference to slice and check dim402 403 IPosition start, end;404 setSlice(start, end, spectrum_.shape(), whichBeam, whichIF);405 //406 Array<Float> dataIn = tsys_(start,end);407 Vector<Float> dataOut(nPol_);408 //409 ReadOnlyVectorIterator<Float> itIn(dataIn, asap::ChanAxis);410 VectorIterator<Float> itOut(dataOut, 0);411 uInt i = 0;412 while (!itIn.pastEnd()) {413 dataOut[i++] = itIn.vector()[0];414 itIn.next();415 }416 //417 return dataOut.copy();418 }419 420 421 422 Array<Double> SDContainer::getDirection(uInt whichBeam) const423 //424 // Input [nBeam,2]425 // Output [nBeam]426 //427 {428 Vector<Double> dataOut(2);429 dataOut(0) = direction_(IPosition(2,whichBeam,0));430 dataOut(1) = direction_(IPosition(2,whichBeam,1));431 return dataOut.copy();432 }433 434 435 Bool SDContainer::setFrequencyMap(uInt freqID, uInt whichIF) {436 freqidx_[whichIF] = freqID;437 return True;438 }439 440 Bool SDContainer::putFreqMap(const Vector<uInt>& freqs) {441 freqidx_.resize();442 freqidx_ = freqs;443 return True;444 }445 446 Bool SDContainer::setRestFrequencyMap(uInt freqID, uInt whichIF) {447 restfreqidx_[whichIF] = freqID;448 return True;449 }450 451 Bool SDContainer::putRestFreqMap(const Vector<uInt>& freqs) {452 restfreqidx_.resize();453 restfreqidx_ = freqs;454 return True;455 }456 457 Bool SDContainer::setDirection(const Vector<Double>& point, uInt whichBeam)458 //459 // Input [2]460 // Output [nBeam,2]461 //462 {463 if (point.nelements() != 2) return False;464 //465 Vector<Double> dataOut(2);466 direction_(IPosition(2,whichBeam,0)) = point[0];467 direction_(IPosition(2,whichBeam,1)) = point[1];468 return True;469 }470 471 472 Bool SDContainer::putDirection(const Array<Double>& dir) {473 direction_.resize();474 direction_ = dir;475 return True;476 }477 478 Bool SDContainer::putFitMap(const Array<Int>& arr) {479 fitIDMap_.resize();480 fitIDMap_ = arr;481 return True;482 }483 484 void SDContainer::setSlice(IPosition& start, IPosition& end,485 const IPosition& shpIn, const IPosition& shpOut,486 uInt whichBeam, uInt whichIF, Bool tSys,487 Bool xPol) const488 //489 // tSYs490 // shpIn [nPol]491 // else492 // shpIn [nCHan,nPol]493 //494 // if xPol present, the output nPol = 4 but495 // the input spectra are nPol=2 (tSys) or nPol=2 (spectra)496 //497 {498 AlwaysAssert(asap::nAxes==4,AipsError);499 uInt pOff = 0;500 if (xPol) pOff += 2;501 if (tSys) {502 AlwaysAssert(shpOut(asap::PolAxis)==shpIn(0)+pOff,AipsError); // pol503 } else {504 AlwaysAssert(shpOut(asap::ChanAxis)==shpIn(0),AipsError); // chan505 AlwaysAssert(shpOut(asap::PolAxis)==shpIn(1)+pOff,AipsError); // pol506 }507 //508 setSlice(start, end, shpOut, whichBeam, whichIF);509 }510 511 512 void SDContainer::setSlice(IPosition& start, IPosition& end,513 const IPosition& shape,514 uInt whichBeam, uInt whichIF) const515 {516 AlwaysAssert(asap::nAxes==4,AipsError);517 //518 start.resize(asap::nAxes);519 start = 0;520 start(asap::BeamAxis) = whichBeam;521 start(asap::IFAxis) = whichIF;522 //523 end.resize(asap::nAxes);524 end = shape-1;525 end(asap::BeamAxis) = whichBeam;526 end(asap::IFAxis) = whichIF;527 }528 529 530 uInt SDFrequencyTable::addFrequency(Double refPix, Double refVal, Double inc)531 {532 if (length() > 0) {533 for (uInt i=0; i< length();i++) {534 if (near(refVal,refVal_[i]) &&535 near(refPix,refPix_[i]) &&536 near(inc,increment_[i])) {537 return i;538 }539 }540 }541 542 // Not found - add it543 544 nFreq_ += 1;545 refPix_.resize(nFreq_,True);546 refVal_.resize(nFreq_,True);547 increment_.resize(nFreq_,True);548 refPix_[nFreq_-1] = refPix;549 refVal_[nFreq_-1] = refVal;550 increment_[nFreq_-1] = inc;551 return nFreq_-1;552 }553 554 uInt SDFrequencyTable::addRestFrequency(Double val)555 {556 uInt nFreq = restFreqs_.nelements();557 if (nFreq>0) {558 for (uInt i=0; i<nFreq;i++) {559 if (near(restFreqs_[i],val)) {560 return i;561 }562 }563 }564 565 // Not found - add it566 567 nFreq += 1;568 restFreqs_.resize(nFreq,True);569 restFreqs_[nFreq-1] = val;570 return nFreq-1;571 }572 573 574 void SDFrequencyTable::restFrequencies(Vector<Double>& rfs,575 String& rfunit ) const576 {577 rfs.resize(restFreqs_.nelements());578 rfs = restFreqs_;579 rfunit = restFreqUnit_;580 }581 582 66 // SDDataDesc 583 67 584 uInt SDDataDesc::addEntry(const String& source, uInt ID, 68 uInt SDDataDesc::addEntry(const String& source, uInt ID, 585 69 const MDirection& dir, uInt secID) 586 70 { … … 615 99 { 616 100 if (n_>0) { 617 cerr << "Source ID" << endl; 101 cerr << "Source ID" << endl; 618 102 for (uInt i=0; i<n_; i++) { 619 103 cout << setw(11) << source_(i) << ID_(i) << endl; -
trunk/src/SDContainer.h
r754 r832 36 36 #include <casa/aips.h> 37 37 #include <casa/BasicSL/String.h> 38 #include <casa/Arrays/Array.h>39 38 #include <casa/Arrays/Vector.h> 40 39 #include <casa/Containers/Block.h> … … 65 64 void print() const ; 66 65 }; 67 68 class SDFrequencyTable {69 70 public:71 72 SDFrequencyTable() : nFreq_(0) {;}73 virtual ~SDFrequencyTable() {;}74 75 // Add a new entry or match an existing one. Returns the index into76 // the table77 casa::uInt addFrequency(casa::Double refPix, casa::Double refVal,78 casa::Double inc);79 80 casa::Int length() const { return nFreq_;} // # of stored Frequencies81 void setLength(casa::uInt length) {nFreq_ = length;}82 83 // Get attributes84 casa::Double referencePixel(casa::uInt which) const { return refPix_[which];}85 casa::Double referenceValue(casa::uInt which) const { return refVal_[which];}86 casa::Double increment(casa::uInt which) const { return increment_[which];}87 casa::Float equinox() const { return equinox_; }88 casa::String refFrame() const { return refFrame_; }89 casa::String baseRefFrame() const { return baseRefFrame_; }90 casa::String unit() const { return unit_; }91 92 void restFrequencies(casa::Vector<casa::Double>& rfs,93 casa::String& rfunit ) const ;94 95 // Set attributes96 void setEquinox(casa::Float eq) { equinox_ = eq; }97 void setRefFrame(const casa::String& reff) { refFrame_ = reff; }98 void setBaseRefFrame(const casa::String& reff) { baseRefFrame_ = reff; }99 void setUnit(const casa::String& un) { unit_= un; }100 101 void deleteRestFrequencies() {restFreqs_.resize(0);}102 casa::uInt addRestFrequency(casa::Double);103 void setRestFrequencyUnit(const casa::String& theunit)104 { restFreqUnit_ = theunit;}105 106 private:107 casa::uInt nFreq_;108 casa::Vector<casa::Double> refPix_;109 casa::Vector<casa::Double> refVal_; // Hz110 casa::Vector<casa::Double> increment_; // Hz111 casa::Float equinox_;112 casa::String unit_;113 casa::String refFrame_;114 casa::String baseRefFrame_;115 casa::Vector<casa::Double> restFreqs_; // Hz116 casa::String restFreqUnit_;117 };118 119 120 class SDContainer {121 122 public:123 SDContainer(casa::uInt nBeam, casa::uInt nIF, casa::uInt nPol,124 casa::uInt nChan);125 SDContainer(casa::IPosition shp);126 127 virtual ~SDContainer();128 129 casa::Bool resize(casa::IPosition shp);130 131 casa::Bool setSpectrum(const casa::Matrix<casa::Float>& spec,132 casa::uInt whichBeam, casa::uInt whichIF);133 casa::Bool setSpectrum(const casa::Matrix<casa::Float>& spec,134 const casa::Vector<casa::Complex>& cSpec,135 casa::uInt whichBeam, casa::uInt whichIF);136 casa::Bool putSpectrum(const casa::Array<casa::Float>& spec);137 138 casa::Bool setFlags(const casa::Matrix<casa::uChar>& flgs,139 casa::uInt whichBeam, casa::uInt whichIF,140 casa::Bool hasXPol=casa::False);141 casa::Bool putFlags(const casa::Array<casa::uChar>& spec);142 143 casa::Bool setTsys(const casa::Vector<casa::Float>& ts,144 casa::uInt whichBeam, casa::uInt whichIF,145 casa::Bool hasXpol);146 casa::Bool putTsys(const casa::Array<casa::Float>& spec);147 148 casa::Bool setDirection(const casa::Vector<casa::Double>& point,149 casa::uInt whichBeam);150 casa::Bool putDirection(const casa::Array<casa::Double>& dir);151 152 casa::Bool setFrequencyMap(casa::uInt freqslot, casa::uInt whichIF);153 casa::Bool putFreqMap(const casa::Vector<casa::uInt>& freqs);154 155 casa::Bool setRestFrequencyMap(casa::uInt freqslot, casa::uInt whichIF);156 casa::Bool putRestFreqMap(const casa::Vector<casa::uInt>& freqs);157 158 casa::Array<casa::Float> getSpectrum(casa::uInt whichBeam,159 casa::uInt whichIF);160 casa::Array<casa::uChar> getFlags(casa::uInt whichBeam,161 casa::uInt whichIF);162 casa::Array<casa::Float> getTsys(casa::uInt whichBeam,163 casa::uInt whichIF);164 casa::Array<casa::Double> getDirection(casa::uInt whichBeam) const;165 166 const casa::Array<casa::Float>& getSpectrum() const { return spectrum_; }167 const casa::Array<casa::uChar>& getFlags() const { return flags_; }168 const casa::Array<casa::Float>& getTsys() const { return tsys_; }169 const casa::Array<casa::Double>& getDirection() const { return direction_; }170 171 const casa::Vector<casa::uInt>& getFreqMap() const { return freqidx_; }172 const casa::Vector<casa::uInt>& getRestFreqMap() const173 { return restfreqidx_; }174 175 casa::Bool putFitMap(const casa::Array<casa::Int>& arr);176 177 const casa::Array<casa::Int>& getFitMap() const { return fitIDMap_; }178 179 180 casa::Double timestamp;181 //Double bandwidth;182 casa::String sourcename;183 casa::String fieldname;184 casa::Double interval;185 casa::Int scanid;186 casa::Vector<casa::Float> tcal;187 casa::String tcaltime;188 casa::Float azimuth;189 casa::Float elevation;190 casa::Float parangle;191 casa::Int refbeam;192 193 private:194 casa::uInt nBeam_,nIF_,nPol_,nChan_;195 196 // (nBeam,nIF,nPol,nChannel)197 casa::Array<casa::Float> spectrum_;198 casa::Array<casa::uChar> flags_;199 200 // (nBeam,nIF,nPol,[nChannel]) Tsys is not really a function of201 // channel, but this makes it easier to work with at the expense of202 // a little memory203 casa::Array<casa::Float> tsys_;204 casa::Array<casa::Float> tcal_;205 206 //(nIF) indx into "global" frequency table207 casa::Vector<casa::uInt> freqidx_;208 209 // (nIF) indx into "global" rest frequency table210 casa::Vector<casa::uInt> restfreqidx_;211 212 //(nBeam,2) maybe use Measures here...213 casa::Array<casa::Double> direction_;214 casa::Array<casa::Int> fitIDMap_;215 216 void setSlice(casa::IPosition& start, casa::IPosition& end,217 const casa::IPosition& shpIn, const casa::IPosition& shpOut,218 casa::uInt whichBeam, casa::uInt whichIF, casa::Bool checkPol,219 casa::Bool xPol) const;220 void setSlice(casa::IPosition& start, casa::IPosition& end,221 const casa::IPosition& shape,222 casa::uInt whichBeam, casa::uInt whichIF) const;223 };224 225 226 66 227 67 class SDDataDesc {
Note:
See TracChangeset
for help on using the changeset viewer.