Changeset 2711


Ignore:
Timestamp:
12/27/12 17:37:43 (12 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: Yes (CAS-4141/CSV-1526)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: Added asap.sbseparator.set_lo1root() = SBSeparator::set_lo1root(),

and STSideBandSep::setLO1Root()

Test Programs:

Put in Release Notes: No

Module(s): sbseparator and STSideBandSep

Description:

Added a new python method asap.sbseparator.set_lo1root() to set MS
name to search for LO1 frequency.
Underlying c++ functions are SBSeparator::set_lo1root (interface) and STSideBandSep::setLO1Root().
Also developed a capability to get relevant table names from scantable header and
fill frequencies of image side band.


Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/sbseparator.py

    r2707 r2711  
    4949        self.solveother = False
    5050        self.dirtol = [1.e-5, 1.e-5] # direction tolerance in rad (2 arcsec)
    51         self.lo1 = 0.
     51        #self.lo1 = 0.
    5252
    5353        self.tables = []
     
    5757        self.set_data(infiles)
    5858       
    59         #self.separator = sidebandsep()
     59        self.separator = SBSeparator()
    6060
    6161    @asaplog_post_dec
     
    221221        lo1 : LO1 frequency in float
    222222        """
     223        lo1val = -1.
    223224        if isinstance(lo1, dict) and lo1["unit"] == "Hz":
    224             self.lo1 = lo1["value"]
    225         else:
    226             self.lo1 = float(lo1)
    227         if self.lo1 <= 0.:
     225            lo1val = lo1["value"]
     226        else:
     227            lo1val = float(lo1)
     228        if lo1val <= 0.:
    228229            asaplog.push("Got negative LO1 frequency. It will be ignored.")
    229230            asaplog.post("WARN")
     231        else:
     232            self.separator.set_lo1(lo1val)
     233
     234
     235    def set_lo1root(self, name):
     236        """
     237        Set MS name which stores LO1 frequency of signal side band.
     238        It is used to calculate frequency of image sideband.
     239
     240        name : MS name which contains 'ASDM_SPECTRALWINDOW' and
     241               'ASDM_RECEIVER' tables.
     242        """
     243        self.separator.set_lo1root(name)
    230244
    231245
     
    289303            asaplog.post()
    290304            asaplog.push("Saving IMAGE sideband.")
    291             asaplog.push("Note, frequency information of IMAGE sideband cannot be properly filled so far. (future development)")
    292             asaplog.push("Storing frequency setting of SIGNAL sideband in FREQUENCIES table for now.")
    293             asaplog.post("WARN")
     305            #asaplog.push("Note, frequency information of IMAGE sideband cannot be properly filled so far. (future development)")
     306            #asaplog.push("Storing frequency setting of SIGNAL sideband in FREQUENCIES table for now.")
     307            #asaplog.post("WARN")
    294308
    295309            imagename = outname + ".imageband"
     
    300314                    shutil.rmtree(imagename)
    301315            # Update frequency information
    302             sbsep = SBSeparator()
    303             sbsep.set_imgtable(imagetab)
    304             if self.lo1 > 0.:
    305                 sbsep.set_lo1(self.lo1)
    306             sbsep.solve_imgfreq()
     316            self.separator.set_imgtable(imagetab)
     317            self.separator.solve_imgfreq()
    307318            imagetab.save(imagename)
    308             del sbsep
    309319
    310320
  • trunk/src/STSideBandSep.cpp

    r2709 r2711  
    2121#include <measures/Measures/MCFrequency.h>
    2222
     23#include <tables/Tables/TableRow.h>
    2324#include <tables/Tables/TableRecord.h>
    2425#include <tables/Tables/TableVector.h>
     
    9899};
    99100
    100 void STSideBandSep::setLO1Asdm(string asdmname)
    101 {
    102   // Check for existance of the asdm.
    103   if (!checkFile(asdmname)) {
     101void STSideBandSep::setLO1Root(string name)
     102{
     103   LogIO os(LogOrigin("STSideBandSep","setLO1Root()", WHERE));
     104   os << "Searching for '" << name << "'..." << LogIO::POST;
     105  // Check for existance of the file
     106  if (!checkFile(name)) {
    104107     throw(AipsError("File does not exist"));
    105108  }
    106   if (asdmname[(asdmname.size()-1)] == '/')
    107     asdmname = asdmname.substr(0,(asdmname.size()-2));
    108 
    109   asdmName_ = asdmname;
    110 
    111 #ifdef KS_DEBUG
    112   cout << "STSideBandSep::setLO1Asdm" << endl;
    113   cout << "asdm name = " << asdmName_ << endl;
     109  if (name[(name.size()-1)] == '/')
     110    name = name.substr(0,(name.size()-2));
     111
     112  if (checkFile(name+"/Receiver.xml", "file") &&
     113      checkFile(name+"/SpectralWindow.xml", "file")){
     114    os << "Found '" << name << "/Receiver.xml' ... got an ASDM name." << LogIO::POST;
     115    asdmName_ = name;
     116  } else if (checkFile(name+"/ASDM_RECEIVER") &&
     117             checkFile(name+"/ASDM_SPECTRALWINDOW")){
     118    os << "Found '" << name << "/ASDM_RECEIVER' ... got a Table name." << LogIO::POST;
     119    asisName_ = name;
     120  } else {
     121    throw(AipsError("Invalid file name. Set an MS or ASDM name."));
     122  }
     123
     124#ifdef KS_DEBUG
     125  cout << "STSideBandSep::setLO1Root" << endl;
     126  if (!asdmName_.empty())
     127    cout << "asdm name = " << asdmName_ << endl;
     128  if (!asisName_.empty())
     129    cout << "MS name = " << asisName_ << endl;
    114130#endif
    115131};
     
    126142    throw AipsError("STSideBandSep::solveImageFreqency - an image side band scantable should be set first");
    127143
    128   // Check for the availability of LO1
    129   os << "Looking for LO1. lo1Freq_ = " << lo1Freq_ << LogIO::POST;
    130   if (lo1Freq_ > 0.) {
    131     os << "Using user defined LO1 frequency." << LogIO::POST;
    132   } else if (!asdmName_.empty() > 0) {
    133       // ASDM name is set.
    134     os << "Using user defined ASDM: " << asdmName_ << LogIO::POST;
    135     if (!getLo1FromAsdm(asdmName_)) {
    136       throw AipsError("Failed to get LO1 frequency from ASDM");
    137     }
    138   } else {
    139     // Try getting ASDM name from scantable header
    140     os << "Try getting information from scantable header" << LogIO::POST;
    141     if (!getLo1FromTab(imgTab_p)) {
    142       throw AipsError("Failed to get LO1 frequency from asis table");
    143     }
    144   }
    145   // LO1 should now be ready.
    146   if (lo1Freq_ < 0.)
    147     throw(AipsError("Got negative LO1 Frequency"));
    148 
     144  // Convert frequency REFVAL to the value in frame of LO.
    149145  // The code assumes that imgTab_p has only an IF and only a FREQ_ID
    150146  // is associated to an IFNO
     
    160156  // assuming single freqID per IFNO
    161157  uInt freqid = freqIdVec(0);
     158  int nChan = imgTab_p->nchan(imgTab_p->getIF(0));
    162159  double refpix, refval, increment ;
    163160  freqTab_.getEntry(refpix, refval, increment, freqid);
     
    203200    md = MDirection(ra.getValue("rad"), dec.getValue("rad"),epoch);
    204201  }
    205   // Summary (LO1)
     202  MeasFrame mframe( me, mp, md );
     203  MFrequency::Convert tobframe(loFrame_, MFrequency::Ref(tabframe, mframe));
     204  MFrequency::Convert toloframe(tabframe, MFrequency::Ref(loFrame_, mframe));
     205  // Convert refval to loFrame_
     206  double sigrefval;
     207  if (tabframe == loFrame_)
     208    sigrefval = refval;
     209  else
     210    sigrefval = toloframe(Quantum<Double>(refval, "Hz")).get("Hz").getValue();
     211
     212
     213  // Check for the availability of LO1
     214  if (lo1Freq_ > 0.) {
     215    os << "Using user defined LO1 frequency." << LogIO::POST;
     216  } else if (!asisName_.empty()) {
     217      // MS name is set.
     218    os << "Using user defined MS (asis): " << asisName_ << LogIO::POST;
     219    if (!getLo1FromAsisTab(asisName_, sigrefval, refpix, increment, nChan)) {
     220      throw AipsError("Failed to get LO1 frequency from MS");
     221    }
     222  } else if (!asdmName_.empty()) {
     223      // ASDM name is set.
     224    os << "Using user defined ASDM: " << asdmName_ << LogIO::POST;
     225    if (!getLo1FromAsdm(asdmName_, sigrefval, refpix, increment, nChan)) {
     226      throw AipsError("Failed to get LO1 frequency from ASDM");
     227    }
     228  } else {
     229    // Try getting ASDM name from scantable header
     230    os << "Try getting information from scantable header" << LogIO::POST;
     231    if (!getLo1FromScanTab(imgTab_p, sigrefval, refpix, increment, nChan)) {
     232      //throw AipsError("Failed to get LO1 frequency from asis table");
     233      os << LogIO::WARN << "Failed to get LO1 frequency using information in scantable." << LogIO::POST;
     234      os << LogIO::WARN << "Could not fill frequency information of IMAGE sideband properly." << LogIO::POST;
     235      os << LogIO::WARN << "Storing values of SIGNAL sideband in FREQUENCIES table" << LogIO::POST;
     236      return;
     237    }
     238  }
     239  // LO1 should now be ready.
     240  if (lo1Freq_ < 0.)
     241    throw(AipsError("Got negative LO1 Frequency"));
     242
     243  // Print summary (LO1)
    206244  Vector<Double> dirvec = md.getAngle(Unit(String("rad"))).getValue();
    207245  os << "[LO1 settings]" << LogIO::POST;
     
    212250  os << "- Reference direction: [" << dirvec[0] << ", " << dirvec[1]
    213251     << "] (" << md.getRefString() << ") " << LogIO::POST;
    214   //
    215   MeasFrame mframe( me, mp, md );
    216   MFrequency::Convert tobframe(loFrame_, MFrequency::Ref(tabframe, mframe));
    217   MFrequency::Convert toloframe(tabframe, MFrequency::Ref(loFrame_, mframe));
    218   // convert refval to loFrame_
    219   double sigrefval;
    220   if (tabframe == loFrame_)
    221     sigrefval = refval;
    222   else
    223     sigrefval = toloframe(Quantum<Double>(refval, "Hz")).get("Hz").getValue();
    224 
    225   //Summary (signal)
     252
     253  //Print summary (signal)
    226254  os << "[Signal side band]" << LogIO::POST;
    227255  os << "- IFNO: " << imgTab_p->getIF(0) << " (FREQ_ID = " << freqid << ")"
     
    233261  os << "- Reference pixel: " << refpix  << LogIO::POST;
    234262  os << "- Increment: " << increment << " [Hz]" << LogIO::POST;
    235   // calculate image band incr and refval in loFrame_
     263
     264  // Calculate image band incr and refval in loFrame_
    236265  Double imgincr = -increment;
    237266  Double imgrefval = 2 * lo1Freq_ - sigrefval;
    238267  Double imgrefval_tab = imgrefval;
    239   // convert imgrefval back to table base frame
     268  // Convert imgrefval back to table base frame
    240269  if (tabframe != loFrame_)
    241270    imgrefval = tobframe(Quantum<Double>(imgrefval, "Hz")).get("Hz").getValue();
    242   // set new frequencies table
     271  // Set new frequencies table
    243272  uInt fIDnew = freqTab_.addEntry(refpix, imgrefval, imgincr);
    244   // update freq_ID in table.
     273  // Update FREQ_ID in table.
    245274  freqIdVec = fIDnew;
    246   // Summary (Image side band)
     275
     276  // Print summary (Image side band)
    247277  os << "[Image side band]" << LogIO::POST;
    248278  os << "- IFNO: " << imgTab_p->getIF(0) << " (FREQ_ID = " << freqIdVec(0)
     
    278308};
    279309
    280 bool STSideBandSep::getLo1FromAsdm(const string asdmname)
     310bool STSideBandSep::getLo1FromAsdm(const string asdmname,
     311                                   const double refval,
     312                                   const double refpix,
     313                                   const double increment,
     314                                   const int nChan)
    281315{
    282316  // Check for relevant tables.
     
    292326
    293327
    294 bool STSideBandSep::getLo1FromTab(CountedPtr< Scantable > &scantab)
    295 {
     328bool STSideBandSep::getLo1FromScanTab(CountedPtr< Scantable > &scantab,
     329                                      const double refval,
     330                                      const double refpix,
     331                                      const double increment,
     332                                      const int nChan)
     333{
     334  LogIO os(LogOrigin("STSideBandSep","getLo1FromScanTab()", WHERE));
    296335  Table& tab = scantab->table();
    297336  // Check for relevant tables.
    298   const String spwname = tab.keywordSet().asString("ASDM_SPECTRALWINDOW");
    299   const String recname = tab.keywordSet().asString("ASDM_RECEIVER");
     337  String spwname, recname;
     338  try {
     339    spwname = tab.keywordSet().asString("ASDM_SPECTRALWINDOW");
     340    recname = tab.keywordSet().asString("ASDM_RECEIVER");
     341  } catch (...) {
     342    // keywords are not there
     343    os << LogIO::WARN
     344       << "Could not find necessary table names in scantable header."
     345       << LogIO::POST;
     346    return false;
     347  }
    300348  if (!checkFile(spwname,"directory") || !checkFile(recname,"directory")) {
    301     throw(AipsError("Could not find subtables in MS"));
    302   }
    303   // get
    304 
     349    throw(AipsError("Could not find relevant subtables in MS"));
     350  }
     351  // Get root MS name
     352  string msname;
     353  const String recsuff = "/ASDM_RECEIVER";
     354  String::size_type pos;
     355  pos = recname.size()-recsuff.size()-1;
     356  if (recname.substr(pos) == recsuff)
     357    msname = recname.substr(0, pos-1);
     358  else
     359    throw(AipsError("Internal error in parsing table name from a scantable keyword."));
     360
     361  if (!checkFile(msname))
     362    throw(AipsError("Internal error in parsing MS name from a scantable keyword."));
     363
     364  return getLo1FromAsisTab(msname, refval, refpix, increment, nChan);
     365
     366};
     367
     368bool STSideBandSep::getLo1FromAsisTab(const string msname,
     369                                      const double refval,
     370                                      const double refpix,
     371                                      const double increment,
     372                                      const int nChan)
     373{
     374  LogIO os(LogOrigin("STSideBandSep","getLo1FromAsisTab()", WHERE));
     375  os << "Searching an LO1 frequency in '" << msname << "'" << LogIO::POST;
     376  // Check for relevant tables.
     377  const string spwname = msname + "/ASDM_SPECTRALWINDOW";
     378  const string recname = msname + "/ASDM_RECEIVER";
     379  if (!checkFile(spwname,"directory") || !checkFile(recname,"directory")) {
     380    throw(AipsError("Could not find relevant tables in MS"));
     381  }
     382
     383  Table spwtab_ = Table(spwname);
     384  String asdmSpw;
     385  ROTableRow spwrow(spwtab_);
     386  const Double rtol = 0.01;
     387  for (uInt idx = 0; idx < spwtab_.nrow(); idx++){
     388    const TableRecord& rec = spwrow.get(idx);
     389    // Compare nchan
     390    if (rec.asInt("numChan") != (Int) nChan)
     391      continue;
     392    // Compare increment
     393    Double asdminc;
     394    Array<Double> incarr = rec.asArrayDouble("chanWidthArray");
     395    if (incarr.size() > 0)
     396      asdminc = incarr(IPosition(1, (uInt) refpix));
     397    else
     398      asdminc = rec.asDouble("chanWidth");
     399    if (abs(asdminc - abs(increment)) > rtol * abs(increment))
     400      continue;
     401    // Compare refval
     402    Double asdmrefv;
     403    Array<Double> refvarr = rec.asArrayDouble("chanFreqArray");
     404    if (refvarr.size() > 0){
     405      const uInt iref = (uInt) refpix;
     406      const Double ratio = refpix - (Double) iref;
     407      asdmrefv = refvarr(IPosition(1, iref))*(1.-ratio)
     408        + refvarr(IPosition(1,iref+1))*ratio;
     409    }
     410    else {
     411      const Double ch0 = rec.asDouble("chanFreqStart");
     412      const Double chstep = rec.asDouble("chanFreqStep");
     413      asdmrefv = ch0 + chstep * refpix;
     414    }
     415    if (abs(asdmrefv - refval) < 0.5*abs(asdminc)){
     416      asdmSpw = rec.asString("spectralWindowId");
     417      break;
     418    }
     419  }
     420
     421  if (asdmSpw.empty()){
     422    os << LogIO::WARN << "Could not find relevant SPW ID in " << spwname << LogIO::POST;
     423    return false;
     424  }
     425  else {
     426    os << asdmSpw << " in " << spwname
     427       << " matches the freqeuncies of signal side band." << LogIO::POST;
     428  }
     429
     430  Table rectab_ = Table(recname);
     431  ROTableRow recrow(rectab_);
     432  for (uInt idx = 0; idx < rectab_.nrow(); idx++){
     433    const TableRecord& rec = recrow.get(idx);
     434    if (rec.asString("spectralWindowId") == asdmSpw){
     435      const Array<Double> loarr = rec.asArrayDouble("freqLO");
     436      lo1Freq_ = loarr(IPosition(1,0));
     437      os << "Found LO1 Frequency in " << recname << ": "
     438         << lo1Freq_ << " [Hz]" << LogIO::POST;
     439      return true;
     440    }
     441  }
     442  os << LogIO::WARN << "Could not find " << asdmSpw << " in " << recname
     443     << LogIO::POST;
    305444  return false;
    306 
    307 };
    308 
     445};
     446
     447// String STSideBandSep::()
     448// {
     449
     450// };
    309451
    310452} //namespace asap
  • trunk/src/STSideBandSep.h

    r2707 r2711  
    5454   **/
    5555  void setLO1(const double lo1, string frame="TOPO", double reftime=-1, string refdir="");
    56   void setLO1Asdm(const string asdmname);
     56  void setLO1Root(const string name);
    5757  /**
    5858   * Actual calculation of frequencies of image sideband
     
    6262private:
    6363  Bool checkFile(const string name, string type="");
    64   bool getLo1FromAsdm(string asdmname);
    65   bool getLo1FromTab(casa::CountedPtr< Scantable > &scantab);
     64  bool getLo1FromAsdm(const string asdmname,
     65                      const double refval, const double refpix,
     66                      const double increment, const int nChan);
     67  bool getLo1FromAsisTab(const string msname,
     68                         const double refval, const double refpix,
     69                         const double increment, const int nChan);
     70  bool getLo1FromScanTab(casa::CountedPtr< Scantable > &scantab,
     71                         const double refval, const double refpix,
     72                         const double increment, const int nChan);
    6673
    6774  unsigned int sigIfno_;
     
    7178  double loTime_;
    7279  string loDir_;
    73   string asdmName_;
     80  string asdmName_, asisName_;
    7481
    7582  CountedPtr< Scantable > imgTab_p, sigTab_p;
  • trunk/src/python_PlotHelper.cpp

    r2689 r2711  
    11//#---------------------------------------------------------------------------
    2 //# python_PlotHelper.cc: python exposure of c++ PlotHelper class
     2//# python_PlotHelper.cpp: python exposure of c++ PlotHelper class
     3//#---------------------------------------------------------------------------
     4//# Author: Kanako Sugimoto, (C) 2012
     5//#
     6//# Copyright: See COPYING file that comes with this distribution
     7//#
    38//#---------------------------------------------------------------------------
    49#include <boost/python.hpp>
    510#include <boost/python/args.hpp>
    611
    7 #include <string>
    8 #include <vector>
    9 
    1012#include "PlotHelper.h"
    11 #include "ScantableWrapper.h"
     13//#include "ScantableWrapper.h"
    1214
    1315using namespace boost::python;
  • trunk/src/python_STSideBandSep.cpp

    r2707 r2711  
    2727           boost::python::arg("reftime")=-1,
    2828           boost::python::arg("refdir")="") )
    29     //.def( "set_asdm", &STSideBandSep::setLO1Asdm )
     29    .def( "set_lo1root", &STSideBandSep::setLO1Root )
    3030    // temporal methods
    3131    .def( "set_imgtable", &STSideBandSep::setImageTable )
Note: See TracChangeset for help on using the changeset viewer.