def shift_images(imd, img, imi): """ This isn't so useful yet because color terms are probably needed """ import sdsspy import scipy.ndimage if False: return img, imi run=imd['run'] camcol=imd['camcol'] path=sdsspy.filename('photoField', run=run, camcol=camcol) if not os.path.exists(path): print 'astrometry not found, no shifts applied' return img, imi ast=sdsspy.astrom.Astrom(run=run,camcol=camcol) idrowg,idrowr,idrowi=imd['drow'][1:1+3] idcolg,idcolr,idcoli=imd['dcol'][1:1+3] # use corner of atlas image as reference rowr,colr= imd['row0'][2], imd['col0'][2] ra_r,dec_r = ast.pix2eq(imd['field'],'r',rowr, colr) rowg,colg= ast.eq2pix(imd['field'], 'g', ra_r, dec_r) rowi,coli= ast.eq2pix(imd['field'], 'i', ra_r, dec_r) gshift=array([rowg-rowr, colg-colr], dtype='f4') ishift=array([rowi-rowr, coli-colr], dtype='f4') gshift[0] -= idrowg gshift[1] -= idcolg ishift[0] -= idrowi ishift[1] -= idcoli gout = scipy.ndimage.interpolation.shift(img, gshift, output='f4', order=1, mode='constant', cval=0.0) iout = scipy.ndimage.interpolation.shift(imi, ishift, output='f4', order=1, mode='constant', cval=0.0) return gout,iout
def collate(self): """ Keep objects if have nrunmin matches in both model and psf flux, in *any* one of g,r,i """ runs = stripe82_run_list() #runs=runs[where1(runs == 259)] pcoldir = self.coldir('primary82') ecoldir = self.coldir('epochs82') if os.path.exists(pcoldir): raise ValueError("primary coldir exists: '%s'\n Start Fresh" % pcoldir) if os.path.exists(ecoldir): raise ValueError("epochs coldir exists: '%s'\n Start Fresh" % ecoldir) pcols = columns.Columns(pcoldir) pcols.create() ecols = columns.Columns(ecoldir) ecols.create() # count in the epochs columns epochs_index = 0 for run in runs: for camcol in [1,2,3,4,5,6]: fname=sdsspy.filename('photoCombineCamcol', run, camcol) if os.path.exists(fname): data=sdsspy.read('photoCombineCamcol', run, camcol, verbose=True,lower=True) # first select by number of runs matched, then do flag # selection and such print(" selecting r-band nrunmin >",self.nrunmin) model_nuse = data['cmodel_nuse'][:,2] psf_nuse = data['psf_nuse'][:,2] w=where1( (psf_nuse >= self.nrunmin) & (model_nuse >= self.nrunmin) ) print(" kept:",w.size) if w.size > 0: data = data[w] print(" getting sweep matches for flags") data = self.match_sweeps(data) print(" found",data.size,"sweep matches") if data.size > 0: print(" selecting flags and rflux >",self.rlim) w = where1( get_select_logic(data, self.rlim) ) print(" kept:",w.size) if w.size > 0: data = data[w] print(" making primary output") poutput = self.make_primary_output(data) print(" gathering epochs") epochs, epochs_indices, epochs_count = \ self.gather_epochs(data, epochs_index) poutput['epochs_index'] = epochs_indices poutput['epochs_count'] = epochs_count nexpected = self.calc_expected_nepoch(data) if epochs.size != nexpected: #if nexpected-epochs.size == 1: #print("FOUND ERROR nexpected greater than epochs by 1. primary bug?") #else: # raise ValueError("Expected",nexpected,"epochs, but found",epochs.size) print("ERROR: Expected",nexpected,"epochs, but found",epochs.size) print(" found:",epochs.size) print(" making epochs output") eoutput = self.make_epochs_output(epochs) pcols.write_columns(poutput) ecols.write_columns(eoutput) # keep track of index in epochs database epochs_index += epochs.size