def plotMagDiff(args, show=False): """ options """ # bins_mag = np.linspace(0.0, 24.0, 50) title = args.title fileInName = args.input.split(",") keys_mags=['G_Gaia', 'phot_g_mean_mag'] """ read input file """ cols, _ = getCols(fileInName[0], keys_mags, select=args.select, dictionary=True) """ initialise figure """ fig = plt.figure(figsize=(FIGX, FIGX)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'Gaia', r'Tycho-2 (emulated)', [3.0, 14.0], [3.0, 14.0], title=title) hb = ax.hexbin(cols[keys_mags[0]], cols[keys_mags[1]], gridsize=80, mincnt=1, cmap='viridis') x = np.linspace(0.0, 20.0, 50) ax.plot(x, x, color='black') fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def CAMIRA(args, show=False): """ Options """ fileInName = args.input.split(",") labels = args.labels.split(",") #title = os.path.basename(args.input) title = args.title #fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca() fig, ax = plt.subplots(2, 1, sharex=True, sharey=True, figsize=(FIGX*0.8, FIGX*0.8)); size = MARKER_SIZE for i,f in enumerate(fileInName): if i == 0: plot_utils.axes(ax[i], '', r'$\frac{\^N_\mathrm{m}-\^N_\mathrm{m, w/masks}}{\^N_\mathrm{m, w/masks}}$', [0.0, 1.2], [-0.5, 1.0], title=title, fontsize = FONT_SIZE) else: plot_utils.axes(ax[i], r'Cluster redshift' , r'$\frac{\^N_\mathrm{m}-\^N_\mathrm{m, w/masks}}{\^N_\mathrm{m, w/masks}}$', [0.0, 1.2], [-0.5, 1.0], title=title, fontsize = FONT_SIZE) ax[i].plot([0.0, 1.20], [0.0, 0.0], lw=size, color='black', ls=':') data = ascii.read("{0:s}".format(f)) z = data['z_nomask'] eta = (data['N_nomask']-data['N_mask'])/data['N_mask'] if "sirius" in f: alpha = 1.0 color='red' else: alpha = 1.0 color='blue' plot_utils.markers(ax[i], z, eta, None, size/3.0, color, labels[i], alpha=alpha) ax[i].locator_params(axis='y', nbins=4) if not args.nolegend: ax[i].legend( frameon=False, numpoints=1, loc='upper right') fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return return
def plotSeeingDist(args, show=False): title = args.title # input data points fileInName = args.input.split(",") keys=['gpsf_pix', 'rpsf_pix', 'ipsf_pix', 'zpsf_pix', 'ypsf_pix'] filtName = dict(zip(keys, ['g', 'r', 'i', 'z', 'Y'])) PSF, _ = getCols(fileInName[0], keys, dictionary=True) # convert to FWHM for k,v in PSF.items(): v *= 0.17 * 2.0 * np.sqrt(2) # randoms db is in pixel # Initialise figure fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'PSF size [arcsec]', r'n', [0.3, 1.5], [0.0, 5.0], title=title) ymax=0.0 for i,k in enumerate(keys): hist, bin_edges = np.histogram(PSF[k], bins=50, range=[0.3, 2.0], density=True) bins = (bin_edges[1:]+bin_edges[:-1])/2.0 ax.fill_between(bins, 0.0*hist, hist, color=COLOR[i], alpha=0.2, label='') ax.plot(bins, hist, color=COLOR[i], lw=size, label=filtName[k]) ymax=max(ymax, np.max(hist)) ax.set_ylim([0.0, ymax*1.2]) if not args.nolegend: plt.legend( frameon=False, numpoints=1, ncol=1) fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotWoftheta(args, show=False): """ Options """ fileInName = args.input.split(",") labels = args.labels.split(",") #title = os.path.basename(args.input) title = args.title fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'$\theta$ [deg]', r'$w(\theta)$', [5.e-5, 3.e0], [4e-5, 8.e1], title=title, xlog=True, ylog=True, xexp=True, yexp=True) IC=0.0 for i,f in enumerate(fileInName): data = ascii.read("{0:s}".format(f), format="no_header") select = (data['col2'] > 0.0) & (data['col3'] > 0.0) if "CFHTLenS" in f: ax.plot(data['col1'][select], (data['col2'][select]+IC), lw=size, color=COLOR[i], label=labels[i]) #ax.fill_between(data['col1'][select], data['col2'][select]-data['col3'][select], data['col2'][select]+data['col3'][select], color=COLOR[i], alpha=0.2, label=labels[i]) else: alpha = 1.0 if "oldMask" in f or "insideNewMask" in f: alpha = 0.5 plot_utils.markers(ax, data['col1'][select], (data['col2'][select]+IC), data['col3'][select], size, COLOR[i-1], labels[i], alpha=alpha) if not args.nolegend: plt.legend( frameon=False, numpoints=1, loc='lower left') fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotSimuEta(args, show=False): fig = plt.figure(figsize=(FIGX, FIGX)); ax = plt.gca(); size = 2 plot_utils.axes(ax, "$\mathrm{Flux\,error}_\mathrm{DC2} \\times $" , "$\eta$", [1.70, 0.01], [5.0, 20.0], title=args.title) data = ascii.read("{0:s}".format(args.input), format="commented_header", header_start=-1) #N = [float(n) for n in data['N']] err = 1.0/np.sqrt(12000.0)*data['eta'] plot_utils.markers(ax, data['factor'], data['eta'], err, size, COLOR[0], 'Simulation') popt, pcov = curve_fit(power_law, data['factor'], data['eta'], sigma=err) x = np.linspace(ax.get_xlim()[0], ax.get_xlim()[1]) ax.plot(x, power_law(x, popt[0], popt[1]), color= COLOR[0], lw=2) plot_utils.markers(ax, [1.0], [15.64], err[0], size, COLOR[1], 'DC2') ax.plot(ax.get_xlim(), [10.0, 10.0], color=COLOR[2], label='Requirement', lw=size) #return # ----------------------------------------------------------------- # # save figure # ----------------------------------------------------------------- # plt.legend(loc='upper right', frameon=False, numpoints=1) fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotScatter(args, show=False): zmin = args.zmin zmax = args.zmax fig = plt.figure(figsize=(FIGX, FIGX)); ax = plt.gca(); size = FONT_SIZE plot_utils.axes(ax, "$z_\mathrm{spectro}$" , "$z_\mathrm{photo}$", [zmin, zmax], [zmin, zmax], title=args.title) # ----------------------------------------------------------------- # # scatter plot # ----------------------------------------------------------------- # fileInName=args.input.split(",") if args.weight_key is not None: [zp, zs, weight], _ = getCols(fileInName[0], [args.zp_key, args.zs_key, args.weight_key], selection=args.select) else: [zp, zs], _ = getCols(fileInName[0], [args.zp_key, args.zs_key], selection=args.select) weight = None if weight is not None: from scipy import stats # [mode, _] = stats.mode(weight) # weight /= mode indices=[] for i,w in enumerate(weight): for n in range(np.random.poisson(w)): indices.append(i) zp = zp[indices] zs = zs[indices] if args.density: hh, locx, locy = np.histogram2d(zs, zp, range=[[zmin, zmax],[zmin, zmax]], bins=[150, 150]) # hh, locx, locy = np.histogram2d(zs, zp, range=[[zmin, zmax],[zmin, zmax]], bins=[80, 80]) hh[hh < EPS] = np.nan ax.imshow(np.log(hh.T), origin="lower", cmap='Blues', extent=np.array([[zmin, zmax],[zmin, zmax]]).flatten(), aspect='auto', interpolation="nearest") else: plot_utils.markers(ax, zs, zp, None, 0.3, COLOR[0], "") # ----------------------------------------------------------------- # # stats # ----------------------------------------------------------------- # sigma, eta, bias, eta2sig = stats_zpzs(zp, zs, [zmin, zmax]) stats_string = '$N_\mathrm{{gals}}$ = {0}'.format(len(zp)) stats_string += '\n$\sigma = {0:5.3f} \\times (1+z)$'.format(sigma[0]) stats_string += '\n$\eta = {0:5.2f}\%$'.format(eta[0]) stats_string += '\nbias$ = {0:5.3f} \\times (1+z)$'.format(bias[0]) # stats_string += '\n$\eta_{{2\sigma}}/(1+z) = {0:5.2f}\%$'.format(eta2sig[0]) ax.text(0.05*(zmax-zmin)+zmin, 0.75*(zmax-zmin)+zmin, stats_string, size=FONT_SIZE) # ----------------------------------------------------------------- # # red lines # ----------------------------------------------------------------- # x = np.arange(zmin, zmax, 0.01) ax.plot(x, x, 'r-', lw=2) ax.plot(x, x + 0.15*(1+x), 'r:', lw=2) ax.plot(x, x - 0.15*(1+x), 'r:', lw=2) # ----------------------------------------------------------------- # # save figure # ----------------------------------------------------------------- # fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return #print len(zp) return
def PSFwGhost(args, show=False): rmin = 0.05 rmax = 500 cmax = 1.0 cmin = 1.0E-12 xlabel = 'r (arcsec)' ylabel = 'Contrast' r = np.arange(0, rmax, 0.05) k1 = kolmogorov(r, 0.25, 7, 0.86) k2 = kolmogorov(r, 0.25, 2, 0.14) k = [] for i in range(len(k1)): k.append(k1[i]+k2[i]) ip = instpsf(r) cg1 = circ_ghost(r, 2.25*11.2, 3.53547E-08) cg2 = circ_ghost(r, 4.68*11.2, 4.1028E-09) cg3 = circ_ghost(r, 27.66*11.2, 1.1742E-09) cg4 = circ_ghost(r, 13.83*11.2, 9.40048E-10) cg5 = circ_ghost(r, 13.85*11.2, 4.68405E-10) cg6 = circ_ghost(r, 23.00*11.2, 3.39806E-10) cg7 = circ_ghost(r, 9.18*11.2, 2.13051E-10) cg8 = circ_ghost(r, 25.42*11.2, 1.39032E-10) cg9 = circ_ghost(r, 11.59*11.2, 1.33885E-10) cg10 = circ_ghost(r, 20.76*11.2, 4.17137E-11) t = [] for i in range(len(k)): t.append(k[i]+cg1[i]+cg2[i]+cg3[i]+cg4[i]+cg5[i]+cg6[i]+cg7[i]+cg8[i]+cg9[i]+cg10[i]) fig = plt.figure(figsize=(FIGX, FIGX)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'$r\,\,\mathrm{[arcsec]}$', r'Contrast', [rmin, rmax], [cmin, cmax], ylog=True, xlog=True, yexp=True, title=args.title) #ax.yscale('log') ax.plot(r, ip, color='green', marker=".", markersize=0, linewidth=size, linestyle="--", label="Instrumental") ax.plot(r, k, color='blue', marker=".", markersize=0, linewidth=size, linestyle="-", label="Atmospheric") ax.plot(r, k1, color='blue', marker=".", markersize=0, linewidth=size, linestyle=":", label=r"Moffat ($\beta=7$)") ax.plot(r, k2, color='blue', marker=".", markersize=0, linewidth=size, linestyle="-.", label=r"Moffat ($\beta=2$)") ax.plot(r, cg1, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg2, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg3, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg4, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg5, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg6, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg7, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg8, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg9, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, cg10, color='red', marker=".", markersize=0, linewidth=size/2.0, linestyle=":", label="") ax.plot(r, t, color='black', marker=".", markersize=0, linewidth=size, linestyle="-", label="Total") ax.text(0.1, 3.53547E-08, 'CCD-WinS2', fontsize=FONT_SIZE/1.5) ax.text(0.1, 4.1028E-09, 'FilS2-FilS1', fontsize=FONT_SIZE/1.5) ax.text(0.1, 1.1742E-09, 'CCD-FilS1', fontsize=FONT_SIZE/1.5) #ax.text(0.1, 9.40048E-10, 'CCD-WinS1') ax.text(0.1, 5.40048E-10, 'CCD-WinS1', fontsize=FONT_SIZE/1.5) #ax.legend((sptype,), loc=0) #ax.xticks() #ax.yticks() #ax.xlim(rmin, rmax) #ax.ylim(cmin, cmax) #ax.xscale('log') #ax.yscale('log') #ax.locator_params(axis='y', nbins=5) if not args.nolegend: plt.legend(frameon=False, numpoints=1, ncol=1, loc='upper right') ax.set_rasterized(True) fig.set_tight_layout(True) fig.savefig(args.output, dpi=300) if show: plt.show() return
def plotSourceDensity(args, show=False): from scipy.optimize import curve_fit title = args.title fileInName = args.input.split(",") rmax = float(args.rmax) if args.labels is None: label = fileInName else: label = args.labels.split(",") """ initialise figure """ xmin = 3.0 xmax = rmax #sys.stderr.write("{0:f} {1:f}".format(xmin, xmax)) # return fig = plt.figure(figsize=(FIGX*0.7, FIGY*0.7)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'$r\,\,\mathrm{[arcsec]}$', r'Source density', [xmin, xmax], [0.0, 2.5], ylog=False, title=title) """ loop over input files """ ymax = 0.0 for i,(l,f) in enumerate(zip(label,fileInName)): data = ascii.read(f, header_start=-1) bins = data['r'] histIsoptropic = data['nIsotropic'] histBleedTrail = data['nBleedTrail'] histSpikes = data['nSpikes'] hist = histIsoptropic ax.fill_between(bins, 0.0*hist, hist, color=COLOR[i], alpha=0.2, label=l) #, drawstyle="steps") # first file = parent incompleteness if i == 0: histIsoptropicParent = histIsoptropic histBleedTrailParent = histBleedTrail histSpikesParent = histSpikes popt, pcov = curve_fit(BM.completness_func, bins, histIsoptropic, p0=[rmax/2.0, 5.0]) ax.plot(bins, BM.completness_func(bins, popt[0], popt[1]), color=COLOR[i], lw=size, label='', ls='--') # second file = children overdensity if i == 1: histIsoptropicPrimary = histIsoptropic histBleedTrailPrimary = histBleedTrail histSpikesPrimary = histSpikes radiusIsotropic = BM.getRadius(bins, histIsoptropicParent, histIsoptropicPrimary, rmax, args.mag) radiusBleedTrail = BM.getRadius(bins, histBleedTrailParent, histBleedTrailPrimary, rmax, args.mag) radiusSpikeRadius = BM.getRadius(bins, histSpikesParent, histSpikesPrimary, rmax, args.mag) ax.arrow(radiusIsotropic, 1.70, 0.0, -0.20 , head_width=(xmax-xmin)*0.02, head_length=0.1, fc='black', ec='black') #ax.arrow(YSpikeRadius, 1.60, 0.0, -0.30 , head_width=(xmax-xmin)*0.02, head_length=0.1, fc='magenta', ec='magenta') if not args.nolegend: plt.legend(frameon=False, numpoints=1, ncol=1, loc='upper left') #ax.locator_params(axis='x', nticks=3) ax.set_xlim([xmin, xmax]) ax.locator_params(axis='x', nbins=5) fig.subplots_adjust(bottom=0.18) fig.subplots_adjust(left=0.18) #fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return if not args.nolegend: plt.legend(frameon=False, numpoints=1, ncol=1, loc='upper left') #ax.locator_params(axis='x', nticks=3) ax.set_xlim([xmin, xmax]) ax.locator_params(axis='x', nbins=5) fig.subplots_adjust(bottom=0.15) #fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show()
def plotMaskRadius(args, show=False): from scipy.optimize import curve_fit title = args.title brightest = BM.MAG_BRIGHTEST limit = BM.MAG_LIMIT # Initialise figure fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'$G_{\rm Gaia}$ [mag]', r'r [arcsec]', [2.0, 18.5], [3.0, 1.e4], yexp=True, ylog=True, title=title) ax.locator_params(axis='x', nticks=4) ax.fill_between([brightest, limit], [3.0, 3.0], [1.e4, 1.e4], color=COLOR[0], alpha=0.1) ax.text((brightest+limit)/2.0, 10.0, 'Extended \n halo', horizontalalignment='center', verticalalignment='center', fontsize=FONT_SIZE, color=COLOR[0]) G_Gaia = np.linspace(brightest, 18.0, num=100) fileInName = args.input.split(",") r_Czakon = 200.0*pow(10.0, 0.25*(7.0 - G_Gaia)) + 12.0*pow(10.0, 0.05*(16.0 - G_Gaia)) ax.plot(G_Gaia, r_Czakon, color=COLOR[1], lw=size, label='Sirius (old)', ls='--') maskRadiusPara = ascii.read(fileInName[1], header_start=-1) bright = maskRadiusPara["mask_type"] == "bright" faint = maskRadiusPara["mask_type"] == "faint" allStars = ascii.read(fileInName[0], header_start=-1) x = allStars['mag'] y = allStars['radiusIsotropic'] #ax.plot(x, y, color=COLOR[i], lw=size, label='Mask radius') plot_utils.markers(ax, x, y, y*0.0, size, COLOR[0], '') ax.plot(G_Gaia[G_Gaia < limit], BM.r_vs_mag(G_Gaia[G_Gaia < limit], maskRadiusPara["a"][bright], maskRadiusPara["b"][bright]), color=COLOR[0], lw=size, label='Arcturus (this work)') ax.plot(G_Gaia[G_Gaia > limit], BM.r_vs_mag(G_Gaia[G_Gaia > limit], maskRadiusPara["a"][faint], maskRadiusPara["b"][faint]), color=COLOR[0], lw=size, label='') bestSeeing = ascii.read(fileInName[2], header_start=-1) select = np.isfinite(bestSeeing['seeing']) x = bestSeeing['mag'][select] y = bestSeeing['radiusIsotropic'][select] #ax.plot(x, y, color=COLOR[i], lw=size, label='Mask radius') plot_utils.markers(ax, x, y, None, size, COLOR[2], '10% best PSF', alpha=1.0, marker='^', fillstyle='none') #ax.scatter(x, y, label='10% best seeing', color=COLOR[2], marker=MARKER[1], fillstyle='none') print np.mean(bestSeeing['radiusIsotropic']/allStars['radiusIsotropic']) worstSeeing = ascii.read(fileInName[3], header_start=-1) select = np.isfinite(worstSeeing['seeing']) x = worstSeeing['mag'][select] y = worstSeeing['radiusIsotropic'][select] #ax.plot(x, y, color=COLOR[i], lw=size, label='Mask radius') plot_utils.markers(ax, x, y, None, size, COLOR[3], '10% worst PSF', alpha=1.0, marker='s', fillstyle='none') # ax.scatter(x, y, label='10% worst seeing', color=COLOR[3], marker=MARKER[0], s=5*size) print np.mean(worstSeeing['radiusIsotropic']/allStars['radiusIsotropic']) # plot_utils.markers(ax, x, data['radiusSpikes'], data['radiusIsotropic']*0.0, size, COLOR[2], 'Spikes') # plot_utils.markers(ax, x, data['radiusBleedTrail'], data['radiusBleedTrail']*0.0, size, COLOR[3], 'Bleedtrails') # ax.plot([limit, limit], [3.0, 1.e4], color='black', lw=size, ls='--', label='') ax.plot([brightest, brightest], [3.0, 1.e4], color='black', lw=size, ls=':', label='') if not args.nolegend: plt.legend( frameon=False, numpoints=1, ncol=1) fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotSaturVsSeeing(args, show=False): """ options """ bins_seeing = np.linspace(0.3, 1.3, 15) title = args.title fileInName = args.input.split(",") filters = ['g', 'r', 'i', 'z', 'Y'] keys_PSF=['gpsf_pix', 'rpsf_pix', 'ipsf_pix', 'zpsf_pix', 'ypsf_pix'] keys_mags=['gmag_psf', 'rmag_psf', 'imag_psf', 'zmag_psf', 'ymag_psf'] """ read input file """ cols, _ = getCols(fileInName[0], keys_PSF+keys_mags, select=args.select, dictionary=True) """ convert moments to FWHM """ for k in keys_PSF: cols[k] *= 2.0 * np.sqrt(2) # object db is in arcsec """ initialise figure """ fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'PSF size [arcsec]', r'PSF mag', [0.3, 1.40], [16.0, 22.0], title=title) """ loop over filters """ for i,f in enumerate(filters): """ loop over seeing bins """ x=[] lower=[] upper=[] median=[] for l,r in zip(bins_seeing[:-1], bins_seeing[1:]): select = (l < cols[keys_PSF[i]]) & (cols[keys_PSF[i]] < r) & (cols[keys_mags[i]] > 0.0) if select.any(): x.append(np.mean(cols[keys_PSF[i]][select])) lower.append(np.percentile(cols[keys_mags[i]][select], 25.0)) upper.append(np.percentile(cols[keys_mags[i]][select], 75.0)) median.append(np.percentile(cols[keys_mags[i]][select], 50.0)) print f, median[0] ax.fill_between(x, lower, upper, color=COLOR[i], alpha=0.2, label=f) ax.plot(x, median, color=COLOR[i], lw=size) """ legend """ if not args.nolegend: plt.legend( frameon=False, numpoints=1, ncol=1) """ output file """ fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotMagDist(args, show=False): """ options """ #bins_mag = np.linspace(0.0, 22.5, 200) bins_mag = np.linspace(0.0, 22.5, 100) title = args.title fileInName = args.input.split(",") keys = args.keys.split(",") if args.select is not None: sel = args.select.split(",") else: sel = ["" for i in range(len(keys))] if args.labels is None: labels = fileInName else: labels = args.labels.split(",") """ read data """ data = {} for l,f,k,s in zip(labels, fileInName, keys, sel): if s == "": s = None data[l], _ = getCols(f, [k], select=s) """ initialise figure """ fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'$G_\mathrm{Gaia}$', r'N', [8.0, 22.0], [0.5, 1e4], ylog=True, yexp=True, title=title) # plot_utils.axes(ax, r'$i$', r'N', [14.0, 23.0], [0.5, 1e4], ylog=True, yexp=True, title=title) """ loop over input files """ ymax = 0.0 for i,l in enumerate(labels): #hist, bin_edges = np.histogram(data[f], bins=50, range=[0.0, 20.0], density=False) #bins = (bin_edges[1:]+bin_edges[:-1])/2.0 #ax.fill_between(bins, 0.0*hist, hist, color=COLOR[i], alpha=0.2, label=f) if i == 2: hist, bin_edges, patches = ax.hist(data[l], bins_mag, histtype='step', color='black', fill=False, label=labels[i], lw=size) else: hist, bin_edges, patches = ax.hist(data[l], bins_mag, histtype='step', color=COLOR[i], alpha=0.3, fill=True, label=labels[i]) ymax=max(ymax, np.max(hist)) ax.set_ylim([0.0, ymax*1.2]) ax.locator_params(axis='x', nbins=5) #ax.set_ylim([0.0, ymax*1.2]) if not args.nolegend: plt.legend(frameon=False, numpoints=1, ncol=1, loc='upper left') fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotGalFrac(args, show=False): """ options """ bins_mag = np.linspace(5.0, 24.0, 100.0) title = args.title fileInName = args.input.split(",") if args.select is not None: sel = args.select.split(",") else: sel = ["" for i in len(keys)] """ read input files """ # HSC galaxies cols, _ = getCols(fileInName[0], ['G_Gaia', 'extended_HSC', 'extended_SDSS'], select=sel[0], dictionary=True) extended = cols['extended_HSC'] == 1 all_hist, bin_edges = np.histogram(cols['G_Gaia'], bins=bins_mag) extended_hist, bin_edges = np.histogram(cols['G_Gaia'][extended] , bins=bins_mag) nonZero = (all_hist > 0) & (extended_hist > 0) galFrac_from_HSC = np.array(extended_hist[nonZero], dtype='f')/np.array(all_hist[nonZero], dtype='f') galFrac_from_HSC_err = np.sqrt(np.array(extended_hist[nonZero], dtype='f'))/np.array(all_hist[nonZero], dtype='f') bins_HSC = ((bin_edges[1:]+bin_edges[:-1])/2.0)[nonZero] # SDSS galaxies in HSC sample extended = cols['extended_SDSS'] == 1 all_hist, bin_edges = np.histogram(cols['G_Gaia'], bins=bins_mag) extended_hist, bin_edges = np.histogram(cols['G_Gaia'][extended] , bins=bins_mag) nonZero = (all_hist > 0) & (extended_hist > 0) galFrac_from_HSC_SDSS = np.array(extended_hist[nonZero], dtype='f')/np.array(all_hist[nonZero], dtype='f') galFrac_from_HSC_SDSS_err = np.sqrt(np.array(extended_hist[nonZero], dtype='f'))/np.array(all_hist[nonZero], dtype='f') bins_HSC_SDSS = ((bin_edges[1:]+bin_edges[:-1])/2.0)[nonZero] # SDSS galaxies cols, _ = getCols(fileInName[1], ['G_Gaia', 'extended_SDSS'], select=sel[1], dictionary=True) extended = cols['extended_SDSS'] == 1 all_hist, bin_edges = np.histogram(cols['G_Gaia'], bins=bins_mag) extended_hist, bin_edges = np.histogram(cols['G_Gaia'][extended] , bins=bins_mag) nonZero = (all_hist > 0) & (extended_hist > 0) galFrac_from_SDSS = np.array(extended_hist[nonZero], dtype='f')/np.array(all_hist[nonZero], dtype='f') galFrac_from_SDSS_err = np.sqrt(np.array(extended_hist[nonZero], dtype='f'))/np.array(all_hist[nonZero], dtype='f') bins_SDSS = ((bin_edges[1:]+bin_edges[:-1])/2.0)[nonZero] """ initialise figure """ fig = plt.figure(figsize=(FIGX, FIGY)); ax = plt.gca(); size = MARKER_SIZE plot_utils.axes(ax, r'$G_\mathrm{Gaia}$', r'Galaxy fraction', [10.0, 22.0], [0.00, 0.30], ylog=False, title=title) ax.fill_between(bins_HSC, galFrac_from_HSC-galFrac_from_HSC_err, galFrac_from_HSC+galFrac_from_HSC_err, color=COLOR[0], alpha=0.2, label='HSC-SSP extended') ax.plot(bins_HSC, galFrac_from_HSC, color=COLOR[0], lw=size) ax.fill_between(bins_SDSS, galFrac_from_SDSS-galFrac_from_SDSS_err, galFrac_from_SDSS+galFrac_from_SDSS_err, color=COLOR[1], alpha=0.2, label='SDSS extended') ax.plot(bins_SDSS, galFrac_from_SDSS, color=COLOR[1], lw=size) ax.plot([18.0, 18.0], [0.0, 0.30], lw=size, ls='--', color='black') # ax.fill_between(bins_HSC_SDSS, galFrac_from_HSC_SDSS-galFrac_from_HSC_SDSS_err, galFrac_from_HSC_SDSS-galFrac_from_HSC_SDSS_err, color=COLOR[2], alpha=0.2, label='SDSS extended (in HSC-SSP)') # ax.plot(bins_HSC_SDSS, galFrac_from_HSC_SDSS, color=COLOR[2], lw=size) if not args.nolegend: plt.legend(frameon=False, numpoints=1, ncol=1, loc='upper left') fig.set_tight_layout(True) fig.savefig(args.output) if show: plt.show() return
def plotPDF(PDF, bins, N, fileOutName, zs=None, zp=None, PDF2=None, PDF3=None, xtitle="$z$", label="P(z)"): import plot_utils from matplotlib.backends.backend_pdf import PdfPages sys.stderr.write('Plot PDFs...') pp = PdfPages(fileOutName) if N > 30: indices = np.random.randint(0, high=N - 1, size=30) else: indices = range(N) for i in indices: fig = plot_utils.plt.figure(figsize=(FIGX, FIGY)) ax = plot_utils.plt.gca() size = FONT_SIZE plot_utils.axes(ax, xtitle, "PDF", [bins[0], bins[-1]], [0.0, 1.0], title=args.title) ylim = max(PDF[i, :]) nonZero = bins[PDF[i] > EPS] if len(nonZero) > 1: (xmin, xmax) = (nonZero[0], nonZero[-1]) else: (xmin, xmax) = (0.0, 6.0) ax.fill_between(bins, 0.0, PDF[i, :], color=COLOR[0], alpha=0.5, label=label) if PDF2 is not None: ax.fill_between(PDF2[1], 0.0, PDF2[0][i, :], color=COLOR[1], label=PDF2[2], alpha=0.5) ylim = max(ylim, max(PDF2[0][i, :])) nonZero = PDF2[1][PDF2[0][i, :] > EPS] (xmin, xmax) = (min(nonZero[0], xmin), max(nonZero[-1], xmax)) if PDF3 is not None: ax.fill_between(PDF3[1], 0.0, PDF3[0][i, :], color=COLOR[2], label=PDF3[2], alpha=0.5) ylim = max(ylim, max(PDF3[0][i, :])) nonZero = PDF3[1][PDF3[0][i, :] > EPS] (xmin, xmax) = (min(nonZero[0], xmin), max(nonZero[-1], xmax)) if zp is not None: ax.plot([zp[i], zp[i]], [0.0, ylim], '--', color=COLOR[3], lw=2, label="$z_\mathrm{phot}$") if zs is not None: ax.plot([zs[i], zs[i]], [0.0, ylim], '--', color=COLOR[4], lw=2, label="$z_\mathrm{spec}$") ax.set_ylim([0.0, ylim]) ax.set_xlim([xmin, xmax]) ax.legend(frameon=False, loc="upper right") fig.set_tight_layout(True) pp.savefig() pp.close() sys.stderr.write('done\n') return