Esempio n. 1
0
    def extract_fields(self, objs):
        """
        Extract tags from the input structure and add some if needed.
        """

        dtype=self.keep_dtype()
        new = numpy.zeros(objs.size, dtype=dtype)
        esutil.numpy_util.copy_fields(objs, new)
    
        # calculate new fields
        new['photoid'] = sdsspy.photoid(new)

        flux,ivar=new['modelflux'],new['modelflux_ivar']
        ext=new['extinction']
        flux_dered,ivar_dered = sdsspy.dered_fluxes(ext, flux, ivar=ivar)


        mag_dered,err_dered = sdsspy.util.nmgy2mag(flux_dered, ivar=ivar_dered)
        new['modelmag_dered'] = mag_dered
        new['modelmag_dered_err'] = err_dered

        cmag_dered,cmagerr_dered = sdsspy.make_cmodelmag(objs, dered=True)
        new['cmodelmag_dered'] = cmag_dered
        new['cmodelmag_dered_err'] = cmagerr_dered

        return new
Esempio n. 2
0
 def cmodelmag_logic(self, filter, limit, dered=True):
     fnum = sdsspy.FILTERNUM[filter]
     if dered:
         name='cmodel_dered'
     else:
         name='cmodel'
     
     # cache the mags
     if name not in self.mags:
         self.mags[name] = sdsspy.make_cmodelmag(self.objs, doerr=False, dered=dered)
     mag_logic = self.mags[name][:,fnum] < limit
     return mag_logic
Esempio n. 3
0
    def process_runs(self, **keys):
        d=self.outdir()
        if not os.path.exists(d):
            os.makedirs(d)

        outfile = self.outfile()
        stdout.write("Will write to file: %s\n" % outfile)
        if os.path.exists(outfile):
            stdout.write("Removing existing file: %s\n" % outfile)
            os.remove(outfile)

        i=1
        ntot=len(self.runs)

        for run in sorted(self.runs):
            stdout.write("Run: %s  %s/%s\n" % (run,i,ntot))
            stdout.write('-'*70 + '\n')
            if i == 1:
                # more verbose the first time
                stdout.write(self.run_query(run))
                stdout.write('\n')
            objs = self.read_run(run)

            if objs.size > 0:

                self.cmodelmag_dered,self.cmodelmag_dered_err = \
                        sdsspy.make_cmodelmag(objs, dered=True)

                stdout.write("    Getting logic\n")
                mag_logic = self.mag_logic()
                binned_logic = self.binned_logic(objs)
                object1_logic = self.object1_logic(objs)

                logic = mag_logic & binned_logic & object1_logic

                stdout.write("    Selecting good galaxies\n")
                keep, = where(logic)

                nkeep = keep.size
                stdout.write("    Keeping %s/%s\n" % (nkeep,objs.size))

                if nkeep > 0:
                    stdout.write("        Extracting fields...")
                    output= self.extract_fields(objs, keep)
                    stdout.write("Writing data...")
                    esutil.sfile.write(output, outfile,append=True)
                    stdout.write("Done\n")

            i+=1
Esempio n. 4
0
    def create_output(self, st):
        bands = ['u','g','r','i','z']

        out_dict = {}
        for d in st.dtype.descr:
            name = str( d[0] )

            if len(d) == 3:
                if d[2] == 5:
                    # ignoring the higher dim stuff
                    for bandi in xrange(5):
                        fname = name+'_'+bands[bandi]
                        out_dict[fname] = st[name][:, bandi]
            else:
                out_dict[name] = st[name]

        if 'devflux' in st.dtype.names:
            #cmodelflux, cmodelflux_ivar = sdsspy.make_cmodelflux(st, doivar=True)
            cmodelmag_dered, cmodelmag_dered_err = sdsspy.make_cmodelmag(st, dered=True)

        modelflux, modelflux_ivar = sdsspy.dered_fluxes(st['extinction'], 
                                                        st['modelflux'], 
                                                        st['modelflux_ivar'])
        modelmag_dered, modelmag_dered_err = sdsspy.nmgy2mag(modelflux, modelflux_ivar)

        for f in sdsspy.FILTERCHARS:
            fnum = sdsspy.FILTERNUM[f]
            if 'devflux' in st.dtype.names:
                out_dict['cmodelflux_'+f] = cmodelmag_dered[:,fnum]
                out_dict['cmodelflux_ivar_'+f] = cmodelmag_dered_err[:,fnum]
                out_dict['cmodelmag_dered_'+f] = cmodelmag_dered[:,fnum]
                out_dict['cmodelmag_dered_err_'+f] = cmodelmag_dered_err[:,fnum]
            out_dict['modelmag_dered_'+f] = modelmag_dered[:,fnum]
            out_dict['modelmag_dered_err_'+f] = modelmag_dered_err[:,fnum]

        out_dict['photoid'] = sdsspy.photoid(st)

        self.set_maskflags(out_dict)

        # we will add an "survey_primary" column if we are not explicitly 
        # selecting survey_primary
        if self.type not in ['primgal','primstar']:
            survey_primary = numpy.zeros(st.size, dtype='i1')
            w=self.get_primary_indices(st)
            if w.size > 0:
                survey_primary[w] = 1
            out_dict['survey_primary'] = survey_primary

        return out_dict
Esempio n. 5
0
 def mag_logic(self):
     cmodel_dered = sdsspy.make_cmodelmag(self.objs, doerr=False, dered=True)
     mag_logic = cmodel_dered[:,2] < self.max_rmag
     return mag_logic