- Timestamp:
- 12/21/11 15:42:01 (13 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STGrid.cpp
r2378 r2379 18 18 #include <tables/Tables/ScalarColumn.h> 19 19 #include <tables/Tables/ArrayColumn.h> 20 #include <tables/Tables/TableIter.h> 20 21 21 22 #include <measures/Measures/MDirection.h> … … 60 61 userSupport_ = -1 ; 61 62 convSampling_ = 100 ; 62 irow_ = 0 ; 63 nprocessed_ = 0 ; 64 nchunk_ = 0 ; 63 65 } 64 66 … … 177 179 //cout << "convSupport=" << convSupport_ << endl ; 178 180 //cout << "convFunc=" << convFunc << endl ; 179 Float *conv_p = convFunc.getStorage( deleteConv ) ; 180 181 // Extend grid plane with convSupport_ 181 182 // grid data 182 183 Int gnx = nx_ ; 183 184 Int gny = ny_ ; 185 // Extend grid plane with convSupport_ 184 186 // Int gnx = nx_+convSupport_*2 ; 185 187 // Int gny = ny_+convSupport_*2 ; … … 191 193 data_ = 0.0 ; 192 194 Array<Float> gwgtArr( data_ ) ; 193 //Array<Float> gwgtArr( gshape, 0.0 ) ;194 Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ;195 Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ;196 197 // data selection198 selectData( tab_ ) ;199 setupArray( tab_ ) ;200 195 201 196 // data storage 202 IPosition mshape( 3, npol_, nchan_, 1 ) ; 203 IPosition vshape( 2, npol_, 1 ) ; 204 IPosition dshape( 2, 2, 1 ) ; 197 Int irow = -1 ; 198 IPosition mshape( 3, npol_, nchan_, nchunk_ ) ; 199 IPosition vshape( 2, npol_, nchunk_ ) ; 200 IPosition dshape( 2, 2, nchunk_ ) ; 205 201 Array<Complex> spectra( mshape ) ; 206 202 Array<Double> direction( dshape ) ; … … 210 206 Array<Double> xypos( dshape ) ; 211 207 208 // parameters for gridding 209 Int idopsf = 0 ; 210 Int *chanMap = new Int[nchan_] ; 211 { 212 Int *work_p = chanMap ; 213 for ( Int i = 0 ; i < nchan_ ; i++ ) { 214 *work_p = i ; 215 work_p++ ; 216 } 217 } 218 Int *polMap = new Int[npol_] ; 219 { 220 Int *work_p = polMap ; 221 for ( Int i = 0 ; i < npol_ ; i++ ) { 222 *work_p = i ; 223 work_p++ ; 224 } 225 } 226 Double *sumw_p = new Double[npol_*nchan_] ; 227 { 228 Double *work_p = sumw_p ; 229 for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) { 230 *work_p = 0.0 ; 231 work_p++ ; 232 } 233 } 234 235 // for performance check 236 double eGetDataChunk = 0.0 ; 237 double eToPixel = 0.0 ; 238 double eGGridSD = 0.0 ; 239 212 240 while( !pastEnd() ) { 213 241 // retrieve data 214 getDataChunk( spectra, direction, flagtra, rflag, weight ) ; 242 t0 = mathutil::gettimeofday_sec() ; 243 Int nrow = getDataChunk( spectra, direction, flagtra, rflag, weight ) ; 244 //os << "nrow = " << nrow << LogIO::POST ; 245 t1 = mathutil::gettimeofday_sec() ; 246 eGetDataChunk += t1-t0 ; 215 247 216 248 // world -> pixel 249 t0 = mathutil::gettimeofday_sec() ; 217 250 toPixel( direction, xypos ) ; 218 251 t1 = mathutil::gettimeofday_sec() ; 252 eToPixel += t1-t0 ; 253 254 // prepare pointer 255 Float *conv_p = convFunc.getStorage( deleteConv ) ; 256 Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ; 257 Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ; 258 const Complex *data_p = spectra.getStorage( deleteData ) ; 259 const Float *wgt_p = weight.getStorage( deleteWgt ) ; 260 const Int *flag_p = flagtra.getStorage( deleteFlag ) ; 261 const Int *rflag_p = rflag.getStorage( deleteFlagR ) ; 262 Double *xypos_p = xypos.getStorage( deletePos ) ; 263 219 264 // call ggridsd 220 } 221 265 irow = -1 ; 266 t0 = mathutil::gettimeofday_sec() ; 267 ggridsd( xypos_p, 268 data_p, 269 &npol_, 270 &nchan_, 271 &idopsf, 272 flag_p, 273 rflag_p, 274 wgt_p, 275 &nrow, 276 &irow, 277 gdata_p, 278 wdata_p, 279 &gnx, 280 &gny, 281 &npol_, 282 &nchan_, 283 &convSupport_, 284 &convSampling_, 285 conv_p, 286 chanMap, 287 polMap, 288 sumw_p ) ; 289 t1 = mathutil::gettimeofday_sec() ; 290 eGGridSD += t1-t0 ; 291 292 // finalization 293 convFunc.putStorage( conv_p, deleteConv ) ; 294 gdataArrC.putStorage( gdata_p, deleteDataG ) ; 295 gwgtArr.putStorage( wdata_p, deleteWgtG ) ; 296 xypos.putStorage( xypos_p, deletePos ) ; 297 spectra.freeStorage( data_p, deleteData ) ; 298 weight.freeStorage( wgt_p, deleteWgt ) ; 299 flagtra.freeStorage( flag_p, deleteFlag ) ; 300 rflag.freeStorage( rflag_p, deleteFlagR ) ; 301 } 302 os << "getDataChunk: elapsed time is " << eGetDataChunk << " sec." << LogIO::POST ; 303 os << "toPixel: elapsed time is " << eToPixel << " sec." << LogIO::POST ; 304 os << "ggridsd: elapsed time is " << eGGridSD << " sec." << LogIO::POST ; 305 306 307 // finalization 308 delete polMap ; 309 delete chanMap ; 310 delete sumw_p ; 311 222 312 // set data 223 313 setData( gdataArrC, gwgtArr ) ; 314 224 315 } 225 316 226 317 Bool STGrid::pastEnd() 227 318 { 228 Bool b = irow_ >= nrow_ ; 319 LogIO os( LogOrigin("STGrid","pastEnd",WHERE) ) ; 320 Bool b = nprocessed_ >= nrow_ ; 229 321 return b ; 230 322 } 231 323 232 void STGrid::grid() 324 void STGrid::grid() 325 { 326 // data selection 327 selectData() ; 328 setupArray() ; 329 sortData() ; 330 331 if ( npol_ > 1 ) { 332 LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; 333 os << LogIO::WARN << "STGrid doesn't support assigning polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ; 334 } 335 336 if ( wtype_.compare("UNIFORM") != 0 && 337 wtype_.compare("TINT") != 0 && 338 wtype_.compare("TINTSYS") != 0 ) { 339 LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; 340 os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ; 341 wtype_ = "UNIFORM" ; 342 } 343 344 Bool doAll = examine() ; 345 346 if ( doAll ) 347 gridAll() ; 348 else 349 gridPerRow() ; 350 } 351 352 Bool STGrid::examine() 353 { 354 // TODO: nchunk_ must be determined from nchan_, npol_, and (nx_,ny_) 355 // by considering data size to be allocated for ggridsd input/output 356 nchunk_ = 100 ; 357 Bool b = nchunk_ >= nrow_ ; 358 return b ; 359 } 360 361 void STGrid::gridAll() 233 362 { 234 363 LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; … … 380 509 double t0, t1 ; 381 510 t0 = mathutil::gettimeofday_sec() ; 382 //data.resize( gdata.shape() ) ;383 511 uInt len = data_.nelements() ; 384 512 const Complex *w1_p ; 385 513 Float *w2_p ; 386 Bool b 0, b1, b2 ;514 Bool b1, b2 ; 387 515 const Complex *gdata_p = gdata.getStorage( b1 ) ; 388 516 Float *gwgt_p = data_.getStorage( b2 ) ; … … 390 518 w2_p = gwgt_p ; 391 519 for ( uInt i = 0 ; i < len ; i++ ) { 392 //*w2_p = (*w2_p > 0.0) ? ((*w1_p).real() / *w2_p) : 0.0 ;393 520 if ( *w2_p > 0.0 ) *w2_p = (*w1_p).real() / *w2_p ; 394 521 w1_p++ ; … … 519 646 } 520 647 521 void STGrid::selectData( Table &tab)648 void STGrid::selectData() 522 649 { 523 650 Int ifno = ifno_ ; … … 539 666 node = node && taborg.col("SCANNO").in( scanlist_ ) ; 540 667 } 541 // Block<String> cols( 3 ) ; 542 // cols[0] = "TIME" ; 543 // cols[1] = "BEAMNO" ; 544 // cols[2] = "POLNO" ; 545 // Block<Int> order( 3, Sort::Ascending ) ; 546 // tab = taborg( node ).sort( cols, order ) ; 547 tab = taborg( node ) ; 548 if ( tab.nrow() == 0 ) { 668 tab_ = taborg( node ) ; 669 if ( tab_.nrow() == 0 ) { 549 670 LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ; 550 671 os << LogIO::SEVERE … … 554 675 os << LogIO::EXCEPTION ; 555 676 } 677 attach() ; 678 } 679 680 void STGrid::attach() 681 { 682 // attach to table 683 spectraCol_.attach( tab_, "SPECTRA" ) ; 684 flagtraCol_.attach( tab_, "FLAGTRA" ) ; 685 directionCol_.attach( tab_, "DIRECTION" ) ; 686 flagRowCol_.attach( tab_, "FLAGROW" ) ; 687 tsysCol_.attach( tab_, "TSYS" ) ; 688 intervalCol_.attach( tab_, "INTERVAL" ) ; 556 689 } 557 690 … … 564 697 LogIO os( LogOrigin("STGrid","getData",WHERE) ) ; 565 698 // os << "start" << LogIO::POST ; 566 Table tab ;567 selectData( tab ) ;568 setupArray( tab ) ;569 699 // os << "npol_ = " << npol_ << LogIO::POST ; 570 700 // os << "nchan_ = " << nchan_ << LogIO::POST ; … … 598 728 long rincr = npol_ * nchan_ ; 599 729 for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) { 600 Table subt = tab ( tab.col("POLNO") == pollist_[ipol] ) ;730 Table subt = tab_( tab_.col("POLNO") == pollist_[ipol] ) ; 601 731 ROArrayColumn<Float> spectraCol( subt, "SPECTRA" ) ; 602 732 ROArrayColumn<Double> directionCol( subt, "DIRECTION" ) ; … … 670 800 } 671 801 672 void STGrid::getDataChunk( Array<Complex> &spectra, 673 Array<Double> &direction, 674 Array<Int> &flagtra, 675 Array<Int> &rflag, 676 Array<Float> &weight ) 677 { 678 } 679 680 void STGrid::setupArray( Table &tab ) 802 Int STGrid::getDataChunk( Array<Complex> &spectra, 803 Array<Double> &direction, 804 Array<Int> &flagtra, 805 Array<Int> &rflag, 806 Array<Float> &weight ) 807 { 808 Array<Float> spFloat( spectra.shape() ) ; 809 Array<uChar> fluChar( flagtra.shape() ) ; 810 Array<uInt> fruInt( rflag.shape() ) ; 811 Int nrow = getDataChunk( spFloat, direction, fluChar, fruInt, weight ) ; 812 convertArray( spectra, spFloat ) ; 813 convertArray( flagtra, fluChar ) ; 814 convertArray( rflag, fruInt ) ; 815 816 return nrow ; 817 } 818 819 Int STGrid::getDataChunk( Array<Float> &spectra, 820 Array<Double> &direction, 821 Array<uChar> &flagtra, 822 Array<uInt> &rflag, 823 Array<Float> &weight ) 824 { 825 LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ; 826 Int nrow = min( spectra.shape()[2], nrow_-nprocessed_ ) ; 827 Array<Float> tsys( spectra.shape() ) ; 828 Array<Double> tint( rflag.shape() ) ; 829 IPosition m( 2, 0, 2 ) ; 830 IPosition v( 1, 0 ) ; 831 ArrayIterator<Float> spi( spectra, m, False ) ; 832 ArrayIterator<uChar> fli( flagtra, m, False ) ; 833 ArrayIterator<Float> tsi( tsys, m, False ) ; 834 ArrayIterator<Double> di( direction, v ) ; 835 Bool bfr, bti ; 836 uInt *fr_p = rflag.getStorage( bfr ) ; 837 Double *ti_p = tint.getStorage( bti ) ; 838 uInt *wfr_p = fr_p ; 839 Double *wti_p = ti_p ; 840 Int offset = nprocessed_ * npol_ ; 841 for ( Int irow = 0 ; irow < npol_ * nrow ; irow++ ) { 842 Array<Float> spSlice = spi.array() ; 843 Array<uChar> flSlice = fli.array() ; 844 Array<Float> tsSlice = tsi.array() ; 845 846 uInt idx = rows_[offset+irow] ; 847 spectraCol_.get( idx, spSlice ) ; 848 849 flagtraCol_.get( idx, flSlice ) ; 850 Vector<Float> tmpF = tsysCol_( idx ) ; 851 if ( tmpF.nelements() == (uInt)nchan_ ) { 852 tsSlice = tmpF ; 853 } 854 else { 855 tsSlice = tmpF[0] ; 856 } 857 *wfr_p = flagRowCol_( idx ) ; 858 *wti_p = intervalCol_( idx ) ; 859 860 spi.next() ; 861 fli.next() ; 862 tsi.next() ; 863 wfr_p++ ; 864 wti_p++ ; 865 } 866 rflag.putStorage( fr_p, bfr ) ; 867 tint.putStorage( ti_p, bti ) ; 868 869 for ( Int irow = 0 ; irow < nrow ; irow += npol_ ) { 870 uInt idx = rows_[offset+irow] ; 871 directionCol_.get( idx, di.array() ) ; 872 di.next() ; 873 } 874 875 getWeight( weight, tsys, tint ) ; 876 877 nprocessed_ += nrow ; 878 879 return nrow ; 880 } 881 882 void STGrid::setupArray() 681 883 { 682 884 LogIO os( LogOrigin("STGrid","setupArray",WHERE) ) ; 683 ROScalarColumn<uInt> polnoCol( tab , "POLNO" ) ;885 ROScalarColumn<uInt> polnoCol( tab_, "POLNO" ) ; 684 886 Vector<uInt> pols = polnoCol.getColumn() ; 685 887 //os << pols << LogIO::POST ; … … 714 916 os << LogIO::SEVERE << "Empty pollist" << LogIO::EXCEPTION ; 715 917 } 716 nrow_ = tab .nrow() / npolOrg ;717 ROArrayColumn<uChar> tmpCol( tab , "FLAGTRA" ) ;918 nrow_ = tab_.nrow() / npolOrg ; 919 ROArrayColumn<uChar> tmpCol( tab_, "FLAGTRA" ) ; 718 920 nchan_ = tmpCol( 0 ).nelements() ; 719 921 // os << "npol_ = " << npol_ << "(" << pollist_ << ")" << endl … … 727 929 { 728 930 LogIO os( LogOrigin("STGrid","getWeight",WHERE) ) ; 729 double t0, t1 ;730 t0 = mathutil::gettimeofday_sec() ;931 // double t0, t1 ; 932 // t0 = mathutil::gettimeofday_sec() ; 731 933 // resize 732 934 IPosition refShape = tsys.shape() ; … … 797 999 else { 798 1000 //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ; 799 os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;1001 //os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ; 800 1002 w = 1.0 ; 801 1003 } 802 1004 803 if ( npol_ > 1 ) { 804 //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ; 805 os << LogIO::WARN << "STGrid doesn't support assigning polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ; 806 } 807 t1 = mathutil::gettimeofday_sec() ; 808 os << "getWeight: elapsed time is " << t1-t0 << " sec" << LogIO::POST ; 1005 // t1 = mathutil::gettimeofday_sec() ; 1006 // os << "getWeight: elapsed time is " << t1-t0 << " sec" << LogIO::POST ; 809 1007 } 810 1008 … … 1063 1261 tab = Table( name, Table::Update ) ; 1064 1262 } 1065 } 1263 1264 void STGrid::sortData() 1265 { 1266 LogIO os( LogOrigin("STGRid","sortData",WHERE) ) ; 1267 double t0, t1 ; 1268 t0 = mathutil::gettimeofday_sec() ; 1269 rows_.resize( npol_*nrow_ ) ; 1270 Table tab = tab_( tab_.col("POLNO").in(pollist_) ) ; 1271 Block<String> cols( 2 ) ; 1272 cols[0] = "TIME" ; 1273 cols[1] = "BEAMNO" ; 1274 TableIterator iter( tab, cols ) ; 1275 uInt idx = 0 ; 1276 while( !iter.pastEnd() ) { 1277 Table t = iter.table().sort( "POLNO" ) ; 1278 Vector<uInt> rows = t.rowNumbers() ; 1279 //os << "rows=" << rows << LogIO::POST ; 1280 for ( uInt i = 0 ; i < rows.nelements() ; i++ ) { 1281 rows_[idx] = rows[i] ; 1282 idx++ ; 1283 } 1284 iter.next() ; 1285 } 1286 t1 = mathutil::gettimeofday_sec() ; 1287 os << "sortData: elapsed time is " << t1-t0 << " sec" << LogIO::POST ; 1288 //os << "rows_ = " << rows_ << LogIO::POST ; 1289 } 1290 } -
trunk/src/STGrid.h
r2378 r2379 29 29 30 30 #include <tables/Tables/Table.h> 31 //#include <tables/Tables/ScalarColumn.h>32 //#include <tables/Tables/ArrayColumn.h>31 #include <tables/Tables/ScalarColumn.h> 32 #include <tables/Tables/ArrayColumn.h> 33 33 34 34 // #include <measures/Measures/MDirection.h> … … 66 66 67 67 void grid() ; 68 void gridAll() ; 68 69 void gridPerRow() ; 69 70 … … 96 97 Array<uInt> &rflag, 97 98 Array<Float> &weight ) ; 98 void getDataChunk( Array<Complex> &spectra, 99 Array<Double> &direction, 100 Array<Int> &flagtra, 101 Array<Int> &rflag, 102 Array<Float> &weight ) ; 99 Int getDataChunk( Array<Complex> &spectra, 100 Array<Double> &direction, 101 Array<Int> &flagtra, 102 Array<Int> &rflag, 103 Array<Float> &weight ) ; 104 Int getDataChunk( Array<Float> &spectra, 105 Array<Double> &direction, 106 Array<uChar> &flagtra, 107 Array<uInt> &rflag, 108 Array<Float> &weight ) ; 103 109 104 110 void getWeight( Array<Float> &w, … … 116 122 void pbFunc( Vector<Float> &convFunc ) ; 117 123 void setConvFunc( Vector<Float> &convFunc ) ; 118 void selectData( Table &tab ) ;119 124 120 125 Float polMean( const Float *p ) ; 121 126 Double polMean( const Double *p ) ; 122 127 123 void setupArray( Table &tab ) ;124 125 128 void prepareTable( Table &tab, String &name ) ; 126 129 127 130 Bool pastEnd() ; 131 132 void selectData() ; 133 void setupArray() ; 134 void sortData() ; 135 136 Bool examine() ; 137 void attach() ; 128 138 129 139 … … 148 158 149 159 Table tab_ ; 150 Int irow_ ; 160 ROArrayColumn<Float> spectraCol_ ; 161 ROArrayColumn<uChar> flagtraCol_ ; 162 ROArrayColumn<Double> directionCol_ ; 163 ROScalarColumn<uInt> flagRowCol_ ; 164 ROArrayColumn<Float> tsysCol_ ; 165 ROScalarColumn<Double> intervalCol_ ; 166 Int nprocessed_ ; 167 Vector<uInt> rows_ ; 168 Int nchunk_ ; 151 169 }; 152 170 }
Note:
See TracChangeset
for help on using the changeset viewer.