Example #1
0
    def _get_model(self):
        im, psf_im, coords, dims, sing_im, sing_coord = Simulation.__call__(
            self)
        bg_rms = self['Image']['Bgrms']
        mode = self['Mode']
        if mode == 'scarlet':
            #constraints = {"S": None, "m": {'use_nearest': False}, "+": None}
            #constraints['l1'] = bg_rms
            #psf_dims = np.shape(psf_im)
            #psf_im3d = psf_im.reshape( (1, psf_dims[0], psf_dims[1]) )
            #target_psf = scarlet.psf_match.fit_target_psf(psf_im3d, scarlet.psf_match.gaussian)
            #diff_kernels, psf_blend = scarlet.psf_match.build_diff_kernels(psf_im3d, target_psf)
            sources = [
                scarlet.ExtendedSource(coord, im, [bg_rms]) for coord in coords
            ]  #,psf=diff_kernels) for coord in coords]
            #config = scarlet.Config(edge_flux_thresh=0.05)
            config = scarlet.Config(source_sizes=[25
                                                  ])  #,edge_flux_thresh=0.05)
            #scarlet.ExtendedSource.shift_center=0.0
            blend = scarlet.Blend(sources, im, bg_rms=[bg_rms], config=config)
            blend.fit(10000, e_rel=1e-3)
            model = blend.get_model()
            mod1 = blend.get_model(m=0)
            #mod2 = blend.get_model(m=1)
            cen_mod = sources[0].get_model()
            #neigh_mod = sources[1].get_model()
            #steps_used = blend.it

        #return im,psf_im,model,mod1,mod2,cen_mod,neigh_mod,coords,sing_im,sing_coord
        return im, psf_im, model, mod1, cen_mod, coords, sing_im, sing_coord
Example #2
0
    def get_scar_model(self):
        import scarlet
        import scarlet.constraint as sc
        im, psf_im, coords, dims, dx1, dy1, noise = self.sim()
        bg_rms = self.sim['Image']['Bgrms']
        bg_rms = bg_rms / np.sqrt(len(im))
        mode = self.sim['Mode']

        #create multiband background im
        bg = np.zeros((len(im)))
        bg += bg_rms

        #choose constraints for PSF and sources (optional)
        #psf_constraints = ()#sc.SimpleConstraint())
        #source_constraints = ()#sc.SimpleConstraint(),sc.DirectSymmetryConstraint()) #sc.DirectMonotonicityConstraint(use_nearest=False)

        config = scarlet.Config(source_sizes=[25])

        #create multiband PSF image
        #psf_dims = np.shape(psf_im)
        #psf_im3d = psf_im.reshape( (1, psf_dims[0], psf_dims[1]) )
        #psfs = np.zeros((len(im), psf_dims[0],psf_dims[1]))
        #psfs += psf_im3d

        #PSF Matching
        #target_psf = scarlet.psf_match.fit_target_psf(psfs,
        #                                scarlet.psf_match.gaussian)
        #diff_kernels, psf_blend = scarlet.psf_match.build_diff_kernels(psfs,
        #                                    target_psf)
        #if use PSF matching, set psf = diff_kernels below
        sources = [
            scarlet.ExtendedSource(coord,
                                   im,
                                   bg_rms=bg,
                                   psf=None,
                                   config=config) for coord in coords
        ]
        #config = scarlet.Config(edge_flux_thresh=0.05)
        blend = scarlet.Blend(sources)
        blend.set_data(im, bg_rms=bg, config=config)
        blend.fit(10000, e_rel=1e-3)

        #get full sized scarlet models
        model = blend.get_model()
        mod1 = blend.get_model(0)
        mod2 = blend.get_model(1)

        #get postage stamp models
        cen_mod = sources[0].get_model()
        neigh_mod = sources[1].get_model()

        #get scarlet coordinates
        cen_cen_pos = blend[0][0].center
        neigh_cen_pos = blend[1][0].center

        return im, psf_im, model, mod1, mod2, cen_mod, neigh_mod, coords, dx1, dy1, noise, cen_cen_pos, neigh_cen_pos
    def _get_model(self):
        im, psf_im, coords, dims, sing_im, sing_coord = Simulation.__call__(
            self)
        bg_rms = self['Image']['Bgrms']
        mode = self['Mode']
        #constraints = {"S": None, "m": {'use_nearest': False}, "+": None}
        constraint = (sc.SimpleConstraint())
        #constraint = PSFConstraint()
        config = (scarlet.Config(source_sizes=[25]))
        #psf_dims = np.shape(psf_im)
        #psf_im3d = psf_im.reshape( (1, psf_dims[0], psf_dims[1]) )
        #target_psf = scarlet.psf_match.fit_target_psf(psf_im3d, scarlet.psf_match.gaussian)
        #diff_kernels, psf_blend = scarlet.psf_match.build_diff_kernels(psf_im3d, target_psf,constraints=constraint)

        #constraint =  (sc.L0Constraint(.5*bg_rms))
        #& sc.DirectSymmetryConstraint(sigma=0.25))
        #& sc.MonotonicityConstraint(use_nearest=True))
        #constraints['l1'] = bg_rms
        sources = [
            scarlet.ExtendedSource(coord,
                                   im, [bg_rms],
                                   psf=None,
                                   config=config,
                                   shift_center=0.0) for coord in coords
        ]
        #config = scarlet.Config(edge_flux_thresh=1.25)
        #scarlet.ExtendedSource.shift_center=0.0
        blend = scarlet.Blend(sources)
        blend.set_data(im, bg_rms=[bg_rms], config=config)
        blend.fit(10000, e_rel=1e-3)
        model = blend.get_model()
        mod1 = blend.get_model(0)
        #mod2 = blend.get_model(1)
        cen_mod = sources[0].get_model()
        #cen_pos = sources[0].center
        #neigh_mod = sources[1].get_model()
        #print(cen_pos[0]-coords[0][0],cen_pos[1]-coords[0][1])
        #psf_model = psf_blend.get_model()
        """
        masked_mod = np.ma.masked_equal(diff_kernels,0.0)
        f,ax = plt.subplots(1,2,figsize=(8,4))
        f1 = ax[0].imshow(psf_im3d[0,:,:])
        ax[0].set_title("Orig PSF")
        plt.colorbar(f1,ax=ax[0])
        f2 = ax[1].imshow(masked_mod[0,:,:])
        plt.colorbar(f2,ax=ax[1])
        ax[1].set_title("Diff Kernels")
        plt.tight_layout()
        f.savefig('test.png')
        plt.close()
        steps_used = blend.it
        print(steps_used)
        """
        #return im,psf_im,model,mod1,mod2,cen_mod,neigh_mod,coords,sing_im,sing_coord
        return im, psf_im, model, mod1, cen_mod, coords, sing_im, sing_coord
 def get_scar_model(self):
     import scarlet
     import scarlet.constraint as sc
     im, psf_im, coords, dims, dx1, dy1, noise = self.sim()
     bg_rms = self.sim['Image']['Bgrms']
     mode = self.sim['Mode']
     bg = np.zeros((len(im)))
     bg += bg_rms
     #psf_constraints = (sc.SimpleConstraint())
     #source_constraints = ()#sc.SimpleConstraint(),sc.DirectSymmetryConstraint()) #sc.DirectMonotonicityConstraint(use_nearest=False)
     config = scarlet.Config(source_sizes=[25])
     psf_dims = np.shape(psf_im)
     psf_im3d = psf_im.reshape((1, psf_dims[0], psf_dims[1]))
     psfs = np.zeros((len(im), psf_dims[0], psf_dims[1]))
     psfs += psf_im3d
     #target_psf = scarlet.psf_match.fit_target_psf(psfs,
     #                                scarlet.psf_match.gaussian)
     #diff_kernels, psf_blend = scarlet.psf_match.build_diff_kernels(psfs,
     #                        target_psf, constraints = None)
     sources = [
         scarlet.ExtendedSource(coord,
                                im,
                                bg_rms=bg,
                                psf=None,
                                config=config) for coord in coords
     ]
     #config = scarlet.Config(edge_flux_thresh=0.05)
     blend = scarlet.Blend(sources)
     blend.set_data(im, bg_rms=bg, config=config)
     blend.fit(10000, e_rel=1e-3)
     model = blend.get_model()
     mod1 = blend.get_model(0)
     #mod2 = blend.get_model(1)
     cen_mod = sources[0].get_model()
     #neigh_mod = sources[1].get_model()
     #psf_model = psf_blend.get_model()
     #steps_used = blend.it
     cen_cen_pos = blend[0][0].center
     #return im,psf_im,model,mod1,mod2,cen_mod,neigh_mod,coords,dx1,dy1,noise
     return im, psf_im, model, mod1, cen_mod, coords, dx1, dy1, noise, cen_cen_pos, psfs
    def get_scar_model(self):
        import scarlet

        im, psf_im, coords, dims, dx1, dy1, noise, sep_coords = self.sim()
        bg_rms = self.sim['Image']['Bgrms']
        mode = self.sim['Mode']
        #constraints = {"S": None, "m": {'use_nearest': False}, "+": None}
        #constraints['l0'] = bg_rms
        constraint = (sc.SimpleConstraint())
        #                       & sc.MonotonicityConstraint(use_nearest=True))
        config = scarlet.Config(source_sizes=[25])
        psf_dims = np.shape(psf_im)
        psf_im3d = psf_im.reshape((1, psf_dims[0], psf_dims[1]))
        target_psf = scarlet.psf_match.fit_target_psf(
            psf_im3d, scarlet.psf_match.gaussian)
        diff_kernels, psf_blend = scarlet.psf_match.build_diff_kernels(
            psf_im3d, target_psf, constraints=constraint.copy())
        sources = [
            scarlet.ExtendedSource(coord,
                                   im, [bg_rms],
                                   psf=diff_kernels,
                                   config=config) for coord in coords
        ]
        #sources = [scarlet.ExtendedSource(coord, im, [bg_rms]) for coord in coords]
        #scarlet.ExtendedSource.shift_center=0.0
        #config = scarlet.Config(edge_flux_thresh=0.05)
        blend = scarlet.Blend(sources, im, bg_rms=[bg_rms], config=config)
        blend.fit(10000, e_rel=1e-3)
        model = blend.get_model()
        mod1 = blend.get_model(m=0)
        mod2 = blend.get_model(m=1)
        cen_mod = sources[0].get_model()
        neigh_mod = sources[1].get_model()
        #steps_used = blend.it

        return im, psf_im, model, mod1, mod2, cen_mod, neigh_mod, coords, dx1, dy1, noise, sep_coords