Example #1
0
    def make_f0conv(self):
        """
        Make f0 convolved with epsilon.  It is on this image we will
        measure new adaptive moments.

        f0 will be expanded if epsilon is larger.  The center will remain
        the same in that expansion

        """
        import scipy.signal
        import images
        if self.f0 is None or self.epsilon is None:
            raise ValueError("Create both f0 and epsilon first")
        if self.f0 is None:
            raise ValueError("f0 is None")

        f0 = self.f0
        ep = self.epsilon

        if self.verbose:
            if ep.shape[0] > f0.shape[0] or ep.shape[1] > f0.shape[0]:
                print("epsilon is larger than image:")
                print("  epsize:",ep.shape)
                print("  f0size:",f0.shape)
        # if f0 is bigger, it is returned unchanged
        f0_expand = images.expand(f0, ep.shape)

        if self.conv == 'fft':
            f0conv = scipy.signal.fftconvolve(f0_expand, ep, mode='same')
        else:
            f0conv = scipy.signal.convolve2d(f0_expand,
                                             ep, 
                                             #old_behavior=False,
                                             mode='same')

        # trim back to the original size
        if (f0conv.shape[0] > self.image.shape[0] 
                or f0conv.shape[1] > self.image.shape[1]):
            f0conv = f0conv[ 0:self.image.shape[0], 0:self.image.shape[1] ]
            if self.debug:
                print("trimming back")

        self.f0conv = f0conv

        if self.debug:
            print("f0.shape",self.f0.shape)
            print("f0conv.shape",self.f0conv.shape)
            images.multiview(self.f0,title='f0')
            images.multiview(self.f0conv, title='f0conv')
Example #2
0
    def make_image(self):

        # expand the image if needed to accomodate psf
        # if image0 is bigger than psf, it is returned unchanged

        if self.verbose:
            print("Convolving to final image")

        dims = self['dims']
        image0 = self.image0
        psf = self.psf

        # we don't have to do a numerical convolution if both are gaussians
        if self['psfmodel'] == 'gauss' and self['objmodel'] == 'gauss':
            Irr=self['Irr']+self['Irr_psf']
            Irc=self['Irc']+self['Irc_psf']
            Icc=self['Icc']+self['Icc_psf']
            image = mom2disk('gauss', 
                             Irr, 
                             Irc, 
                             Icc, 
                             self['dims'], 
                             cen=self['cen'],
                             counts=self['counts'])
        else:

            # this should be un-necessary
            image0_expand = images.expand(self.image0, self.psf.shape, verbose=self.verbose)

            image = scipy.signal.fftconvolve(image0_expand, self.psf, mode='same')

            if image.shape[0] > dims[0] or image.shape[1] > dims[1]:
                if self.verbose:
                    print("  Trimming back to requested size")
                image = image[ 0:self['dims'][0], 0:self['dims'][1] ]

        self.image = image