Exemple #1
0
 def _plot1d(self, a, b, xlabel, xarr, zarr):
     f = np.poly1d((a, b))
     xx = np.linspace(0, 2500, 5)
     win = plot.xyplot(
         xarr,
         zarr,  #yrange=self.sig5range,
         xname=xlabel,
         yname='DN')
     plot.curve(xx, f(xx), oplot=1, lineStyle='--', color='r')
     plot.hline(self.sigrange[0], color='g')
     plot.hline(self.sigrange[1], color='g')
     return win
Exemple #2
0
 def plot_curves(self, outfile=None, interactive=False):
     if interactive:
         plot.pylab.ion()
     else:
         plot.pylab.ioff()
     indx = np.argsort(self.wlarrs[1])
     for i, amp in enumerate(self.qe):
         plot.curve(self.wlarrs[amp][indx],
                    self.qe[amp][indx],
                    oplot=i,
                    xname='wavelength (nm)',
                    yname='QE (%)',
                    xrange=(350, 1100))
         plot.xyplot(self.wlarrs[amp][indx], self.qe[amp][indx], oplot=1)
         wl = [sum(self.band_pass[band]) / 2. for band in self.qe_band[amp]]
         plot.xyplot(wl, self.qe_band[amp].values(), oplot=1, color='r')
     plot.curve(self.wlarrs[1][indx], self.ccd_qe[indx], oplot=1, color='g')
     plot.xyplot(wl, self.ccd_qe_band.values(), oplot=1, color='b')
     if outfile is not None:
         plot.save(outfile)
Exemple #3
0
 def _plot_stats(self, icol, C2, C3, oplot):
     plot.pylab.ion()
     if oplot == 0:
         rows = range(self.edge_rolloff+1, self.edge_rolloff + len(C2) + 1)
         win0 = plot.curve(rows, C2, xname='row', yname='C2')
         win0.set_title('Column %i' % icol)
         plot.hline(-self.C2_thresh)
     win1 = plot.xyplot(C2, C3, xname='C2', yname='C3', oplot=oplot)
     win1.set_title('Column %i' % icol)
     plot.hline(self.C3_thresh)
     plot.vline(-self.C2_thresh)
Exemple #4
0
    def __init__(self, scan_file, ccd_cal_file, sph_cal_file):
        data = np.recfromtxt(scan_file, names=True)
        self.wavelengths = data['wl']
        pd_ccd = PhotodiodeResponse(ccd_cal_file)
        pd_sph = PhotodiodeResponse(sph_cal_file)
        intsphere = data['intsphere'] / pd_sph(self.wavelengths)
        ccdpos = data['ccdpos'] / pd_ccd(self.wavelengths)
        self.ccdfrac = ccdpos / intsphere
        Interpolator.__init__(self, self.wavelengths, self.ccdfrac)


if __name__ == '__main__':
    import pylab_plotter as plot

    pd1 = PhotodiodeResponse('OD142.csv')
    pd2 = PhotodiodeResponse('OD143.csv')

    lamb = np.linspace(400, 1000, 200)
    plot.curve(lamb,
               pd1(lamb),
               xname='wavelength (nm)',
               yname='Photodiode response')
    plot.curve(lamb, [pd2(x) for x in lamb], oplot=1, color='r')

    ccd_frac = CcdIllumination('WLscan.txt', 'OD142.csv', 'OD143.csv')

    plot.curve(lamb,
               ccd_frac(lamb),
               xname='wavelength (nm)',
               yname='ratio of illumination at CCD to integrating sphere')
Exemple #5
0
 def plot_diagnostics(self, flux, Ne, indxp, f1, fp):
     plot.pylab.ion()
     plot.xyplot(flux, Ne)
     plot.xyplot(flux[indxp], Ne[indxp], oplot=1, color='r')
     plot.curve(flux, f1(flux), oplot=1)
     plot.curve(flux, fp(flux), oplot=1, color='b')
Exemple #6
0
def full_well(ptcfile,
              amp,
              gain=None,
              fracdevmax=0.10,
              make_plot=False,
              outfile_prefix=None):
    data = np.recfromtxt(ptcfile)
    data = data.transpose()

    exptime = data[0]
    meanDN = data[(amp - 1) * 2 + 1]
    varDN = data[(amp - 1) * 2 + 2]

    if gain is None:
        gain = gain_est(meanDN, varDN)
    #
    # Convert from DN to e-.
    #
    meanNe = gain * meanDN
    varNe = gain * varDN
    #
    # Find the reference e- signal level.
    #
    xref = 1000.
    indx = 0
    while meanNe[indx] < xref:
        indx += 1
    #
    # Linear fit local to this point.
    #
    imin = max(0, indx - 3)
    imax = imin + 5
    f = np.poly1d(np.polyfit(meanNe[imin:imax], varNe[imin:imax], 1))
    fref = f(xref)
    #
    # Loop over signal level points greater than this, compute linear
    # and quadratic fit anchored at xref(=1000e-), and compute maximum
    # deviation.
    #
    dvarmax = 0
    imax = indx + 10
    while dvarmax < fracdevmax and imax < len(meanNe) - 1:
        xx = meanNe[indx:imax]
        ff = varNe[indx:imax]

        slope = linear_fit_fixedpt(xx, ff, xref, fref)
        f1 = lambda x: slope * (x - xref) + fref

        quadfit = quadratic_fit_fixedpt(xx, ff, xref, fref)
        f2 = lambda x: quadfit[0] * (x**2 - xref**2) + quadfit[1] * (x - xref
                                                                     ) + fref
        #
        # Here the fractional deviation is computed at the current
        # end-point for the data that are fit.  May need to check the
        # extremum of f1-f2. If "deviation *below* the linear curve"
        # is the criterion, then the current implementation is ok.
        #
        #fracdev = lambda x : np.abs(f1(x) - f2(x))/f1(x)
        fracdev = lambda x: (f1(x) - f2(x)) / f1(x)
        full_well_est = meanNe[imax]
        dvarmax = fracdev(full_well_est)
        imax += 1

    if make_plot and plot is not None:
        win0 = plot.xyplot(meanNe, varNe, xname='mean(e-)', yname='var(e-)')
        plot.xyplot(xx, ff, oplot=1, color='r')
        x = np.linspace(xref, meanNe[imax], 100)
        plot.curve(x, f1(x), oplot=1, lineStyle=':')
        plot.curve(x, f2(x), oplot=1, lineStyle='--')
        plot.vline(full_well_est)
        win0.set_title('Amp %i, full well = %i e-' % (amp, full_well_est))
        if outfile_prefix is not None:
            plot.save(outfile_prefix + '_ptc.png')

        win1 = plot.curve(x,
                          fracdev(x),
                          xname='mean(e-)',
                          yname='fractional deviation from linear fit')
        plot.hline(fracdevmax)
        plot.vline(full_well_est)
        win1.set_title('Amp %i, full well = %i e-' % (amp, full_well_est))
        if outfile_prefix is not None:
            plot.save(outfile_prefix + '_fracdev.png')

    return full_well_est
Exemple #7
0
interval2 = num.sort(ra.random(20)) + interval1[-1]

seq = num.concatenate((interval0, interval1, interval2))

bb = BayesianBlocks.BayesianBlocks(seq)
bbp = BayesianBlocks_python.BayesianBlocks(seq)

xr = (0, 3)
bins = 50
binsize = float(xr[1] - xr[0])/bins
win0 = plot.Window(0)
plot.histogram(seq, xrange=xr, bins=bins)

for ncpPrior in range(1, 10):
    xx, yy = bb.lightCurve(ncpPrior)
    plot.curve(xx, num.array(yy)*binsize, color='r', linewidth=3)

    xxp, yyp = bbp.lightCurve(ncpPrior)
    plot.curve(xxp, num.array(yyp)*binsize, color='b', linewidth=1)

#
# Exposure weighting in unbinned mode
#
exposures = ra.random(len(seq))
bb.setCellSizes(exposures)

win1 = plot.Window(1)
for ncpPrior in range(1, 10):
    xx, yy = bb.lightCurve(ncpPrior)
    plot.curve(xx, num.array(yy)*binsize, color='r', linewidth=5)