예제 #1
0
파일: lcat.py 프로젝트: esheldon/espy
    def create_objshear_input(self, nrand=None, extra=None):
        """
        To work in chunks, send nrand= and extra=chunknum
        """
        from es_sdsspy.stomp_maps import get_quad_logic

        if nrand is not None:
            if extra is None:
                raise ValueError("If sending nrand, also send extra=")
        else:
            nrand = self['nrand']

        self.load_stomp_maps()

        strict_edgecut = self.get('strict_edgecut',False)

        print("Generating",nrand,"random points "
              "with z in [%0.2f,%0.2f]" % (self['zmin'],self['zmax']))
        n=0

        dt = lensing.files.lcat_dtype()
        output = numpy.zeros(nrand, dtype=dt)
        while n < nrand:
            if n == 0:
                print("  generating",nrand-n," ",end='')
            else:
                print("  re-generating",nrand-n," ",end='')
            print("z",end='')
            z = self.zgen.genrand(nrand-n)
            print(" -> ra,dec ",end='')
            ra,dec = self.tycho_map.GenerateRandomEq(nrand-n)

            if 'rmax_hard' in self:
                print(" -> maskflags_hard (%0.1f)" % self['rmax_hard'], end='')
                maskflags_hard = self.get_maskflags(ra,dec,z,hard=True)
                hard_edge_logic = get_quad_logic(maskflags_hard, strict=True)

            print(" -> maskflags (%0.1f)" % self['rmax'], end='')
            maskflags = self.get_maskflags(ra,dec,z)
            quad_logic      = get_quad_logic(maskflags,strict=strict_edgecut)

            if 'rmax_hard' in self:
                wgood = where1(quad_logic & hard_edge_logic)
            else:
                wgood = where1(quad_logic)

            print(" -> good ones:",wgood.size)
            if wgood.size > 0:
                output['zindex'][n:n+wgood.size] = \
                        numpy.arange(n,n+wgood.size,dtype='i4')
                output['ra'][n:n+wgood.size] = ra[wgood]
                output['dec'][n:n+wgood.size] = dec[wgood]
                output['z'][n:n+wgood.size] = z[wgood]
                output['maskflags'][n:n+wgood.size] = maskflags[wgood]
                n += wgood.size

        lensing.files.lcat_write(sample=self['sample'], data=output, extra=extra)
예제 #2
0
파일: lcat.py 프로젝트: esheldon/espy
    def create_objshear_input(self, lens_split=None):
        """
        To work in chunks, send nrand= and extra=chunknum
        """
        from es_sdsspy.stomp_maps import get_quad_logic

        nsplit=self['nsplit']
        if lens_split is None:
            raise ValueError("send lens_split=")
        print("doing lens_split %s: %s/%s" % (lens_split,lens_split+1,nsplit))

        self.load_stomp_maps()

        strict_edgecut = self['strict_edgecut']

        n=0

        data=self.read_raw()
        zindex = numpy.arange(data.size,dtype='i4')

        # do in chunks so we can see the progress
        npersplit = data.size/nsplit
        nleft = data.size % nsplit

        data = data[lens_split*npersplit:(lens_split+1)*npersplit]
        zindex = zindex[lens_split*npersplit:(lens_split+1)*npersplit]
        #data = data[0:100]
        #zindex = zindex[0:100]

        print("Generating z in [%0.2f,%0.2f]" % (self['zmin'],self['zmax']))
        z = self.zgen.genrand(data.size)


        print(" -> maskflags, max radius: %0.1f" % self['rmax'])
        maskflags = self.get_maskflags(data['ra'],data['dec'],z)

        quad_logic = get_quad_logic(maskflags, strict=strict_edgecut)

        wgood = where1(quad_logic)

        print(" -> good ones:",wgood.size)

        data      = data[wgood]
        zindex    = zindex[wgood]
        z         = z[wgood]
        maskflags = maskflags[wgood]

        dt = lensing.files.lcat_dtype()
        output = numpy.zeros(wgood.size, dtype=dt)
        output['zindex'][:]    = zindex
        output['ra'][:]        = data['ra']
        output['dec'][:]       = data['dec']
        output['z'][:]         = z
        output['maskflags'][:] = maskflags

        lensing.files.lcat_write(sample=self['sample'], data=output, lens_split=lens_split)
예제 #3
0
파일: lcat.py 프로젝트: esheldon/espy
    def create_objshear_input(self, **keys):
        from es_sdsspy.stomp_maps import get_quad_logic

        lens_split=keys.get('lens_split',None)
        if lens_split is None:
            raise ValueError("send lens_split=")

        nsplit=self['nsplit']
        print("doing lens_split %s: %s/%s" % (lens_split,lens_split+1,nsplit))

        strict_edgecut = self['strict_edgecut']

        n=0

        data=self.read_original()
        ntot=data.size

        npersplit = data.size/nsplit

        start = lens_split*npersplit
        end   = (lens_split+1)*npersplit
        data = data[start:end]
        print('lens_split',lens_split)
        print('    keeping: %d/%d' % (data.size,ntot))

        # trim z for speed was not implemented in rmrand01
        z_logic = self.get_z_logic(data['z'])
        w=where1(z_logic)
        data=data[w]

        maskflags = self.get_maskflags(data['ra'],data['dec'],data['z'])

        quad_logic = get_quad_logic(maskflags, strict=strict_edgecut)

        wgood = where1(quad_logic)

        print("    keeping: %d/%d" %(wgood.size,data.size))

        data      = data[wgood]
        maskflags = maskflags[wgood]

        dt = lensing.files.lcat_dtype()
        output = numpy.zeros(wgood.size, dtype=dt)
        output['zindex'][:]    = data['zindex']
        output['ra'][:]        = data['ra']
        output['dec'][:]       = data['dec']
        output['z'][:]         = data['z']
        output['maskflags'][:] = maskflags

        lensing.files.lcat_write(sample=self['sample'],
                                 data=output,
                                 lens_split=lens_split)
예제 #4
0
파일: lcat.py 프로젝트: esheldon/espy
    def create_objshear_input(self, **keys):
        from es_sdsspy.stomp_maps import get_quad_logic

        nsplit=self['nsplit']
        if nsplit != 1:
            raise ValueError("expected nsplit=1 for SDSSVoids")

        data = self.read_original()
        orig_size = data.size
        zindex = numpy.arange(orig_size,dtype='i4')

        zmin = self['zmin']
        zmax = self['zmax']

        good=where1(  (data['z'] > zmin) & (data['z'] < zmax) )
        print("  z cut: %s/%s: %s" % (data.size-good.size,
                                      orig_size,
                                      (data.size-good.size)/float(orig_size)) )
        if good.size == 0:
            stop

        print("Actually trimming the bad z for speed")
        data = data[good]
        zindex = zindex[good]

        #maskflags = self.get_maskflags(data['ra'][0:5], data['dec'][0:5], data['z'][0:5])
        maskflags = self.get_maskflags(data['ra'], data['dec'], data['z'])
        quad_logic = get_quad_logic(maskflags)

        good = where1(quad_logic)
        print("  quad mask cut: %s/%s: %s" % (data.size-good.size,
                                              orig_size,
                                              (data.size-good.size)/float(orig_size)) )

        if good.size == 0:
            stop

        print('creating output array')
        output = make_output_array(good.size)

        print('copying data')
        output['zindex']    = zindex[good]
        output['ra']        = data['ra'][good]
        output['dec']       = data['dec'][good]
        output['z']         = data['z'][good]
        output['maskflags'] = maskflags[good]
        lensing.files.lcat_write(sample=self['sample'], data=output, 
                                 lens_split=0)
예제 #5
0
파일: lcat.py 프로젝트: esheldon/espy
    def create_objshear_input(self, **keys):
        from es_sdsspy.stomp_maps import get_quad_logic
        
        nsplit=self['nsplit']
        if nsplit != 1:
            raise ValueError("expected nsplit=1 for RedMapper")

        strict_edgecut = self.get('strict_edgecut',False)

        z_field = self['z_field']

        data = self.read_original()

        # keep index into original data
        orig_size = data.size
        zindex = numpy.arange(orig_size,dtype='i4')

        # trim z for speed
        z_logic = self.get_z_logic(data[z_field])

        w=where1(z_logic)
        data = data[w]
        zindex = zindex[w]

        # make sure in the tycho window and two adjacent quadrants
        # not hitting edge (or no edge if strict=True)

        maskflags = self.get_maskflags(data['ra'], data['dec'], data[z_field])

        quad_logic = get_quad_logic(maskflags, strict=strict_edgecut)

        good = where1(quad_logic)
        print("Finally kept: %d/%d" % (good.size,data.size))

        print('creating output array')
        output = make_output_array(good.size)

        self.copy_output(output, zindex, data, maskflags, good)

        lensing.files.lcat_write(sample=self['sample'], data=output,
                                 lens_split=0)