Пример #1
0
    def go(self):
        import fitsio
        import esutil as eu

        reslist=[]

        nstack=0
        npsf_stack=0
        psf_skyvar=0.0
        for ccd in xrange(1,62+1):
            path=files.get_output_path(ftype='shear',
                                       run=self.run,
                                       psfnum=self.psfnum,
                                       shnum=self.shnum,
                                       ccd=ccd)
            
            print path
            with fitsio.FITS(path) as fits:

                res=fits[1].read()

                psf_stacks_real=fits[2].read()
                psf_stacks_imag=fits[3].read()

                psf_h=fits[2].read_header()

                npsf_stack += psf_h['nstack']
                psf_skyvar += psf_h['skyvar']

                im_stacks=fits[4].read()

            reslist.append(res)
            if ccd==1:
                psf_stack_real_tot = psf_stacks_real.copy()
                psf_stack_imag_tot = psf_stacks_imag.copy()
                im_stacks_tot = im_stacks.copy()
            else:
                psf_stack_real_tot += psf_stacks_real
                psf_stack_imag_tot += psf_stacks_imag
                # these sum across multiple dimensions
                im_stacks_tot['images_real'] += im_stacks['images_real']
                im_stacks_tot['images_imag'] += im_stacks['images_imag']
                im_stacks_tot['nstack'] += im_stacks['nstack']
                im_stacks_tot['skyvar'] += im_stacks['skyvar']
        
        res=eu.numpy_util.combine_arrlist(reslist)

        self._write_data(res, 
                         psf_stack_real_tot, psf_stack_imag_tot, npsf_stack, psf_skyvar,
                         im_stacks_tot, psf_h['boost'])
Пример #2
0
    def _write_data(self, res, psf_stack, npsf_stack, psf_skyvar,
                    im_stacks, boost):
        import fitsio
        path=files.get_output_path(ftype='shear-stack',
                                   run=self.run,
                                   psfnum=self.psfnum,
                                   shnum=self.shnum)


        psf_header={'skyvar':psf_skyvar,
                    'nstack':npsf_stack, 
                    'boost':boost}
        print path
        with fitsio.FITS(path, mode='rw', clobber=True) as fits:
            fits.write(res)
            fits.write(psf_stack, header=psf_header)
            fits.write(im_stacks)
Пример #3
0
    def go(self):
        import fitsio
        import esutil as eu

        reslist=[]

        nstack=0
        npsf_stack=0
        psf_skyvar=0.0
        for ccd in xrange(1,62+1):
            path=files.get_output_path(ftype='shear',
                                       run=self.run,
                                       psfnum=self.psfnum,
                                       shnum=self.shnum,
                                       ccd=ccd)
            
            print path
            with fitsio.FITS(path) as fits:
                res=fits[1].read()
                psf_stack_i=fits[2].read()
                psf_h=fits[2].read_header()

                npsf_stack += psf_h['nstack']
                psf_skyvar += psf_h['skyvar']

                im_stacks_i=fits[3].read()

            reslist.append(res)
            if ccd==1:
                psf_stack = psf_stack_i.copy()
                im_stacks = im_stacks_i.copy()
            else:
                psf_stack += psf_stack_i
                # these sum across multiple dimensions
                im_stacks['images'] += im_stacks_i['images']
                im_stacks['nstack'] += im_stacks_i['nstack']
                im_stacks['skyvar'] += im_stacks_i['skyvar']

                #print im_stacks['images'][3,:,:].sum(),numpy.sqrt(im_stacks['skyvar'][3])
        
        res=eu.numpy_util.combine_arrlist(reslist)

        boost=psf_h['boost']
        self._write_data(res, 
                         psf_stack, npsf_stack, psf_skyvar,
                         im_stacks, boost)
Пример #4
0
    def _read_data(self):
        import fitsio
        import images
        path=files.get_output_path(ftype='shear-stack',
                                   run=self.run,
                                   psfnum=self.psfnum,
                                   shnum=self.shnum)
        print path
        with fitsio.FITS(path) as fits:
            #res=fits[1].read()
            self.psf_stack=fits[2].read()

            self.psf_h=fits[2].read_header()
            self.psf_skyvar=self.psf_h['skyvar']

            self.im_stacks=fits[3].read()

        return 
        subtract_median=False

        images.multiview(self.psf_stack,title='psf')

        edg=3

        if subtract_median:
            psf=self.psf_stack
            pix2med = tuple( [psf[:,0:edg].ravel(), psf[:, -edg:-1].ravel(), psf[0:edg, :].ravel(), psf[-edg:-1, :].ravel() ])
            pix2med=numpy.concatenate(pix2med)
            self.psf_stack -= numpy.median(pix2med)

            images.multiview(self.psf_stack,title='psf after')

        for i in xrange(self.im_stacks.size):

            images.multiview(self.im_stacks['images'][i,:,:],title='%d before' % (i+1))
            
            if subtract_median:

                im=self.im_stacks['images'][i,:,:]
                pix2med = tuple( [im[:,0:edg].ravel(), im[:, -edg:-1].ravel(), im[0:edg, :].ravel(), im[-edg:-1, :].ravel() ])
                pix2med=numpy.concatenate(pix2med)

                self.im_stacks['images'][i,:,:] -= numpy.median(pix2med)

                images.multiview(self.im_stacks['images'][i,:,:],title='%d after' % (i+1))
Пример #5
0
    def _load_data(self):
        from esutil.numpy_util import combine_arrlist

        alldata = []
        for ccd in xrange(1, 62 + 1):
            datai = files.read_fits_output(run=self.run, ftype="psf", psfnum=self.psfnum, shnum=self.shnum, ccd=ccd)
            if datai is None:
                fname = files.get_output_path(run=self.run, ftype="psf", psfnum=self.psfnum, shnum=self.shnum, ccd=ccd)
                raise ValueError("error reading: %s")
            alldata.append(datai)

        data = combine_arrlist(alldata)
        flags_name = self.model + "_flags"
        w, = where(data[flags_name] == 0)
        if w.size == 0:
            raise ValueError("none with flags==0")
        data = data[w]
        self._data = data
Пример #6
0
    def _read_data(self):
        import fitsio
        path=files.get_output_path(ftype='shear-stack',
                                   run=self.run,
                                   psfnum=self.psfnum,
                                   shnum=self.shnum)
        print path
        with fitsio.FITS(path) as fits:
            #res=fits[1].read()
            psf_stack_real=fits[2].read()
            psf_stack_imag=fits[3].read()
            self.psf_stack_c = self._make_complex_image(psf_stack_real, psf_stack_imag)

            self.psf_stack=self._make_cspace_image(self.psf_stack_c)

            self.psf_h=fits[3].read_header()
            self.psf_skyvar=self.psf_h['skyvar']

            self.im_stacks=fits[4].read()