[2356] | 1 | #include <iostream> |
---|
| 2 | #include <fstream> |
---|
| 3 | |
---|
| 4 | #include <casa/BasicSL/String.h> |
---|
| 5 | #include <casa/Arrays/Vector.h> |
---|
| 6 | #include <casa/Arrays/Matrix.h> |
---|
| 7 | #include <casa/Arrays/Cube.h> |
---|
| 8 | #include <casa/Arrays/ArrayMath.h> |
---|
[2375] | 9 | #include <casa/Arrays/ArrayIter.h> |
---|
[2356] | 10 | #include <casa/Quanta/Quantum.h> |
---|
| 11 | #include <casa/Quanta/QuantumHolder.h> |
---|
| 12 | #include <casa/Utilities/CountedPtr.h> |
---|
[2361] | 13 | #include <casa/Logging/LogIO.h> |
---|
[2356] | 14 | |
---|
| 15 | #include <tables/Tables/Table.h> |
---|
[2360] | 16 | #include <tables/Tables/TableRecord.h> |
---|
| 17 | #include <tables/Tables/ExprNode.h> |
---|
[2356] | 18 | #include <tables/Tables/ScalarColumn.h> |
---|
| 19 | #include <tables/Tables/ArrayColumn.h> |
---|
[2379] | 20 | #include <tables/Tables/TableIter.h> |
---|
[2356] | 21 | |
---|
| 22 | #include <measures/Measures/MDirection.h> |
---|
| 23 | |
---|
[2364] | 24 | #include <MathUtils.h> |
---|
| 25 | |
---|
[2356] | 26 | #include "STGrid.h" |
---|
| 27 | |
---|
| 28 | using namespace std ; |
---|
| 29 | using namespace casa ; |
---|
| 30 | using namespace asap ; |
---|
| 31 | |
---|
| 32 | namespace asap { |
---|
| 33 | |
---|
| 34 | // constructor |
---|
| 35 | STGrid::STGrid() |
---|
| 36 | { |
---|
| 37 | init() ; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | STGrid::STGrid( const string infile ) |
---|
| 41 | { |
---|
| 42 | init() ; |
---|
| 43 | |
---|
| 44 | setFileIn( infile ) ; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void STGrid::init() |
---|
| 48 | { |
---|
[2362] | 49 | ifno_ = -1 ; |
---|
[2356] | 50 | nx_ = -1 ; |
---|
| 51 | ny_ = -1 ; |
---|
[2361] | 52 | npol_ = 0 ; |
---|
| 53 | nchan_ = 0 ; |
---|
| 54 | nrow_ = 0 ; |
---|
[2356] | 55 | cellx_ = 0.0 ; |
---|
| 56 | celly_ = 0.0 ; |
---|
| 57 | center_ = Vector<Double> ( 2, 0.0 ) ; |
---|
| 58 | convType_ = "BOX" ; |
---|
[2361] | 59 | wtype_ = "UNIFORM" ; |
---|
[2356] | 60 | convSupport_ = -1 ; |
---|
| 61 | userSupport_ = -1 ; |
---|
| 62 | convSampling_ = 100 ; |
---|
[2379] | 63 | nprocessed_ = 0 ; |
---|
| 64 | nchunk_ = 0 ; |
---|
[2356] | 65 | } |
---|
| 66 | |
---|
| 67 | void STGrid::setFileIn( const string infile ) |
---|
| 68 | { |
---|
| 69 | String name( infile ) ; |
---|
| 70 | if ( infile_.compare( name ) != 0 ) { |
---|
| 71 | infile_ = String( infile ) ; |
---|
| 72 | tab_ = Table( infile_ ) ; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[2360] | 76 | void STGrid::setPolList( vector<unsigned int> pols ) |
---|
| 77 | { |
---|
| 78 | pollist_.assign( Vector<uInt>( pols ) ) ; |
---|
| 79 | cout << "pollist_ = " << pollist_ << endl ; |
---|
| 80 | } |
---|
| 81 | |
---|
[2364] | 82 | void STGrid::setScanList( vector<unsigned int> scans ) |
---|
| 83 | { |
---|
| 84 | scanlist_.assign( Vector<uInt>( scans ) ) ; |
---|
| 85 | cout << "scanlist_ = " << scanlist_ << endl ; |
---|
| 86 | } |
---|
| 87 | |
---|
[2361] | 88 | void STGrid::setWeight( const string wType ) |
---|
| 89 | { |
---|
| 90 | wtype_ = String( wType ) ; |
---|
| 91 | wtype_.upcase() ; |
---|
| 92 | cout << "wtype_ = " << wtype_ << endl ; |
---|
| 93 | } |
---|
| 94 | |
---|
[2356] | 95 | void STGrid::defineImage( int nx, |
---|
| 96 | int ny, |
---|
| 97 | string scellx, |
---|
| 98 | string scelly, |
---|
| 99 | string scenter ) |
---|
| 100 | { |
---|
| 101 | ROArrayColumn<Double> dirCol( tab_, "DIRECTION" ) ; |
---|
| 102 | Matrix<Double> direction = dirCol.getColumn() ; |
---|
| 103 | Double rmax, rmin, dmax, dmin ; |
---|
| 104 | minMax( rmin, rmax, direction.row( 0 ) ) ; |
---|
| 105 | minMax( dmin, dmax, direction.row( 1 ) ) ; |
---|
| 106 | |
---|
| 107 | Int npx = (Int)nx ; |
---|
| 108 | Int npy = (Int)ny ; |
---|
| 109 | String cellx( scellx ) ; |
---|
| 110 | String celly( scelly ) ; |
---|
| 111 | String center( scenter ) ; |
---|
| 112 | setupGrid( npx, npy, |
---|
| 113 | cellx, celly, |
---|
| 114 | rmin, rmax, |
---|
| 115 | dmin, dmax, |
---|
| 116 | center ) ; |
---|
| 117 | } |
---|
| 118 | |
---|
[2364] | 119 | void STGrid::setFunc( string convType, |
---|
| 120 | int convSupport ) |
---|
[2356] | 121 | { |
---|
| 122 | convType_ = String( convType ) ; |
---|
| 123 | convType_.upcase() ; |
---|
| 124 | userSupport_ = (Int)convSupport ; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | #define NEED_UNDERSCORES |
---|
| 128 | #if defined(NEED_UNDERSCORES) |
---|
| 129 | #define ggridsd ggridsd_ |
---|
| 130 | #endif |
---|
| 131 | extern "C" { |
---|
| 132 | void ggridsd(Double*, |
---|
| 133 | const Complex*, |
---|
| 134 | Int*, |
---|
| 135 | Int*, |
---|
| 136 | Int*, |
---|
| 137 | const Int*, |
---|
| 138 | const Int*, |
---|
| 139 | const Float*, |
---|
| 140 | Int*, |
---|
| 141 | Int*, |
---|
| 142 | Complex*, |
---|
| 143 | Float*, |
---|
| 144 | Int*, |
---|
| 145 | Int*, |
---|
| 146 | Int *, |
---|
| 147 | Int *, |
---|
| 148 | Int*, |
---|
| 149 | Int*, |
---|
| 150 | Float*, |
---|
| 151 | Int*, |
---|
| 152 | Int*, |
---|
| 153 | Double*); |
---|
| 154 | } |
---|
[2378] | 155 | void STGrid::gridPerRow() |
---|
| 156 | { |
---|
| 157 | LogIO os( LogOrigin("STGrid", "gridPerRow", WHERE) ) ; |
---|
| 158 | double t0, t1 ; |
---|
| 159 | |
---|
| 160 | // grid parameter |
---|
| 161 | os << LogIO::DEBUGGING ; |
---|
| 162 | os << "----------" << endl ; |
---|
| 163 | os << "Grid parameter summary" << endl ; |
---|
| 164 | os << " (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ; |
---|
| 165 | os << " (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ; |
---|
| 166 | os << " center = " << center_ << endl ; |
---|
| 167 | os << "----------" << LogIO::POST ; |
---|
| 168 | os << LogIO::NORMAL ; |
---|
| 169 | |
---|
| 170 | // boolean for getStorage |
---|
| 171 | Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ; |
---|
| 172 | |
---|
| 173 | // convolution kernel |
---|
| 174 | Vector<Float> convFunc ; |
---|
| 175 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 176 | setConvFunc( convFunc ) ; |
---|
| 177 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 178 | os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
| 179 | //cout << "convSupport=" << convSupport_ << endl ; |
---|
| 180 | //cout << "convFunc=" << convFunc << endl ; |
---|
| 181 | |
---|
[2379] | 182 | // grid data |
---|
[2378] | 183 | Int gnx = nx_ ; |
---|
| 184 | Int gny = ny_ ; |
---|
[2379] | 185 | // Extend grid plane with convSupport_ |
---|
[2378] | 186 | // Int gnx = nx_+convSupport_*2 ; |
---|
| 187 | // Int gny = ny_+convSupport_*2 ; |
---|
| 188 | IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ; |
---|
| 189 | Array<Complex> gdataArrC( gshape, 0.0 ) ; |
---|
| 190 | // 2011/12/20 TN |
---|
| 191 | // data_ and gwgtArr share storage |
---|
| 192 | data_.resize( gshape ) ; |
---|
| 193 | data_ = 0.0 ; |
---|
| 194 | Array<Float> gwgtArr( data_ ) ; |
---|
| 195 | |
---|
| 196 | // data storage |
---|
[2379] | 197 | Int irow = -1 ; |
---|
[2380] | 198 | IPosition cshape( 3, npol_, nchan_, nchunk_ ) ; |
---|
| 199 | IPosition mshape( 2, npol_, nchunk_ ) ; |
---|
| 200 | IPosition vshape( 1, nchunk_ ) ; |
---|
[2379] | 201 | IPosition dshape( 2, 2, nchunk_ ) ; |
---|
[2380] | 202 | IPosition wshape( 2, nchan_, nchunk_ ) ; |
---|
| 203 | Array<Complex> spectra( cshape ) ; |
---|
[2378] | 204 | Array<Double> direction( dshape ) ; |
---|
[2380] | 205 | Array<Int> flagtra( cshape ) ; |
---|
| 206 | //Array<Int> rflag( mshape ) ; |
---|
[2378] | 207 | Array<Int> rflag( vshape ) ; |
---|
[2380] | 208 | Array<Float> weight( wshape ) ; |
---|
[2378] | 209 | Array<Double> xypos( dshape ) ; |
---|
| 210 | |
---|
[2379] | 211 | // parameters for gridding |
---|
| 212 | Int idopsf = 0 ; |
---|
| 213 | Int *chanMap = new Int[nchan_] ; |
---|
| 214 | { |
---|
| 215 | Int *work_p = chanMap ; |
---|
| 216 | for ( Int i = 0 ; i < nchan_ ; i++ ) { |
---|
| 217 | *work_p = i ; |
---|
| 218 | work_p++ ; |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | Int *polMap = new Int[npol_] ; |
---|
| 222 | { |
---|
| 223 | Int *work_p = polMap ; |
---|
| 224 | for ( Int i = 0 ; i < npol_ ; i++ ) { |
---|
| 225 | *work_p = i ; |
---|
| 226 | work_p++ ; |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | Double *sumw_p = new Double[npol_*nchan_] ; |
---|
| 230 | { |
---|
| 231 | Double *work_p = sumw_p ; |
---|
| 232 | for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) { |
---|
| 233 | *work_p = 0.0 ; |
---|
| 234 | work_p++ ; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | // for performance check |
---|
| 239 | double eGetDataChunk = 0.0 ; |
---|
| 240 | double eToPixel = 0.0 ; |
---|
| 241 | double eGGridSD = 0.0 ; |
---|
| 242 | |
---|
[2380] | 243 | // prepare pointer |
---|
| 244 | Float *conv_p = convFunc.getStorage( deleteConv ) ; |
---|
| 245 | Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ; |
---|
| 246 | Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ; |
---|
| 247 | const Complex *data_p = spectra.getStorage( deleteData ) ; |
---|
| 248 | const Float *wgt_p = weight.getStorage( deleteWgt ) ; |
---|
| 249 | const Int *flag_p = flagtra.getStorage( deleteFlag ) ; |
---|
| 250 | const Int *rflag_p = rflag.getStorage( deleteFlagR ) ; |
---|
| 251 | Double *xypos_p = xypos.getStorage( deletePos ) ; |
---|
| 252 | |
---|
[2378] | 253 | while( !pastEnd() ) { |
---|
| 254 | // retrieve data |
---|
[2379] | 255 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 256 | Int nrow = getDataChunk( spectra, direction, flagtra, rflag, weight ) ; |
---|
| 257 | //os << "nrow = " << nrow << LogIO::POST ; |
---|
| 258 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 259 | eGetDataChunk += t1-t0 ; |
---|
[2378] | 260 | |
---|
| 261 | // world -> pixel |
---|
[2379] | 262 | t0 = mathutil::gettimeofday_sec() ; |
---|
[2378] | 263 | toPixel( direction, xypos ) ; |
---|
[2379] | 264 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 265 | eToPixel += t1-t0 ; |
---|
| 266 | |
---|
[2378] | 267 | // call ggridsd |
---|
[2379] | 268 | irow = -1 ; |
---|
| 269 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 270 | ggridsd( xypos_p, |
---|
| 271 | data_p, |
---|
| 272 | &npol_, |
---|
| 273 | &nchan_, |
---|
| 274 | &idopsf, |
---|
| 275 | flag_p, |
---|
| 276 | rflag_p, |
---|
| 277 | wgt_p, |
---|
| 278 | &nrow, |
---|
| 279 | &irow, |
---|
| 280 | gdata_p, |
---|
| 281 | wdata_p, |
---|
| 282 | &gnx, |
---|
| 283 | &gny, |
---|
| 284 | &npol_, |
---|
| 285 | &nchan_, |
---|
| 286 | &convSupport_, |
---|
| 287 | &convSampling_, |
---|
| 288 | conv_p, |
---|
| 289 | chanMap, |
---|
| 290 | polMap, |
---|
| 291 | sumw_p ) ; |
---|
| 292 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 293 | eGGridSD += t1-t0 ; |
---|
| 294 | |
---|
[2378] | 295 | } |
---|
[2379] | 296 | os << "getDataChunk: elapsed time is " << eGetDataChunk << " sec." << LogIO::POST ; |
---|
| 297 | os << "toPixel: elapsed time is " << eToPixel << " sec." << LogIO::POST ; |
---|
| 298 | os << "ggridsd: elapsed time is " << eGGridSD << " sec." << LogIO::POST ; |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | // finalization |
---|
[2380] | 302 | convFunc.putStorage( conv_p, deleteConv ) ; |
---|
| 303 | gdataArrC.putStorage( gdata_p, deleteDataG ) ; |
---|
| 304 | gwgtArr.putStorage( wdata_p, deleteWgtG ) ; |
---|
| 305 | xypos.putStorage( xypos_p, deletePos ) ; |
---|
| 306 | spectra.freeStorage( data_p, deleteData ) ; |
---|
| 307 | weight.freeStorage( wgt_p, deleteWgt ) ; |
---|
| 308 | flagtra.freeStorage( flag_p, deleteFlag ) ; |
---|
| 309 | rflag.freeStorage( rflag_p, deleteFlagR ) ; |
---|
[2379] | 310 | delete polMap ; |
---|
| 311 | delete chanMap ; |
---|
| 312 | delete sumw_p ; |
---|
| 313 | |
---|
[2378] | 314 | // set data |
---|
| 315 | setData( gdataArrC, gwgtArr ) ; |
---|
[2379] | 316 | |
---|
[2378] | 317 | } |
---|
| 318 | |
---|
| 319 | Bool STGrid::pastEnd() |
---|
| 320 | { |
---|
[2379] | 321 | LogIO os( LogOrigin("STGrid","pastEnd",WHERE) ) ; |
---|
| 322 | Bool b = nprocessed_ >= nrow_ ; |
---|
[2378] | 323 | return b ; |
---|
| 324 | } |
---|
| 325 | |
---|
[2379] | 326 | void STGrid::grid() |
---|
[2356] | 327 | { |
---|
[2379] | 328 | // data selection |
---|
| 329 | selectData() ; |
---|
| 330 | setupArray() ; |
---|
| 331 | sortData() ; |
---|
| 332 | |
---|
| 333 | if ( npol_ > 1 ) { |
---|
| 334 | LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; |
---|
| 335 | os << LogIO::WARN << "STGrid doesn't support assigning polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | if ( wtype_.compare("UNIFORM") != 0 && |
---|
| 339 | wtype_.compare("TINT") != 0 && |
---|
| 340 | wtype_.compare("TINTSYS") != 0 ) { |
---|
| 341 | LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; |
---|
| 342 | os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ; |
---|
| 343 | wtype_ = "UNIFORM" ; |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | Bool doAll = examine() ; |
---|
| 347 | |
---|
| 348 | if ( doAll ) |
---|
| 349 | gridAll() ; |
---|
| 350 | else |
---|
| 351 | gridPerRow() ; |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | Bool STGrid::examine() |
---|
| 355 | { |
---|
| 356 | // TODO: nchunk_ must be determined from nchan_, npol_, and (nx_,ny_) |
---|
| 357 | // by considering data size to be allocated for ggridsd input/output |
---|
| 358 | nchunk_ = 100 ; |
---|
| 359 | Bool b = nchunk_ >= nrow_ ; |
---|
| 360 | return b ; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | void STGrid::gridAll() |
---|
| 364 | { |
---|
[2361] | 365 | LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ; |
---|
[2356] | 366 | |
---|
| 367 | // retrieve data |
---|
[2375] | 368 | Array<Complex> spectra ; |
---|
| 369 | Array<Double> direction ; |
---|
| 370 | Array<Int> flagtra ; |
---|
| 371 | Array<Int> rflag ; |
---|
| 372 | Array<Float> weight ; |
---|
[2364] | 373 | double t0, t1 ; |
---|
| 374 | t0 = mathutil::gettimeofday_sec() ; |
---|
[2362] | 375 | getData( spectra, direction, flagtra, rflag, weight ) ; |
---|
[2364] | 376 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 377 | os << "getData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
[2356] | 378 | IPosition sshape = spectra.shape() ; |
---|
[2361] | 379 | //os << "spectra.shape()=" << spectra.shape() << LogIO::POST ; |
---|
| 380 | //os << "max(spectra) = " << max(spectra) << LogIO::POST ; |
---|
| 381 | //os << "weight = " << weight << LogIO::POST ; |
---|
[2356] | 382 | |
---|
| 383 | // grid parameter |
---|
[2362] | 384 | os << LogIO::DEBUGGING ; |
---|
| 385 | os << "----------" << endl ; |
---|
| 386 | os << "Grid parameter summary" << endl ; |
---|
| 387 | os << " (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ; |
---|
| 388 | os << " (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ; |
---|
| 389 | os << " center = " << center_ << endl ; |
---|
| 390 | os << "----------" << LogIO::POST ; |
---|
| 391 | os << LogIO::NORMAL ; |
---|
[2356] | 392 | |
---|
[2359] | 393 | // convolution kernel |
---|
| 394 | Vector<Float> convFunc ; |
---|
[2364] | 395 | t0 = mathutil::gettimeofday_sec() ; |
---|
[2359] | 396 | setConvFunc( convFunc ) ; |
---|
[2364] | 397 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 398 | os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
[2359] | 399 | //cout << "convSupport=" << convSupport_ << endl ; |
---|
| 400 | //cout << "convFunc=" << convFunc << endl ; |
---|
| 401 | |
---|
[2356] | 402 | // world -> pixel |
---|
[2375] | 403 | Array<Double> xypos( direction.shape(), 0.0 ) ; |
---|
[2364] | 404 | t0 = mathutil::gettimeofday_sec() ; |
---|
[2356] | 405 | toPixel( direction, xypos ) ; |
---|
[2364] | 406 | t1 = mathutil::gettimeofday_sec() ; |
---|
[2375] | 407 | //os << "xypos=" << xypos << LogIO::POST ; |
---|
[2364] | 408 | os << "toPixel: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
[2356] | 409 | |
---|
[2361] | 410 | // call ggridsd |
---|
[2356] | 411 | Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ; |
---|
| 412 | Double *xypos_p = xypos.getStorage( deletePos ) ; |
---|
[2374] | 413 | const Complex *data_p = spectra.getStorage( deleteData ) ; |
---|
[2356] | 414 | const Float *wgt_p = weight.getStorage( deleteWgt ) ; |
---|
[2375] | 415 | //const Int *flag_p = flagI.getStorage( deleteFlag ) ; |
---|
| 416 | //const Int *rflag_p = rflagI.getStorage( deleteFlagR ) ; |
---|
| 417 | const Int *flag_p = flagtra.getStorage( deleteFlag ) ; |
---|
| 418 | const Int *rflag_p = rflag.getStorage( deleteFlagR ) ; |
---|
[2356] | 419 | Float *conv_p = convFunc.getStorage( deleteConv ) ; |
---|
[2359] | 420 | // Extend grid plane with convSupport_ |
---|
[2364] | 421 | Int gnx = nx_ ; |
---|
| 422 | Int gny = ny_ ; |
---|
| 423 | // Int gnx = nx_+convSupport_*2 ; |
---|
| 424 | // Int gny = ny_+convSupport_*2 ; |
---|
[2361] | 425 | IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ; |
---|
[2356] | 426 | Array<Complex> gdataArrC( gshape, 0.0 ) ; |
---|
[2378] | 427 | //Array<Float> gwgtArr( gshape, 0.0 ) ; |
---|
| 428 | // 2011/12/20 TN |
---|
| 429 | // data_ and weight array shares storage |
---|
| 430 | data_.resize( gshape ) ; |
---|
| 431 | data_ = 0.0 ; |
---|
| 432 | Array<Float> gwgtArr( data_ ) ; |
---|
[2356] | 433 | Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ; |
---|
| 434 | Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ; |
---|
| 435 | Int idopsf = 0 ; |
---|
[2361] | 436 | Int *chanMap = new Int[nchan_] ; |
---|
[2356] | 437 | { |
---|
| 438 | Int *work_p = chanMap ; |
---|
[2361] | 439 | for ( Int i = 0 ; i < nchan_ ; i++ ) { |
---|
[2356] | 440 | *work_p = i ; |
---|
| 441 | work_p++ ; |
---|
| 442 | } |
---|
| 443 | } |
---|
[2361] | 444 | Int *polMap = new Int[npol_] ; |
---|
[2356] | 445 | { |
---|
| 446 | Int *work_p = polMap ; |
---|
[2361] | 447 | for ( Int i = 0 ; i < npol_ ; i++ ) { |
---|
[2356] | 448 | *work_p = i ; |
---|
| 449 | work_p++ ; |
---|
| 450 | } |
---|
| 451 | } |
---|
[2361] | 452 | Double *sumw_p = new Double[npol_*nchan_] ; |
---|
[2356] | 453 | { |
---|
| 454 | Double *work_p = sumw_p ; |
---|
[2361] | 455 | for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) { |
---|
[2356] | 456 | *work_p = 0.0 ; |
---|
| 457 | work_p++ ; |
---|
| 458 | } |
---|
| 459 | } |
---|
[2364] | 460 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 461 | Int irow = -1 ; |
---|
[2356] | 462 | ggridsd( xypos_p, |
---|
| 463 | data_p, |
---|
[2361] | 464 | &npol_, |
---|
| 465 | &nchan_, |
---|
[2356] | 466 | &idopsf, |
---|
| 467 | flag_p, |
---|
| 468 | rflag_p, |
---|
| 469 | wgt_p, |
---|
[2361] | 470 | &nrow_, |
---|
[2356] | 471 | &irow, |
---|
| 472 | gdata_p, |
---|
| 473 | wdata_p, |
---|
[2359] | 474 | &gnx, |
---|
| 475 | &gny, |
---|
[2361] | 476 | &npol_, |
---|
| 477 | &nchan_, |
---|
[2356] | 478 | &convSupport_, |
---|
| 479 | &convSampling_, |
---|
| 480 | conv_p, |
---|
| 481 | chanMap, |
---|
| 482 | polMap, |
---|
| 483 | sumw_p ) ; |
---|
[2364] | 484 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 485 | os << "ggridsd: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
[2356] | 486 | xypos.putStorage( xypos_p, deletePos ) ; |
---|
[2374] | 487 | spectra.freeStorage( data_p, deleteData ) ; |
---|
[2356] | 488 | weight.freeStorage( wgt_p, deleteWgt ) ; |
---|
[2375] | 489 | flagtra.freeStorage( flag_p, deleteFlag ) ; |
---|
| 490 | rflag.freeStorage( rflag_p, deleteFlagR ) ; |
---|
[2356] | 491 | convFunc.putStorage( conv_p, deleteConv ) ; |
---|
| 492 | delete polMap ; |
---|
| 493 | delete chanMap ; |
---|
| 494 | gdataArrC.putStorage( gdata_p, deleteDataG ) ; |
---|
| 495 | gwgtArr.putStorage( wdata_p, deleteWgtG ) ; |
---|
[2378] | 496 | setData( gdataArrC, gwgtArr ) ; |
---|
[2361] | 497 | //Matrix<Double> sumWeight( IPosition( 2, npol_, nchan_ ), sumw_p, TAKE_OVER ) ; |
---|
| 498 | delete sumw_p ; |
---|
[2356] | 499 | //cout << "sumWeight = " << sumWeight << endl ; |
---|
[2364] | 500 | // os << "gdataArr = " << gdataArr << LogIO::POST ; |
---|
| 501 | // os << "gwgtArr = " << gwgtArr << LogIO::POST ; |
---|
| 502 | // os << "data_ " << data_ << LogIO::POST ; |
---|
[2356] | 503 | } |
---|
| 504 | |
---|
[2378] | 505 | void STGrid::setData( Array<Complex> &gdata, |
---|
[2368] | 506 | Array<Float> &gwgt ) |
---|
| 507 | { |
---|
[2378] | 508 | // 2011/12/20 TN |
---|
| 509 | // gwgt and data_ share storage |
---|
[2368] | 510 | LogIO os( LogOrigin("STGrid","setData",WHERE) ) ; |
---|
| 511 | double t0, t1 ; |
---|
| 512 | t0 = mathutil::gettimeofday_sec() ; |
---|
[2378] | 513 | uInt len = data_.nelements() ; |
---|
[2374] | 514 | const Complex *w1_p ; |
---|
[2378] | 515 | Float *w2_p ; |
---|
[2379] | 516 | Bool b1, b2 ; |
---|
[2374] | 517 | const Complex *gdata_p = gdata.getStorage( b1 ) ; |
---|
[2378] | 518 | Float *gwgt_p = data_.getStorage( b2 ) ; |
---|
[2368] | 519 | w1_p = gdata_p ; |
---|
| 520 | w2_p = gwgt_p ; |
---|
| 521 | for ( uInt i = 0 ; i < len ; i++ ) { |
---|
[2378] | 522 | if ( *w2_p > 0.0 ) *w2_p = (*w1_p).real() / *w2_p ; |
---|
[2368] | 523 | w1_p++ ; |
---|
| 524 | w2_p++ ; |
---|
| 525 | } |
---|
| 526 | gdata.freeStorage( gdata_p, b1 ) ; |
---|
[2378] | 527 | data_.putStorage( gwgt_p, b2 ) ; |
---|
[2368] | 528 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 529 | os << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
| 530 | } |
---|
| 531 | |
---|
[2356] | 532 | void STGrid::setupGrid( Int &nx, |
---|
| 533 | Int &ny, |
---|
| 534 | String &cellx, |
---|
| 535 | String &celly, |
---|
| 536 | Double &xmin, |
---|
| 537 | Double &xmax, |
---|
| 538 | Double &ymin, |
---|
| 539 | Double &ymax, |
---|
| 540 | String ¢er ) |
---|
| 541 | { |
---|
[2375] | 542 | LogIO os( LogOrigin("STGrid","setupGrid",WHERE) ) ; |
---|
[2356] | 543 | //cout << "nx=" << nx << ", ny=" << ny << endl ; |
---|
[2359] | 544 | |
---|
| 545 | // center position |
---|
| 546 | if ( center.size() == 0 ) { |
---|
| 547 | center_(0) = 0.5 * ( xmin + xmax ) ; |
---|
| 548 | center_(1) = 0.5 * ( ymin + ymax ) ; |
---|
| 549 | } |
---|
| 550 | else { |
---|
| 551 | String::size_type pos0 = center.find( " " ) ; |
---|
| 552 | if ( pos0 == String::npos ) { |
---|
| 553 | throw AipsError( "bad string format in parameter center" ) ; |
---|
| 554 | } |
---|
| 555 | String::size_type pos1 = center.find( " ", pos0+1 ) ; |
---|
| 556 | String typestr, xstr, ystr ; |
---|
| 557 | if ( pos1 != String::npos ) { |
---|
| 558 | typestr = center.substr( 0, pos0 ) ; |
---|
| 559 | xstr = center.substr( pos0+1, pos1-pos0 ) ; |
---|
| 560 | ystr = center.substr( pos1+1 ) ; |
---|
| 561 | // todo: convert to J2000 (or direction ref for DIRECTION column) |
---|
| 562 | } |
---|
| 563 | else { |
---|
| 564 | typestr = "J2000" ; |
---|
| 565 | xstr = center.substr( 0, pos0 ) ; |
---|
| 566 | ystr = center.substr( pos0+1 ) ; |
---|
| 567 | } |
---|
| 568 | QuantumHolder qh ; |
---|
| 569 | String err ; |
---|
| 570 | qh.fromString( err, xstr ) ; |
---|
| 571 | Quantum<Double> xcen = qh.asQuantumDouble() ; |
---|
| 572 | qh.fromString( err, ystr ) ; |
---|
| 573 | Quantum<Double> ycen = qh.asQuantumDouble() ; |
---|
| 574 | center_(0) = xcen.getValue( "rad" ) ; |
---|
| 575 | center_(1) = ycen.getValue( "rad" ) ; |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | |
---|
[2356] | 579 | nx_ = nx ; |
---|
| 580 | ny_ = ny ; |
---|
| 581 | if ( nx < 0 && ny > 0 ) { |
---|
| 582 | nx_ = ny ; |
---|
| 583 | ny_ = ny ; |
---|
| 584 | } |
---|
| 585 | if ( ny < 0 && nx > 0 ) { |
---|
| 586 | nx_ = nx ; |
---|
| 587 | ny_ = nx ; |
---|
| 588 | } |
---|
[2375] | 589 | |
---|
| 590 | //Double wx = xmax - xmin ; |
---|
| 591 | //Double wy = ymax - ymin ; |
---|
| 592 | Double wx = max( abs(xmax-center_(0)), abs(xmin-center_(0)) ) * 2 ; |
---|
| 593 | Double wy = max( abs(ymax-center_(1)), abs(ymin-center_(1)) ) * 2 ; |
---|
| 594 | // take 10% margin |
---|
| 595 | wx *= 1.10 ; |
---|
| 596 | wy *= 1.10 ; |
---|
| 597 | |
---|
| 598 | Quantum<Double> qcellx ; |
---|
| 599 | Quantum<Double> qcelly ; |
---|
[2356] | 600 | //cout << "nx_ = " << nx_ << ", ny_ = " << ny_ << endl ; |
---|
| 601 | if ( cellx.size() != 0 && celly.size() != 0 ) { |
---|
| 602 | readQuantity( qcellx, cellx ) ; |
---|
| 603 | readQuantity( qcelly, celly ) ; |
---|
| 604 | } |
---|
| 605 | else if ( celly.size() != 0 ) { |
---|
[2375] | 606 | os << "Using celly to x-axis..." << LogIO::POST ; |
---|
[2356] | 607 | readQuantity( qcelly, celly ) ; |
---|
| 608 | qcellx = qcelly ; |
---|
| 609 | } |
---|
| 610 | else if ( cellx.size() != 0 ) { |
---|
[2375] | 611 | os << "Using cellx to y-axis..." << LogIO::POST ; |
---|
[2356] | 612 | readQuantity( qcellx, cellx ) ; |
---|
| 613 | qcelly = qcellx ; |
---|
| 614 | } |
---|
| 615 | else { |
---|
| 616 | if ( nx_ < 0 ) { |
---|
[2375] | 617 | os << "No user preference in grid setting. Using default..." << LogIO::POST ; |
---|
[2356] | 618 | readQuantity( qcellx, "1.0arcmin" ) ; |
---|
| 619 | qcelly = qcellx ; |
---|
| 620 | } |
---|
| 621 | else { |
---|
[2375] | 622 | if ( wx == 0.0 ) { |
---|
| 623 | os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ; |
---|
| 624 | wx = 0.00290888 ; |
---|
| 625 | } |
---|
| 626 | if ( wy == 0.0 ) { |
---|
| 627 | os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ; |
---|
| 628 | wy = 0.00290888 ; |
---|
| 629 | } |
---|
[2356] | 630 | qcellx = Quantum<Double>( wx/nx_, "rad" ) ; |
---|
| 631 | qcelly = Quantum<Double>( wy/ny_, "rad" ) ; |
---|
| 632 | } |
---|
| 633 | } |
---|
| 634 | cellx_ = qcellx.getValue( "rad" ) ; |
---|
| 635 | celly_ = qcelly.getValue( "rad" ) ; |
---|
| 636 | if ( nx_ < 0 ) { |
---|
[2375] | 637 | if ( wx == 0.0 ) { |
---|
| 638 | os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ; |
---|
| 639 | wx = 0.00290888 ; |
---|
| 640 | } |
---|
| 641 | if ( wy == 0.0 ) { |
---|
| 642 | os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ; |
---|
| 643 | wy = 0.00290888 ; |
---|
| 644 | } |
---|
[2356] | 645 | nx_ = Int( ceil( wx/cellx_ ) ) ; |
---|
| 646 | ny_ = Int( ceil( wy/celly_ ) ) ; |
---|
| 647 | } |
---|
| 648 | } |
---|
| 649 | |
---|
[2379] | 650 | void STGrid::selectData() |
---|
[2362] | 651 | { |
---|
| 652 | Int ifno = ifno_ ; |
---|
| 653 | Table taborg( infile_ ) ; |
---|
| 654 | if ( ifno == -1 ) { |
---|
[2368] | 655 | LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ; |
---|
[2362] | 656 | // os << LogIO::SEVERE |
---|
| 657 | // << "Please set IFNO before actual gridding" |
---|
| 658 | // << LogIO::EXCEPTION ; |
---|
| 659 | ROScalarColumn<uInt> ifnoCol( taborg, "IFNO" ) ; |
---|
| 660 | ifno = ifnoCol( 0 ) ; |
---|
| 661 | os << LogIO::WARN |
---|
| 662 | << "IFNO is not given. Using default IFNO: " << ifno << LogIO::POST ; |
---|
| 663 | } |
---|
[2364] | 664 | // tab = taborg( taborg.col("IFNO") == ifno ) ; |
---|
| 665 | TableExprNode node ; |
---|
| 666 | node = taborg.col("IFNO") == ifno ; |
---|
| 667 | if ( scanlist_.size() > 0 ) { |
---|
| 668 | node = node && taborg.col("SCANNO").in( scanlist_ ) ; |
---|
| 669 | } |
---|
[2379] | 670 | tab_ = taborg( node ) ; |
---|
| 671 | if ( tab_.nrow() == 0 ) { |
---|
[2368] | 672 | LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ; |
---|
[2362] | 673 | os << LogIO::SEVERE |
---|
[2376] | 674 | << "No corresponding rows for given selection: IFNO " << ifno ; |
---|
| 675 | if ( scanlist_.size() > 0 ) |
---|
| 676 | os << " SCANNO " << scanlist_ ; |
---|
| 677 | os << LogIO::EXCEPTION ; |
---|
[2362] | 678 | } |
---|
[2379] | 679 | attach() ; |
---|
[2362] | 680 | } |
---|
| 681 | |
---|
[2379] | 682 | void STGrid::attach() |
---|
| 683 | { |
---|
| 684 | // attach to table |
---|
| 685 | spectraCol_.attach( tab_, "SPECTRA" ) ; |
---|
| 686 | flagtraCol_.attach( tab_, "FLAGTRA" ) ; |
---|
| 687 | directionCol_.attach( tab_, "DIRECTION" ) ; |
---|
| 688 | flagRowCol_.attach( tab_, "FLAGROW" ) ; |
---|
| 689 | tsysCol_.attach( tab_, "TSYS" ) ; |
---|
| 690 | intervalCol_.attach( tab_, "INTERVAL" ) ; |
---|
| 691 | } |
---|
| 692 | |
---|
[2375] | 693 | void STGrid::getData( Array<Complex> &spectra, |
---|
| 694 | Array<Double> &direction, |
---|
| 695 | Array<uChar> &flagtra, |
---|
| 696 | Array<uInt> &rflag, |
---|
| 697 | Array<Float> &weight ) |
---|
[2356] | 698 | { |
---|
[2375] | 699 | LogIO os( LogOrigin("STGrid","getData",WHERE) ) ; |
---|
[2374] | 700 | // os << "start" << LogIO::POST ; |
---|
| 701 | // os << "npol_ = " << npol_ << LogIO::POST ; |
---|
| 702 | // os << "nchan_ = " << nchan_ << LogIO::POST ; |
---|
| 703 | // os << "nrow_ = " << nrow_ << LogIO::POST ; |
---|
[2375] | 704 | IPosition cshape( 3, npol_, nchan_, nrow_ ) ; |
---|
| 705 | IPosition mshape( 2, npol_, nrow_ ) ; |
---|
[2380] | 706 | IPosition vshape( 1, nrow_ ) ; |
---|
[2375] | 707 | spectra.resize( cshape ) ; |
---|
| 708 | flagtra.resize( cshape ) ; |
---|
[2380] | 709 | rflag.resize( vshape ) ; |
---|
| 710 | Vector<uInt> rflagPerPol( rflag ) ; |
---|
[2375] | 711 | direction.resize( IPosition(2,2,nrow_) ) ; |
---|
| 712 | Array<Float> tsys( cshape ) ; |
---|
| 713 | Array<Double> tint( mshape ) ; |
---|
| 714 | |
---|
| 715 | ArrayIterator<uChar> fli( flagtra, IPosition(2,1,2) ) ; |
---|
| 716 | ArrayIterator<Float> tsi( tsys, IPosition(2,1,2) ) ; |
---|
| 717 | ArrayIterator<Double> tii( tint, IPosition(1,1) ) ; |
---|
| 718 | |
---|
[2371] | 719 | // boolean for pointer access |
---|
[2375] | 720 | Bool bsp, bsps ; |
---|
[2371] | 721 | // pointer to the data |
---|
[2374] | 722 | Complex *sp_p = spectra.getStorage( bsp ) ; |
---|
[2371] | 723 | // working pointer |
---|
[2374] | 724 | Complex *wsp_p = sp_p ; |
---|
[2371] | 725 | uInt len = nchan_ * nrow_ ; |
---|
[2375] | 726 | IPosition mshape2( 2, nchan_, nrow_ ) ; |
---|
[2374] | 727 | Vector<Float> spSlice( nchan_ ) ; |
---|
| 728 | const Float *sps_p = spSlice.getStorage( bsps ) ; |
---|
| 729 | long cincr = npol_ ; |
---|
| 730 | long rincr = npol_ * nchan_ ; |
---|
[2361] | 731 | for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) { |
---|
[2379] | 732 | Table subt = tab_( tab_.col("POLNO") == pollist_[ipol] ) ; |
---|
[2360] | 733 | ROArrayColumn<Float> spectraCol( subt, "SPECTRA" ) ; |
---|
| 734 | ROArrayColumn<Double> directionCol( subt, "DIRECTION" ) ; |
---|
| 735 | ROArrayColumn<uChar> flagtraCol( subt, "FLAGTRA" ) ; |
---|
| 736 | ROScalarColumn<uInt> rflagCol( subt, "FLAGROW" ) ; |
---|
[2361] | 737 | ROArrayColumn<Float> tsysCol( subt, "TSYS" ) ; |
---|
| 738 | ROScalarColumn<Double> tintCol( subt, "INTERVAL" ) ; |
---|
[2374] | 739 | for ( Int irow = 0 ; irow < nrow_ ; irow++ ) { |
---|
| 740 | spectraCol.get( irow, spSlice ) ; |
---|
| 741 | const Float *wsps_p = sps_p ; |
---|
| 742 | wsp_p = sp_p + (long)ipol + rincr * (long)irow ; |
---|
| 743 | for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) { |
---|
| 744 | *wsp_p = *wsps_p ; |
---|
| 745 | wsps_p++ ; |
---|
| 746 | wsp_p += cincr ; |
---|
| 747 | } |
---|
| 748 | } |
---|
[2375] | 749 | Array<uChar> flSlice = fli.array() ; |
---|
[2371] | 750 | flagtraCol.getColumn( flSlice ) ; |
---|
[2380] | 751 | if ( ipol == 0 ) { |
---|
[2360] | 752 | directionCol.getColumn( direction ) ; |
---|
[2380] | 753 | rflagCol.getColumn( rflagPerPol ) ; |
---|
| 754 | } |
---|
| 755 | else { |
---|
| 756 | rflagPerPol += rflagCol.getColumn() ; |
---|
| 757 | } |
---|
[2371] | 758 | Vector<Float> tmpF = tsysCol( 0 ) ; |
---|
[2375] | 759 | Array<Float> tsSlice = tsi.array() ; |
---|
[2371] | 760 | if ( tmpF.nelements() == (uInt)nchan_ ) { |
---|
| 761 | tsysCol.getColumn( tsSlice ) ; |
---|
[2361] | 762 | } |
---|
| 763 | else { |
---|
[2371] | 764 | tsSlice = tmpF( 0 ) ; |
---|
[2361] | 765 | } |
---|
[2375] | 766 | Vector<Double> tmpD = tii.array() ; |
---|
[2361] | 767 | tintCol.getColumn( tmpD ) ; |
---|
[2371] | 768 | |
---|
| 769 | wsp_p += len ; |
---|
[2375] | 770 | |
---|
| 771 | fli.next() ; |
---|
| 772 | tsi.next() ; |
---|
| 773 | tii.next() ; |
---|
[2360] | 774 | } |
---|
[2374] | 775 | spSlice.freeStorage( sps_p, bsps ) ; |
---|
[2371] | 776 | spectra.putStorage( sp_p, bsp ) ; |
---|
[2361] | 777 | |
---|
[2375] | 778 | // os << "spectra=" << spectra << LogIO::POST ; |
---|
| 779 | // os << "flagtra=" << flagtra << LogIO::POST ; |
---|
| 780 | // os << "rflag=" << rflag << LogIO::POST ; |
---|
| 781 | // os << "direction=" << direction << LogIO::POST ; |
---|
| 782 | |
---|
[2380] | 783 | weight.resize( IPosition(2,nchan_,nrow_) ) ; |
---|
[2361] | 784 | getWeight( weight, tsys, tint ) ; |
---|
[2356] | 785 | } |
---|
| 786 | |
---|
[2375] | 787 | void STGrid::getData( Array<Complex> &spectra, |
---|
| 788 | Array<Double> &direction, |
---|
| 789 | Array<Int> &flagtra, |
---|
| 790 | Array<Int> &rflag, |
---|
| 791 | Array<Float> &weight ) |
---|
[2371] | 792 | { |
---|
[2375] | 793 | LogIO os( LogOrigin("STGrid","getData",WHERE) ) ; |
---|
| 794 | double t0, t1 ; |
---|
| 795 | |
---|
| 796 | Array<uChar> flagUC ; |
---|
| 797 | Array<uInt> rflagUI ; |
---|
| 798 | getData( spectra, direction, flagUC, rflagUI, weight ) ; |
---|
| 799 | |
---|
| 800 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 801 | toInt( flagUC, flagtra ) ; |
---|
| 802 | toInt( rflagUI, rflag ) ; |
---|
| 803 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 804 | os << "toInt: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
| 805 | } |
---|
| 806 | |
---|
[2379] | 807 | Int STGrid::getDataChunk( Array<Complex> &spectra, |
---|
| 808 | Array<Double> &direction, |
---|
| 809 | Array<Int> &flagtra, |
---|
| 810 | Array<Int> &rflag, |
---|
| 811 | Array<Float> &weight ) |
---|
[2378] | 812 | { |
---|
[2379] | 813 | Array<Float> spFloat( spectra.shape() ) ; |
---|
| 814 | Array<uChar> fluChar( flagtra.shape() ) ; |
---|
| 815 | Array<uInt> fruInt( rflag.shape() ) ; |
---|
| 816 | Int nrow = getDataChunk( spFloat, direction, fluChar, fruInt, weight ) ; |
---|
| 817 | convertArray( spectra, spFloat ) ; |
---|
| 818 | convertArray( flagtra, fluChar ) ; |
---|
| 819 | convertArray( rflag, fruInt ) ; |
---|
| 820 | |
---|
| 821 | return nrow ; |
---|
[2378] | 822 | } |
---|
| 823 | |
---|
[2379] | 824 | Int STGrid::getDataChunk( Array<Float> &spectra, |
---|
| 825 | Array<Double> &direction, |
---|
| 826 | Array<uChar> &flagtra, |
---|
| 827 | Array<uInt> &rflag, |
---|
| 828 | Array<Float> &weight ) |
---|
[2375] | 829 | { |
---|
[2379] | 830 | LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ; |
---|
| 831 | Int nrow = min( spectra.shape()[2], nrow_-nprocessed_ ) ; |
---|
| 832 | Array<Float> tsys( spectra.shape() ) ; |
---|
[2380] | 833 | //Array<Double> tint( rflag.shape() ) ; |
---|
| 834 | Array<Double> tint( IPosition(2,spectra.shape()[0],spectra.shape()[2]) ) ; |
---|
[2379] | 835 | IPosition m( 2, 0, 2 ) ; |
---|
| 836 | IPosition v( 1, 0 ) ; |
---|
| 837 | ArrayIterator<Float> spi( spectra, m, False ) ; |
---|
| 838 | ArrayIterator<uChar> fli( flagtra, m, False ) ; |
---|
| 839 | ArrayIterator<Float> tsi( tsys, m, False ) ; |
---|
[2380] | 840 | ArrayIterator<Double> di( direction, v ) ; |
---|
[2379] | 841 | Bool bfr, bti ; |
---|
| 842 | uInt *fr_p = rflag.getStorage( bfr ) ; |
---|
| 843 | Double *ti_p = tint.getStorage( bti ) ; |
---|
| 844 | uInt *wfr_p = fr_p ; |
---|
| 845 | Double *wti_p = ti_p ; |
---|
| 846 | Int offset = nprocessed_ * npol_ ; |
---|
| 847 | for ( Int irow = 0 ; irow < npol_ * nrow ; irow++ ) { |
---|
| 848 | Array<Float> spSlice = spi.array() ; |
---|
| 849 | Array<uChar> flSlice = fli.array() ; |
---|
| 850 | Array<Float> tsSlice = tsi.array() ; |
---|
| 851 | |
---|
| 852 | uInt idx = rows_[offset+irow] ; |
---|
| 853 | spectraCol_.get( idx, spSlice ) ; |
---|
| 854 | |
---|
| 855 | flagtraCol_.get( idx, flSlice ) ; |
---|
| 856 | Vector<Float> tmpF = tsysCol_( idx ) ; |
---|
| 857 | if ( tmpF.nelements() == (uInt)nchan_ ) { |
---|
| 858 | tsSlice = tmpF ; |
---|
| 859 | } |
---|
| 860 | else { |
---|
| 861 | tsSlice = tmpF[0] ; |
---|
| 862 | } |
---|
| 863 | *wti_p = intervalCol_( idx ) ; |
---|
| 864 | |
---|
| 865 | spi.next() ; |
---|
| 866 | fli.next() ; |
---|
| 867 | tsi.next() ; |
---|
| 868 | wti_p++ ; |
---|
| 869 | } |
---|
| 870 | tint.putStorage( ti_p, bti ) ; |
---|
| 871 | |
---|
| 872 | for ( Int irow = 0 ; irow < nrow ; irow += npol_ ) { |
---|
| 873 | uInt idx = rows_[offset+irow] ; |
---|
| 874 | directionCol_.get( idx, di.array() ) ; |
---|
| 875 | di.next() ; |
---|
[2380] | 876 | |
---|
| 877 | *wfr_p = flagRowCol_( idx ) ; |
---|
| 878 | for ( Int ipol = 1 ; ipol < npol_ ; ipol++ ) { |
---|
| 879 | *wfr_p = max( *wfr_p, flagRowCol_( rows_[offset+irow+ipol] ) ) ; |
---|
| 880 | } |
---|
| 881 | wfr_p++ ; |
---|
[2379] | 882 | } |
---|
[2380] | 883 | rflag.putStorage( fr_p, bfr ) ; |
---|
[2379] | 884 | |
---|
| 885 | getWeight( weight, tsys, tint ) ; |
---|
| 886 | |
---|
| 887 | nprocessed_ += nrow ; |
---|
| 888 | |
---|
| 889 | return nrow ; |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | void STGrid::setupArray() |
---|
| 893 | { |
---|
[2376] | 894 | LogIO os( LogOrigin("STGrid","setupArray",WHERE) ) ; |
---|
[2379] | 895 | ROScalarColumn<uInt> polnoCol( tab_, "POLNO" ) ; |
---|
[2371] | 896 | Vector<uInt> pols = polnoCol.getColumn() ; |
---|
[2376] | 897 | //os << pols << LogIO::POST ; |
---|
[2371] | 898 | Vector<uInt> pollistOrg ; |
---|
| 899 | uInt npolOrg = 0 ; |
---|
| 900 | uInt polno ; |
---|
| 901 | for ( uInt i = 0 ; i < polnoCol.nrow() ; i++ ) { |
---|
| 902 | //polno = polnoCol( i ) ; |
---|
| 903 | polno = pols( i ) ; |
---|
| 904 | if ( allNE( pollistOrg, polno ) ) { |
---|
| 905 | pollistOrg.resize( npolOrg+1, True ) ; |
---|
| 906 | pollistOrg[npolOrg] = polno ; |
---|
| 907 | npolOrg++ ; |
---|
| 908 | } |
---|
| 909 | } |
---|
| 910 | if ( pollist_.size() == 0 ) |
---|
| 911 | pollist_ = pollistOrg ; |
---|
| 912 | else { |
---|
| 913 | Vector<uInt> newlist ; |
---|
| 914 | uInt newsize = 0 ; |
---|
| 915 | for ( uInt i = 0 ; i < pollist_.size() ; i++ ) { |
---|
| 916 | if ( anyEQ( pollistOrg, pollist_[i] ) ) { |
---|
| 917 | newlist.resize( newsize+1, True ) ; |
---|
| 918 | newlist[newsize] = pollist_[i] ; |
---|
| 919 | newsize++ ; |
---|
| 920 | } |
---|
| 921 | } |
---|
| 922 | pollist_.assign( newlist ) ; |
---|
| 923 | } |
---|
| 924 | npol_ = pollist_.size() ; |
---|
| 925 | if ( npol_ == 0 ) { |
---|
| 926 | os << LogIO::SEVERE << "Empty pollist" << LogIO::EXCEPTION ; |
---|
| 927 | } |
---|
[2379] | 928 | nrow_ = tab_.nrow() / npolOrg ; |
---|
| 929 | ROArrayColumn<uChar> tmpCol( tab_, "FLAGTRA" ) ; |
---|
[2371] | 930 | nchan_ = tmpCol( 0 ).nelements() ; |
---|
| 931 | // os << "npol_ = " << npol_ << "(" << pollist_ << ")" << endl |
---|
| 932 | // << "nchan_ = " << nchan_ << endl |
---|
| 933 | // << "nrow_ = " << nrow_ << LogIO::POST ; |
---|
| 934 | } |
---|
| 935 | |
---|
[2375] | 936 | void STGrid::getWeight( Array<Float> &w, |
---|
| 937 | Array<Float> &tsys, |
---|
| 938 | Array<Double> &tint ) |
---|
[2361] | 939 | { |
---|
[2368] | 940 | LogIO os( LogOrigin("STGrid","getWeight",WHERE) ) ; |
---|
[2379] | 941 | // double t0, t1 ; |
---|
| 942 | // t0 = mathutil::gettimeofday_sec() ; |
---|
[2361] | 943 | // resize |
---|
[2375] | 944 | IPosition refShape = tsys.shape() ; |
---|
| 945 | Int nchan = refShape[1] ; |
---|
| 946 | Int nrow = refShape[2] ; |
---|
[2361] | 947 | |
---|
| 948 | // set weight |
---|
| 949 | if ( wtype_.compare( "UNIFORM" ) == 0 ) { |
---|
[2368] | 950 | w = 1.0 ; |
---|
[2361] | 951 | } |
---|
| 952 | else if ( wtype_.compare( "TINT" ) == 0 ) { |
---|
[2369] | 953 | Bool b0, b1 ; |
---|
| 954 | Float *w_p = w.getStorage( b0 ) ; |
---|
| 955 | Float *w0_p = w_p ; |
---|
| 956 | const Double *ti_p = tint.getStorage( b1 ) ; |
---|
| 957 | const Double *w1_p = ti_p ; |
---|
[2375] | 958 | for ( Int irow = 0 ; irow < nrow ; irow++ ) { |
---|
[2369] | 959 | Float val = (Float)(polMean( w1_p )) ; |
---|
[2375] | 960 | for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) { |
---|
[2369] | 961 | *w0_p = val ; |
---|
| 962 | w0_p++ ; |
---|
| 963 | } |
---|
[2361] | 964 | } |
---|
[2369] | 965 | w.putStorage( w_p, b0 ) ; |
---|
| 966 | tint.freeStorage( ti_p, b1 ) ; |
---|
[2361] | 967 | } |
---|
| 968 | else if ( wtype_.compare( "TSYS" ) == 0 ) { |
---|
[2369] | 969 | Bool b0, b1 ; |
---|
| 970 | Float *w_p = w.getStorage( b0 ) ; |
---|
| 971 | Float *w0_p = w_p ; |
---|
| 972 | const Float *ts_p = tsys.getStorage( b1 ) ; |
---|
| 973 | const Float *w1_p = ts_p ; |
---|
[2375] | 974 | for ( Int irow = 0 ; irow < nrow ; irow++ ) { |
---|
| 975 | for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) { |
---|
[2369] | 976 | Float val = polMean( w1_p ) ; |
---|
| 977 | *w0_p = 1.0 / ( val * val ) ; |
---|
| 978 | w0_p++ ; |
---|
[2361] | 979 | } |
---|
| 980 | } |
---|
[2369] | 981 | w.putStorage( w_p, b0 ) ; |
---|
| 982 | tsys.freeStorage( ts_p, b1 ) ; |
---|
[2361] | 983 | } |
---|
| 984 | else if ( wtype_.compare( "TINTSYS" ) == 0 ) { |
---|
[2369] | 985 | Bool b0, b1, b2 ; |
---|
| 986 | Float *w_p = w.getStorage( b0 ) ; |
---|
| 987 | Float *w0_p = w_p ; |
---|
| 988 | const Double *ti_p = tint.getStorage( b1 ) ; |
---|
| 989 | const Double *w1_p = ti_p ; |
---|
| 990 | const Float *ts_p = tsys.getStorage( b2 ) ; |
---|
| 991 | const Float *w2_p = ts_p ; |
---|
[2375] | 992 | for ( Int irow = 0 ; irow < nrow ; irow++ ) { |
---|
[2369] | 993 | Float interval = (Float)(polMean( w1_p )) ; |
---|
[2375] | 994 | for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) { |
---|
[2369] | 995 | Float temp = polMean( w2_p ) ; |
---|
| 996 | *w0_p = interval / ( temp * temp ) ; |
---|
| 997 | w0_p++ ; |
---|
[2361] | 998 | } |
---|
| 999 | } |
---|
[2369] | 1000 | w.putStorage( w_p, b0 ) ; |
---|
| 1001 | tint.freeStorage( ti_p, b1 ) ; |
---|
| 1002 | tsys.freeStorage( ts_p, b2 ) ; |
---|
[2361] | 1003 | } |
---|
| 1004 | else { |
---|
[2368] | 1005 | //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ; |
---|
[2379] | 1006 | //os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ; |
---|
[2368] | 1007 | w = 1.0 ; |
---|
[2361] | 1008 | } |
---|
| 1009 | |
---|
[2379] | 1010 | // t1 = mathutil::gettimeofday_sec() ; |
---|
| 1011 | // os << "getWeight: elapsed time is " << t1-t0 << " sec" << LogIO::POST ; |
---|
[2361] | 1012 | } |
---|
| 1013 | |
---|
[2369] | 1014 | Float STGrid::polMean( const Float *p ) |
---|
| 1015 | { |
---|
| 1016 | Float v = 0.0 ; |
---|
| 1017 | for ( Int i = 0 ; i < npol_ ; i++ ) { |
---|
| 1018 | v += *p ; |
---|
| 1019 | p++ ; |
---|
| 1020 | } |
---|
| 1021 | v /= npol_ ; |
---|
| 1022 | return v ; |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | Double STGrid::polMean( const Double *p ) |
---|
| 1026 | { |
---|
| 1027 | Double v = 0.0 ; |
---|
| 1028 | for ( Int i = 0 ; i < npol_ ; i++ ) { |
---|
| 1029 | v += *p ; |
---|
| 1030 | p++ ; |
---|
| 1031 | } |
---|
| 1032 | v /= npol_ ; |
---|
| 1033 | return v ; |
---|
| 1034 | } |
---|
| 1035 | |
---|
[2375] | 1036 | void STGrid::toInt( Array<uChar> &u, Array<Int> &v ) |
---|
[2356] | 1037 | { |
---|
[2375] | 1038 | uInt len = u.nelements() ; |
---|
[2356] | 1039 | Int *int_p = new Int[len] ; |
---|
| 1040 | Bool deleteIt ; |
---|
[2375] | 1041 | const uChar *data_p = u.getStorage( deleteIt ) ; |
---|
[2356] | 1042 | Int *i_p = int_p ; |
---|
| 1043 | const uChar *u_p = data_p ; |
---|
| 1044 | for ( uInt i = 0 ; i < len ; i++ ) { |
---|
| 1045 | *i_p = ( *u_p == 0 ) ? 0 : 1 ; |
---|
| 1046 | i_p++ ; |
---|
| 1047 | u_p++ ; |
---|
| 1048 | } |
---|
[2375] | 1049 | u.freeStorage( data_p, deleteIt ) ; |
---|
| 1050 | v.takeStorage( u.shape(), int_p, TAKE_OVER ) ; |
---|
[2356] | 1051 | } |
---|
| 1052 | |
---|
[2375] | 1053 | void STGrid::toInt( Array<uInt> &u, Array<Int> &v ) |
---|
[2356] | 1054 | { |
---|
[2375] | 1055 | uInt len = u.nelements() ; |
---|
[2356] | 1056 | Int *int_p = new Int[len] ; |
---|
| 1057 | Bool deleteIt ; |
---|
[2375] | 1058 | const uInt *data_p = u.getStorage( deleteIt ) ; |
---|
[2356] | 1059 | Int *i_p = int_p ; |
---|
| 1060 | const uInt *u_p = data_p ; |
---|
| 1061 | for ( uInt i = 0 ; i < len ; i++ ) { |
---|
| 1062 | *i_p = ( *u_p == 0 ) ? 0 : 1 ; |
---|
| 1063 | i_p++ ; |
---|
| 1064 | u_p++ ; |
---|
| 1065 | } |
---|
[2375] | 1066 | u.freeStorage( data_p, deleteIt ) ; |
---|
| 1067 | v.takeStorage( u.shape(), int_p, TAKE_OVER ) ; |
---|
[2356] | 1068 | } |
---|
| 1069 | |
---|
[2375] | 1070 | void STGrid::toPixel( Array<Double> &world, Array<Double> &pixel ) |
---|
[2356] | 1071 | { |
---|
[2359] | 1072 | // gridding will be done on (nx_+2*convSupport_) x (ny_+2*convSupport_) |
---|
| 1073 | // grid plane to avoid unexpected behavior on grid edge |
---|
[2375] | 1074 | Block<Double> pixc( 2 ) ; |
---|
| 1075 | pixc[0] = Double( nx_-1 ) * 0.5 ; |
---|
| 1076 | pixc[1] = Double( ny_-1 ) * 0.5 ; |
---|
| 1077 | // pixc[0] = Double( nx_+2*convSupport_-1 ) * 0.5 ; |
---|
| 1078 | // pixc[1] = Double( ny_+2*convSupport_-1 ) * 0.5 ; |
---|
[2356] | 1079 | uInt nrow = world.shape()[1] ; |
---|
[2375] | 1080 | Bool bw, bp ; |
---|
| 1081 | const Double *w_p = world.getStorage( bw ) ; |
---|
| 1082 | Double *p_p = pixel.getStorage( bp ) ; |
---|
| 1083 | const Double *ww_p = w_p ; |
---|
| 1084 | Double *wp_p = p_p ; |
---|
| 1085 | for ( uInt i = 0 ; i < nrow ; i++ ) { |
---|
| 1086 | *wp_p = pixc[0] + ( *ww_p - center_[0] ) / cellx_ ; |
---|
| 1087 | wp_p++ ; |
---|
| 1088 | ww_p++ ; |
---|
| 1089 | *wp_p = pixc[1] + ( *ww_p - center_[1] ) / celly_ ; |
---|
| 1090 | wp_p++ ; |
---|
| 1091 | ww_p++ ; |
---|
[2356] | 1092 | } |
---|
[2375] | 1093 | world.freeStorage( w_p, bw ) ; |
---|
| 1094 | pixel.putStorage( p_p, bp ) ; |
---|
[2364] | 1095 | // String gridfile = "grid."+convType_+"."+String::toString(convSupport_)+".dat" ; |
---|
| 1096 | // ofstream ofs( gridfile.c_str(), ios::out ) ; |
---|
| 1097 | // ofs << "center " << center_(0) << " " << pixc(0) |
---|
| 1098 | // << " " << center_(1) << " " << pixc(1) << endl ; |
---|
| 1099 | // for ( uInt irow = 0 ; irow < nrow ; irow++ ) { |
---|
| 1100 | // ofs << irow ; |
---|
| 1101 | // for ( uInt i = 0 ; i < 2 ; i++ ) { |
---|
| 1102 | // ofs << " " << world(i, irow) << " " << pixel(i, irow) ; |
---|
| 1103 | // } |
---|
| 1104 | // ofs << endl ; |
---|
| 1105 | // } |
---|
| 1106 | // ofs.close() ; |
---|
[2356] | 1107 | } |
---|
| 1108 | |
---|
| 1109 | void STGrid::boxFunc( Vector<Float> &convFunc, Int &convSize ) |
---|
| 1110 | { |
---|
| 1111 | convFunc = 0.0 ; |
---|
| 1112 | for ( Int i = 0 ; i < convSize/2 ; i++ ) |
---|
| 1113 | convFunc(i) = 1.0 ; |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | #define NEED_UNDERSCORES |
---|
| 1117 | #if defined(NEED_UNDERSCORES) |
---|
| 1118 | #define grdsf grdsf_ |
---|
| 1119 | #endif |
---|
| 1120 | extern "C" { |
---|
| 1121 | void grdsf(Double*, Double*); |
---|
| 1122 | } |
---|
| 1123 | void STGrid::spheroidalFunc( Vector<Float> &convFunc ) |
---|
| 1124 | { |
---|
| 1125 | convFunc = 0.0 ; |
---|
| 1126 | for ( Int i = 0 ; i < convSampling_*convSupport_ ; i++ ) { |
---|
| 1127 | Double nu = Double(i) / Double(convSupport_*convSampling_) ; |
---|
| 1128 | Double val ; |
---|
| 1129 | grdsf( &nu, &val ) ; |
---|
| 1130 | convFunc(i) = ( 1.0 - nu * nu ) * val ; |
---|
| 1131 | } |
---|
| 1132 | } |
---|
| 1133 | |
---|
| 1134 | void STGrid::gaussFunc( Vector<Float> &convFunc ) |
---|
| 1135 | { |
---|
| 1136 | convFunc = 0.0 ; |
---|
[2363] | 1137 | // HWHM of the Gaussian is convSupport_ / 4 |
---|
| 1138 | // To take into account Gaussian tail, kernel cutoff is set to 4 * HWHM |
---|
| 1139 | Int len = convSampling_ * convSupport_ ; |
---|
| 1140 | Double hwhm = len * 0.25 ; |
---|
| 1141 | for ( Int i = 0 ; i < len ; i++ ) { |
---|
[2356] | 1142 | Double val = Double(i) / hwhm ; |
---|
| 1143 | convFunc(i) = exp( -log(2)*val*val ) ; |
---|
| 1144 | } |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | void STGrid::pbFunc( Vector<Float> &convFunc ) |
---|
| 1148 | { |
---|
| 1149 | convFunc = 0.0 ; |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | void STGrid::setConvFunc( Vector<Float> &convFunc ) |
---|
| 1153 | { |
---|
| 1154 | convSupport_ = userSupport_ ; |
---|
| 1155 | if ( convType_ == "BOX" ) { |
---|
| 1156 | if ( convSupport_ < 0 ) |
---|
| 1157 | convSupport_ = 0 ; |
---|
| 1158 | Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ; |
---|
| 1159 | convFunc.resize( convSize ) ; |
---|
| 1160 | boxFunc( convFunc, convSize ) ; |
---|
| 1161 | } |
---|
| 1162 | else if ( convType_ == "SF" ) { |
---|
| 1163 | if ( convSupport_ < 0 ) |
---|
| 1164 | convSupport_ = 3 ; |
---|
| 1165 | Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ; |
---|
| 1166 | convFunc.resize( convSize ) ; |
---|
| 1167 | spheroidalFunc( convFunc ) ; |
---|
| 1168 | } |
---|
| 1169 | else if ( convType_ == "GAUSS" ) { |
---|
[2363] | 1170 | // to take into account Gaussian tail |
---|
[2356] | 1171 | if ( convSupport_ < 0 ) |
---|
[2363] | 1172 | convSupport_ = 12 ; // 3 * 4 |
---|
| 1173 | else { |
---|
| 1174 | convSupport_ = userSupport_ * 4 ; |
---|
| 1175 | } |
---|
[2356] | 1176 | Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ; |
---|
| 1177 | convFunc.resize( convSize ) ; |
---|
| 1178 | gaussFunc( convFunc ) ; |
---|
| 1179 | } |
---|
[2359] | 1180 | else if ( convType_ == "PB" ) { |
---|
| 1181 | if ( convSupport_ < 0 ) |
---|
| 1182 | convSupport_ = 0 ; |
---|
[2356] | 1183 | pbFunc( convFunc ) ; |
---|
[2359] | 1184 | } |
---|
[2356] | 1185 | else { |
---|
| 1186 | throw AipsError( "Unsupported convolution function" ) ; |
---|
| 1187 | } |
---|
| 1188 | } |
---|
| 1189 | |
---|
| 1190 | string STGrid::saveData( string outfile ) |
---|
| 1191 | { |
---|
[2368] | 1192 | LogIO os( LogOrigin("STGrid", "saveData", WHERE) ) ; |
---|
| 1193 | double t0, t1 ; |
---|
| 1194 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 1195 | |
---|
[2360] | 1196 | //Int polno = 0 ; |
---|
[2371] | 1197 | String outfile_ ; |
---|
[2356] | 1198 | if ( outfile.size() == 0 ) { |
---|
| 1199 | if ( infile_.lastchar() == '/' ) { |
---|
| 1200 | outfile_ = infile_.substr( 0, infile_.size()-1 ) ; |
---|
| 1201 | } |
---|
| 1202 | else { |
---|
| 1203 | outfile_ = infile_ ; |
---|
| 1204 | } |
---|
| 1205 | outfile_ += ".grid" ; |
---|
| 1206 | } |
---|
| 1207 | else { |
---|
| 1208 | outfile_ = outfile ; |
---|
| 1209 | } |
---|
[2371] | 1210 | Table tab ; |
---|
| 1211 | prepareTable( tab, outfile_ ) ; |
---|
[2356] | 1212 | IPosition dshape = data_.shape() ; |
---|
[2361] | 1213 | Int nrow = nx_ * ny_ * npol_ ; |
---|
| 1214 | tab.rwKeywordSet().define( "nPol", npol_ ) ; |
---|
[2360] | 1215 | tab.addRow( nrow ) ; |
---|
[2356] | 1216 | Vector<Double> cpix( 2 ) ; |
---|
| 1217 | cpix(0) = Double( nx_ - 1 ) * 0.5 ; |
---|
| 1218 | cpix(1) = Double( ny_ - 1 ) * 0.5 ; |
---|
| 1219 | Vector<Double> dir( 2 ) ; |
---|
| 1220 | ArrayColumn<Double> directionCol( tab, "DIRECTION" ) ; |
---|
| 1221 | ArrayColumn<Float> spectraCol( tab, "SPECTRA" ) ; |
---|
| 1222 | ScalarColumn<uInt> polnoCol( tab, "POLNO" ) ; |
---|
| 1223 | Int irow = 0 ; |
---|
[2371] | 1224 | Vector<Float> sp( nchan_ ) ; |
---|
| 1225 | Bool bsp, bdata ; |
---|
| 1226 | const Float *data_p = data_.getStorage( bdata ) ; |
---|
| 1227 | Float *wsp_p, *sp_p ; |
---|
| 1228 | const Float *wdata_p = data_p ; |
---|
| 1229 | long step = nx_ * ny_ * npol_ ; |
---|
| 1230 | long offset ; |
---|
[2356] | 1231 | for ( Int iy = 0 ; iy < ny_ ; iy++ ) { |
---|
[2371] | 1232 | dir(1) = center_(1) - ( cpix(1) - (Double)iy ) * celly_ ; |
---|
[2356] | 1233 | for ( Int ix = 0 ; ix < nx_ ; ix++ ) { |
---|
[2371] | 1234 | dir(0) = center_(0) - ( cpix(0) - (Double)ix ) * cellx_ ; |
---|
[2361] | 1235 | for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) { |
---|
[2371] | 1236 | offset = ix + iy * nx_ + ipol * nx_ * ny_ ; |
---|
| 1237 | //os << "offset = " << offset << LogIO::POST ; |
---|
| 1238 | sp_p = sp.getStorage( bsp ) ; |
---|
| 1239 | wsp_p = sp_p ; |
---|
| 1240 | wdata_p = data_p + offset ; |
---|
| 1241 | for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) { |
---|
| 1242 | *wsp_p = *wdata_p ; |
---|
| 1243 | wsp_p++ ; |
---|
| 1244 | wdata_p += step ; |
---|
| 1245 | } |
---|
| 1246 | sp.putStorage( sp_p, bsp ) ; |
---|
[2356] | 1247 | spectraCol.put( irow, sp ) ; |
---|
| 1248 | directionCol.put( irow, dir ) ; |
---|
[2360] | 1249 | polnoCol.put( irow, pollist_[ipol] ) ; |
---|
[2356] | 1250 | irow++ ; |
---|
| 1251 | } |
---|
| 1252 | } |
---|
| 1253 | } |
---|
[2371] | 1254 | data_.freeStorage( data_p, bdata ) ; |
---|
[2368] | 1255 | |
---|
| 1256 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 1257 | os << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ; |
---|
[2374] | 1258 | |
---|
[2356] | 1259 | return outfile_ ; |
---|
| 1260 | } |
---|
| 1261 | |
---|
[2371] | 1262 | void STGrid::prepareTable( Table &tab, String &name ) |
---|
| 1263 | { |
---|
| 1264 | Table t( infile_, Table::Old ) ; |
---|
| 1265 | t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ; |
---|
| 1266 | tab = Table( name, Table::Update ) ; |
---|
[2356] | 1267 | } |
---|
[2379] | 1268 | |
---|
| 1269 | void STGrid::sortData() |
---|
| 1270 | { |
---|
| 1271 | LogIO os( LogOrigin("STGRid","sortData",WHERE) ) ; |
---|
| 1272 | double t0, t1 ; |
---|
| 1273 | t0 = mathutil::gettimeofday_sec() ; |
---|
| 1274 | rows_.resize( npol_*nrow_ ) ; |
---|
| 1275 | Table tab = tab_( tab_.col("POLNO").in(pollist_) ) ; |
---|
| 1276 | Block<String> cols( 2 ) ; |
---|
| 1277 | cols[0] = "TIME" ; |
---|
| 1278 | cols[1] = "BEAMNO" ; |
---|
| 1279 | TableIterator iter( tab, cols ) ; |
---|
| 1280 | uInt idx = 0 ; |
---|
| 1281 | while( !iter.pastEnd() ) { |
---|
| 1282 | Table t = iter.table().sort( "POLNO" ) ; |
---|
| 1283 | Vector<uInt> rows = t.rowNumbers() ; |
---|
| 1284 | //os << "rows=" << rows << LogIO::POST ; |
---|
| 1285 | for ( uInt i = 0 ; i < rows.nelements() ; i++ ) { |
---|
| 1286 | rows_[idx] = rows[i] ; |
---|
| 1287 | idx++ ; |
---|
| 1288 | } |
---|
| 1289 | iter.next() ; |
---|
| 1290 | } |
---|
| 1291 | t1 = mathutil::gettimeofday_sec() ; |
---|
| 1292 | os << "sortData: elapsed time is " << t1-t0 << " sec" << LogIO::POST ; |
---|
| 1293 | //os << "rows_ = " << rows_ << LogIO::POST ; |
---|
[2371] | 1294 | } |
---|
[2379] | 1295 | } |
---|