Esempio n. 1
0
    def extract_cols(self, data):
        """
        get the actual columns we want to write
        """
        from esutil.numpy_util import copy_fields

        dt = [(self["ra_col"], "f8"), (self["dec_col"], "f8"), (self["e1_col"], "f8"), (self["e2_col"], "f8")]

        if self["shear_style"] == "lensfit":
            dt += [(self["e1sens_col"], "f8"), (self["e2sens_col"], "f8")]

        dt += [("weight", "f8")]

        if self["scinv_style"] == "interp":
            nzl = data[self["scinv_col"]].shape[1]
            dt += [(self["scinv_col"], "f8", nzl)]
        elif self["scinv_style"] == "interp-summed":
            nzl = self.scinv_data.size
            dt += [("scinv", "f8", nzl)]
        else:
            dt += [(self["z_col"], "f8")]

        newdata = numpy.zeros(data.size, dtype=dt)

        copy_fields(data, newdata)

        if self["scinv_style"] == "interp-summed":
            newdata["scinv"] = self.scinv_data[newaxis, :]

        var = 2 * self["shapenoise"] ** 2 + data[self["e_cov_11_col"]] + data[self["e_cov_22_col"]]

        weight = 1.0 / var
        newdata["weight"] = weight

        return newdata
Esempio n. 2
0
File: cas.py Progetto: esheldon/espy
    def add_scinv_to_raw(self, fname, clobber=True):
        """

        Read in the raw file and write out a new file with just ra,dec and the
        mean scinv as a function of lens redshift

        """

        import lensing

        outfile = self.scinv_name(fname)
        if os.path.exists(outfile) and not clobber:
            stdout.write("file exists, skipping\n")
            return
        
        if self.type != 'dr7pofz':
            raise ValueError("only support dr4cc2 for now")

        data = self.read_raw(fname)

        zsvals = self.dr7pofz_zvals()
        zsmax = zsvals.max()
        zsmin = zsvals.min()
        scalc = lensing.tools.ScinvCalculator(zsmin, zsmax)

        output = self.scinv_array(scalc.n_zlens, data.size)

        stdout.write("Copying in common columns\n")
        stdout.flush()
        numpy_util.copy_fields(data, output)

        for i in range(data.size):
            if ((i+1) % 10000) == 0:
                stdout.write("%d/%d\n" % ((i+1), data.size))
                stdout.flush()
            pz = data['pz'][i]

            output['mean_scinv'][i] = scalc.calc_mean_sigmacritinv(zsvals, pz)

        hdr = {'zlvals': list(scalc.zlvals)}

        stdout.write("Writing scinv file: %s\n" % outfile)
        esutil.sfile.write(output, outfile, header=hdr)
        stdout.write("done\n")
Esempio n. 3
0
    def get_matched_struct(self, pipe):
        dt=[
            ('simid','i4'),
            ('ccd','i2'),
            ('id','i4'),
            ('flags','i4'),
            ('row','f8'),
            ('col','f8'),
            ('model','S4'),
            ('s2n_w','f8'),
            ('Ts2n','f8'),
            ('s2','f8'),
            ('sratio','f8'),
            ('objtype','S4'),
            ('g','f8',2),
            ('gcov','f8',(2,2)),
            ('gsens','f8',2),
            ('Tmean','f8'),
            ('weight','f8'),
            ('use1','i2'),
            ('use2','i2'),
            ('use3','i2'),
            ('use4','i2')]

        # note this s2n min is just the limit used in the
        # shear measurement code
        wgal=pipe.get_gals(s2n_min=self.conf['shear_s2n_min'])

        gals=pipe.cat[wgal]
        output=zeros(gals.size, dtype=dt)

        print wgal.size, pipe.shear_res.size
        w,=where(gals['simid'] != pipe.shear_res['simid'])
        if w.size != 0:
            raise ValueError("gals and shear don't line up")

        mcat,mshear=match(gals['simid'], pipe.shear_res['simid'])
        if mshear.size != pipe.shear_res.size:
            mess="""not all shear objects matched
                by simid: %d %d""" % (pipe.shear_res.size,mshear.size)
            print mess
         
        # gets simid, row, col
        copy_fields(gals, output)

        output['ccd'] = pipe['ccd']

        output['flags'][:] = pipe.shear_res['flags'][:]

        output['s2n_w'][:] = pipe.shear_res['s2n_w'][:]
        output['Ts2n'][:] = pipe.shear_res['Ts2n'][:]
        output['s2'][:] = pipe.shear_res['s2'][:]
        output['sratio'][:] = sqrt(1./output['s2'][:])

        for i in xrange(output.size):
            output['objtype'][i] = pipe.shear_res['model'][i]

        output['g'][:,:] = pipe.shear_res['g'][:,:]
        output['gcov'][:,:,:] = pipe.shear_res['gcov'][:,:,:]
        output['gsens'][:,:] = pipe.shear_res['gsens'][:,:]

        output['Tmean'][:] = pipe.shear_res['Tmean'][:]
        output['model'][:] = pipe.shear_res['model'][:]


        wts=stats.get_weights(pipe.shear_res['gcov'][:,:,:])
        output['weight'][:] = wts[:]


        return output