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
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
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)
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
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