Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2351 r2435  
    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
     
    264275        Parameters:
    265276
    266             name:        the name of the outputfile. For format "ASCII"
     277            name:        the name of the outputfile. For format 'ASCII'
    267278                         this is the root file name (data in 'name'.txt
    268279                         and header in 'name'_header.txt)
     
    522533
    523534            selection:    a selector object (default unset the selection), or
    524                           any combination of "pols", "ifs", "beams", "scans",
    525                           "cycles", "name", "query"
     535                          any combination of 'pols', 'ifs', 'beams', 'scans',
     536                          'cycles', 'name', 'query'
    526537
    527538        Examples::
     
    757768        return self._row_callback(self._gettsys, "Tsys")
    758769
     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 )
    759784
    760785    def get_weather(self, row=-1):
     
    11771202            end:      the end frequency or period to remove
    11781203
    1179             unit:     the frequency unit (default "MHz") or "" for
     1204            unit:     the frequency unit (default 'MHz') or '' for
    11801205                      explicit lag channels
    11811206
     
    12391264        if rowno is None:
    12401265            rowno = []
    1241         if mask is None:
    1242             mask = []
    12431266        if isinstance(rowno, int):
    12441267            rowno = [rowno]
    12451268        elif not (isinstance(rowno, list) or isinstance(rowno, tuple)):
    12461269            raise TypeError("The row number(s) must be int, list or tuple.")
    1247 
    12481270        if len(rowno) == 0: rowno = [i for i in xrange(self.nrow())]
    12491271
    1250         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:
    12511299            raise TypeError("The mask must be a boolean list or a list of "
    12521300                            "boolean list.")
    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        
     1301
    12691302        res = []
    12701303
     
    13931426        if not (isinstance(mask,list) or isinstance(mask, tuple)):
    13941427            raise TypeError("The mask should be list or tuple.")
    1395         if len(mask) < 2:
    1396             raise TypeError("The mask elements should be > 1")
     1428        if len(mask) <= 0:
     1429            raise TypeError("The mask elements should be > 0")
    13971430        data = self._getabcissa(row)
    13981431        if len(data) != len(mask):
     
    14341467        if not (isinstance(mask,list) or isinstance(mask, tuple)):
    14351468            raise TypeError("The mask should be list or tuple.")
    1436         if len(mask) < 2:
    1437             raise TypeError("The mask elements should be > 1")
     1469        if len(mask) <= 0:
     1470            raise TypeError("The mask elements should be > 0")
    14381471        istart = []
    14391472        iend = []
     
    17211754                # provided your scantable is called scan
    17221755                selection = selector()
    1723                 selection.set_name("ORION*")
     1756                selection.set_name('ORION*')
    17241757                selection.set_ifs([1])
    17251758                scan.set_selection(selection)
     
    19621995                         The first row of the ascii file must give the column
    19631996                         names and these MUST include columns
    1964                          "ELEVATION" (degrees) and "FACTOR" (multiply data
     1997                         'ELEVATION' (degrees) and 'FACTOR' (multiply data
    19651998                         by this) somewhere.
    19661999                         The second row must give the data type of the
     
    19792012
    19802013            method:      Interpolation method when correcting from a table.
    1981                          Values are  "nearest", "linear" (default), "cubic"
    1982                          and "spline"
     2014                         Values are  'nearest', 'linear' (default), 'cubic'
     2015                         and 'spline'
    19832016
    19842017            insitu:      if False a new scantable is returned.
     
    20142047
    20152048            method:      Interpolation method for regridding the spectra.
    2016                          Choose from "nearest", "linear", "cubic" (default)
    2017                          and "spline"
     2049                         Choose from 'nearest', 'linear', 'cubic' (default)
     2050                         and 'spline'
    20182051
    20192052            insitu:      if False a new scantable is returned.
     
    20232056        """
    20242057        if insitu is None: insitu = rcParams["insitu"]
     2058        oldInsitu = self._math._insitu()
    20252059        self._math._setinsitu(insitu)
    20262060        varlist = vars()
     
    20282062        s = scantable(self._math._freq_align(self, reftime, method))
    20292063        s._add_history("freq_align", varlist)
     2064        self._math._setinsitu(oldInsitu)
    20302065        if insitu:
    20312066            self._assign(s)
     
    21032138
    21042139            method:      Interpolation method when correcting from a table.
    2105                          Values are  "nearest", "linear", "cubic" (default)
    2106                          and "spline"
     2140                         Values are  'nearest', 'linear', 'cubic' (default)
     2141                         and 'spline'
    21072142
    21082143            insitu:      if False a new scantable is returned.
     
    21872222
    21882223            poltype:    The new polarisation type. Valid types are:
    2189                         "linear", "circular", "stokes" and "linpol"
     2224                        'linear', 'circular', 'stokes' and 'linpol'
    21902225
    21912226        """
     
    22742309
    22752310    @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
    22762382    def _parse_wn(self, wn):
    22772383        if isinstance(wn, list) or isinstance(wn, tuple):
     
    22972403                val = int(wn[:-1])
    22982404                res = [i for i in xrange(val)]
    2299             elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,a+1,...,a_nyq]
     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)
    23002409                val = int(wn[2:])
    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]
     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)
    23032416                val = int(wn[:-2])
    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]
     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)
    23062423                val = int(wn[1:])+1
    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]
     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)
    23092430                val = int(wn[:-1])+1
    2310                 res = [i for i in xrange(val, self.nchan()/2+1)]
     2431                res = [val, -999]
     2432                #res = [i for i in xrange(val, self.nchan()/2+1)]
    23112433
    23122434            return res
     
    23572479                                        number corresponding to the Nyquist
    23582480                                        frequency for the case of FFT).
    2359                            default is [].
     2481                           default is [0].
    23602482            rejwn:         the wave numbers NOT to be used for fitting.
    23612483                           can be set just as addwn but has higher priority:
     
    24012523                workscan = self.copy()
    24022524           
    2403             if mask          is None: mask          = [True for i in xrange(workscan.nchan())]
     2525            #if mask          is None: mask          = [True for i in xrange(workscan.nchan())]
     2526            if mask          is None: mask          = []
    24042527            if applyfft      is None: applyfft      = True
    24052528            if fftmethod     is None: fftmethod     = 'fft'
    24062529            if fftthresh     is None: fftthresh     = 3.0
    2407             if addwn         is None: addwn         = []
     2530            if addwn         is None: addwn         = [0]
    24082531            if rejwn         is None: rejwn         = []
    24092532            if clipthresh    is None: clipthresh    = 3.0
     
    24802603                                         number corresponding to the Nyquist
    24812604                                         frequency for the case of FFT).
    2482                             default is [].
     2605                            default is [0].
    24832606            rejwn:          the wave numbers NOT to be used for fitting.
    24842607                            can be set just as addwn but has higher priority:
     
    25412664                workscan = self.copy()
    25422665           
    2543             if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
     2666            #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
     2667            if mask           is None: mask           = []
    25442668            if applyfft       is None: applyfft       = True
    25452669            if fftmethod      is None: fftmethod      = 'fft'
    25462670            if fftthresh      is None: fftthresh      = 3.0
    2547             if addwn          is None: addwn          = []
     2671            if addwn          is None: addwn          = [0]
    25482672            if rejwn          is None: rejwn          = []
    25492673            if clipthresh     is None: clipthresh     = 3.0
     
    26362760                workscan = self.copy()
    26372761
    2638             if mask         is None: mask         = [True for i in xrange(workscan.nchan())]
     2762            #if mask         is None: mask         = [True for i in xrange(workscan.nchan())]
     2763            if mask         is None: mask         = []
    26392764            if npiece       is None: npiece       = 2
    26402765            if clipthresh   is None: clipthresh   = 3.0
     
    27382863                workscan = self.copy()
    27392864           
    2740             if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
     2865            #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
     2866            if mask           is None: mask           = []
    27412867            if npiece         is None: npiece         = 2
    27422868            if clipthresh     is None: clipthresh     = 3.0
     
    28142940                workscan = self.copy()
    28152941
    2816             if mask         is None: mask         = [True for i in \
    2817                                                        xrange(workscan.nchan())]
     2942            #if mask         is None: mask         = [True for i in \
     2943            #                                           xrange(workscan.nchan())]
     2944            if mask         is None: mask         = []
    28182945            if order        is None: order        = 0
    28192946            if plot         is None: plot         = False
     
    29533080                workscan = self.copy()
    29543081
    2955             if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
     3082            #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
     3083            if mask           is None: mask           = []
    29563084            if order          is None: order          = 0
    29573085            if edge           is None: edge           = (0, 0)
Note: See TracChangeset for help on using the changeset viewer.