Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 5
0
    
            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
            im = nt.restore_nans(im,bp)

            #print 'NUMBER OF bp>1',np.sum(bp>1.)
            #print 'NUMBER OF NANS',np.sum(np.isnan(im))

            log.info('%s %s: xcen: %.2f ycen: %.2f' % 
                                      (outfile,
                                      ['red','blue'][ext-1],
                                      xcen,ycen))  

            # Order wcs -in place.
            nt.order_wcs(hdr)
            hdr.update("EXTNAME",'SCI', "SCIENCE extension",after='GCOUNT')
            hdr.__delitem__("EXTVER")
            hdr.update("EXTVER",ext, "SCIENCE ext version",after='EXTNAME')
            pf.append(outfile,im,hdr)
Ejemplo n.º 6
0
                        # 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)
        mdfw =    self.medfilt_width    # Medfiltering width  (def:11)

        # to accelerate the code, we bin the image and the 'r'
        # image down to 256x256 and do the radial profile on the binned versions