[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>
|
---|
| 20 |
|
---|
| 21 | #include <measures/Measures/MDirection.h>
|
---|
| 22 |
|
---|
[2364] | 23 | #include <MathUtils.h>
|
---|
| 24 |
|
---|
[2356] | 25 | #include "STGrid.h"
|
---|
| 26 |
|
---|
| 27 | using namespace std ;
|
---|
| 28 | using namespace casa ;
|
---|
| 29 | using namespace asap ;
|
---|
| 30 |
|
---|
| 31 | namespace asap {
|
---|
| 32 |
|
---|
| 33 | // constructor
|
---|
| 34 | STGrid::STGrid()
|
---|
| 35 | {
|
---|
| 36 | init() ;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | STGrid::STGrid( const string infile )
|
---|
| 40 | {
|
---|
| 41 | init() ;
|
---|
| 42 |
|
---|
| 43 | setFileIn( infile ) ;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | void STGrid::init()
|
---|
| 47 | {
|
---|
[2362] | 48 | ifno_ = -1 ;
|
---|
[2356] | 49 | nx_ = -1 ;
|
---|
| 50 | ny_ = -1 ;
|
---|
[2361] | 51 | npol_ = 0 ;
|
---|
| 52 | nchan_ = 0 ;
|
---|
| 53 | nrow_ = 0 ;
|
---|
[2356] | 54 | cellx_ = 0.0 ;
|
---|
| 55 | celly_ = 0.0 ;
|
---|
| 56 | center_ = Vector<Double> ( 2, 0.0 ) ;
|
---|
| 57 | convType_ = "BOX" ;
|
---|
[2361] | 58 | wtype_ = "UNIFORM" ;
|
---|
[2356] | 59 | convSupport_ = -1 ;
|
---|
| 60 | userSupport_ = -1 ;
|
---|
| 61 | convSampling_ = 100 ;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void STGrid::setFileIn( const string infile )
|
---|
| 65 | {
|
---|
| 66 | String name( infile ) ;
|
---|
| 67 | if ( infile_.compare( name ) != 0 ) {
|
---|
| 68 | infile_ = String( infile ) ;
|
---|
| 69 | tab_ = Table( infile_ ) ;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[2360] | 73 | void STGrid::setPolList( vector<unsigned int> pols )
|
---|
| 74 | {
|
---|
| 75 | pollist_.assign( Vector<uInt>( pols ) ) ;
|
---|
| 76 | cout << "pollist_ = " << pollist_ << endl ;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[2364] | 79 | void STGrid::setScanList( vector<unsigned int> scans )
|
---|
| 80 | {
|
---|
| 81 | scanlist_.assign( Vector<uInt>( scans ) ) ;
|
---|
| 82 | cout << "scanlist_ = " << scanlist_ << endl ;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[2361] | 85 | void STGrid::setWeight( const string wType )
|
---|
| 86 | {
|
---|
| 87 | wtype_ = String( wType ) ;
|
---|
| 88 | wtype_.upcase() ;
|
---|
| 89 | cout << "wtype_ = " << wtype_ << endl ;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[2356] | 92 | void STGrid::defineImage( int nx,
|
---|
| 93 | int ny,
|
---|
| 94 | string scellx,
|
---|
| 95 | string scelly,
|
---|
| 96 | string scenter )
|
---|
| 97 | {
|
---|
| 98 | ROArrayColumn<Double> dirCol( tab_, "DIRECTION" ) ;
|
---|
| 99 | Matrix<Double> direction = dirCol.getColumn() ;
|
---|
| 100 | Double rmax, rmin, dmax, dmin ;
|
---|
| 101 | minMax( rmin, rmax, direction.row( 0 ) ) ;
|
---|
| 102 | minMax( dmin, dmax, direction.row( 1 ) ) ;
|
---|
| 103 |
|
---|
| 104 | Int npx = (Int)nx ;
|
---|
| 105 | Int npy = (Int)ny ;
|
---|
| 106 | String cellx( scellx ) ;
|
---|
| 107 | String celly( scelly ) ;
|
---|
| 108 | String center( scenter ) ;
|
---|
| 109 | setupGrid( npx, npy,
|
---|
| 110 | cellx, celly,
|
---|
| 111 | rmin, rmax,
|
---|
| 112 | dmin, dmax,
|
---|
| 113 | center ) ;
|
---|
| 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 | }
|
---|
| 152 | void STGrid::grid()
|
---|
| 153 | {
|
---|
[2361] | 154 | LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ;
|
---|
[2356] | 155 |
|
---|
| 156 | // retrieve data
|
---|
[2375] | 157 | Array<Complex> spectra ;
|
---|
| 158 | Array<Double> direction ;
|
---|
| 159 | Array<Int> flagtra ;
|
---|
| 160 | Array<Int> rflag ;
|
---|
| 161 | Array<Float> weight ;
|
---|
[2364] | 162 | double t0, t1 ;
|
---|
| 163 | t0 = mathutil::gettimeofday_sec() ;
|
---|
[2362] | 164 | getData( spectra, direction, flagtra, rflag, weight ) ;
|
---|
[2364] | 165 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 166 | os << "getData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
[2356] | 167 | IPosition sshape = spectra.shape() ;
|
---|
[2361] | 168 | //os << "spectra.shape()=" << spectra.shape() << LogIO::POST ;
|
---|
| 169 | //os << "max(spectra) = " << max(spectra) << LogIO::POST ;
|
---|
| 170 | //os << "weight = " << weight << LogIO::POST ;
|
---|
[2356] | 171 |
|
---|
| 172 | // grid parameter
|
---|
[2362] | 173 | os << LogIO::DEBUGGING ;
|
---|
| 174 | os << "----------" << endl ;
|
---|
| 175 | os << "Grid parameter summary" << endl ;
|
---|
| 176 | os << " (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ;
|
---|
| 177 | os << " (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ;
|
---|
| 178 | os << " center = " << center_ << endl ;
|
---|
| 179 | os << "----------" << LogIO::POST ;
|
---|
| 180 | os << LogIO::NORMAL ;
|
---|
[2356] | 181 |
|
---|
[2359] | 182 | // convolution kernel
|
---|
| 183 | Vector<Float> convFunc ;
|
---|
[2364] | 184 | t0 = mathutil::gettimeofday_sec() ;
|
---|
[2359] | 185 | setConvFunc( convFunc ) ;
|
---|
[2364] | 186 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 187 | os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
[2359] | 188 | //cout << "convSupport=" << convSupport_ << endl ;
|
---|
| 189 | //cout << "convFunc=" << convFunc << endl ;
|
---|
| 190 |
|
---|
[2356] | 191 | // world -> pixel
|
---|
[2375] | 192 | Array<Double> xypos( direction.shape(), 0.0 ) ;
|
---|
[2364] | 193 | t0 = mathutil::gettimeofday_sec() ;
|
---|
[2356] | 194 | toPixel( direction, xypos ) ;
|
---|
[2364] | 195 | t1 = mathutil::gettimeofday_sec() ;
|
---|
[2375] | 196 | //os << "xypos=" << xypos << LogIO::POST ;
|
---|
[2364] | 197 | os << "toPixel: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
[2356] | 198 |
|
---|
[2361] | 199 | // call ggridsd
|
---|
[2356] | 200 | Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ;
|
---|
| 201 | Double *xypos_p = xypos.getStorage( deletePos ) ;
|
---|
[2374] | 202 | const Complex *data_p = spectra.getStorage( deleteData ) ;
|
---|
[2356] | 203 | const Float *wgt_p = weight.getStorage( deleteWgt ) ;
|
---|
[2375] | 204 | //const Int *flag_p = flagI.getStorage( deleteFlag ) ;
|
---|
| 205 | //const Int *rflag_p = rflagI.getStorage( deleteFlagR ) ;
|
---|
| 206 | const Int *flag_p = flagtra.getStorage( deleteFlag ) ;
|
---|
| 207 | const Int *rflag_p = rflag.getStorage( deleteFlagR ) ;
|
---|
[2356] | 208 | Float *conv_p = convFunc.getStorage( deleteConv ) ;
|
---|
[2359] | 209 | // Extend grid plane with convSupport_
|
---|
[2364] | 210 | Int gnx = nx_ ;
|
---|
| 211 | Int gny = ny_ ;
|
---|
| 212 | // Int gnx = nx_+convSupport_*2 ;
|
---|
| 213 | // Int gny = ny_+convSupport_*2 ;
|
---|
[2361] | 214 | IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
|
---|
[2356] | 215 | Array<Complex> gdataArrC( gshape, 0.0 ) ;
|
---|
| 216 | Array<Float> gwgtArr( gshape, 0.0 ) ;
|
---|
| 217 | Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ;
|
---|
| 218 | Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ;
|
---|
| 219 | Int idopsf = 0 ;
|
---|
[2361] | 220 | Int *chanMap = new Int[nchan_] ;
|
---|
[2356] | 221 | {
|
---|
| 222 | Int *work_p = chanMap ;
|
---|
[2361] | 223 | for ( Int i = 0 ; i < nchan_ ; i++ ) {
|
---|
[2356] | 224 | *work_p = i ;
|
---|
| 225 | work_p++ ;
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
[2361] | 228 | Int *polMap = new Int[npol_] ;
|
---|
[2356] | 229 | {
|
---|
| 230 | Int *work_p = polMap ;
|
---|
[2361] | 231 | for ( Int i = 0 ; i < npol_ ; i++ ) {
|
---|
[2356] | 232 | *work_p = i ;
|
---|
| 233 | work_p++ ;
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
[2361] | 236 | Double *sumw_p = new Double[npol_*nchan_] ;
|
---|
[2356] | 237 | {
|
---|
| 238 | Double *work_p = sumw_p ;
|
---|
[2361] | 239 | for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) {
|
---|
[2356] | 240 | *work_p = 0.0 ;
|
---|
| 241 | work_p++ ;
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
[2364] | 244 | t0 = mathutil::gettimeofday_sec() ;
|
---|
| 245 | Int irow = -1 ;
|
---|
[2356] | 246 | ggridsd( xypos_p,
|
---|
| 247 | data_p,
|
---|
[2361] | 248 | &npol_,
|
---|
| 249 | &nchan_,
|
---|
[2356] | 250 | &idopsf,
|
---|
| 251 | flag_p,
|
---|
| 252 | rflag_p,
|
---|
| 253 | wgt_p,
|
---|
[2361] | 254 | &nrow_,
|
---|
[2356] | 255 | &irow,
|
---|
| 256 | gdata_p,
|
---|
| 257 | wdata_p,
|
---|
[2359] | 258 | &gnx,
|
---|
| 259 | &gny,
|
---|
[2361] | 260 | &npol_,
|
---|
| 261 | &nchan_,
|
---|
[2356] | 262 | &convSupport_,
|
---|
| 263 | &convSampling_,
|
---|
| 264 | conv_p,
|
---|
| 265 | chanMap,
|
---|
| 266 | polMap,
|
---|
| 267 | sumw_p ) ;
|
---|
[2364] | 268 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 269 | os << "ggridsd: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
[2356] | 270 | xypos.putStorage( xypos_p, deletePos ) ;
|
---|
[2374] | 271 | spectra.freeStorage( data_p, deleteData ) ;
|
---|
[2356] | 272 | weight.freeStorage( wgt_p, deleteWgt ) ;
|
---|
[2375] | 273 | flagtra.freeStorage( flag_p, deleteFlag ) ;
|
---|
| 274 | rflag.freeStorage( rflag_p, deleteFlagR ) ;
|
---|
[2356] | 275 | convFunc.putStorage( conv_p, deleteConv ) ;
|
---|
| 276 | delete polMap ;
|
---|
| 277 | delete chanMap ;
|
---|
| 278 | gdataArrC.putStorage( gdata_p, deleteDataG ) ;
|
---|
| 279 | gwgtArr.putStorage( wdata_p, deleteWgtG ) ;
|
---|
[2374] | 280 | setData( data_, gdataArrC, gwgtArr ) ;
|
---|
[2361] | 281 | //Matrix<Double> sumWeight( IPosition( 2, npol_, nchan_ ), sumw_p, TAKE_OVER ) ;
|
---|
| 282 | delete sumw_p ;
|
---|
[2356] | 283 | //cout << "sumWeight = " << sumWeight << endl ;
|
---|
[2364] | 284 | // os << "gdataArr = " << gdataArr << LogIO::POST ;
|
---|
| 285 | // os << "gwgtArr = " << gwgtArr << LogIO::POST ;
|
---|
| 286 | // os << "data_ " << data_ << LogIO::POST ;
|
---|
[2356] | 287 | }
|
---|
| 288 |
|
---|
[2368] | 289 | void STGrid::setData( Array<Float> &data,
|
---|
[2374] | 290 | Array<Complex> &gdata,
|
---|
[2368] | 291 | Array<Float> &gwgt )
|
---|
| 292 | {
|
---|
| 293 | LogIO os( LogOrigin("STGrid","setData",WHERE) ) ;
|
---|
| 294 | double t0, t1 ;
|
---|
| 295 | t0 = mathutil::gettimeofday_sec() ;
|
---|
[2371] | 296 | data.resize( gdata.shape() ) ;
|
---|
[2368] | 297 | uInt len = data.nelements() ;
|
---|
| 298 | Float *w0_p ;
|
---|
[2374] | 299 | const Complex *w1_p ;
|
---|
| 300 | const Float *w2_p ;
|
---|
[2368] | 301 | Bool b0, b1, b2 ;
|
---|
| 302 | Float *data_p = data.getStorage( b0 ) ;
|
---|
[2374] | 303 | const Complex *gdata_p = gdata.getStorage( b1 ) ;
|
---|
[2368] | 304 | const Float *gwgt_p = gwgt.getStorage( b2 ) ;
|
---|
| 305 | w0_p = data_p ;
|
---|
| 306 | w1_p = gdata_p ;
|
---|
| 307 | w2_p = gwgt_p ;
|
---|
| 308 | for ( uInt i = 0 ; i < len ; i++ ) {
|
---|
[2374] | 309 | *w0_p = (*w2_p > 0.0) ? ((*w1_p).real() / *w2_p) : 0.0 ;
|
---|
[2368] | 310 | w0_p++ ;
|
---|
| 311 | w1_p++ ;
|
---|
| 312 | w2_p++ ;
|
---|
| 313 | }
|
---|
| 314 | data.putStorage( data_p, b0 ) ;
|
---|
| 315 | gdata.freeStorage( gdata_p, b1 ) ;
|
---|
| 316 | gwgt.freeStorage( gwgt_p, b2 ) ;
|
---|
| 317 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 318 | os << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[2356] | 321 | void STGrid::setupGrid( Int &nx,
|
---|
| 322 | Int &ny,
|
---|
| 323 | String &cellx,
|
---|
| 324 | String &celly,
|
---|
| 325 | Double &xmin,
|
---|
| 326 | Double &xmax,
|
---|
| 327 | Double &ymin,
|
---|
| 328 | Double &ymax,
|
---|
| 329 | String ¢er )
|
---|
| 330 | {
|
---|
[2375] | 331 | LogIO os( LogOrigin("STGrid","setupGrid",WHERE) ) ;
|
---|
[2356] | 332 | //cout << "nx=" << nx << ", ny=" << ny << endl ;
|
---|
[2359] | 333 |
|
---|
| 334 | // center position
|
---|
| 335 | if ( center.size() == 0 ) {
|
---|
| 336 | center_(0) = 0.5 * ( xmin + xmax ) ;
|
---|
| 337 | center_(1) = 0.5 * ( ymin + ymax ) ;
|
---|
| 338 | }
|
---|
| 339 | else {
|
---|
| 340 | String::size_type pos0 = center.find( " " ) ;
|
---|
| 341 | if ( pos0 == String::npos ) {
|
---|
| 342 | throw AipsError( "bad string format in parameter center" ) ;
|
---|
| 343 | }
|
---|
| 344 | String::size_type pos1 = center.find( " ", pos0+1 ) ;
|
---|
| 345 | String typestr, xstr, ystr ;
|
---|
| 346 | if ( pos1 != String::npos ) {
|
---|
| 347 | typestr = center.substr( 0, pos0 ) ;
|
---|
| 348 | xstr = center.substr( pos0+1, pos1-pos0 ) ;
|
---|
| 349 | ystr = center.substr( pos1+1 ) ;
|
---|
| 350 | // todo: convert to J2000 (or direction ref for DIRECTION column)
|
---|
| 351 | }
|
---|
| 352 | else {
|
---|
| 353 | typestr = "J2000" ;
|
---|
| 354 | xstr = center.substr( 0, pos0 ) ;
|
---|
| 355 | ystr = center.substr( pos0+1 ) ;
|
---|
| 356 | }
|
---|
| 357 | QuantumHolder qh ;
|
---|
| 358 | String err ;
|
---|
| 359 | qh.fromString( err, xstr ) ;
|
---|
| 360 | Quantum<Double> xcen = qh.asQuantumDouble() ;
|
---|
| 361 | qh.fromString( err, ystr ) ;
|
---|
| 362 | Quantum<Double> ycen = qh.asQuantumDouble() ;
|
---|
| 363 | center_(0) = xcen.getValue( "rad" ) ;
|
---|
| 364 | center_(1) = ycen.getValue( "rad" ) ;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 |
|
---|
[2356] | 368 | nx_ = nx ;
|
---|
| 369 | ny_ = ny ;
|
---|
| 370 | if ( nx < 0 && ny > 0 ) {
|
---|
| 371 | nx_ = ny ;
|
---|
| 372 | ny_ = ny ;
|
---|
| 373 | }
|
---|
| 374 | if ( ny < 0 && nx > 0 ) {
|
---|
| 375 | nx_ = nx ;
|
---|
| 376 | ny_ = nx ;
|
---|
| 377 | }
|
---|
[2375] | 378 |
|
---|
| 379 | //Double wx = xmax - xmin ;
|
---|
| 380 | //Double wy = ymax - ymin ;
|
---|
| 381 | Double wx = max( abs(xmax-center_(0)), abs(xmin-center_(0)) ) * 2 ;
|
---|
| 382 | Double wy = max( abs(ymax-center_(1)), abs(ymin-center_(1)) ) * 2 ;
|
---|
| 383 | // take 10% margin
|
---|
| 384 | wx *= 1.10 ;
|
---|
| 385 | wy *= 1.10 ;
|
---|
| 386 |
|
---|
| 387 | Quantum<Double> qcellx ;
|
---|
| 388 | Quantum<Double> qcelly ;
|
---|
[2356] | 389 | //cout << "nx_ = " << nx_ << ", ny_ = " << ny_ << endl ;
|
---|
| 390 | if ( cellx.size() != 0 && celly.size() != 0 ) {
|
---|
| 391 | readQuantity( qcellx, cellx ) ;
|
---|
| 392 | readQuantity( qcelly, celly ) ;
|
---|
| 393 | }
|
---|
| 394 | else if ( celly.size() != 0 ) {
|
---|
[2375] | 395 | os << "Using celly to x-axis..." << LogIO::POST ;
|
---|
[2356] | 396 | readQuantity( qcelly, celly ) ;
|
---|
| 397 | qcellx = qcelly ;
|
---|
| 398 | }
|
---|
| 399 | else if ( cellx.size() != 0 ) {
|
---|
[2375] | 400 | os << "Using cellx to y-axis..." << LogIO::POST ;
|
---|
[2356] | 401 | readQuantity( qcellx, cellx ) ;
|
---|
| 402 | qcelly = qcellx ;
|
---|
| 403 | }
|
---|
| 404 | else {
|
---|
| 405 | if ( nx_ < 0 ) {
|
---|
[2375] | 406 | os << "No user preference in grid setting. Using default..." << LogIO::POST ;
|
---|
[2356] | 407 | readQuantity( qcellx, "1.0arcmin" ) ;
|
---|
| 408 | qcelly = qcellx ;
|
---|
| 409 | }
|
---|
| 410 | else {
|
---|
[2375] | 411 | if ( wx == 0.0 ) {
|
---|
| 412 | os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ;
|
---|
| 413 | wx = 0.00290888 ;
|
---|
| 414 | }
|
---|
| 415 | if ( wy == 0.0 ) {
|
---|
| 416 | os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ;
|
---|
| 417 | wy = 0.00290888 ;
|
---|
| 418 | }
|
---|
[2356] | 419 | qcellx = Quantum<Double>( wx/nx_, "rad" ) ;
|
---|
| 420 | qcelly = Quantum<Double>( wy/ny_, "rad" ) ;
|
---|
| 421 | }
|
---|
| 422 | }
|
---|
| 423 | cellx_ = qcellx.getValue( "rad" ) ;
|
---|
| 424 | celly_ = qcelly.getValue( "rad" ) ;
|
---|
| 425 | if ( nx_ < 0 ) {
|
---|
[2375] | 426 | if ( wx == 0.0 ) {
|
---|
| 427 | os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ;
|
---|
| 428 | wx = 0.00290888 ;
|
---|
| 429 | }
|
---|
| 430 | if ( wy == 0.0 ) {
|
---|
| 431 | os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ;
|
---|
| 432 | wy = 0.00290888 ;
|
---|
| 433 | }
|
---|
[2356] | 434 | nx_ = Int( ceil( wx/cellx_ ) ) ;
|
---|
| 435 | ny_ = Int( ceil( wy/celly_ ) ) ;
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 |
|
---|
[2362] | 439 | void STGrid::selectData( Table &tab )
|
---|
| 440 | {
|
---|
| 441 | Int ifno = ifno_ ;
|
---|
| 442 | Table taborg( infile_ ) ;
|
---|
| 443 | if ( ifno == -1 ) {
|
---|
[2368] | 444 | LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;
|
---|
[2362] | 445 | // os << LogIO::SEVERE
|
---|
| 446 | // << "Please set IFNO before actual gridding"
|
---|
| 447 | // << LogIO::EXCEPTION ;
|
---|
| 448 | ROScalarColumn<uInt> ifnoCol( taborg, "IFNO" ) ;
|
---|
| 449 | ifno = ifnoCol( 0 ) ;
|
---|
| 450 | os << LogIO::WARN
|
---|
| 451 | << "IFNO is not given. Using default IFNO: " << ifno << LogIO::POST ;
|
---|
| 452 | }
|
---|
[2364] | 453 | // tab = taborg( taborg.col("IFNO") == ifno ) ;
|
---|
| 454 | TableExprNode node ;
|
---|
| 455 | node = taborg.col("IFNO") == ifno ;
|
---|
| 456 | if ( scanlist_.size() > 0 ) {
|
---|
| 457 | node = node && taborg.col("SCANNO").in( scanlist_ ) ;
|
---|
| 458 | }
|
---|
| 459 | tab = taborg( node ) ;
|
---|
[2362] | 460 | if ( tab.nrow() == 0 ) {
|
---|
[2368] | 461 | LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;
|
---|
[2362] | 462 | os << LogIO::SEVERE
|
---|
[2365] | 463 | << "No corresponding rows for given selection: IFNO " << ifno
|
---|
| 464 | << " SCANNO " << scanlist_
|
---|
[2362] | 465 | << LogIO::EXCEPTION ;
|
---|
| 466 | }
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[2375] | 469 | void STGrid::getData( Array<Complex> &spectra,
|
---|
| 470 | Array<Double> &direction,
|
---|
| 471 | Array<uChar> &flagtra,
|
---|
| 472 | Array<uInt> &rflag,
|
---|
| 473 | Array<Float> &weight )
|
---|
[2356] | 474 | {
|
---|
[2375] | 475 | LogIO os( LogOrigin("STGrid","getData",WHERE) ) ;
|
---|
[2374] | 476 | // os << "start" << LogIO::POST ;
|
---|
[2362] | 477 | Table tab ;
|
---|
| 478 | selectData( tab ) ;
|
---|
[2375] | 479 | setupArray( tab ) ;
|
---|
[2374] | 480 | // os << "npol_ = " << npol_ << LogIO::POST ;
|
---|
| 481 | // os << "nchan_ = " << nchan_ << LogIO::POST ;
|
---|
| 482 | // os << "nrow_ = " << nrow_ << LogIO::POST ;
|
---|
[2375] | 483 | IPosition cshape( 3, npol_, nchan_, nrow_ ) ;
|
---|
| 484 | IPosition mshape( 2, npol_, nrow_ ) ;
|
---|
| 485 | spectra.resize( cshape ) ;
|
---|
| 486 | flagtra.resize( cshape ) ;
|
---|
| 487 | rflag.resize( mshape ) ;
|
---|
| 488 | direction.resize( IPosition(2,2,nrow_) ) ;
|
---|
| 489 | Array<Float> tsys( cshape ) ;
|
---|
| 490 | Array<Double> tint( mshape ) ;
|
---|
| 491 |
|
---|
| 492 | ArrayIterator<uChar> fli( flagtra, IPosition(2,1,2) ) ;
|
---|
| 493 | ArrayIterator<uInt> fri( rflag, IPosition(1,1) ) ;
|
---|
| 494 | ArrayIterator<Float> tsi( tsys, IPosition(2,1,2) ) ;
|
---|
| 495 | ArrayIterator<Double> tii( tint, IPosition(1,1) ) ;
|
---|
| 496 |
|
---|
[2371] | 497 | // boolean for pointer access
|
---|
[2375] | 498 | Bool bsp, bsps ;
|
---|
[2371] | 499 | // pointer to the data
|
---|
[2374] | 500 | Complex *sp_p = spectra.getStorage( bsp ) ;
|
---|
[2371] | 501 | // working pointer
|
---|
[2374] | 502 | Complex *wsp_p = sp_p ;
|
---|
[2371] | 503 | uInt len = nchan_ * nrow_ ;
|
---|
[2375] | 504 | IPosition mshape2( 2, nchan_, nrow_ ) ;
|
---|
[2371] | 505 | IPosition vshape( 1, nrow_ ) ;
|
---|
[2374] | 506 | Vector<Float> spSlice( nchan_ ) ;
|
---|
| 507 | const Float *sps_p = spSlice.getStorage( bsps ) ;
|
---|
| 508 | long cincr = npol_ ;
|
---|
| 509 | long rincr = npol_ * nchan_ ;
|
---|
[2361] | 510 | for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
|
---|
[2360] | 511 | Table subt = tab( tab.col("POLNO") == pollist_[ipol] ) ;
|
---|
| 512 | ROArrayColumn<Float> spectraCol( subt, "SPECTRA" ) ;
|
---|
| 513 | ROArrayColumn<Double> directionCol( subt, "DIRECTION" ) ;
|
---|
| 514 | ROArrayColumn<uChar> flagtraCol( subt, "FLAGTRA" ) ;
|
---|
| 515 | ROScalarColumn<uInt> rflagCol( subt, "FLAGROW" ) ;
|
---|
[2361] | 516 | ROArrayColumn<Float> tsysCol( subt, "TSYS" ) ;
|
---|
| 517 | ROScalarColumn<Double> tintCol( subt, "INTERVAL" ) ;
|
---|
[2374] | 518 | for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
|
---|
| 519 | spectraCol.get( irow, spSlice ) ;
|
---|
| 520 | const Float *wsps_p = sps_p ;
|
---|
| 521 | wsp_p = sp_p + (long)ipol + rincr * (long)irow ;
|
---|
| 522 | for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
|
---|
| 523 | *wsp_p = *wsps_p ;
|
---|
| 524 | wsps_p++ ;
|
---|
| 525 | wsp_p += cincr ;
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
[2375] | 528 | Array<uChar> flSlice = fli.array() ;
|
---|
| 529 | Vector<uInt> frSlice = fri.array() ;
|
---|
[2371] | 530 | flagtraCol.getColumn( flSlice ) ;
|
---|
| 531 | rflagCol.getColumn( frSlice ) ;
|
---|
[2360] | 532 | if ( ipol == 0 )
|
---|
| 533 | directionCol.getColumn( direction ) ;
|
---|
[2371] | 534 | Vector<Float> tmpF = tsysCol( 0 ) ;
|
---|
[2375] | 535 | Array<Float> tsSlice = tsi.array() ;
|
---|
[2371] | 536 | if ( tmpF.nelements() == (uInt)nchan_ ) {
|
---|
| 537 | tsysCol.getColumn( tsSlice ) ;
|
---|
[2361] | 538 | }
|
---|
| 539 | else {
|
---|
[2371] | 540 | tsSlice = tmpF( 0 ) ;
|
---|
[2361] | 541 | }
|
---|
[2375] | 542 | Vector<Double> tmpD = tii.array() ;
|
---|
[2361] | 543 | tintCol.getColumn( tmpD ) ;
|
---|
[2371] | 544 |
|
---|
| 545 | wsp_p += len ;
|
---|
[2375] | 546 |
|
---|
| 547 | fli.next() ;
|
---|
| 548 | fri.next() ;
|
---|
| 549 | tsi.next() ;
|
---|
| 550 | tii.next() ;
|
---|
[2360] | 551 | }
|
---|
[2374] | 552 | spSlice.freeStorage( sps_p, bsps ) ;
|
---|
[2371] | 553 | spectra.putStorage( sp_p, bsp ) ;
|
---|
[2361] | 554 |
|
---|
[2375] | 555 | // os << "spectra=" << spectra << LogIO::POST ;
|
---|
| 556 | // os << "flagtra=" << flagtra << LogIO::POST ;
|
---|
| 557 | // os << "rflag=" << rflag << LogIO::POST ;
|
---|
| 558 | // os << "direction=" << direction << LogIO::POST ;
|
---|
| 559 |
|
---|
[2361] | 560 | getWeight( weight, tsys, tint ) ;
|
---|
[2356] | 561 | }
|
---|
| 562 |
|
---|
[2375] | 563 | void STGrid::getData( Array<Complex> &spectra,
|
---|
| 564 | Array<Double> &direction,
|
---|
| 565 | Array<Int> &flagtra,
|
---|
| 566 | Array<Int> &rflag,
|
---|
| 567 | Array<Float> &weight )
|
---|
[2371] | 568 | {
|
---|
[2375] | 569 | LogIO os( LogOrigin("STGrid","getData",WHERE) ) ;
|
---|
| 570 | double t0, t1 ;
|
---|
| 571 |
|
---|
| 572 | Array<uChar> flagUC ;
|
---|
| 573 | Array<uInt> rflagUI ;
|
---|
| 574 | getData( spectra, direction, flagUC, rflagUI, weight ) ;
|
---|
| 575 |
|
---|
| 576 | t0 = mathutil::gettimeofday_sec() ;
|
---|
| 577 | toInt( flagUC, flagtra ) ;
|
---|
| 578 | toInt( rflagUI, rflag ) ;
|
---|
| 579 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 580 | os << "toInt: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
| 581 | }
|
---|
| 582 |
|
---|
| 583 | void STGrid::setupArray( Table &tab )
|
---|
| 584 | {
|
---|
[2371] | 585 | ROScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
|
---|
| 586 | Vector<uInt> pols = polnoCol.getColumn() ;
|
---|
| 587 | Vector<uInt> pollistOrg ;
|
---|
| 588 | uInt npolOrg = 0 ;
|
---|
| 589 | uInt polno ;
|
---|
| 590 | for ( uInt i = 0 ; i < polnoCol.nrow() ; i++ ) {
|
---|
| 591 | //polno = polnoCol( i ) ;
|
---|
| 592 | polno = pols( i ) ;
|
---|
| 593 | if ( allNE( pollistOrg, polno ) ) {
|
---|
| 594 | pollistOrg.resize( npolOrg+1, True ) ;
|
---|
| 595 | pollistOrg[npolOrg] = polno ;
|
---|
| 596 | npolOrg++ ;
|
---|
| 597 | }
|
---|
| 598 | }
|
---|
| 599 | if ( pollist_.size() == 0 )
|
---|
| 600 | pollist_ = pollistOrg ;
|
---|
| 601 | else {
|
---|
| 602 | Vector<uInt> newlist ;
|
---|
| 603 | uInt newsize = 0 ;
|
---|
| 604 | for ( uInt i = 0 ; i < pollist_.size() ; i++ ) {
|
---|
| 605 | if ( anyEQ( pollistOrg, pollist_[i] ) ) {
|
---|
| 606 | newlist.resize( newsize+1, True ) ;
|
---|
| 607 | newlist[newsize] = pollist_[i] ;
|
---|
| 608 | newsize++ ;
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
| 611 | pollist_.assign( newlist ) ;
|
---|
| 612 | }
|
---|
| 613 | npol_ = pollist_.size() ;
|
---|
| 614 | if ( npol_ == 0 ) {
|
---|
[2375] | 615 | LogIO os( LogOrigin("STGrid","setupArray",WHERE) ) ;
|
---|
[2371] | 616 | os << LogIO::SEVERE << "Empty pollist" << LogIO::EXCEPTION ;
|
---|
| 617 | }
|
---|
| 618 | nrow_ = tab.nrow() / npolOrg ;
|
---|
| 619 | ROArrayColumn<uChar> tmpCol( tab, "FLAGTRA" ) ;
|
---|
| 620 | nchan_ = tmpCol( 0 ).nelements() ;
|
---|
[2375] | 621 | // LogIO os( LogOrigin("STGrid","setupArray",WHERE) ) ;
|
---|
[2371] | 622 | // os << "npol_ = " << npol_ << "(" << pollist_ << ")" << endl
|
---|
| 623 | // << "nchan_ = " << nchan_ << endl
|
---|
| 624 | // << "nrow_ = " << nrow_ << LogIO::POST ;
|
---|
| 625 | }
|
---|
| 626 |
|
---|
[2375] | 627 | void STGrid::getWeight( Array<Float> &w,
|
---|
| 628 | Array<Float> &tsys,
|
---|
| 629 | Array<Double> &tint )
|
---|
[2361] | 630 | {
|
---|
[2368] | 631 | LogIO os( LogOrigin("STGrid","getWeight",WHERE) ) ;
|
---|
| 632 | double t0, t1 ;
|
---|
| 633 | t0 = mathutil::gettimeofday_sec() ;
|
---|
[2361] | 634 | // resize
|
---|
[2375] | 635 | IPosition refShape = tsys.shape() ;
|
---|
| 636 | Int nchan = refShape[1] ;
|
---|
| 637 | Int nrow = refShape[2] ;
|
---|
| 638 | w.resize( IPosition(2,nchan,nrow) ) ;
|
---|
[2361] | 639 |
|
---|
| 640 | // set weight
|
---|
| 641 | Bool warn = False ;
|
---|
| 642 | if ( wtype_.compare( "UNIFORM" ) == 0 ) {
|
---|
[2368] | 643 | w = 1.0 ;
|
---|
[2361] | 644 | }
|
---|
| 645 | else if ( wtype_.compare( "TINT" ) == 0 ) {
|
---|
| 646 | if ( npol_ > 1 ) warn = True ;
|
---|
[2369] | 647 | Bool b0, b1 ;
|
---|
| 648 | Float *w_p = w.getStorage( b0 ) ;
|
---|
| 649 | Float *w0_p = w_p ;
|
---|
| 650 | const Double *ti_p = tint.getStorage( b1 ) ;
|
---|
| 651 | const Double *w1_p = ti_p ;
|
---|
[2375] | 652 | for ( Int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
[2369] | 653 | Float val = (Float)(polMean( w1_p )) ;
|
---|
[2375] | 654 | for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
|
---|
[2369] | 655 | *w0_p = val ;
|
---|
| 656 | w0_p++ ;
|
---|
| 657 | }
|
---|
[2361] | 658 | }
|
---|
[2369] | 659 | w.putStorage( w_p, b0 ) ;
|
---|
| 660 | tint.freeStorage( ti_p, b1 ) ;
|
---|
[2361] | 661 | }
|
---|
| 662 | else if ( wtype_.compare( "TSYS" ) == 0 ) {
|
---|
| 663 | if ( npol_ > 1 ) warn = True ;
|
---|
[2369] | 664 | Bool b0, b1 ;
|
---|
| 665 | Float *w_p = w.getStorage( b0 ) ;
|
---|
| 666 | Float *w0_p = w_p ;
|
---|
| 667 | const Float *ts_p = tsys.getStorage( b1 ) ;
|
---|
| 668 | const Float *w1_p = ts_p ;
|
---|
[2375] | 669 | for ( Int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 670 | for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
|
---|
[2369] | 671 | Float val = polMean( w1_p ) ;
|
---|
| 672 | *w0_p = 1.0 / ( val * val ) ;
|
---|
| 673 | w0_p++ ;
|
---|
[2361] | 674 | }
|
---|
| 675 | }
|
---|
[2369] | 676 | w.putStorage( w_p, b0 ) ;
|
---|
| 677 | tsys.freeStorage( ts_p, b1 ) ;
|
---|
[2361] | 678 | }
|
---|
| 679 | else if ( wtype_.compare( "TINTSYS" ) == 0 ) {
|
---|
| 680 | if ( npol_ > 1 ) warn = True ;
|
---|
[2369] | 681 | Bool b0, b1, b2 ;
|
---|
| 682 | Float *w_p = w.getStorage( b0 ) ;
|
---|
| 683 | Float *w0_p = w_p ;
|
---|
| 684 | const Double *ti_p = tint.getStorage( b1 ) ;
|
---|
| 685 | const Double *w1_p = ti_p ;
|
---|
| 686 | const Float *ts_p = tsys.getStorage( b2 ) ;
|
---|
| 687 | const Float *w2_p = ts_p ;
|
---|
[2375] | 688 | for ( Int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
[2369] | 689 | Float interval = (Float)(polMean( w1_p )) ;
|
---|
[2375] | 690 | for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
|
---|
[2369] | 691 | Float temp = polMean( w2_p ) ;
|
---|
| 692 | *w0_p = interval / ( temp * temp ) ;
|
---|
| 693 | w0_p++ ;
|
---|
[2361] | 694 | }
|
---|
| 695 | }
|
---|
[2369] | 696 | w.putStorage( w_p, b0 ) ;
|
---|
| 697 | tint.freeStorage( ti_p, b1 ) ;
|
---|
| 698 | tsys.freeStorage( ts_p, b2 ) ;
|
---|
[2361] | 699 | }
|
---|
| 700 | else {
|
---|
[2368] | 701 | //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
|
---|
| 702 | os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
|
---|
| 703 | w = 1.0 ;
|
---|
[2361] | 704 | }
|
---|
| 705 |
|
---|
| 706 | if ( npol_ > 1 ) {
|
---|
[2368] | 707 | //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
|
---|
[2362] | 708 | os << LogIO::WARN << "STGrid doesn't support assigning polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ;
|
---|
[2361] | 709 | }
|
---|
[2368] | 710 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 711 | os << "getWeight: elapsed time is " << t1-t0 << " sec" << LogIO::POST ;
|
---|
[2361] | 712 | }
|
---|
| 713 |
|
---|
[2369] | 714 | Float STGrid::polMean( const Float *p )
|
---|
| 715 | {
|
---|
| 716 | Float v = 0.0 ;
|
---|
| 717 | for ( Int i = 0 ; i < npol_ ; i++ ) {
|
---|
| 718 | v += *p ;
|
---|
| 719 | p++ ;
|
---|
| 720 | }
|
---|
| 721 | v /= npol_ ;
|
---|
| 722 | return v ;
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | Double STGrid::polMean( const Double *p )
|
---|
| 726 | {
|
---|
| 727 | Double v = 0.0 ;
|
---|
| 728 | for ( Int i = 0 ; i < npol_ ; i++ ) {
|
---|
| 729 | v += *p ;
|
---|
| 730 | p++ ;
|
---|
| 731 | }
|
---|
| 732 | v /= npol_ ;
|
---|
| 733 | return v ;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[2375] | 736 | void STGrid::toInt( Array<uChar> &u, Array<Int> &v )
|
---|
[2356] | 737 | {
|
---|
[2375] | 738 | uInt len = u.nelements() ;
|
---|
[2356] | 739 | Int *int_p = new Int[len] ;
|
---|
| 740 | Bool deleteIt ;
|
---|
[2375] | 741 | const uChar *data_p = u.getStorage( deleteIt ) ;
|
---|
[2356] | 742 | Int *i_p = int_p ;
|
---|
| 743 | const uChar *u_p = data_p ;
|
---|
| 744 | for ( uInt i = 0 ; i < len ; i++ ) {
|
---|
| 745 | *i_p = ( *u_p == 0 ) ? 0 : 1 ;
|
---|
| 746 | i_p++ ;
|
---|
| 747 | u_p++ ;
|
---|
| 748 | }
|
---|
[2375] | 749 | u.freeStorage( data_p, deleteIt ) ;
|
---|
| 750 | v.takeStorage( u.shape(), int_p, TAKE_OVER ) ;
|
---|
[2356] | 751 | }
|
---|
| 752 |
|
---|
[2375] | 753 | void STGrid::toInt( Array<uInt> &u, Array<Int> &v )
|
---|
[2356] | 754 | {
|
---|
[2375] | 755 | uInt len = u.nelements() ;
|
---|
[2356] | 756 | Int *int_p = new Int[len] ;
|
---|
| 757 | Bool deleteIt ;
|
---|
[2375] | 758 | const uInt *data_p = u.getStorage( deleteIt ) ;
|
---|
[2356] | 759 | Int *i_p = int_p ;
|
---|
| 760 | const uInt *u_p = data_p ;
|
---|
| 761 | for ( uInt i = 0 ; i < len ; i++ ) {
|
---|
| 762 | *i_p = ( *u_p == 0 ) ? 0 : 1 ;
|
---|
| 763 | i_p++ ;
|
---|
| 764 | u_p++ ;
|
---|
| 765 | }
|
---|
[2375] | 766 | u.freeStorage( data_p, deleteIt ) ;
|
---|
| 767 | v.takeStorage( u.shape(), int_p, TAKE_OVER ) ;
|
---|
[2356] | 768 | }
|
---|
| 769 |
|
---|
[2375] | 770 | void STGrid::toPixel( Array<Double> &world, Array<Double> &pixel )
|
---|
[2356] | 771 | {
|
---|
[2359] | 772 | // gridding will be done on (nx_+2*convSupport_) x (ny_+2*convSupport_)
|
---|
| 773 | // grid plane to avoid unexpected behavior on grid edge
|
---|
[2375] | 774 | Block<Double> pixc( 2 ) ;
|
---|
| 775 | pixc[0] = Double( nx_-1 ) * 0.5 ;
|
---|
| 776 | pixc[1] = Double( ny_-1 ) * 0.5 ;
|
---|
| 777 | // pixc[0] = Double( nx_+2*convSupport_-1 ) * 0.5 ;
|
---|
| 778 | // pixc[1] = Double( ny_+2*convSupport_-1 ) * 0.5 ;
|
---|
[2356] | 779 | uInt nrow = world.shape()[1] ;
|
---|
[2375] | 780 | Bool bw, bp ;
|
---|
| 781 | const Double *w_p = world.getStorage( bw ) ;
|
---|
| 782 | Double *p_p = pixel.getStorage( bp ) ;
|
---|
| 783 | const Double *ww_p = w_p ;
|
---|
| 784 | Double *wp_p = p_p ;
|
---|
| 785 | for ( uInt i = 0 ; i < nrow ; i++ ) {
|
---|
| 786 | *wp_p = pixc[0] + ( *ww_p - center_[0] ) / cellx_ ;
|
---|
| 787 | wp_p++ ;
|
---|
| 788 | ww_p++ ;
|
---|
| 789 | *wp_p = pixc[1] + ( *ww_p - center_[1] ) / celly_ ;
|
---|
| 790 | wp_p++ ;
|
---|
| 791 | ww_p++ ;
|
---|
[2356] | 792 | }
|
---|
[2375] | 793 | world.freeStorage( w_p, bw ) ;
|
---|
| 794 | pixel.putStorage( p_p, bp ) ;
|
---|
[2364] | 795 | // String gridfile = "grid."+convType_+"."+String::toString(convSupport_)+".dat" ;
|
---|
| 796 | // ofstream ofs( gridfile.c_str(), ios::out ) ;
|
---|
| 797 | // ofs << "center " << center_(0) << " " << pixc(0)
|
---|
| 798 | // << " " << center_(1) << " " << pixc(1) << endl ;
|
---|
| 799 | // for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 800 | // ofs << irow ;
|
---|
| 801 | // for ( uInt i = 0 ; i < 2 ; i++ ) {
|
---|
| 802 | // ofs << " " << world(i, irow) << " " << pixel(i, irow) ;
|
---|
| 803 | // }
|
---|
| 804 | // ofs << endl ;
|
---|
| 805 | // }
|
---|
| 806 | // ofs.close() ;
|
---|
[2356] | 807 | }
|
---|
| 808 |
|
---|
| 809 | void STGrid::boxFunc( Vector<Float> &convFunc, Int &convSize )
|
---|
| 810 | {
|
---|
| 811 | convFunc = 0.0 ;
|
---|
| 812 | for ( Int i = 0 ; i < convSize/2 ; i++ )
|
---|
| 813 | convFunc(i) = 1.0 ;
|
---|
| 814 | }
|
---|
| 815 |
|
---|
| 816 | #define NEED_UNDERSCORES
|
---|
| 817 | #if defined(NEED_UNDERSCORES)
|
---|
| 818 | #define grdsf grdsf_
|
---|
| 819 | #endif
|
---|
| 820 | extern "C" {
|
---|
| 821 | void grdsf(Double*, Double*);
|
---|
| 822 | }
|
---|
| 823 | void STGrid::spheroidalFunc( Vector<Float> &convFunc )
|
---|
| 824 | {
|
---|
| 825 | convFunc = 0.0 ;
|
---|
| 826 | for ( Int i = 0 ; i < convSampling_*convSupport_ ; i++ ) {
|
---|
| 827 | Double nu = Double(i) / Double(convSupport_*convSampling_) ;
|
---|
| 828 | Double val ;
|
---|
| 829 | grdsf( &nu, &val ) ;
|
---|
| 830 | convFunc(i) = ( 1.0 - nu * nu ) * val ;
|
---|
| 831 | }
|
---|
| 832 | }
|
---|
| 833 |
|
---|
| 834 | void STGrid::gaussFunc( Vector<Float> &convFunc )
|
---|
| 835 | {
|
---|
| 836 | convFunc = 0.0 ;
|
---|
[2363] | 837 | // HWHM of the Gaussian is convSupport_ / 4
|
---|
| 838 | // To take into account Gaussian tail, kernel cutoff is set to 4 * HWHM
|
---|
| 839 | Int len = convSampling_ * convSupport_ ;
|
---|
| 840 | Double hwhm = len * 0.25 ;
|
---|
| 841 | for ( Int i = 0 ; i < len ; i++ ) {
|
---|
[2356] | 842 | Double val = Double(i) / hwhm ;
|
---|
| 843 | convFunc(i) = exp( -log(2)*val*val ) ;
|
---|
| 844 | }
|
---|
| 845 | }
|
---|
| 846 |
|
---|
| 847 | void STGrid::pbFunc( Vector<Float> &convFunc )
|
---|
| 848 | {
|
---|
| 849 | convFunc = 0.0 ;
|
---|
| 850 | }
|
---|
| 851 |
|
---|
| 852 | void STGrid::setConvFunc( Vector<Float> &convFunc )
|
---|
| 853 | {
|
---|
| 854 | convSupport_ = userSupport_ ;
|
---|
| 855 | if ( convType_ == "BOX" ) {
|
---|
| 856 | if ( convSupport_ < 0 )
|
---|
| 857 | convSupport_ = 0 ;
|
---|
| 858 | Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ;
|
---|
| 859 | convFunc.resize( convSize ) ;
|
---|
| 860 | boxFunc( convFunc, convSize ) ;
|
---|
| 861 | }
|
---|
| 862 | else if ( convType_ == "SF" ) {
|
---|
| 863 | if ( convSupport_ < 0 )
|
---|
| 864 | convSupport_ = 3 ;
|
---|
| 865 | Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ;
|
---|
| 866 | convFunc.resize( convSize ) ;
|
---|
| 867 | spheroidalFunc( convFunc ) ;
|
---|
| 868 | }
|
---|
| 869 | else if ( convType_ == "GAUSS" ) {
|
---|
[2363] | 870 | // to take into account Gaussian tail
|
---|
[2356] | 871 | if ( convSupport_ < 0 )
|
---|
[2363] | 872 | convSupport_ = 12 ; // 3 * 4
|
---|
| 873 | else {
|
---|
| 874 | convSupport_ = userSupport_ * 4 ;
|
---|
| 875 | }
|
---|
[2356] | 876 | Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ;
|
---|
| 877 | convFunc.resize( convSize ) ;
|
---|
| 878 | gaussFunc( convFunc ) ;
|
---|
| 879 | }
|
---|
[2359] | 880 | else if ( convType_ == "PB" ) {
|
---|
| 881 | if ( convSupport_ < 0 )
|
---|
| 882 | convSupport_ = 0 ;
|
---|
[2356] | 883 | pbFunc( convFunc ) ;
|
---|
[2359] | 884 | }
|
---|
[2356] | 885 | else {
|
---|
| 886 | throw AipsError( "Unsupported convolution function" ) ;
|
---|
| 887 | }
|
---|
| 888 | }
|
---|
| 889 |
|
---|
| 890 | string STGrid::saveData( string outfile )
|
---|
| 891 | {
|
---|
[2368] | 892 | LogIO os( LogOrigin("STGrid", "saveData", WHERE) ) ;
|
---|
| 893 | double t0, t1 ;
|
---|
| 894 | t0 = mathutil::gettimeofday_sec() ;
|
---|
| 895 |
|
---|
[2360] | 896 | //Int polno = 0 ;
|
---|
[2371] | 897 | String outfile_ ;
|
---|
[2356] | 898 | if ( outfile.size() == 0 ) {
|
---|
| 899 | if ( infile_.lastchar() == '/' ) {
|
---|
| 900 | outfile_ = infile_.substr( 0, infile_.size()-1 ) ;
|
---|
| 901 | }
|
---|
| 902 | else {
|
---|
| 903 | outfile_ = infile_ ;
|
---|
| 904 | }
|
---|
| 905 | outfile_ += ".grid" ;
|
---|
| 906 | }
|
---|
| 907 | else {
|
---|
| 908 | outfile_ = outfile ;
|
---|
| 909 | }
|
---|
[2371] | 910 | Table tab ;
|
---|
| 911 | prepareTable( tab, outfile_ ) ;
|
---|
[2356] | 912 | IPosition dshape = data_.shape() ;
|
---|
[2361] | 913 | Int nrow = nx_ * ny_ * npol_ ;
|
---|
| 914 | tab.rwKeywordSet().define( "nPol", npol_ ) ;
|
---|
[2360] | 915 | tab.addRow( nrow ) ;
|
---|
[2356] | 916 | Vector<Double> cpix( 2 ) ;
|
---|
| 917 | cpix(0) = Double( nx_ - 1 ) * 0.5 ;
|
---|
| 918 | cpix(1) = Double( ny_ - 1 ) * 0.5 ;
|
---|
| 919 | Vector<Double> dir( 2 ) ;
|
---|
| 920 | ArrayColumn<Double> directionCol( tab, "DIRECTION" ) ;
|
---|
| 921 | ArrayColumn<Float> spectraCol( tab, "SPECTRA" ) ;
|
---|
| 922 | ScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
|
---|
| 923 | Int irow = 0 ;
|
---|
[2371] | 924 | Vector<Float> sp( nchan_ ) ;
|
---|
| 925 | Bool bsp, bdata ;
|
---|
| 926 | const Float *data_p = data_.getStorage( bdata ) ;
|
---|
| 927 | Float *wsp_p, *sp_p ;
|
---|
| 928 | const Float *wdata_p = data_p ;
|
---|
| 929 | long step = nx_ * ny_ * npol_ ;
|
---|
| 930 | long offset ;
|
---|
[2356] | 931 | for ( Int iy = 0 ; iy < ny_ ; iy++ ) {
|
---|
[2371] | 932 | dir(1) = center_(1) - ( cpix(1) - (Double)iy ) * celly_ ;
|
---|
[2356] | 933 | for ( Int ix = 0 ; ix < nx_ ; ix++ ) {
|
---|
[2371] | 934 | dir(0) = center_(0) - ( cpix(0) - (Double)ix ) * cellx_ ;
|
---|
[2361] | 935 | for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
|
---|
[2371] | 936 | offset = ix + iy * nx_ + ipol * nx_ * ny_ ;
|
---|
| 937 | //os << "offset = " << offset << LogIO::POST ;
|
---|
| 938 | sp_p = sp.getStorage( bsp ) ;
|
---|
| 939 | wsp_p = sp_p ;
|
---|
| 940 | wdata_p = data_p + offset ;
|
---|
| 941 | for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
|
---|
| 942 | *wsp_p = *wdata_p ;
|
---|
| 943 | wsp_p++ ;
|
---|
| 944 | wdata_p += step ;
|
---|
| 945 | }
|
---|
| 946 | sp.putStorage( sp_p, bsp ) ;
|
---|
[2356] | 947 | spectraCol.put( irow, sp ) ;
|
---|
| 948 | directionCol.put( irow, dir ) ;
|
---|
[2360] | 949 | polnoCol.put( irow, pollist_[ipol] ) ;
|
---|
[2356] | 950 | irow++ ;
|
---|
| 951 | }
|
---|
| 952 | }
|
---|
| 953 | }
|
---|
[2371] | 954 | data_.freeStorage( data_p, bdata ) ;
|
---|
[2368] | 955 |
|
---|
| 956 | t1 = mathutil::gettimeofday_sec() ;
|
---|
| 957 | os << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
|
---|
[2374] | 958 |
|
---|
[2356] | 959 | return outfile_ ;
|
---|
| 960 | }
|
---|
| 961 |
|
---|
[2371] | 962 | void STGrid::prepareTable( Table &tab, String &name )
|
---|
| 963 | {
|
---|
| 964 | Table t( infile_, Table::Old ) ;
|
---|
| 965 | t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ;
|
---|
| 966 | tab = Table( name, Table::Update ) ;
|
---|
[2356] | 967 | }
|
---|
[2371] | 968 | }
|
---|