Ignore:
Timestamp:
12/01/04 10:57:15 (19 years ago)
Author:
mar637
Message:

added set/getCoordInfo, reworked summary, added columns for azimuth,elevation,parangle,refbeam,fieldname,tcal,tcaltime
modified getabscissa, added getAbscissaString
added doppler, frequency frame an unit conversion via columns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r89 r105  
    5151#include <measures/Measures/MFrequency.h>
    5252#include <measures/Measures/MeasTable.h>
     53#include <coordinates/Coordinates/CoordinateUtil.h>
    5354#include <casa/Quanta/MVTime.h>
    5455
     
    9293  beamSel_(0),
    9394  polSel_(0) {
    94   //cerr << exprs << endl;
    9595  Table t = tableCommand(exprs,tab);
    9696  if (t.nrow() == 0)
     
    100100
    101101SDMemTable::~SDMemTable(){
    102   cerr << "goodbye from SDMemTable @ " << this << endl;
     102  //cerr << "goodbye from SDMemTable @ " << this << endl;
    103103}
    104104
     
    127127  td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
    128128  td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
     129  td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
     130  td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
     131  td.addColumn(ArrayColumnDesc<Float>("TCAL"));
     132  td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
     133  td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
     134  td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
     135  td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
     136
    129137  // Now create a new table from the description.
    130138
     
    145153  src.get(whichRow, tm);
    146154  MVTime mvt(tm);
    147   mvt.setFormat(MVTime::YMD);
     155  mvt.setFormat(MVTime::TIME);
    148156  ostringstream oss;
    149157  oss << mvt;
     
    186194  std::vector<int>::iterator it;
    187195  uInt n = spec.shape(0)(3);
     196  if (whichChans.empty()) {
     197    chanMask_ = std::vector<bool>(n,true);
     198    return true;     
     199  }
    188200  chanMask_.resize(n,true);
    189201  for (it = whichChans.begin(); it != whichChans.end(); ++it) {
    190     if (*it < n)
     202    if (*it < n) {
    191203      chanMask_[*it] = false;
     204    }
    192205  }
    193206  return true;
     
    240253  return spectrum;
    241254}
    242 
    243 std::vector<double> SDMemTable::getAbscissa(Int whichRow,
    244                                             const std::string& whichUnit,
    245                                             const std::string& whichFrame,
    246                                             double restfreq) {
     255std::vector<string> SDMemTable::getCoordInfo() const {
     256  String un;
     257  Table t = table_.keywordSet().asTable("FREQUENCIES");
     258  String sunit;
     259  t.keywordSet().get("UNIT",sunit);
     260  String dpl;
     261  t.keywordSet().get("DOPPLER",dpl);
     262  if (dpl == "") dpl = "RADIO";
     263  String rfrm;
     264  t.keywordSet().get("REFFRAME",rfrm);
     265  std::vector<string> inf;
     266  inf.push_back(sunit);
     267  inf.push_back(rfrm);
     268  inf.push_back(dpl);
     269  return inf;
     270}
     271
     272void SDMemTable::setCoordInfo(std::vector<string> theinfo) {
     273
     274  std::vector<string>::iterator it;
     275  String un,rfrm,dpl;
     276  un = theinfo[0];
     277  rfrm = theinfo[1];
     278  dpl = theinfo[2];
     279
     280  //String un(theunit);
     281  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
     282  Vector<Double> rstf;
     283  t.keywordSet().get("RESTFREQS",rstf);
     284  Bool canDo = True;
     285  Unit u1("km/s");Unit u2("Hz");
     286  if (Unit(un) == u1) {
     287    Vector<Double> rstf;
     288    t.keywordSet().get("RESTFREQS",rstf);
     289    if (rstf.nelements() == 0) {
     290        throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
     291    }
     292  } else if (Unit(un) != u2 && un != "") {
     293        throw(AipsError("Unit not conformant with Spectral Coordinates"));
     294  }
     295  t.rwKeywordSet().define("UNIT", un);
     296
     297  MFrequency::Types mdr;
     298  if (!MFrequency::getType(mdr, rfrm)) {
     299   
     300    Int a,b;const uInt* c;
     301    const String* valid = MFrequency::allMyTypes(a, b, c);
     302    String pfix = "Please specify a legal frame type. Types are\n";
     303    throw(AipsError(pfix+(*valid)));
     304  } else {
     305    t.rwKeywordSet().define("REFFRAME",rfrm);
     306  }
     307
     308}
     309
     310std::vector<double> SDMemTable::getAbscissa(Int whichRow) {
    247311  std::vector<double> absc(nChan());
    248312  Vector<Double> absc1(nChan());
     
    252316  fid.get(whichRow, v);
    253317  uInt specidx = v(IFSel_);
    254   Unit u;
    255   if (whichUnit == "") {
    256     // get unit from table
    257   } else {
    258     u = String(whichUnit);
    259   }
    260318  SpectralCoordinate spc = getCoordinate(specidx);
    261319  Table t = table_.keywordSet().asTable("FREQUENCIES");
    262320  String rf;
    263   t.keywordSet().get("REFFRAME",rf);
     321  //t.keywordSet().get("EQUINOX",rf);
    264322  MDirection::Types mdr;
    265   MDirection::getType(mdr, rf);
     323  //if (!MDirection::getType(mdr, rf)) {
     324  mdr = MDirection::J2000;
     325  //cout << "Unknown equinox using J2000" << endl;
     326  //}
    266327  ROArrayColumn<Double> dir(table_, "DIRECTION");
    267328  Array<Double> posit;
     
    276337  Double obstime;
    277338  tme.get(whichRow,obstime);
    278   //Quantum<Double> tm(obstime, Unit(String("d")));
    279339  MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
    280340  MEpoch epoch(tm2);
     
    282342  Vector<Double> antpos;
    283343  table_.keywordSet().get("AntennaPosition", antpos);
    284   //MPosition pos;
    285344  MVPosition mvpos(antpos(0),antpos(1),antpos(2));
    286345  MPosition pos(mvpos);
    287   //MeasTable::Observatory(pos, String("ATCA"));
    288 
     346  String sunit;
     347  t.keywordSet().get("UNIT",sunit);
     348  if (sunit == "") sunit = "pixel";
     349  Unit u(sunit);
     350  String frm;
     351  t.keywordSet().get("REFFRAME",frm);
     352  if (frm == "") frm = "TOPO";
     353  String dpl;
     354  t.keywordSet().get("DOPPLER",dpl);
     355  if (dpl == "") dpl = "RADIO";
    289356  MFrequency::Types mtype;
    290   if (!MFrequency::getType(mtype, whichFrame)) {
     357  if (!MFrequency::getType(mtype, frm)) {
    291358    cout << "Frequency type unknown assuming TOPO" << endl;
    292359    mtype = MFrequency::TOPO;
    293360  }
    294   spc.setReferenceConversion(mtype,epoch,pos,direct);
     361 
     362  if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) {
     363    throw(AipsError("Couldn't convert frequency frame."));
     364  }
    295365
    296366  if ( u == Unit("km/s") ) {
     
    298368    t.keywordSet().get("RESTFREQS",rstf);
    299369    if (rstf.nelements() > 0) {
    300       cout << "converting to velocities"<< endl;
    301       //spc.setRestFrequency(Double(restfreq));
    302370      spc.setVelocity(u.getName());
    303371      Vector<Double> wrld;
     
    313381    Vector<String> wau(1); wau = u.getName();
    314382    spc.setWorldAxisUnits(wau);
    315     cout << " converting in frequency" << endl;
    316383    std::vector<double>::iterator it;
    317384    Double tmp;
     
    322389      i++;
    323390    }
     391
     392  } else {
     393    // assume channels/pixels
     394    std::vector<double>::iterator it;
     395    uInt i=0;
     396    for (it = absc.begin(); it != absc.end(); ++it) {
     397      (*it) = Double(i++);
     398    }
    324399  }
    325400  return absc;
     401}
     402
     403std::string SDMemTable::getAbscissaString(Int whichRow)
     404{
     405  ROArrayColumn<uInt> fid(table_, "FREQID");
     406  Table t = table_.keywordSet().asTable("FREQUENCIES");
     407  String sunit;
     408  t.keywordSet().get("UNIT",sunit);
     409  if (sunit == "") sunit = "pixel";
     410  Unit u(sunit);
     411  Vector<uInt> v;
     412  fid.get(whichRow, v);
     413  uInt specidx = v(IFSel_);
     414  SpectralCoordinate spc = getCoordinate(specidx);
     415  String frm;
     416  t.keywordSet().get("REFFRAME",frm);
     417  MFrequency::Types mtype;
     418  if (!MFrequency::getType(mtype, frm)) {
     419    cout << "Frequency type unknown assuming TOPO" << endl;
     420    mtype = MFrequency::TOPO;
     421  }
     422  spc.setFrequencySystem(mtype);
     423  String s = "Channel";
     424  if (u == Unit("km/s")) {
     425    spc.setVelocity(u.getName());
     426    s = CoordinateUtil::axisLabel(spc,0,True,True,True);
     427  } else if (u == Unit("Hz")) {
     428    Vector<String> wau(1);wau = u.getName();
     429    spc.setWorldAxisUnits(wau);
     430    s = CoordinateUtil::axisLabel(spc);
     431  }
     432  return s;
    326433}
    327434
     
    472579  ROScalarColumn<Double> incc(t, "INCREMENT");
    473580  t.keywordSet().get("RESTFREQS",vec);
    474   t.keywordSet().get("REFFRAME",rf);
     581  t.keywordSet().get("BASEREFFRAME",rf);
    475582
    476583  MFrequency::Types mft;
     
    482589  rvc.get(whichIdx, rv);
    483590  incc.get(whichIdx, inc);
    484   //cerr << "creating speccord from " << whichIdx << ": "
    485   //     << rp <<", " << rv << ", " << inc << ", " << mft <<endl;
    486591  SpectralCoordinate spec(mft,rv,inc,rp);
    487592  if (vec.nelements() > 0)
     
    520625  Table t = table_.keywordSet().asTable("FREQUENCIES");
    521626  t.rwKeywordSet().define("RESTFREQS",tvec);
    522 
    523627}
    524628
     
    538642    sc2.put(i,sdft.increment(i));
    539643  }
    540   aTable.rwKeywordSet().define("REFFRAME", sdft.refFrame());
     644  String rf = sdft.refFrame();
     645  if (rf.contains("TOPO")) rf = "TOPO";
     646
     647  aTable.rwKeywordSet().define("BASEREFFRAME", rf);
     648  aTable.rwKeywordSet().define("REFFRAME", rf);
    541649  aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
    542   aTable.rwKeywordSet().define("Unit", String("kms-1"));
     650  aTable.rwKeywordSet().define("UNIT", String(""));
     651  aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
    543652  Vector<Double> rfvec;
    544653  aTable.rwKeywordSet().define("RESTFREQS", rfvec);
     
    556665  ScalarColumn<Double> mjd(table_, "TIME");
    557666  ScalarColumn<String> srcn(table_, "SRCNAME");
     667  ScalarColumn<String> fldn(table_, "FIELDNAME");
    558668  ArrayColumn<Float> spec(table_, "SPECTRA");
    559669  ArrayColumn<uChar> flags(table_, "FLAGTRA");
     
    563673  ArrayColumn<uInt> freqid(table_, "FREQID");
    564674  ArrayColumn<Double> dir(table_, "DIRECTION");
     675  ScalarColumn<Int> rbeam(table_, "REFBEAM");
     676  ArrayColumn<Float> tcal(table_, "TCAL");
     677  ScalarColumn<String> tcalt(table_, "TCALTIME");
     678  ScalarColumn<Float> az(table_, "AZIMUTH");
     679  ScalarColumn<Float> el(table_, "ELEVATION");
     680  ScalarColumn<Float> para(table_, "PARANGLE");
    565681
    566682  uInt rno = table_.nrow();
     
    569685  mjd.put(rno, sdc.timestamp);
    570686  srcn.put(rno, sdc.sourcename);
     687  fldn.put(rno, sdc.fieldname);
    571688  spec.put(rno, sdc.getSpectrum());
    572689  flags.put(rno, sdc.getFlags());
     
    576693  freqid.put(rno, sdc.getFreqMap());
    577694  dir.put(rno, sdc.getDirection());
     695  rbeam.put(rno, sdc.refbeam);
     696  tcal.put(rno, sdc.tcal);
     697  tcalt.put(rno, sdc.tcaltime);
     698  az.put(rno, sdc.azimuth);
     699  el.put(rno, sdc.elevation);
     700  para.put(rno, sdc.parangle);
    578701
    579702  return true;
     
    583706  ROScalarColumn<Double> mjd(table_, "TIME");
    584707  ROScalarColumn<String> srcn(table_, "SRCNAME");
     708  ROScalarColumn<String> fldn(table_, "FIELDNAME");
    585709  ROArrayColumn<Float> spec(table_, "SPECTRA");
    586710  ROArrayColumn<uChar> flags(table_, "FLAGTRA");
     
    590714  ROArrayColumn<uInt> freqid(table_, "FREQID");
    591715  ROArrayColumn<Double> dir(table_, "DIRECTION");
     716  ROScalarColumn<Int> rbeam(table_, "REFBEAM");
     717  ROArrayColumn<Float> tcal(table_, "TCAL");
     718  ROScalarColumn<String> tcalt(table_, "TCALTIME");
     719  ROScalarColumn<Float> az(table_, "AZIMUTH");
     720  ROScalarColumn<Float> el(table_, "ELEVATION");
     721  ROScalarColumn<Float> para(table_, "PARANGLE");
    592722
    593723  SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
     
    596726  integr.get(whichRow, sdc.interval);
    597727  scan.get(whichRow, sdc.scanid);
     728  fldn.get(whichRow, sdc.fieldname);
     729  rbeam.get(whichRow, sdc.refbeam);
     730  az.get(whichRow, sdc.azimuth);
     731  el.get(whichRow, sdc.elevation);
     732  para.get(whichRow, sdc.parangle);
     733  Vector<Float> tc;
     734  tcal.get(whichRow, tc);
     735  sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
     736  tcalt.get(whichRow, sdc.tcaltime);
    598737  Array<Float> spectrum;
    599738  Array<Float> tsys;
     
    670809}
    671810
    672 std::string SDMemTable::summary() const {
     811String SDMemTable::formatSec(Double x) {
     812  Double xcop = x;
     813  MVTime mvt(xcop/24./3600.);  // make days
     814  if (x < 59.95)
     815    return  String("   ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
     816  return mvt.string(MVTime::TIME_CLEAN_NO_H, 7)+" ";
     817};
     818
     819std::string SDMemTable::summary()  {
    673820  ROScalarColumn<Int> scans(table_, "SCANID");
    674821  ROScalarColumn<String> srcs(table_, "SRCNAME");
     
    679826  oss << "--------------------------------------------------" << endl;
    680827  oss.flags(std::ios_base::left);
    681   //oss.width(15);
    682828  oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
    683829      << setw(15) << "IFs:" << setw(4) << nIF() << endl
     
    694840  table_.keywordSet().get("AntennaName", tmp);
    695841  oss << setw(15) << "Antenna Name:" << tmp << endl;
     842  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
     843  Vector<Double> vec;
     844  t.keywordSet().get("RESTFREQS",vec);
     845  oss << setw(15) << "Rest Freqs:";
     846  if (vec.nelements() > 0) {
     847      oss << setprecision(0) << vec << " [Hz]" << endl;
     848  } else {
     849      oss << "None set" << endl;
     850  }
     851  oss << setw(15) << "Abscissa:" << getAbscissaString() << endl;
     852  oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
     853      << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
    696854  oss << endl;
    697855  uInt count = 0;
     
    703861      << setw(21) << "Time"
    704862      << setw(11) << "Integration" << endl;
     863  oss << "--------------------------------------------------" << endl;
    705864  for (uInt i=0; i< scans.nrow();i++) {
    706865    scans.getScalar(i,current);
     
    708867      srcs.getScalar(i,name);
    709868      previous = current;
    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";
    716       }
     869      String t = formatSec(Double(getInterval(i)));
    717870      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;
     871          << setw(2) << setprecision(1)
     872          << t << endl;
    720873      count++;
    721874    } else {
Note: See TracChangeset for help on using the changeset viewer.