Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2435 r2351  
    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 ###############################################################
    3221
    3322
     
    275264        Parameters:
    276265
    277             name:        the name of the outputfile. For format 'ASCII'
     266            name:        the name of the outputfile. For format "ASCII"
    278267                         this is the root file name (data in 'name'.txt
    279268                         and header in 'name'_header.txt)
     
    533522
    534523            selection:    a selector object (default unset the selection), or
    535                           any combination of 'pols', 'ifs', 'beams', 'scans',
    536                           'cycles', 'name', 'query'
     524                          any combination of "pols", "ifs", "beams", "scans",
     525                          "cycles", "name", "query"
    537526
    538527        Examples::
     
    768757        return self._row_callback(self._gettsys, "Tsys")
    769758
    770     def get_tsysspectrum(self, row=-1):
    771         """\
    772         Return the channel dependent system temperatures.
    773 
    774         Parameters:
    775 
    776             row:    the rowno to get the information for. (default all rows)
    777 
    778         Returns:
    779 
    780             a list of Tsys values for the current selection
    781 
    782         """
    783         return self._get_column( self._gettsysspectrum, row )
    784759
    785760    def get_weather(self, row=-1):
     
    12021177            end:      the end frequency or period to remove
    12031178
    1204             unit:     the frequency unit (default 'MHz') or '' for
     1179            unit:     the frequency unit (default "MHz") or "" for
    12051180                      explicit lag channels
    12061181
     
    12641239        if rowno is None:
    12651240            rowno = []
     1241        if mask is None:
     1242            mask = []
    12661243        if isinstance(rowno, int):
    12671244            rowno = [rowno]
    12681245        elif not (isinstance(rowno, list) or isinstance(rowno, tuple)):
    12691246            raise TypeError("The row number(s) must be int, list or tuple.")
     1247
    12701248        if len(rowno) == 0: rowno = [i for i in xrange(self.nrow())]
    12711249
    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:
     1250        if not (isinstance(mask, list) or isinstance(mask, tuple)):
    12991251            raise TypeError("The mask must be a boolean list or a list of "
    13001252                            "boolean list.")
    1301 
     1253        if len(mask) == 0: mask = [True for i in xrange(self.nchan())]
     1254        if isinstance(mask[0], bool): mask = [mask]
     1255        elif not (isinstance(mask[0], list) or isinstance(mask[0], tuple)):
     1256            raise TypeError("The mask must be a boolean list or a list of "
     1257                            "boolean list.")
     1258
     1259        usecommonmask = (len(mask) == 1)
     1260        if not usecommonmask:
     1261            if len(mask) != len(rowno):
     1262                raise ValueError("When specifying masks for each spectrum, "
     1263                                 "the numbers of them must be identical.")
     1264        for amask in mask:
     1265            if len(amask) != self.nchan():
     1266                raise ValueError("The spectra and the mask have different "
     1267                                 "length.")
     1268       
    13021269        res = []
    13031270
     
    14261393        if not (isinstance(mask,list) or isinstance(mask, tuple)):
    14271394            raise TypeError("The mask should be list or tuple.")
    1428         if len(mask) <= 0:
    1429             raise TypeError("The mask elements should be > 0")
     1395        if len(mask) < 2:
     1396            raise TypeError("The mask elements should be > 1")
    14301397        data = self._getabcissa(row)
    14311398        if len(data) != len(mask):
     
    14671434        if not (isinstance(mask,list) or isinstance(mask, tuple)):
    14681435            raise TypeError("The mask should be list or tuple.")
    1469         if len(mask) <= 0:
    1470             raise TypeError("The mask elements should be > 0")
     1436        if len(mask) < 2:
     1437            raise TypeError("The mask elements should be > 1")
    14711438        istart = []
    14721439        iend = []
     
    17541721                # provided your scantable is called scan
    17551722                selection = selector()
    1756                 selection.set_name('ORION*')
     1723                selection.set_name("ORION*")
    17571724                selection.set_ifs([1])
    17581725                scan.set_selection(selection)
     
    19951962                         The first row of the ascii file must give the column
    19961963                         names and these MUST include columns
    1997                          'ELEVATION' (degrees) and 'FACTOR' (multiply data
     1964                         "ELEVATION" (degrees) and "FACTOR" (multiply data
    19981965                         by this) somewhere.
    19991966                         The second row must give the data type of the
     
    20121979
    20131980            method:      Interpolation method when correcting from a table.
    2014                          Values are  'nearest', 'linear' (default), 'cubic'
    2015                          and 'spline'
     1981                         Values are  "nearest", "linear" (default), "cubic"
     1982                         and "spline"
    20161983
    20171984            insitu:      if False a new scantable is returned.
     
    20472014
    20482015            method:      Interpolation method for regridding the spectra.
    2049                          Choose from 'nearest', 'linear', 'cubic' (default)
    2050                          and 'spline'
     2016                         Choose from "nearest", "linear", "cubic" (default)
     2017                         and "spline"
    20512018
    20522019            insitu:      if False a new scantable is returned.
     
    20562023        """
    20572024        if insitu is None: insitu = rcParams["insitu"]
    2058         oldInsitu = self._math._insitu()
    20592025        self._math._setinsitu(insitu)
    20602026        varlist = vars()
     
    20622028        s = scantable(self._math._freq_align(self, reftime, method))
    20632029        s._add_history("freq_align", varlist)
    2064         self._math._setinsitu(oldInsitu)
    20652030        if insitu:
    20662031            self._assign(s)
     
    21382103
    21392104            method:      Interpolation method when correcting from a table.
    2140                          Values are  'nearest', 'linear', 'cubic' (default)
    2141                          and 'spline'
     2105                         Values are  "nearest", "linear", "cubic" (default)
     2106                         and "spline"
    21422107
    21432108            insitu:      if False a new scantable is returned.
     
    22222187
    22232188            poltype:    The new polarisation type. Valid types are:
    2224                         'linear', 'circular', 'stokes' and 'linpol'
     2189                        "linear", "circular", "stokes" and "linpol"
    22252190
    22262191        """
     
    23092274
    23102275    @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
    23822276    def _parse_wn(self, wn):
    23832277        if isinstance(wn, list) or isinstance(wn, tuple):
     
    24032297                val = int(wn[:-1])
    24042298                res = [i for i in xrange(val)]
    2405             elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,-999], which is
    2406                                                      #                     then interpreted in C++
    2407                                                      #                     side as [a,a+1,...,a_nyq]
    2408                                                      #                     (CAS-3759)
     2299            elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,a+1,...,a_nyq]
    24092300                val = int(wn[2:])
    2410                 res = [val, -999]
    2411                 #res = [i for i in xrange(val, self.nchan()/2+1)]
    2412             elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,-999], which is
    2413                                                      #                     then interpreted in C++
    2414                                                      #                     side as [a,a+1,...,a_nyq]
    2415                                                      #                     (CAS-3759)
     2301                res = [i for i in xrange(val, self.nchan()/2+1)]
     2302            elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,a+1,...,a_nyq]
    24162303                val = int(wn[:-2])
    2417                 res = [val, -999]
    2418                 #res = [i for i in xrange(val, self.nchan()/2+1)]
    2419             elif wn[0] == '>':                       # case '>a' :         return [a+1,-999], which is
    2420                                                      #                     then interpreted in C++
    2421                                                      #                     side as [a+1,a+2,...,a_nyq]
    2422                                                      #                     (CAS-3759)
     2304                res = [i for i in xrange(val, self.nchan()/2+1)]
     2305            elif wn[0] == '>':                       # case '>a' :         return [a+1,a+2,...,a_nyq]
    24232306                val = int(wn[1:])+1
    2424                 res = [val, -999]
    2425                 #res = [i for i in xrange(val, self.nchan()/2+1)]
    2426             elif wn[-1] == '<':                      # case 'a<' :         return [a+1,-999], which is
    2427                                                      #                     then interpreted in C++
    2428                                                      #                     side as [a+1,a+2,...,a_nyq]
    2429                                                      #                     (CAS-3759)
     2307                res = [i for i in xrange(val, self.nchan()/2+1)]
     2308            elif wn[-1] == '<':                      # case 'a<' :         return [a+1,a+2,...,a_nyq]
    24302309                val = int(wn[:-1])+1
    2431                 res = [val, -999]
    2432                 #res = [i for i in xrange(val, self.nchan()/2+1)]
     2310                res = [i for i in xrange(val, self.nchan()/2+1)]
    24332311
    24342312            return res
     
    24792357                                        number corresponding to the Nyquist
    24802358                                        frequency for the case of FFT).
    2481                            default is [0].
     2359                           default is [].
    24822360            rejwn:         the wave numbers NOT to be used for fitting.
    24832361                           can be set just as addwn but has higher priority:
     
    25232401                workscan = self.copy()
    25242402           
    2525             #if mask          is None: mask          = [True for i in xrange(workscan.nchan())]
    2526             if mask          is None: mask          = []
     2403            if mask          is None: mask          = [True for i in xrange(workscan.nchan())]
    25272404            if applyfft      is None: applyfft      = True
    25282405            if fftmethod     is None: fftmethod     = 'fft'
    25292406            if fftthresh     is None: fftthresh     = 3.0
    2530             if addwn         is None: addwn         = [0]
     2407            if addwn         is None: addwn         = []
    25312408            if rejwn         is None: rejwn         = []
    25322409            if clipthresh    is None: clipthresh    = 3.0
     
    26032480                                         number corresponding to the Nyquist
    26042481                                         frequency for the case of FFT).
    2605                             default is [0].
     2482                            default is [].
    26062483            rejwn:          the wave numbers NOT to be used for fitting.
    26072484                            can be set just as addwn but has higher priority:
     
    26642541                workscan = self.copy()
    26652542           
    2666             #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    2667             if mask           is None: mask           = []
     2543            if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    26682544            if applyfft       is None: applyfft       = True
    26692545            if fftmethod      is None: fftmethod      = 'fft'
    26702546            if fftthresh      is None: fftthresh      = 3.0
    2671             if addwn          is None: addwn          = [0]
     2547            if addwn          is None: addwn          = []
    26722548            if rejwn          is None: rejwn          = []
    26732549            if clipthresh     is None: clipthresh     = 3.0
     
    27602636                workscan = self.copy()
    27612637
    2762             #if mask         is None: mask         = [True for i in xrange(workscan.nchan())]
    2763             if mask         is None: mask         = []
     2638            if mask         is None: mask         = [True for i in xrange(workscan.nchan())]
    27642639            if npiece       is None: npiece       = 2
    27652640            if clipthresh   is None: clipthresh   = 3.0
     
    28632738                workscan = self.copy()
    28642739           
    2865             #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    2866             if mask           is None: mask           = []
     2740            if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    28672741            if npiece         is None: npiece         = 2
    28682742            if clipthresh     is None: clipthresh     = 3.0
     
    29402814                workscan = self.copy()
    29412815
    2942             #if mask         is None: mask         = [True for i in \
    2943             #                                           xrange(workscan.nchan())]
    2944             if mask         is None: mask         = []
     2816            if mask         is None: mask         = [True for i in \
     2817                                                       xrange(workscan.nchan())]
    29452818            if order        is None: order        = 0
    29462819            if plot         is None: plot         = False
     
    30802953                workscan = self.copy()
    30812954
    3082             #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    3083             if mask           is None: mask           = []
     2955            if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    30842956            if order          is None: order          = 0
    30852957            if edge           is None: edge           = (0, 0)
Note: See TracChangeset for help on using the changeset viewer.