Exemple #1
0
def load5v6simdata(worklist):

    clusters = [x[0] for x in worklist]
    redshifts = cm.readClusterRedshifts()
    properredshifts = np.array([redshifts[x] for x in clusters])

    subdirs = ['contam0p10/%s' % x for x in ['BVRIZ', 'APER']]

    fracbiases = ss.processFracBiasData(
        '/u/ki/dapple/nfs12/cosmos/simulations/publication/highsn/cluster3',
        subdirs, clusters, redshifts)

    data = [fracbiases[0], fracbiases[1], properredshifts]

    return data
Exemple #2
0
def galdensity(data = None):

    if data is None:
        data = {}

    
    if 'ngals' not in data:

        

        ngals = cPickle.load(open('galaxy_counts_pzmethod.pkl', 'rb'))
        data['ngals'] = ngals
        


        items = [tuple(x) for x in readtxtfile('worklist')]
        clusters = [x[0] for x in items]

        redshifts = cm.readClusterRedshifts()
        properz = np.array([redshifts[x] for x in clusters])
        data['properz'] = properz

        Dl = np.array([nfwutils.angulardist(z) for z in properz])
        data['Dl'] = Dl

        inner_rad = np.arctan2(0.75, Dl) * (180./np.pi) * 60
        outer_rad = np.arctan2(3., Dl) * (180 / np.pi) * 60
        area = np.pi*(outer_rad**2 - inner_rad**2)
        data['area'] = area

        propercounts = np.array([ngals[x] for x in items])
        
        density = propercounts / area
        data['density'] = density

    else:

        properz = data['properz']
        density = data['density']
    

    fig = pylab.figure()
    ax = fig.add_axes([0.12, 0.12, 0.95 - 0.12, 0.95 - 0.12])
    ax.plot(properz, density, 'bo')
    ax.set_xlabel('Cluster Redshift')
    ax.set_ylabel('Input Galaxy Density')

    return fig, data
Exemple #3
0
def ML5filterContamCompareScript(data=None):

    if data is None:
        data = {}

    if 'worklist' not in data:
        data['worklist'] = readtxtfile('simclusterlist')
        data['clusters'] = [x[0] for x in data['worklist']]

    worklist = data['worklist']
    clusters = data['clusters']

    if 'redshifts' not in data:
        data['redshifts'] = cm.readClusterRedshifts()
        redshifts = data['redshifts']
        data['properredshifts'] = np.array([redshifts[x] for x in clusters])

    redshifts = data['redshifts']
    properredshifts = data['properredshifts']

    if 'fracbiases' not in data:
        subdirs = ['%sBVRIZ' % x for x in ['', 'contam0p10/', 'contam0p20/']]

        data['fracbiases'] = ss.processFracBiasData(
            '/u/ki/dapple/nfs12/cosmos/simulations/clusters_2012-05-17-highdensity',
            subdirs, clusters, redshifts)
    fracbiases = data['fracbiases']

    fig = publicationContamComparePlot(fracbiases[0], fracbiases[1],
                                       fracbiases[2], properredshifts)

    ax = fig.axes[0]
    ax.text(0.2, 0.06, r'$B_{\mathrm J}V_{\mathrm J}r^+i^+z^+$', fontsize=16)

    fig.savefig('publication/clustersims_bvriz_contam_compare.eps')

    return fig, data
Exemple #4
0
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
Exemple #5
0
def PointEstPzScript(data=None):

    if data is None:

        worklist = readtxtfile('simclusterlist')
        clusters = [x[0] for x in worklist]
        redshifts = cm.readClusterRedshifts()
        properredshifts = np.array([redshifts[x] for x in clusters])

        subdirs = ['contam0p10/BVRIZ']

        MLfracbias = ss.processFracBiasData(
            '/u/ki/dapple/nfs12/cosmos/simulations/clusters_2012-05-17-highdensity',
            subdirs, clusters, redshifts)[0]

        Bpointmass, Bpointgrid, scale_radii = ss.readPointMasses(
            '/u/ki/dapple/nfs12/cosmos/simulations/clusters_2012-05-17',
            'contam0p10/newman/BVRIZ', clusters)

        truemasses = [
            nfwutils.massInsideR(scale_radii[x], 4., redshifts[x], 1.5)
            for x in clusters
        ]

        Bpointfracbias = ss.calcFracBias(Bpointgrid, truemasses)

        data = [MLfracbias, Bpointfracbias, properredshifts]

    else:

        MLfracbias = data[0]
        Bpointfracbias = data[1]
        properredshifts = data[2]

    fig = pylab.figure()

    try:

        ax = fig.add_axes([0.15, 0.12, 0.96 - 0.15, 0.95 - 0.12])

        ax.axhline(0.0, c='k', linewidth=1.25)

        Apointmean, Apointerr = ss.bootstrapMean(MLfracbias)
        Bpointmean, Bpointerr = ss.bootstrapMean(Bpointfracbias)

        ax.errorbar(properredshifts - 0.0025,
                    Bpointmean,
                    Bpointerr,
                    fmt='cs',
                    label=r'Point Estimators',
                    color='#BFBFD4')
        ax.errorbar(properredshifts + 0.0025,
                    Apointmean,
                    Apointerr,
                    fmt='ro',
                    label=r'P(z) Method')

        ax.set_xlim(0.16, 0.72)
        ax.set_ylim(-0.08, 0.19)

        ax.set_xlabel('Cluster Redshift')
        ax.set_ylabel(r'Fractional Mass Bias within 1.5 Mpc')

        #        ax.text(0.2, 0.12, r'$BVr^{+}i^{+}z^{+}$ Photo-$z$ Point Est', fontsize=16)

        ax.legend(loc='upper left', numpoints=1, ncol=1)

        fig.savefig('publication/clustersims_pointest_pz_compare.eps')

    finally:

        return fig, data
Exemple #6
0
def MLPointEstScript(data=None):

    if data is None:

        worklist = readtxtfile('simclusterlist')
        clusters = [x[0] for x in worklist]
        redshifts = cm.readClusterRedshifts()
        properredshifts = np.array([redshifts[x] for x in clusters])

        subdirs = ['contam0p10/BVRIZ']

        #        MLfracbias = ss.processFracBiasData('/u/ki/dapple/nfs12/cosmos/simulations/publication/highsn/cluster3',
        #                                            subdirs, clusters, redshifts)[0]
        #
        #
        #        Apointmass, Apointgrid, scale_radii = ss.readPointMasses('/u/ki/dapple/nfs12/cosmos/simulations/publication/highsn/cluster3', 'contam0p10/newman/APER', clusters)
        Bpointmass, Bpointgrid, scale_radii = ss.readPointMasses(
            '/u/ki/dapple/nfs12/cosmos/simulations/clusters_2012-05-17',
            'contam0p10/newman/BVRIZ', clusters)

        truemasses = [
            nfwutils.massInsideR(scale_radii[x], 4., redshifts[x], 1.5)
            for x in clusters
        ]

        #        Apointfracbias = ss.calcFracBias(Apointgrid, truemasses)
        Bpointfracbias = ss.calcFracBias(Bpointgrid, truemasses)

        data = [None, Bpointfracbias, properredshifts]

    else:

        #        Apointfracbias = data[0]
        Bpointfracbias = data[1]
        properredshifts = data[2]

    fig = pylab.figure()

    try:

        ax = fig.add_axes([0.15, 0.12, 0.95 - 0.15, 0.95 - 0.12])

        ax.axhline(0.0, c='k', linewidth=1.25)

        #        Apointmean, Apointerr = ss.bootstrapMean(Apointfracbias)
        Bpointmean, Bpointerr = ss.bootstrapMean(Bpointfracbias)

        ax.errorbar(properredshifts,
                    Bpointmean,
                    Bpointerr,
                    fmt='bo',
                    label=r'$BVr^+i^+z^+$')
        #        ax.errorbar(properredshifts+0.0025, Apointmean, Apointerr, fmt='rs', label=r'$uBVr^+i^+z^+$')

        ax.text(0.166, 0.135, r'$BVr^+i^+z^+$ Photo-Z Point Est', fontsize=16)

        ax.set_xlim(0.16, 0.72)
        ax.set_ylim(-0.05, 0.15)

        ax.set_xlabel('Cluster Redshift', fontsize=16)
        ax.set_ylabel(r'Fractional Mass Bias within 1.5 Mpc')

        #        ax.legend(loc='lower right', numpoints = 1, ncol=2)

        fig.savefig('publication/clustersims_pointest_compare.eps')

    finally:

        return fig, data
Exemple #7
0
def MLUbandRatioScript(data=None):

    simlist = readtxtfile('simclusterlist')
    noUlist = readtxtfile('noUlist')

    worklist = [x for x in simlist if x in noUlist]
    del worklist[-1]
    clusters = [x[0] for x in worklist]

    if data is None:

        redshifts = cm.readClusterRedshifts()
        properredshifts = np.array([redshifts[x] for x in clusters])

        noUsim_masses, noUsim_errs, noUsim_grid, scale_radii = ss.readMLMasses(
            '/u/ki/dapple/nfs12/cosmos/simulations/publication/highsn/cluster3',
            'contam0p10/BVRIZ', clusters)

        Usim_masses, Usim_errs, Usim_grid, scale_radii = ss.readMLMasses(
            '/u/ki/dapple/nfs12/cosmos/simulations/publication/highsn/cluster3',
            'contam0p10/APER', clusters)

        noUmasses, noUmask = cm.readMLBootstraps(
            '/u/ki/dapple/ki06/bootstrap_2011-12-14', worklist, np.arange(100))
        Umasses, Umask = cm.readMLBootstraps(
            '/u/ki/dapple/ki06/bootstrap_U_2012-02-03', worklist,
            np.arange(100))

        data = [
            noUsim_grid, Usim_grid, properredshifts, noUmasses, noUmask,
            Umasses, Umask
        ]

    else:

        noUsim_grid = data[0]
        Usim_grid = data[1]
        properredshifts = data[2]
        noUmasses = data[3]
        noUmask = data[4]
        Umasses = data[5]
        Umask = data[6]

    simRatio = noUsim_grid / Usim_grid
    simMean, simErr = ss.bootstrapMean(simRatio.T)

    dataRatios = cm.makeRatios(Umasses, Umask, noUmasses, noUmask)
    dataMeans, dataErrs = cm.bootstrapMeans(dataRatios, clusters)

    fig = pylab.figure()
    ax = fig.add_axes([0.14, 0.12, 0.95 - 0.14, 0.95 - 0.12])

    ax.errorbar(properredshifts + 0.0025,
                dataMeans,
                dataErrs,
                fmt='rs',
                label='Data')
    ax.errorbar(properredshifts - 0.0025,
                simMean,
                simErr,
                fmt='bo',
                label='Simulations')

    ax.axhline(1.0, c='k', linewidth=1.5)

    ax.set_xlim(0.16, 0.72)
    ax.set_ylim(0.85, 1.35)

    ax.set_xlabel('Cluster Redshift')
    ax.set_ylabel('Mass without U-band / Mass with U-band')

    ax.legend(loc='upper left', numpoints=1)

    fig.savefig('publication/dropU_comp.eps')

    return fig, data
Exemple #8
0
def calcMasses(clusters, scale_radii, concentration=4.0, mradius=1.5):

    redshifts = cm.readClusterRedshifts()
    redshifts = [redshifts[x] for x in clusters]

    return masses
Exemple #9
0
def precisionZ(data = None):
    #mass precision as a function of redshift

    if data is None:
        data = {}

    if 'fracerrs' not in data:

        items = [tuple(x) for x in readtxtfile('worklist')]


        allmasses = cm.readDougMasses('/u/ki/dapple/subaru/doug/publication/baseline_2012-05-17')

        redshifts = cm.readClusterRedshifts()

        clusters = [x[0] for x in items]

        properz = np.array([redshifts[x] for x in clusters])

        masses, errs = cm.constructMassArray(allmasses, items)


        fracerrs = errs / masses

        aveerrs = np.mean(fracerrs, axis=0)

        data['aveerrs'] = aveerrs
        data['properz'] = properz

        ccitems = [tuple(x) for x in readtxtfile('referenceset')]
        
        ccmasses = cm.readAnjaMasses()
        clusters = [x[0] for x in ccitems]
        ccproperz = np.array([redshifts[x] for x in clusters])
        data['ccproperz'] = ccproperz
        
        masses, errs = cm.constructMassArray(ccmasses, ccitems)
        
        fracerrs = errs/masses
        
        ccaveerrs = np.mean(fracerrs, axis=0)

        data['ccaveerrs'] = ccaveerrs
                   

    else:

        aveerrs = data['aveaerrs']
        properz = data['properz']
        
        ccaveerrs = data['ccaveerrs']
        ccproperz = data['ccproperz']

    
    fig = pylab.figure()
    ax = fig.add_axes([0.12, 0.12, 0.95-0.12, 0.95-0.12])
    ax.plot(ccproperz, ccaveerrs, 'bo', label = 'Color-Cut', mfc = 'None', mew = 1.0, mec='b')
    ax.plot(properz, aveerrs, 'rD', label = 'P($z$)')
    ax.set_xlabel('Cluster Redshift')
    ax.set_ylabel('Fractional Statistical Uncertainty M(r$<$1.5Mpc)')
    ax.set_xlim([0.14, 0.72])
    ax.legend(loc='upper left', numpoints = 1)

    fig.savefig('publication/aveerr_redshift.eps')
    

    return fig, data
Exemple #10
0
def lostgals(data = None):

    if data is None:

        data = {}

    items = readtxtfile('worklist')
    del items[-1]
    clusters = [x[0] for x in items]


    if 'properz' not in data:




        redshifts = cm.readClusterRedshifts()
        properz = np.array([redshifts[x] for x in clusters])
        data['properz'] = properz
    else:
        properz = data['properz']

    if 'properbase' not in data:

        basecuts = {}
        for cluster, filter, image in items:

            controller = driver.makeController()

            options, args = controller.modelbuilder.createOptions()
            options, args = controller.filehandler.createOptions(options = options, args = args,
                                                     workdir = '/u/ki/dapple/ki06/catalog_backup_2012-02-08',
                                                     incatalog = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.lensingbase.cat' % (cluster, filter, image),
                                                     cluster = cluster, filter = filter, image = image,
                                                     redseqcat = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.redsequence.cat' % (cluster, filter, image), shapecut = True)

            controller.load(options, args)

            basecuts[cluster] = controller.ngalaxies
        data['basecuts'] = basecuts
        properbase = np.array([basecuts[x[0]] for x in items])
        data['properbase'] = properbase

    else:

        properbase = data['properbase']

    if 'properloose' not in data:

        loosecuts = {}
        for cluster, filter, image in items:

            controller = driver.makeController()

            options, args = controller.modelbuilder.createOptions(deltaz95high = 9999, zbhigh = 9999)
            options, args = controller.filehandler.createOptions(options = options, args = args,
                                                     workdir = '/u/ki/dapple/ki06/catalog_backup_2012-02-08',
                                                     incatalog = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.lensingbase.cat' % (cluster, filter, image),
                                                     cluster = cluster, filter = filter, image = image,
                                                     redseqcat = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.redsequence.cat' % (cluster, filter, image), shapecut = True)

            controller.load(options, args)

            loosecuts[cluster] = controller.ngalaxies
        data['loosecuts'] = loosecuts
        properloose = np.array([loosecuts[x[0]] for x in items])
        data['properloose'] = properloose

    else:
        
        properloose = data['properloose']

    if 'ratio' not in data:

        ratio = 1 - (properbase.astype('float64') / properloose)
        data['ratio'] = ratio

    else:

        ratio = data['ratio']

    fig = pylab.figure()
    ax = fig.add_axes([0.12, 0.12, 0.95 - 0.12, 0.95 - 0.12])
    ax.plot(properz, ratio, 'bo')
    ax.set_xlim([0.16, 0.72])

    ax.set_xlabel('Cluster Redshift')
    ax.set_ylabel('Fraction of Catalog Discarded')

    return fig, data
Exemple #11
0
import sys
import numpy as np
import compare_masses as cm, intrinsicscatter as isc
import scatter_sims as ss, nfwutils
from dappleutils import readtxtfile

workdir = sys.argv[1]
subdir = sys.argv[2]
outfile = sys.argv[3]
nsamples = int(sys.argv[4])

items = readtxtfile('simclusterlist')
clusters = clusters = [ x[0] for x in items]

redshifts = cm.readClusterRedshifts()
properredshifts = np.array([redshifts[x] for x in clusters])


masses, errs, massgrid, scale_radii = ss.readMLMasses(workdir, subdir, clusters)
truemasses = {}
for cluster in clusters:
    truemasses[cluster] = nfwutils.massInsideR(scale_radii[cluster], 4., redshifts[cluster], 1.5)

x = np.hstack([len(masses[c])*[truemasses[c]] for c in clusters])
y = np.hstack([masses[c] for c in clusters])
yerr = np.hstack([errs[c] for c in clusters])



calibmodel = isc.IntrinsicScatter(x, y, yerr)
Exemple #12
0
def table(items, mlsrcdir, output, strInterval=normalStrInterval):

    MLmasses = cm.readDougMasses(dir=mlsrcdir)
    CCmasses = cm.readAnjaMasses()

    nametranslation = readNameTranslation()

    filtertranslation = readFilterTranslation()

    redshifts = cm.readClusterRedshifts()

    cordist = np.hstack([pymc.database.pickle.load('ml_cc_rlog.out.%d' % i).trace('m', -1)[25000:] \
                             for i in range(1, 6)])

    sortlist = sorted([(redshifts[x[0]], x) for x in items])
    print sortlist

    for clusterz, (cluster, filter, image) in sortlist:

        if (cluster, filter, image) not in CCmasses:
            print 'Skipping %s %s %s' % (cluster, filter, image)
            continue

        try:
            MLcluster = MLCluster.load(cluster, filter, image, clusterz)

            values = {
                'cluster':
                nametranslation[cluster],
                'redshift':
                clusterz,
                'filter':
                filtertranslation[filter],
                'rs':
                strInterval(MLcluster.getRs()),
                'con':
                strInterval(MLcluster.getConcentration()),
                'mlmass':
                strInterval(MLmasses[cluster, filter, image],
                            fmt='%2.1f',
                            norm=1e14),
                'ccrs':
                strInterval(
                    getRs(clusterz, *CCmasses[(cluster, filter, image)])),
                'ccmass':
                strInterval(CCmasses[(cluster, filter, image)],
                            fmt='%2.1f',
                            norm=1e14)
            }

#                      'cccor' : strInterval(CCcluster.getCorMass(cordist), fmt='%2.1f', norm = 1e14)}

#                      'mlmass' : strInterval(MLcluster.getMass(), fmt = '%2.1f', norm = 1e14),
#                      'ccmass' : strInterval(CCcluster.getMass(), fmt = '%2.1f', norm = 1e14),

        except (KeyError, IOError):

            values = {
                'cluster':
                nametranslation[cluster],
                'redshift':
                clusterz,
                'filter':
                filtertranslation[filter],
                'rs':
                '-',
                'con':
                '-',
                'mlmass':
                '-',
                'ccrs':
                strInterval(
                    getRs(clusterz, *CCmasses[(cluster, filter, image)])),
                'ccmass':
                strInterval(CCmasses[(cluster, filter, image)],
                            fmt='%2.1f',
                            norm=1e14)
            }

#                                  'cccor' : strInterval(CCcluster.getCorMass(cordist), fmt='%2.1f', norm = 1e14)}
#        output.write('%(cluster)s & %(redshift)1.2f & %(rs)s & %(con)s & %(mlmass)s  & %(ccrs)s & %(ccmass)s & %(cccor)s \\\\ \n' % values)
        output.write(
            '%(cluster)s & %(redshift)1.3f &  %(rs)s & %(mlmass)s & %(ccrs)s & %(ccmass)s \\\\ \n'
            % values)