Changeset 483


Ignore:
Timestamp:
02/21/05 08:21:00 (19 years ago)
Author:
mar637
Message:
  • Added history support.
  • Added version keyword to SDMemTable.
Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDContainer.cc

    r473 r483  
    479479}
    480480
    481 Bool SDContainer::appendHistory(const String& hist)
    482 {
    483   history_.resize(history_.nelements()+1,True);
    484   history_[history_.nelements()-1] = hist;
    485   return True;
    486 }
    487 Bool SDContainer::putHistory(const Vector<String>& hist)
    488 {
    489   history_.resize();
    490   history_ = hist;
    491   return True;
    492 }
    493 
    494481Bool SDContainer::putFitMap(const Array<Int>& arr) {
    495482  fitIDMap_.resize();
  • trunk/src/SDContainer.h

    r465 r483  
    167167  { return restfreqidx_; }
    168168 
    169   const casa::Vector<casa::String>& getHistory() const { return history_; }
    170   casa::Bool putHistory(const casa::Vector<casa::String>& hist);
    171   casa::Bool appendHistory(const casa::String& hist);
    172 
    173169  casa::Bool putFitMap(const casa::Array<casa::Int>& arr);
    174170
     
    210206  //(nBeam,2) maybe use Measures here...
    211207  casa::Array<casa::Double>   direction_;
    212   casa::Vector<casa::String> history_;
    213208  casa::Array<casa::Int> fitIDMap_;
    214209
  • trunk/src/SDFitter.cc

    r125 r483  
    6060    for (uInt i=0;i< funcs_.nelements();++i) {
    6161        delete funcs_[i]; funcs_[i] = 0;
    62     };
     62    }
    6363    funcs_.resize(0, True);
    6464    parameters_.resize();
     
    146146        funcs_[0] = new Polynomial<Float>(ncomp);
    147147    } else {
    148         cerr << " compiled functions not yet implemented" << endl;
     148        //cerr << " compiled functions not yet implemented" << endl;
    149149        //funcs_.resize(1);
    150150        //funcs_[0] = new CompiledFunction<Float>();
     
    285285        //computeEstimates();
    286286        for (uInt i=0; i<funcs_.nelements(); i++) {
    287             Gaussian1D<AutoDiff<Float> > gauss;
    288             for (uInt j=0; j<funcs_[i]->nparameters(); j++) {
    289                 gauss[j] = AutoDiff<Float>((*funcs_[i])[j], gauss.nparameters(), j);
    290                 gauss.mask(j) = funcs_[i]->mask(j);
     287            Gaussian1D<AutoDiff<Float> > gauss;//(*funcs_[i]);
     288           
     289            for (uInt j=0; j<funcs_[i]->nparameters(); j++) {
     290                gauss[j] = AutoDiff<Float>((*funcs_[i])[j],
     291                                           gauss.nparameters(), j);
     292                gauss.mask(j) = funcs_[i]->mask(j);
    291293            }
     294           
    292295            func.addFunction(gauss);
    293296        }
    294297    } else if (dynamic_cast<Polynomial<Float>* >(funcs_[0]) != 0) {
    295         Polynomial<AutoDiff<Float> > poly(funcs_[0]->nparameters()-1);
    296         for (uInt j=0; j<funcs_[0]->nparameters(); j++) {
    297             poly[j] = AutoDiff<Float>(0, poly.nparameters(), j);
    298             poly.mask(j) = funcs_[0]->mask(j);
    299         }
    300         func.addFunction(poly);
     298        Polynomial<AutoDiff<Float> > poly(funcs_[0]->nparameters()-1);
     299        //Polynomial<AutoDiff<Float> > poly(*funcs_[0]);
     300        for (uInt j=0; j<funcs_[0]->nparameters(); j++) {
     301            poly[j] = AutoDiff<Float>(0, poly.nparameters(), j);
     302            poly.mask(j) = funcs_[0]->mask(j);
     303        }
     304        func.addFunction(poly);
    301305    } else if (dynamic_cast<CompiledFunction<Float>* >(funcs_[0]) != 0) {
    302 
    303 //         CompiledFunction<AutoDiff<Float> > comp;
    304 //         for (uInt j=0; j<funcs_[0]->nparameters(); j++) {
     306       
     307        //         CompiledFunction<AutoDiff<Float> > comp;
     308        //         for (uInt j=0; j<funcs_[0]->nparameters(); j++) {
    305309//             comp[j] = AutoDiff<Float>(0, comp.nparameters(), j);
    306310//             comp.mask(j) = funcs_[0]->mask(j);
    307311//         }
    308312//         func.addFunction(comp);
    309 
     313       
    310314        cout << "NYI." << endl;
    311315    } else {
    312         throw (AipsError("Fitter not set up correctly."));
     316        throw(AipsError("Fitter not set up correctly."));
    313317    }
    314318    fitter.setFunction(func);
     
    316320    // Convergence criterium
    317321    fitter.setCriteria(0.001);
     322
    318323    // Fit
    319324    Vector<Float> sigma(x_.nelements());
    320325    sigma = 1.0;
    321     //Vector<Float> sol;
     326
    322327    parameters_.resize();
    323     //Vector<Float> err;
     328    parameters_ = fitter.fit(x_, y_, sigma, &m_);
     329
    324330    error_.resize();
    325     parameters_ = fitter.fit(x_, y_, sigma, &m_);
    326     /*
    327     CompoundFunction<Float> f;
    328     for (uInt i=0; i<funcs_.nelements(); i++) {
    329         f.addFunction(*funcs_[i]);
    330     }
    331     f.parameters().setParameters(parameters_);
    332     */
    333331    error_ = fitter.errors();
     332
    334333    chisquared_ = fitter.getChi2();
     334
    335335    residual_.resize();
    336336    residual_ =  y_;
    337337    fitter.residual(residual_,x_);
     338
    338339    // use fitter.residual(model=True) to get the model
    339340    thefit_.resize(x_.nelements());
  • trunk/src/SDMemTable.cc

    r476 r483  
    8585{
    8686  Table tab(name);
     87  uInt version;
     88  tab.keywordSet().get("VERSION", version);
     89  if (version != version_) {
     90    throw(AipsError("Unsupported version of ASAP file."));
     91  }
    8792  table_ = tab.copyToMemoryTable("dummy");
    8893  //cerr << "hello from C SDMemTable @ " << this << endl;
     
    9297SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
    9398{
    94   IFSel_= other.IFSel_;
    95   beamSel_= other.beamSel_;
    96   polSel_= other.polSel_;
    97   chanMask_ = other.chanMask_;
    9899  table_ = other.table_.copyToMemoryTable(String("dummy"));
    99100  // clear all rows()
    100101  if (clear) {
    101102    table_.removeRow(this->table_.rowNumbers());
     103    IFSel_= 0;
     104    beamSel_= 0;
     105    polSel_= 0;
     106    chanMask_.resize(0);
    102107  } else {
    103     IFSel_ = other.IFSel_;
    104     beamSel_ = other.beamSel_;
    105     polSel_ = other.polSel_;
    106   }
    107 //
     108    IFSel_= other.IFSel_;
     109    beamSel_= other.beamSel_;
     110    polSel_= other.polSel_;
     111    chanMask_.resize(0);
     112    chanMask_ = other.chanMask_;
     113  }
     114
    108115  attach();
    109116  //cerr << "hello from CC SDMemTable @ " << this << endl;
     
    146153     attach();
    147154  }
    148   //cerr << "hello from ASS SDMemTable @ " << this << endl;
    149155  return *this;
    150156}
     
    161167  TableDesc td("", "1", TableDesc::Scratch);
    162168  td.comment() = "A SDMemTable";
    163  
     169  td.rwKeywordSet().define("VERSION", Int(version_));
     170
    164171  td.addColumn(ScalarColumnDesc<Double>("TIME"));
    165172  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
     
    180187  td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
    181188  td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
    182   td.addColumn(ArrayColumnDesc<String>("HISTORY"));
    183189  td.addColumn(ArrayColumnDesc<Int>("FITID"));
    184190
    185 
    186191  // Now create Table SetUp from the description.
    187 
    188192  SetupNewTable aNewTab("dummy", td, Table::New);
    189193
     
    192196  // point, we must bind the Virtual Engine regardless.  The STOKES
    193197  // column won't be accessed if not appropriate (nPol=4)
    194 
    195 
    196    SDStokesEngine::registerClass();
    197    SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA"));
    198    aNewTab.bindColumn ("STOKES", stokesEngine);
    199 
    200    // Create Table
    201   table_ = Table(aNewTab, Table::Memory, 0);
     198  SDStokesEngine::registerClass();
     199  SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA"));
     200  aNewTab.bindColumn("STOKES", stokesEngine);
     201 
     202  // Create Table
     203  table_ = Table(aNewTab, Table::Memory, 0);
    202204  // add subtable
    203205  TableDesc tdf("", "1", TableDesc::Scratch);
     
    211213  table_.rwKeywordSet().defineTable("FITS", fitTable);
    212214
    213 
     215  TableDesc tdh("", "1", TableDesc::Scratch);
     216  tdh.addColumn(ScalarColumnDesc<String>("ITEM"));
     217  SetupNewTable histtab("hist", tdh, Table::New);
     218  Table histTable(histtab, Table::Memory);
     219  table_.rwKeywordSet().defineTable("HISTORY", histTable);
    214220}
    215221
     
    234240  paraCol_.attach(table_, "PARANGLE");
    235241  rbeamCol_.attach(table_, "REFBEAM");
    236   histCol_.attach(table_, "HISTORY");
    237242  fitCol_.attach(table_,"FITID");
    238243}
     
    359364std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
    360365{
    361 
    362366  Array<Float> arr;
    363367  specCol_.get(whichRow, arr);
     
    385389     const IPosition& shape = arr.shape();
    386390     IPosition start, end;
    387      setCursorSlice (start, end, shape);
     391     getCursorSlice(start, end, shape);
    388392
    389393     // Get Q and U slices
     
    433437  const IPosition& shape = arr.shape();
    434438  IPosition start, end;
    435   setCursorSlice(start, end, shape);
     439  getCursorSlice(start, end, shape);
    436440
    437441  // Get I and V slices
     
    11991203  elCol_.put(rno, sdc.elevation);
    12001204  paraCol_.put(rno, sdc.parangle);
    1201   histCol_.put(rno, sdc.getHistory());
    12021205  fitCol_.put(rno, sdc.getFitMap());
    12031206  return true;
     
    12261229  Vector<uInt> fmap;
    12271230  Array<Double> direction;
    1228   Vector<String> histo;
    12291231  Array<Int> fits;
    12301232 
     
    12411243  dirCol_.get(whichRow, direction);
    12421244  sdc.putDirection(direction);
    1243   histCol_.get(whichRow, histo);
    1244   sdc.putHistory(histo);
    12451245  fitCol_.get(whichRow, fits);
    12461246  sdc.putFitMap(fits);
     
    12911291}
    12921292void SDMemTable::makePersistent(const std::string& filename)
    1293 {
     1293{ 
    12941294  table_.deepCopy(filename,Table::New);
     1295
    12951296}
    12961297
     
    14721473  return String(oss);
    14731474}
    1474 
     1475/*
     1476std::string SDMemTable::scanSummary(const std::vector<int>& whichScans) {
     1477  ostringstream oss;
     1478  Vector<Int> scanIDs = scanCol_.getColumn();
     1479  Vector<uInt> startInt, endInt;
     1480  mathutil::scanBoundaries(startInt, endInt, scanIDs);
     1481  const uInt nScans = startInt.nelements();
     1482  std::vector<int>::const_iterator it(whichScans);
     1483  return String(oss);
     1484}
     1485*/
    14751486Int SDMemTable::nBeam() const
    14761487{
     
    14981509}
    14991510
    1500 bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
     1511void SDMemTable::addHistory(const std::string& hist)
     1512{
     1513  Table t = table_.rwKeywordSet().asTable("HISTORY");
     1514  uInt nrow = t.nrow(); 
     1515  t.addRow();
     1516  ScalarColumn<String> itemCol(t, "ITEM");
     1517  itemCol.put(nrow, hist);
     1518}
     1519
     1520std::vector<std::string> SDMemTable::getHistory() const
    15011521{
    15021522  Vector<String> history;
    1503   histCol_.get(whichRow, history);
    1504   history.resize(history.nelements()+1,True);
    1505   history[history.nelements()-1] = hist;
    1506   histCol_.put(whichRow, history);
    1507 }
    1508 
    1509 std::vector<std::string> SDMemTable::history(int whichRow) const
    1510 {
    1511   Vector<String> history;
    1512   histCol_.get(whichRow, history);
    1513   std::vector<std::string> stlout = mathutil::tovectorstring(history);
     1523  const Table& t = table_.keywordSet().asTable("HISTORY");
     1524  uInt nrow = t.nrow(); 
     1525  ROScalarColumn<String> itemCol(t, "ITEM");
     1526  std::vector<std::string> stlout;
     1527  String hist;
     1528  for (uInt i=0; i<nrow; ++i) {
     1529    itemCol.get(i, hist);
     1530    stlout.push_back(hist);
     1531  }
    15141532  return stlout;
    15151533}
    15161534/*
    1517 void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
     1535  void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
    15181536
    15191537  std::vector<int>::iterator it;
     
    15341552*/
    15351553void SDMemTable::flag(int whichRow)
    1536 {
     1554  {
    15371555  Array<uChar> arr;
    15381556  flagsCol_.get(whichRow, arr);
     
    17191737
    17201738
    1721 void SDMemTable::setCursorSlice(IPosition& start, IPosition& end,
     1739void SDMemTable::getCursorSlice(IPosition& start, IPosition& end,
    17221740                                const IPosition& shape) const
    17231741{
  • trunk/src/SDMemTable.h

    r476 r483  
    192192  virtual std::string summary(bool verbose=false) const;
    193193
    194   std::vector<std::string> history(int whichRow=0) const;
    195   bool appendHistory(const std::string& hist, int whichRow=0);
     194  // get/set the history
     195  std::vector<std::string> getHistory() const;
     196  void addHistory(const std::string& hist);
     197
    196198  // write to disk as aips++ table
    197199  void makePersistent(const std::string& filename);
     
    269271
    270272  // Generate start and end for shape and current cursor selection
    271   void setCursorSlice(casa::IPosition& start, casa::IPosition& end,
     273  void getCursorSlice(casa::IPosition& start, casa::IPosition& end,
    272274                      const casa::IPosition& shape) const;
    273275
     
    277279  // the underlying memory table
    278280  casa::Table table_;
     281  // The current table version
     282  static const casa::uInt version_ = 1;
    279283
    280284  // Cached Columns to avoid reconstructing them for each row get/put
  • trunk/src/SDMemTableWrapper.h

    r465 r483  
    6363  }
    6464
    65   //SDMemTableWrapper getScan(int scan) {
    6665  SDMemTableWrapper getScan(std::vector<int> scan) {
    6766    casa::String cond("SELECT FROM $1 WHERE SCANID IN ");
     
    7776    cond += source;cond += "')";
    7877    return SDMemTableWrapper(*this, cond);
     78  }
     79
     80  SDMemTableWrapper getSQL(const std::string& sqlexpr) {
     81    return SDMemTableWrapper(*this, sqlexpr);
    7982  }
    8083
     
    166169                                casa::Int(whichIF));
    167170  }
    168 
     171 
    169172  void spectralLines() const {table_->spectralLines();}
    170173
     
    187190  }
    188191 
    189   std::vector<std::string> history(int whichRow=0) {
    190     return table_->history(whichRow);
     192  std::vector<std::string> getHistory() {
     193    return table_->getHistory();
     194  }
     195  void addHistory(const std::string& hist) {
     196    table_->addHistory(hist);
    191197  }
    192198
  • trunk/src/python_SDMemTable.cc

    r465 r483  
    9999    .def("_setcoordinfo", &SDMemTableWrapper::setCoordInfo)
    100100    .def("_getcoordinfo", &SDMemTableWrapper::getCoordInfo)
    101     .def("_history", &SDMemTableWrapper::history,
    102          (boost::python::arg("whichRow")=0) )
     101    .def("_gethistory", &SDMemTableWrapper::getHistory)
     102    .def("_addhistory", &SDMemTableWrapper::addHistory)
    103103    .def("_addfit", &SDMemTableWrapper::addFit)
    104104    .def("_getfit", &SDMemTableWrapper::getSDFitTable)
Note: See TracChangeset for help on using the changeset viewer.