def plot_patch_zpoffset(patchdat, maglim=None, etitle="", newfig=True, z_method=n.mean): if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad, patchdat['dec']*deg2rad) gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(patchdat['x'], patchdat['y'], patchdat['dmag'], z_method=z_method, zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='mag') figtitle = "Zeropoint Offsets " + etitle pyl.title(figtitle, fontsize='medium') return
def plot_nstars_patch(patchdat, z_method=n.mean, zlimits=None, newfig=True): """Plot the n.min/mean/std number of stars ever seen in a particular patch.""" if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad, patchdat['dec']*deg2rad) gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(patchdat['x'], patchdat['y'], z=patchdat['nstars'], z_method=z_method, zlimits=zlimits, gridsize=gridsize, radecgrid=True, newfig=newfig) pyl.title("Patch Minimum Nstars") return
def plot_visits(visits, visitlim=None, etitle="", newfig=True): """Plot the location of the visits across the sky. Color code by number of visits.""" if 'x' not in list(visits.keys()): visits['x'], visits['y'] = cpu.hammer_project_toxy(visits['ra']*deg2rad, visits['dec']*deg2rad) gridsize = cpu.calc_gridsize(visits,binsize='fov', rad_fov=1.8) cpu.plot_density(visits['x'], visits['y'], gridsize=gridsize, zlimits=visitlim, radecgrid=True, newfig=newfig)#, zscale='log') pyl.title("Visit density " + etitle, fontsize='medium') return
def plot_visits(visits, visitlim=None, etitle="", newfig=True): """Plot the location of the visits across the sky. Color code by number of visits.""" if 'x' not in list(visits.keys()): visits['x'], visits['y'] = cpu.hammer_project_toxy( visits['ra'] * deg2rad, visits['dec'] * deg2rad) gridsize = cpu.calc_gridsize(visits, binsize='fov', rad_fov=1.8) cpu.plot_density(visits['x'], visits['y'], gridsize=gridsize, zlimits=visitlim, radecgrid=True, newfig=newfig) #, zscale='log') pyl.title("Visit density " + etitle, fontsize='medium') return
def plot_nstars_patch(patchdat, z_method=n.mean, zlimits=None, newfig=True): """Plot the n.min/mean/std number of stars ever seen in a particular patch.""" if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy( patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad) gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(patchdat['x'], patchdat['y'], z=patchdat['nstars'], z_method=z_method, zlimits=zlimits, gridsize=gridsize, radecgrid=True, newfig=newfig) pyl.title("Patch Minimum Nstars") return
def plot_nvisits_patch(patchdat, subpatch=None, patchlim=None, newfig=True): """Plot the location of the (sub)patches across the sky. Color code by number of visits. Also plot the number of stars observed in each patch. """ if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad, patchdat['dec']*deg2rad) if subpatch != None: condition = (patchdat['subpatch'] == subpatch) x = patchdat['x'][condition] y = patchdat['y'][condition] else: x = patchdat['x'] y = patchdat['y'] gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(x, y, gridsize=gridsize, zlimits=patchlim, radecgrid=True, newfig=newfig) pyl.title("Patch Density", fontsize='medium') return
def plot_patch_zpoffset(patchdat, maglim=None, etitle="", newfig=True, z_method=n.mean): if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy( patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad) gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(patchdat['x'], patchdat['y'], patchdat['dmag'], z_method=z_method, zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='mag') figtitle = "Zeropoint Offsets " + etitle pyl.title(figtitle, fontsize='medium') return
def plot_nvisits_patch(patchdat, subpatch=None, patchlim=None, newfig=True): """Plot the location of the (sub)patches across the sky. Color code by number of visits. Also plot the number of stars observed in each patch. """ if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy( patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad) if subpatch != None: condition = (patchdat['subpatch'] == subpatch) x = patchdat['x'][condition] y = patchdat['y'][condition] else: x = patchdat['x'] y = patchdat['y'] gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(x, y, gridsize=gridsize, zlimits=patchlim, radecgrid=True, newfig=newfig) pyl.title("Patch Density", fontsize='medium') return
def plot_patch_nstars(patchdat, maglim=None, etitle="", newfig=True, patchcal=None, z_method=n.mean): adjust_patchdat = False if maglim != None: maglim=n.array(maglim) if 'dmagcal' not in list(patchdat.keys()): if patchcal == None: raise Exception("Must either pass in patchcal as well, or match_patch_calvstrue previously") patchdat = match_calvstrue(patchdat, starcal) adjust_patchdat = True if 'magdiff' not in list(patchdat.keys()): patchdat = adjust_calvstrue(patchdat) adjust_patchdat = True if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad, patchdat['dec']*deg2rad) adjust_patchdat = True gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(patchdat['x'], patchdat['y'], patchdat['nstars'], z_method=z_method, zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='') figtitle = "N stars per patch" + etitle pyl.title(figtitle, fontsize='medium') return patchdat
def plot_stars_dmagcaltrue(stardat, maglim=None, etitle="", newfig=True, starcal=None, z_method=n.mean): adjust_stardat = False if maglim !=0: maglim=n.round(n.array(maglim)*1000, decimals=1) if 'magcal' not in list(stardat.keys()): if starcal == None: raise Exception("Must either pass in starcal as well, or match_calvstrue previously") stardat = match_calvstrue(stardat, starcal) adjust_stardat = True if 'magdiff' not in list(stardat.keys()): stardat = adjust_calvstrue(stardat) adjust_stardat = True if 'x' not in list(stardat.keys()): stardat['x'], stardat['y'] = cpu.hammer_project_toxy(stardat['ra']*deg2rad, stardat['dec']*deg2rad) adjust_stardat = True gridsize = cpu.calc_gridsize(stardat, binsize='patch') cpu.plot_density(stardat['x'], stardat['y'], stardat['magdiff']*1000, z_method=z_method, zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='mmag') figtitle = "Stars dMag(true-bestfit) " + etitle pyl.title(figtitle, fontsize='medium') return stardat
def plot_stars_dmagcaltrue(stardat, maglim=None, etitle="", newfig=True, starcal=None, z_method=n.mean): adjust_stardat = False if maglim != 0: maglim = n.round(n.array(maglim) * 1000, decimals=1) if 'magcal' not in list(stardat.keys()): if starcal == None: raise Exception( "Must either pass in starcal as well, or match_calvstrue previously" ) stardat = match_calvstrue(stardat, starcal) adjust_stardat = True if 'magdiff' not in list(stardat.keys()): stardat = adjust_calvstrue(stardat) adjust_stardat = True if 'x' not in list(stardat.keys()): stardat['x'], stardat['y'] = cpu.hammer_project_toxy( stardat['ra'] * deg2rad, stardat['dec'] * deg2rad) adjust_stardat = True gridsize = cpu.calc_gridsize(stardat, binsize='patch') cpu.plot_density(stardat['x'], stardat['y'], stardat['magdiff'] * 1000, z_method=z_method, zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='mmag') figtitle = "Stars dMag(true-bestfit) " + etitle pyl.title(figtitle, fontsize='medium') return stardat
def plot_patch_nstars(patchdat, maglim=None, etitle="", newfig=True, patchcal=None, z_method=n.mean): adjust_patchdat = False if maglim != None: maglim = n.array(maglim) if 'dmagcal' not in list(patchdat.keys()): if patchcal == None: raise Exception( "Must either pass in patchcal as well, or match_patch_calvstrue previously" ) patchdat = match_calvstrue(patchdat, starcal) adjust_patchdat = True if 'magdiff' not in list(patchdat.keys()): patchdat = adjust_calvstrue(patchdat) adjust_patchdat = True if 'x' not in list(patchdat.keys()): patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy( patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad) adjust_patchdat = True gridsize = cpu.calc_gridsize(patchdat, binsize='patch') cpu.plot_density(patchdat['x'], patchdat['y'], patchdat['nstars'], z_method=z_method, zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='') figtitle = "N stars per patch" + etitle pyl.title(figtitle, fontsize='medium') return patchdat
def starPlots(truestarfile = "stardata.dat", bestfitstarfile = "test_bestfit_Star.dat"): #assume both the files are sorted by star id. stardat = cp.read_true_stars(truestarfile) #keys are ('id', 'dbid', 'ra', 'dec', 'magtrue', 'color') starcal = ui.readDatafile(bestfitstarfile, keys=('id','magcal','rms','iqr_sigma','nobs')) HP = True if np.size(starcal['id']) == 0: starcal = ui.readDatafile(bestfitstarfile, keys=('id','magcal')) HP = False fitted_stars = np.in1d(stardat['id'], starcal['id']) for key in stardat.keys(): stardat[key] = stardat[key][fitted_stars] for key in starcal.keys(): stardat[key] = starcal[key] stardat['magdiff'] = stardat['magcal'] - stardat['magtrue'] stardat = cp.adjust_stars_calvstrue(stardat) starResults = {} HPResults = {} starResults['N stars Fit'] = np.size(stardat['magdiff']) outlier_clip=np.where(np.abs(stardat['magdiff']) < .05) rms = stardat['magdiff'][outlier_clip].std() print 'true-bestfit RMS = %f, true-bestfit (clipped) = %f'%(stardat['magdiff'].std(), rms) lim = rms*2.5 if lim < 0.001: lim = round(lim * 10000) / 10000.0 elif lim < 0.01: lim = round(lim * 1000) / 1000.0 print "Using magnitude limits for plots of %f, %f" %(-lim, lim) maglim= [-lim, lim] starResults['Residuals RMS (mmag)'] = stardat['magdiff'].std()*1e3 starResults['IQR_sigma (mmag)'] = so.robustSigma(stardat['magdiff'])*1e3 #star residual map stardat['x'], stardat['y'] = cpu.hammer_project_toxy(stardat['ra']*deg2rad, stardat['dec']*deg2rad) gridsize = cpu.calc_gridsize(stardat, binsize='patch') etitle = " RMS = %4.1f mmag"%(rms*1000) cpu.plot_density(stardat['x'], stardat['y'], stardat['magdiff']*1000, z_method=np.mean, zlimits=np.array(maglim)*1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') figtitle = "Stars dMag(true-bestfit)" pyl.title(figtitle, fontsize='medium') pyl.savefig('Sdmag.png',type='png') maglim2 = [0, maglim[1]/2.] cp.plot_stars_dmagcaltrue(stardat, maglim=maglim2, etitle=" RMS "+etitle, z_method=np.std) pyl.savefig('Sdmag_rms.png', format='png') histrange = [maglim[0]*2.5, maglim[1]*2.5] nbins = 100 cp.histogram_stars_dmagcaltrue(stardat, nbins=nbins, range=histrange, etitle=etitle) pyl.savefig('Sdamg_hist.png', format='png') #color distribution of stars pyl.figure() pyl.hist(stardat['color'], bins=100) pyl.xlabel(r'$g-i$') pyl.ylabel('# of stars') pyl.title('Color Distribution') pyl.savefig('Scolordist.png',type='png') #accuracy v color pyl.figure() #pyl.scatter(stardat['color'], stardat['magdiff']*1000., c=stardat['magtrue'], alpha=0.1,edgecolors=None) pyl.hexbin(stardat['color'], stardat['magdiff']*1000., bins='log') cb=pyl.colorbar() cb.ax.set_ylabel(r'$\log{\rm{N}}$') pyl.xlabel(r'$g-i$') pyl.ylabel('Bestfit-True (mmag)') pyl.savefig('Saccuracyvcolor.png',type='png') #accuracy v mag pyl.figure() #pyl.scatter(stardat['magtrue'], stardat['magdiff']*1000., c=stardat['color'], alpha=0.1,edgecolors=None) pyl.hexbin(stardat['magtrue'], stardat['magdiff']*1000., bins='log') cb=pyl.colorbar() cb.ax.set_ylabel(r'$\log{\rm{N}}$') pyl.xlabel('True Mag') pyl.ylabel('Bestfit-True (mmag)') pyl.savefig('Saccuracyvmag.png',type='png') if HP: zlim = [np.min(stardat['nobs']), (np.median(stardat['nobs'])-np.min(stardat['nobs']))+np.median(stardat['nobs'])] cpu.plot_density(stardat['x'], stardat['y'],stardat['nobs'], z_method=np.mean, zlimits=zlim, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='N observations') pyl.title('Visit Density') pyl.savefig('Snobs.png', format='png') pyl.figure() #I should just figure out from the data what nsides is! hpid = hp.ang2pix(16, (stardat['dec']+90.)*deg2rad, stardat['ra']*deg2rad) cpu.plot_density(stardat['x'], stardat['y'],np.mod(hpid,250), z_method=np.median, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='HEALpix ID mod 250') pyl.title("HEALpix Map") pyl.savefig('HPid.png') HPResults['number of HEALpix'] = np.size(np.unique(hpid)) pyl.figure() num, b, p = pyl.hist(stardat['nobs'], bins=100, range=zlim, histtype='bar') pyl.xlabel("Number of Observations per Star") pyl.title('Median = %d'%np.median(stardat['nobs'])) pyl.savefig('Snobs_hist.png',type='png') starResults['median repeat obs'] = np.median(stardat['nobs']) pyl.figure() x = np.sort(stardat['iqr_sigma'])*1e3 y = np.arange(np.size(x), dtype='float') y = y/np.max(y) per50 = np.max(np.where(y <= .5)) per90 = np.max(np.where(y <= .9)) pyl.plot(x,y, 'k--', label='IQR, 50th,90th %2.1f, %2.1f'%(x[per50],x[per90])) pyl.plot([0,x[per50]],[y[per50],y[per50]],'b--') pyl.plot([x[per50],x[per50]],[0,y[per50]],'b--') pyl.plot([0,x[per90]],[y[per90],y[per90]],'b--') pyl.plot([x[per90],x[per90]],[0,y[per90]],'b--') #pyl.title('Cumulative Distribution of Stellar Repeatability') #pyl.xlabel('Repeatability IQR RMS (mmag)') #pyl.ylabel('Cumulative Fraction') #pyl.savefig('Srepeat_IQR_cumulative.png',type='png') pyl.legend() pyl.savefig('Srepeat_cumulative.png',type='png') #repeatability from IQR rs = so.robustSigma(stardat['iqr_sigma']) med = np.median(stardat['iqr_sigma']) maglim = np.around(np.array([med-3*rs, med+3.*rs])*1000, decimals=2)/1000 cpu.plot_density(stardat['x'], stardat['y'], stardat['iqr_sigma']*1000, z_method=np.mean, zlimits=maglim*1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') pyl.title('Repeatability (IQR)') pyl.savefig('Srepeat_IQR.png',type='png') pyl.figure() num, b, p = pyl.hist(stardat['iqr_sigma']*1000, bins=100, range=maglim*1000, histtype='bar') pyl.xlabel('RMS per star (mmag)') pyl.title('Repeatability IQR, Median = %4.2f mmag'%np.median(stardat['iqr_sigma']*1000)) pyl.savefig('Srepeat_IQR_hist.png',type='png') starResults['Median Repeatability (IQR) (mmag)'] = np.median(med)*1e3 pyl.figure() good = np.where(stardat['magtrue'] < 18) num, b, p = pyl.hist(stardat['iqr_sigma'][good]*1000, bins=100, range=maglim*1000, histtype='bar') pyl.xlabel('RMS per star, m < 18 (mmag)') pyl.title('Repeatability IQR, Median = %4.2f mmag'%np.median(stardat['iqr_sigma'][good]*1000)) pyl.savefig('Srepeat_IQR_bright_hist.png',type='png') starResults['Median Repeatability Bright (IQR) (mmag)'] = np.median(stardat['iqr_sigma'][good])*1e3 #repeatability v color pyl.figure() #pyl.plot(stardat['color'], stardat['rms']*1000., 'ko', alpha=.1) pyl.hexbin(stardat['color'], stardat['iqr_sigma']*1000., bins='log') cb = pyl.colorbar() cb.set_label(r'$\log{\rm{N}}$') pyl.ylim([0,40]) pyl.xlabel(r'$g-i$') pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)') pyl.savefig('Srepeatvcolor.png',type='png') #repeatability v mag pyl.figure() #pyl.plot(stardat['magtrue'], stardat['rms']*1000., 'ko', alpha=.1) pyl.hexbin(stardat['magtrue'], stardat['iqr_sigma']*1000.,bins='log') cb = pyl.colorbar() cb.set_label(r'$\log{\rm{N}}$') pyl.ylim([0,40]) pyl.xlabel('True Mag') pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)') pyl.savefig('Srepeatvmag.png',type='png') #repeatability rs = so.robustSigma(stardat['rms']) med = np.median(stardat['rms']) maglim = np.around(np.array([med-3*rs, med+3.*rs])*1000, decimals=2)/1000 cpu.plot_density(stardat['x'], stardat['y'], stardat['rms']*1000, z_method=np.mean, zlimits=maglim*1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') pyl.title('Repeatability') pyl.savefig('Srepeat.png',type='png') pyl.figure() num, b, p = pyl.hist(stardat['rms']*1000, bins=100, range=maglim*1000, histtype='bar') pyl.xlabel('RMS per star (mmag)') pyl.title('Repeatability, Median = %4.2f mmag'%np.median(stardat['rms']*1000)) pyl.savefig('Srepeat_hist.png',type='png') starResults['Median Repeatability (mmag)'] = np.median(med)*1e3 pyl.figure() x = np.sort(stardat['rms'])*1e3 y = np.arange(np.size(x), dtype='float') y = y/np.max(y) per50 = np.max(np.where(y <= .5)) per90 = np.max(np.where(y <= .9)) pyl.plot(x,y, 'k', label='RMS, %2.1f, %2.1f'%(x[per50],x[per90])) pyl.plot([0,x[per50]],[y[per50],y[per50]],'k') pyl.plot([x[per50],x[per50]],[0,y[per50]],'k') pyl.plot([0,x[per90]],[y[per90],y[per90]],'k') pyl.plot([x[per90],x[per90]],[0,y[per90]],'k') pyl.title('Cumulative Distribution of Stellar Repeatability') pyl.xlabel('Repeatability RMS (mmag)') pyl.ylabel('Cumulative Fraction') pyl.savefig('Srepeat_cumulative.png',type='png') #need to make a spatial uniformity plot since we can now have varying densities of stars. nside = 64 stardat['hpid'] = hp.ang2pix(nside, (stardat['dec']+90.)*deg2rad, stardat['ra']*deg2rad) uhpid = np.unique(stardat['hpid']) hp_mean = uhpid*0. hp_std = uhpid*0. hp_dec, hp_ra = hp.pix2ang(nside,uhpid) #hp_ra = hp_ra hp_dec = hp_dec-90.*deg2rad hp_x, hp_y = cpu.hammer_project_toxy(hp_ra, hp_dec) stardat = dictsort(stardat,'hpid') left = np.searchsorted(stardat['hpid'], uhpid) right = np.searchsorted(stardat['hpid'], uhpid,side='right') for i in np.arange(left.size): hp_mean[i] = np.mean(stardat['magdiff'][left[i]:right[i]]) hp_std[i] = np.std(stardat['magdiff'][left[i]:right[i]]) cpu.plot_density(hp_x, hp_y, hp_mean*1000, z_method=np.mean, zlimits=None, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') HPResults['Spatial Uniformity RMS (mmag)'] = np.std(hp_mean)*1e3 HPResults['Spatial Uniformity IQR RMS (mmag)'] = so.robustSigma(hp_mean)*1e3 pyl.title('mean(True-Bestfit), binned by HEALpix') pyl.savefig('HPresid.png',type='png') cpu.plot_density(hp_x, hp_y, hp_std*1000, z_method=np.mean, zlimits=None, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') pyl.title('std(True-Bestfit), binned by HEALpix') pyl.savefig('HPstd.png',type='png') pyl.figure() num, b, p = pyl.hist( hp_mean*1000, bins=100, range=None, histtype='bar') pyl.xlabel("HEALpix(True-Bestfit) (mmag)") pyl.title('Spatial Uniformity, RMS=%4.2f'%HPResults['Spatial Uniformity RMS (mmag)']) pyl.savefig('HPmean_hist.png',type='png') pyl.figure() num, b, p = pyl.hist( hp_std*1000, bins=100, range=None, histtype='bar') pyl.xlabel("std(True-Bestfit) per HEALpix (mmag)") pyl.title('Variation within HEALpix, median=%4.2f mmag'%np.median(hp_std*1000)) pyl.savefig('HPstd_hist.png',type='png') return starResults,HPResults
def starPlots(truestarfile="stardata.dat", bestfitstarfile="test_bestfit_Star.dat"): #assume both the files are sorted by star id. stardat = cp.read_true_stars( truestarfile ) #keys are ('id', 'dbid', 'ra', 'dec', 'magtrue', 'color') starcal = ui.readDatafile(bestfitstarfile, keys=('id', 'magcal', 'rms', 'iqr_sigma', 'nobs')) HP = True if np.size(starcal['id']) == 0: starcal = ui.readDatafile(bestfitstarfile, keys=('id', 'magcal')) HP = False fitted_stars = np.in1d(stardat['id'], starcal['id']) for key in list(stardat.keys()): stardat[key] = stardat[key][fitted_stars] for key in list(starcal.keys()): stardat[key] = starcal[key] stardat['magdiff'] = stardat['magcal'] - stardat['magtrue'] stardat = cp.adjust_stars_calvstrue(stardat) starResults = {} HPResults = {} starResults['N stars Fit'] = np.size(stardat['magdiff']) outlier_clip = np.where(np.abs(stardat['magdiff']) < .05) rms = stardat['magdiff'][outlier_clip].std() print('true-bestfit RMS = %f, true-bestfit (clipped) = %f' % (stardat['magdiff'].std(), rms)) lim = rms * 2.5 if lim < 0.001: lim = round(lim * 10000) / 10000.0 elif lim < 0.01: lim = round(lim * 1000) / 1000.0 print("Using magnitude limits for plots of %f, %f" % (-lim, lim)) maglim = [-lim, lim] starResults['Residuals RMS (mmag)'] = stardat['magdiff'].std() * 1e3 starResults['IQR_sigma (mmag)'] = so.robustSigma(stardat['magdiff']) * 1e3 #star residual map stardat['x'], stardat['y'] = cpu.hammer_project_toxy( stardat['ra'] * deg2rad, stardat['dec'] * deg2rad) gridsize = cpu.calc_gridsize(stardat, binsize='patch') etitle = " RMS = %4.1f mmag" % (rms * 1000) cpu.plot_density(stardat['x'], stardat['y'], stardat['magdiff'] * 1000, z_method=np.mean, zlimits=np.array(maglim) * 1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') figtitle = "Stars dMag(true-bestfit)" pyl.title(figtitle, fontsize='medium') pyl.savefig('Sdmag.png', type='png') maglim2 = [0, maglim[1] / 2.] cp.plot_stars_dmagcaltrue(stardat, maglim=maglim2, etitle=" RMS " + etitle, z_method=np.std) pyl.savefig('Sdmag_rms.png', format='png') histrange = [maglim[0] * 2.5, maglim[1] * 2.5] nbins = 100 cp.histogram_stars_dmagcaltrue(stardat, nbins=nbins, range=histrange, etitle=etitle) pyl.savefig('Sdamg_hist.png', format='png') #color distribution of stars pyl.figure() pyl.hist(stardat['color'], bins=100) pyl.xlabel(r'$g-i$') pyl.ylabel('# of stars') pyl.title('Color Distribution') pyl.savefig('Scolordist.png', type='png') #accuracy v color pyl.figure() #pyl.scatter(stardat['color'], stardat['magdiff']*1000., c=stardat['magtrue'], alpha=0.1,edgecolors=None) pyl.hexbin(stardat['color'], stardat['magdiff'] * 1000., bins='log') cb = pyl.colorbar() cb.ax.set_ylabel(r'$\log{\rm{N}}$') pyl.xlabel(r'$g-i$') pyl.ylabel('Bestfit-True (mmag)') pyl.savefig('Saccuracyvcolor.png', type='png') #accuracy v mag pyl.figure() #pyl.scatter(stardat['magtrue'], stardat['magdiff']*1000., c=stardat['color'], alpha=0.1,edgecolors=None) pyl.hexbin(stardat['magtrue'], stardat['magdiff'] * 1000., bins='log') cb = pyl.colorbar() cb.ax.set_ylabel(r'$\log{\rm{N}}$') pyl.xlabel('True Mag') pyl.ylabel('Bestfit-True (mmag)') pyl.savefig('Saccuracyvmag.png', type='png') if HP: zlim = [ np.min(stardat['nobs']), (np.median(stardat['nobs']) - np.min(stardat['nobs'])) + np.median(stardat['nobs']) ] cpu.plot_density(stardat['x'], stardat['y'], stardat['nobs'], z_method=np.mean, zlimits=zlim, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='N observations') pyl.title('Visit Density') pyl.savefig('Snobs.png', format='png') pyl.figure() #I should just figure out from the data what nsides is! hpid = hp.ang2pix(16, (stardat['dec'] + 90.) * deg2rad, stardat['ra'] * deg2rad) cpu.plot_density(stardat['x'], stardat['y'], np.mod(hpid, 250), z_method=np.median, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='HEALpix ID mod 250') pyl.title("HEALpix Map") pyl.savefig('HPid.png') HPResults['number of HEALpix'] = np.size(np.unique(hpid)) pyl.figure() num, b, p = pyl.hist(stardat['nobs'], bins=100, range=zlim, histtype='bar') pyl.xlabel("Number of Observations per Star") pyl.title('Median = %d' % np.median(stardat['nobs'])) pyl.savefig('Snobs_hist.png', type='png') starResults['median repeat obs'] = np.median(stardat['nobs']) pyl.figure() x = np.sort(stardat['iqr_sigma']) * 1e3 y = np.arange(np.size(x), dtype='float') y = y / np.max(y) per50 = np.max(np.where(y <= .5)) per90 = np.max(np.where(y <= .9)) pyl.plot(x, y, 'k--', label='IQR, 50th,90th %2.1f, %2.1f' % (x[per50], x[per90])) pyl.plot([0, x[per50]], [y[per50], y[per50]], 'b--') pyl.plot([x[per50], x[per50]], [0, y[per50]], 'b--') pyl.plot([0, x[per90]], [y[per90], y[per90]], 'b--') pyl.plot([x[per90], x[per90]], [0, y[per90]], 'b--') #pyl.title('Cumulative Distribution of Stellar Repeatability') #pyl.xlabel('Repeatability IQR RMS (mmag)') #pyl.ylabel('Cumulative Fraction') #pyl.savefig('Srepeat_IQR_cumulative.png',type='png') pyl.legend() pyl.savefig('Srepeat_cumulative.png', type='png') #repeatability from IQR rs = so.robustSigma(stardat['iqr_sigma']) med = np.median(stardat['iqr_sigma']) maglim = np.around(np.array([med - 3 * rs, med + 3. * rs]) * 1000, decimals=2) / 1000 cpu.plot_density(stardat['x'], stardat['y'], stardat['iqr_sigma'] * 1000, z_method=np.mean, zlimits=maglim * 1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') pyl.title('Repeatability (IQR)') pyl.savefig('Srepeat_IQR.png', type='png') pyl.figure() num, b, p = pyl.hist(stardat['iqr_sigma'] * 1000, bins=100, range=maglim * 1000, histtype='bar') pyl.xlabel('RMS per star (mmag)') pyl.title('Repeatability IQR, Median = %4.2f mmag' % np.median(stardat['iqr_sigma'] * 1000)) pyl.savefig('Srepeat_IQR_hist.png', type='png') starResults['Median Repeatability (IQR) (mmag)'] = np.median(med) * 1e3 pyl.figure() good = np.where(stardat['magtrue'] < 18) num, b, p = pyl.hist(stardat['iqr_sigma'][good] * 1000, bins=100, range=maglim * 1000, histtype='bar') pyl.xlabel('RMS per star, m < 18 (mmag)') pyl.title('Repeatability IQR, Median = %4.2f mmag' % np.median(stardat['iqr_sigma'][good] * 1000)) pyl.savefig('Srepeat_IQR_bright_hist.png', type='png') starResults['Median Repeatability Bright (IQR) (mmag)'] = np.median( stardat['iqr_sigma'][good]) * 1e3 #repeatability v color pyl.figure() #pyl.plot(stardat['color'], stardat['rms']*1000., 'ko', alpha=.1) pyl.hexbin(stardat['color'], stardat['iqr_sigma'] * 1000., bins='log') cb = pyl.colorbar() cb.set_label(r'$\log{\rm{N}}$') pyl.ylim([0, 40]) pyl.xlabel(r'$g-i$') pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)') pyl.savefig('Srepeatvcolor.png', type='png') #repeatability v mag pyl.figure() #pyl.plot(stardat['magtrue'], stardat['rms']*1000., 'ko', alpha=.1) pyl.hexbin(stardat['magtrue'], stardat['iqr_sigma'] * 1000., bins='log') cb = pyl.colorbar() cb.set_label(r'$\log{\rm{N}}$') pyl.ylim([0, 40]) pyl.xlabel('True Mag') pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)') pyl.savefig('Srepeatvmag.png', type='png') #repeatability rs = so.robustSigma(stardat['rms']) med = np.median(stardat['rms']) maglim = np.around(np.array([med - 3 * rs, med + 3. * rs]) * 1000, decimals=2) / 1000 cpu.plot_density(stardat['x'], stardat['y'], stardat['rms'] * 1000, z_method=np.mean, zlimits=maglim * 1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') pyl.title('Repeatability') pyl.savefig('Srepeat.png', type='png') pyl.figure() num, b, p = pyl.hist(stardat['rms'] * 1000, bins=100, range=maglim * 1000, histtype='bar') pyl.xlabel('RMS per star (mmag)') pyl.title('Repeatability, Median = %4.2f mmag' % np.median(stardat['rms'] * 1000)) pyl.savefig('Srepeat_hist.png', type='png') starResults['Median Repeatability (mmag)'] = np.median(med) * 1e3 pyl.figure() x = np.sort(stardat['rms']) * 1e3 y = np.arange(np.size(x), dtype='float') y = y / np.max(y) per50 = np.max(np.where(y <= .5)) per90 = np.max(np.where(y <= .9)) pyl.plot(x, y, 'k', label='RMS, %2.1f, %2.1f' % (x[per50], x[per90])) pyl.plot([0, x[per50]], [y[per50], y[per50]], 'k') pyl.plot([x[per50], x[per50]], [0, y[per50]], 'k') pyl.plot([0, x[per90]], [y[per90], y[per90]], 'k') pyl.plot([x[per90], x[per90]], [0, y[per90]], 'k') pyl.title('Cumulative Distribution of Stellar Repeatability') pyl.xlabel('Repeatability RMS (mmag)') pyl.ylabel('Cumulative Fraction') pyl.savefig('Srepeat_cumulative.png', type='png') #need to make a spatial uniformity plot since we can now have varying densities of stars. nside = 64 stardat['hpid'] = hp.ang2pix(nside, (stardat['dec'] + 90.) * deg2rad, stardat['ra'] * deg2rad) uhpid = np.unique(stardat['hpid']) hp_mean = uhpid * 0. hp_std = uhpid * 0. hp_dec, hp_ra = hp.pix2ang(nside, uhpid) #hp_ra = hp_ra hp_dec = hp_dec - 90. * deg2rad hp_x, hp_y = cpu.hammer_project_toxy(hp_ra, hp_dec) stardat = dictsort(stardat, 'hpid') left = np.searchsorted(stardat['hpid'], uhpid) right = np.searchsorted(stardat['hpid'], uhpid, side='right') for i in np.arange(left.size): hp_mean[i] = np.mean(stardat['magdiff'][left[i]:right[i]]) hp_std[i] = np.std(stardat['magdiff'][left[i]:right[i]]) cpu.plot_density(hp_x, hp_y, hp_mean * 1000, z_method=np.mean, zlimits=None, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') HPResults['Spatial Uniformity RMS (mmag)'] = np.std(hp_mean) * 1e3 HPResults['Spatial Uniformity IQR RMS (mmag)'] = so.robustSigma( hp_mean) * 1e3 pyl.title('mean(True-Bestfit), binned by HEALpix') pyl.savefig('HPresid.png', type='png') cpu.plot_density(hp_x, hp_y, hp_std * 1000, z_method=np.mean, zlimits=None, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag') pyl.title('std(True-Bestfit), binned by HEALpix') pyl.savefig('HPstd.png', type='png') pyl.figure() num, b, p = pyl.hist(hp_mean * 1000, bins=100, range=None, histtype='bar') pyl.xlabel("HEALpix(True-Bestfit) (mmag)") pyl.title('Spatial Uniformity, RMS=%4.2f' % HPResults['Spatial Uniformity RMS (mmag)']) pyl.savefig('HPmean_hist.png', type='png') pyl.figure() num, b, p = pyl.hist(hp_std * 1000, bins=100, range=None, histtype='bar') pyl.xlabel("std(True-Bestfit) per HEALpix (mmag)") pyl.title('Variation within HEALpix, median=%4.2f mmag' % np.median(hp_std * 1000)) pyl.savefig('HPstd_hist.png', type='png') return starResults, HPResults
def split_obs(nside,shift_size=5., splitNS=False, NorthOnly=False, SouthOnly=False, blocksize=1e6): """ XXX kill this function XXX replaced by just including neighboring healpixels""" """nside gives the number of sides for healpixels. shift_size is in degrees and sets how """ #XXX-prob should put in a check so I don't sort repeatedly #if not os.path.isfile('star_obs.dat.s'): waitpop('sort -nk 1 star_obs.dat > star_obs.dat.s') npix = hp.nside2npix(nside) keys = ('visitid', 'patchid', 'subpatch', 'nstars', 'ra', 'dec') patchfile='patchdata.dat' patchdat = ui.readDatafile(patchfile, keys) ord = np.argsort(patchdat['patchid']) for key in list(patchdat.keys()): patchdat[key]=patchdat[key][ord] shift_size = shift_size*np.pi/180. #1.*np.pi/180. #compute galactic coords for healpixels and patches heal={} heal['ra'], heal['dec'] = hp.pix2ang(nside, np.arange(npix)) heal['dec'] = heal['dec']-90.*np.pi/180. heal['b'] = galac_b(heal['ra'], heal['dec']) #np.arcsin(np.sin(heal['dec'])*np.cos(62.6*np.pi/180.)-np.cos(heal['dec'])*np.sin(heal['ra']-282.25*np.pi/180.)*np.sin(62.6*np.pi/180.)) patchdat['dec'] = patchdat['dec']*np.pi/180. patchdat['ra'] = patchdat['ra']*np.pi/180. patchdat['b'] = galac_b(patchdat['ra'], patchdat['dec']) patchdat['l'] = galac_l(patchdat['ra'], patchdat['dec']) patchdat['dec']=patchdat['dec']+90.*np.pi/180. #stupid healpix wants 0-180 I think... patch_healpix = hp.ang2pix(nside, patchdat['dec'], patchdat['ra']) pyl.figure() cpu.plot_density(patchdat['ra'], patchdat['dec'], z=patch_healpix) pyl.savefig('heal_check.png', type='png') patch_healpix_shifted1 = hp.ang2pix(nside, patchdat['dec']+shift_size, patchdat['ra']+shift_size*2) patch_healpix_shifted2 = hp.ang2pix(nside, patchdat['dec']-shift_size, patchdat['ra']+shift_size*2) patch_healpix_shifted3 = hp.ang2pix(nside, patchdat['dec']+shift_size, patchdat['ra']-shift_size*2) patch_healpix_shifted4 = hp.ang2pix(nside, patchdat['dec']-shift_size, patchdat['ra']-shift_size*2) pyl.figure() cpu.plot_density(patchdat['ra'], patchdat['dec'], z=patch_healpix_shifted1) pyl.savefig('heal_check1.png', type='png') #ok, just go through and set duplicates to -1. Also set any of the shifted ones that are not in patch_healpix to -1 uhp = np.unique(patch_healpix) patch_healpix_shifted1[np.invert(np.in1d(patch_healpix_shifted1, uhp))] = -1 patch_healpix_shifted2[np.invert(np.in1d(patch_healpix_shifted2, uhp))] = -1 patch_healpix_shifted3[np.invert(np.in1d(patch_healpix_shifted3, uhp))] = -1 patch_healpix_shifted4[np.invert(np.in1d(patch_healpix_shifted4, uhp))] = -1 diff = patch_healpix_shifted1-patch_healpix good = np.where(diff == 0) patch_healpix_shifted1[good] = -1 diff1 = patch_healpix_shifted2-patch_healpix diff2 = patch_healpix_shifted2-patch_healpix_shifted1 good = np.where( (diff1 == 0) | (diff2 == 0)) patch_healpix_shifted2[good] = -1 diff1 = patch_healpix_shifted3-patch_healpix diff2 = patch_healpix_shifted3-patch_healpix_shifted1 diff3 = patch_healpix_shifted3-patch_healpix_shifted2 good = np.where( (diff1 == 0) | (diff2 == 0) | (diff3 == 0)) patch_healpix_shifted3[good] = -1 diff1 = patch_healpix_shifted4-patch_healpix diff2 = patch_healpix_shifted4-patch_healpix_shifted1 diff3 = patch_healpix_shifted4-patch_healpix_shifted2 diff4 = patch_healpix_shifted4-patch_healpix_shifted3 good = np.where( (diff1 == 0) | (diff2 == 0) | (diff3 == 0) | (diff4 == 0)) patch_healpix_shifted4[good] = -1 pyl.figure() cpu.plot_density(patchdat['ra'], patchdat['dec'], z=patch_healpix_shifted1) pyl.savefig('heal_check1_post.png', type='png') heal_pixels = np.unique(patch_healpix) keys = [patch_healpix, patch_healpix_shifted1, patch_healpix_shifted2,patch_healpix_shifted3,patch_healpix_shifted4] filenames = ['hp1.dat','hp2.dat','hp3.dat','hp4.dat','hp5.dat'] #ok, if a healpix stradles b =0, I want to split it in two # I could also just loop through each HP. if the HP has patches w/ b> 0 and b< 0 and min l < xxx or max l < xxx, then break it apart. if splitNS: break_up = np.where( (patchdat['b'] < 0) & ( (patchdat['l'] < 120.*np.pi/180.) | (patchdat['l'] > 240)*np.pi/180.) & (np.abs(patchdat['b']) < 5*np.pi/180.)) for key in keys: mask=np.where(key == -1) key[break_up] = key[break_up]+max(heal_pixels)+1 key[mask] = -1 print('reading star_obs.dat.s') star_obs = open('star_obs.dat.s', 'r') #read in just the patch id's from star_obs all_patch_ids = [] for line in star_obs: if line.startswith('#'): continue linevalues = line.split() all_patch_ids.append(linevalues[0]) all_patch_ids = np.array(all_patch_ids, dtype=np.int) star_obs.close() for j in np.arange(4): filename = filenames[j] patch_healpix = keys[j] hpid = all_patch_ids*0 left = np.searchsorted(all_patch_ids, patchdat['patchid']) right = np.searchsorted(all_patch_ids, patchdat['patchid'], side='right') for i in np.arange(np.size(left)): hpid[left[i]:right[i]] = patch_healpix[i] print('left %i, hpid %i, all_patch_ids %i, patch_healpix %i '%(np.size(left), np.size(hpid), np.size(all_patch_ids), np.size( patch_healpix))) file = open(filename,'w') print("#", file=file) for value in hpid: print(value, file=file) file.close() #print j, np.size(hpid), np.size(all_patch_ids) waitpop('paste hp1.dat star_obs.dat.s > hp1_star_obs.dat') waitpop('paste hp2.dat star_obs.dat.s > hp2_star_obs.dat') waitpop("sed -i '/^-1/d' hp2_star_obs.dat" ) waitpop('paste hp3.dat star_obs.dat.s > hp3_star_obs.dat') waitpop("sed -i '/^-1/d' hp3_star_obs.dat" ) waitpop('paste hp4.dat star_obs.dat.s > hp4_star_obs.dat') waitpop("sed -i '/^-1/d' hp4_star_obs.dat" ) waitpop('paste hp5.dat star_obs.dat.s > hp5_star_obs.dat') waitpop("sed -i '/^-1/d' hp5_star_obs.dat" ) #waitpop("mv temp.dat hp2_star_obs.dat") waitpop('cat hp2_star_obs.dat >> hp1_star_obs.dat') waitpop('cat hp3_star_obs.dat >> hp1_star_obs.dat') waitpop('cat hp4_star_obs.dat >> hp1_star_obs.dat') waitpop('cat hp5_star_obs.dat >> hp1_star_obs.dat') waitpop(''' awk '{print $2" "$3" "$4" "$5 " "$6> ("h"$1"star_obs.dat")}' hp1_star_obs.dat''') waitpop('rm h#star_obs.dat') waitpop('mv hp1_star_obs.dat star_obs_hp1.dat') waitpop('mv hp2_star_obs.dat star_obs_hp2.dat') waitpop('mv hp3_star_obs.dat star_obs_hp3.dat') waitpop('mv hp4_star_obs.dat star_obs_hp4.dat') waitpop('mv hp5_star_obs.dat star_obs_hp5.dat')
histrange = [maglim[0] * 2, maglim[1] * 2] # or set range for histogram nbins = 100 # or set number of bins for histogram cp.histogram_stars_dmagcaltrue(stardat, nbins=nbins, range=histrange, etitle=etitle) if iteration_number > 0: figname = "S%ddmag_hist." % (iteration_number) else: figname = "Sdmag_hist." if savefig: pyl.savefig(figname + figformat, format=figformat) #just make a generic plot of the stellar density cpu.plot_density(stardat['x'], stardat['y'], radecgrid=True, zlimits=[0, 30]) pyl.title('Stellar density') if savefig: pyl.savefig('Stardensity.png', format='png') cpu.plot_density(stardat['x'], stardat['y'], z=stardat['magtrue'], z_method=ninety, radecgrid=True, zlimits=[ n.min(stardat['magtrue']), stats.scoreatpercentile(stardat['magtrue'], 98) ]) pyl.title('90th percentile magnitude') if savefig:
if maglim == None: histrange = None else: histrange = [maglim[0]*2, maglim[1]*2] # or set range for histogram nbins = 100 # or set number of bins for histogram cp.histogram_stars_dmagcaltrue(stardat, nbins=nbins, range=histrange, etitle=etitle) if iteration_number > 0 : figname = "S%ddmag_hist." %(iteration_number) else: figname = "Sdmag_hist." if savefig: pyl.savefig(figname + figformat, format=figformat) #just make a generic plot of the stellar density cpu.plot_density(stardat['x'],stardat['y'],radecgrid=True, zlimits=[0,30]) pyl.title('Stellar density') if savefig: pyl.savefig('Stardensity.png', format='png') cpu.plot_density(stardat['x'],stardat['y'],z=stardat['magtrue'],z_method=ninety,radecgrid=True, zlimits=[n.min(stardat['magtrue']), stats.scoreatpercentile(stardat['magtrue'], 98)]) pyl.title('90th percentile magnitude') if savefig: pyl.savefig('Starmag90.png', format='png') cpu.plot_density(stardat['x'],stardat['y'],z=stardat['color'],radecgrid=True) pyl.title('Average $g-i$')
def split_obs(nside, shift_size=5., splitNS=False, NorthOnly=False, SouthOnly=False, blocksize=1e6): """ XXX kill this function XXX replaced by just including neighboring healpixels""" """nside gives the number of sides for healpixels. shift_size is in degrees and sets how """ #XXX-prob should put in a check so I don't sort repeatedly #if not os.path.isfile('star_obs.dat.s'): waitpop('sort -nk 1 star_obs.dat > star_obs.dat.s') npix = hp.nside2npix(nside) keys = ('visitid', 'patchid', 'subpatch', 'nstars', 'ra', 'dec') patchfile = 'patchdata.dat' patchdat = ui.readDatafile(patchfile, keys) ord = np.argsort(patchdat['patchid']) for key in list(patchdat.keys()): patchdat[key] = patchdat[key][ord] shift_size = shift_size * np.pi / 180. #1.*np.pi/180. #compute galactic coords for healpixels and patches heal = {} heal['ra'], heal['dec'] = hp.pix2ang(nside, np.arange(npix)) heal['dec'] = heal['dec'] - 90. * np.pi / 180. heal['b'] = galac_b( heal['ra'], heal['dec'] ) #np.arcsin(np.sin(heal['dec'])*np.cos(62.6*np.pi/180.)-np.cos(heal['dec'])*np.sin(heal['ra']-282.25*np.pi/180.)*np.sin(62.6*np.pi/180.)) patchdat['dec'] = patchdat['dec'] * np.pi / 180. patchdat['ra'] = patchdat['ra'] * np.pi / 180. patchdat['b'] = galac_b(patchdat['ra'], patchdat['dec']) patchdat['l'] = galac_l(patchdat['ra'], patchdat['dec']) patchdat['dec'] = patchdat[ 'dec'] + 90. * np.pi / 180. #stupid healpix wants 0-180 I think... patch_healpix = hp.ang2pix(nside, patchdat['dec'], patchdat['ra']) pyl.figure() cpu.plot_density(patchdat['ra'], patchdat['dec'], z=patch_healpix) pyl.savefig('heal_check.png', type='png') patch_healpix_shifted1 = hp.ang2pix(nside, patchdat['dec'] + shift_size, patchdat['ra'] + shift_size * 2) patch_healpix_shifted2 = hp.ang2pix(nside, patchdat['dec'] - shift_size, patchdat['ra'] + shift_size * 2) patch_healpix_shifted3 = hp.ang2pix(nside, patchdat['dec'] + shift_size, patchdat['ra'] - shift_size * 2) patch_healpix_shifted4 = hp.ang2pix(nside, patchdat['dec'] - shift_size, patchdat['ra'] - shift_size * 2) pyl.figure() cpu.plot_density(patchdat['ra'], patchdat['dec'], z=patch_healpix_shifted1) pyl.savefig('heal_check1.png', type='png') #ok, just go through and set duplicates to -1. Also set any of the shifted ones that are not in patch_healpix to -1 uhp = np.unique(patch_healpix) patch_healpix_shifted1[np.invert(np.in1d(patch_healpix_shifted1, uhp))] = -1 patch_healpix_shifted2[np.invert(np.in1d(patch_healpix_shifted2, uhp))] = -1 patch_healpix_shifted3[np.invert(np.in1d(patch_healpix_shifted3, uhp))] = -1 patch_healpix_shifted4[np.invert(np.in1d(patch_healpix_shifted4, uhp))] = -1 diff = patch_healpix_shifted1 - patch_healpix good = np.where(diff == 0) patch_healpix_shifted1[good] = -1 diff1 = patch_healpix_shifted2 - patch_healpix diff2 = patch_healpix_shifted2 - patch_healpix_shifted1 good = np.where((diff1 == 0) | (diff2 == 0)) patch_healpix_shifted2[good] = -1 diff1 = patch_healpix_shifted3 - patch_healpix diff2 = patch_healpix_shifted3 - patch_healpix_shifted1 diff3 = patch_healpix_shifted3 - patch_healpix_shifted2 good = np.where((diff1 == 0) | (diff2 == 0) | (diff3 == 0)) patch_healpix_shifted3[good] = -1 diff1 = patch_healpix_shifted4 - patch_healpix diff2 = patch_healpix_shifted4 - patch_healpix_shifted1 diff3 = patch_healpix_shifted4 - patch_healpix_shifted2 diff4 = patch_healpix_shifted4 - patch_healpix_shifted3 good = np.where((diff1 == 0) | (diff2 == 0) | (diff3 == 0) | (diff4 == 0)) patch_healpix_shifted4[good] = -1 pyl.figure() cpu.plot_density(patchdat['ra'], patchdat['dec'], z=patch_healpix_shifted1) pyl.savefig('heal_check1_post.png', type='png') heal_pixels = np.unique(patch_healpix) keys = [ patch_healpix, patch_healpix_shifted1, patch_healpix_shifted2, patch_healpix_shifted3, patch_healpix_shifted4 ] filenames = ['hp1.dat', 'hp2.dat', 'hp3.dat', 'hp4.dat', 'hp5.dat'] #ok, if a healpix stradles b =0, I want to split it in two # I could also just loop through each HP. if the HP has patches w/ b> 0 and b< 0 and min l < xxx or max l < xxx, then break it apart. if splitNS: break_up = np.where((patchdat['b'] < 0) & ((patchdat['l'] < 120. * np.pi / 180.) | (patchdat['l'] > 240) * np.pi / 180.) & (np.abs(patchdat['b']) < 5 * np.pi / 180.)) for key in keys: mask = np.where(key == -1) key[break_up] = key[break_up] + max(heal_pixels) + 1 key[mask] = -1 print('reading star_obs.dat.s') star_obs = open('star_obs.dat.s', 'r') #read in just the patch id's from star_obs all_patch_ids = [] for line in star_obs: if line.startswith('#'): continue linevalues = line.split() all_patch_ids.append(linevalues[0]) all_patch_ids = np.array(all_patch_ids, dtype=np.int) star_obs.close() for j in np.arange(4): filename = filenames[j] patch_healpix = keys[j] hpid = all_patch_ids * 0 left = np.searchsorted(all_patch_ids, patchdat['patchid']) right = np.searchsorted(all_patch_ids, patchdat['patchid'], side='right') for i in np.arange(np.size(left)): hpid[left[i]:right[i]] = patch_healpix[i] print('left %i, hpid %i, all_patch_ids %i, patch_healpix %i ' % (np.size(left), np.size(hpid), np.size(all_patch_ids), np.size(patch_healpix))) file = open(filename, 'w') print("#", file=file) for value in hpid: print(value, file=file) file.close() #print j, np.size(hpid), np.size(all_patch_ids) waitpop('paste hp1.dat star_obs.dat.s > hp1_star_obs.dat') waitpop('paste hp2.dat star_obs.dat.s > hp2_star_obs.dat') waitpop("sed -i '/^-1/d' hp2_star_obs.dat") waitpop('paste hp3.dat star_obs.dat.s > hp3_star_obs.dat') waitpop("sed -i '/^-1/d' hp3_star_obs.dat") waitpop('paste hp4.dat star_obs.dat.s > hp4_star_obs.dat') waitpop("sed -i '/^-1/d' hp4_star_obs.dat") waitpop('paste hp5.dat star_obs.dat.s > hp5_star_obs.dat') waitpop("sed -i '/^-1/d' hp5_star_obs.dat") #waitpop("mv temp.dat hp2_star_obs.dat") waitpop('cat hp2_star_obs.dat >> hp1_star_obs.dat') waitpop('cat hp3_star_obs.dat >> hp1_star_obs.dat') waitpop('cat hp4_star_obs.dat >> hp1_star_obs.dat') waitpop('cat hp5_star_obs.dat >> hp1_star_obs.dat') waitpop( ''' awk '{print $2" "$3" "$4" "$5 " "$6> ("h"$1"star_obs.dat")}' hp1_star_obs.dat''' ) waitpop('rm h#star_obs.dat') waitpop('mv hp1_star_obs.dat star_obs_hp1.dat') waitpop('mv hp2_star_obs.dat star_obs_hp2.dat') waitpop('mv hp3_star_obs.dat star_obs_hp3.dat') waitpop('mv hp4_star_obs.dat star_obs_hp4.dat') waitpop('mv hp5_star_obs.dat star_obs_hp5.dat')