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