Ejemplo n.º 1
0
    def simTOT(self, oImg, tImg, subImgNum=1000):

        mchFile, nmhFile = self.runSelfMatch(self.objectImgCatNew, 24)
        self.osn32 = nmhFile

        osn16s = selectTempOTs(self.osn16, self.tmpDir)
        tdata = np.loadtxt("%s/%s" % (self.tmpDir, osn16s))
        if len(tdata.shape) < 2 or tdata.shape[0] < 100:
            print("%s has too little stars, break this run" % (oImg))
            return np.array([]), np.array([])

        osn16sf = filtOTs(osn16s, self.tmpDir)
        tdata = np.loadtxt("%s/%s" % (self.tmpDir, osn16sf))
        if len(tdata.shape) < 2 or tdata.shape[0] < 45:
            print("%s has too little stars, break this run" % (oImg))
            return np.array([]), np.array([])

        osn32f = filtOTs(self.osn32, self.tmpDir)

        totalTOT = subImgNum
        subImgBuffer = []
        objS2NBuffer = []
        tnum = 0
        imgSimClass = ImageSimulation()

        ii = 1
        sexConf = [
            '-DETECT_MINAREA', '3', '-DETECT_THRESH', '2.5',
            '-ANALYSIS_THRESH', '2.5'
        ]
        while tnum < totalTOT:
            simFile, simPosFile, simDeltaXYA, tmpOtImgs = imgSimClass.simulateImage1(
                osn32f, self.newImageName, osn16sf, self.newImageName)
            self.objectImgSim = simFile
            self.objectImgSimAdd = simPosFile

            self.runSextractor(self.objectImgSim)

            self.simTmpResi = self.runHotpants(self.objectImgSim,
                                               self.templateImg)
            self.simTmpResiCat = self.runSextractor(self.simTmpResi, sexConf)

            simTmpResiCatEf = filtByEllipticity(self.simTmpResiCat,
                                                self.tmpDir,
                                                maxEllip=0.5)
            mchFile, nmhFile = self.runSelfMatch(simTmpResiCatEf, 16)
            simTmpResiCatEf_sn32 = nmhFile
            #simTmpResiCatEf_sn32 = simTmpResiCatEf

            mchFile, nmhFile, mchPair = self.runCrossMatch(
                simTmpResiCatEf_sn32, self.objectImgSimAdd, 1)
            tdata1 = np.loadtxt("%s/%s" % (self.tmpDir, mchFile))
            poslist = tdata1[:, 0:2]
            size = 100
            subImgs = self.getWindowImgs(self.objectImgSim, self.templateImg,
                                         self.simTmpResi, poslist, size)
            tnum = tnum + len(subImgs)

            ts2n = tdata1[:, 3]
            subImgBuffer.extend(subImgs)
            objS2NBuffer.extend(ts2n.tolist())

            self.log.info("\n******************")
            self.log.info("run %d, total sub image %d" % (ii, tnum))
            if ii > 6:
                break
            ii = ii + 1
            #break

        subImgs = np.array(subImgBuffer)
        objS2NBuffer = np.array(objS2NBuffer)
        print(subImgs.shape)
        print(objS2NBuffer.shape)

        return subImgs, objS2NBuffer
Ejemplo n.º 2
0
    def simTOT(self, oImg, tImg, subImgNum=1000):

        mchFile, nmhFile = self.runSelfMatch(self.objectImgCat, 24)
        self.osn32 = nmhFile

        osn16s = selectTempOTs(self.osn16, self.tmpDir)
        tdata = np.loadtxt("%s/%s" % (self.tmpDir, osn16s))
        if len(tdata.shape) < 2 or tdata.shape[0] < 100:
            print("%s has too little stars, break this run" % (oImg))
            return np.array([]), np.array([])

        osn16sf = filtOTs(osn16s, self.tmpDir)
        tdata = np.loadtxt("%s/%s" % (self.tmpDir, osn16sf))
        if len(tdata.shape) < 2 or tdata.shape[0] < 45:
            print("%s has too little stars, break this run" % (oImg))
            return np.array([]), np.array([])

        osn32f = filtOTs(self.osn32, self.tmpDir)

        mchFile, nmhFile, mchPair = self.runCrossMatch(osn32f, self.tsn16, 5)
        osn32s_tsn5_cm5 = mchFile
        osn32s_tsn5_cm5_pair = mchPair

        totalTOT = subImgNum
        subImgBuffer = []
        objS2NBuffer = []
        tnum = 0
        imgSimClass = ImageSimulation()

        ii = 1
        sexConf = [
            '-DETECT_MINAREA', '3', '-DETECT_THRESH', '2.5',
            '-ANALYSIS_THRESH', '2.5'
        ]
        while tnum < totalTOT:
            simFile, simPosFile, simDeltaXYA, psfImgs = imgSimClass.simulateImage1(
                osn32f, self.objectImg, osn16sf, self.objectImg)
            self.objectImgSim = simFile
            self.objectImgSimAdd = simPosFile

            self.runSextractor(self.objectImgSim)

            self.simTmpResi = self.runHotpants(self.objectImgSim,
                                               self.templateImg)
            self.simTmpResiCat = self.runSextractor(self.simTmpResi, sexConf)

            simTmpResiCatEf = filtByEllipticity(self.simTmpResiCat,
                                                self.tmpDir,
                                                maxEllip=0.5)
            mchFile, nmhFile = self.runSelfMatch(simTmpResiCatEf, 16)
            simTmpResiCatEf_sn32 = nmhFile
            #simTmpResiCatEf_sn32 = simTmpResiCatEf

            mchFile, nmhFile, mchPair = self.runCrossMatch(
                self.objectImgSimAdd, simTmpResiCatEf_sn32, self.r5)
            str_oisa_cm5 = mchFile
            str_oisa_cm5_pair = mchPair

            tIdx1 = np.loadtxt(
                "%s/%s" % (self.tmpDir, osn32s_tsn5_cm5_pair)).astype(np.int)
            tIdx2 = np.loadtxt("%s/%s" %
                               (self.tmpDir, str_oisa_cm5_pair)).astype(np.int)
            tIdx1 = tIdx1 - 1
            tIdx2 = tIdx2 - 1
            self.log.debug(
                "objectCat matched data %d, ResiCat matched data %d" %
                (tIdx1.shape[0], tIdx2.shape[0]))

            tnames1 = ['objId', 'tmpId']
            tnames2 = ['objId', 'resiId']

            #unionIdx = np.intersect1d(tIdx1[:,0], tIdx2[:,0])  #union1d
            #self.log.debug("intersect objectCat and templateCat matched data: %d"%(unionIdx.shape[0]))

            df1 = pd.DataFrame(data=tIdx1, columns=tnames1)
            df2 = pd.DataFrame(data=tIdx2, columns=tnames2)
            unionIdx = pd.merge(df1, df2, how='inner', on=['objId'])
            self.log.debug(
                "innerjoin objectCat and templateCat matched data %d" %
                (unionIdx.shape[0]))

            tdata1 = np.loadtxt("%s/%s" % (self.tmpDir, self.objectImgSimAdd))
            tdata2 = np.loadtxt("%s/%s" % (self.tmpDir, self.tsn16))
            tdata3 = np.loadtxt("%s/%s" % (self.tmpDir, simTmpResiCatEf_sn32))

            simDeltaXYA = np.array(simDeltaXYA)
            tdeltaXYA = simDeltaXYA[unionIdx["objId"].values]
            tdata11 = tdata1[unionIdx["objId"].values]
            tdata12 = tdata2[unionIdx["tmpId"].values]
            tdata22 = tdata3[unionIdx["resiId"].values]

            poslist = np.concatenate(([tdata11[:, 0]], [tdata11[:, 1]], [
                tdata12[:, 3] + tdeltaXYA[:, 0]
            ], [tdata12[:, 4] + tdeltaXYA[:, 1]], [tdata22[:, 0]
                                                   ], [tdata22[:, 1]]),
                                     axis=0).transpose()
            #print(poslist)
            #genFinalOTDs9Reg('tot', self.tmpDir, poslist)
            #size = self.subImgSize
            size = 100
            subImgs = self.getWindowImgs(self.objectImgSim, self.templateImg,
                                         self.simTmpResi, poslist, size)
            #subImgs = self.getWindowImgs(self.objectImgSimSubBkg, self.templateImgSubBkg, self.simTmpResi, poslist, size)
            tnum = tnum + len(subImgs)

            subImgBuffer.extend(subImgs)
            objS2NBuffer.extend(tdata22[:, 3].tolist())

            self.log.info("\n******************")
            self.log.info("run %d, total sub image %d" % (ii, tnum))
            if ii > 6:
                break
            ii = ii + 1
            #break

        subImgs = np.array(subImgBuffer)
        objS2NBuffer = np.array(objS2NBuffer)
        print(subImgs.shape)
        print(objS2NBuffer.shape)

        return subImgs, objS2NBuffer
Ejemplo n.º 3
0
    def simTOT(self, oImg, tImg, subImgNum=100):
        
        mchFile, nmhFile = self.runSelfMatch(self.objectImgCat, 24)
        self.osn32 = nmhFile

        osn16s = selectTempOTs(self.osn16, self.tmpDir)
        osn16sf = filtOTs(osn16s, self.tmpDir)
        osn32f = filtOTs(self.osn32, self.tmpDir)
        
        mchFile, nmhFile, mchPair = self.runCrossMatch(osn32f, self.tsn5, self.r5)
        osn32s_tsn5_cm5 = mchFile
        osn32s_tsn5_cm5_pair = mchPair
        
        totalTOT = subImgNum
        subImgBuffer = []
        tnum = 0
        imgSimClass = ImageSimulation()
        
        ii = 1
        sexConf=['-DETECT_MINAREA','3','-DETECT_THRESH','2.5','-ANALYSIS_THRESH','2.5']
        while tnum<totalTOT:
            simFile, simPosFile, simDeltaXYA = imgSimClass.simulateImage1(osn32f, self.objectImg, osn16sf, self.objectImg)
            self.objectImgSim = simFile
            self.objectImgSimAdd = simPosFile
            
            self.simTmpResi = self.runHotpants(self.objectImgSim, self.templateImg)
            objectImgSimCat = self.runSextractor(self.simTmpResi, sexConf)
            
            tdata0 = np.loadtxt("%s/%s"%(self.tmpDir, objectImgSimCat))
            print(tdata0.shape)
            
            simTmpResiCatEf = filtByEllipticity(objectImgSimCat, self.tmpDir, maxEllip=0.5)
            mchFile, nmhFile = self.runSelfMatch(simTmpResiCatEf, self.r5)
            simTmpResiCatEf_sn32 = nmhFile
            #simTmpResiCatEf_sn32 = simTmpResiCatEf
            
            
            mchFile, nmhFile, mchPair = self.runCrossMatch(self.objectImgSimAdd, simTmpResiCatEf_sn32, self.r5)
            str_oisa_cm5 = mchFile
            str_oisa_cm5_pair = mchPair
            
            
            tIdx1 = np.loadtxt("%s/%s"%(self.tmpDir, osn32s_tsn5_cm5_pair)).astype(np.int)
            tIdx2 = np.loadtxt("%s/%s"%(self.tmpDir, str_oisa_cm5_pair)).astype(np.int)
            tIdx1 = tIdx1 - 1
            tIdx2 = tIdx2 - 1
            self.log.debug("objectCat matched data %d, templateCat matched data %d"%(tIdx1.shape[0], tIdx2.shape[0]))
                    
            tnames1 = ['objId', 'tmpId']
            tnames2 = ['objId', 'resiId']
            
            #unionIdx = np.intersect1d(tIdx1[:,0], tIdx2[:,0])  #union1d
            #self.log.debug("intersect objectCat and templateCat matched data: %d"%(unionIdx.shape[0]))
            
            df1 = pd.DataFrame(data=tIdx1, columns=tnames1)
            df2 = pd.DataFrame(data=tIdx2, columns=tnames2)
            unionIdx=pd.merge(df1, df2, how='inner', on=['objId'])
            self.log.debug("innerjoin objectCat and templateCat matched data %d"%(unionIdx.shape[0]))
            
            tdata1 = np.loadtxt("%s/%s"%(self.tmpDir, self.objectImgSimAdd))
            tdata2 = np.loadtxt("%s/%s"%(self.tmpDir, self.tsn5))
            tdata3 = np.loadtxt("%s/%s"%(self.tmpDir, simTmpResiCatEf_sn32))
            
            simDeltaXYA = np.array(simDeltaXYA)
            tdeltaXYA = simDeltaXYA[unionIdx["objId"].values]
            tdata11 = tdata1[unionIdx["objId"].values]
            tdata12 = tdata2[unionIdx["tmpId"].values]
            tdata22 = tdata3[unionIdx["resiId"].values]
            
            print(tdata22.shape)
            print("sim star %d, matched %d"%(tdata1.shape[0],tIdx2.shape[0]))
            
            magerr = tdata22[:,3]
            print(magerr[:10])
                        
            from matplotlib.ticker import MultipleLocator, FormatStrFormatter
            xmajorLocator   = MultipleLocator(2)
            xminorLocator   = MultipleLocator(1)
            
            plt.figure(figsize = (16, 8))
            ax = plt.subplot(111)
            plt.hist(magerr, bins=20, range=(0,20), normed=False,     
                    weights=None, cumulative=False, bottom=None,     
                    histtype=u'bar', align=u'left', orientation=u'vertical',     
                    rwidth=0.8, log=False, color=None, label=None, stacked=False,     
                    hold=None) 
            ax.xaxis.set_major_locator(xmajorLocator)
            ax.xaxis.set_minor_locator(xminorLocator)
            plt.show()
            
        
            self.log.info("\n******************")
            self.log.info("run %d, total sub image %d"%(ii, tnum))
            if ii>0:
                break
            ii = ii + 1
        
        rsts = np.array(subImgBuffer)
        print(rsts.shape)
        
        return rsts