Пример #1
0
 def find_hits(self, nsig=2, gain_range=(2, 10), buff=1, make_plots=True):
     DN_range = (self.fe55_yield / gain_range[1],
                 self.fe55_yield / gain_range[0])
     threshold = afwDetect.Threshold(self.mean + nsig * self.stdev)
     fpset = afwDetect.FootprintSet(self.image, threshold)
     zarr, xarr, yarr, peaks = [], [], [], []
     for fp in fpset.getFootprints():
         if fp.getNpix() < 9:
             f, ix, iy, peak_value = self._footprint_info(fp, buff)
             if ((DN_range[0] < f < DN_range[1])
                     and not (fp.contains(afwGeom.Point2I(ix - 1, iy))
                              or fp.contains(afwGeom.Point2I(ix, iy - 1)))):
                 zarr.append(f)
                 xarr.append(ix)
                 yarr.append(iy)
                 peaks.append(peak_value)
     self.xarr = np.array(xarr)
     self.yarr = np.array(yarr)
     self.zarr = np.array(zarr)
     self.peaks = np.array(peaks)
     median_signal = imUtils.median(self.zarr)
     self.median_signal = median_signal
     self.sigrange = (median_signal * (1. - 2. / np.sqrt(self.fe55_yield)),
                      median_signal * (1. + 2. / np.sqrt(self.fe55_yield)))
     self.sig5range = (median_signal * (1. - 5. / np.sqrt(self.fe55_yield)),
                       median_signal * (1. + 5. / np.sqrt(self.fe55_yield)))
     if plot is not None and make_plots:
         plot.histogram(self.zarr,
                        xrange=self.sig5range,
                        yrange=(0, 200),
                        bins=100,
                        xname='DN',
                        yname='entries / bin')
         plot.vline(median_signal)
         plot.vline(self.sigrange[0], color='g')
         plot.vline(self.sigrange[1], color='g')
         plot.xyplot(xarr,
                     zarr,
                     yrange=DN_range,
                     xname='x pixel',
                     yname='DN')
         plot.hline(self.sigrange[0], color='g')
         plot.hline(self.sigrange[1], color='g')
Пример #2
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)
Пример #3
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
Пример #4
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)
Пример #5
0
    flags = afwMath.MEDIAN | afwMath.STDEVCLIP

    stats = afwMath.makeStatistics(results['sigmax'], flags)
    median = stats.getValue(afwMath.MEDIAN)
    stdev = stats.getValue(afwMath.STDEVCLIP)
    plot.histogram(results['sigmax'],
                   xname='Fitted sigma values',
                   xrange=(median - 3 * stdev, median + 3 * stdev))
    plot.histogram(results['sigmay'],
                   oplot=1,
                   color='r',
                   xrange=(median - 3 * stdev, median + 3 * stdev))

    plot.histogram(results['dn'], xname='Fitted DN values', xrange=(250, 450))

    plot.xyplot(results['chiprob'],
                results['sigmax'],
                xname='chi-square prob.',
                yname='sigma',
                ylog=1)

    plot.xyplot(results['chiprob'], results['sigmay'], oplot=1, color='r')

    plot.xyplot(results['dn'],
                results['dn_fp'],
                xname='DN (fitted value)',
                yname='DN (footprint sum)',
                xrange=(0, max(results['dn_fp'])),
                yrange=(0, max(results['dn_fp'])))
Пример #6
0
    events = num.sort(events)
    ncp_prior = BayesianBlocks.BayesianBlocks.ncp_prior(nsamp, fp_frac)
    tstart = time.time()
    bb = BB_imp.BayesianBlocks(events)
    x, y = bb.lightCurve(ncp_prior)
    dt = time.time() - tstart
    return dt, len(x) - 2


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

    nsamp = 200
    fp_frac = 1e-3
    nsamps = (10, 30, 100, 300, 1000)
    dts = [running_time(BayesianBlocks, nsamp=nsamp)[0] for nsamp in nsamps]

    nsamps = (10, 30, 100, 300, 1000)
    dts_p = [
        running_time(BayesianBlocks_python, nsamp=nsamp)[0]
        for nsamp in nsamps[:4]
    ]

    plot.xyplot(nsamps, dts, xlog=1, ylog=1)
    plot.xyplot(nsamps[:4],
                dts_p,
                color='r',
                yrange=(min(dts) / 1.3, max(dts_p) * 1.3),
                xname='Sample size',
                yname='Running time (cpusec)')
Пример #7
0
        for i, item in enumerate(self.files):
            print i, item
            forced = pd.read_pickle(item)
            lc_data = forced.merge(ccdVisit, on='ccdVisitId')
            selection = (lc_data['objectId'] == objectId)
            if band is not None:
                selection = selection & (lc_data['filterName'] == band)
            if i == 0:
                df = lc_data[selection]
            else:
                df = df.append(lc_data[selection])
        return df

forced_files = sorted(glob.glob('forced*.pkl'))

t0 = time.time()
forced_data = ForcedSourceData(forced_files)
t1 = time.time()
df = forced_data(1628)
t2 = time.time()

print 'execution times:', t2 - t1

mjd = df['obsStart']
flux = df['psFlux']
fluxerr = df['psFlux_Sigma']

print len(mjd)

plot.xyplot(mjd, flux, yerr=fluxerr, xname='mjd', yname='flux')
Пример #8
0
results['nsig'] = np.sqrt(2.*results['chisq']) - np.sqrt(2.*results['ndof']-1.)
results['dz'] = results['z'] - results['z_model']

nsig = plot.histogram(results['nsig'], xname='nsig', xrange=(0, 200))
plot.vline(100, color='r')
plot.vline(30, color='g')
plot.vline(10, color='b')

dz_range = 0, 0.5
dz_hist = plot.histogram(results['dz'], xrange=dz_range, xname='z - z_model')

selection = results['nsig'] < 100.
plot.histogram(results[selection]['dz'], xrange=dz_range, oplot=1, color='r')

z_vs_zmod = plot.xyplot(results[selection]['z_model'], results[selection]['z'],
                        xname='z_model', yname='z', color='r')

selection = results['nsig'] < 30.
plot.set_window(dz_hist)
plot.histogram(results[selection]['dz'], xrange=dz_range, oplot=1, color='g')
plot.set_window(z_vs_zmod)
plot.xyplot(results[selection]['z_model'], results[selection]['z'],
            xname='z_model', yname='z', oplot=1, color='g')

selection = results['nsig'] < 10.
plot.set_window(dz_hist)
plot.histogram(results[selection]['dz'], xrange=dz_range, oplot=1, color='b')
plot.set_window(z_vs_zmod)
plot.xyplot(results[selection]['z_model'], results[selection]['z'],
            xname='z_model', yname='z', oplot=1, color='b')
Пример #9
0
    events = ra.random(nsamp)
    events = num.sort(events)
    ncp_prior = BayesianBlocks.BayesianBlocks.ncp_prior(nsamp, fp_frac)
    tstart = time.time()
    dt_avg = num.mean(events[1:] - events[:-1])
    tmin = events[0] - dt_avg
    tmax = events[-1] + dt_avg
    bb = BB_imp.BayesianBlocks(events, tmin, tmax)
    x, y = bb.lightCurve(ncp_prior)
    dt = time.time() - tstart
    return dt, len(x) - 2


if __name__ == '__main__':
    import pylab_plotter as plot
    plot.pylab.ion()

    nsamp = 200
    fp_frac = 1e-3
    nsamps = (10, 30, 100, 300, 1000)
    dts = [running_time(BayesianBlocks, nsamp=nsamp)[0] for nsamp in nsamps]

    #    nsamps = (10, 30, 100, 300, 1000)
    #    dts_p = [running_time(BayesianBlocks_python, nsamp=nsamp)[0]
    #             for nsamp in nsamps[:4]]

    plot.xyplot(nsamps, dts, xlog=1, ylog=1)
#    plot.xyplot(nsamps[:4], dts_p, color='r',
#                yrange=(min(dts)/1.3, max(dts_p)*1.3),
#                xname='Sample size', yname='Running time (cpusec)')
Пример #10
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')
Пример #11
0
                               edgecolor=color)
    return intervals

#grb_ids = read_data('asp_blind_search.txt', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_24Oct2012.dat', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_12Jul2013.txt', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_20Nov2013.txt', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_26Aug2014.txt', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_14Mar2015.txt', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_01Nov2015.txt', ncols=1)[0]
#grb_ids = read_data('blind_search_triggers_13Mar2016.txt', ncols=1)[0]
grb_ids = read_data('blind_search_triggers_24Aug2016.txt', ncols=1)[0]
asp_grbs = read_data('asp_grbs.txt', ncols=1)[0]

npts = len(grb_ids)
win = plot.xyplot(mjd(grb_ids), range(npts), xname='MJD', yname='#trigger')

indx = [num.where(x == grb_ids)[0][0] for x in asp_grbs]
plot.xyplot(mjd(asp_grbs), indx, color='r', oplot=1)

#time, accidentals = read_data('accidentals_vs_time.dat')
#plot.curve(mjd(time), accidentals/1.744e3*2, oplot=1, color='r')

# March 6-7, 2012 X5-class flares
march_sf = (met(datetime.datetime(2012, 3, 6)),
            met(datetime.datetime(2012, 3, 8)))
plot.pylab.axvspan(mjd(march_sf[0]), mjd(march_sf[1]), color='r')

# Crab pointed observation not in FSSC pointed list
crab_2012_pointing = (met(datetime.datetime(2012, 7, 5, 0, 0, 0)),
                      met(datetime.datetime(2012, 7, 8, 12, 38, 01)))
Пример #12
0
            self._plot_stats(icol, C2, C3, oplot)
        return ix, iy, c2, c3, a0, a1
    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)

if __name__ == '__main__':
    from MaskedCCD import MaskedCCD
    trap_file = '../20141118-184914/114-03_trap_000.fits'
    ccd = MaskedCCD(trap_file)
    amp = 4

    finder = TrapFinder(ccd, amp)
    results = finder.find()
    for row in zip(*results):
        print row

    index = np.where(results[2] == min(results[2]))
    finder.process_column(results[0][index[0][0]]-4, True)
    for icol in range(509):
        finder.process_column(icol, True, oplot=1)
    plot.xyplot(results[2], results[3], oplot=1, color='r')
Пример #13
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
Пример #14
0
        if filter_uls:
            index = np.where((self.data.field('NAME') == source_name) & 
                             (ul == False))
        else:
            index = np.where(self.data.field('NAME') == source_name)
        return self.tmid[index], flux[index], error[index], ul[index]

if __name__ == '__main__':
    import pylab_plotter as plot
    plot.pylab.ion()

    lcdata = FermiLightCurveData('gll_asp_0457833600_v00.fit')

    source = '3C 454.3'
    t, f, df, ul = lcdata.light_curve(source)
    win = plot.xyplot(t, f, yerr=df, xname='MJD', yname='flux (ph/cm^2/s)',
                      yrange=(0, 1.1*max(f)))
    win.set_title('%s, 100 to 300000 MeV' % source)
    plot.save('3C_454.3_100_300000.png')

    t1, f1, df1, ul1 = lcdata.light_curve(source, eband='300_1000')
    win1 = plot.xyplot(t1, f1, yerr=df1, xname='MJD', yname='flux (ph/cm^2/s)',
                       yrange=(0, 1.1*max(f1)))
    win1.set_title('%s, 300 to 1000 MeV' % source)
    plot.save('3C_454.3_300_1000.png')

    t2, f2, df2, ul2 = lcdata.light_curve(source, eband='1000_300000')
    win2 = plot.xyplot(t2, f2, yerr=df2, xname='MJD', yname='flux (ph/cm^2/s)',
                       yrange=(0, 1.1*max(f2)))
    win2.set_title('%s, 1000 to 300000 MeV' % source)
    plot.save('3C_454.3_1000_300000.png')
Пример #15
0
        if i < len(self.bins):
            self.bins[i] += wt

hist = Histogram(0, 20, 30)
for i in range(100):
    hist.add(func0.draw())

bb = BayesianBlocks.BayesianBlocks(hist.xvals[0] - hist.xstep/2.,
                                   hist.bins, 
                                   num.ones(len(hist.bins), dtype=num.float)*hist.xstep)
                                    
bbp = BayesianBlocks_python.BayesianBlocks(hist.bins, 
                                           num.ones(len(hist.bins))*hist.xstep,
                                           hist.xvals[0] - hist.xstep/2.)
win2 = plot.Window(2)
plot.xyplot(hist.xvals, hist.bins/hist.xstep, yerr=num.sqrt(hist.bins))
for ncpPrior in range(1, 10):
    xx, yy = bb.lightCurve(ncpPrior)
    plot.curve(xx, yy, color='r', linewidth=3)

    print ncpPrior
    xxp, yyp = bbp.lightCurve(ncpPrior)
    plot.curve(xxp, yyp, color='g', linewidth=1)

#
# Point measurement mode
#
func1 = Gaussian(1, 5, 1)
func2 = Gaussian(1, 10, 1)
func3 = Gaussian(1, 6, 1)