def plotdist_1d_hist(x, probs, mode=None, ranges=None): if mode is None or ranges is None: mode, ranges = isg.getdist_1d_hist(x, probs, [0.68, 0.95]) fig = pylab.figure() ax = fig.add_axes([0.12, 0.12, 0.95 - 0.12, 0.95 - 0.12]) ax.plot(x, probs, 'b-') print '!!!!!!!!!' print ranges ax.axvline(mode, c='r', linewidth=1.5) s68, s95 = ranges if isinstance(s68[0], float): s68 = [s68] if isinstance(s95[0], float): s95 = [s95] for range in s68: ax.axvline(range[0], c='m', linewidth=1.2, linestyle='--') ax.axvline(range[1], c='m', linewidth=1.2, linestyle='--') for range in s95: ax.axvline(range[0], c='c', linewidth=1.2, linestyle=':') ax.axvline(range[1], c='c', linewidth=1.2, linestyle=':') return fig
def fitAltOffsetScript(data=None): if data is None: data = {} worklist = readtxtfile('worklist') clusters = [x[0] for x in worklist] workdir = '/u/ki/dapple/nfs12/cosmos/simulations/clusters_2012-05-17-highdensity/' subdirs = ['%sBVRIZ' % x for x in ['', 'contam0p10/', 'contam0p20/']] concentration = 4. mradius = 1.5 redshifts = cm.readClusterRedshifts() figs = [] for subdir in subdirs: if subdir not in data: data[subdir] = {} curdata = data[subdir] if 'masses' not in curdata: curdata['masses'], errs, massgrid, curdata[ 'scale_radii'] = ss.readMLMasses(workdir, subdir, clusters) masses = curdata['masses'] scale_radii = curdata['scale_radii'] if 'grid' not in curdata: refmasses = {} for cluster in clusters: refmasses[cluster] = nfwutils.massInsideR( scale_radii[cluster], concentration, redshifts[cluster], mradius) * np.ones_like(masses[cluster]) curdata['grid'], curdata['means'], curdata[ 'scatters'] = isg.intrinsicScatter( refmasses, masses, means=1. + np.arange(-0.08, 0.08, 0.0001), scatters=np.arange(0.005, 0.05, 0.0025)) means = curdata['means'] scatters = curdata['scatters'] mode, (r68, r95) = isg.getdist_1d_hist(means[0], means[1], levels=[0.68, 0.95]) curdata['meandist'] = (mode, r68, r95) mode, (r68, r95) = isg.getdist_1d_hist(scatters[0], scatters[1], levels=[0.68, 0.95]) curdata['scatterdist'] = (mode, r68, r95) for varname in 'mean scatter'.split(): mode, r68, r95 = curdata['%sdist' % varname] print mode, r68, r95 print '%s\t%2.4f\t+%2.4f\t-%2.4f\t+%2.4f\t-%2.4f' % ( varname, mode, r68[0][1] - mode, mode - r68[0][0], r95[0][1] - mode, mode - r95[0][0]) x, prob = curdata['%ss' % varname] fig = isgp.plotdist_1d_hist(x, prob, mode, [r68[0], r95[0]]) ax = fig.axes[0] ax.set_title('%s %s' % (subdir, varname)) figs.append(fig) fig.show() return figs, data
def measureMLCcBootIS(sample='worklist', data=None, diffR=None): if data is None: data = {} if 'items' not in data: items = readtxtfile(sample) clusters = [x[0] for x in items] redshifts = readClusterRedshifts() properredshifts = np.array([redshifts[x] for x in clusters]) data['items'] = items data['clusters'] = clusters data['redshifts'] = redshifts data['properredshifts'] = properredshifts else: items = data['items'] clusters = data['clusters'] redshifts = data['redshifts'] properredshifts = data['properredshifts'] if 'MLmasses' not in data or 'CCmasses' not in data: if diffR is None: if 'MLmasses' not in data: MLmasses, MLmask = readMLBootstraps( '/u/ki/dapple/ki06/bootstrap_2012-05-17', items, np.arange(0, 200)) data['MLmasses'] = MLmasses data['MLmask'] = MLmask else: MLmasses, MLmask = data['MLmasses'], data['MLmask'] if 'CCmasses' not in data: CCmasses, CCmask = readCCSummary( '/u/ki/dapple/ki06/bootstrap_2012-05-17', clusters, np.arange(0, 200)) data['CCmasses'] = CCmasses data['CCmask'] = CCmask else: CCmasses, CCmask = data['CCmasses'], data['CCmask'] else: print 'Using Alternative diffR' if 'MLmasses' not in data: MLmasses, MLmask = readMLBootstraps_diffR( '/u/ki/dapple/ki06/bootstrap_2012-05-17', items, np.arange(0, 200), diffR, redshifts) data['MLmasses'] = MLmasses data['MLmask'] = MLmask else: MLmasses, MLmask = data['MLmasses'], data['MLmask'] if 'CCmasses' not in data: CCmasses, CCmask = readCCSummary_diffR( '/u/ki/dapple/ki06/bootstrap_2012-05-17', clusters, np.arange(0, 200), diffR, redshifts) data['CCmasses'] = CCmasses data['CCmask'] = CCmask else: CCmasses, CCmask = data['CCmasses'], data['CCmask'] MLreduced = {} CCreduced = {} for key in MLmasses.keys(): totalmask = np.logical_and(MLmask[key], CCmask[key]) MLreduced[key] = MLmasses[key][totalmask] CCreduced[key] = CCmasses[key][totalmask] data['MLreduced'] = MLreduced data['CCreduced'] = CCreduced else: MLreduced, CCreduced = data['MLreduced'], data['CCreduced'] grid, means, scatters = isg.intrinsicScatter( MLreduced, CCreduced, means=np.arange(0.5, 1.5, 0.002), scatters=np.arange(0.02, 0.2, 0.005)) data['grid'] = grid data['means'] = means data['scatters'] = scatters figs = [] print print print '-----' print 'var\tmode\t68%% +\t-\t95%% +\t-' print '-----' if 'meandist' not in data: means = data['means'] scatters = data['scatters'] mode, (r68, r95) = isg.getdist_1d_hist(means[0], means[1], levels=[0.68, 0.95]) data['meandist'] = (mode, r68, r95) mode, (r68, r95) = isg.getdist_1d_hist(scatters[0], scatters[1], levels=[0.68, 0.95]) data['scatterdist'] = (mode, r68, r95) for varname in 'mean scatter'.split(): mode, r68, r95 = data['%sdist' % varname] print mode, r68, r95 print '%s\t%2.4f\t+%2.4f\t-%2.4f\t+%2.4f\t-%2.4f' % ( varname, mode, r68[0][1] - mode, mode - r68[0][0], r95[0][1] - mode, mode - r95[0][0]) x, prob = data['%ss' % varname] fig = isgp.plotdist_1d_hist(x, prob, mode, [r68[0], r95[0]]) ax = fig.axes[0] ax.set_title(varname) figs.append(fig) fig.show() return figs, data
def profileScript(items, curdata = None): clusters = [x[0] for x in items] if curdata is None: curdata = {} if 'norm' not in curdata and 'cut' not in curdata: normMass, normMask = cm.readCCSummary('/u/ki/dapple/ki06/bootstrap_5mpc_2012-02-14/', clusters,np.arange(50), '_rm1.5_ri0.75_ro3.0.out') cutMass, cutMask = cm.readCCSummary('/u/ki/dapple/ki06/bootstrap_5mpc_2012-02-14/', clusters, np.arange(50), '_bmo2_t2p0_rm1.5_ri0.75_ro3.0.out') reducedNorm = {} reducedCut = {} for cluster in normMass.keys(): totalmask = np.logical_and(normMask[cluster], cutMask[cluster]) reducedNorm[cluster] = normMass[cluster][totalmask] reducedCut[cluster] = cutMass[cluster][totalmask] curdata['norm'] = reducedNorm curdata['cut'] = reducedCut if 'grid' not in curdata: grid, means, scatters = isg.intrinsicScatter(curdata['norm'], curdata['cut'], scatters=np.arange(0.005, 0.05, 0.01)) curdata['grid'] = grid curdata['means'] = means curdata['scatters'] = scatters print print print '-----' print 'var\tmode\t68%% +\t-\t95%% +\t-' print '-----' if 'meandist' not in curdata or 'scatterdist' not in curdata: means = curdata['means'] scatters = curdata['scatters'] mode, (r68, r95) = isg.getdist_1d_hist(means[0], means[1], levels = [0.68, 0.95]) curdata['meandist'] = (mode, r68, r95) mode, (r68, r95) = isg.getdist_1d_hist(scatters[0], scatters[1], levels = [0.68, 0.95]) curdata['scatterdist'] = (mode, r68, r95) figs = [] for varname in 'mean scatter'.split(): mode, r68, r95 = curdata['%sdist' % varname] print mode, r68, r95 print '%s\t%2.4f\t+%2.4f\t-%2.4f\t+%2.4f\t-%2.4f' % (varname, mode, r68[0][1] - mode, mode - r68[0][0], r95[0][1] - mode, mode - r95[0][0]) x, prob = curdata['%ss' % varname] fig = isgp.plotdist_1d_hist(x, prob, mode, [r68[0], r95[0]]) ax = fig.axes[0] ax.set_title(varname) figs.append(fig) fig.show() return figs, data
def radialScript(items, curdata = None): clusters = [x[0] for x in items] if curdata is None: curdata = {} if 'ir' not in curdata: curdata['ir'] = cm.readCCSummary('/u/ki/dapple/ki06/bootstrap_5mpc_2012-02-14/', clusters,np.arange(50), '_rm1.5_ri0.75_ro3.0.out') if 'or' not in curdata: curdata['or'] = cm.readCCSummary('/u/ki/dapple/ki06/bootstrap_5mpc_2012-02-14/', clusters,np.arange(50), '_rm1.5_ri0.75_ro5.0.out') if 'reducedIR' not in curdata or 'reducedOR' not in curdata: irMass, irMask = curdata['ir'] orMass, orMask = curdata['or'] reducedIR = {} reducedOR = {} for cluster in clusters: totalmask = np.logical_and(irMask[cluster], orMask[cluster]) reducedIR[cluster] = irMass[cluster][totalmask] reducedOR[cluster] = orMass[cluster][totalmask] reducedIR[cluster][reducedIR[cluster] == 0.] = 1e13 reducedOR[cluster][reducedOR[cluster] == 0.] = 1e13 curdata['reducedIR'] = reducedIR curdata['reducedOR'] = reducedOR if 'grid' not in curdata: grid, means, scatters = isg.intrinsicScatter(curdata['reducedIR'], curdata['reducedOR']) curdata['grid'] = grid curdata['means'] = means curdata['scatters'] = scatters print print print '-----' print 'var\tmode\t68%% +\t-\t95%% +\t-' print '-----' if 'meandist' not in curdata: means = curdata['means'] scatters = curdata['scatters'] mode, (r68, r95) = isg.getdist_1d_hist(means[0], means[1], levels = [0.68, 0.95]) curdata['meandist'] = (mode, r68, r95) mode, (r68, r95) = isg.getdist_1d_hist(scatters[0], scatters[1], levels = [0.68, 0.95]) curdata['scatterdist'] = (mode, r68, r95) for varname in 'mean scatter'.split(): mode, r68, r95 = curdata['%sdist' % varname] print mode, r68, r95 print '%s\t%2.4f\t+%2.4f\t-%2.4f\t+%2.4f\t-%2.4f' % (varname, mode, r68[0][1] - mode, mode - r68[0][0], r95[0][1] - mode, mode - r95[0][0]) x, prob = curdata['%ss' % varname] fig = isgp.plotdist_1d_hist(x, prob, mode, [r68[0], r95[0]]) ax = fig.axes[0] ax.set_title(varname) figs.append(fig) fig.show() return figs, data
def magSplit_script(category, data = None): figs = [] if data is None: data = {} if 'items' not in data: data['items'] = readtxtfile('worklist') # try: loc1 = '%s/%s/low' % (trialsdir, category) loc2 = '%s/%s/high' % (trialsdir, category) if category not in data: masses = loadData(loc1, loc2, data['items']) data[category] = {} data[category]['masses'] = masses curdata = data[category] if 'grid' not in curdata: grid, means, scatters = isg.intrinsicScatter(curdata['masses'][0], curdata['masses'][1], means = np.arange(0.6, 1.4, 0.002), scatters = np.arange(0.02, 0.2, 0.01)) curdata['grid'] = grid curdata['means'] = means curdata['scatters'] = scatters else: grid = curdata['grid'] means = curdata['means'] scatters = curdata['scatters'] print print print category print '-----' print 'var\tmode\t68%% +\t-\t95%% +\t-' print '-----' if 'meandist' not in curdata: mode, (r68, r95) = isg.getdist_1d_hist(means[0], means[1], levels = [0.68, 0.95]) curdata['meandist'] = (mode, r68, r95) mode, (r68, r95) = isg.getdist_1d_hist(scatters[0], scatters[1], levels = [0.68, 0.95]) curdata['scatterdist'] = (mode, r68, r95) for varname in 'mean scatter'.split(): mode, r68, r95 = curdata['%sdist' % varname] print mode, r68, r95 print '%s\t%2.4f\t+%2.4f\t-%2.4f\t+%2.4f\t-%2.4f' % (varname, mode, r68[0][1] - mode, mode - r68[0][0], r95[0][1] - mode, mode - r95[0][0]) x, prob = curdata['%ss' % varname] fig = isgp.plotdist_1d_hist(x, prob, mode, [r68[0], r95[0]]) ax = fig.axes[0] ax.set_title(varname) figs.append(fig) fig.show() xlabel, ylabel = label_conv[category] fig, xmasses, ymasses = cm.publicationPlotMassMass(loc1, loc2, xlabel, ylabel) ax = fig.axes[0] mode, r68, r95 = curdata['meandist'] # ax.axhline(mode, c='r', ls='--', linewidth=1.5) ax.fill_between([0.16, 0.72], r95[0][0], r95[0][1], facecolor=(1, 0.642, 0.610), zorder=-1) ax.fill_between([0.16, 0.72], r68[0][0], r68[0][1], facecolor='#CC0000', zorder=-1) ax.set_xlim(0.16, 0.72) ax.set_ylim(0.1, 10) fig.show() fig.savefig(filename_conv[category]) figs.append(fig) # finally: return figs, data