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