Changeset 89


Ignore:
Timestamp:
11/12/04 12:14:41 (20 years ago)
Author:
mar637
Message:

changes summary to return std::string
comment out unused getMask function
rename a few functions to make it consistent nXXX()
added nCoordinates
added use and setting of internal restfrequencies
added setSpecturm to mdify a spectrum
gave the summary function a major overhaul
added flag function, to hard flag full spectra

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r83 r89  
    9494  //cerr << exprs << endl;
    9595  Table t = tableCommand(exprs,tab);
     96  if (t.nrow() == 0)
     97      throw(AipsError("Query unsuccessful."));
    9698  table_ = t.copyToMemoryTable("dummy");
    9799}
    98100
    99101SDMemTable::~SDMemTable(){
    100   //cerr << "goodbye from SDMemTable @ " << this << endl;
     102  cerr << "goodbye from SDMemTable @ " << this << endl;
    101103}
    102104
     
    120122  td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
    121123  td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
    122   td.addColumn(ArrayColumnDesc<Float>("TSYS")); 
    123   td.addColumn(ScalarColumnDesc<Int>("SCANID")); 
    124   td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); 
     124  td.addColumn(ArrayColumnDesc<Float>("TSYS"));
     125  td.addColumn(ScalarColumnDesc<Int>("SCANID"));
     126  td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
    125127  td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
    126128  td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
     
    128130
    129131  SetupNewTable aNewTab("dummy", td, Table::New);
    130   table_ = Table(aNewTab, Table::Memory, 0); 
     132  table_ = Table(aNewTab, Table::Memory, 0);
    131133}
    132134
     
    182184bool SDMemTable::setMask(std::vector<int> whichChans) {
    183185  ROArrayColumn<uChar> spec(table_, "FLAGTRA");
    184  
    185186  std::vector<int>::iterator it;
    186187  uInt n = spec.shape(0)(3);
     
    219220    }
    220221    mask.push_back(out);
    221   } 
     222  }
    222223  return mask;
    223224}
     
    240241}
    241242
    242 std::vector<double> SDMemTable::getAbscissa(Int whichRow, 
    243                                             const std::string& whichUnit,
    244                                             const std::string& whichFrame,
    245                                             double restfreq) {
     243std::vector<double> SDMemTable::getAbscissa(Int whichRow,
     244                                            const std::string& whichUnit,
     245                                            const std::string& whichFrame,
     246                                            double restfreq) {
    246247  std::vector<double> absc(nChan());
    247   Vector<Double> absc1(nChan()); 
     248  Vector<Double> absc1(nChan());
    248249  indgen(absc1);
    249250  ROArrayColumn<uInt> fid(table_, "FREQID");
     
    262263  t.keywordSet().get("REFFRAME",rf);
    263264  MDirection::Types mdr;
    264   MDirection::getType(mdr, rf);   
     265  MDirection::getType(mdr, rf);
    265266  ROArrayColumn<Double> dir(table_, "DIRECTION");
    266267  Array<Double> posit;
     
    275276  Double obstime;
    276277  tme.get(whichRow,obstime);
    277   Quantum<Double> tm(obstime, Unit(String("d")));
    278   MVEpoch tm2(tm);
     278  //Quantum<Double> tm(obstime, Unit(String("d")));
     279  MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
    279280  MEpoch epoch(tm2);
    280281
     
    288289  MFrequency::Types mtype;
    289290  if (!MFrequency::getType(mtype, whichFrame)) {
    290     cerr << "Frequency type unknown assuming TOPO" << endl;
     291    cout << "Frequency type unknown assuming TOPO" << endl;
    291292    mtype = MFrequency::TOPO;
    292293  }
    293   spc.setReferenceConversion(mtype,epoch,pos,direct); 
     294  spc.setReferenceConversion(mtype,epoch,pos,direct);
    294295
    295296  if ( u == Unit("km/s") ) {
    296     if (Double(restfreq) >  Double(0.000001)) {
    297       cerr << "converting to velocities"<< endl;
    298       spc.setRestFrequency(Double(restfreq));
    299       spc.setVelocity(u.getName());
     297    Vector<Double> rstf;
     298    t.keywordSet().get("RESTFREQS",rstf);
     299    if (rstf.nelements() > 0) {
     300      cout << "converting to velocities"<< endl;
     301      //spc.setRestFrequency(Double(restfreq));
     302      spc.setVelocity(u.getName());
    300303      Vector<Double> wrld;
    301304      spc.pixelToVelocity(wrld,absc1);
     
    303306      uInt i = 0;
    304307      for (it = absc.begin(); it != absc.end(); ++it) {
    305         (*it) = wrld[i];
    306         i++;
     308        (*it) = wrld[i];
     309        i++;
    307310      }
    308311    }
     
    310313    Vector<String> wau(1); wau = u.getName();
    311314    spc.setWorldAxisUnits(wau);
    312     cerr << " converting in frequency" << endl;
     315    cout << " converting in frequency" << endl;
    313316    std::vector<double>::iterator it;
    314317    Double tmp;
    315318    uInt i = 0;
    316     for (it = absc.begin(); it != absc.end(); ++it) {     
     319    for (it = absc.begin(); it != absc.end(); ++it) {
    317320      spc.toWorld(tmp,absc1[i]);
    318321      (*it) = tmp;
     
    321324  }
    322325  return absc;
     326}
     327
     328void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow) {
     329  ArrayColumn<Float> spec(table_, "SPECTRA");
     330  Array<Float> arr;
     331  spec.get(whichRow, arr);
     332  if (spectrum.size() != arr.shape()(3)) {
     333    throw(AipsError("Attempting to set spectrum with incorrect length."));
     334  }
     335
     336  ArrayAccessor<Float, Axis<0> > aa0(arr);
     337  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     338  ArrayAccessor<Float, Axis<1> > aa1(aa0);
     339  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
     340  ArrayAccessor<Float, Axis<2> > aa2(aa1);
     341  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
     342
     343  std::vector<float>::iterator it = spectrum.begin();
     344  for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) {
     345    (*i) = Float(*it);
     346    it++;
     347  }
     348  spec.put(whichRow, arr);
    323349}
    324350
     
    341367  }
    342368}
    343 
     369/*
    344370void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
    345371  ROArrayColumn<uChar> spec(table_, "FLAGTRA");
     
    356382
    357383  Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
    358  
     384
    359385  ArrayAccessor<Bool, Axis<0> > va(mask);
    360386  std::vector<bool> tmp;
    361387  tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
    362                    // iterator should work on chanMask_??
     388                   // iterator should work on chanMask_??
    363389  std::vector<bool>::iterator miter;
    364390  miter = tmp.begin();
     
    372398    (*va) = out;
    373399    va++;
    374   } 
    375 }
    376 
     400  }
     401}
     402*/
    377403MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
    378                                                 Bool useSelection) {
     404                                                Bool useSelection) {
    379405  ROArrayColumn<Float> spec(table_, "SPECTRA");
    380406  Array<Float> arr;
     
    392418    ArrayAccessor<Float, Axis<2> > aa2(aa1);
    393419    aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
    394    
     420
    395421    ArrayAccessor<Bool, Axis<0> > baa0(barr);
    396422    baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
     
    438464    return SpectralCoordinate();
    439465  }
    440  
     466
    441467  Double rp,rv,inc;
    442468  String rf;
     469  Vector<Double> vec;
    443470  ROScalarColumn<Double> rpc(t, "REFPIX");
    444471  ROScalarColumn<Double> rvc(t, "REFVAL");
    445472  ROScalarColumn<Double> incc(t, "INCREMENT");
     473  t.keywordSet().get("RESTFREQS",vec);
    446474  t.keywordSet().get("REFFRAME",rf);
    447  
     475
    448476  MFrequency::Types mft;
    449477  if (!MFrequency::getType(mft, rf)) {
    450478    cerr << "Frequency type unknown assuming TOPO" << endl;
    451     mft = MFrequency::TOPO;   
    452   }   
     479    mft = MFrequency::TOPO;
     480  }
    453481  rpc.get(whichIdx, rp);
    454482  rvc.get(whichIdx, rv);
     
    457485  //     << rp <<", " << rv << ", " << inc << ", " << mft <<endl;
    458486  SpectralCoordinate spec(mft,rv,inc,rp);
     487  if (vec.nelements() > 0)
     488    spec.setRestFrequencies(vec);
    459489  return spec;
    460490}
    461491
    462 Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, 
    463                                uInt whichIdx) {
     492Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
     493                               uInt whichIdx) {
    464494  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
    465495  if (whichIdx > t.nrow() ) {
    466     cerr << "SDMemTable::setCoordinate - whichIdx out of range" << endl;
    467     return False;
     496    throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
    468497  }
    469498  ScalarColumn<Double> rpc(t, "REFPIX");
    470499  ScalarColumn<Double> rvc(t, "REFVAL");
    471500  ScalarColumn<Double> incc(t, "INCREMENT");
    472  
     501
    473502  rpc.put(whichIdx, speccord.referencePixel()[0]);
    474503  rvc.put(whichIdx, speccord.referenceValue()[0]);
     
    478507}
    479508
     509Int SDMemTable::nCoordinates() const
     510{
     511  return table_.keywordSet().asTable("FREQUENCIES").nrow();
     512}
     513
     514void SDMemTable::setRestFreqs(std::vector<double> freqs, const std::string& theunit)
     515{
     516  Vector<Double> tvec(freqs);
     517  Quantum<Vector<Double> > q(tvec, String(theunit));
     518  tvec.resize();
     519  tvec = q.getValue("Hz");
     520  Table t = table_.keywordSet().asTable("FREQUENCIES");
     521  t.rwKeywordSet().define("RESTFREQS",tvec);
     522
     523}
    480524
    481525bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) {
     
    497541  aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
    498542  aTable.rwKeywordSet().define("Unit", String("kms-1"));
     543  Vector<Double> rfvec;
     544  aTable.rwKeywordSet().define("RESTFREQS", rfvec);
    499545  table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
    500546  return True;
     
    503549SDFrequencyTable SDMemTable::getSDFreqTable() const  {
    504550  SDFrequencyTable sdft;
    505  
     551
    506552  return sdft;
    507553}
     
    520566  uInt rno = table_.nrow();
    521567  table_.addRow();
    522  
     568
    523569  mjd.put(rno, sdc.timestamp);
    524570  srcn.put(rno, sdc.sourcename);
     
    530576  freqid.put(rno, sdc.getFreqMap());
    531577  dir.put(rno, sdc.getDirection());
    532  
     578
    533579  return true;
    534580}
     
    610656}
    611657
    612 Int SDMemTable::nScans() const {
     658Int SDMemTable::nScan() const {
    613659  Int n = 0;
    614660  ROScalarColumn<Int> scans(table_, "SCANID");
     
    617663    scans.getScalar(i,current);
    618664    if (previous != current) {
    619       previous = current;     
     665      previous = current;
    620666      n++;
    621667    }
     
    624670}
    625671
    626 void SDMemTable::summary() const {
     672std::string SDMemTable::summary() const {
    627673  ROScalarColumn<Int> scans(table_, "SCANID");
    628674  ROScalarColumn<String> srcs(table_, "SRCNAME");
    629   cout << "*************** Header ***************" << endl;
    630   cout << "nBeam = " << nBeam() << "\t"
    631        << "nIF   = " << nIF() << endl
    632        << "nPol  = " << nPol() << "\t"
    633        << "nChan = " << nChan() << "\t" << endl;
    634   cout << "*************** Header ***************" << endl;
     675  ostringstream oss;
     676  oss << endl;
     677  oss << "--------------------------------------------------" << endl;
     678  oss << " Scan Table Summary" << endl;
     679  oss << "--------------------------------------------------" << endl;
     680  oss.flags(std::ios_base::left);
     681  //oss.width(15);
     682  oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
     683      << setw(15) << "IFs:" << setw(4) << nIF() << endl
     684      << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
     685      << setw(15) << "Channels:"  << setw(4) << nChan() << endl;
     686  oss << endl;
     687  String tmp;
     688  table_.keywordSet().get("Observer", tmp);
     689  oss << setw(15) << "Observer:" << tmp << endl;
     690  table_.keywordSet().get("Project", tmp);
     691  oss << setw(15) << "Project:" << tmp << endl;
     692  table_.keywordSet().get("Obstype", tmp);
     693  oss << setw(15) << "Obs. Type:" << tmp << endl;
     694  table_.keywordSet().get("AntennaName", tmp);
     695  oss << setw(15) << "Antenna Name:" << tmp << endl;
     696  oss << endl;
    635697  uInt count = 0;
    636698  String name;
    637699  Int previous = -1;Int current=0;
    638   cout << "Scan\tSource\t\tTime\t\tIntegration" << endl;
     700  Int integ = 0;
     701  oss << setw(6) << "Scan"
     702      << setw(12) << "Source"
     703      << setw(21) << "Time"
     704      << setw(11) << "Integration" << endl;
    639705  for (uInt i=0; i< scans.nrow();i++) {
    640706    scans.getScalar(i,current);
     
    642708      srcs.getScalar(i,name);
    643709      previous = current;
    644       Double t = getInterval();
    645       String unit("sec");
    646       if (t/60.0 > 1.0) {
    647         t/=60.0;unit = "min";
     710      Double t = getInterval(i);
     711      String unit("s");
     712      if (t/3600.0 > 1.0) {
     713          t/=3600.0;unit = "h";
     714      } else if (t/60.0 > 1.0) {
     715        t/=60.0;unit = "m";
    648716      }
    649       cout << count << "\t"
    650            << name << "\t"
    651            << getTime() << "\t"
    652            << setprecision(2) <<  setiosflags(std::ios_base::fixed)
    653            << t << " " << unit << endl
    654            << endl;
     717      oss << setw(6) << count << setw(12) << name << setw(21) << getTime(i)
     718          << setw(2) << setprecision(1) <<  setiosflags(std::ios_base::fixed)
     719          << t << " " << unit << endl;
    655720      count++;
     721    } else {
     722      integ++;
    656723    }
    657724  }
    658   cout << "Table contains " << table_.nrow() << " integration(s)." << endl;
    659   cout << "in " << count << " scan(s)." << endl;
     725  oss << endl;
     726  oss << "Table contains " << table_.nrow() << " integration(s)." << endl;
     727  oss << "in " << count << " scan(s)." << endl;
     728  oss << "--------------------------------------------------";
     729  return String(oss);
    660730}
    661731
     
    682752/*
    683753void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
    684  
     754
    685755  std::vector<int>::iterator it;
    686756  ArrayAccessor<uChar, Axis<2> > j(flags_);
     
    689759    for (ArrayAccessor<uChar, Axis<0> > i(j); i != i.end(); ++i) {
    690760      for (ArrayAccessor<uChar, Axis<1> > ii(i); ii != ii.end(); ++ii) {
    691         for (ArrayAccessor<uChar, Axis<3> > iii(ii);
    692              iii != iii.end(); ++iii) {   
    693           (*iii) =
    694         }
     761        for (ArrayAccessor<uChar, Axis<3> > iii(ii);
     762             iii != iii.end(); ++iii) {
     763          (*iii) =
     764        }
    695765      }
    696766    }
    697767  }
    698  
     768
    699769}
    700770*/
     771void SDMemTable::flag(int whichRow) {
     772  ArrayColumn<uChar> spec(table_, "FLAGTRA");
     773  Array<uChar> arr;
     774  spec.get(whichRow, arr);
     775
     776  ArrayAccessor<uChar, Axis<0> > aa0(arr);
     777  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     778  ArrayAccessor<uChar, Axis<1> > aa1(aa0);
     779  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
     780  ArrayAccessor<uChar, Axis<2> > aa2(aa1);
     781  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
     782
     783  for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) {
     784    (*i) = uChar(True);
     785  }
     786
     787  spec.put(whichRow, arr);
     788}
Note: See TracChangeset for help on using the changeset viewer.