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