Changeset 2593
- Timestamp:
- 07/09/12 16:54:10 (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/__init__.py
r2587 r2593 52 52 from opacity import skydip 53 53 from opacity import model as opacity_model 54 from asapgrid import asapgrid 54 from asapgrid import asapgrid, asapgrid2 55 55 #from plotter2 import plotter2 56 56 from _asap import srctype -
trunk/python/asapgrid.py
r2450 r2593 3 3 from asap.scantable import scantable 4 4 from asap.selector import selector 5 from asap._asap import stgrid 5 from asap._asap import stgrid, stgrid2 6 6 import pylab as pl 7 7 from logging import asaplog … … 224 224 asaplog.post('DEBUG','asapgrid.plot') 225 225 226 class asapgrid2: 227 """ 228 The asapgrid class is defined to convolve data onto regular 229 spatial grid. Typical usage is as follows: 230 231 # create asapgrid instance with input scantable 232 s = scantable( 'testimage1.asap', average=False ) 233 g = asapgrid( s ) 234 # set IFNO if necessary 235 g.setIF( 0 ) 236 # set POLNOs if necessary 237 g.setPolList( [0,1] ) 238 # set SCANNOs if necessary 239 g.setScanList( [22,23,24] ) 240 # define image with full specification 241 # you can skip some parameters (see help for defineImage) 242 g.defineImage( nx=12, ny=12, cellx='10arcsec', celly='10arcsec', 243 center='J2000 10h10m10s -5d05m05s' ) 244 # set convolution function 245 g.setFunc( func='sf', width=3 ) 246 # enable min/max clipping 247 g.enableClip() 248 # or, disable min/max clipping 249 #g.disableClip() 250 # actual gridding 251 g.grid() 252 # get result as scantable 253 sg = g.getResult() 254 """ 255 def __init__( self, scantab ): 256 """ 257 Create asapgrid instance. 258 259 scantab -- input data as a scantable or a list of scantables 260 to grid more than one data at once. 261 """ 262 self.outfile = None 263 self.ifno = None 264 self.gridder = stgrid2() 265 self.setData( scantab ) 266 267 def setData( self, scantab ): 268 """ 269 Set data to be processed. 270 271 scantab -- input data as a scantable or a list of scantables 272 to grid more than one data at once. 273 """ 274 if isinstance( scantab, scantable ): 275 self.gridder._setin( scantab ) 276 else: 277 self.gridder._setfiles( scantab ) 278 self.scantab = scantab 279 280 def setIF( self, ifno ): 281 """ 282 Set IFNO to be processed. Currently, asapgrid allows to process 283 only one IFNO for one gridding run even if the data contains 284 multiple IFs. If you didn't specify IFNO, default value, which 285 is IFNO in the first spectrum, will be processed. 286 287 ifno -- IFNO to be processed. 288 """ 289 self.ifno = ifno 290 self.gridder._setif( self.ifno ) 291 292 def setPolList( self, pollist ): 293 """ 294 Set list of polarization components you want to process. 295 If not specified, all POLNOs will be processed. 296 297 pollist -- list of POLNOs. 298 """ 299 self.gridder._setpollist( pollist ) 300 301 def setScanList( self, scanlist ): 302 """ 303 Set list of scans you want to process. If not specified, all 304 scans will be processed. 305 306 scanlist -- list of SCANNOs. 307 """ 308 self.gridder._setscanlist( scanlist ) 309 310 def defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ): 311 """ 312 Define spatial grid. 313 314 First two parameters, nx and ny, define number of pixels of 315 the grid. If which of those is not specified, it will be set 316 to the same value as the other. If none of them are specified, 317 it will be determined from map extent and cell size. 318 319 Next two parameters, cellx and celly, define size of pixel. 320 You should set those parameters as string, which is constructed 321 numerical value and unit, e.g. '0.5arcmin', or numerical value. 322 If those values are specified as numerical value, their units 323 will be assumed to 'arcsec'. If which of those is not specified, 324 it will be set to the same value as the other. If none of them 325 are specified, it will be determined from map extent and number 326 of pixels, or set to '1arcmin' if neither nx nor ny is set. 327 328 The last parameter, center, define the central coordinate of 329 the grid. You should specify its value as a string, like, 330 331 'J2000 05h08m50s -16d23m30s' 332 333 or 334 335 'J2000 05:08:50 -16.23.30' 336 337 You can omit equinox when you specify center coordinate. In that 338 case, J2000 is assumed. If center is not specified, it will be 339 determined from the observed positions of input data. 340 341 nx -- number of pixels along x (R.A.) direction. 342 ny -- number of pixels along y (Dec.) direction. 343 cellx -- size of pixel in x (R.A.) direction. 344 celly -- size of pixel in y (Dec.) direction. 345 center -- central position of the grid. 346 """ 347 if not isinstance( cellx, str ): 348 cellx = '%sarcsec'%(cellx) 349 if not isinstance( celly, str ): 350 celly = '%sarcsec'%(celly) 351 self.gridder._defineimage( nx, ny, cellx, celly, center ) 352 353 def setFunc( self, func='box', width=-1 ): 354 """ 355 Set convolution function. Possible options are 'box' (Box-car, 356 default), 'sf' (prolate spheroidal), and 'gauss' (Gaussian). 357 Width of convolution function can be set using width parameter. 358 By default (-1), width is automatically set depending on each 359 convolution function. Default values for width are: 360 361 'box': 1 pixel 362 'sf': 3 pixels 363 'gauss': 1 pixel (width is used as HWHM) 364 365 func -- Function type ('box', 'sf', 'gauss'). 366 width -- Width of convolution function. Default (-1) is to 367 choose pre-defined value for each convolution function. 368 """ 369 self.gridder._setfunc( func, width ) 370 371 def setWeight( self, weightType='uniform' ): 372 """ 373 Set weight type. Possible options are 'uniform' (default), 374 'tint' (weight by integration time), 'tsys' (weight by 375 Tsys: 1/Tsys**2), and 'tintsys' (weight by integration time 376 as well as Tsys: tint/Tsys**2). 377 378 weightType -- weight type ('uniform', 'tint', 'tsys', 'tintsys') 379 """ 380 self.gridder._setweight( weightType ) 381 382 def enableClip( self ): 383 """ 384 Enable min/max clipping. 385 386 By default, min/max clipping is disabled so that you should 387 call this method before actual gridding if you want to do 388 clipping. 389 """ 390 self.gridder._enableclip() 391 392 def disableClip( self ): 393 """ 394 Disable min/max clipping. 395 """ 396 self.gridder._disableclip() 397 398 def grid( self ): 399 """ 400 Actual gridding which will be done based on several user inputs. 401 """ 402 self.gridder._grid() 403 404 def getResult( self ): 405 """ 406 Return gridded data as a scantable. 407 """ 408 return scantable( self.gridder._get(), average=False ) 409 226 410 class _SDGridPlotter: 227 411 def __init__( self, infile, outfile=None, ifno=-1 ): -
trunk/src/STGrid.cpp
r2478 r2593 1185 1185 } 1186 1186 1187 void STGrid::table( Table &tab, uInt i ) 1188 { 1189 if ( i >= 0 && i < nfile_ ) 1190 tab = Table( infileList_[i] ) ; 1191 } 1192 1187 1193 void STGrid::selectData() 1188 1194 { … … 1191 1197 tableList_.resize( nfile_ ) ; 1192 1198 if ( ifno_ == -1 ) { 1193 Table taborg( infileList_[0] ) ; 1199 //Table taborg( infileList_[0] ) ; 1200 Table taborg ; 1201 table( taborg, 0 ) ; 1194 1202 ROScalarColumn<uInt> ifnoCol( taborg, "IFNO" ) ; 1195 1203 ifno_ = ifnoCol( 0 ) ; … … 1198 1206 } 1199 1207 for ( uInt i = 0 ; i < nfile_ ; i++ ) { 1200 Table taborg( infileList_[i] ) ; 1208 //Table taborg( infileList_[i] ) ; 1209 Table taborg ; 1210 table( taborg, i ) ; 1201 1211 TableExprNode node ; 1202 1212 if ( ifno != -1 || isMultiIF( taborg ) ) { … … 1639 1649 Table tab ; 1640 1650 prepareTable( tab, outfile_ ) ; 1651 fillTable( tab ) ; 1652 1653 t1 = mathutil::gettimeofday_sec() ; 1654 os << LogIO::DEBUGGING << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; 1655 1656 return outfile_ ; 1657 } 1658 1659 void STGrid::prepareTable( Table &tab, String &name ) 1660 { 1661 Table t( infileList_[0], Table::Old ) ; 1662 t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ; 1663 tab = Table( name, Table::Update ) ; 1664 // 2012/02/13 TN 1665 // explicitly copy subtables since no rows including subtables are 1666 // copied by Table::deepCopy with noRows=True 1667 TableCopy::copySubTables( tab, t ) ; 1668 } 1669 1670 void STGrid::fillTable( Table &tab ) 1671 { 1641 1672 IPosition dshape = data_.shape() ; 1642 1673 Int nrow = nx_ * ny_ * npol_ ; … … 1687 1718 data_.freeStorage( data_p, bdata ) ; 1688 1719 1689 t1 = mathutil::gettimeofday_sec() ;1690 os << LogIO::DEBUGGING << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;1691 1692 1720 fillMainColumns( tab ) ; 1693 1694 return outfile_ ;1695 }1696 1697 void STGrid::prepareTable( Table &tab, String &name )1698 {1699 Table t( infileList_[0], Table::Old ) ;1700 t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ;1701 tab = Table( name, Table::Update ) ;1702 // 2012/02/13 TN1703 // explicitly copy subtables since no rows including subtables are1704 // copied by Table::deepCopy with noRows=True1705 TableCopy::copySubTables( tab, t ) ;1706 1721 } 1707 1722 … … 1779 1794 } 1780 1795 1781 } 1796 // STGrid2 1797 STGrid2::STGrid2() 1798 : STGrid() 1799 { 1800 } 1801 1802 STGrid2::STGrid2( const ScantableWrapper &s ) 1803 : STGrid() 1804 { 1805 setScantable( s ) ; 1806 } 1807 1808 STGrid2::STGrid2( const vector<ScantableWrapper> &v ) 1809 : STGrid() 1810 { 1811 setScantableList( v ) ; 1812 } 1813 1814 void STGrid2::setScantable( const ScantableWrapper &s ) 1815 { 1816 nfile_ = 1 ; 1817 dataList_.resize( nfile_ ) ; 1818 dataList_[0] = s ; 1819 infileList_.resize( nfile_ ) ; 1820 infileList_[0] = s.getCP()->table().tableName() ; 1821 } 1822 1823 void STGrid2::setScantableList( const vector<ScantableWrapper> &v ) 1824 { 1825 nfile_ = v.size() ; 1826 dataList_.resize( nfile_ ) ; 1827 infileList_.resize( nfile_ ) ; 1828 for ( uInt i = 0 ; i < nfile_ ; i++ ) { 1829 dataList_[i] = v[i] ; 1830 infileList_[i] = v[i].getCP()->table().tableName() ; 1831 } 1832 } 1833 1834 ScantableWrapper STGrid2::getResultAsScantable() 1835 { 1836 CountedPtr<Scantable> s = new Scantable( Table::Plain ) ; 1837 s->setHeader( dataList_[0].getCP()->getHeader() ) ; 1838 Table tout, tin ; 1839 String subt[] = { "FREQUENCIES", "FOCUS", "WEATHER", 1840 "TCAL", "MOLECULES", "HISTORY", "FIT" } ; 1841 for ( uInt i = 0 ; i < 7 ; i++ ) { 1842 tout = s->table().rwKeywordSet().asTable(subt[i]) ; 1843 tin = dataList_[0].getCP()->table().rwKeywordSet().asTable(subt[i]) ; 1844 TableCopy::copyRows( tout, tin ) ; 1845 } 1846 fillTable( s->table() ) ; 1847 ScantableWrapper sw( s ) ; 1848 return sw ; 1849 } 1850 1851 void STGrid2::table( Table &tab, uInt i ) 1852 { 1853 if ( i < nfile_ ) 1854 tab = dataList_[i].getCP()->table() ; 1855 } 1856 1857 } -
trunk/src/STGrid.h
r2413 r2593 27 27 #include <tables/Tables/ArrayColumn.h> 28 28 29 #include "ScantableWrapper.h" 30 #include "Scantable.h" 29 31 #include "concurrent.h" 30 32 … … 67 69 string saveData( string outfile="" ) ; 68 70 69 private: 71 //private: 72 protected: 70 73 void init() ; 71 74 … … 196 199 Bool isMultiIF( Table &tab ) ; 197 200 void fillMainColumns( Table &tab ) ; 201 void fillTable( Table &tab ) ; 202 virtual void table( Table &tab, uInt i ) ; 198 203 static bool produceChunk(void *ctx) throw(concurrent::PCException); 199 204 static void consumeChunk(void *ctx) throw(concurrent::PCException); … … 257 262 double eGGridSD_; 258 263 }; 264 265 class STGrid2 : public STGrid 266 { 267 public: 268 STGrid2() ; 269 STGrid2( const ScantableWrapper &s ) ; 270 STGrid2( const vector<ScantableWrapper> &v ) ; 271 void setScantable( const ScantableWrapper &s ) ; 272 void setScantableList( const vector<ScantableWrapper> &v ) ; 273 void selectData() ; 274 virtual void table( Table &tab, uInt i ) ; 275 ScantableWrapper getResultAsScantable() ; 276 277 private: 278 Block<ScantableWrapper> dataList_ ; 279 }; 259 280 } 260 281 #endif -
trunk/src/python_STGrid.cpp
r2526 r2593 9 9 10 10 #include "STGrid.h" 11 //#include "STGridWrapper.h"11 #include "ScantableWrapper.h" 12 12 13 13 using namespace boost::python; … … 17 17 18 18 void python_STGrid() { 19 //class_<STGridWrapper>("stgrid")20 19 class_<STGrid>("stgrid") 21 20 .def( init <> () ) … … 35 34 .def("_save", &STGrid::saveData) 36 35 ; 36 37 class_<STGrid2>("stgrid2") 38 .def( init <> () ) 39 .def( init < const ScantableWrapper & > () ) 40 .def( init < const std::vector<ScantableWrapper> & > () ) 41 .def("_setif", &STGrid2::setIF) 42 .def("_setpollist", &STGrid2::setPolList) 43 .def("_setscanlist", &STGrid2::setScanList) 44 .def("_defineimage", &STGrid2::defineImage) 45 .def("_setfunc", &STGrid2::setFunc) 46 .def("_grid", &STGrid2::grid) 47 .def("_setin", &STGrid2::setScantable) 48 .def("_setfiles", &STGrid2::setScantableList) 49 .def("_setweight", &STGrid2::setWeight) 50 .def("_enableclip", &STGrid2::enableClip) 51 .def("_disableclip", &STGrid2::disableClip) 52 .def("_get", &STGrid2::getResultAsScantable) 53 ; 54 37 55 }; 38 56
Note:
See TracChangeset
for help on using the changeset viewer.