Ejemplo n.º 1
0
    def plot(self, vlo=2., vhi=98., nc=-1, method='p', mpl=False, cmap=CMDEF, \
                 close=True, x1=None, x2=None, y1=None, y2=None, sepmin=1.):
        """
        Plots an MCCD using pgplot or matplotlib if preferred.

        :Parameters:
         vlo : float
            number specifying the lowest level to plot (default as a percentile)
         vhi : float
            number specifying the lowest level to plot (default as a percentile)
         nc : int
            CCD number (starting from 0, -1 for all)
         method : string
            how vlo and vhi are to be interpreted. 'p' = percentile, 'a' = automatic (min to max,
            vlo and vhi are irrelevant), 'd' = direct, i.e. just take the values given.
         mpl : bool
            True to prefer matplotlib over pgplot (which may not even be an option)
         cmap : matplotlib.cm.binary
            colour map if using matplotlib
         close : bool
            close (pgplot) or 'show' (matplotlib) the plot at the end (or not, to allow 
            you to plot something else, use a cursor etc). In the case of pgplot, this also
            implies opening the plot at the start, i.e. a self-contained quick plot.
         x1 : float
            left-hand plot limit. Defaults to 0.5
         x2 : float
             right-hand plot limit. Defaults to nxmax+0.5
         y1 : float
            lower plot limit. Defaults to 0.5
         y2 : float
             upper plot limit. Defaults to nymax+0.5
         sepmin : float
             minimum separation between intensity limits (> 0 to stop PGPLOT complaining)

        :Returns:
         range(s) : tuple or list
            the plot range(s) used either as a single 2-element tuple, or
            a list of them, one per CCD plotted.
        """

        if nc == -1:
            nc1 = 0
            nc2 = len(self)
        else:
            nc1 = nc
            nc2 = nc+1
        
        if not mpl:
            if close: pg.pgopen('/xs')
            if nc2-nc1 > 1: pg.pgsubp(nc2-nc1,1)

        prange = []
        for nc, ccd in enumerate(self._data[nc1:nc2]):

            # Determine intensity range to display
            if method == 'p':
                vmin, vmax = ccd.centile((vlo,vhi))
            elif method == 'a':
                vmin, vmax = ccd.min(), ccd.max()
            elif method == 'd':
                vmin, vmax = vlo, vhi
            else:
                raise UltracamError('MCCD.plot: method must be one of p, a or d.')

            if vmin == vmax:
                vmin -= sepmin/2.
                vmax += sepmin/2.
            prange.append((vmin, vmax))

            # start
            nxmax, nymax = ccd.nxmax, ccd.nymax
            x1    = 0.5 if x1 is None else x1
            x2    = nxmax+0.5 if x2 is None else x2
            y1    = 0.5 if y1 is None else y1
            y2    = nymax+0.5 if y2 is None else y2

            if mpl:
                if nc2-nc1 > 1:
                    plt.subplot(1,nc2-nc1,nc+1)
                plt.axis('equal')
            else:
                if nc2-nc1 > 1: pg.pgpanl(nc-nc1+1,1)
                pg.pgwnad(x1,x2,y1,y2)

            # plot CCD
            ccd.plot(vmin,vmax,mpl,cmap)

            # per-frame finishing-off
            if mpl:
                plt.xlim(x1,x2)
                plt.ylim(y1,y2)
            else:
                pg.pgbox('bcnst',0,0,'bcnst',0,0)
                pg.pglab('X','Y','')

        if close:
            if mpl:
                plt.show()
            else:
                pg.pgclos()

        # return intensity range(s) used
        if len(prange) == 1:
            return prange[0]
        else:
            return tuple(prange)
				xyPositionPlot['yLimit'] = yLimit
				ppgplot.pgsubp(1, xyPositionPlot['numXYPanels'])
				ppgplot.pgsci(5)
				ppgplot.pgeras()
				for p in range(xyPositionPlot['numXYPanels']):
					ppgplot.pgenv(startFrame, startFrame + frameRange, -yLimit, yLimit, 0, 0)
					ppgplot.pgbox('A', 1.0, 10, 'BCG', 0.0, 0)
					ppgplot.pglab("", "%d"%p, "")
					ppgplot.pgsch(currentSize)
					
				for p, a in enumerate(referenceApertures.getSources()):
					xValues = [log['frameNumber'] for log in a.positionLog]
					yValues = [log['position'][0] - a.position[0] for log in a.positionLog]
					yErrors = [log['positionError'][0] for log in a.positionLog] 
					ppgplot.pgsci(2)
					ppgplot.pgpanl(1, p + 1)
					ppgplot.pgpt(xValues, yValues, 1)
					ppgplot.pgerry(xValues, yValues + yErrors, yValues + yErrors, 0)
					yValues = [log['position'][1] - a.position[1] for log in a.positionLog]
					ppgplot.pgsci(3)
					ppgplot.pgpanl(1, p + 1)
					ppgplot.pgpt(xValues, yValues, 1)
				
					
			shortXArray = [trueFrameNumber]
			shortYArray = [xPosition]
			ppgplot.pgsci(2)
			ppgplot.pgpanl(1, panel + 1)
			ppgplot.pgpt(shortXArray, shortYArray, 1)
			ppgplot.pgsci(3)
			shortYArray = [yPosition]
Ejemplo n.º 3
0
    def plot(self, vlo=2., vhi=98., nc=-1, method='p', mpl=False, cmap=CMDEF, \
                 close=True, x1=None, x2=None, y1=None, y2=None, sepmin=1.):
        """
        Plots an MCCD using pgplot or matplotlib if preferred.

        :Parameters:
         vlo : float
            number specifying the lowest level to plot (default as a percentile)
         vhi : float
            number specifying the lowest level to plot (default as a percentile)
         nc : int
            CCD number (starting from 0, -1 for all)
         method : string
            how vlo and vhi are to be interpreted. 'p' = percentile, 'a' = automatic (min to max,
            vlo and vhi are irrelevant), 'd' = direct, i.e. just take the values given.
         mpl : bool
            True to prefer matplotlib over pgplot (which may not even be an option)
         cmap : matplotlib.cm.binary
            colour map if using matplotlib
         close : bool
            close (pgplot) or 'show' (matplotlib) the plot at the end (or not, to allow 
            you to plot something else, use a cursor etc). In the case of pgplot, this also
            implies opening the plot at the start, i.e. a self-contained quick plot.
         x1 : float
            left-hand plot limit. Defaults to 0.5
         x2 : float
             right-hand plot limit. Defaults to nxmax+0.5
         y1 : float
            lower plot limit. Defaults to 0.5
         y2 : float
             upper plot limit. Defaults to nymax+0.5
         sepmin : float
             minimum separation between intensity limits (> 0 to stop PGPLOT complaining)

        :Returns:
         range(s) : tuple or list
            the plot range(s) used either as a single 2-element tuple, or
            a list of them, one per CCD plotted.
        """

        if nc == -1:
            nc1 = 0
            nc2 = len(self)
        else:
            nc1 = nc
            nc2 = nc + 1

        if not mpl:
            if close: pg.pgopen('/xs')
            if nc2 - nc1 > 1: pg.pgsubp(nc2 - nc1, 1)

        prange = []
        for nc, ccd in enumerate(self._data[nc1:nc2]):

            # Determine intensity range to display
            if method == 'p':
                vmin, vmax = ccd.centile((vlo, vhi))
            elif method == 'a':
                vmin, vmax = ccd.min(), ccd.max()
            elif method == 'd':
                vmin, vmax = vlo, vhi
            else:
                raise UltracamError(
                    'MCCD.plot: method must be one of p, a or d.')

            if vmin == vmax:
                vmin -= sepmin / 2.
                vmax += sepmin / 2.
            prange.append((vmin, vmax))

            # start
            nxmax, nymax = ccd.nxmax, ccd.nymax
            x1 = 0.5 if x1 is None else x1
            x2 = nxmax + 0.5 if x2 is None else x2
            y1 = 0.5 if y1 is None else y1
            y2 = nymax + 0.5 if y2 is None else y2

            if mpl:
                if nc2 - nc1 > 1:
                    plt.subplot(1, nc2 - nc1, nc + 1)
                plt.axis('equal')
            else:
                if nc2 - nc1 > 1: pg.pgpanl(nc - nc1 + 1, 1)
                pg.pgwnad(x1, x2, y1, y2)

            # plot CCD
            ccd.plot(vmin, vmax, mpl, cmap)

            # per-frame finishing-off
            if mpl:
                plt.xlim(x1, x2)
                plt.ylim(y1, y2)
            else:
                pg.pgbox('bcnst', 0, 0, 'bcnst', 0, 0)
                pg.pglab('X', 'Y', '')

        if close:
            if mpl:
                plt.show()
            else:
                pg.pgclos()

        # return intensity range(s) used
        if len(prange) == 1:
            return prange[0]
        else:
            return tuple(prange)