// // C++ Implementation: STFrequencies // // Description: // // // Author: Malte Marquarding , (C) 2006 // // Copyright: See COPYING file that comes with this distribution // // #include #include #include #include #include #include #include #include #include #include #include #include #include #include "STFrequencies.h" using namespace casa; namespace asap { const casa::String STFrequencies::name_ = "FREQUENCIES"; STFrequencies::STFrequencies(casa::Table::TableType tt) : STSubTable( name_, tt ) { setup(); } STFrequencies::~STFrequencies() { } void STFrequencies::setup( ) { // add to base class table table_.addColumn(ScalarColumnDesc("REFPIX")); table_.addColumn(ScalarColumnDesc("REFVAL")); table_.addColumn(ScalarColumnDesc("INCREMENT")); table_.rwKeywordSet().define("REFFRAME", String("TOPO")); table_.rwKeywordSet().define("EQUINOX",String( "J2000")); table_.rwKeywordSet().define("UNIT", String("Hz")); table_.rwKeywordSet().define("DOPPLER", String("RADIO")); // new cached columns refpixCol_.attach(table_,"REFPIX"); refvalCol_.attach(table_,"REFVAL"); incrCol_.attach(table_,"INCREMENT"); } uInt STFrequencies::addEntry( Double refpix, Double refval, Double inc ) { // test if this already exists Table result = table_( near(table_.col("REFVAL"), refval) && near(table_.col("REFPIX"), refpix) && near(table_.col("INCREMENT"), inc) ); uInt resultid = 0; if ( result.nrow() > 0) { ROScalarColumn c(result, "ID"); c.get(0, resultid); } else { uInt rno = table_.nrow(); table_.addRow(); // get last assigned freq_id and increment if ( rno > 0 ) { idCol_.get(rno-1, resultid); resultid++; } refpixCol_.put(rno, refpix); refvalCol_.put(rno, refval); incrCol_.put(rno, inc); idCol_.put(rno, resultid); } return resultid; } SpectralCoordinate STFrequencies::getSpectralCoordinate( uInt freqID ) { Table t = table_(table_.col("ID") == Int(freqID) ); if (t.nrow() == 0 ) { throw(AipsError("STFrequencies::getSpectralCoordinate - freqID out of range")); } // get the data ROTableRow row(t); // get first row - there should only be one matching id const TableRecord& rec = row.get(0); return SpectralCoordinate( getFrame(), rec.asDouble("REFVAL"), rec.asDouble("INCREMENT"), rec.asDouble("REFPIX")); } void STFrequencies::rescale( casa::Float factor, const std::string& mode ) { TableRow row(table_); TableRecord& outrec = row.record(); RecordFieldPtr rv(outrec, "REFVAL"); RecordFieldPtr rp(outrec, "REFPIX"); RecordFieldPtr inc(outrec, "INCREMENT"); for (uInt i=0; i offset(1,0.0); Vector factors(1,1.0/width); Vector newshape; CoordinateSystem csys; csys.addCoordinate(sc); CoordinateSystem csys2 = csys.subImage(offset, factors, newshape); return csys2.spectralCoordinate(0); } casa::MFrequency::Types STFrequencies::getFrame( ) const { // get the ref frame String rf; table_.keywordSet().get("REFFRAME", rf); // Create SpectralCoordinate (units Hz) MFrequency::Types mft; if (!MFrequency::getType(mft, rf)) { ostringstream oss; pushLog("WARNING: Frequency type unknown assuming TOPO"); mft = MFrequency::TOPO; } return mft; } std::string asap::STFrequencies::print( int id ) { Table t; ostringstream oss; if ( id < 0 ) t = table_; else t = table_(table_.col("ID") == Int(id) ); ROTableRow row(t); for (uInt i=0; i