def comparePrior(): ngauss = [512, 128] iter = ['1st', '6th'] color = ['k', 'red'] label = ['512 Gaussians', '128 Gaussians'] fig, ax = plt.subplots(1,2, figsize=(12,5)) for n, i, c, l in zip(ngauss, iter, color, label): xdgmmFilename = 'xdgmm.' + str(n) + 'gauss.dQ0.05.' + i + '.2MASS.All.npz.fit' xdgmm = XDGMM(filename=xdgmmFilename) for gg in range(xdgmm.n_components): if xdgmm.weights[gg] == np.max(xdgmm.weights): lab = l else: lab = None points = drawEllipse.plotvector(xdgmm.mu[gg], xdgmm.V[gg]) ax[0].plot(points[0,:],testXD.absMagKinda2absMag(points[1,:]), c, lw=1, alpha=xdgmm.weights[gg]/np.max(xdgmm.weights)) ax[1].plot(points[0,:], points[1,:], c, lw=1, alpha=xdgmm.weights[gg]/np.max(xdgmm.weights), label=lab) for a in ax: a.set_xlim(-0.5, 1.5) a.set_xlabel(r'$(J - K)^C$') ax[0].set_ylabel(r'$M_J^C$') ax[1].set_ylabel(r'$\varpi 10^{0.2\,m_J}$') ax[0].set_ylim(6, -6) ax[1].set_ylim(1100, -100) ax[1].legend(loc='lower left', fontsize=10) plt.tight_layout() fig.savefig('priorNgaussComparison.png')
def prior(xdgmm, ax): for gg in range(xdgmm.n_components): points = drawEllipse.plotvector(xdgmm.mu[gg], xdgmm.V[gg]) ax[0].plot(points[0, :], testXD.absMagKinda2absMag(points[1, :]), c, lw=1, alpha=xdgmm.weights[gg] / np.max(xdgmm.weights))
def priorSample(ngauss=128, quantile=0.5, iter='8th', survey='2MASS', dataFilename='All.npz', Nsamples=1.2e6, xdgmmFilename='xdgmm.fit', xlabel='X', ylabel='Y', contourColor='k'): setup_text_plots(fontsize=16, usetex=True) xdgmm = XDGMM(filename=xdgmmFilename) figPrior = plt.figure(figsize=(12, 5.5)) figPrior.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.95, wspace=0.1, hspace=0.1) sample = xdgmm.sample(Nsamples) negParallax = sample[:,1] < 0 nNegP = np.sum(negParallax) while nNegP > 0: sampleNew = xdgmm.sample(nNegP) sample[negParallax] = sampleNew negParallax = sample[:,1] < 0 nNegP = np.sum(negParallax) samplex = sample[:,0] sampley = testXD.absMagKinda2absMag(sample[:,1]) ax3 = figPrior.add_subplot(121) alpha = 0.1 xlim = [-0.25, 1.25] ylim = [6, -6] levels = 1.0 - np.exp(-0.5 * np.arange(1.0, 2.1, 1.0) ** 2) corner.hist2d(samplex, sampley, ax=ax3, levels=levels, bins=200, plot_datapoints=False, no_fill_contours=True, plot_density=False, color=contourColor) ax3.scatter(samplex, sampley, s=1, lw=0, c='k', alpha=alpha) ax4 = figPrior.add_subplot(122) for i in range(xdgmm.n_components): points = drawEllipse.plotvector(xdgmm.mu[i], xdgmm.V[i]) ax4.plot(points[0, :], testXD.absMagKinda2absMag(points[1,:]), 'k-', alpha=xdgmm.weights[i]/np.max(xdgmm.weights)) titles = ["Extreme Deconvolution\n resampling", "Extreme Deconvolution\n cluster locations"] ax = [ax3, ax4] for i in range(2): ax[i].set_xlim(xlim) ax[i].set_ylim(ylim[0], ylim[1]*1.1) ax[i].text(0.05, 0.95, titles[i], ha='left', va='top', transform=ax[i].transAxes, fontsize=18) ax[i].set_xlabel(xlabel, fontsize = 18) if i in (1, 3): ax[i].yaxis.set_major_formatter(plt.NullFormatter()) else: ax[i].set_ylabel(ylabel, fontsize = 18) figPrior.savefig('prior_ngauss' + str(ngauss) +'.png')
def plotPrior(xdgmm, ax, c='black', lw=1, stretch=False): for gg in range(xdgmm.n_components): points = drawEllipse.plotvector(xdgmm.mu[gg], xdgmm.V[gg]) if stretch: Stretch = av.PowerStretch(1. / 5) alpha = np.power(xdgmm.weights[gg] / np.max(xdgmm.weights), 1. / 10) else: alpha = xdgmm.weights[gg] / np.max(xdgmm.weights) ax.plot(points[0, :], testXD.absMagKinda2absMag(points[1, :]), c, lw=lw, alpha=alpha)
def plot_sample(x, y, samplex, sampley, xdgmm, xlabel='x', ylabel='y', xerr=None, yerr=None, ylim=(6, -6), xlim=(0.5, 1.5), errSubsample=1.2e6, thresholdScatter=0.1, binsScatter=200, c='black', norm=None, cmap=None, contourColor='k', posterior=False, ind=None, plot_contours=True, sdss5=False, whatsThatFeature=False, rasterized=False): prng = np.random.RandomState(1234567890) setup_text_plots(fontsize=16, usetex=True) plt.clf() alpha = 0.1 alpha_points = 0.01 figData = plt.figure(figsize=(12, 5.5)) figPrior = plt.figure(figsize=(12, 5.5)) for fig in [figData, figPrior]: fig.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.95, wspace=0.1, hspace=0.1) ax1 = figData.add_subplot(121) levels = 1.0 - np.exp(-0.5 * np.arange(1.0, 2.1, 1.0)**2) cNorm = plt.matplotlib.colors.LogNorm(vmin=3, vmax=1e5) #ax1.hist2d(x, y, bins=100, norm=cNorm, cmap='Greys') if sdss5: plot_contours = False im = corner.hist2d(x, y, ax=ax1, levels=levels, bins=200, no_fill_contours=True, plot_density=False, color=contourColor, rasterized=rasterized, plot_contours=plot_contours) #im = ax1.scatter(x, y, s=1, lw=0, c=c, alpha=alpha, norm=norm, cmap=cmap) ax2 = figData.add_subplot(122) if ind is None: ind = prng.randint(0, len(x), size=errSubsample) #ax2.scatter(x[ind], y[ind], s=1, lw=0, c='black', alpha=alpha_points) ax2.errorbar(x[ind], y[ind], xerr=xerr[ind], yerr=[yerr[0][ind], yerr[1][ind]], fmt="none", zorder=0, mew=0, ecolor='black', alpha=0.5, elinewidth=0.5) ax3 = figPrior.add_subplot(121) #ax3.hist2d(x, y, bins=100, norm=cNorm, cmap='Greys') #kdeDensity(ax3, samplex, sampley, threshold=thresholdScatter, bins=binsScatter, s=1, lw=0, alpha=alpha) corner.hist2d(samplex, sampley, ax=ax3, levels=levels, bins=200, no_fill_contours=True, plot_density=False, color=contourColor, rasterized=rasterized, plot_contours=False) ax3.scatter(samplex, sampley, s=1, lw=0, c='k', alpha=alpha) ax4 = figPrior.add_subplot(122) for i in range(xdgmm.n_components): points = drawEllipse.plotvector(xdgmm.mu[i], xdgmm.V[i]) ax4.plot(points[0, :], absMagKinda2absMag(points[1, :]), 'k-', alpha=xdgmm.weights[i] / np.max(xdgmm.weights)) #draw_ellipse(xdgmm.mu[i], xdgmm.V[i], scales=[2], ax=ax4, # ec='None', fc='gray', alpha=xdgmm.weights[i]/np.max(xdgmm.weights)*0.1) #xlim = ax4.get_xlim() #ylim = ylim #ax3.get_ylim() titles = [ "Observed Distribution", "Obs+Noise Distribution", "Extreme Deconvolution\n resampling", "Extreme Deconvolution\n cluster locations" ] if posterior: titles = [ "De-noised Expectation Values", "Posterior Distributions", "Extreme Deconvolution\n resampling", "Extreme Deconvolution\n cluster locations" ] if sdss5: titles = ['', '', '', ''] ax = [ax1, ax2, ax3, ax4] for i in range(4): ax[i].set_xlim(xlim) ax[i].set_ylim(ylim[0], ylim[1] * 1.1) #ax[i].xaxis.set_major_locator(plt.MultipleLocator([-1, 0, 1])) #ax[i].yaxis.set_major_locator(plt.MultipleLocator([3, 4, 5, 6])) ax[i].text(0.05, 0.95, titles[i], ha='left', va='top', transform=ax[i].transAxes, fontsize=18) #if i in (0, 1): # ax[i].xaxis.set_major_formatter(plt.NullFormatter()) #else: ax[i].set_xlabel(xlabel, fontsize=18) if i in (1, 3): ax[i].yaxis.set_major_formatter(plt.NullFormatter()) else: ax[i].set_ylabel(ylabel, fontsize=18) #ax[3].text(0.05, 0.95, titles[3], # ha='left', va='top', transform=ax[3].transAxes) #ax[3].set_ylabel(r'$\varpi10^{0.2*m_G}$', fontsize=18) #ax[3].set_xlim(-2, 3) #ax[3].set_ylim(3, -1) #ax[3].yaxis.tick_right() #ax[3].yaxis.set_label_position("right") #plt.tight_layout() """ if norm is not None: figData.subplots_adjust(left=0.2, right=0.95) cbar_ax = figData.add_axes([0.01, 0.125, 0.02, 0.75]) cb = figData.colorbar(im, cax=cbar_ax) #cb = plt.colorbar(im, ax=axes[2]) cb.set_label(r'$ln \, \tilde{\sigma}_{\varpi}^2 - ln \, \sigma_{\varpi}^2$', fontsize=20) cb.set_clim(-7, 2) """ figData.savefig('plot_sample.data.pdf', format='pdf') figPrior.savefig('plot_sample.prior.pdf', format='pdf')