Changeset 2094


Ignore:
Timestamp:
04/01/11 21:36:20 (13 years ago)
Author:
WataruKawasaki
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): Scantable

Description: minor bugfix/cleanup.


Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2081 r2094  
    20732073                          clipthresh=None, clipniter=None, plot=None, getresidual=None, outlog=None, blfile=None):
    20742074        """\
    2075         Return a scan which has been baselined (all rows) by sinusoidal functions.
     2075        Return a scan which has been baselined (all rows) with sinusoidal functions.
    20762076        Parameters:
    20772077            insitu:        If False a new scantable is returned.
     
    21662166                               chan_avg_limit=None, plot=None, getresidual=None, outlog=None, blfile=None):
    21672167        """\
    2168         Return a scan which has been baselined (all rows) by cubic spline
    2169         function (piecewise cubic polynomial).
     2168        Return a scan which has been baselined (all rows) with sinusoidal functions.
    21702169        Spectral lines are detected first using linefinder and masked out
    21712170        to avoid them affecting the baseline solution.
     
    23092308
    23102309    @asaplog_post_dec
    2311     def cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, plot=None, outlog=None, blfile=None):
     2310    def cspline_baseline(self, insitu=None, mask=None, npiece=None,
     2311                         clipthresh=None, clipniter=None, plot=None, getresidual=None, outlog=None, blfile=None):
    23122312        """\
    23132313        Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial).
     
    23242324                        indivual fit has to be approved, by typing 'y'
    23252325                        or 'n'
     2326            getresidual:if False, returns best-fit values instead of
     2327                        residual. (default is True)
    23262328            outlog:     Output the coefficients of the best-fit
    23272329                        function to logger (default is False)
     
    23502352        nchan = workscan.nchan()
    23512353       
    2352         if mask is None: mask = [True for i in xrange(nchan)]
    2353         if npiece is None: npiece = 2
    2354         if clipthresh is None: clipthresh = 3.0
    2355         if clipniter is None: clipniter = 1
    2356         if plot is None: plot = False
    2357         if outlog is None: outlog = False
    2358         if blfile is None: blfile = ""
     2354        if mask        is None: mask        = [True for i in xrange(nchan)]
     2355        if npiece      is None: npiece      = 2
     2356        if clipthresh  is None: clipthresh  = 3.0
     2357        if clipniter   is None: clipniter   = 1
     2358        if plot        is None: plot        = False
     2359        if getresidual is None: getresidual = True
     2360        if outlog      is None: outlog      = False
     2361        if blfile      is None: blfile      = ""
    23592362
    23602363        outblfile = (blfile != "") and os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
     
    23622365        try:
    23632366            #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method.
    2364             workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, outlog, blfile)
     2367            workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, getresidual, outlog, blfile)
    23652368           
    23662369            workscan._add_history("cspline_baseline", varlist)
     
    23832386    def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None,
    23842387                              clipniter=None, edge=None, threshold=None,
    2385                               chan_avg_limit=None, plot=None, outlog=None, blfile=None):
     2388                              chan_avg_limit=None, getresidual=None, plot=None, outlog=None, blfile=None):
    23862389        """\
    23872390        Return a scan which has been baselined (all rows) by cubic spline
     
    24232426                        indivual fit has to be approved, by typing 'y'
    24242427                        or 'n'
     2428            getresidual:if False, returns best-fit values instead of
     2429                        residual. (default is True)
    24252430            outlog:     Output the coefficients of the best-fit
    24262431                        function to logger (default is False)
     
    24472452        nchan = workscan.nchan()
    24482453       
    2449         if mask is None: mask = [True for i in xrange(nchan)]
    2450         if npiece is None: npiece = 2
    2451         if clipthresh is None: clipthresh = 3.0
    2452         if clipniter is None: clipniter = 1
    2453         if edge is None: edge = (0, 0)
    2454         if threshold is None: threshold = 3
     2454        if mask           is None: mask          = [True for i in xrange(nchan)]
     2455        if npiece         is None: npiece        = 2
     2456        if clipthresh     is None: clipthresh    = 3.0
     2457        if clipniter      is None: clipniter      = 1
     2458        if edge           is None: edge          = (0, 0)
     2459        if threshold      is None: threshold      = 3
    24552460        if chan_avg_limit is None: chan_avg_limit = 1
    2456         if plot is None: plot = False
    2457         if outlog is None: outlog = False
    2458         if blfile is None: blfile = ""
     2461        if plot           is None: plot           = False
     2462        if getresidual    is None: getresidual    = True
     2463        if outlog         is None: outlog         = False
     2464        if blfile         is None: blfile         = ""
    24592465
    24602466        outblfile = (blfile != "") and os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
     
    24912497                    curedge += edge[i]
    24922498               
    2493             workscan._auto_cspline_baseline(mask, npiece, clipthresh, clipniter, curedge, threshold, chan_avg_limit, outlog, blfile)
     2499            workscan._auto_cspline_baseline(mask, npiece, clipthresh, clipniter, curedge, threshold, chan_avg_limit, getresidual, outlog, blfile)
    24942500
    24952501            workscan._add_history("auto_cspline_baseline", varlist)
     
    25112517
    25122518    @asaplog_post_dec
    2513     def poly_baseline(self, insitu=None, mask=None, order=None, plot=None, outlog=None, blfile=None):
     2519    def poly_baseline(self, insitu=None, mask=None, order=None, plot=None, getresidual=None, outlog=None, blfile=None):
    25142520        """\
    25152521        Return a scan which has been baselined (all rows) by a polynomial.
     
    25232529                        indivual fit has to be approved, by typing 'y'
    25242530                        or 'n'
     2531            getresidual:if False, returns best-fit values instead of
     2532                        residual. (default is True)
    25252533            outlog:     Output the coefficients of the best-fit
    25262534                        function to logger (default is False)
     
    25452553        nchan = workscan.nchan()
    25462554       
    2547         if mask is None: mask = [True for i in xrange(nchan)]
    2548         if order is None: order = 0
    2549         if plot is None: plot = False
    2550         if outlog is None: outlog = False
    2551         if blfile is None: blfile = ""
     2555        if mask        is None: mask        = [True for i in xrange(nchan)]
     2556        if order       is None: order       = 0
     2557        if plot        is None: plot        = False
     2558        if getresidual is None: getresidual = True
     2559        if outlog      is None: outlog      = False
     2560        if blfile      is None: blfile      = ""
    25522561
    25532562        outblfile = (blfile != "") and os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
     
    25792588                    masklist = workscan.get_masklist(f.mask, row=r, silent=True)
    25802589                    #workscan._append_blinfo(blpars, masklist, f.mask)
    2581                     workscan._setspectrum(f.fitter.getresidual(), r)
     2590                    workscan._setspectrum((f.fitter.getresidual() if getresidual else f.fitter.getfit()), r)
    25822591                   
    25832592                    if outblfile:
     
    25912600                if outblfile: blf.close()
    25922601            else:
    2593                 workscan._poly_baseline(mask, order, outlog, blfile)
     2602                workscan._poly_baseline(mask, order, getresidual, outlog, blfile)
    25942603           
    25952604            workscan._add_history("poly_baseline", varlist)
     
    26112620
    26122621    def auto_poly_baseline(self, insitu=None, mask=None, order=None, edge=None, threshold=None,
    2613                            chan_avg_limit=None, plot=None, outlog=None, blfile=None):
     2622                           chan_avg_limit=None, plot=None, getresidual=None, outlog=None, blfile=None):
    26142623        """\
    26152624        Return a scan which has been baselined (all rows) by a polynomial.
     
    26472656                        indivual fit has to be approved, by typing 'y'
    26482657                        or 'n'
     2658            getresidual:if False, returns best-fit values instead of
     2659                        residual. (default is True)
    26492660            outlog:     Output the coefficients of the best-fit
    26502661                        function to logger (default is False)
     
    26672678        nchan = workscan.nchan()
    26682679       
    2669         if mask is None: mask = [True for i in xrange(nchan)]
    2670         if order is None: order = 0
    2671         if edge is None: edge = (0, 0)
    2672         if threshold is None: threshold = 3
     2680        if mask           is None: mask          = [True for i in xrange(nchan)]
     2681        if order          is None: order          = 0
     2682        if edge           is None: edge          = (0, 0)
     2683        if threshold      is None: threshold      = 3
    26732684        if chan_avg_limit is None: chan_avg_limit = 1
    2674         if plot is None: plot = False
    2675         if outlog is None: outlog = False
    2676         if blfile is None: blfile = ""
     2685        if plot           is None: plot           = False
     2686        if getresidual    is None: getresidual    = True
     2687        if outlog         is None: outlog         = False
     2688        if blfile         is None: blfile         = ""
    26772689
    26782690        outblfile = (blfile != "") and os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
     
    27412753                    masklist = workscan.get_masklist(f.mask, row=r, silent=True)
    27422754                    #workscan._append_blinfo(blpars, masklist, f.mask)
    2743                     workscan._setspectrum(f.fitter.getresidual(), r)
     2755                    workscan._setspectrum((f.fitter.getresidual() if getresidual else f.fitter.getfit()), r)
    27442756
    27452757                    if outblfile:
     
    27592771                        curedge += edge[i]
    27602772               
    2761                 workscan._auto_poly_baseline(mask, order, curedge, threshold, chan_avg_limit, outlog, blfile)
     2773                workscan._auto_poly_baseline(mask, order, curedge, threshold, chan_avg_limit, getresidual, outlog, blfile)
    27622774
    27632775            workscan._add_history("auto_poly_baseline", varlist)
  • trunk/src/Scantable.cpp

    r2084 r2094  
    17751775}
    17761776
    1777 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool outLogger, const std::string& blfile)
     1777void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool getResidual, bool outLogger, const std::string& blfile)
    17781778{
    17791779  ofstream ofs;
     
    18031803    chanMask = getCompositeChanMask(whichrow, mask);
    18041804    fitBaseline(chanMask, whichrow, fitter);
    1805     setSpectrum(fitter.getResidual(), whichrow);
     1805    setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    18061806    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);
    18071807  }
     
    18101810}
    18111811
    1812 void Scantable::autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool outLogger, const std::string& blfile)
     1812void Scantable::autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, bool outLogger, const std::string& blfile)
    18131813{
    18141814  ofstream ofs;
     
    18641864
    18651865    fitBaseline(chanMask, whichrow, fitter);
    1866     setSpectrum(fitter.getResidual(), whichrow);
     1866    setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    18671867
    18681868    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);
     
    18721872}
    18731873
    1874 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool outLogger, const std::string& blfile)
     1874void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, bool outLogger, const std::string& blfile)
    18751875{
    18761876  ofstream ofs;
     
    19001900    chanMask = getCompositeChanMask(whichrow, mask);
    19011901    //fitBaseline(chanMask, whichrow, fitter);
    1902     //setSpectrum(fitter.getResidual(), whichrow);
     1902    //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    19031903    std::vector<int> pieceEdges;
    19041904    std::vector<float> params;
    1905     std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, thresClip, nIterClip, true);
     1905    std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, thresClip, nIterClip, getResidual);
    19061906    setSpectrum(res, whichrow);
    19071907    //
     
    19131913}
    19141914
    1915 void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool outLogger, const std::string& blfile)
     1915void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, bool outLogger, const std::string& blfile)
    19161916{
    19171917  ofstream ofs;
     
    19681968
    19691969    //fitBaseline(chanMask, whichrow, fitter);
    1970     //setSpectrum(fitter.getResidual(), whichrow);
     1970    //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    19711971    std::vector<int> pieceEdges;
    19721972    std::vector<float> params;
    1973     std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, thresClip, nIterClip, true);
     1973    std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, thresClip, nIterClip, getResidual);
    19741974    setSpectrum(res, whichrow);
    19751975    //
     
    19871987  }
    19881988  if (nPiece < 1) {
    1989     throw(AipsError("wrong number of the sections for fitting"));
     1989    throw(AipsError("number of the sections must be one or more"));
    19901990  }
    19911991
     
    22292229    chanMask = getCompositeChanMask(whichrow, mask);
    22302230    //fitBaseline(chanMask, whichrow, fitter);
    2231     //setSpectrum(fitter.getResidual(), whichrow);
     2231    //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    22322232    std::vector<float> params;
    2233     //std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, params, thresClip, nIterClip, true);
    22342233    std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, maxWaveLength, params, thresClip, nIterClip, getResidual);
    22352234    setSpectrum(res, whichrow);
     
    22972296
    22982297    //fitBaseline(chanMask, whichrow, fitter);
    2299     //setSpectrum(fitter.getResidual(), whichrow);
     2298    //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    23002299    std::vector<float> params;
    23012300    std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, maxWaveLength, params, thresClip, nIterClip, getResidual);
     
    23492348
    23502349  const double PI = 6.0 * asin(0.5); // PI (= 3.141592653...)
    2351   double baseXFactor = 2.0*PI/(double)maxWaveLength/(double)(nChan-1);  //the denominator (nChan-1) should be changed to (xdata[nChan-1]-xdata[0]) for accepting x-values given in velocity or frequency when this function is moved to fitter.
     2350  double baseXFactor = 2.0*PI/(double)maxWaveLength/(double)(nChan-1);  //the denominator (nChan-1) should be changed to (xdata[nChan-1]-xdata[0]) for accepting x-values given in velocity or frequency when this function is moved to fitter. (2011/03/30 WK)
    23522351
    23532352  // xArray : contains elemental values for computing the least-square matrix.
     
    26492648
    26502649  if (verbose) {
    2651     for (int i = 0; i < 60; ++i) {
    2652       oss << "-";
    2653     }
    2654     oss << endl;
    26552650    oss <<  " Scan[" << getScan(whichrow)  << "]";
    26562651    oss <<  " Beam[" << getBeam(whichrow)  << "]";
     
    26732668    oss << "Results of baseline fit" << endl;
    26742669    oss << "  rms = " << setprecision(6) << rms << endl;
     2670    for (int i = 0; i < 60; ++i) {
     2671      oss << "-";
     2672    }
     2673    oss << flush;
    26752674  }
    26762675
  • trunk/src/Scantable.h

    r2081 r2094  
    497497  void polyBaseline(const std::vector<bool>& mask,
    498498                    int order,
     499                    bool getResidual=true,
    499500                    bool outLogger=false,
    500501                    const std::string& blfile="");
     
    504505                        float threshold=3.0,
    505506                        int chanAvgLimit=1,
     507                        bool getResidual=true,
    506508                        bool outLogger=false,
    507509                        const std::string& blfile="");
     
    510512                           float thresClip,
    511513                           int nIterClip,
     514                           bool getResidual=true,
    512515                           bool outLogger=false,
    513516                           const std::string& blfile="");
     
    519522                               float threshold=3.0,
    520523                               int chanAvgLimit=1,
     524                               bool getResidual=true,
    521525                               bool outLogger=false,
    522526                               const std::string& blfile="");
     
    679683                                          float thresClip=3.0,
    680684                                          int nIterClip=1,
    681                                           bool getResidual=false);
     685                                          bool getResidual=true);
    682686  std::vector<float> doSinusoidFitting(const std::vector<float>& data,
    683687                                       const std::vector<bool>& mask,
     
    687691                                       float thresClip=3.0,
    688692                                       int nIterClip=1,
    689                                        bool getResidual=false);
     693                                       bool getResidual=true);
    690694  bool hasSameNchanOverIFs();
    691695  std::string getMaskRangeList(const std::vector<bool>& mask,
  • trunk/src/ScantableWrapper.h

    r2081 r2094  
    257257  { table_->reshapeSpectrum( nmin, nmax ); }
    258258
    259   void polyBaseline(const std::vector<bool>& mask, int order, bool outlog=false, const std::string& blfile="")
    260   { table_->polyBaseline(mask, order, outlog, blfile); }
    261 
    262   void autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool outlog=false, const std::string& blfile="")
    263   { table_->autoPolyBaseline(mask, order, edge, threshold, chan_avg_limit, outlog, blfile); }
    264 
    265   void cubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, bool outlog=false, const std::string& blfile="")
    266   { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, outlog, blfile); }
    267 
    268   void autoCubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool outlog=false, const std::string& blfile="")
    269   { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, outlog, blfile); }
     259  void polyBaseline(const std::vector<bool>& mask, int order, bool getresidual=true, bool outlog=false, const std::string& blfile="")
     260  { table_->polyBaseline(mask, order, getresidual, outlog, blfile); }
     261
     262  void autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, bool outlog=false, const std::string& blfile="")
     263  { table_->autoPolyBaseline(mask, order, edge, threshold, chan_avg_limit, getresidual, outlog, blfile); }
     264
     265  void cubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, bool getresidual=true, bool outlog=false, const std::string& blfile="")
     266  { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, outlog, blfile); }
     267
     268  void autoCubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, bool outlog=false, const std::string& blfile="")
     269  { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, outlog, blfile); }
    270270
    271271  void sinusoidBaseline(const std::vector<bool>& mask, const std::vector<int>& nwave, float maxwavelength, float clipthresh, int clipniter, bool getresidual=true, bool outlog=false, const std::string& blfile="")
Note: See TracChangeset for help on using the changeset viewer.