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