Changeset 2411


Ignore:
Timestamp:
02/17/12 16:30:24 (12 years ago)
Author:
WataruKawasaki
Message:

New Development: No

JIRA Issue: Yes CAS-3759

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: (1) in sinusoidal baselining procedures and their relevants, quit getting nchan info in Python side but in C++ side.

(2) changed the defaults value of addwn from [] to [0] in sd.*_sinusoid_baseline(). (i.e., toolkit level)


Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2410 r2411  
    1919from asap.utils import _n_bools, mask_not, mask_and, mask_or, page
    2020from asap.asapfitter import fitter
     21
     22###############################################################
     23### WK temporarily added these lines for testing 2011/11/28 ###
     24###############################################################
     25#from asap._asap import TestClass
     26
     27#class testclass(TestClass):
     28#    def __init__(self, nelem):
     29#        TestClass.__init__(self, nelem)
     30
     31###############################################################
    2132
    2233
     
    12531264        if rowno is None:
    12541265            rowno = []
    1255         if mask is None:
    1256             mask = []
    12571266        if isinstance(rowno, int):
    12581267            rowno = [rowno]
    12591268        elif not (isinstance(rowno, list) or isinstance(rowno, tuple)):
    12601269            raise TypeError("The row number(s) must be int, list or tuple.")
    1261 
    12621270        if len(rowno) == 0: rowno = [i for i in xrange(self.nrow())]
    12631271
    1264         if not (isinstance(mask, list) or isinstance(mask, tuple)):
     1272        usecommonmask = True
     1273       
     1274        if mask is None:
     1275            mask = []
     1276        if isinstance(mask, list) or isinstance(mask, tuple):
     1277            if len(mask) == 0:
     1278                mask = [[]]
     1279            else:
     1280                if isinstance(mask[0], bool):
     1281                    if len(mask) != self.nchan(self.getif(rowno[0])):
     1282                        raise ValueError("The spectra and the mask have "
     1283                                         "different length.")
     1284                    mask = [mask]
     1285                elif isinstance(mask[0], list) or isinstance(mask[0], tuple):
     1286                    usecommonmask = False
     1287                    if len(mask) != len(rowno):
     1288                        raise ValueError("When specifying masks for each "
     1289                                         "spectrum, the numbers of them "
     1290                                         "must be identical.")
     1291                    for i in xrange(mask):
     1292                        if len(mask[i]) != self.nchan(self.getif(rowno[i])):
     1293                            raise ValueError("The spectra and the mask have "
     1294                                             "different length.")
     1295                else:
     1296                    raise TypeError("The mask must be a boolean list or "
     1297                                    "a list of boolean list.")
     1298        else:
    12651299            raise TypeError("The mask must be a boolean list or a list of "
    12661300                            "boolean list.")
    1267         if len(mask) == 0: mask = [True for i in xrange(self.nchan())]
    1268         if isinstance(mask[0], bool): mask = [mask]
    1269         elif not (isinstance(mask[0], list) or isinstance(mask[0], tuple)):
    1270             raise TypeError("The mask must be a boolean list or a list of "
    1271                             "boolean list.")
    1272 
    1273         usecommonmask = (len(mask) == 1)
    1274         if not usecommonmask:
    1275             if len(mask) != len(rowno):
    1276                 raise ValueError("When specifying masks for each spectrum, "
    1277                                  "the numbers of them must be identical.")
    1278         for amask in mask:
    1279             if len(amask) != self.nchan():
    1280                 raise ValueError("The spectra and the mask have different "
    1281                                  "length.")
    1282        
     1301
    12831302        res = []
    12841303
     
    23112330                val = int(wn[:-1])
    23122331                res = [i for i in xrange(val)]
    2313             elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,a+1,...,a_nyq]
     2332            elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,-999], which is
     2333                                                     #                     then interpreted in C++
     2334                                                     #                     side as [a,a+1,...,a_nyq]
     2335                                                     #                     (CAS-3759)
    23142336                val = int(wn[2:])
    2315                 res = [i for i in xrange(val, self.nchan()/2+1)]
    2316             elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,a+1,...,a_nyq]
     2337                res = [val, -999]
     2338                #res = [i for i in xrange(val, self.nchan()/2+1)]
     2339            elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,-999], which is
     2340                                                     #                     then interpreted in C++
     2341                                                     #                     side as [a,a+1,...,a_nyq]
     2342                                                     #                     (CAS-3759)
    23172343                val = int(wn[:-2])
    2318                 res = [i for i in xrange(val, self.nchan()/2+1)]
    2319             elif wn[0] == '>':                       # case '>a' :         return [a+1,a+2,...,a_nyq]
     2344                res = [val, -999]
     2345                #res = [i for i in xrange(val, self.nchan()/2+1)]
     2346            elif wn[0] == '>':                       # case '>a' :         return [a+1,-999], which is
     2347                                                     #                     then interpreted in C++
     2348                                                     #                     side as [a+1,a+2,...,a_nyq]
     2349                                                     #                     (CAS-3759)
    23202350                val = int(wn[1:])+1
    2321                 res = [i for i in xrange(val, self.nchan()/2+1)]
    2322             elif wn[-1] == '<':                      # case 'a<' :         return [a+1,a+2,...,a_nyq]
     2351                res = [val, -999]
     2352                #res = [i for i in xrange(val, self.nchan()/2+1)]
     2353            elif wn[-1] == '<':                      # case 'a<' :         return [a+1,-999], which is
     2354                                                     #                     then interpreted in C++
     2355                                                     #                     side as [a+1,a+2,...,a_nyq]
     2356                                                     #                     (CAS-3759)
    23232357                val = int(wn[:-1])+1
    2324                 res = [i for i in xrange(val, self.nchan()/2+1)]
     2358                res = [val, -999]
     2359                #res = [i for i in xrange(val, self.nchan()/2+1)]
    23252360
    23262361            return res
     
    23712406                                        number corresponding to the Nyquist
    23722407                                        frequency for the case of FFT).
    2373                            default is [].
     2408                           default is [0].
    23742409            rejwn:         the wave numbers NOT to be used for fitting.
    23752410                           can be set just as addwn but has higher priority:
     
    24202455            if fftmethod     is None: fftmethod     = 'fft'
    24212456            if fftthresh     is None: fftthresh     = 3.0
    2422             if addwn         is None: addwn         = []
     2457            if addwn         is None: addwn         = [0]
    24232458            if rejwn         is None: rejwn         = []
    24242459            if clipthresh    is None: clipthresh    = 3.0
     
    24952530                                         number corresponding to the Nyquist
    24962531                                         frequency for the case of FFT).
    2497                             default is [].
     2532                            default is [0].
    24982533            rejwn:          the wave numbers NOT to be used for fitting.
    24992534                            can be set just as addwn but has higher priority:
     
    25612596            if fftmethod      is None: fftmethod      = 'fft'
    25622597            if fftthresh      is None: fftthresh      = 3.0
    2563             if addwn          is None: addwn          = []
     2598            if addwn          is None: addwn          = [0]
    25642599            if rejwn          is None: rejwn          = []
    25652600            if clipthresh     is None: clipthresh     = 3.0
  • trunk/src/Scantable.cpp

    r2410 r2411  
    26972697  }
    26982698
    2699   addAuxWaveNumbers(addNWaves, rejectNWaves, nWaves);
     2699  addAuxWaveNumbers(whichrow, addNWaves, rejectNWaves, nWaves);
    27002700}
    27012701
     
    27792779}
    27802780
    2781 void Scantable::addAuxWaveNumbers(const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves)
    2782 {
     2781void Scantable::addAuxWaveNumbers(const int whichrow, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves)
     2782{
     2783  std::vector<int> tempAddNWaves, tempRejectNWaves;
    27832784  for (uInt i = 0; i < addNWaves.size(); ++i) {
     2785    tempAddNWaves.push_back(addNWaves[i]);
     2786  }
     2787  if ((tempAddNWaves.size() == 2) && (tempAddNWaves[1] == -999)) {
     2788    setWaveNumberListUptoNyquistFreq(whichrow, tempAddNWaves);
     2789  }
     2790
     2791  for (uInt i = 0; i < rejectNWaves.size(); ++i) {
     2792    tempRejectNWaves.push_back(rejectNWaves[i]);
     2793  }
     2794  if ((tempRejectNWaves.size() == 2) && (tempRejectNWaves[1] == -999)) {
     2795    setWaveNumberListUptoNyquistFreq(whichrow, tempRejectNWaves);
     2796  }
     2797
     2798  for (uInt i = 0; i < tempAddNWaves.size(); ++i) {
    27842799    bool found = false;
    27852800    for (uInt j = 0; j < nWaves.size(); ++j) {
    2786       if (nWaves[j] == addNWaves[i]) {
     2801      if (nWaves[j] == tempAddNWaves[i]) {
    27872802        found = true;
    27882803        break;
    27892804      }
    27902805    }
    2791     if (!found) nWaves.push_back(addNWaves[i]);
    2792   }
    2793 
    2794   for (uInt i = 0; i < rejectNWaves.size(); ++i) {
     2806    if (!found) nWaves.push_back(tempAddNWaves[i]);
     2807  }
     2808
     2809  for (uInt i = 0; i < tempRejectNWaves.size(); ++i) {
    27952810    for (std::vector<int>::iterator j = nWaves.begin(); j != nWaves.end(); ) {
    2796       if (*j == rejectNWaves[i]) {
     2811      if (*j == tempRejectNWaves[i]) {
    27972812        j = nWaves.erase(j);
    27982813      } else {
     
    28052820    sort(nWaves.begin(), nWaves.end());
    28062821    unique(nWaves.begin(), nWaves.end());
     2822  }
     2823}
     2824
     2825void Scantable::setWaveNumberListUptoNyquistFreq(const int whichrow, std::vector<int>& nWaves)
     2826{
     2827  if ((nWaves.size() == 2)&&(nWaves[1] == -999)) {
     2828    int val = nWaves[0];
     2829    int nyquistFreq = nchan(getIF(whichrow))/2+1;
     2830    nWaves.clear();
     2831    if (val > nyquistFreq) {  // for safety, at least nWaves contains a constant; CAS-3759
     2832      nWaves.push_back(0);
     2833    }
     2834    while (val <= nyquistFreq) {
     2835      nWaves.push_back(val);
     2836      val++;
     2837    }
    28072838  }
    28082839}
     
    28442875
    28452876      //FOR DEBUGGING------------
     2877      /*
    28462878      if (whichrow < 0) {// == nRow -1) {
    28472879        cout << "+++ i=" << setw(3) << whichrow << ", IF=" << setw(2) << getIF(whichrow);
     
    28552887        cout << flush;
    28562888      }
     2889      */
    28572890      //-------------------------
    28582891
  • trunk/src/Scantable.h

    r2357 r2411  
    739739                           const std::string& fftThAttr,
    740740                           std::vector<int>& nWaves);
    741   void addAuxWaveNumbers(const std::vector<int>& addNWaves,
     741  void addAuxWaveNumbers(const int whichrow,
     742                         const std::vector<int>& addNWaves,
    742743                         const std::vector<int>& rejectNWaves,
    743744                         std::vector<int>& nWaves);
     745  void setWaveNumberListUptoNyquistFreq(const int whichrow,
     746                                        std::vector<int>& nWaves);
    744747  bool hasSameNchanOverIFs();
    745748  std::string getMaskRangeList(const std::vector<bool>& mask,
Note: See TracChangeset for help on using the changeset viewer.