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