示例#1
0
def makeHist(output, catalog, number):
    record = catalog[number]
    baseHsmKey = afwTable.QuadrupoleKey(
        catalog.schema["ext_shapeHSM_HsmSourceMoments"])
    baseSimpleKey = afwTable.QuadrupoleKey(
        catalog.schema["ext_simpleShape_SimpleShape"])
    baseSdssKey = afwTable.QuadrupoleKey(catalog.schema["base_SdssShape"])
    extract = lambda s: [s.getIxx(), s.getIyy(), s.getIxy()]
    hsmShape = extract(record.get(baseHsmKey))
    simpleShape = extract(record.get(baseSimpleKey))
    sdssShape = extract(record.get(baseSdssKey))
    for i in range(3):
        plt.figure(i)
        plt.hist(output[3][:, i], bins=50)
        plt.axvline(hsmShape[i], c='m', label='hsm')
        plt.axvline(simpleShape[i], c='r', label='simple')
        plt.axvline(sdssShape[i], c='y', label='sdss')
        plt.legend()
示例#2
0
def plotEllipse(stamp,
                record,
                fig=plt.figure(),
                position=111,
                show=True,
                extra=None):
    baseHsmKey = "ext_shapeHSM_HsmSourceMoments"
    baseSimpleKey = "ext_simpleShape_SimpleShape"
    baseSdssKey = "base_SdssShape"
    allKeys = [baseHsmKey, baseSimpleKey, baseSdssKey]
    colors = ['w', 'm', 'k']
    ax = fig.add_subplot(position)
    imshowData = ax.imshow(stamp.array)
    for color, shapeKey in zip(colors, allKeys):
        eKey = afwTable.QuadrupoleKey(record.schema[shapeKey])
        print(record.get(eKey))
        print(afwGeom.ellipses.Axes(record.get(eKey)))
        ellipse = afwGeom.ellipses.Axes(record.get(eKey))
        centerE = record.getCentroid() - stamp.getXY0()
        centerE = centerE.asPoint()
        center = (centerE.getX(), centerE.getY())
        ax.add_patch(
            mpatch.Ellipse(center,
                           ellipse.getA(),
                           ellipse.getB(),
                           np.rad2deg(ellipse.getTheta()),
                           fill=False,
                           color=color,
                           label=shapeKey))
    fig.colorbar(imshowData)
    if extra is not None:
        quad = afwGeom.ellipses.Quadrupole(*extra)
        axes = afwGeom.ellipses.Axes(quad)
        ax.add_patch(
            mpatch.Ellipse(center,
                           axes.getA(),
                           axes.getB(),
                           np.rad2deg(axes.getTheta()),
                           fill=False,
                           color='r',
                           label='Fit'))

    ax.legend()
    if show:
        fig.show()
示例#3
0
def plotEllipse(stamp,
                record,
                shapeKey,
                fig=plt.Figure(),
                position=111,
                show=True):
    ax = fig.add_subplot(position)
    ax.imshow(stamp.array)
    eKey = afwTable.QuadrupoleKey(record.schema[shapeKey])
    ellipse = afwGeom.ellipses.Axes(record.get(eKey))
    centerE = record.getCentroid() - stamp.getXY0()
    centerE = centerE.asPoint()
    center = (centerE.getX(), centerE.getY())
    ax.add_patch(
        mpatch.Ellipse(center,
                       ellipse.getA(),
                       ellipse.getB(),
                       ellipse.getTheta(),
                       fill=False))
    if show:
        plt.show()
    def testRejectBlends(self):
        """Test the PcaPsfDeterminerTask blend removal."""
        """
        We give it a single blended source, asking it to remove blends,
        and check that it barfs in the expected way.
        """

        psfDeterminerClass = measAlg.psfDeterminerRegistry["pca"]
        config = psfDeterminerClass.ConfigClass()
        config.doRejectBlends = True
        psfDeterminer = psfDeterminerClass(config=config)

        schema = afwTable.SourceTable.makeMinimalSchema()
        # Use The single frame measurement task to populate the schema with standard keys
        measBase.SingleFrameMeasurementTask(schema)
        catalog = afwTable.SourceCatalog(schema)
        source = catalog.addNew()

        # Make the source blended, with necessary information to calculate pca
        spanShift = afwGeom.Point2I(54, 123)
        spans = afwGeom.SpanSet.fromShape(6, offset=spanShift)
        foot = afwDetection.Footprint(spans, self.exposure.getBBox())
        foot.addPeak(45, 123, 6)
        foot.addPeak(47, 126, 5)
        source.setFootprint(foot)
        centerKey = afwTable.Point2DKey(source.schema['slot_Centroid'])
        shapeKey = afwTable.QuadrupoleKey(schema['slot_Shape'])
        source.set(centerKey, afwGeom.Point2D(46, 124))
        source.set(shapeKey, afwGeom.Quadrupole(1.1, 2.2, 1))

        candidates = [measAlg.makePsfCandidate(source, self.exposure)]
        metadata = dafBase.PropertyList()

        with self.assertRaises(RuntimeError) as cm:
            psfDeterminer.determinePsf(self.exposure, candidates, metadata)
        self.assertEqual(str(cm.exception),
                         "All PSF candidates removed as blends")
示例#5
0
def printShapes(catalog, number):
    baseHsmKey = "ext_shapeHSM_HsmSourceMoments"
    baseSimpleKey = "ext_simpleShape_SimpleShape"
    baseSdssKey = "base_SdssShape"
    for n in [baseHsmKey, baseSimpleKey, baseSdssKey]:
        print(catalog[number][afwTable.QuadrupoleKey(catalog.schema[n])], n)
示例#6
0
    count += len(cat)

totalCatalog = afwTable.SourceCatalog(catalogs[0].schema)
totalCatalog.reserve(count)
imageId = []
for n in range(len(catalogs)):
    for record in catalogs[n]:
        tmpRecord = totalCatalog.addNew()
        tmpRecord.assign(record)
        imageId.append(n)

baseHsmKey = "ext_shapeHSM_HsmSourceMoments"
baseSdssKey = "base_SdssShape"
fluxKey = "base_GaussianFlux_flux"

SdssKey = afwTable.QuadrupoleKey(totalCatalog.schema[baseSdssKey])
HsmKey = afwTable.QuadrupoleKey(totalCatalog.schema[baseHsmKey])

flux = []
radius = []
shape = []
positions = []

catLen = len(totalCatalog)
for i, record in enumerate(totalCatalog):
    if i % 1000 == 0:
        print("Record {}  out of {}".format(i, catLen))

    gausFlux = record[fluxKey]
    if np.isnan(gausFlux):
        continue