Example #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')
Example #2
0
    fitter = PsfGaussFit(nsig=nsig, outfile=outfile, fit_xy=fit_xy)
    for amp in ccd.keys()[2:]:
        print "processing amp:", amp
        fitter.process_image(ccd, amp)
    fitter.write_results(outfile)

    results = fitter.results()

    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')
import glob
import numpy as np
import pandas as pd
import pylab_plotter as plot
plot.pylab.ion()

#results_file = 'sncosmo_results_model_comparisons.pkl'
#results = pd.read_pickle(results_file)

infiles = sorted(glob.glob('refit_results_*.pkl'))
results = pd.concat([pd.read_pickle(infile) for infile in infiles])

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)
Example #4
0
                        type=str,
                        help='file name of list of Fe55 files')
    args = parser.parse_args()

    sensor_id = args.sensor_id

    files = args.files(args.file_pattern, args.Fe55_file_list)

    fitter = PsfGaussFit()
    for infile in files:
        print(os.path.basename(infile))
        ccd = MaskedCCD(infile, mask_files=args.mask_files())
        for amp in ccd:
            print("   amp", amp)
            fitter.process_image(ccd, amp)
    outfile = os.path.join(args.output_dir, '%s_psf_params.fits' % sensor_id)
    fitter.write_results(outfile=outfile)

    sigma, dn, chiprob, amp = fitter.results()

    flags = afwMath.MEDIAN | afwMath.STDEVCLIP

    stats = afwMath.makeStatistics(sigma, flags)
    median = stats.getValue(afwMath.MEDIAN)
    stdev = stats.getValue(afwMath.STDEVCLIP)
    plot.histogram(sigma,
                   xname='Fitted sigma values',
                   xrange=(median - 3 * stdev, median + 3 * stdev))
    plot.pylab.savefig(
        os.path.join(args.output_dir, '%s_sigma_distribution.png' % sensor_id))
Example #5
0
# Unbinned mode
#
interval0 = num.sort(ra.random(20))
interval1 = num.sort(ra.random(100)) + interval0[-1]
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)