Changeset 2349


Ignore:
Timestamp:
11/16/11 13:57:29 (12 years ago)
Author:
Malte Marquarding
Message:

cosmetic and typo corretions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2348 r2349  
    180180
    181181    @asaplog_post_dec
    182     #def __init__(self, filename, average=None, unit=None, getpt=None,
    183     #             antenna=None, parallactify=None):
    184182    def __init__(self, filename, average=None, unit=None, parallactify=None,
    185183                 **args):
     
    204202                          in existing scantables
    205203
    206             getpt:        for MeasurementSet input data only:
    207                           If True, all pointing data are filled.
    208                           The deafult is False, which makes time to load
    209                           the MS data faster in some cases.
    210 
    211204            antenna:      for MeasurementSet input data only:
    212                           Antenna selection. integer (id) or string (name or id).
    213 
    214             parallactify: Indicate that the data had been parallatified. Default
    215                           is taken from rc file.
     205                          Antenna selection. integer (id) or string
     206                          (name or id).
     207
     208            parallactify: Indicate that the data had been parallactified.
     209                          Default (false) is taken from rc file.
    216210
    217211        """
    218212        if average is None:
    219213            average = rcParams['scantable.autoaverage']
    220         #if getpt is None:
    221         #    getpt = True
    222         #if antenna is not None:
    223         #    asaplog.push("Antenna selection currently unsupported."
    224         #                 "Using ''")
    225         #    asaplog.post('WARN')
    226         #if antenna is None:
    227         #    antenna = ''
    228         #elif type(antenna) == int:
    229         #    antenna = '%s' % antenna
    230         #elif type(antenna) == list:
    231         #    tmpstr = ''
    232         #    for i in range( len(antenna) ):
    233         #        if type(antenna[i]) == int:
    234         #            tmpstr = tmpstr + ('%s,'%(antenna[i]))
    235         #        elif type(antenna[i]) == str:
    236         #            tmpstr=tmpstr+antenna[i]+','
    237         #        else:
    238         #            raise TypeError('Bad antenna selection.')
    239         #    antenna = tmpstr.rstrip(',')
    240214        parallactify = parallactify or rcParams['scantable.parallactify']
    241215        varlist = vars()
     
    260234                    # do not reset to the default freqframe
    261235                    #self.set_freqframe(rcParams['scantable.freqframe'])
    262                 #elif os.path.isdir(filename) \
    263                 #         and not os.path.exists(filename+'/table.f1'):
    264236                elif is_ms(filename):
    265237                    # Measurement Set
     
    269241                        if key in args.keys():
    270242                            opts['ms'][key] = args[key]
    271                     #self._fill([filename], unit, average, getpt, antenna)
    272243                    self._fill([filename], unit, average, opts)
    273244                elif os.path.isfile(filename):
    274                     #self._fill([filename], unit, average, getpt, antenna)
    275245                    self._fill([filename], unit, average)
     246#                    # only apply to new data not "copy constructor"
     247#                    self.parallactify(parallactify)
    276248                else:
    277249                    msg = "The given file '%s'is not a valid " \
     
    280252            elif (isinstance(filename, list) or isinstance(filename, tuple)) \
    281253                  and isinstance(filename[-1], str):
    282                 #self._fill(filename, unit, average, getpt, antenna)
    283254                self._fill(filename, unit, average)
    284255        self.parallactify(parallactify)
     
    594565
    595566        """
    596         if insitu is None: insitu = rcParams['insitu']
     567        if insitu is None:
     568            insitu = rcParams['insitu']
    597569        if not insitu:
    598570            workscan = self.copy()
     
    600572            workscan = self
    601573        # Select a row
    602         sel=selector()
     574        sel = selector()
    603575        sel.set_rows([row])
    604         #sel.set_scans([workscan.getscan(row)])
    605         #sel.set_cycles([workscan.getcycle(row)])
    606         #sel.set_beams([workscan.getbeam(row)])
    607         #sel.set_ifs([workscan.getif(row)])
    608         #sel.set_polarisations([workscan.getpol(row)])
    609         #sel.set_name(workscan._getsourcename(row))
    610576        workscan.set_selection(sel)
    611577        if not workscan.nrow() == 1:
    612             msg = "Cloud not identify single row. %d rows selected."%(workscan.nrow())
     578            msg = "Could not identify single row. %d rows selected." \
     579                % (workscan.nrow())
    613580            raise RuntimeError(msg)
    614         del sel
    615581        if insitu:
    616582            self._assign(workscan)
     
    868834            asdatetime:   return values as datetime objects rather than strings
    869835
    870             prec:         number of digits shown. Default -1 to automatic calculation.
     836            prec:         number of digits shown. Default -1 to automatic
     837                          calculation.
    871838                          Note this number is equals to the digits of MVTime,
    872839                          i.e., 0<prec<3: dates with hh:: only,
     
    878845        if prec < 0:
    879846            # automagically set necessary precision +1
    880             prec = 7 - numpy.floor(numpy.log10(numpy.min(self.get_inttime(row))))
     847            prec = 7 - \
     848                numpy.floor(numpy.log10(numpy.min(self.get_inttime(row))))
    881849            prec = max(6, int(prec))
    882850        else:
     
    12361204
    12371205    @asaplog_post_dec
    1238     def fft(self, rowno=[], mask=[], getrealimag=False):
     1206    def fft(self, rowno=None, mask=None, getrealimag=False):
    12391207        """\
    12401208        Apply FFT to the spectra.
     
    12441212
    12451213            rowno:          The row number(s) to be processed. int, list
    1246                             and tuple are accepted. By default ([]), FFT
     1214                            and tuple are accepted. By default (None), FFT
    12471215                            is applied to the whole data.
    12481216
     
    12521220                            apply different masks. In the latter case, the
    12531221                            length of 'mask' must be the same as that of
    1254                             'rowno'. The default is [].
     1222                            'rowno'. The default is None.
    12551223       
    12561224            getrealimag:    If True, returns the real and imaginary part
     
    12691237            respectively.
    12701238        """
     1239        if rowno is None:
     1240            rowno = []
     1241        if mask is None:
     1242            mask = []
    12711243        if isinstance(rowno, int):
    12721244            rowno = [rowno]
     
    12771249
    12781250        if not (isinstance(mask, list) or isinstance(mask, tuple)):
    1279             raise TypeError("The mask must be a boolean list or a list of boolean list.")
     1251            raise TypeError("The mask must be a boolean list or a list of "
     1252                            "boolean list.")
    12801253        if len(mask) == 0: mask = [True for i in xrange(self.nchan())]
    12811254        if isinstance(mask[0], bool): mask = [mask]
    12821255        elif not (isinstance(mask[0], list) or isinstance(mask[0], tuple)):
    1283             raise TypeError("The mask must be a boolean list or a list of boolean list.")
     1256            raise TypeError("The mask must be a boolean list or a list of "
     1257                            "boolean list.")
    12841258
    12851259        usecommonmask = (len(mask) == 1)
    12861260        if not usecommonmask:
    12871261            if len(mask) != len(rowno):
    1288                 raise ValueError("When specifying masks for each spectrum, the numbers of them must be identical.")
     1262                raise ValueError("When specifying masks for each spectrum, "
     1263                                 "the numbers of them must be identical.")
    12891264        for amask in mask:
    12901265            if len(amask) != self.nchan():
    1291                 raise ValueError("The spectra and the mask have different length.")
     1266                raise ValueError("The spectra and the mask have different "
     1267                                 "length.")
    12921268       
    12931269        res = []
     
    12981274            nspec = len(fspec)
    12991275           
    1300             i=0
    1301             v1=[]
    1302             v2=[]
    1303             reselem = {"real":[],"imag":[]} if getrealimag else {"ampl":[],"phase":[]}
     1276            i = 0
     1277            v1 = []
     1278            v2 = []
     1279            reselem = {"real":[],"imag":[]} if getrealimag \
     1280                                            else {"ampl":[],"phase":[]}
    13041281           
    13051282            while (i < nspec):
    13061283                v1.append(fspec[i])
    13071284                v2.append(fspec[i+1])
    1308                 i+=2
     1285                i += 2
    13091286           
    13101287            if getrealimag:
     
    13171294            res.append(reselem)
    13181295           
    1319             if not usecommonmask: imask += 1
     1296            if not usecommonmask:
     1297                imask += 1
    13201298       
    13211299        return res
     
    13741352        # test if args is a 'list' or a 'normal *args - UGLY!!!
    13751353
    1376         ws = (isinstance(args[-1][-1], int) or isinstance(args[-1][-1], float)) \
    1377              and args or args[0]
     1354        ws = (isinstance(args[-1][-1], int)
     1355              or isinstance(args[-1][-1], float)) and args or args[0]
    13781356        for window in ws:
    13791357            if len(window) == 1:
    13801358                window = [window[0], window[0]]
    13811359            if len(window) == 0 or  len(window) > 2:
    1382                 raise ValueError("A window needs to be defined as [start(, end)]")
     1360                raise ValueError("A window needs to be defined as "
     1361                                 "[start(, end)]")
    13831362            if window[0] > window[1]:
    13841363                tmp = window[0]
     
    14291408        if not silent:
    14301409            asaplog.push(msg)
    1431         masklist=[]
     1410        masklist = []
    14321411        ist, ien = None, None
    14331412        ist, ien=self.get_mask_indices(mask)
     
    14571436        if len(mask) < 2:
    14581437            raise TypeError("The mask elements should be > 1")
    1459         istart=[]
    1460         iend=[]
    1461         if mask[0]: istart.append(0)
     1438        istart = []
     1439        iend = []
     1440        if mask[0]:
     1441            istart.append(0)
    14621442        for i in range(len(mask)-1):
    14631443            if not mask[i] and mask[i+1]:
     
    14651445            elif mask[i] and not mask[i+1]:
    14661446                iend.append(i)
    1467         if mask[len(mask)-1]: iend.append(len(mask)-1)
     1447        if mask[len(mask)-1]:
     1448            iend.append(len(mask)-1)
    14681449        if len(istart) != len(iend):
    14691450            raise RuntimeError("Numbers of mask start != mask end.")
     
    14751456
    14761457    @asaplog_post_dec
    1477     def parse_maskexpr(self,maskstring):
     1458    def parse_maskexpr(self, maskstring):
    14781459        """
    14791460        Parse CASA type mask selection syntax (IF dependent).
     
    15091490            selset = currselstr.split(':')
    15101491            # spw and mask string (may include ~, < or >)
    1511             spwmasklist = self._parse_selection(selset[0],typestr='integer',
    1512                                                offset=1,minval=min(valid_ifs),
    1513                                                maxval=max(valid_ifs))
     1492            spwmasklist = self._parse_selection(selset[0], typestr='integer',
     1493                                                offset=1, minval=min(valid_ifs),
     1494                                                maxval=max(valid_ifs))
    15141495            for spwlist in spwmasklist:
    15151496                selspws = []
     
    15221503            # parse frequency mask list
    15231504            if len(selset) > 1:
    1524                 freqmasklist = self._parse_selection(selset[1],typestr='float',
    1525                                                     offset=0.)
     1505                freqmasklist = self._parse_selection(selset[1], typestr='float',
     1506                                                     offset=0.)
    15261507            else:
    15271508                # want to select the whole spectrum
     
    15551536                            offset = 0.5
    15561537                        elif frequnit.find('Hz') > 0:
    1557                             offset = abs(freqcoord.to_frequency(1,unit=frequnit)
    1558                                       -freqcoord.to_frequency(0,unit=frequnit))*0.5
     1538                            offset = abs(freqcoord.to_frequency(1,
     1539                                                                unit=frequnit)
     1540                                         -freqcoord.to_frequency(0,
     1541                                                                 unit=frequnit)
     1542                                         )*0.5
    15591543                        elif frequnit.find('m/s') > 0:
    1560                             offset = abs(freqcoord.to_velocity(1,unit=frequnit)
    1561                                       -freqcoord.to_velocity(0,unit=frequnit))*0.5
     1544                            offset = abs(freqcoord.to_velocity(1,
     1545                                                               unit=frequnit)
     1546                                         -freqcoord.to_velocity(0,
     1547                                                                unit=frequnit)
     1548                                         )*0.5
    15621549                        else:
    15631550                            asaplog.post()
     
    15921579        if len(seldict) == 0:
    15931580            asaplog.post()
    1594             asaplog.push("No valid selection in the mask expression: "+maskstring)
     1581            asaplog.push("No valid selection in the mask expression: "
     1582                         +maskstring)
    15951583            asaplog.post("WARN")
    15961584            return None
     
    16011589        return seldict
    16021590
    1603     def _parse_selection(self,selstr,typestr='float',offset=0.,minval=None,maxval=None):
     1591    def _parse_selection(self, selstr, typestr='float', offset=0.,
     1592                         minval=None, axval=None):
    16041593        """
    16051594        Parameters:
     
    16711660        """
    16721661        if ids is None:
    1673             rfreqs={}
     1662            rfreqs = {}
    16741663            idlist = self.getmolnos()
    16751664            for i in idlist:
    1676                 rfreqs[i]=list(self._getrestfreqs(i))
     1665                rfreqs[i] = list(self._getrestfreqs(i))
    16771666            return rfreqs
    16781667        else:
    1679             if type(ids)==list or type(ids)==tuple:
    1680                 rfreqs={}
     1668            if type(ids) == list or type(ids) == tuple:
     1669                rfreqs = {}
    16811670                for i in ids:
    1682                     rfreqs[i]=list(self._getrestfreqs(i))
     1671                    rfreqs[i] = list(self._getrestfreqs(i))
    16831672                return rfreqs
    16841673            else:
    16851674                return list(self._getrestfreqs(ids))
    1686             #return list(self._getrestfreqs(ids))
    1687 
     1675
     1676    @asaplog_post_dec
    16881677    def set_restfreqs(self, freqs=None, unit='Hz'):
    16891678        """\
     
    18001789        self._add_history("set_restfreqs", varlist)
    18011790
     1791    @asaplog_post_dec
    18021792    def shift_refpix(self, delta):
    18031793        """\
     
    18141804
    18151805        """
     1806        varlist = vars()
    18161807        Scantable.shift_refpix(self, delta)
     1808        s._add_history("shift_refpix", varlist)
    18171809
    18181810    @asaplog_post_dec
     
    18571849                raise IOError(msg)
    18581850        return page(out)
     1851
    18591852    #
    18601853    # Maths business
     
    18631856    def average_time(self, mask=None, scanav=False, weight='tint', align=False):
    18641857        """\
    1865         Return the (time) weighted average of a scan.
     1858        Return the (time) weighted average of a scan. Scans will be averaged
     1859        only if the source direction (RA/DEC) is within 1' otherwise
    18661860
    18671861        *Note*:
     
    20342028        s = scantable(self._math._freq_align(self, reftime, method))
    20352029        s._add_history("freq_align", varlist)
    2036         if insitu: self._assign(s)
    2037         else: return s
     2030        if insitu:
     2031            self._assign(s)
     2032        else:
     2033            return s
    20382034
    20392035    @asaplog_post_dec
     
    20592055
    20602056        """
    2061         if insitu is None: insitu = rcParams['insitu']
     2057        if insitu is None:
     2058            insitu = rcParams['insitu']
    20622059        self._math._setinsitu(insitu)
    20632060        varlist = vars()
     
    20662063        s = scantable(self._math._opacity(self, tau))
    20672064        s._add_history("opacity", varlist)
    2068         if insitu: self._assign(s)
    2069         else: return s
     2065        if insitu:
     2066            self._assign(s)
     2067        else:
     2068            return s
    20702069
    20712070    @asaplog_post_dec
     
    20832082
    20842083        """
    2085         if insitu is None: insitu = rcParams['insitu']
     2084        if insitu is None:
     2085            insitu = rcParams['insitu']
    20862086        self._math._setinsitu(insitu)
    20872087        varlist = vars()
     
    21112111
    21122112        """
    2113         if insitu is None: insitu = rcParams['insitu']
     2113        if insitu is None:
     2114            insitu = rcParams['insitu']
    21142115        self._math._setinsitu(insitu)
    21152116        varlist = vars()
    21162117        s = scantable(self._math._resample(self, method, width))
    21172118        s._add_history("resample", varlist)
    2118         if insitu: self._assign(s)
    2119         else: return s
     2119        if insitu:
     2120            self._assign(s)
     2121        else:
     2122            return s
    21202123
    21212124    @asaplog_post_dec
     
    22542257                ### Ugly part for legend
    22552258                for i in [0,1]:
    2256                     theplot.subplots[0]['lines'].append([theplot.subplots[0]['axes'].lines[i]])
     2259                    theplot.subplots[0]['lines'].append(
     2260                        [theplot.subplots[0]['axes'].lines[i]]
     2261                        )
    22572262                theplot.release()
    22582263                ### Ugly part for legend
     
    23192324                          minnrow=None, outlog=None, blfile=None):
    23202325        """\
    2321         Return a scan which has been baselined (all rows) with sinusoidal functions.
     2326        Return a scan which has been baselined (all rows) with sinusoidal
     2327        functions.
     2328
    23222329        Parameters:
    23232330            insitu:        if False a new scantable is returned.
     
    23372344                           given a float value, the unit is set to sigma.
    23382345                           for string values, allowed formats include:
    2339                                'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or
     2346                               'xsigma' or 'x' (= x-sigma level. e.g.,
     2347                               '3sigma'), or
    23402348                               'topx' (= the x strongest ones, e.g. 'top5').
    23412349                           default is 3.0 (unit: sigma).
     
    23552363                           and rejwn will NOT be used. default is [].
    23562364            clipthresh:    Clipping threshold. (default is 3.0, unit: sigma)
    2357             clipniter:     maximum number of iteration of 'clipthresh'-sigma clipping (default is 0)
     2365            clipniter:     maximum number of iteration of 'clipthresh'-sigma
     2366                           clipping (default is 0)
    23582367            plot:      *** CURRENTLY UNAVAILABLE, ALWAYS FALSE ***
    23592368                           plot the fit and the residual. In this each
     
    23732382
    23742383        Example:
    2375             # return a scan baselined by a combination of sinusoidal curves having
    2376             # wave numbers in spectral window up to 10,
     2384            # return a scan baselined by a combination of sinusoidal curves
     2385            # having wave numbers in spectral window up to 10,
    23772386            # also with 3-sigma clipping, iteration up to 4 times
    23782387            bscan = scan.sinusoid_baseline(addwn='<=10',clipthresh=3.0,clipniter=4)
     
    24082417
    24092418            #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method.
    2410             workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile)
     2419            workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(),
     2420                                        str(fftthresh).lower(),
     2421                                        workscan._parse_wn(addwn),
     2422                                        workscan._parse_wn(rejwn), clipthresh,
     2423                                        clipniter, getresidual,
     2424                                        pack_progress_params(showprogress,
     2425                                                             minnrow), outlog,
     2426                                        blfile)
    24112427            workscan._add_history('sinusoid_baseline', varlist)
    24122428           
     
    24212437
    24222438    @asaplog_post_dec
    2423     def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None,
    2424                                addwn=None, rejwn=None, clipthresh=None, clipniter=None, edge=None, threshold=None,
    2425                                chan_avg_limit=None, plot=None, getresidual=None, showprogress=None, minnrow=None,
    2426                                outlog=None, blfile=None):
    2427         """\
    2428         Return a scan which has been baselined (all rows) with sinusoidal functions.
     2439    def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None,
     2440                               fftmethod=None, fftthresh=None,
     2441                               addwn=None, rejwn=None, clipthresh=None,
     2442                               clipniter=None, edge=None, threshold=None,
     2443                               chan_avg_limit=None, plot=None,
     2444                               getresidual=None, showprogress=None,
     2445                               minnrow=None, outlog=None, blfile=None):
     2446        """\
     2447        Return a scan which has been baselined (all rows) with sinusoidal
     2448        functions.
    24292449        Spectral lines are detected first using linefinder and masked out
    24302450        to avoid them affecting the baseline solution.
     
    24472467                            given a float value, the unit is set to sigma.
    24482468                            for string values, allowed formats include:
    2449                                 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or
     2469                                'xsigma' or 'x' (= x-sigma level. e.g.,
     2470                                '3sigma'), or
    24502471                                'topx' (= the x strongest ones, e.g. 'top5').
    24512472                            default is 3.0 (unit: sigma).
     
    24652486                            and rejwn will NOT be used. default is [].
    24662487            clipthresh:     Clipping threshold. (default is 3.0, unit: sigma)
    2467             clipniter:      maximum number of iteration of 'clipthresh'-sigma clipping (default is 0)
     2488            clipniter:      maximum number of iteration of 'clipthresh'-sigma
     2489                            clipping (default is 0)
    24682490            edge:           an optional number of channel to drop at
    24692491                            the edge of spectrum. If only one value is
     
    25382560
    25392561            #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method.
    2540             workscan._auto_sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, normalise_edge_param(edge), threshold, chan_avg_limit, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile)
     2562            workscan._auto_sinusoid_baseline(mask, applyfft,
     2563                                             fftmethod.lower(),
     2564                                             str(fftthresh).lower(),
     2565                                             workscan._parse_wn(addwn),
     2566                                             workscan._parse_wn(rejwn),
     2567                                             clipthresh, clipniter,
     2568                                             normalise_edge_param(edge),
     2569                                             threshold, chan_avg_limit,
     2570                                             getresidual,
     2571                                             pack_progress_params(showprogress,
     2572                                                                  minnrow),
     2573                                             outlog, blfile)
    25412574            workscan._add_history("auto_sinusoid_baseline", varlist)
    25422575           
     
    25502583
    25512584    @asaplog_post_dec
    2552     def cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None,
    2553                          plot=None, getresidual=None, showprogress=None, minnrow=None, outlog=None, blfile=None):
    2554         """\
    2555         Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial).
     2585    def cspline_baseline(self, insitu=None, mask=None, npiece=None,
     2586                         clipthresh=None, clipniter=None, plot=None,
     2587                         getresidual=None, showprogress=None, minnrow=None,
     2588                         outlog=None, blfile=None):
     2589        """\
     2590        Return a scan which has been baselined (all rows) by cubic spline
     2591        function (piecewise cubic polynomial).
     2592
    25562593        Parameters:
    25572594            insitu:       If False a new scantable is returned.
     
    25612598            npiece:       Number of pieces. (default is 2)
    25622599            clipthresh:   Clipping threshold. (default is 3.0, unit: sigma)
    2563             clipniter:    maximum number of iteration of 'clipthresh'-sigma clipping (default is 0)
     2600            clipniter:    maximum number of iteration of 'clipthresh'-sigma
     2601                          clipping (default is 0)
    25642602            plot:     *** CURRENTLY UNAVAILABLE, ALWAYS FALSE ***
    25652603                          plot the fit and the residual. In this each
     
    25792617
    25802618        Example:
    2581             # return a scan baselined by a cubic spline consisting of 2 pieces (i.e., 1 internal knot),
     2619            # return a scan baselined by a cubic spline consisting of 2 pieces
     2620            # (i.e., 1 internal knot),
    25822621            # also with 3-sigma clipping, iteration up to 4 times
    25832622            bscan = scan.cspline_baseline(npiece=2,clipthresh=3.0,clipniter=4)
     
    26092648
    26102649            #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method.
    2611             workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile)
     2650            workscan._cspline_baseline(mask, npiece, clipthresh, clipniter,
     2651                                       getresidual,
     2652                                       pack_progress_params(showprogress,
     2653                                                            minnrow), outlog,
     2654                                       blfile)
    26122655            workscan._add_history("cspline_baseline", varlist)
    26132656           
     
    26212664
    26222665    @asaplog_post_dec
    2623     def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None,
    2624                               edge=None, threshold=None, chan_avg_limit=None, getresidual=None, plot=None,
    2625                               showprogress=None, minnrow=None, outlog=None, blfile=None):
     2666    def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None,
     2667                              clipthresh=None, clipniter=None,
     2668                              edge=None, threshold=None, chan_avg_limit=None,
     2669                              getresidual=None, plot=None,
     2670                              showprogress=None, minnrow=None, outlog=None,
     2671                              blfile=None):
    26262672        """\
    26272673        Return a scan which has been baselined (all rows) by cubic spline
     
    26372683            npiece:         Number of pieces. (default is 2)
    26382684            clipthresh:     Clipping threshold. (default is 3.0, unit: sigma)
    2639             clipniter:      maximum number of iteration of 'clipthresh'-sigma clipping (default is 0)
     2685            clipniter:      maximum number of iteration of 'clipthresh'-sigma
     2686                            clipping (default is 0)
    26402687            edge:           an optional number of channel to drop at
    26412688                            the edge of spectrum. If only one value is
     
    27792826            if plot:
    27802827                outblfile = (blfile != "") and \
    2781                     os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
     2828                    os.path.exists(os.path.expanduser(
     2829                                    os.path.expandvars(blfile))
     2830                                   )
    27822831                if outblfile:
    27832832                    blf = open(blfile, "a")
     
    28202869                f._p = None
    28212870
    2822                 if outblfile: blf.close()
     2871                if outblfile:
     2872                    blf.close()
    28232873            else:
    28242874                workscan._poly_baseline(mask, order, getresidual,
     
    29533003                    masklist = workscan.get_masklist(f.mask, row=r, silent=True)
    29543004                    #workscan._append_blinfo(blpars, masklist, f.mask)
    2955                     workscan._setspectrum((f.fitter.getresidual() \
    2956                                                if getresidual else f.fitter.getfit()), r)
     3005                    workscan._setspectrum(
     3006                        (f.fitter.getresidual() if getresidual
     3007                                                else f.fitter.getfit()), r
     3008                        )
    29573009
    29583010                    if outblfile:
     
    31373189            return s
    31383190
    3139     def set_sourcetype(self, match, matchtype="pattern",
     3191    @preserve_selection
     3192    def set_sourcetype(self, match, matchtype="pattern",
    31403193                       sourcetype="reference"):
    31413194        """\
     
    31733226        else:
    31743227            sel.set_query("SRCNAME == %s('%s')" % (matchtype, match))
    3175         self.set_selection(basesel+sel)
    31763228        self._setsourcetype(stype)
    3177         self.set_selection(basesel)
    31783229        self._add_history("set_sourcetype", varlist)
    31793230
     
    32953346            s = scantable(self._math._unaryop(self, other, "ADD", False))
    32963347        elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3297             if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray):
     3348            if isinstance(other[0], list) \
     3349                    or isinstance(other[0], numpy.ndarray):
    32983350                from asapmath import _array2dOp
    32993351                s = _array2dOp( self.copy(), other, "ADD", False )
    33003352            else:
    3301                 s = scantable( self._math._arrayop( self.copy(), other, "ADD", False ) )
     3353                s = scantable( self._math._arrayop( self.copy(), other,
     3354                                                    "ADD", False ) )
    33023355        else:
    33033356            raise TypeError("Other input is not a scantable or float value")
     
    33173370            s = scantable(self._math._unaryop(self, other, "SUB", False))
    33183371        elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3319             if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray):
     3372            if isinstance(other[0], list) \
     3373                    or isinstance(other[0], numpy.ndarray):
    33203374                from asapmath import _array2dOp
    33213375                s = _array2dOp( self.copy(), other, "SUB", False )
    33223376            else:
    3323                 s = scantable( self._math._arrayop( self.copy(), other, "SUB", False ) )
     3377                s = scantable( self._math._arrayop( self.copy(), other,
     3378                                                    "SUB", False ) )
    33243379        else:
    33253380            raise TypeError("Other input is not a scantable or float value")
     
    33393394            s = scantable(self._math._unaryop(self, other, "MUL", False))
    33403395        elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3341             if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray):
     3396            if isinstance(other[0], list) \
     3397                    or isinstance(other[0], numpy.ndarray):
    33423398                from asapmath import _array2dOp
    33433399                s = _array2dOp( self.copy(), other, "MUL", False )
    33443400            else:
    3345                 s = scantable( self._math._arrayop( self.copy(), other, "MUL", False ) )
     3401                s = scantable( self._math._arrayop( self.copy(), other,
     3402                                                    "MUL", False ) )
    33463403        else:
    33473404            raise TypeError("Other input is not a scantable or float value")
     
    33643421            s = scantable(self._math._unaryop(self, other, "DIV", False))
    33653422        elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3366             if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray):
     3423            if isinstance(other[0], list) \
     3424                    or isinstance(other[0], numpy.ndarray):
    33673425                from asapmath import _array2dOp
    33683426                s = _array2dOp( self.copy(), other, "DIV", False )
    33693427            else:
    3370                 s = scantable( self._math._arrayop( self.copy(), other, "DIV", False ) )
     3428                s = scantable( self._math._arrayop( self.copy(), other,
     3429                                                    "DIV", False ) )
    33713430        else:
    33723431            raise TypeError("Other input is not a scantable or float value")
     
    33913450        return fit.as_dict()
    33923451
     3452    @preserve_selection
    33933453    def flag_nans(self):
    33943454        """\
     
    34043464            bnans = [ bool(v) for v in nans]
    34053465            self.flag(bnans)
    3406         self.set_selection(basesel)
    34073466
    34083467    def get_row_selector(self, rowno):
    3409         #return selector(beams=self.getbeam(rowno),
    3410         #                ifs=self.getif(rowno),
    3411         #                pols=self.getpol(rowno),
    3412         #                scans=self.getscan(rowno),
    3413         #                cycles=self.getcycle(rowno))
    34143468        return selector(rows=[rowno])
    34153469
     
    34233477        hist = dstr+sep
    34243478        hist += funcname+sep#cdate+sep
    3425         if parameters.has_key('self'): del parameters['self']
     3479        if parameters.has_key('self'):
     3480            del parameters['self']
    34263481        for k, v in parameters.iteritems():
    34273482            if type(v) is dict:
     
    34803535
    34813536    def _check_ifs(self):
    3482         #nchans = [self.nchan(i) for i in range(self.nif(-1))]
     3537#        return len(set([self.nchan(i) for i in self.getifnos()])) == 1
    34833538        nchans = [self.nchan(i) for i in self.getifnos()]
    34843539        nchans = filter(lambda t: t > 0, nchans)
     
    34863541
    34873542    @asaplog_post_dec
    3488     #def _fill(self, names, unit, average, getpt, antenna):
    34893543    def _fill(self, names, unit, average, opts={}):
    34903544        first = True
     
    35083562                rx = rcParams['scantable.reference']
    35093563                r.setreferenceexpr(rx)
    3510             #r = filler(tbl)
    3511             #rx = rcParams['scantable.reference']
    3512             #r.setreferenceexpr(rx)
    35133564            msg = "Importing %s..." % (name)
    35143565            asaplog.push(msg, False)
    3515             #opts = {'ms': {'antenna' : antenna, 'getpt': getpt} }
    3516             r.open(name, opts)# antenna, -1, -1, getpt)
     3566            r.open(name, opts)
    35173567            r.fill()
    35183568            if average:
Note: See TracChangeset for help on using the changeset viewer.