Changeset 2711
- Timestamp:
- 12/27/12 17:37:43 (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/sbseparator.py
r2707 r2711 49 49 self.solveother = False 50 50 self.dirtol = [1.e-5, 1.e-5] # direction tolerance in rad (2 arcsec) 51 self.lo1 = 0.51 #self.lo1 = 0. 52 52 53 53 self.tables = [] … … 57 57 self.set_data(infiles) 58 58 59 #self.separator = sidebandsep()59 self.separator = SBSeparator() 60 60 61 61 @asaplog_post_dec … … 221 221 lo1 : LO1 frequency in float 222 222 """ 223 lo1val = -1. 223 224 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.: 228 229 asaplog.push("Got negative LO1 frequency. It will be ignored.") 229 230 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) 230 244 231 245 … … 289 303 asaplog.post() 290 304 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") 294 308 295 309 imagename = outname + ".imageband" … … 300 314 shutil.rmtree(imagename) 301 315 # 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() 307 318 imagetab.save(imagename) 308 del sbsep309 319 310 320 -
trunk/src/STSideBandSep.cpp
r2709 r2711 21 21 #include <measures/Measures/MCFrequency.h> 22 22 23 #include <tables/Tables/TableRow.h> 23 24 #include <tables/Tables/TableRecord.h> 24 25 #include <tables/Tables/TableVector.h> … … 98 99 }; 99 100 100 void STSideBandSep::setLO1Asdm(string asdmname) 101 { 102 // Check for existance of the asdm. 103 if (!checkFile(asdmname)) { 101 void 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)) { 104 107 throw(AipsError("File does not exist")); 105 108 } 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; 114 130 #endif 115 131 }; … … 126 142 throw AipsError("STSideBandSep::solveImageFreqency - an image side band scantable should be set first"); 127 143 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. 149 145 // The code assumes that imgTab_p has only an IF and only a FREQ_ID 150 146 // is associated to an IFNO … … 160 156 // assuming single freqID per IFNO 161 157 uInt freqid = freqIdVec(0); 158 int nChan = imgTab_p->nchan(imgTab_p->getIF(0)); 162 159 double refpix, refval, increment ; 163 160 freqTab_.getEntry(refpix, refval, increment, freqid); … … 203 200 md = MDirection(ra.getValue("rad"), dec.getValue("rad"),epoch); 204 201 } 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) 206 244 Vector<Double> dirvec = md.getAngle(Unit(String("rad"))).getValue(); 207 245 os << "[LO1 settings]" << LogIO::POST; … … 212 250 os << "- Reference direction: [" << dirvec[0] << ", " << dirvec[1] 213 251 << "] (" << 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) 226 254 os << "[Signal side band]" << LogIO::POST; 227 255 os << "- IFNO: " << imgTab_p->getIF(0) << " (FREQ_ID = " << freqid << ")" … … 233 261 os << "- Reference pixel: " << refpix << LogIO::POST; 234 262 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_ 236 265 Double imgincr = -increment; 237 266 Double imgrefval = 2 * lo1Freq_ - sigrefval; 238 267 Double imgrefval_tab = imgrefval; 239 // convert imgrefval back to table base frame268 // Convert imgrefval back to table base frame 240 269 if (tabframe != loFrame_) 241 270 imgrefval = tobframe(Quantum<Double>(imgrefval, "Hz")).get("Hz").getValue(); 242 // set new frequencies table271 // Set new frequencies table 243 272 uInt fIDnew = freqTab_.addEntry(refpix, imgrefval, imgincr); 244 // update freq_ID in table.273 // Update FREQ_ID in table. 245 274 freqIdVec = fIDnew; 246 // Summary (Image side band) 275 276 // Print summary (Image side band) 247 277 os << "[Image side band]" << LogIO::POST; 248 278 os << "- IFNO: " << imgTab_p->getIF(0) << " (FREQ_ID = " << freqIdVec(0) … … 278 308 }; 279 309 280 bool STSideBandSep::getLo1FromAsdm(const string asdmname) 310 bool STSideBandSep::getLo1FromAsdm(const string asdmname, 311 const double refval, 312 const double refpix, 313 const double increment, 314 const int nChan) 281 315 { 282 316 // Check for relevant tables. … … 292 326 293 327 294 bool STSideBandSep::getLo1FromTab(CountedPtr< Scantable > &scantab) 295 { 328 bool 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)); 296 335 Table& tab = scantab->table(); 297 336 // 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 } 300 348 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 368 bool 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; 305 444 return false; 306 307 }; 308 445 }; 446 447 // String STSideBandSep::() 448 // { 449 450 // }; 309 451 310 452 } //namespace asap -
trunk/src/STSideBandSep.h
r2707 r2711 54 54 **/ 55 55 void setLO1(const double lo1, string frame="TOPO", double reftime=-1, string refdir=""); 56 void setLO1 Asdm(const string asdmname);56 void setLO1Root(const string name); 57 57 /** 58 58 * Actual calculation of frequencies of image sideband … … 62 62 private: 63 63 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); 66 73 67 74 unsigned int sigIfno_; … … 71 78 double loTime_; 72 79 string loDir_; 73 string asdmName_ ;80 string asdmName_, asisName_; 74 81 75 82 CountedPtr< Scantable > imgTab_p, sigTab_p; -
trunk/src/python_PlotHelper.cpp
r2689 r2711 1 1 //#--------------------------------------------------------------------------- 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 //# 3 8 //#--------------------------------------------------------------------------- 4 9 #include <boost/python.hpp> 5 10 #include <boost/python/args.hpp> 6 11 7 #include <string>8 #include <vector>9 10 12 #include "PlotHelper.h" 11 #include "ScantableWrapper.h"13 //#include "ScantableWrapper.h" 12 14 13 15 using namespace boost::python; -
trunk/src/python_STSideBandSep.cpp
r2707 r2711 27 27 boost::python::arg("reftime")=-1, 28 28 boost::python::arg("refdir")="") ) 29 //.def( "set_asdm", &STSideBandSep::setLO1Asdm)29 .def( "set_lo1root", &STSideBandSep::setLO1Root ) 30 30 // temporal methods 31 31 .def( "set_imgtable", &STSideBandSep::setImageTable )
Note:
See TracChangeset
for help on using the changeset viewer.