def get_halomodel(required_attrs, get_label=True, kls=HaloModel, fast_kwargs={"transfer_fit":"BBKS", "lnk_min":-4, "lnk_max":2, "dlnk":1, "Mmin":13, "dlog10m":0.5, "rmin":10, "rmax":20, "rnum":4, "halo_exclusion":"None", "nonlinear":False, "scale_dependent_bias":False, "hod_model":"Zehavi05"}, **kwargs): return get_hmf(required_attrs, get_label, kls, fast_kwargs, **kwargs)
def test_order(): order = [ "sigma.8: 0.7, ST, z: 0", "sigma.8: 0.8, ST, z: 0", "sigma.8: 0.7, ST, z: 1", "sigma.8: 0.8, ST, z: 1", "sigma.8: 0.7, ST, z: 2", "sigma.8: 0.8, ST, z: 2", "sigma.8: 0.7, PS, z: 0", "sigma.8: 0.8, PS, z: 0", "sigma.8: 0.7, PS, z: 1", "sigma.8: 0.8, PS, z: 1", "sigma.8: 0.7, PS, z: 2", "sigma.8: 0.8, PS, z: 2" ] for i, (quants, mf, label) in enumerate( tf.get_hmf(['dndm', 'ngtm'], z=range(3), hmf_model=["ST", "PS"], sigma_8=[0.7, 0.8])): assert label == order[i] assert isinstance(mf, MassFunction) assert np.allclose(quants[0], mf.dndm) assert np.allclose(quants[1], mf.ngtm)
def test_order(): order = [ "sigma.8: 0.7, ST, z: 0", "sigma.8: 0.8, ST, z: 0", "sigma.8: 0.7, ST, z: 1", "sigma.8: 0.8, ST, z: 1", "sigma.8: 0.7, ST, z: 2", "sigma.8: 0.8, ST, z: 2", "sigma.8: 0.7, PS, z: 0", "sigma.8: 0.8, PS, z: 0", "sigma.8: 0.7, PS, z: 1", "sigma.8: 0.8, PS, z: 1", "sigma.8: 0.7, PS, z: 2", "sigma.8: 0.8, PS, z: 2", ] for i, (quants, mf, label) in enumerate( tf.get_hmf(["dndm", "ngtm"], z=range(3), hmf_model=["ST", "PS"], sigma_8=[0.7, 0.8]) ): assert label == order[i] assert isinstance(mf, MassFunction) assert np.allclose(quants[0], mf.dndm) assert np.allclose(quants[1], mf.ngtm)
def hmf_driver(label, transfer_fit, transfer_options, **kwargs): # A dictionary of bools for optional extra plots. # Change directory to this file (for picking up transfer files if pre-made) os.chdir(os.path.dirname(__file__)) # Set up a logger hmflog = logging.getLogger("hmf") stream = io.StringIO() ch = logging.StreamHandler(stream) hmflog.addHandler(ch) # Appropriately handle WDM if len(kwargs["wdm_mass"]) == 0: kwargs["wdm_mass"] = [None] objects = [] labels = [] for res in get_hmf('dndm', get_label=True, transfer_fit=transfer_fit, transfer_options=transfer_options, **kwargs): objects += [copy.deepcopy(res[1])] labels += [label + " " + res[2]] # Loop through all the different cosmologies # for cosmo_i, cosmo_dict in enumerate(cosmology_list): # growths.append([]) # # Save the cosmo_label to the column label # if len(cosmology_list) > 1 or max(len(cosmology_list), len(k_bounds), len(z_list), len(approaches), len(overdensities)) == 1: # labels['cosmo'] = cosmo_labels[cosmo_i] # labels["cosmo_fallback"] = cosmo_labels[cosmo_i] # # # Loop through all WDM models (CDM first) # for k_bound in k_bounds: # # Save the k_bounds to the label # lnk = np.linspace(np.log(k_bound[0]), np.log(k_bound[1]), 250) # if len(k_bounds) > 1: # labels['k'] = 'k{' + str(k_bound[0]) + ',' + str(k_bound[1]) + '}' # for wdm in [None] + WDM_list: # # Add WDM label # if len(WDM_list) > 0: # if wdm is None: # labels['wdm'] = 'CDM' # else: # labels['wdm'] = 'WDM=' + str(wdm) # # Loop over all redshifts # for z in z_list: # # Define a column-name extension for the table # if len(z_list) > 1 or z > 0: # labels['z'] = 'z=' + str(z) # # # Update pert object optimally with new variables # pert.update(lnk=lnk, wdm_mass=wdm, z=z, **cosmo_dict) # # growths[cosmo_i].append(pert.transfer.growth) # # Save k-based data # excludes = ['deltahalo', 'fsig', "cosmo_fallback"] # k_data["ln(k)_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.transfer.lnk # k_data["ln(P(k))_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.transfer.power # # # Save Mass-Based data # mass_data["sigma_" + (getname(labels, excl=excludes) or getname(labels, excl=excludes[:-1]))] = pert.sigma # mass_data["lnsigma_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.lnsigma # mass_data["neff_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.n_eff # # # Loop over fitting functions # for approach in approaches: # if len(approaches) > 1: # labels['fsig'] = approach # for overdensity in overdensities: # if len(overdensities) > 1: # labels['deltahalo'] = 'Delta_h=' + str(overdensity) # # # Save the data # pert.update(mf_fit=approach, delta_h=overdensity, delta_c=cosmo_dict['delta_c']) # mass_data["f(sig)_" + getname(labels, excl="cosmo_fallback")] = pert.fsigma # # # ----- Mass Functions ----- # if hmf_form == 'dndlnm': # mass_data["dndlnm_" + getname(labels, excl=['cosmo_fallback'])] = pert.dndlnm # mass_data["M*dndlnm_" + getname(labels, excl="cosmo_fallback")] = pert.dndlnm * pert.M # elif hmf_form == 'dndlog10m': # mass_data["dndlog10m_" + getname(labels, excl=['cosmo_fallback'])] = pert.dndlog10m # mass_data["M*dndlog10m_" + getname(labels, excl="cosmo_fallback")] = pert.dndlog10m * pert.M # elif hmf_form == 'dndm': # mass_data["dndm_" + getname(labels, excl=['cosmo_fallback'])] = pert.dndm # mass_data["M*dndm_" + getname(labels, excl="cosmo_fallback")] = pert.dndm * pert.M # # # Extra Plots: Easily add more when you need to # if 'get_ngtm' in extra_plots: # mass_data["ngtm_" + getname(labels, excl="cosmo_fallback")] = pert.ngtm # if 'get_mgtm' in extra_plots: # mass_data["mgtm_" + getname(labels, excl="cosmo_fallback")] = pert.mgtm # if 'get_nltm' in extra_plots: # mass_data["nltm_" + getname(labels, excl="cosmo_fallback")] = pert.nltm # if 'get_mltm' in extra_plots: # mass_data["mltm_" + getname(labels, excl="cosmo_fallback")] = pert.mltm # if 'get_L' in extra_plots: # mass_data["L(N=1)_" + getname(labels, excl="cosmo_fallback")] = pert.how_big # print stream.getvalue() warnings = stream.buflist warnings = list(set(warnings)) return objects, labels, warnings
def hmf_driver(label, transfer_fit, transfer_options, **kwargs): # A dictionary of bools for optional extra plots. # Change directory to this file (for picking up transfer files if pre-made) os.chdir(os.path.dirname(__file__)) # Set up a logger hmflog = logging.getLogger("hmf") stream = StringIO.StringIO() ch = logging.StreamHandler(stream) hmflog.addHandler(ch) # Appropriately handle WDM if len(kwargs["wdm_mass"]) == 0: kwargs["wdm_mass"] = [None] objects = [] labels = [] for res in get_hmf('dndm', get_label=True, transfer_fit=transfer_fit, transfer_options=transfer_options, **kwargs): objects += [copy.deepcopy(res[1])] labels += [label + " " + res[2]] # Loop through all the different cosmologies # for cosmo_i, cosmo_dict in enumerate(cosmology_list): # growths.append([]) # # Save the cosmo_label to the column label # if len(cosmology_list) > 1 or max(len(cosmology_list), len(k_bounds), len(z_list), len(approaches), len(overdensities)) == 1: # labels['cosmo'] = cosmo_labels[cosmo_i] # labels["cosmo_fallback"] = cosmo_labels[cosmo_i] # # # Loop through all WDM models (CDM first) # for k_bound in k_bounds: # # Save the k_bounds to the label # lnk = np.linspace(np.log(k_bound[0]), np.log(k_bound[1]), 250) # if len(k_bounds) > 1: # labels['k'] = 'k{' + str(k_bound[0]) + ',' + str(k_bound[1]) + '}' # for wdm in [None] + WDM_list: # # Add WDM label # if len(WDM_list) > 0: # if wdm is None: # labels['wdm'] = 'CDM' # else: # labels['wdm'] = 'WDM=' + str(wdm) # # Loop over all redshifts # for z in z_list: # # Define a column-name extension for the table # if len(z_list) > 1 or z > 0: # labels['z'] = 'z=' + str(z) # # # Update pert object optimally with new variables # pert.update(lnk=lnk, wdm_mass=wdm, z=z, **cosmo_dict) # # growths[cosmo_i].append(pert.transfer.growth) # # Save k-based data # excludes = ['deltahalo', 'fsig', "cosmo_fallback"] # k_data["ln(k)_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.transfer.lnk # k_data["ln(P(k))_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.transfer.power # # # Save Mass-Based data # mass_data["sigma_" + (getname(labels, excl=excludes) or getname(labels, excl=excludes[:-1]))] = pert.sigma # mass_data["lnsigma_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.lnsigma # mass_data["neff_" + (getname(labels, excl=excludes)or getname(labels, excl=excludes[:-1]))] = pert.n_eff # # # Loop over fitting functions # for approach in approaches: # if len(approaches) > 1: # labels['fsig'] = approach # for overdensity in overdensities: # if len(overdensities) > 1: # labels['deltahalo'] = 'Delta_h=' + str(overdensity) # # # Save the data # pert.update(mf_fit=approach, delta_h=overdensity, delta_c=cosmo_dict['delta_c']) # mass_data["f(sig)_" + getname(labels, excl="cosmo_fallback")] = pert.fsigma # # # ----- Mass Functions ----- # if hmf_form == 'dndlnm': # mass_data["dndlnm_" + getname(labels, excl=['cosmo_fallback'])] = pert.dndlnm # mass_data["M*dndlnm_" + getname(labels, excl="cosmo_fallback")] = pert.dndlnm * pert.M # elif hmf_form == 'dndlog10m': # mass_data["dndlog10m_" + getname(labels, excl=['cosmo_fallback'])] = pert.dndlog10m # mass_data["M*dndlog10m_" + getname(labels, excl="cosmo_fallback")] = pert.dndlog10m * pert.M # elif hmf_form == 'dndm': # mass_data["dndm_" + getname(labels, excl=['cosmo_fallback'])] = pert.dndm # mass_data["M*dndm_" + getname(labels, excl="cosmo_fallback")] = pert.dndm * pert.M # # # Extra Plots: Easily add more when you need to # if 'get_ngtm' in extra_plots: # mass_data["ngtm_" + getname(labels, excl="cosmo_fallback")] = pert.ngtm # if 'get_mgtm' in extra_plots: # mass_data["mgtm_" + getname(labels, excl="cosmo_fallback")] = pert.mgtm # if 'get_nltm' in extra_plots: # mass_data["nltm_" + getname(labels, excl="cosmo_fallback")] = pert.nltm # if 'get_mltm' in extra_plots: # mass_data["mltm_" + getname(labels, excl="cosmo_fallback")] = pert.mltm # if 'get_L' in extra_plots: # mass_data["L(N=1)_" + getname(labels, excl="cosmo_fallback")] = pert.how_big # print stream.getvalue() warnings = stream.buflist warnings = list(set(warnings)) return objects, labels, warnings