Exemplo n.º 1
0
def genmod_bivvcspread(cmddir, age, mass, vvcmu1, vvcsig1, vvcmu2, vvcsig2, vvclim):

    vvcs = np.arange(0.0, vvclim, 0.1)
    vvcweights = gen_bigaussweights(vvcs, vvcmu1, vvcsig1, vvcmu2, vvcsig2)

    photbase = cmddir.split('/')[1]
    bf, av, agebin, logz, dmod = fio.parse_fname(photbase, mode="str")

    hess_arr = []
    for vvc in vvcs:

        a_cmd = cmd.CMD(fio.get_cmdf(cmddir, bf, age, logz, vvc, av, dmod))
        mock_hess = a_cmd.cmd['Nsim']
        mock_hess /= np.sum(mock_hess)
        #if age == ages[0]:
        #    composite_hess = mock_hess
        #else:
    #    composite_hess += mock_hess
        hess_arr.append(mock_hess)

    hess_arr = np.array(hess_arr)

    #print(len(hess_arr))
    #print(len(vvcweights))
    composite_hess = np.sum(vvcweights*hess_arr.T, axis=1)
    #print(len(composite_hess))
    truths = {}
    for i, vvc in enumerate(vvcs):
        truths[vvc] = mass*vvcweights[i]

    return mass*composite_hess, truths
Exemplo n.º 2
0
def genmod_agespread(cmddir, mass, agemu, agesig):

    ages = np.arange(8.50, 9.50, 0.02)
    ageweights = gen_gaussweights(ages, agemu, agesig)

    photbase = cmddir.split('/')[1]
    bf, av, agebin, logz, dmod = fio.parse_fname(photbase, mode="str")

    hess_arr = []
    for age in ages:
 
        a_cmd = cmd.CMD(fio.get_cmdf(cmddir, bf, age, logz, 0.0, av, dmod))        
        mock_hess = a_cmd.cmd['Nsim']
        mock_hess /= np.sum(mock_hess)
        #if age == ages[0]:
        #    composite_hess = mock_hess
        #else:
        #    composite_hess += mock_hess
        hess_arr.append(mock_hess)

    hess_arr = np.array(hess_arr)

    #print(len(hess_arr))
    #print(len(ageweights))
    composite_hess = np.sum(ageweights*hess_arr.T, axis=1)
    #print(len(composite_hess))    

    truth = np.sum(composite_hess)

    return mass*composite_hess
Exemplo n.º 3
0
def genmod_agebivvcspread(cmddir, mass, agemu, agesig, vvcmu1, vvcsig1, vvcmu2, vvcsig2, vvclim):

    ages = np.arange(8.50, 9.50, 0.02)
    #mu, sig = 9.00, 0.3
    ageweights = gen_gaussweights(ages, agemu, agesig)

    vvcs = np.arange(0.0, vvclim, 0.1)
    #mu, sig = 0.3, 0.2
    vvcweights = gen_bigaussweights(vvcs, vvcmu1, vvcsig1, vvcmu2, vvcsig2)

    photbase = cmddir.split('/')[1]
    bf, av, agebin, logz, dmod = fio.parse_fname(photbase, mode="str")

    composite_hess = cmd.CMD(fio.get_cmdf(cmddir, bf, 9.00, logz, 0.0, av, dmod))
    composite_hess = np.zeros(len(composite_hess.cmd['Nsim']))

    vvc_pts = []
    for i, a_vvc in enumerate(vvcs):
        # step through in age, adding an age vector at each point in v/vc space
        age_vector = []
        for j, an_age in enumerate(ages):

            a_cmd = cmd.CMD(fio.get_cmdf(cmddir, bf, an_age, logz, a_vvc, av, dmod))
            model_hess = a_cmd.cmd['Nsim']
            model_hess /= np.sum(model_hess)

            age_vector.append(model_hess)

        vvc_pts.append(np.array(age_vector))

    model = np.array(vvc_pts)

    composite_hess += np.sum((vvcweights[:, np.newaxis])*np.sum(ageweights[:,np.newaxis]*model, axis=1), axis=0)

    #print(len(hess_arr))
    #print(len(vvcweights))
    #composite_hess = np.sum(vvcweights*hess_arr.T, axis=1)
    #print(len(composite_hess))
    truths = {}
    for i, vvc in enumerate(vvcs):
        truths[vvc] = mass*vvcweights[i]

    return mass*composite_hess, truths
Exemplo n.º 4
0
    # try getting errors:
    try:
        verr = np.genfromtxt(os.path.join(os.getcwd(), phot_dir,
                                          photfn.replace('.phot', '.err')),
                             usecols=(0, ))
        berr = np.genfromtxt(os.path.join(os.getcwd(), phot_dir,
                                          photfn.replace('.phot', '.err')),
                             usecols=(1, ))
        bverr = np.genfromtxt(os.path.join(os.getcwd(), phot_dir,
                                           photfn.replace('.phot', '.err')),
                              usecols=(2, ))
    except IOError:
        pass

    bf, av, agebin, logZ, dmod = parse_fname(photfn)

    # mag cap is not dynamic -- can be troublesome.
    vmi = v - i
    #mag_cap = 8.0
    #vmax = mag_cap
    #imax = mag_cap
    #    vmax = np.amax(v) + 1.5
    #    imax = np.amax(i) + 1.5

    vmin = np.amin(v) - 1.5
    imin = np.amin(i) - 1.5
    vmi_max = np.amax(vmi) + 0.5
    vmi_min = np.amin(vmi) - 0.5

    # dav needs to be dynamic if not fixed. Can't be zero!
Exemplo n.º 5
0
# svdir (directory where plots are saved to), mode (either specifying mock or a run on observations).

# cmddir has format output/photbasename/mcmc/

if __name__ == "__main__":

    #=================================================================================================================================
    # Initialization
    print("Running with {:s} CPUs...".format(sys.argv[2]))
    print("Getting files...")

    # cuts te given directory containing the .cmd files to get the photometry file base (system dep, kinda bad rule for this).
    photbase = sys.argv[1].split('/')[1]

    # The binary fraction, etc. are taken from the photometry filename:
    bf, av, agebin, logz, dmod = fio.parse_fname(photbase, mode="str")
    av = format(float(av), '.2f')

    # move down a grid point if given age is off age grid (not even)
    agebinf = np.array(list(map(float, agebin)))
    if not (agebinf[0] * 100) % 2 == 0:
        agebinf = agebinf - 0.01
        agebin = list(map(str, agebinf))

    print(bf, av, agebin, logz, dmod)
    print(type(bf), type(av), type(agebin[0]), type(agebin[1]), type(logz),
          type(dmod))

    # where the .cmd files are located:
    cmddir = sys.argv[1]