Example #1
0
    def loci_medfilter(self):
        log = self.log

        if self._file_exists('red','cube_loci_medfilter'): return
        ft = lambda i: '%d:%.2d' % ((time.time()-i)/60,(time.time()-i)%60)
        pa = self.pa
        for chan in ['red','blue']:
            cube =  self._read_fits(chan,'cube_medfilter')

            bp,cube = nt.reset_nans(cube)
            log.info('Applying loci method ...(Can take a while......)')
            ti = time.time()
            cube = loci_subtract(cube, pa)
            log.info('                             '+ft(ti))

            sz = np.shape(cube)
            for i in range(sz[0]):
                log.info('rotating cube_medfilter['+str(i+1)+'/'+str(sz[0])+'] %.2f'%-pa[i])
                cube[i,:,:] = nd.rotate (cube[i,:,:],pa[i], reshape=False)
                bp[i,:,:] = nd.rotate (bp[i,:,:],pa[i], reshape=False)
                #cube[i,:,:] = nd.rotate (cube[i,:,:],-pa[i], reshape=False)
                #bp[i,:,:] = nd.rotate (bp[i,:,:],-pa[i], reshape=False)
            cube = nt.restore_nans(cube,bp)

            self._write_fits(cube,chan,'cube_loci_medfilter')
            self._write_fits(np.median(cube,axis=0),chan,'loci_medfilter_medcrunch')
            fs = lambda cube: np.sum(cube,axis=0) / np.sum(np.isfinite(cube),axis=0)
            self._write_fits(fs(cube),chan,'loci_medfilter_sumcrunch')
            del cube,bp
Example #2
0
    def loci_sdi(self):
        log=self.log

        ft = lambda i: '%d:%.2d' % ((time.time()-i)/60,(time.time()-i)%60)
        if self._file_exists('','cube_loci_sdi'): return
        pa = self.pa
        cube =  self._read_fits('','cube_sdi')
        #cube = self.cube_diff
        sz = np.shape(cube)
        bp,cube = nt.reset_nans(cube)
        log.info('Applying loci_subtract...(Can take a while......)')
        ti = time.time()
        cube = loci_subtract(cube, self.pa)
        #bp = loci_subtract(bp, self.pa)
        log.info('                              '+ft(ti))

        for i in range(sz[0]):
            log.info('rotating cube_diff['+str(i+1)+'/'+str(sz[0])+'] %.2f'%-pa[i])
            cube[i,:,:] = nd.rotate (cube[i,:,:],pa[i], reshape=False)
            bp[i,:,:] = nd.rotate (bp[i,:,:],pa[i], reshape=False)
            #cube[i,:,:] = nd.rotate (cube[i,:,:],-pa[i], reshape=False)
            #bp[i,:,:] = nd.rotate (bp[i,:,:],-pa[i], reshape=False)

        cube = nt.restore_nans(cube,bp)
        self._write_fits(cube,'','cube_loci_sdi')
        self._write_fits(np.median(cube,axis=0),'','loci_sdi_medcrunch')
        fs = lambda cube: np.sum(cube,axis=0) / np.sum(np.isfinite(cube),axis=0)
        self._write_fits(fs(cube),'','loci_sdi_sumcrunch')
Example #3
0
    def _scale_im(self,im,scale):

        def _scale_1024(out,scale):
            x = (out[1]-512.)/scale + 512.
            y = (out[0]-512.)/scale + 512.
            return y,x
        def _scale_1600(out,scale):
            x = (out[1]-800.)/scale + 800.
            y = (out[0]-800.)/scale + 800.
            return y,x
        def _scale_512(out, scale):
            x = (out[1]-256.)/scale + 256.
            y = (out[0]-256.)/scale + 256.
            return y,x

        im = np.asarray(im,dtype=np.float32) 
        bp,im = nt.reset_nans(im)
        if (self.central):
            im = nd.geometric_transform(im,_scale_512,extra_arguments=(scale,)) 
            bp = nd.geometric_transform(bp,_scale_512,extra_arguments=(scale,)) 
        else:
            im = nd.geometric_transform(im,_scale_1024,extra_arguments=(scale,))
            bp = nd.geometric_transform(bp,_scale_1024,extra_arguments=(scale,))
        im = nt.restore_nans(im,bp)
        return im
Example #4
0
    def _rotate_cube(self,cube):

        log =  self.log
        pa =   self.pa
        sz = np.shape(cube)
        # Now rotate this cube
        to=time.time()
        for k in range(sz[0]):
            ti=time.time()
            bp,cube[k,:,:] = nt.reset_nans(cube[k,:,:])
            cube[k,:,:] = nd.rotate (cube[k,:,:], pa[k], reshape=False)
            #cube[k,:,:] = nd.rotate (cube[k,:,:], -pa[k], reshape=False)

            #Now rotate the bp matrix 
            #bp = nd.rotate (bp, -pa[k], reshape=False)
            bp = nd.rotate (bp, pa[k], reshape=False)

            # And restore the Nans to cube
            cube[k,:,:] = nt.restore_nans(cube[k,:,:],bp)

            #_form_line('rotating ,k,nk,to,t1,t2,pa[k])
            t = time.time()
            line = 'rotating ['+str(k+1)+'/'+str(sz[0])+']'
            log.info(line+'%.2f %.2f %.2f' % (pa[k],t-ti,t-to))

        return cube
Example #5
0
            # sky subtract flat reduce
            if hdr.has_key('FILTER_R'):
                linearzR = hdr['ITIME_R']*hdr['NCOADD_R']
                #im = (im - sky_red) / flat_red / linearzR
                im = (im/linearzR - sky_red) / flat_red 
            else:
                linearzB = hdr['ITIME_B']*hdr['NCOADD_B']
                #im = (im - sky_blue) / flat_blue / linearzB
                im = (im/linearzB - sky_blue) / flat_blue 

            if dobadpix:               # Aggresive bad pixel removal
                im = remove_badpix(im,log)

            # Create a mask with the Nans.
            bp,im = nt.reset_nans(im)
    
            if ext == 2:
                # register blue frame to red's frame coordinate system
                im = nd.geometric_transform (im,xy_tran)
                #ndis.display(bp,frame=1,zscale=False)
                bp = nd.geometric_transform (bp,xy_tran)
                #ndis.display(bp,frame=2,zscale=False)

            # Get the center of the mask automatically. If not possible
            # nici_cntrd will display the image for the user to click

            xcen,ycen,im = nc.nici_cntrd(im,hdr,center_im=True)
            xco,yco,bp = nc.nici_cntrd(bp,hdr,center_im=True)

            # Now restore the Nans
Example #6
0
        diff = np.zeros(np.shape(rim),dtype=np.float32)
        bim /= np.sum(rim[g]*bim[g])/np.sum(rim[g]**2)
                        # We project (scalar product)
                        # the pixels of the red frame onto
                        # the blue frame inside the annulus. The amplitude
                        # gives the optimal (in a least-square sense)
                        # amplitude of the blue frame to fit
                        # the red frame. The blue frame is scaled to this
                        # optimal amplitude

        if l2 < l1:
            diff[:,:] = bim - rim
        else:
            diff[:,:] = rim - bim
        
        bp,diff = nt.reset_nans(diff)
        diff = nd.rotate (diff,angle, reshape=False)
        bp = nd.rotate (bp,angle, reshape=False)
        #diff = nd.rotate (diff,-angle, reshape=False)
        #bp = nd.rotate (bp,-angle, reshape=False)
        diff = nt.restore_nans(diff,bp)

        return diff 

    def _medfilter(self,im,r,rad):
        """
           Median filtering of each slice in the cube
        """
        log =     self.log
        pa =      self.pa
        bsize =   self.boxcar_size     # Boxcar smoothing size (def:5)