def test_mass_assignment_sharp_k(): r = pynbody.array.SimArray([20]) r.units = "Mpc a h^-1" ic = parameters.InitialConditionsParameters(path=path) w_sk = window.WindowParameters(initial_parameters=ic, volume="sharp-k") mass_sk = w_sk.get_mass_from_radius(ic, r, ic.mean_density) w_th = window.WindowParameters(initial_parameters=ic, volume="sphere") mass_th = w_th.get_mass_from_radius(ic, r, ic.mean_density) assert mass_sk == (9 * np.pi /2) * mass_th
def test_radius_assignment_sharp_k(): m = pynbody.array.SimArray([1e13]) m.units = "Msol h^-1" ic = parameters.InitialConditionsParameters(path=path) w_sk = window.WindowParameters(initial_parameters=ic, volume="sharp-k") r_sk = w_sk.get_smoothing_radius_corresponding_to_filtering_mass(ic, m) w_th = window.WindowParameters(initial_parameters=ic, volume="sphere") r_th = w_th.get_smoothing_radius_corresponding_to_filtering_mass(ic, m) r_sk_test = (2 / (9 * np.pi))**(1/3) * r_th assert np.allclose(r_sk, r_sk_test), "Th sharp k radius is" + str(r_sk) + "and the testing one is " + str(r_sk_test)
def importances_plot(imp, initial_parameters=None, save=False, yerr=None, label=None, subplots=1, figsize=(7.5, 6)): if initial_parameters is None: initial_parameters = parameters.InitialConditionsParameters( path="/Users/lls/Documents/CODE", load_final=True) w = window.WindowParameters(initial_parameters=initial_parameters) mass = w.smoothing_masses plot.plot_importances_vs_mass_scale(imp, mass, save=save, yerr=yerr, label=label, path=".", title=None, width=0.5, log=False, subplots=subplots, figsize=figsize, frameon=False, legend_fontsize=None, ecolor="k")
def __init__(self, ids_particles, initial_parameters=None, num_filtering_scales=50, path=None): """ Instantiates :class:`Inertia` given the Args: """ if initial_parameters is None: initial_parameters = parameters.InitialConditionsParameters( path=path) self.initial_parameters = initial_parameters self.filter_parameters = window.WindowParameters( initial_parameters=initial_parameters, num_filtering_scales=num_filtering_scales) # self.delta_class = density.DensityContrasts(initial_parameters=initial_parameters, # num_filtering_scales=num_filtering_scales, # window_function=window_function) # self.shear_class = shear.Shear(initial_parameters=initial_parameters, # num_filtering_scales=num_filtering_scales, # number_of_processors=number_of_processors) # # Inertia.__init__(self, initial_parameters=initial_parameters, density_contrasts=density_contrasts, # # num_filtering_scales=num_filtering_scales, path=path, window_function=window_function) self.filt_scales = np.arange(50) self.ids_particles = ids_particles
def get_in_range_indices_of_trajectories(mass_range="in", initial_parameters=None): if initial_parameters is None: initial_parameters = parameters.InitialConditionsParameters(path="/Users/lls/Documents/CODE") w = window.WindowParameters(initial_parameters=initial_parameters, num_filtering_scales=50) if mass_range == "in": range_mass_IN = np.intersect1d(np.where(w.smoothing_masses > initial_parameters.halo[initial_parameters.max_halo_number]['mass'].sum()), np.where(w.smoothing_masses < initial_parameters.halo[initial_parameters.min_halo_number]['mass'].sum())) return range_mass_IN else: NameError("Enter a valid mass range of trajectories")
def test_correct_units(): initial_parameters = parameters.InitialConditionsParameters(path=path) snapshot = initial_parameters.initial_conditions smoothing_radii = np.linspace(0.0057291, 0.20, 1500) r_a_h = smoothing_radii/snapshot.properties['a'] * snapshot.properties['h'] r_a_h = r_a_h.view(pynbody.array.SimArray) r_a_h.units = "Mpc a h^-1" th = pynbody.analysis.hmf.TophatFilter(snapshot) m = th.R_to_M(r_a_h) m.units = "Msol h^-1" rho_M = pynbody.analysis.cosmology.rho_M(snapshot, unit="Msol Mpc**-3") w = window.WindowParameters(initial_parameters=initial_parameters, volume="sphere") filtering_masses = w.get_mass_from_radius(initial_parameters, smoothing_radii, rho_M) filtering_masses_with_h = filtering_masses * snapshot.properties['h'] filtering_masses_with_h.units = "Msol h^-1" np.testing.assert_allclose(filtering_masses_with_h, m)
sys.path.append("/home/lls/mlhalos_code/") import numpy as np from mlhalos import parameters from mlhalos import window from mlhalos import density import pynbody from regression.adaboost import gbm_04_only as gbm_fun import matplotlib.pyplot as plt from sklearn.externals import joblib # path="/Users/lls/Documents/mlhalos_files/" saving_path_traj = "/share/data2/lls/regression/gradboost/randomly_sampled_training/ic_traj_smoothed_above_1e15Msol/" ic = parameters.InitialConditionsParameters() w = window.WindowParameters(initial_parameters=ic) d = density.DensityContrasts(initial_parameters=ic) m = np.linspace(np.log10(3e10), np.log10(1e15), 50) width = np.append(np.diff(m), np.diff(m)[-1]) m_all_p = ic.initial_conditions["mass"].sum() m1 = np.arange(np.log10(1e15), np.log10(m_all_p*5000), step=width[-1])[1:] M = pynbody.array.SimArray(10**m1) M.units = "Msol" r_smoothing = w.get_smoothing_radius_corresponding_to_filtering_mass(ic, M) den = d.get_smooth_density_for_radii_list(ic, r_smoothing) traj_high_smoothing = den/ic.mean_density np.save(saving_path_traj + "density_contrasts_smoothed_above_1e15Msol.npy", traj_high_smoothing)
import numpy as np import matplotlib.pyplot as plt from mlhalos import parameters from mlhalos import window ic = parameters.InitialConditionsParameters(path="/Users/lls/Documents/CODE", load_final=True) w = window.WindowParameters(initial_parameters=ic, num_filtering_scales=50) halo_mass = np.load( "/Users/lls/Documents/mlhalos_files/stored_files/halo_mass_particles.npy") in_ids = np.where(halo_mass > 0)[0] path_lowz = "/Users/lls/Documents/mlhalos_files/regression/lowz_density/" lowz_den = np.lib.format.open_memmap(path_lowz + "z8_density_contrasts.npy") ics_den = np.lib.format.open_memmap(path_lowz + "ics_density_contrasts.npy") lowz_den_in_ids = lowz_den[in_ids] ics_in_ids = ics_den[in_ids] h_m_in_ids = halo_mass[in_ids] f_1 = np.vstack((lowz_den_in_ids.transpose(), np.log10(h_m_in_ids))) corr = np.corrcoef(f_1) f_2 = np.vstack((ics_in_ids.transpose(), np.log10(h_m_in_ids))) corr_ics = np.corrcoef(f_2) f_3 = np.vstack((ics_in_ids.transpose(), lowz_den_in_ids.transpose())) corr_dens = np.corrcoef(f_3) x_min = np.log10(w.smoothing_masses).min()