예제 #1
0
    def add_dered_err_to_columns(self):
        """
        I forgot to add errors...
        """
        c = self.open_columns()

        for filt in ['u','g','r','i','z']:
            print("reading extinction for",filt)
            ext = c['extinction_'+filt][:]
            for type in ['cmodelmag','modelmag']:
                outtag = '%s_dered_err_%s' % (type,filt)
                print("making:",outtag)

                print("  reading fluxes")
                if type == 'cmodelmag':
                    fdev         = c['fracpsf_'+filt][:]
                    devflux      = c['devflux_'+filt][:]
                    devflux_ivar = c['devflux_ivar_'+filt][:]
                    expflux      = c['expflux_'+filt][:]
                    expflux_ivar = c['expflux_ivar_'+filt][:]
                    print("    making cmodelmag")
                    flux, ivar   = sdsspy.util._make_cmodelflux_1band(fdev,
                                                                      devflux, devflux_ivar,
                                                                      expflux, expflux_ivar)
                else:
                    flux = c['modelflux_'+filt][:]
                    ivar = c['modelflux_ivar_'+filt][:]

                print("  dereddening")
                flux, ivar = sdsspy.dered_fluxes(ext, flux, ivar)
                print("  making mags")
                mag, magerr = sdsspy.nmgy2mag(flux, ivar)

                print("  writing data to",outtag)
                c.write_column(outtag, magerr, create=True)
예제 #2
0
파일: pgtools.py 프로젝트: esheldon/espy
    def extract_fields(self, objs, keep):
        """
        """
        dtype=[('photoid','i8'),
               ('ra','f8'),
               ('dec','f8'),
               ('modelmag_dered','f4',5),
               ('modelmag_dered_err','f4',5),
               ('cmodelmag_dered','f4',5),
               ('cmodelmag_dered_err','f4',5)]

        output = numpy.zeros(keep.size, dtype=dtype)

        output['photoid'] = objs['photoid'][keep]
        
        output['ra'] = objs['ra'][keep]
        output['dec'] = objs['dec'][keep]

        f, ivar = sdsspy.dered_fluxes(objs['extinction'][keep],
                                      objs['modelflux'][keep],
                                      objs['modelflux_ivar'][keep])
        mag,err = sdsspy.nmgy2mag(f,ivar)
        output['modelmag_dered'] = mag
        output['modelmag_dered_err'] = err

        output['cmodelmag_dered'] = self.cmodelmag_dered[keep,:]
        output['cmodelmag_dered_err'] = self.cmodelmag_dered_err[keep,:]

        return output
예제 #3
0
def calculate_magnitudes(tsObj_dict):
    """ Calculate magnitudes using the fiven ashinh mags (luptitudes).

    nmgy2mag(nmgy, ivar=None)
    lups2nmgy(lups, err=None, band=None)
    make_cmodelmag(objs, doerr=True, dered=False, lups=False)

    objs['devflux']
    objs['expflux']
    objs['fracdev']  or  objs['fracpsf']     fracPSF
    objs['devflux_ivar']
    objs['expflux_ivar']
    """
    out = {}

    nmgy_ivar_arr = sdsspy.lups2nmgy(numpy.array(tsObj_dict['psfCounts']),
                                     err=numpy.array(
                                         tsObj_dict['psfCountsErr']))
    mag = sdsspy.nmgy2mag(nmgy_ivar_arr)
    out['mag_psfcounts'] = mag[0]
    out['mag_psfcounts_ivar'] = mag[1]

    nmgy_ivar_arr = sdsspy.lups2nmgy(tsObj_dict['counts_model'],
                                     err=tsObj_dict['counts_modelErr'])
    mag = sdsspy.nmgy2mag(nmgy_ivar_arr)
    out['mag_countsmodel'] = mag[0]
    out['mag_countsmodel_ivar'] = mag[1]
    """
    ### Here I'm trying to calculate the deV + Exponential model
    ###    magnitude, but the sdsspy module functions don't seem to
    ###    play nicely with numpy recarray, which they require.
    arr = numpy.array([tsObj_dict['counts_deV'],
                       tsObj_dict['counts_exp'],
                       tsObj_dict['counts_deVErr'],
                       tsObj_dict['counts_expErr'],
                       tsObj_dict['fracPSF']],
                      dtype=[('devflux', tsObj_dict['counts_deV'].dtype),
                             ('expflux', tsObj_dict['counts_exp'].dtype),
                             ('devflux_ivar', tsObj_dict['counts_deVErr'].dtype),
                             ('expflux_ivar', tsObj_dict['counts_expErr'].dtype),
                             ('fracpsf', tsObj_dict['fracPSF'].dtype)])
    rec = arr.view(numpy.recarray)
    model_mags = sdsspy.make_cmodelmag(rec, doerr=True, dered=False, lups=False) # this returns log mags
    """
    return out
예제 #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
예제 #5
0
파일: select.py 프로젝트: esheldon/espy
    def modelmag_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:
            mag = sdsspy.nmgy2mag(self.objs['modelflux'])
            if dered:
                mag -= self.objs['extinction']
            self.mags[name] = mag

        mag_logic = self.mags[name][:,fnum] < limit
        return mag_logic
예제 #6
0
파일: regauss.py 프로젝트: esheldon/espy
    def make_output(self):
        import sdsspy

        print("creating output")
        dtype = self.output_dtype()
        self.output = numpy.zeros(self.objs.size, dtype=dtype)

        print("    copying from objs")
        eu.numpy_util.copy_fields(self.objs, self.output)

        mm=sdsspy.nmgy2mag(self.objs['modelflux'][:,2])
        self.output['modelmag_dered_r'] = mm-self.objs['extinction'][:,2]

        # set defaults
        output = self.output

        print("    setting defaults")
        # these get set to 9999
        flist = ['uncer','uncer_rg']
        for f in flist:
            for fnum in [0,1,2,3,4]:
                output[f][:,fnum] = 9999

        # these get set to 2**15 = -32768 which means not processed
        flist = ['amflags','amflags_psf','amflags_rg',
                 'corrflags_lin','corrflags_rg']
        for f in flist:
            for fnum in [0,1,2,3,4]:
                output[f][:,fnum] = 2**15

        for fnum in [0,1,2,3,4]:
            output['amflags_str'][:,fnum] = 'norun'
            output['amflags_psf_str'][:,fnum] = 'norun'
            output['amflags_rg_str'][:,fnum] = 'norun'

        # these get set to -9999
        flist = ['wrow','wcol',
                 'Irr','Irc','Icc','a4',
                 'Irr_psf','Irc_psf','Icc_psf','a4_psf',
                 'Irr_rg','Irc_rg','Icc_rg','a4_rg',
                 'e1_lin','e2_lin','R_lin',
                 'e1_rg','e2_rg','R_rg']
        for f in flist:
            for fnum in [0,1,2,3,4]:
                output[f][:,fnum] = -9999
예제 #7
0
파일: regauss.py 프로젝트: esheldon/espy
    def create_output(self, st):
        import sdsspy

        bands = ['u','g','r','i','z']

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

            if len(d) == 3:
                if isinstance(d[2],tuple):
                    sz=d[2][0]
                else:
                    sz=d[2]
                if sz == 5:
                    for bandi in xrange(5):
                        fname = name+'_'+bands[bandi]
                        out_dict[fname] = st[name][:, bandi]
            else:
                out_dict[name] = st[name]

        # match up to sweeps and get some info
        print("    matching to primary sweeps")
        w=self.sweep_cols['thing_id'].match(st['thing_id'])
        #print("    found %s/%s" % (w.size,st.size))
        if w.size != st.size:
            raise ValueError("Did not match all")

        out_dict['primgal_id'] = w

        print("    Getting psf ellip")
        Irr_psf = st['Irr_psf']
        Irc_psf = st['Irc_psf']
        Icc_psf = st['Icc_psf']
        T_psf = st['Irr_psf'] + st['Icc_psf']

        if 'e1' not in st.dtype.names:
            e1,e2 = self.make_e1e2(st)

        print("    Copying ellip,mags")
        for f in sdsspy.FILTERCHARS:
            fnum = sdsspy.FILTERNUM[f]
            out_dict['e1_psf_'+f] = (Icc_psf[:,fnum]-Irr_psf[:,fnum])/T_psf[:,fnum]
            out_dict['e2_psf_'+f] = 2*Irc_psf[:,fnum]/T_psf[:,fnum]

            out_dict['modelmag_dered_'+f] = self.sweep_cols['modelmag_dered_'+f][w]
            ext = self.sweep_cols['extinction_'+f][w]
            out_dict['extinction_'+f] = ext

            cmodelname = 'cmodelmag_dered_'+f
            if cmodelname in self.sweep_cols:
                out_dict[cmodelname] = self.sweep_cols[cmodelname][w]

            if self.sweeptype == 'star':
                flux = self.sweep_cols['psfflux_'+f][w]
                ivar = self.sweep_cols['psfflux_ivar_'+f][w]
                flux_dered = sdsspy.dered_fluxes(ext, flux)
                mag_dered = sdsspy.nmgy2mag(flux_dered)

                out_dict['psfflux_'+f] = flux
                out_dict['psfflux_ivar_'+f] = ivar
                out_dict['psfmag_dered_'+f] = mag_dered

            if 'e1' not in st.dtype.names:
                out_dict['e1_'+f] = e1[:,fnum]
                out_dict['e2_'+f] = e2[:,fnum]


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

        return out_dict