Changeset 2361
- Timestamp:
- 12/06/11 19:18:40 (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapgrid.py
r2360 r2361 21 21 def setOption( self, convType='box', convSupport=-1 ): 22 22 self.gridder._setoption( convType, convSupport ) 23 24 def setWeight( self, weightType='uniform' ): 25 self.gridder._setweight( weightType ) 23 26 24 27 def grid( self ): -
trunk/src/STGrid.cpp
r2360 r2361 7 7 #include <casa/Arrays/Cube.h> 8 8 #include <casa/Arrays/ArrayMath.h> 9 // #include <casa/Inputs/Input.h>9 #include <casa/Arrays/ArrayPartMath.h> 10 10 #include <casa/Quanta/Quantum.h> 11 11 #include <casa/Quanta/QuantumHolder.h> 12 12 #include <casa/Utilities/CountedPtr.h> 13 #include <casa/Logging/LogIO.h> 13 14 14 15 #include <tables/Tables/Table.h> … … 46 47 nx_ = -1 ; 47 48 ny_ = -1 ; 49 npol_ = 0 ; 50 nchan_ = 0 ; 51 nrow_ = 0 ; 52 ngrid_ = 0 ; 48 53 cellx_ = 0.0 ; 49 54 celly_ = 0.0 ; 50 55 center_ = Vector<Double> ( 2, 0.0 ) ; 51 56 convType_ = "BOX" ; 57 wtype_ = "UNIFORM" ; 52 58 convSupport_ = -1 ; 53 59 userSupport_ = -1 ; … … 69 75 pollist_.assign( Vector<uInt>( pols ) ) ; 70 76 cout << "pollist_ = " << pollist_ << endl ; 77 } 78 79 void STGrid::setWeight( const string wType ) 80 { 81 wtype_ = String( wType ) ; 82 wtype_.upcase() ; 83 cout << "wtype_ = " << wtype_ << endl ; 71 84 } 72 85 … … 133 146 void STGrid::grid() 134 147 { 148 LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; 135 149 136 150 // retrieve data … … 139 153 Cube<uChar> flagtra ; 140 154 Matrix<uInt> rflag ; 141 getData( infile_, spectra, direction, flagtra, rflag ) ; 155 Matrix<Float> weight ; 156 getData( infile_, spectra, direction, flagtra, rflag, weight ) ; 142 157 IPosition sshape = spectra.shape() ; 143 Int npol = sshape[0] ; 144 Int nchan = sshape[1] ; 145 Int nrow = sshape[2] ; 146 cout << "spectra.shape()=" << spectra.shape() << endl ; 147 cout << "max(spectra) = " << max(spectra) << endl ; 158 //os << "spectra.shape()=" << spectra.shape() << LogIO::POST ; 159 //os << "max(spectra) = " << max(spectra) << LogIO::POST ; 160 //os << "weight = " << weight << LogIO::POST ; 148 161 149 162 // flagtra: uChar -> Int 150 163 // rflag: uInt -> Int 151 // Matrix<Int> flagI ;152 // Vector<Int> rflagI ;153 164 Cube<Int> flagI ; 154 165 Matrix<Int> rflagI ; … … 156 167 toInt( &rflag, &rflagI ) ; 157 168 158 cout << "flagI.shape() = " << flagI.shape() << endl ;159 cout << "rflagI.shape() = " << rflagI.shape() << endl ;160 161 169 // grid parameter 162 // cout<< "----------" << endl ;163 // cout<< "Grid parameter summary" << endl ;164 // cout<< " (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ;165 // cout<< " (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ;166 // cout<< " center = " << center_ << endl ;167 // cout << "----------" << endl;170 // os << "----------" << endl ; 171 // os << "Grid parameter summary" << endl ; 172 // os << " (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ; 173 // os << " (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ; 174 // os << " center = " << center_ << endl ; 175 // os << "----------" << LogIO::POST ; 168 176 169 177 // convolution kernel … … 176 184 Matrix<Double> xypos( direction.shape(), 0.0 ) ; 177 185 toPixel( direction, xypos ) ; 178 //cout << "max(xypos.row(0))=" << max(xypos.row(0)) << endl ;179 //cout << "min(xypos.row(0))=" << min(xypos.row(0)) << endl ;180 //cout << "max(xypos.row(1))=" << max(xypos.row(1)) << endl ;181 //cout << "min(xypos.row(1))=" << min(xypos.row(1)) << endl ;182 // for ( Int irow = 0 ; irow < nrow ; irow++ ) {183 // if ( spectra.column( irow )(0) > 0.0 ) {184 // cout << irow << ": xypos=" << xypos.column( irow )185 // << " data = " << spectra.column( irow ) << endl ;186 // }187 // }188 186 189 // weighting factor 190 Matrix<Float> weight( IPosition( 2, nchan, nrow ), 1.0 ) ; 191 192 // // call ggridsd 187 // call ggridsd 193 188 Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ; 194 189 Double *xypos_p = xypos.getStorage( deletePos ) ; 195 //Matrix<Complex> dataC( spectra.shape(), 0.0 ) ;196 190 Cube<Complex> dataC( spectra.shape(), 0.0 ) ; 197 191 setReal( dataC, spectra ) ; … … 201 195 const Int *rflag_p = rflagI.getStorage( deleteFlagR ) ; 202 196 Float *conv_p = convFunc.getStorage( deleteConv ) ; 203 //Int npol = 1 ;204 197 // Extend grid plane with convSupport_ 205 198 //IPosition gshape( 4, nx_, ny_, npol, nchan ) ; 206 199 Int gnx = nx_+convSupport_*2 ; 207 200 Int gny = ny_+convSupport_*2 ; 208 IPosition gshape( 4, gnx, gny, npol , nchan) ;201 IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ; 209 202 Array<Complex> gdataArrC( gshape, 0.0 ) ; 210 203 Array<Float> gwgtArr( gshape, 0.0 ) ; … … 213 206 Int idopsf = 0 ; 214 207 Int irow = -1 ; 215 Int *chanMap = new Int[nchan ] ;208 Int *chanMap = new Int[nchan_] ; 216 209 { 217 210 Int *work_p = chanMap ; 218 for ( Int i = 0 ; i < nchan ; i++ ) {211 for ( Int i = 0 ; i < nchan_ ; i++ ) { 219 212 *work_p = i ; 220 213 work_p++ ; 221 214 } 222 215 } 223 Int *polMap = new Int[npol ] ;216 Int *polMap = new Int[npol_] ; 224 217 { 225 218 Int *work_p = polMap ; 226 for ( Int i = 0 ; i < npol ; i++ ) {219 for ( Int i = 0 ; i < npol_ ; i++ ) { 227 220 *work_p = i ; 228 221 work_p++ ; 229 222 } 230 223 } 231 Double *sumw_p = new Double[npol *nchan] ;224 Double *sumw_p = new Double[npol_*nchan_] ; 232 225 { 233 226 Double *work_p = sumw_p ; 234 for ( Int i = 0 ; i < npol *nchan; i++ ) {227 for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) { 235 228 *work_p = 0.0 ; 236 229 work_p++ ; … … 239 232 ggridsd( xypos_p, 240 233 data_p, 241 &npol ,242 &nchan ,234 &npol_, 235 &nchan_, 243 236 &idopsf, 244 237 flag_p, 245 238 rflag_p, 246 239 wgt_p, 247 &nrow ,240 &nrow_, 248 241 &irow, 249 242 gdata_p, … … 251 244 &gnx, 252 245 &gny, 253 &npol ,254 &nchan ,246 &npol_, 247 &nchan_, 255 248 &convSupport_, 256 249 &convSampling_, … … 274 267 for ( Int ix = 0 ; ix < nx_ ; ix++ ) { 275 268 for ( Int iy = 0 ; iy < ny_ ; iy++ ) { 276 for ( Int ip = 0 ; ip < npol ; ip++ ) {277 for ( Int ic = 0 ; ic < nchan ; ic++ ) {269 for ( Int ip = 0 ; ip < npol_ ; ip++ ) { 270 for ( Int ic = 0 ; ic < nchan_ ; ic++ ) { 278 271 IPosition pos( 4, ix, iy, ip, ic ) ; 279 //if ( gwgtArr( pos ) > 0.0 )280 // data_( pos ) = gdataArr( pos ) / gwgtArr( pos ) ;281 272 IPosition gpos( 4, ix+convSupport_, iy+convSupport_, ip, ic ) ; 282 273 if ( gwgtArr( gpos ) > 0.0 ) … … 286 277 } 287 278 } 288 Matrix<Double> sumWeight( IPosition( 2, npol, nchan ), sumw_p, TAKE_OVER ) ; 279 //Matrix<Double> sumWeight( IPosition( 2, npol_, nchan_ ), sumw_p, TAKE_OVER ) ; 280 delete sumw_p ; 289 281 //cout << "sumWeight = " << sumWeight << endl ; 290 282 //cout << "gdataArr = " << gdataArr << endl ; … … 396 388 Matrix<Double> &direction, 397 389 Cube<uChar> &flagtra, 398 Matrix<uInt> &rflag ) 390 Matrix<uInt> &rflag, 391 Matrix<Float> &weight ) 399 392 { 400 393 Table tab( infile ) ; … … 426 419 pollist_ = newlist ; 427 420 } 428 uInt npol= pollist_.size() ;421 npol_ = pollist_.size() ; 429 422 ROArrayColumn<uChar> tmpCol( tab, "FLAGTRA" ) ; 430 uInt nchan = tmpCol( 0 ).nelements() ; 431 uInt nrow = tab.nrow() / npolOrg ; 432 cout << "npol = " << npol << endl ; 433 cout << "nchan = " << nchan << endl ; 434 cout << "nrow = " << nrow << endl ; 435 spectra.resize( npol, nchan, nrow ) ; 436 flagtra.resize( npol, nchan, nrow ) ; 437 rflag.resize( npol, nrow ) ; 438 cout << "pollist_=" << pollist_ << endl ; 439 for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) { 423 nchan_ = tmpCol( 0 ).nelements() ; 424 nrow_ = tab.nrow() / npolOrg ; 425 // cout << "npol_ = " << npol_ << endl ; 426 // cout << "nchan_ = " << nchan_ << endl ; 427 // cout << "nrow_ = " << nrow_ << endl ; 428 spectra.resize( npol_, nchan_, nrow_ ) ; 429 flagtra.resize( npol_, nchan_, nrow_ ) ; 430 rflag.resize( npol_, nrow_ ) ; 431 Cube<Float> tsys( npol_, nchan_, nrow_ ) ; 432 Matrix<Double> tint( npol_, nrow_ ) ; 433 for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) { 440 434 Table subt = tab( tab.col("POLNO") == pollist_[ipol] ) ; 441 435 ROArrayColumn<Float> spectraCol( subt, "SPECTRA" ) ; … … 443 437 ROArrayColumn<uChar> flagtraCol( subt, "FLAGTRA" ) ; 444 438 ROScalarColumn<uInt> rflagCol( subt, "FLAGROW" ) ; 439 ROArrayColumn<Float> tsysCol( subt, "TSYS" ) ; 440 ROScalarColumn<Double> tintCol( subt, "INTERVAL" ) ; 445 441 Matrix<Float> tmpF = spectra.yzPlane( ipol ) ; 446 442 Matrix<uChar> tmpUC = flagtra.yzPlane( ipol ) ; 447 443 Vector<uInt> tmpUI = rflag.row( ipol ) ; 448 cout << "tmpF.shape()=" << tmpF.shape() << endl ;449 cout << "tmpUC.shape()=" << tmpUC.shape() << endl ;450 cout << "tmpUI.shape()=" << tmpUI.shape() << endl ;451 444 spectraCol.getColumn( tmpF ) ; 452 445 flagtraCol.getColumn( tmpUC ) ; … … 454 447 if ( ipol == 0 ) 455 448 directionCol.getColumn( direction ) ; 456 } 457 cout << "getData end" << endl ; 449 Matrix<Float> tmpF2 = tsysCol.getColumn() ; 450 Vector<Double> tmpD = tint.row( ipol ) ; 451 if ( tmpF2.shape()(0) == nchan_ ) { 452 tsys.yzPlane( ipol ) = tmpF2 ; 453 } 454 else { 455 tsys.yzPlane( ipol ) = tmpF2(0,0) ; 456 } 457 tintCol.getColumn( tmpD ) ; 458 } 459 460 getWeight( weight, tsys, tint ) ; 461 } 462 463 void STGrid::getWeight( Matrix<Float> &w, 464 Cube<Float> &tsys, 465 Matrix<Double> &tint ) 466 { 467 // resize 468 w.resize( nchan_, nrow_ ) ; 469 470 // set weight 471 w = 1.0 ; 472 Bool warn = False ; 473 if ( wtype_.compare( "UNIFORM" ) == 0 ) { 474 // do nothing 475 } 476 else if ( wtype_.compare( "TINT" ) == 0 ) { 477 if ( npol_ > 1 ) warn = True ; 478 for ( Int irow = 0 ; irow < nrow_ ; irow++ ) { 479 Float val = mean( tint.column( irow ) ) ; 480 w.column( irow ) = w.column( irow ) * val ; 481 } 482 } 483 else if ( wtype_.compare( "TSYS" ) == 0 ) { 484 if ( npol_ > 1 ) warn = True ; 485 for ( Int irow = 0 ; irow < nrow_ ; irow++ ) { 486 Matrix<Float> arr = tsys.xyPlane( irow ) ; 487 for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) { 488 Float val = mean( arr.column( ichan ) ) ; 489 w(ichan,irow) = w(ichan,irow) / ( val * val ) ; 490 } 491 } 492 } 493 else if ( wtype_.compare( "TINTSYS" ) == 0 ) { 494 if ( npol_ > 1 ) warn = True ; 495 for ( Int irow = 0 ; irow < nrow_ ; irow++ ) { 496 Float interval = mean( tint.column( irow ) ) ; 497 Matrix<Float> arr = tsys.xyPlane( irow ) ; 498 for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) { 499 Float temp = mean( arr.column( ichan ) ) ; 500 w(ichan,irow) = w(ichan,irow) * interval / ( temp * temp ) ; 501 } 502 } 503 } 504 else { 505 LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ; 506 os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ; 507 } 508 509 if ( npol_ > 1 ) { 510 LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ; 511 os << LogIO::WARN << "STGrid doesn't support assigning independent polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ; 512 } 458 513 } 459 514 … … 612 667 Table tab = out->table() ; 613 668 IPosition dshape = data_.shape() ; 614 Int npol = dshape[2] ;615 Int nchan = dshape[3] ;616 Int nrow = nx_ * ny_ * npol ;617 tab.rwKeywordSet().define( "nPol", npol ) ;669 //Int npol = dshape[2] ; 670 //Int nchan = dshape[3] ; 671 Int nrow = nx_ * ny_ * npol_ ; 672 tab.rwKeywordSet().define( "nPol", npol_ ) ; 618 673 tab.addRow( nrow ) ; 619 674 Vector<Double> cpix( 2 ) ; … … 627 682 for ( Int iy = 0 ; iy < ny_ ; iy++ ) { 628 683 for ( Int ix = 0 ; ix < nx_ ; ix++ ) { 629 for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {684 for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) { 630 685 IPosition start( 4, ix, iy, ipol, 0 ) ; 631 IPosition end( 4, ix, iy, ipol, nchan -1 ) ;686 IPosition end( 4, ix, iy, ipol, nchan_-1 ) ; 632 687 IPosition inc( 4, 1, 1, 1, 1 ) ; 633 688 Vector<Float> sp = data_( start, end, inc ) ; -
trunk/src/STGrid.h
r2360 r2361 58 58 void setOption( string convtype="box", 59 59 int convsupport=-1 ) ; 60 61 void setWeight( const string wType="uniform" ) ; 62 60 63 void grid() ; 61 64 … … 79 82 Matrix<Double> &direction, 80 83 Cube<uChar> &flagtra, 81 Matrix<uInt> &rflag ) ; 84 Matrix<uInt> &rflag, 85 Matrix<Float> &weight ) ; 86 87 void getWeight( Matrix<Float> &w, 88 Cube<Float> &tsys, 89 Matrix<Double> &tint ) ; 82 90 83 91 void toInt( Array<uChar> *u, Array<Int> *v ) ; … … 95 103 Int nx_ ; 96 104 Int ny_ ; 105 Int npol_ ; 106 Int nchan_ ; 107 Int nrow_ ; 108 Int ngrid_ ; 97 109 Double cellx_ ; 98 110 Double celly_ ; … … 104 116 Array<Float> data_ ; 105 117 Vector<uInt> pollist_ ; 118 String wtype_ ; 106 119 107 120 Table tab_ ; -
trunk/src/python_STGrid.cpp
r2360 r2361 21 21 .def( init <> () ) 22 22 .def( init < const std::string > () ) 23 //.def( init < const STGrid& > () )24 // .def("_defineimage", &STGridWrapper::defineImage)25 // .def("_setoption", &STGridWrapper::setOption)26 // .def("_grid", &STGridWrapper::grid)27 23 .def("_setpollist", &STGrid::setPolList) 28 24 .def("_defineimage", &STGrid::defineImage) … … 30 26 .def("_grid", &STGrid::grid) 31 27 .def("_setin", &STGrid::setFileIn) 32 // .def("_setout", &STGrid::setFileOut)28 .def("_setweight", &STGrid::setWeight) 33 29 .def("_save", &STGrid::saveData) 34 30 ;
Note:
See TracChangeset
for help on using the changeset viewer.