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
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
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
def pgplot(obs, model, cmddir, bf, age, logz, av, dmod, vvclim, weights, filters, age_range, svname=None, log=False, svdir=None): """ Creates a MATCH pg style plot of data, model, data-model, and -2lnP map. """ composite_cmd = cmd.CMD(fio.get_cmdf(cmddir, bf, age, logz, 0.0, av, dmod))#, ymag='I') composite_cmd.cmd['Nsim'] = np.zeros(len(composite_cmd.cmd['Nsim'])) vvc_range = np.arange(0.0, vvclim, 0.1) Nrot = len(vvc_range) #age_range = np.arange(8.5, 9.5, 0.02) mu = weights[Nrot] try: sigma = weights[Nrot+1] except IndexError: sigma = 0.0 ageweights = gen_gaussweights(age_range, mu, sigma) #for i, avvc in enumerate(vvc_range): # for j, anage in enumerate(age_range): # a_cmd = cmd.CMD(fio.get_cmdf(cmddir, bf, anage, logz, avvc, av, dmod))#, ymag='I') # 1 * (jth age weight, added i times) * ith rotation rate. # a_cmd.cmd['Nsim'] = (a_cmd.cmd['Nsim'] / np.sum(a_cmd.cmd['Nsim'])) * (best_gweights[j]) * (10**weights[i]) # add each cmd (re-weighted by solutions) to the composite CMD model. # composite_cmd.cmd['Nsim'] += a_cmd.cmd['Nsim'] vvcweights = weights[:Nrot] composite_cmd.cmd['Nsim'] += np.sum((10**vvcweights[:, np.newaxis])*np.sum(ageweights[:,np.newaxis]*model, axis=1), axis=0) composite_cmd.cmd['Nobs'] = obs # arbitrary vvc used -- just need a file name to break up. #fn_base = (fio.get_cmdf(cmddir, bf, age, logz, 0.0, av, dmod).split('/')[-1]).split('.out.cmd')[0] #fehval = float((fn_base.split('logz')[-1]).split('_')[0]) #lageval = float((fn_base.split('_t')[-1]).split('_')[0]) #avval = float((fn_base.split('_av')[-1]).split('_')[0]) #dmodval = float((fn_base.split('_dmod')[-1]).split('_')[0]) print(max(composite_cmd.cmd['Nsim'])) filters, photstrs = match_to_mist(filters) photstr = photstrs[0] print(filters) redmag_name = filters[1] bluemag_name = filters[0] color_name = "{:s}-{:s}".format(bluemag_name, redmag_name) # iso00 = rmm.ISOCMD(round(float(logz), 2), min(vvc_range), ebv= round(float(av), 2)/3.1, photstr=photstr, exttag='TP') # iso00.set_isodata(round(float(mu), 2), color_name, bluemag_name, dmod=round(float(dmod), 2)) # this try except is fudgy -- onl needed cause v/vc = 0.6 models aren't available on my local machine. # try: # iso06 = rmm.ISOCMD(round(float(logz), 2), max(vvc_range), ebv= round(float(av), 2)/3.1, photstr=photstr, exttag='TP') # except Exception as e: # iso06 = rmm.ISOCMD(round(float(logz), 2), 0.6, ebv= round(float(av), 2)/3.1, photstr=photstr, exttag='TP') #iso06.set_isodata(round(float(mu), 2), color_name, bluemag_name, dmod=round(float(dmod), 2)) # (x, y), i.e., (color, red mag) points of each isochrone in a list: #mist_pts = [ # isoget_colmags(iso00, [color_name, bluemag_name], lage=round(float(mu), 2), dmod=round(float(dmod), 2)), # isoget_colmags(iso06, [color_name, bluemag_name], lage=round(float(mu), 2), dmod=round(float(dmod), 2)) # ] # recalculate the d-m and signifigance hesses using the new hesses. composite_cmd.recalc() # create a MATCH pg style plot using the .cmd file: pgcmd_kwargs = {} #pgcmd_kwargs['mist_pts'] = mist_pts if svname == None: if svdir == None: pgcmd_kwargs['figname'] = os.path.join(cmddir, 'match_pgplot.png') else: pgcmd_kwargs['figname'] = os.path.join(cmddir, svdir, 'match_pgplot.png') else: if svdir == None: pgcmd_kwargs['figname'] = os.path.join(cmddir, svname) else: pgcmd_kwargs['figname'] = os.path.join(cmddir, svdir, svname) # four panel plot: if log: pgcmd_kwargs['logcounts'] = True composite_cmd.pgcmd(**pgcmd_kwargs) else: composite_cmd.pgcmd(**pgcmd_kwargs) return
vvclim = round(Nrot / 10.0, 1) vvc_range = np.arange(0.0, vvclim, 0.1) age_range = np.arange(7.9, 9.5, 0.02) # lower lim was 8.5 # default, dummy truths; will be reassigned: truths = {rot: 1e-11 for rot in vvc_range} mass = 5E4 # mock cluster "mass" or total counts; 1e6 was default # Generates mock data from the model library to use instead of observed data if told to: if "mock" in mode: # case of no rotation distribution: if mockd_vvcsig1 == 0.0: # and no age distribution (would be an SSP): if mockd_agesig == 0.0: obscmd = cmd.CMD( fio.get_cmdf(cmddir, bf, mockd_agemu, logz, mockd_vvcmu1, av, dmod)) obs = obscmd.cmd['Nobs'] # age distribution, no rotation distribution, P(sigtau); in practice will trigger so long as mode is mock-sigtau and agesig !=0.0: else: print("GENERATING MOCK DATA WITH AGE SPREAD...") obs = pr.genmod_agespread(cmddir, mass=mass, agemu=mockd_agemu, agesig=mockd_agesig) obsweight = np.sum(obs) # using lower limit of weight search prior for truths of "zero" components. truths = { rot: max([0.0, np.log10(obsweight * 1e-4)]) for rot in vvc_range }
#ax6 = plt.subplot(gs[1, 0]) #ax7 = plt.subplot(gs[1, -1]) #ax8 = plt.subplot(gs[2, 0]) #ax9 = plt.subplot(gs[2, -1]) #ax10 = plt.subplot(gs[-1, 0]) #ax11 = plt.subplot(gs[-1, 1]) #ax12 = plt.subplot(gs[-1, 2]) #ax13 = plt.subplot(gs[-1, 3]) #ax14 = plt.subplot(gs[-1, 4]) #axa = [ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10,ax11,ax12,ax13,ax14] bf, age, logz, av, dmod = "0.00", 9.00, '-0.30', '0.0', '0.00' cmddir = 'output/bf0.00_av0.0_SFR0.01_t9.00_9.02_logZ-0.30_vvc0.4_Tycho_BTycho_V_ex/' # empty out a hess to use as a composite model later: composite_cmd = cmd.CMD(fio.get_cmdf(cmddir, bf, age, logz, 0.0, av, dmod)) #, ymag='I') composite_cmd.cmd['Nsim'] = np.zeros(len(composite_cmd.cmd['Nsim'])) obsweight = np.sum(composite_cmd.cmd['Nobs']) # need random weights and mu, sigma filters = ['Tycho_B', 'Tycho_V'] vvc_range = np.arange(0.0, 1.0, 0.2) Nrot = len(vvc_range) age_range = np.arange(8.5, 9.5, 0.2) mu = np.random.uniform(8.5, 9.3) sigma = 10**np.random.uniform(-2, 0) # try: # sigma = weights[Nrot+1] # except IndexError: # sigma = 0.0