Changeset 286


Ignore:
Timestamp:
01/24/05 17:53:53 (19 years ago)
Author:
kil064
Message:

consolidate some SpectralCoordinate? creation activities in getSpectralCoordinate
functions. Add some other small convenience functions.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r281 r286  
    4141#include <casa/Arrays/ArrayAccessor.h>
    4242#include <casa/Arrays/Vector.h>
     43#include <casa/Quanta/MVAngle.h>
    4344
    4445#include <tables/Tables/TableParse.h>
     
    364365}
    365366
     367
    366368std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
    367369{
    368   std::vector<double> absc(nChan());
    369   Vector<Double> absc1(nChan());
    370   indgen(absc1);
    371   ROArrayColumn<uInt> fid(table_, "FREQID");
    372   Vector<uInt> v;
    373   fid.get(whichRow, v);
    374   uInt specidx = v(IFSel_);
    375   SpectralCoordinate spc = getCoordinate(specidx);
    376   Table t = table_.keywordSet().asTable("FREQUENCIES");
    377 
    378   MDirection direct = getDirection(whichRow);
    379 
    380   ROScalarColumn<Double> tme(table_, "TIME");
    381   Double obstime;
    382   tme.get(whichRow,obstime);
    383   MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
    384   MEpoch::Types met = getTimeReference();
    385   MEpoch epoch(tm2, met);
    386 
    387   Vector<Double> antpos;
    388   table_.keywordSet().get("AntennaPosition", antpos);
    389   MVPosition mvpos(antpos(0),antpos(1),antpos(2));
    390   MPosition pos(mvpos);
    391   String sunit;
    392   t.keywordSet().get("UNIT",sunit);
    393   if (sunit == "") sunit = "pixel";
    394   Unit u(sunit);
    395   String frm;
    396   t.keywordSet().get("REFFRAME",frm);
    397   if (frm == "") frm = "TOPO";
    398   String dpl;
    399   t.keywordSet().get("DOPPLER",dpl);
    400   if (dpl == "") dpl = "RADIO";
    401   MFrequency::Types mtype;
    402   if (!MFrequency::getType(mtype, frm)) {
    403     cout << "Frequency type unknown assuming TOPO" << endl;       // SHould never happen
    404     mtype = MFrequency::TOPO;
    405   }
    406   MDoppler::Types dtype;
    407   if (!MDoppler::getType(dtype, dpl)) {
    408     cout << "Doppler type unknown assuming RADIO" << endl;        // SHould never happen
    409     dtype = MDoppler::RADIO;
    410   }
    411  
    412   if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) {
    413     throw(AipsError("Couldn't convert frequency frame."));
    414   }
    415 
    416   if ( u == Unit("km/s") ) {
    417     Vector<Double> rstf;
    418     t.keywordSet().get("RESTFREQS",rstf);
    419     if (rstf.nelements() > 0) {
    420       if (rstf.nelements() >= nIF())
    421         spc.selectRestFrequency(uInt(IFSel_));
    422       spc.setVelocity(u.getName(),dtype);
    423       Vector<Double> wrld;
    424       spc.pixelToVelocity(wrld,absc1);
    425       std::vector<double>::iterator it;
    426       uInt i = 0;
    427       for (it = absc.begin(); it != absc.end(); ++it) {
    428         (*it) = wrld[i];
    429         i++;
    430       }
    431     }
    432   } else if (u == Unit("Hz")) {
    433     Vector<String> wau(1); wau = u.getName();
    434     spc.setWorldAxisUnits(wau);
    435     std::vector<double>::iterator it;
    436     Double tmp;
    437     uInt i = 0;
    438     for (it = absc.begin(); it != absc.end(); ++it) {
    439       spc.toWorld(tmp,absc1[i]);
    440       (*it) = tmp;
    441       i++;
    442     }
    443 
    444   } else {
    445     // assume channels/pixels
    446     std::vector<double>::iterator it;
    447     uInt i=0;
    448     for (it = absc.begin(); it != absc.end(); ++it) {
    449       (*it) = Double(i++);
    450     }
    451   }
    452   return absc;
    453 }
    454 
    455 std::string SDMemTable::getAbcissaString(Int whichRow) const
    456 {
    457   ROArrayColumn<uInt> fid(table_, "FREQID");
     370  std::vector<double> abc(nChan());
     371
     372// Get header units keyword
     373
    458374  Table t = table_.keywordSet().asTable("FREQUENCIES");
    459375  String sunit;
     
    461377  if (sunit == "") sunit = "pixel";
    462378  Unit u(sunit);
     379
     380// Easy if just wanting pixels
     381
     382  if (sunit==String("pixel")) {
     383    // assume channels/pixels
     384    std::vector<double>::iterator it;
     385    uInt i=0;
     386    for (it = abc.begin(); it != abc.end(); ++it) {
     387      (*it) = Double(i++);
     388    }
     389//
     390    return abc;
     391  }
     392
     393// Continue with km/s or Hz.  Get FreqID
     394
     395  ROArrayColumn<uInt> fid(table_, "FREQID");
    463396  Vector<uInt> v;
    464397  fid.get(whichRow, v);
    465398  uInt specidx = v(IFSel_);
    466   SpectralCoordinate spc = getCoordinate(specidx);
    467   String frm;
    468   t.keywordSet().get("REFFRAME",frm);
    469 //
    470   MFrequency::Types mtype;
    471   if (!MFrequency::getType(mtype, frm)) {
    472     cout << "Frequency type unknown assuming TOPO" << endl;
    473     mtype = MFrequency::TOPO;
    474   }
    475   spc.setFrequencySystem(mtype);
    476 //
    477   String dpl;
    478   t.keywordSet().get("DOPPLER",dpl);
    479   MDoppler::Types dtype;
    480   MDoppler::getType(dtype, dpl);         // Can't fail
     399
     400// Get SpectralCoordinate, set reference frame conversion,
     401// velocity conversion, and rest freq state
     402
     403  SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
     404//
     405  Vector<Double> pixel(nChan());
     406  indgen(pixel);
     407//
     408  if (u == Unit("km/s")) {
     409     Vector<Double> world;
     410     spc.pixelToVelocity(world,pixel);
     411     std::vector<double>::iterator it;
     412     uInt i = 0;
     413     for (it = abc.begin(); it != abc.end(); ++it) {
     414       (*it) = world[i];
     415       i++;
     416     }
     417  } else if (u == Unit("Hz")) {
     418
     419// Set world axis units
     420
     421    Vector<String> wau(1); wau = u.getName();
     422    spc.setWorldAxisUnits(wau);
     423//
     424    std::vector<double>::iterator it;
     425    Double tmp;
     426    uInt i = 0;
     427    for (it = abc.begin(); it != abc.end(); ++it) {
     428      spc.toWorld(tmp,pixel[i]);
     429      (*it) = tmp;
     430      i++;
     431    }
     432  }
     433  return abc;
     434}
     435
     436std::string SDMemTable::getAbcissaString(Int whichRow) const
     437{
     438  ROArrayColumn<uInt> fid(table_, "FREQID");
     439  Table t = table_.keywordSet().asTable("FREQUENCIES");
     440//
     441  String sunit;
     442  t.keywordSet().get("UNIT",sunit);
     443  if (sunit == "") sunit = "pixel";
     444  Unit u(sunit);
     445//
     446  Vector<uInt> v;
     447  fid.get(whichRow, v);
     448  uInt specidx = v(IFSel_);
     449
     450// Get SpectralCoordinate, with frame, velocity, rest freq state set
     451
     452  SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
    481453//
    482454  String s = "Channel";
    483455  if (u == Unit("km/s")) {
    484     spc.setVelocity(u.getName(), dtype);
    485456    s = CoordinateUtil::axisLabel(spc,0,True,True,True);
    486457  } else if (u == Unit("Hz")) {
    487458    Vector<String> wau(1);wau = u.getName();
    488459    spc.setWorldAxisUnits(wau);
    489     s = CoordinateUtil::axisLabel(spc);
     460//
     461    s = CoordinateUtil::axisLabel(spc,0,True,True,False);
    490462  }
    491463  return s;
     
    639611  Quantum<Double> lon(wpos[0],Unit(String("rad")));
    640612  Quantum<Double> lat(wpos[1],Unit(String("rad")));
    641   MDirection direct(lon, lat, mdr);
    642   return direct;
    643 }
    644 
    645 SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const
     613  return MDirection(lon, lat, mdr);
     614}
     615
     616MEpoch SDMemTable::getEpoch (Int whichRow) const
     617{
     618  MEpoch::Types met = getTimeReference();
     619//
     620  ROScalarColumn<Double> tme(table_, "TIME");
     621  Double obstime;
     622  tme.get(whichRow,obstime);
     623  MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
     624  return MEpoch(tm2, met);
     625}
     626
     627MPosition SDMemTable::getAntennaPosition () const
     628{
     629  Vector<Double> antpos;
     630  table_.keywordSet().get("AntennaPosition", antpos);
     631  MVPosition mvpos(antpos(0),antpos(1),antpos(2));
     632  return MPosition(mvpos);
     633}
     634
     635
     636SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx) const
    646637{
    647638 
    648639  Table t = table_.keywordSet().asTable("FREQUENCIES");
    649640  if (whichIdx > t.nrow() ) {
    650     throw(AipsError("SDMemTable::getCoordinate - whichIdx out of range"));
     641    throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range"));
    651642  }
    652643
    653644  Double rp,rv,inc;
    654645  String rf;
    655   Vector<Double> vec;
    656646  ROScalarColumn<Double> rpc(t, "REFPIX");
    657647  ROScalarColumn<Double> rvc(t, "REFVAL");
    658648  ROScalarColumn<Double> incc(t, "INCREMENT");
    659   t.keywordSet().get("RESTFREQS",vec);
    660649  t.keywordSet().get("BASEREFFRAME",rf);
     650
     651// Create SpectralCoordinate (units Hz)
    661652
    662653  MFrequency::Types mft;
     
    668659  rvc.get(whichIdx, rv);
    669660  incc.get(whichIdx, inc);
     661//
    670662  SpectralCoordinate spec(mft,rv,inc,rp);
    671   if (vec.nelements() > 0)
     663//
     664  return spec;
     665}
     666
     667
     668SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx, uInt whichRow) const
     669{
     670// Create basic SC
     671
     672  SpectralCoordinate spec = getSpectralCoordinate (whichIdx);
     673//
     674  Table t = table_.keywordSet().asTable("FREQUENCIES");
     675
     676// Set rest frequencies
     677
     678  Vector<Double> vec;
     679  t.keywordSet().get("RESTFREQS",vec);
     680  if (vec.nelements() > 0) {
    672681    spec.setRestFrequencies(vec);
     682
     683// Select rest freq
     684
     685    if (vec.nelements() >= nIF()) {
     686       spec.selectRestFrequency(uInt(IFSel_));
     687    }
     688  }
     689
     690// Set up frame conversion layer
     691
     692  String frm;
     693  t.keywordSet().get("REFFRAME",frm);
     694  if (frm == "") frm = "TOPO";
     695  MFrequency::Types mtype;
     696  if (!MFrequency::getType(mtype, frm)) {
     697    cout << "Frequency type unknown assuming TOPO" << endl;       // SHould never happen
     698    mtype = MFrequency::TOPO;
     699  }
     700
     701// Set reference frame conversion  (requires row)
     702
     703  MDirection direct = getDirection(whichRow);
     704  MEpoch epoch = getEpoch(whichRow);
     705  MPosition pos = getAntennaPosition();
     706  if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) {
     707    throw(AipsError("Couldn't convert frequency frame."));
     708  }
     709
     710// Now velocity conversion if appropriate
     711
     712  String unitStr;
     713  t.keywordSet().get("UNIT",unitStr);
     714//
     715  String dpl;
     716  t.keywordSet().get("DOPPLER",dpl);
     717  MDoppler::Types dtype;
     718  MDoppler::getType(dtype, dpl);
     719
     720// Only set velocity unit if non-blank and non-Hz
     721
     722  if (!unitStr.empty()) {
     723     Unit unitU(unitStr);
     724     if (unitU==Unit("Hz")) {
     725     } else {
     726        spec.setVelocity(unitStr, dtype);
     727     }
     728  }
     729//
    673730  return spec;
    674731}
     732
    675733
    676734Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
  • trunk/src/SDMemTable.h

    r281 r286  
    9797  std::string getTime(casa::Int whichRow=0,
    9898                      casa::Bool showDate=casa::False) const ;
     99  casa::MEpoch getEpoch(casa::Int whichRow=0) const;
     100  casa::MDirection getDirection(casa::Int whichRow=0,
     101                                casa::Bool refBeam=casa::False) const;
     102//
    99103  std::string getSourceName(casa::Int whichRow=0) const;
    100104  double getInterval(casa::Int whichRow=0) const;
     
    164168                                                  casa::False) const;
    165169
    166   casa::SpectralCoordinate getCoordinate(casa::uInt whichIdx) const;
     170  // Return SC, setting only the basic construction state (i.e.
     171  // no conversion or velocity or rest frequency state)
     172  casa::SpectralCoordinate getSpectralCoordinate(casa::uInt whichIdx) const;
     173
     174  // Return SC. Set velocity conversion state (unit,doppler),
     175  // set rest frequencies.  If row number given (>-0), also set
     176  // frame conversion layer (needs direction & time which require row)
     177  casa::SpectralCoordinate getSpectralCoordinate(casa::uInt whichIdx, casa::uInt row) const;
     178
     179  // Set just the reference value, pixel and increment into the table
     180  // No other state is extracted.
    167181  casa::Bool setCoordinate(const casa::SpectralCoordinate& speccord,
    168182                           casa::uInt whichIdx);
     
    170184  casa::Int nCoordinates() const;
    171185
    172 
    173186  std::vector<double> getAbcissa(int whichRow=0) const;
    174187  std::string getAbcissaString(casa::Int whichRow=0) const;
    175188
    176 // Get MDirection for this row
    177   casa::MDirection getDirection(casa::Int whichRow=0,
    178                                 casa::Bool refBeam=casa::False) const;
    179 
    180 // Get gloabl Direction reference
     189// Get global reference  types
    181190  casa::MDirection::Types getDirectionReference() const;
    182 
    183 // Get global Time reference
    184191  casa::MEpoch::Types getTimeReference() const;
     192
     193// Get global antenna position
     194  casa::MPosition getAntennaPosition() const;
    185195
    186196// Helper function to check instrument (antenna) name and give enum
Note: See TracChangeset for help on using the changeset viewer.