コード例 #1
0
ファイル: task_sdflag.py プロジェクト: schiebel/casa
 def interactive_flag(self):
     from matplotlib import rc as rcp
     rcp('lines', linewidth=1)
     guiflagger = flagplotter(visible=True)
     #guiflagger.set_legend(loc=1,refresh=False)
     guiflagger.set_showflagged(self.showflagged)
     guiflagger.plot(self.scan)
     finish = raw_input("Press enter to finish interactive flagging:")
     guiflagger._plotter.unmap()
     ismodified = guiflagger._ismodified
     guiflagger._plotter = None
     self.anyflag = ismodified
コード例 #2
0
ファイル: task_sdflag.py プロジェクト: keflavich/casa
 def interactive_flag(self):
     from matplotlib import rc as rcp
     rcp('lines', linewidth=1)
     guiflagger = flagplotter(visible=True)
     #guiflagger.set_legend(loc=1,refresh=False)
     guiflagger.set_showflagged(self.showflagged)
     guiflagger.plot(self.scan)
     finish=raw_input("Press enter to finish interactive flagging:")
     guiflagger._plotter.unmap()
     ismodified = guiflagger._ismodified
     guiflagger._plotter = None
     self.anyflag = ismodified
コード例 #3
0
ファイル: task_sdfitold.py プロジェクト: radio-astro/casa
 def __init_plot(self):
     n = self.scan.nrow()
     if n > 16:
         casalog.post( 'Only first 16 results are plotted.', priority = 'WARN' )
         n = 16
     
     # initialize plotter
     from matplotlib import rc as rcp
     rcp('lines', linewidth=1)
     if not (self.fitter._p and self.fitter._p._alive()):
         self.fitter._p = sdutil.get_plotter(self.plotlevel)
     self.fitter._p.hold()
     self.fitter._p.clear()
     # set nrow and ncol (maximum 4x4)
     self.fitter._p.set_panels(rows=n, cols=0, ganged=False)
     casalog.post( 'nrow,ncol= %d,%d' % (self.fitter._p.rows, self.fitter._p.cols ) )
     self.fitter._p.palette(0,["#777777", "#dddddd", "red", "orange", "purple", "green", "magenta", "cyan"])        
コード例 #4
0
    def __init_plot(self):
        n = self.scan.nrow()
        if n > 16:
            casalog.post('Only first 16 results are plotted.', priority='WARN')
            n = 16

        # initialize plotter
        from matplotlib import rc as rcp
        rcp('lines', linewidth=1)
        if not (self.fitter._p and self.fitter._p._alive()):
            self.fitter._p = sdutil.get_plotter(self.plotlevel)
        self.fitter._p.hold()
        self.fitter._p.clear()
        # set nrow and ncol (maximum 4x4)
        self.fitter._p.set_panels(rows=n, cols=0, ganged=False)
        casalog.post('nrow,ncol= %d,%d' %
                     (self.fitter._p.rows, self.fitter._p.cols))
        self.fitter._p.palette(0, [
            "#777777", "#dddddd", "red", "orange", "purple", "green",
            "magenta", "cyan"
        ])
コード例 #5
0
def calfs(scantab,
          scannos=[],
          smooth=1,
          tsysval=0.0,
          tauval=0.0,
          tcalval=0.0,
          verify=False):
    """
    Calibrate GBT frequency switched data.
    Adopted from GBTIDL getfs.
    Currently calfs identify the scans as frequency switched data if source
    type enum is fson and fsoff. The data must contains 'CAL' signal
    on/off in each integration. To identify 'CAL' on state, the source type 
    enum of foncal and foffcal need to be present.

    Parameters:
        scantab:       scantable
        scannos:       list of scan numbers
        smooth:        optional box smoothing order for the reference
                       (default is 1 = no smoothing)
        tsysval:       optional user specified Tsys (default is 0.0,
                       use Tsys in the data)
        tauval:        optional user specified Tau
        verify:        Verify calibration if true
    """
    varlist = vars()
    from asap._asap import stmath
    from asap._asap import srctype
    stm = stmath()
    stm._setinsitu(False)

    #    check = scantab.get_scan('*_fs*')
    #    if check is None:
    #        msg = "The input data appear to contain no Nod observing mode data."
    #        raise TypeError(msg)
    s = scantab.get_scan(scannos)
    del scantab

    resspec = scantable(stm._dofs(s, scannos, smooth, tsysval, tauval,
                                  tcalval))
    ###
    if verify:
        # get data
        ssub = s.get_scan(scannos)
        #ssubon = ssub.get_scan('*calon')
        #ssuboff = ssub.get_scan('*[^calon]')
        sel = selector()
        sel.set_types([srctype.foncal, srctype.foffcal])
        ssub.set_selection(sel)
        ssubon = ssub.copy()
        ssub.set_selection()
        sel.reset()
        sel.set_types([srctype.fson, srctype.fsoff])
        ssub.set_selection(sel)
        ssuboff = ssub.copy()
        ssub.set_selection()
        sel.reset()
        import numpy
        precal = {}
        postcal = []
        keys = ['fs', 'fs_calon', 'fsr', 'fsr_calon']
        types = [srctype.fson, srctype.foncal, srctype.fsoff, srctype.foffcal]
        ifnos = list(ssub.getifnos())
        polnos = list(ssub.getpolnos())
        for i in range(2):
            #ss=ssuboff.get_scan('*'+keys[2*i])
            ll = []
            for j in range(len(ifnos)):
                for k in range(len(polnos)):
                    sel.set_ifs(ifnos[j])
                    sel.set_polarizations(polnos[k])
                    sel.set_types(types[2 * i])
                    try:
                        #ss.set_selection(sel)
                        ssuboff.set_selection(sel)
                    except:
                        continue
                    ll.append(numpy.array(ss._getspectrum(0)))
                    sel.reset()
                    #ss.set_selection()
                    ssuboff.set_selection()
            precal[keys[2 * i]] = ll
            #del ss
            #ss=ssubon.get_scan('*'+keys[2*i+1])
            ll = []
            for j in range(len(ifnos)):
                for k in range(len(polnos)):
                    sel.set_ifs(ifnos[j])
                    sel.set_polarizations(polnos[k])
                    sel.set_types(types[2 * i + 1])
                    try:
                        #ss.set_selection(sel)
                        ssubon.set_selection(sel)
                    except:
                        continue
                    ll.append(numpy.array(ss._getspectrum(0)))
                    sel.reset()
                    #ss.set_selection()
                    ssubon.set_selection()
            precal[keys[2 * i + 1]] = ll
            #del ss
        #sig=resspec.get_scan('*_fs')
        #ref=resspec.get_scan('*_fsr')
        sel.set_types(srctype.fson)
        resspec.set_selection(sel)
        sig = resspec.copy()
        resspec.set_selection()
        sel.reset()
        sel.set_type(srctype.fsoff)
        resspec.set_selection(sel)
        ref = resspec.copy()
        resspec.set_selection()
        sel.reset()
        for k in range(len(polnos)):
            for j in range(len(ifnos)):
                sel.set_ifs(ifnos[j])
                sel.set_polarizations(polnos[k])
                try:
                    sig.set_selection(sel)
                    postcal.append(numpy.array(sig._getspectrum(0)))
                except:
                    ref.set_selection(sel)
                    postcal.append(numpy.array(ref._getspectrum(0)))
                sel.reset()
                resspec.set_selection()
        del sel
        # plot
        asaplog.post()
        asaplog.push(
            'Plot only first spectrum for each [if,pol] pairs to verify calibration.'
        )
        asaplog.post('WARN')
        p = new_asaplot()
        rcp('lines', linewidth=1)
        #nr=min(6,len(ifnos)*len(polnos))
        nr = len(ifnos) / 2 * len(polnos)
        titles = []
        btics = []
        if nr > 3:
            asaplog.post()
            asaplog.push('Only first 3 [if,pol] pairs are plotted.')
            asaplog.post('WARN')
            nr = 3
        p.set_panels(rows=nr, cols=3, nplots=3 * nr, ganged=False)
        for i in range(3 * nr):
            b = False
            if i >= 3 * nr - 3:
                b = True
            btics.append(b)
        for i in range(nr):
            p.subplot(3 * i)
            p.color = 0
            title = 'raw data IF%s,%s POL%s' % (
                ifnos[2 * int(i / len(polnos))],
                ifnos[2 * int(i / len(polnos)) + 1], polnos[i % len(polnos)])
            titles.append(title)
            #p.set_axes('title',title,fontsize=40)
            ymin = 1.0e100
            ymax = -1.0e100
            nchan = s.nchan(ifnos[2 * int(i / len(polnos))])
            edge = int(nchan * 0.01)
            for j in range(4):
                spmin = min(precal[keys[j]][i][edge:nchan - edge])
                spmax = max(precal[keys[j]][i][edge:nchan - edge])
                ymin = min(ymin, spmin)
                ymax = max(ymax, spmax)
            for j in range(4):
                if i == 0:
                    p.set_line(label=keys[j])
                else:
                    p.legend()
                p.plot(precal[keys[j]][i])
            p.axes.set_ylim(ymin - 0.1 * abs(ymin), ymax + 0.1 * abs(ymax))
            if not btics[3 * i]:
                p.axes.set_xticks([])
            p.subplot(3 * i + 1)
            p.color = 0
            title = 'sig data IF%s POL%s' % (ifnos[2 * int(i / len(polnos))],
                                             polnos[i % len(polnos)])
            titles.append(title)
            #p.set_axes('title',title)
            p.legend()
            ymin = postcal[2 * i][edge:nchan - edge].min()
            ymax = postcal[2 * i][edge:nchan - edge].max()
            p.plot(postcal[2 * i])
            p.axes.set_ylim(ymin - 0.1 * abs(ymin), ymax + 0.1 * abs(ymax))
            if not btics[3 * i + 1]:
                p.axes.set_xticks([])
            p.subplot(3 * i + 2)
            p.color = 0
            title = 'ref data IF%s POL%s' % (ifnos[2 * int(i / len(polnos)) +
                                                   1], polnos[i % len(polnos)])
            titles.append(title)
            #p.set_axes('title',title)
            p.legend()
            ymin = postcal[2 * i + 1][edge:nchan - edge].min()
            ymax = postcal[2 * i + 1][edge:nchan - edge].max()
            p.plot(postcal[2 * i + 1])
            p.axes.set_ylim(ymin - 0.1 * abs(ymin), ymax + 0.1 * abs(ymax))
            if not btics[3 * i + 2]:
                p.axes.set_xticks([])
        for i in range(3 * nr):
            p.subplot(i)
            p.set_axes('title', titles[i], fontsize='medium')
        x = raw_input('Accept calibration ([y]/n): ')
        if x.upper() == 'N':
            p.quit()
            del p
            return scantab
        p.quit()
        del p
    ###
    resspec._add_history("calfs", varlist)
    return resspec
コード例 #6
0
         try:
             ress.set_selection(sel)
         except:
             continue
         postcal.append(numpy.array(ress._getspectrum(0)))
         sel.reset()
         ress.set_selection()
 del sel
 # plot
 asaplog.post()
 asaplog.push(
     'Plot only first spectrum for each [if,pol] pairs to verify calibration.'
 )
 asaplog.post('WARN')
 p = new_asaplot()
 rcp('lines', linewidth=1)
 #nr=min(6,len(ifnos)*len(polnos))
 nr = len(ifnos) * len(polnos)
 titles = []
 btics = []
 if nr < 4:
     p.set_panels(rows=nr, cols=2, nplots=2 * nr, ganged=False)
     for i in range(2 * nr):
         b = False
         if i >= 2 * nr - 2:
             b = True
         btics.append(b)
 elif nr == 4:
     p.set_panels(rows=2, cols=4, nplots=8, ganged=False)
     for i in range(2 * nr):
         b = False
コード例 #7
0
ファイル: interactivemask.py プロジェクト: schiebel/casa
    def select_mask(self,once=False,showmask=True):
        """
        Do interactive mask selection.
        Modify masks interactively by adding/deleting regions with
        mouse drawing.(left-button: mask; right-button: UNmask)
        Note that the interactive region selection is available only
        when GUI plotter is active.

        Parameters:
            once:     If specified as True, you can modify masks only
                      once. Else if False, you can modify them repeatedly.
            showmask: If specified as True, the masked regions are plotted
                      on the plotter.
                  Note this parameter is valid only when once=True.
                  Otherwise, maskes are forced to be plotted for reference.
        """
        # Return if GUI is not active
        if not rcParams['plotter.gui']:
            msg = 'GUI plotter is disabled.\n'
            msg += 'Exit interactive mode.'
            asaplog.push(msg)
            asaplog.post("ERROR")
            return

        self.once = once
        if self.once:
            self.showmask = showmask
        else:
            if not showmask:
                asaplog.post()
                asaplog.push('showmask spcification is ignored. Mask regions are plotted anyway.')
                asaplog.post("WARN")
            self.showmask = True

        if not self.p:
            asaplog.push('A new ASAP plotter will be loaded')
            asaplog.post()
            from asap.asapplotter import asapplotter
            self.p = asapplotter()
            self.newplot = True
        self.p._assert_plotter(action='reload')
        from matplotlib import rc as rcp
        rcp('lines', linewidth=1)
        
        # Plot selected spectra if needed
        if self.scan != self.p._data:
            if len(self.scan.getifnos()) > 16:
                asaplog.post()
                asaplog.push("Number of panels > 16. Plotting the first 16...")
                asaplog.post("WARN")
            # Need replot
            self.p._legendloc = 1
            self.p.plot(self.scan)
            # disable casa toolbar
            if self.p._plotter.figmgr.casabar:
                self.p._plotter.figmgr.casabar.disable_button()
                self.p._plotter.figmgr.casabar.disable_prev()
                self.p._plotter.figmgr.casabar.disable_next()
            for panel in self.p._plotter.subplots:
                xmin, xmax = panel['axes'].get_xlim()
                marg = 0.05*abs(xmax-xmin)
                panel['axes'].set_xlim(xmin-marg, xmax+marg)
                if rcParams['plotter.ganged']: break
            self.p._plotter.show()

        # Plot initial mask region
        #if self.showmask or not self.once:
        if self.showmask:
            self._plot_mask()
            print ''
            print 'Selected regions are shaded with yellow. (gray: projections)'
            print 'Now you can modify the selection.'
            print 'Draw rectangles with Left-mouse to add the regions,'
            print 'or with Right-mouse to exclude the regions.'


        if self.event != None:
            self._region_start(self.event)
        else:
            self.p._plotter.register('button_press',None)
            self.p._plotter.register('button_press',self._region_start)
コード例 #8
0
ファイル: asapfitter.py プロジェクト: schiebel/casa
    def plot(self, residual=False, components=None, plotparms=False, filename=None):
        """
        Plot the last fit.
        Parameters:
            residual:    an optional parameter indicating if the residual
                         should be plotted (default 'False')
            components:  a list of components to plot, e.g [0,1],
                         -1 plots the total fit. Default is to only
                         plot the total fit.
            plotparms:   Inidicates if the parameter values should be present
                         on the plot
        """
        from matplotlib import rc as rcp

        if not self.fitted:
            return
        # if not self._p or self._p.is_dead:
        if not (self._p and self._p._alive()):
            from asap.asapplotter import new_asaplot

            del self._p
            self._p = new_asaplot(rcParams["plotter.gui"])
        self._p.hold()
        self._p.clear()
        rcp("lines", linewidth=1)
        self._p.set_panels()
        self._p.palette(0)
        tlab = "Spectrum"
        xlab = "Abcissa"
        ylab = "Ordinate"
        from numpy import ma, logical_not, logical_and, array

        m = self.mask
        if self.data:
            tlab = self.data._getsourcename(self._fittedrow)
            xlab = self.data._getabcissalabel(self._fittedrow)
            if self.data._getflagrow(self._fittedrow):
                m = [False]
            else:
                m = logical_and(self.mask, array(self.data._getmask(self._fittedrow), copy=False))

            ylab = self.data._get_ordinate_label()

        colours = ["#777777", "#dddddd", "red", "orange", "purple", "green", "magenta", "cyan"]
        nomask = True
        for i in range(len(m)):
            nomask = nomask and m[i]
        if len(m) == 1:
            m = m[0]
            invm = not m
        else:
            invm = logical_not(m)
        label0 = "Masked Region"
        label1 = "Spectrum"
        if nomask:
            label0 = label1
        else:
            y = ma.masked_array(self.y, mask=m)
            self._p.palette(1, colours)
            self._p.set_line(label=label1)
            self._p.plot(self.x, y)
        self._p.palette(0, colours)
        self._p.set_line(label=label0)
        y = ma.masked_array(self.y, mask=invm)
        self._p.plot(self.x, y)
        if residual:
            self._p.palette(7)
            self._p.set_line(label="Residual")
            y = ma.masked_array(self.get_residual(), mask=invm)
            self._p.plot(self.x, y)
        self._p.palette(2)
        if components is not None:
            cs = components
            if isinstance(components, int):
                cs = [components]
            if plotparms:
                self._p.text(0.15, 0.15, str(self.get_parameters()["formatted"]), size=8)
            n = len(self.components)
            self._p.palette(3)
            for c in cs:
                if 0 <= c < n:
                    lab = self.fitfuncs[c] + str(c)
                    self._p.set_line(label=lab)
                    y = ma.masked_array(self.fitter.evaluate(c), mask=invm)

                    self._p.plot(self.x, y)
                elif c == -1:
                    self._p.palette(2)
                    self._p.set_line(label="Total Fit")
                    y = ma.masked_array(self.fitter.getfit(), mask=invm)
                    self._p.plot(self.x, y)
        else:
            self._p.palette(2)
            self._p.set_line(label="Fit")
            y = ma.masked_array(self.fitter.getfit(), mask=invm)
            self._p.plot(self.x, y)
        xlim = [min(self.x), max(self.x)]
        self._p.axes.set_xlim(xlim)
        self._p.set_axes("xlabel", xlab)
        self._p.set_axes("ylabel", ylab)
        self._p.set_axes("title", tlab)
        self._p.release()
        if not rcParams["plotter.gui"]:
            self._p.save(filename)
コード例 #9
0
ファイル: asapmath.py プロジェクト: schiebel/casa
def calfs(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False):
    """
    Calibrate GBT frequency switched data.
    Adopted from GBTIDL getfs.
    Currently calfs identify the scans as frequency switched data if source
    type enum is fson and fsoff. The data must contains 'CAL' signal
    on/off in each integration. To identify 'CAL' on state, the source type 
    enum of foncal and foffcal need to be present.

    Parameters:
        scantab:       scantable
        scannos:       list of scan numbers
        smooth:        optional box smoothing order for the reference
                       (default is 1 = no smoothing)
        tsysval:       optional user specified Tsys (default is 0.0,
                       use Tsys in the data)
        tauval:        optional user specified Tau
        verify:        Verify calibration if true
    """
    varlist = vars()
    from asap._asap import stmath
    from asap._asap import srctype
    stm = stmath()
    stm._setinsitu(False)

#    check = scantab.get_scan('*_fs*')
#    if check is None:
#        msg = "The input data appear to contain no Nod observing mode data."
#        raise TypeError(msg)
    s = scantab.get_scan(scannos)
    del scantab

    resspec = scantable(stm._dofs(s, scannos, smooth, tsysval,tauval,tcalval))
    ###
    if verify:
        # get data
        ssub = s.get_scan(scannos)
        #ssubon = ssub.get_scan('*calon')
        #ssuboff = ssub.get_scan('*[^calon]')
        sel = selector()
        sel.set_types( [srctype.foncal,srctype.foffcal] )
        ssub.set_selection( sel )
        ssubon = ssub.copy()
        ssub.set_selection()
        sel.reset()
        sel.set_types( [srctype.fson,srctype.fsoff] )
        ssub.set_selection( sel )
        ssuboff = ssub.copy()
        ssub.set_selection()
        sel.reset()
        import numpy
        precal={}
        postcal=[]
        keys=['fs','fs_calon','fsr','fsr_calon']
        types=[srctype.fson,srctype.foncal,srctype.fsoff,srctype.foffcal]
        ifnos=list(ssub.getifnos())
        polnos=list(ssub.getpolnos())
        for i in range(2):
            #ss=ssuboff.get_scan('*'+keys[2*i])
            ll=[]
            for j in range(len(ifnos)):
                for k in range(len(polnos)):
                    sel.set_ifs(ifnos[j])
                    sel.set_polarizations(polnos[k])
                    sel.set_types(types[2*i])
                    try:
                        #ss.set_selection(sel)
                        ssuboff.set_selection(sel)
                    except:
                        continue
                    ll.append(numpy.array(ss._getspectrum(0)))
                    sel.reset()
                    #ss.set_selection()
                    ssuboff.set_selection()
            precal[keys[2*i]]=ll
            #del ss
            #ss=ssubon.get_scan('*'+keys[2*i+1])
            ll=[]
            for j in range(len(ifnos)):
                for k in range(len(polnos)):
                    sel.set_ifs(ifnos[j])
                    sel.set_polarizations(polnos[k])
                    sel.set_types(types[2*i+1])
                    try:
                        #ss.set_selection(sel)
                        ssubon.set_selection(sel)
                    except:
                        continue
                    ll.append(numpy.array(ss._getspectrum(0)))
                    sel.reset()
                    #ss.set_selection()
                    ssubon.set_selection()
            precal[keys[2*i+1]]=ll
            #del ss
        #sig=resspec.get_scan('*_fs')
        #ref=resspec.get_scan('*_fsr')
        sel.set_types( srctype.fson )
        resspec.set_selection( sel )
        sig=resspec.copy()
        resspec.set_selection()
        sel.reset()
        sel.set_type( srctype.fsoff )
        resspec.set_selection( sel )
        ref=resspec.copy()
        resspec.set_selection()
        sel.reset()
        for k in range(len(polnos)):
            for j in range(len(ifnos)):
                sel.set_ifs(ifnos[j])
                sel.set_polarizations(polnos[k])
                try:
                    sig.set_selection(sel)
                    postcal.append(numpy.array(sig._getspectrum(0)))
                except:
                    ref.set_selection(sel)
                    postcal.append(numpy.array(ref._getspectrum(0)))
                sel.reset()
                resspec.set_selection()
        del sel
        # plot
        asaplog.post()
        asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.')
        asaplog.post('WARN')
        p=new_asaplot()
        rcp('lines', linewidth=1)
        #nr=min(6,len(ifnos)*len(polnos))
        nr=len(ifnos)/2*len(polnos)
        titles=[]
        btics=[]
        if nr>3:
            asaplog.post()
            asaplog.push('Only first 3 [if,pol] pairs are plotted.')
            asaplog.post('WARN')
            nr=3
        p.set_panels(rows=nr,cols=3,nplots=3*nr,ganged=False)
        for i in range(3*nr):
            b=False
            if i >= 3*nr-3:
                b=True
            btics.append(b)
        for i in range(nr):
            p.subplot(3*i)
            p.color=0
            title='raw data IF%s,%s POL%s' % (ifnos[2*int(i/len(polnos))],ifnos[2*int(i/len(polnos))+1],polnos[i%len(polnos)])
            titles.append(title)
            #p.set_axes('title',title,fontsize=40)
            ymin=1.0e100
            ymax=-1.0e100
            nchan=s.nchan(ifnos[2*int(i/len(polnos))])
            edge=int(nchan*0.01)
            for j in range(4):
                spmin=min(precal[keys[j]][i][edge:nchan-edge])
                spmax=max(precal[keys[j]][i][edge:nchan-edge])
                ymin=min(ymin,spmin)
                ymax=max(ymax,spmax)
            for j in range(4):
                if i==0:
                    p.set_line(label=keys[j])
                else:
                    p.legend()
                p.plot(precal[keys[j]][i])
            p.axes.set_ylim(ymin-0.1*abs(ymin),ymax+0.1*abs(ymax))
            if not btics[3*i]:
                p.axes.set_xticks([])
            p.subplot(3*i+1)
            p.color=0
            title='sig data IF%s POL%s' % (ifnos[2*int(i/len(polnos))],polnos[i%len(polnos)])
            titles.append(title)
            #p.set_axes('title',title)
            p.legend()
            ymin=postcal[2*i][edge:nchan-edge].min()
            ymax=postcal[2*i][edge:nchan-edge].max()
            p.plot(postcal[2*i])
            p.axes.set_ylim(ymin-0.1*abs(ymin),ymax+0.1*abs(ymax))
            if not btics[3*i+1]:
                p.axes.set_xticks([])
            p.subplot(3*i+2)
            p.color=0
            title='ref data IF%s POL%s' % (ifnos[2*int(i/len(polnos))+1],polnos[i%len(polnos)])
            titles.append(title)
            #p.set_axes('title',title)
            p.legend()
            ymin=postcal[2*i+1][edge:nchan-edge].min()
            ymax=postcal[2*i+1][edge:nchan-edge].max()
            p.plot(postcal[2*i+1])
            p.axes.set_ylim(ymin-0.1*abs(ymin),ymax+0.1*abs(ymax))
            if not btics[3*i+2]:
                p.axes.set_xticks([])
        for i in range(3*nr):
            p.subplot(i)
            p.set_axes('title',titles[i],fontsize='medium')
        x=raw_input('Accept calibration ([y]/n): ' )
        if x.upper() == 'N':
            p.quit()
            del p
            return scantab
        p.quit()
        del p
    ###
    resspec._add_history("calfs",varlist)
    return resspec
コード例 #10
0
ファイル: asapmath.py プロジェクト: schiebel/casa
         sel.set_ifs(ifnos[j])
         sel.set_polarizations(polnos[k])
         try:
             ress.set_selection(sel)
         except:
             continue
         postcal.append(numpy.array(ress._getspectrum(0)))
         sel.reset()
         ress.set_selection()
 del sel
 # plot
 asaplog.post()
 asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.')
 asaplog.post('WARN')
 p=new_asaplot()
 rcp('lines', linewidth=1)
 #nr=min(6,len(ifnos)*len(polnos))
 nr=len(ifnos)*len(polnos)
 titles=[]
 btics=[]
 if nr<4:
     p.set_panels(rows=nr,cols=2,nplots=2*nr,ganged=False)
     for i in range(2*nr):
         b=False
         if i >= 2*nr-2:
             b=True
         btics.append(b)
 elif nr==4:
     p.set_panels(rows=2,cols=4,nplots=8,ganged=False)
     for i in range(2*nr):
         b=False
コード例 #11
0
    def plot(self,
             residual=False,
             components=None,
             plotparms=False,
             filename=None):
        """
        Plot the last fit.
        Parameters:
            residual:    an optional parameter indicating if the residual
                         should be plotted (default 'False')
            components:  a list of components to plot, e.g [0,1],
                         -1 plots the total fit. Default is to only
                         plot the total fit.
            plotparms:   Inidicates if the parameter values should be present
                         on the plot
        """
        from matplotlib import rc as rcp
        if not self.fitted:
            return
        #if not self._p or self._p.is_dead:
        if not (self._p and self._p._alive()):
            from asap.asapplotter import new_asaplot
            del self._p
            self._p = new_asaplot(rcParams['plotter.gui'])
        self._p.hold()
        self._p.clear()
        rcp('lines', linewidth=1)
        self._p.set_panels()
        self._p.palette(0)
        tlab = 'Spectrum'
        xlab = 'Abcissa'
        ylab = 'Ordinate'
        from numpy import ma, logical_not, logical_and, array
        m = self.mask
        if self.data:
            tlab = self.data._getsourcename(self._fittedrow)
            xlab = self.data._getabcissalabel(self._fittedrow)
            if self.data._getflagrow(self._fittedrow):
                m = [False]
            else:
                m = logical_and(
                    self.mask,
                    array(self.data._getmask(self._fittedrow), copy=False))

            ylab = self.data._get_ordinate_label()

        colours = [
            "#777777", "#dddddd", "red", "orange", "purple", "green",
            "magenta", "cyan"
        ]
        nomask = True
        for i in range(len(m)):
            nomask = nomask and m[i]
        if len(m) == 1:
            m = m[0]
            invm = (not m)
        else:
            invm = logical_not(m)
        label0 = 'Masked Region'
        label1 = 'Spectrum'
        if (nomask):
            label0 = label1
        else:
            y = ma.masked_array(self.y, mask=m)
            self._p.palette(1, colours)
            self._p.set_line(label=label1)
            self._p.plot(self.x, y)
        self._p.palette(0, colours)
        self._p.set_line(label=label0)
        y = ma.masked_array(self.y, mask=invm)
        self._p.plot(self.x, y)
        if residual:
            self._p.palette(7)
            self._p.set_line(label='Residual')
            y = ma.masked_array(self.get_residual(), mask=invm)
            self._p.plot(self.x, y)
        self._p.palette(2)
        if components is not None:
            cs = components
            if isinstance(components, int): cs = [components]
            if plotparms:
                self._p.text(0.15,
                             0.15,
                             str(self.get_parameters()['formatted']),
                             size=8)
            n = len(self.components)
            self._p.palette(3)
            for c in cs:
                if 0 <= c < n:
                    lab = self.fitfuncs[c] + str(c)
                    self._p.set_line(label=lab)
                    y = ma.masked_array(self.fitter.evaluate(c), mask=invm)

                    self._p.plot(self.x, y)
                elif c == -1:
                    self._p.palette(2)
                    self._p.set_line(label="Total Fit")
                    y = ma.masked_array(self.fitter.getfit(), mask=invm)
                    self._p.plot(self.x, y)
        else:
            self._p.palette(2)
            self._p.set_line(label='Fit')
            y = ma.masked_array(self.fitter.getfit(), mask=invm)
            self._p.plot(self.x, y)
        xlim = [min(self.x), max(self.x)]
        self._p.axes.set_xlim(xlim)
        self._p.set_axes('xlabel', xlab)
        self._p.set_axes('ylabel', ylab)
        self._p.set_axes('title', tlab)
        self._p.release()
        if (not rcParams['plotter.gui']):
            self._p.save(filename)