source: trunk/src/STGrid.cpp @ 2361

Last change on this file since 2361 was 2361, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: No

Interface Changes: Yes

What Interface Changed: Added method to set weight type

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Weighting type can be specified.
Supported types are:

UNIFORM
TINT
TSYS
TINTSYS


File size: 19.5 KB
Line 
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>
9#include <casa/Arrays/ArrayPartMath.h>
10#include <casa/Quanta/Quantum.h>
11#include <casa/Quanta/QuantumHolder.h>
12#include <casa/Utilities/CountedPtr.h>
13#include <casa/Logging/LogIO.h>
14
15#include <tables/Tables/Table.h>
16#include <tables/Tables/TableRecord.h>
17#include <tables/Tables/ExprNode.h>
18#include <tables/Tables/ScalarColumn.h>
19#include <tables/Tables/ArrayColumn.h>
20
21#include <measures/Measures/MDirection.h>
22
23#include <Scantable.h>
24#include "STGrid.h"
25
26using namespace std ;
27using namespace casa ;
28using namespace asap ;
29
30namespace asap {
31
32// constructor
33STGrid::STGrid()
34{
35  init() ;
36}
37
38STGrid::STGrid( const string infile )
39{
40  init() ;
41
42  setFileIn( infile ) ;
43}
44
45void  STGrid::init()
46{
47  nx_ = -1 ;
48  ny_ = -1 ;
49  npol_ = 0 ;
50  nchan_ = 0 ;
51  nrow_ = 0 ;
52  ngrid_ = 0 ;
53  cellx_ = 0.0 ;
54  celly_ = 0.0 ;
55  center_ = Vector<Double> ( 2, 0.0 ) ;
56  convType_ = "BOX" ;
57  wtype_ = "UNIFORM" ;
58  convSupport_ = -1 ;
59  userSupport_ = -1 ;
60  convSampling_ = 100 ;
61}
62
63void STGrid::setFileIn( const string infile )
64{
65  String name( infile ) ;
66  if ( infile_.compare( name ) != 0 ) {
67    infile_ = String( infile ) ;
68    tab_ = Table( infile_ ) ;
69  }
70}
71
72void STGrid::setPolList( vector<unsigned int> pols )
73{
74  //pollist_ = Vector<uInt>( pols ) ;
75  pollist_.assign( Vector<uInt>( pols ) ) ;
76  cout << "pollist_ = " << pollist_ << endl ;
77}
78
79void STGrid::setWeight( const string wType )
80{
81  wtype_ = String( wType ) ;
82  wtype_.upcase() ;
83  cout << "wtype_ = " << wtype_ << endl ;
84}
85
86void STGrid::defineImage( int nx,
87                          int ny,
88                          string scellx,
89                          string scelly,
90                          string scenter )
91{
92  ROArrayColumn<Double> dirCol( tab_, "DIRECTION" ) ;
93  Matrix<Double> direction = dirCol.getColumn() ;
94  Double rmax, rmin, dmax, dmin ;
95  minMax( rmin, rmax, direction.row( 0 ) ) ;
96  minMax( dmin, dmax, direction.row( 1 ) ) ;
97
98  Int npx = (Int)nx ;
99  Int npy = (Int)ny ;
100  String cellx( scellx ) ;
101  String celly( scelly ) ;
102  String center( scenter ) ;
103  setupGrid( npx, npy,
104             cellx, celly,
105             rmin, rmax,
106             dmin, dmax,
107             center ) ;
108}
109 
110void STGrid::setOption( string convType,
111                        int convSupport )
112{
113  convType_ = String( convType ) ;
114  convType_.upcase() ;
115  userSupport_ = (Int)convSupport ;
116}
117
118#define NEED_UNDERSCORES
119#if defined(NEED_UNDERSCORES)
120#define ggridsd ggridsd_
121#endif
122extern "C" {
123   void ggridsd(Double*,
124                const Complex*,
125                Int*,
126                Int*,
127                Int*,
128                const Int*,
129                const Int*,
130                const Float*,
131                Int*,
132                Int*,
133                Complex*,
134                Float*,
135                Int*,
136                Int*,
137                Int *,
138                Int *,
139                Int*,
140                Int*,
141                Float*,
142                Int*,
143                Int*,
144                Double*);
145}
146void STGrid::grid()
147{
148  LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ;
149
150  // retrieve data
151  Cube<Float> spectra ;
152  Matrix<Double> direction ;
153  Cube<uChar> flagtra ;
154  Matrix<uInt> rflag ;
155  Matrix<Float> weight ;
156  getData( infile_, spectra, direction, flagtra, rflag, weight ) ;
157  IPosition sshape = spectra.shape() ;
158  //os << "spectra.shape()=" << spectra.shape() << LogIO::POST ;
159  //os << "max(spectra) = " << max(spectra) << LogIO::POST ;
160  //os << "weight = " << weight << LogIO::POST ;
161
162  // flagtra: uChar -> Int
163  // rflag: uInt -> Int
164  Cube<Int> flagI ;
165  Matrix<Int> rflagI ;
166  toInt( &flagtra, &flagI ) ;
167  toInt( &rflag, &rflagI ) ;
168 
169  // grid parameter
170//   os << "----------" << endl ;
171//   os << "Grid parameter summary" << endl ;
172//   os << "   (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ;
173//   os << "   (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ;
174//   os << "   center = " << center_ << endl ;
175//   os << "----------" << LogIO::POST ;
176
177  // convolution kernel
178  Vector<Float> convFunc ;
179  setConvFunc( convFunc ) ;
180  //cout << "convSupport=" << convSupport_ << endl ;
181  //cout << "convFunc=" << convFunc << endl ;
182
183  // world -> pixel
184  Matrix<Double> xypos( direction.shape(), 0.0 ) ;
185  toPixel( direction, xypos ) ; 
186 
187  // call ggridsd
188  Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ;
189  Double *xypos_p = xypos.getStorage( deletePos ) ;
190  Cube<Complex> dataC( spectra.shape(), 0.0 ) ;
191  setReal( dataC, spectra ) ;
192  const Complex *data_p = dataC.getStorage( deleteData ) ;
193  const Float *wgt_p = weight.getStorage( deleteWgt ) ;
194  const Int *flag_p = flagI.getStorage( deleteFlag ) ;
195  const Int *rflag_p = rflagI.getStorage( deleteFlagR ) ;
196  Float *conv_p = convFunc.getStorage( deleteConv ) ;
197  // Extend grid plane with convSupport_
198  //IPosition gshape( 4, nx_, ny_, npol, nchan ) ;
199  Int gnx = nx_+convSupport_*2 ;
200  Int gny = ny_+convSupport_*2 ;
201  IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
202  Array<Complex> gdataArrC( gshape, 0.0 ) ;
203  Array<Float> gwgtArr( gshape, 0.0 ) ;
204  Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ;
205  Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ;
206  Int idopsf = 0 ;
207  Int irow = -1 ;
208  Int *chanMap = new Int[nchan_] ;
209  {
210    Int *work_p = chanMap ;
211    for ( Int i = 0 ; i < nchan_ ; i++ ) {
212      *work_p = i ;
213      work_p++ ;
214    }
215  }
216  Int *polMap = new Int[npol_] ;
217  {
218    Int *work_p = polMap ;
219    for ( Int i = 0 ; i < npol_ ; i++ ) {
220      *work_p = i ;
221      work_p++ ;
222    }
223  }
224  Double *sumw_p = new Double[npol_*nchan_] ;
225  {
226    Double *work_p = sumw_p ;
227    for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) {
228      *work_p = 0.0 ;
229      work_p++ ;
230    }
231  }
232  ggridsd( xypos_p,
233           data_p,
234           &npol_,
235           &nchan_,
236           &idopsf,
237           flag_p,
238           rflag_p,
239           wgt_p,
240           &nrow_,
241           &irow,
242           gdata_p,
243           wdata_p,
244           &gnx,
245           &gny,
246           &npol_,
247           &nchan_,
248           &convSupport_,
249           &convSampling_,
250           conv_p,
251           chanMap,
252           polMap,
253           sumw_p ) ;
254  xypos.putStorage( xypos_p, deletePos ) ;
255  dataC.freeStorage( data_p, deleteData ) ;
256  weight.freeStorage( wgt_p, deleteWgt ) ;
257  flagI.freeStorage( flag_p, deleteFlag ) ;
258  rflagI.freeStorage( rflag_p, deleteFlagR ) ;
259  convFunc.putStorage( conv_p, deleteConv ) ;
260  delete polMap ;
261  delete chanMap ;
262  gdataArrC.putStorage( gdata_p, deleteDataG ) ;
263  gwgtArr.putStorage( wdata_p, deleteWgtG ) ;
264  Array<Float> gdataArr = real( gdataArrC ) ;
265  data_.resize( gdataArr.shape() ) ;
266  data_ = 0.0 ;
267  for ( Int ix = 0 ; ix < nx_ ; ix++ ) {
268    for ( Int iy = 0 ; iy < ny_ ; iy++ ) {
269      for ( Int ip = 0 ; ip < npol_ ; ip++ ) {
270        for ( Int ic = 0 ; ic < nchan_ ; ic++ ) {
271          IPosition pos( 4, ix, iy, ip, ic ) ;
272          IPosition gpos( 4, ix+convSupport_, iy+convSupport_, ip, ic ) ;
273          if ( gwgtArr( gpos ) > 0.0 )
274            data_( pos ) = gdataArr( gpos ) / gwgtArr( gpos ) ;
275        }
276      }
277    }
278  }
279  //Matrix<Double> sumWeight( IPosition( 2, npol_, nchan_ ), sumw_p, TAKE_OVER ) ;
280  delete sumw_p ;
281  //cout << "sumWeight = " << sumWeight << endl ;
282  //cout << "gdataArr = " << gdataArr << endl ;
283  //cout << "gwgtArr = " << gwgtArr << endl ;
284  //cout << "data_ " << data_ << endl ;
285}
286
287void STGrid::setupGrid( Int &nx,
288                        Int &ny,
289                        String &cellx,
290                        String &celly,
291                        Double &xmin,
292                        Double &xmax,
293                        Double &ymin,
294                        Double &ymax,
295                        String &center )
296{
297  //cout << "nx=" << nx << ", ny=" << ny << endl ;
298
299  // center position
300  if ( center.size() == 0 ) {
301    center_(0) = 0.5 * ( xmin + xmax ) ;
302    center_(1) = 0.5 * ( ymin + ymax ) ;
303  }
304  else {
305    String::size_type pos0 = center.find( " " ) ;
306    if ( pos0 == String::npos ) {
307      throw AipsError( "bad string format in parameter center" ) ;
308    }
309    String::size_type pos1 = center.find( " ", pos0+1 ) ;
310    String typestr, xstr, ystr ;
311    if ( pos1 != String::npos ) {
312      typestr = center.substr( 0, pos0 ) ;
313      xstr = center.substr( pos0+1, pos1-pos0 ) ;
314      ystr = center.substr( pos1+1 ) ;
315      // todo: convert to J2000 (or direction ref for DIRECTION column)
316    }
317    else {
318      typestr = "J2000" ;
319      xstr = center.substr( 0, pos0 ) ;
320      ystr = center.substr( pos0+1 ) ;
321    }
322    QuantumHolder qh ;
323    String err ;
324    qh.fromString( err, xstr ) ;
325    Quantum<Double> xcen = qh.asQuantumDouble() ;
326    qh.fromString( err, ystr ) ;
327    Quantum<Double> ycen = qh.asQuantumDouble() ;
328    center_(0) = xcen.getValue( "rad" ) ;
329    center_(1) = ycen.getValue( "rad" ) ;
330  }
331
332
333  //Double wx = xmax - xmin ;
334  //Double wy = ymax - ymin ;
335  Double wx = max( abs(xmax-center_(0)), abs(xmin-center_(0)) ) * 2 ;
336  Double wy = max( abs(ymax-center_(1)), abs(ymin-center_(1)) ) * 2 ;
337  // take 10% margin
338  wx *= 1.10 ;
339  wy *= 1.10 ;
340  Quantum<Double> qcellx ;
341  Quantum<Double> qcelly ;
342  nx_ = nx ;
343  ny_ = ny ;
344  if ( nx < 0 && ny > 0 ) {
345    nx_ = ny ;
346    ny_ = ny ;
347  }
348  if ( ny < 0 && nx > 0 ) {
349    nx_ = nx ;
350    ny_ = nx ;
351  }
352  //cout << "nx_ = " << nx_ << ",  ny_ = " << ny_ << endl ;
353  if ( cellx.size() != 0 && celly.size() != 0 ) {
354    readQuantity( qcellx, cellx ) ;
355    readQuantity( qcelly, celly ) ;
356  }
357  else if ( celly.size() != 0 ) {
358    cout << "Using celly to x-axis..." << endl ;
359    readQuantity( qcelly, celly ) ;
360    qcellx = qcelly ;
361  }
362  else if ( cellx.size() != 0 ) {
363    cout << "Using cellx to y-axis..." << endl ;
364    readQuantity( qcellx, cellx ) ;
365    qcelly = qcellx ;
366  }
367  else {
368    if ( nx_ < 0 ) {
369      cout << "No user preference in grid setting. Using default..." << endl ;
370      readQuantity( qcellx, "1.0arcmin" ) ;
371      qcelly = qcellx ;
372    }
373    else {
374      qcellx = Quantum<Double>( wx/nx_, "rad" ) ;
375      qcelly = Quantum<Double>( wy/ny_, "rad" ) ;
376    }
377  }
378  cellx_ = qcellx.getValue( "rad" ) ;
379  celly_ = qcelly.getValue( "rad" ) ;
380  if ( nx_ < 0 ) {
381    nx_ = Int( ceil( wx/cellx_ ) ) ;
382    ny_ = Int( ceil( wy/celly_ ) ) ;
383  }
384}
385
386void STGrid::getData( String &infile,
387                      Cube<Float> &spectra,
388                      Matrix<Double> &direction,
389                      Cube<uChar> &flagtra,
390                      Matrix<uInt> &rflag,
391                      Matrix<Float> &weight )
392{
393  Table tab( infile ) ;
394  //uInt npol = tab.keywordSet().asuInt( "nPol" ) ;
395  ROScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
396  //uInt npol = max( polnoCol.getColumn() ) + 1 ;
397  Vector<uInt> pols = polnoCol.getColumn() ;
398  Vector<uInt> pollistOrg ;
399  uInt npolOrg = 0 ;
400  for ( uInt i = 0 ; i < pols.size() ; i++ ) {
401    if ( allNE( pollistOrg, pols[i] ) ) {
402      pollistOrg.resize( npolOrg+1, True ) ;
403      pollistOrg[npolOrg] = pols[i] ;
404      npolOrg++ ;
405    }
406  }
407  if ( pollist_.size() == 0 )
408    pollist_ = pollistOrg ;
409  else {
410    Vector<uInt> newlist ;
411    uInt newsize = 0 ;
412    for ( uInt i = 0 ; i < pollist_.size() ; i++ ) {
413      if ( anyEQ( pols, pollist_[i] ) ) {
414        newlist.resize( newsize+1, True ) ;
415        newlist[newsize] = pollist_[i] ;
416        newsize++ ;
417      }
418    }
419    pollist_ = newlist ;
420  }
421  npol_ = pollist_.size() ;
422  ROArrayColumn<uChar> tmpCol( tab, "FLAGTRA" ) ;
423  nchan_ = tmpCol( 0 ).nelements() ;
424  nrow_ = tab.nrow() / npolOrg ;
425//   cout << "npol_ = " << npol_ << endl ;
426//   cout << "nchan_ = " << nchan_ << endl ;
427//   cout << "nrow_ = " << nrow_ << endl ;
428  spectra.resize( npol_, nchan_, nrow_ ) ;
429  flagtra.resize( npol_, nchan_, nrow_ ) ;
430  rflag.resize( npol_, nrow_ ) ;
431  Cube<Float> tsys( npol_, nchan_, nrow_ ) ;
432  Matrix<Double> tint( npol_, nrow_ ) ;
433  for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
434    Table subt = tab( tab.col("POLNO") == pollist_[ipol] ) ;
435    ROArrayColumn<Float> spectraCol( subt, "SPECTRA" ) ;
436    ROArrayColumn<Double> directionCol( subt, "DIRECTION" ) ;
437    ROArrayColumn<uChar> flagtraCol( subt, "FLAGTRA" ) ;
438    ROScalarColumn<uInt> rflagCol( subt, "FLAGROW" ) ;
439    ROArrayColumn<Float> tsysCol( subt, "TSYS" ) ;
440    ROScalarColumn<Double> tintCol( subt, "INTERVAL" ) ;
441    Matrix<Float> tmpF = spectra.yzPlane( ipol ) ;
442    Matrix<uChar> tmpUC = flagtra.yzPlane( ipol ) ;
443    Vector<uInt> tmpUI = rflag.row( ipol ) ;
444    spectraCol.getColumn( tmpF ) ;
445    flagtraCol.getColumn( tmpUC ) ;
446    rflagCol.getColumn( tmpUI ) ;
447    if ( ipol == 0 )
448      directionCol.getColumn( direction ) ;
449    Matrix<Float> tmpF2 = tsysCol.getColumn() ;
450    Vector<Double> tmpD = tint.row( ipol ) ;
451    if ( tmpF2.shape()(0) == nchan_ ) {
452      tsys.yzPlane( ipol ) = tmpF2 ;
453    }
454    else {
455      tsys.yzPlane( ipol ) = tmpF2(0,0) ;
456    }
457    tintCol.getColumn( tmpD ) ;
458  }
459
460  getWeight( weight, tsys, tint ) ;
461}
462
463void STGrid::getWeight( Matrix<Float> &w,
464                        Cube<Float> &tsys,
465                        Matrix<Double> &tint )
466{
467  // resize
468  w.resize( nchan_, nrow_ ) ;
469
470  // set weight
471  w = 1.0 ;
472  Bool warn = False ;
473  if ( wtype_.compare( "UNIFORM" ) == 0 ) {
474    // do nothing
475  }
476  else if ( wtype_.compare( "TINT" ) == 0 ) {
477    if ( npol_ > 1 ) warn = True ;
478    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
479      Float val = mean( tint.column( irow ) ) ;
480      w.column( irow ) = w.column( irow ) *  val ;
481    }
482  }
483  else if ( wtype_.compare( "TSYS" ) == 0 ) {
484    if ( npol_ > 1 ) warn = True ;
485    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
486      Matrix<Float> arr = tsys.xyPlane( irow ) ;
487      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
488        Float val = mean( arr.column( ichan ) ) ;
489        w(ichan,irow) = w(ichan,irow) / ( val * val ) ;
490      }
491    }
492  }
493  else if ( wtype_.compare( "TINTSYS" ) == 0 ) {
494    if ( npol_ > 1 ) warn = True ;
495    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
496      Float interval = mean( tint.column( irow ) ) ;
497      Matrix<Float> arr = tsys.xyPlane( irow ) ;
498      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
499        Float temp = mean( arr.column( ichan ) ) ;
500        w(ichan,irow) = w(ichan,irow) * interval / ( temp * temp ) ;
501      }
502    }
503  }
504  else {
505    LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
506    os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
507  }
508
509  if ( npol_ > 1 ) {
510    LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
511    os << LogIO::WARN << "STGrid doesn't support assigning independent polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ;
512  }
513}
514
515void STGrid::toInt( Array<uChar> *u, Array<Int> *v )
516{
517  uInt len = u->nelements() ;
518  Int *int_p = new Int[len] ;
519  Bool deleteIt ;
520  const uChar *data_p = u->getStorage( deleteIt ) ;
521  Int *i_p = int_p ;
522  const uChar *u_p = data_p ;
523  for ( uInt i = 0 ; i < len ; i++ ) {
524    *i_p = ( *u_p == 0 ) ? 0 : 1 ;
525    i_p++ ;
526    u_p++ ;
527  }
528  u->freeStorage( data_p, deleteIt ) ;
529  v->takeStorage( u->shape(), int_p, TAKE_OVER ) ;
530}
531
532void STGrid::toInt( Array<uInt> *u, Array<Int> *v )
533{
534  uInt len = u->nelements() ;
535  Int *int_p = new Int[len] ;
536  Bool deleteIt ;
537  const uInt *data_p = u->getStorage( deleteIt ) ;
538  Int *i_p = int_p ;
539  const uInt *u_p = data_p ;
540  for ( uInt i = 0 ; i < len ; i++ ) {
541    *i_p = ( *u_p == 0 ) ? 0 : 1 ;
542    i_p++ ;
543    u_p++ ;
544  }
545  u->freeStorage( data_p, deleteIt ) ;
546  v->takeStorage( u->shape(), int_p, TAKE_OVER ) ;
547}
548
549void STGrid::toPixel( Matrix<Double> &world, Matrix<Double> &pixel )
550{
551  // gridding will be done on (nx_+2*convSupport_) x (ny_+2*convSupport_)
552  // grid plane to avoid unexpected behavior on grid edge
553  Vector<Double> pixc( 2 ) ;
554  //pixc(0) = Double( nx_-1 ) * 0.5 ;
555  //pixc(1) = Double( ny_-1 ) * 0.5 ;
556  pixc(0) = Double( nx_+2*convSupport_-1 ) * 0.5 ;
557  pixc(1) = Double( ny_+2*convSupport_-1 ) * 0.5 ;
558  uInt nrow = world.shape()[1] ;
559  Vector<Double> cell( 2 ) ;
560  cell(0) = cellx_ ;
561  cell(1) = celly_ ;
562  //ofstream ofs( "grid.dat", ios::out ) ;
563  for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
564    //ofs << irow ;
565    for ( uInt i = 0 ; i < 2 ; i++ ) {
566      pixel( i, irow ) = pixc(i) + ( world(i, irow) - center_(i) ) / cell(i) ;
567      //ofs << " " << world(i, irow) << " " << pixel(i, irow) ;
568    }
569    //ofs << endl ;
570  }
571  //ofs.close() ;
572}
573
574void STGrid::boxFunc( Vector<Float> &convFunc, Int &convSize )
575{
576  convFunc = 0.0 ;
577  for ( Int i = 0 ; i < convSize/2 ; i++ )
578    convFunc(i) = 1.0 ;
579}
580
581#define NEED_UNDERSCORES
582#if defined(NEED_UNDERSCORES)
583#define grdsf grdsf_
584#endif
585extern "C" {
586   void grdsf(Double*, Double*);
587}
588void STGrid::spheroidalFunc( Vector<Float> &convFunc )
589{
590  convFunc = 0.0 ;
591  for ( Int i = 0 ; i < convSampling_*convSupport_ ; i++ ) {
592    Double nu = Double(i) / Double(convSupport_*convSampling_) ;
593    Double val ;
594    grdsf( &nu, &val ) ;
595    convFunc(i) = ( 1.0 - nu * nu ) * val ;
596  }
597}
598
599void STGrid::gaussFunc( Vector<Float> &convFunc )
600{
601  convFunc = 0.0 ;
602  for ( Int i = 0 ; i < convSampling_*convSupport_ ; i++ ) {
603    Double hwhm = convSampling_ * convSupport_ * 0.25 ;
604    Double val = Double(i) / hwhm ;
605    convFunc(i) = exp( -log(2)*val*val ) ;
606  }
607}
608
609void STGrid::pbFunc( Vector<Float> &convFunc )
610{
611  convFunc = 0.0 ;
612}
613
614void STGrid::setConvFunc( Vector<Float> &convFunc )
615{
616  convSupport_ = userSupport_ ;
617  if ( convType_ == "BOX" ) {
618    if ( convSupport_ < 0 )
619      convSupport_ = 0 ;
620    Int convSize = convSampling_ * ( 2 * convSupport_ + 2 )  ;
621    convFunc.resize( convSize ) ;
622    boxFunc( convFunc, convSize ) ;
623  }
624  else if ( convType_ == "SF" ) {
625    if ( convSupport_ < 0 )
626      convSupport_ = 3 ;
627    Int convSize = convSampling_ * ( 2 * convSupport_ + 2 )  ;
628    convFunc.resize( convSize ) ;
629    spheroidalFunc( convFunc ) ;
630  }
631  else if ( convType_ == "GAUSS" ) {
632    if ( convSupport_ < 0 )
633      convSupport_ = 3 ;
634    Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ;
635    convFunc.resize( convSize ) ;
636    gaussFunc( convFunc ) ;
637  }
638  else if ( convType_ == "PB" ) {
639    if ( convSupport_ < 0 )
640      convSupport_ = 0 ;
641    pbFunc( convFunc ) ;
642  }
643  else {
644    throw AipsError( "Unsupported convolution function" ) ;
645  }
646}
647
648string STGrid::saveData( string outfile )
649{
650  //Int polno = 0 ;
651  string outfile_ ;
652  if ( outfile.size() == 0 ) {
653    if ( infile_.lastchar() == '/' ) {
654      outfile_ = infile_.substr( 0, infile_.size()-1 ) ;
655    }
656    else {
657      outfile_ = infile_ ;
658    }
659    outfile_ += ".grid" ;
660  }
661  else {
662    outfile_ = outfile ;
663  }
664  CountedPtr<Scantable> ref( new Scantable( infile_, Table::Memory ) ) ;
665  //cout << "ref->nchan()=" << ref->nchan() << endl ;
666  CountedPtr<Scantable> out( new Scantable( *ref, True ) ) ;
667  Table tab = out->table() ;
668  IPosition dshape = data_.shape() ;
669  //Int npol = dshape[2] ;
670  //Int nchan = dshape[3] ;
671  Int nrow = nx_ * ny_ * npol_ ;
672  tab.rwKeywordSet().define( "nPol", npol_ ) ;
673  tab.addRow( nrow ) ;
674  Vector<Double> cpix( 2 ) ;
675  cpix(0) = Double( nx_ - 1 ) * 0.5 ;
676  cpix(1) = Double( ny_ - 1 ) * 0.5 ;
677  Vector<Double> dir( 2 ) ;
678  ArrayColumn<Double> directionCol( tab, "DIRECTION" ) ;
679  ArrayColumn<Float> spectraCol( tab, "SPECTRA" ) ;
680  ScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
681  Int irow = 0 ;
682  for ( Int iy = 0 ; iy < ny_ ; iy++ ) {
683    for ( Int ix = 0 ; ix < nx_ ; ix++ ) {
684      for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
685        IPosition start( 4, ix, iy, ipol, 0 ) ;
686        IPosition end( 4, ix, iy, ipol, nchan_-1 ) ;
687        IPosition inc( 4, 1, 1, 1, 1 ) ;
688        Vector<Float> sp = data_( start, end, inc ) ;
689        dir(0) = center_(0) - ( cpix(0) - (Double)ix ) * cellx_ ;
690        dir(1) = center_(1) - ( cpix(1) - (Double)iy ) * celly_ ;
691        spectraCol.put( irow, sp ) ;
692        directionCol.put( irow, dir ) ;
693        polnoCol.put( irow, pollist_[ipol] ) ;
694        irow++ ;
695      }
696    }
697  }
698  //cout << "outfile_=" << outfile_ << endl ;
699  out->makePersistent( outfile_ ) ;
700 
701  return outfile_ ;
702}
703
704}
Note: See TracBrowser for help on using the repository browser.