Exemple #1
0
    def source_selection(self):
             
        # signal-to-noise ratio
        self.signal_to_noise()
        # local variance
        utils.local_variance(
             self.imagedata, self.header, self.poscatalog, self.wcs,
             self.pixsize, tag=self.snr_tag,local_region=self.local_region,
             noise=self.noise, highvariance_factor= self.local_thresh,
             high_local_tag=self.high_local_tag, neg_side=True,
             setatr=False, prefix=self.prefix, do_high_loc=True)
        # correlation
        utils.psf_image_correlation(
            catalog=self.poscatalog, psfimage=self.psfname,
            imagedata=self.imagedata, header=self.header,
            wcs=self.wcs, pixelsize=self.pixsize, corr_region=
            self.psfcorr_region, thresh=self.high_corr_thresh,
            tags=self.high_local_tag, coefftag=self.high_corr_tag,
            setatr=False, do_high=True, prefix=self.prefix)
        # number of negative detections
        self.number_negatives()

        return self.poscatalog, self.negcatalog
    def get_reliability(self):


        # finding sources 
        self.source_finder(image=self.imagename, lsmname=self.poslsm, 
                           thresh=self.pos_smooth, **self.opts_pos)

        self.source_finder(image=self.negativeimage, lsmname=self.neglsm,
                           thresh=self.neg_smooth, **self.opts_neg)

        # removing sources within a specified radius
        self.remove_sources_within(catalog=self.poslsm, rel_excl_src=
                                   self.rel_excl_src)
        self.remove_sources_within(catalog=self.neglsm, rel_excl_src=
                                   self.rel_excl_src)

        # add local variance as a parameter
        if self.do_local_var:
            utils.local_variance(self.imagedata, self.header, 
                              catalog=self.poslsm, wcs=self.wcs, 
                              pixelsize=self.pixelsize, local_region=
                              self.local_var_region, savefig=False,
                              highvariance_factor=None, prefix=self.prefix,
                              neg_side=True)

            utils.local_variance(self.imagedata, self.header,
                              catalog=self.neglsm, wcs=self.wcs,
                              pixelsize=self.pixelsize, local_region=
                              self.local_var_region, savefig=False,
                              highvariance_factor=None, prefix=self.prefix, neg_side=True)
        # compute correlation if only do_psf_corr = True 
        #and the psf is provided 
        if self.do_psf_corr and self.psfname:
            utils.psf_image_correlation(
                 catalog=self.poslsm, psfimage=self.psfname,
                 imagedata=self.imagedata, header=self.header,
                 wcs=self.wcs, pixelsize=self.pixelsize,
                 corr_region=self.psf_corr_region, prefix= self.prefix)
            utils.psf_image_correlation(
                 catalog=self.neglsm, psfimage=self.psfname, 
                 imagedata=self.imagedata, header=self.header,
                 wcs=self.wcs, pixelsize=self.pixelsize, 
                 corr_region=self.psf_corr_region, prefix=self.prefix)
      
        ##TODO verbose vs. logging
        pmodel = Tigger.load(self.poslsm, verbose=self.loglevel)
        nmodel = Tigger.load(self.neglsm, verbose=self.loglevel)
        
        posSources = pmodel.sources
        negSources = nmodel.sources

        npsrc = len(posSources)
        nnsrc = len(negSources)      
 
        positive, labels = self.params(posSources, pmodel)
        negative, labels = self.params(negSources, nmodel)

        # setting up a kernel, Gaussian kernel
        bandwidth = []

        for plane in negative.T:
            bandwidth.append(plane.std())



        nplanes = len(labels)
        cov = numpy.zeros([nplanes, nplanes])


        for i in range(nplanes):
            for j in range(nplanes):
                if i == j:
                    cov[i, j] = bandwidth[i]*((4.0/((nplanes+2)*
                                  npsrc))**(1.0/(nplanes+4.0)))

        pcov = utils.gaussian_kde_set_covariance(positive.T, cov)
        ncov = utils.gaussian_kde_set_covariance(negative.T, cov)
    

        # get number densities
        nps = pcov(positive.T) * npsrc
        nns = ncov(positive.T) * nnsrc

        # define reliability of positive catalog
        rel = (nps-nns)/nps

        for src, rf in zip(posSources, rel):
            src.setAttribute("rel", rf)
            out_lsm = self.poslsm
        pmodel.save(out_lsm)

        if self.makeplots:
            savefig = self.prefix + "_planes.png"
            utils.plot(positive, negative, rel=rel, labels=labels,
                        savefig=savefig, prefix=self.prefix)

        return  self.poslsm, self.neglsm