Changeset 2435 for trunk


Ignore:
Timestamp:
03/15/12 15:25:45 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-2818)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: Added methods and functions
scantable.regrid_channel, scantable._regrid_specchan (defined in python_Scantable.cpp),
Scantable::regridSpecChannel, and ScantableWrapper::regridSpecChannel

Test Programs: comming soon with sdsmooth

Put in Release Notes: No

Module(s): scantable

Description:

Enabled regridding of spectra in a scantable.

scantable.regrid_channel(width, insitu=True/False)

will do this.
width can be either in channel, frequency, or velocity unit.
verification is not available yet.


Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2431 r2435  
    23092309
    23102310    @asaplog_post_dec
     2311    def regrid_channel(self, width=5, plot=False, insitu=None):
     2312        """\
     2313        Regrid the spectra by the specified channel width
     2314
     2315        Parameters:
     2316
     2317            width:      The channel width (float) of regridded spectra
     2318                        in the current spectral unit.
     2319
     2320            plot:       [NOT IMPLEMENTED YET]
     2321                        plot the original and the regridded spectra.
     2322                        In this each indivual fit has to be approved, by
     2323                        typing 'y' or 'n'
     2324
     2325            insitu:     if False a new scantable is returned.
     2326                        Otherwise, the scaling is done in-situ
     2327                        The default is taken from .asaprc (False)
     2328
     2329        """
     2330        if insitu is None: insitu = rcParams['insitu']
     2331        varlist = vars()
     2332
     2333        if plot:
     2334           asaplog.post()
     2335           asaplog.push("Verification plot is not implemtnetd yet.")
     2336           asaplog.post("WARN")
     2337
     2338        s = self.copy()
     2339        s._regrid_specchan(width)
     2340
     2341        s._add_history("regrid_channel", varlist)
     2342
     2343#         if plot:
     2344#             from asap.asapplotter import new_asaplot
     2345#             theplot = new_asaplot(rcParams['plotter.gui'])
     2346#             theplot.set_panels()
     2347#             ylab=s._get_ordinate_label()
     2348#             #theplot.palette(0,["#777777","red"])
     2349#             for r in xrange(s.nrow()):
     2350#                 xsm=s._getabcissa(r)
     2351#                 ysm=s._getspectrum(r)
     2352#                 xorg=orgscan._getabcissa(r)
     2353#                 yorg=orgscan._getspectrum(r)
     2354#                 theplot.clear()
     2355#                 theplot.hold()
     2356#                 theplot.set_axes('ylabel',ylab)
     2357#                 theplot.set_axes('xlabel',s._getabcissalabel(r))
     2358#                 theplot.set_axes('title',s._getsourcename(r))
     2359#                 theplot.set_line(label='Original',color="#777777")
     2360#                 theplot.plot(xorg,yorg)
     2361#                 theplot.set_line(label='Smoothed',color="red")
     2362#                 theplot.plot(xsm,ysm)
     2363#                 ### Ugly part for legend
     2364#                 for i in [0,1]:
     2365#                     theplot.subplots[0]['lines'].append(
     2366#                         [theplot.subplots[0]['axes'].lines[i]]
     2367#                         )
     2368#                 theplot.release()
     2369#                 ### Ugly part for legend
     2370#                 theplot.subplots[0]['lines']=[]
     2371#                 res = raw_input("Accept smoothing ([y]/n): ")
     2372#                 if res.upper() == 'N':
     2373#                     s._setspectrum(yorg, r)
     2374#             theplot.quit()
     2375#             del theplot
     2376#             del orgscan
     2377
     2378        if insitu: self._assign(s)
     2379        else: return s
     2380
     2381    @asaplog_post_dec
    23112382    def _parse_wn(self, wn):
    23122383        if isinstance(wn, list) or isinstance(wn, tuple):
  • trunk/src/Scantable.cpp

    r2433 r2435  
    18851885}
    18861886
     1887void asap::Scantable::regridSpecChannel( double dnu, int nChan )
     1888{
     1889  LogIO os( LogOrigin( "Scantable", "regridChannel()", WHERE ) ) ;
     1890  os << "Regrid abcissa with spectral resoultion " << dnu << " " << freqTable_.getUnitString() << " with channel number " << ((nChan>0)? String(nChan) : "covering band width")<< LogIO::POST ;
     1891  int freqnrow = freqTable_.table().nrow() ;
     1892  Vector<bool> firstTime( freqnrow, true ) ;
     1893  double oldincr, factor;
     1894  uInt currId;
     1895  Double refpix ;
     1896  Double refval ;
     1897  Double increment ;
     1898  for ( int irow = 0 ; irow < nrow() ; irow++ ) {
     1899    currId = mfreqidCol_(irow);
     1900    vector<double> abcissa = getAbcissa( irow ) ;
     1901    if (nChan < 0) {
     1902      int oldsize = abcissa.size() ;
     1903      double bw = (abcissa[oldsize-1]-abcissa[0]) +                     \
     1904        0.5 * (abcissa[1]-abcissa[0] + abcissa[oldsize-1]-abcissa[oldsize-2]) ;
     1905      nChan = int( ceil( abs(bw/dnu) ) ) ;
     1906    }
     1907    // actual regridding
     1908    regridChannel( nChan, dnu, irow ) ;
     1909
     1910    // update FREQUENCIES subtable
     1911    if (firstTime[currId]) {
     1912      oldincr = abcissa[1]-abcissa[0] ;
     1913      factor = dnu/oldincr ;
     1914      firstTime[currId] = false ;
     1915      freqTable_.getEntry( refpix, refval, increment, currId ) ;
     1916      /***
     1917       * need to shift refpix to 0
     1918       ***/
     1919      refval = refval - ( refpix + 0.5 * (1 - factor) ) * increment ;
     1920      refpix = 0 ;
     1921      freqTable_.setEntry( refpix, refval, increment*factor, currId ) ;
     1922      os << "ID" << currId << ": channel width (Orig) = " << oldincr << " [" << freqTable_.getUnitString() << "], scale factor = " << factor << LogIO::POST ;
     1923      os << "     frequency increment (Orig) = " << increment << "-> (New) " << increment*factor << LogIO::POST ;
     1924    }
     1925  }
     1926}
    18871927
    18881928void asap::Scantable::regridChannel( int nChan, double dnu )
  • trunk/src/Scantable.h

    r2411 r2435  
    501501  void regridChannel( int nchan, double dnu ) ;
    502502  void regridChannel( int nchan, double dnu, int irow ) ;
     503
     504  void regridSpecChannel( double dnu, int nchan=-1 ) ;
    503505
    504506  bool getFlagtraFast(casa::uInt whichrow);
  • trunk/src/ScantableWrapper.h

    r2290 r2435  
    268268  { table_->reshapeSpectrum( nmin, nmax ); }
    269269
     270  void regridSpecChannel( double dnu, int nchan )
     271  { table_->regridSpecChannel( dnu, nchan ); }
     272
    270273  void polyBaseline(const std::vector<bool>& mask, int order, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="")
    271274  { table_->polyBaseline(mask, order, getresidual, showprogress, outlog, blfile); }
  • trunk/src/python_Scantable.cpp

    r2286 r2435  
    145145         (boost::python::arg("nmin")=-1,
    146146          boost::python::arg("nmax")=-1) )
     147    .def("_regrid_specchan", &ScantableWrapper::regridSpecChannel,
     148         (boost::python::arg("nchan")=-1) )
    147149    .def("_poly_baseline", &ScantableWrapper::polyBaseline)
    148150    .def("_auto_poly_baseline", &ScantableWrapper::autoPolyBaseline)
Note: See TracChangeset for help on using the changeset viewer.