def make_edges(rcen): edges = np.empty(len(rcen)+1) spacing = 0.5*np.diff(rcen) edges[0], edges[-1] = rcen[0]-spacing[0], rcen[-1]+spacing[-1] edges[1:-1] = rcen[1:]-spacing return edges
def get_Phm(self, space="real"): """ Return Phm in the space specified, either `real` or `redshift` """ if space != "real": raise NotImplementedError("sorry, only real-space results exist for Phm") try: return getattr(self, "_Phm_" + space) except AttributeError: d = os.path.join(self.root, "halo-matter") mass_bins = ["00020_00060", "00060_00180", "00180_00540", "00540_01620"] redshifts = ["z007", "z005", "z004"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} basename = "pk_mr0_hr0_{mass}_{z}_linaax" data = np.empty((len(redshifts), len(mass_bins)), dtype=object) for i in range(len(redshifts)): for j in range(len(mass_bins)): args = {"mass": mass_bins[j], "z": redshifts[i]} filename = os.path.join(d, basename.format(**args)) if os.path.exists(filename): data[i, j] = load_data(np.loadtxt(filename), space, **meta) else: data[i, j] = np.nan Phm = SpectraSet(data, coords=[self.z, self.mass], dims=["z", "mass"]) setattr(self, "_Phm_" + space, Phm) return Phm
def get_Phh(self, space="real"): """ Return Phh in the space specified. Only 'real' is currently implemented. """ try: return getattr(self, "_Phh_" + space) except AttributeError: d = os.path.join(self.root, "halo") mass_bins = ["00020_00060", "00060_00180", "00180_00540", "00540_01620"] redshifts = ["z007", "z005", "z004"] Pshot = [ [2336.0, 6494.0, 21882.0, 101112.0], [2849.0, 9174.0, 41152.0, 314465.0], [4065.0, 16447.0, 111359.0, np.nan], ] meta = {"box_size": 1600.0, "N1": 0, "N2": 0} basename = "pkmu_chi_00_h_h_{mass}_{z}_1-3_02-13binaaQ" data = np.empty((len(redshifts), len(mass_bins)), dtype=object) for i in range(len(redshifts)): for j in range(len(mass_bins)): args = {"mass": mass_bins[j], "z": redshifts[i]} meta["N1"] = meta["N2"] = meta["box_size"] ** 3 / Pshot[i][j] filename = os.path.join(d, basename.format(**args)) if os.path.exists(filename): data[i, j] = load_data(np.loadtxt(filename), space, **meta) else: data[i, j] = np.nan Phh = SpectraSet(data, coords=[self.z, self.mass], dims=["z", "mass"]) setattr(self, "_Phh_" + space, Phh) return Phh
def make_kedges(data): k = data[:, 0] kedges = np.empty(len(k) + 1) dk = 0.5 * np.diff(k) kedges[0], kedges[-1] = k[0] - dk[0], k[-1] + dk[-1] kedges[1:-1] = k[1:] - dk return kedges
def get_P11(self, mu, smooth=False): """ Return the dark matter P11[mu^2] or P11[mu^4] correlator in real-space """ tag = "_smooth" if smooth else "" name = "_P11_%s%s" % (mu, smooth) if mu not in ["mu2", "mu4"]: raise ValueError("`mu` must be one of [`mu2`, `mu4`]") try: return getattr(self, name) except AttributeError: redshifts = ["z007", "z005", "z004"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} if smooth: if mu == "mu2": from pyRSD.data import P11_mu2_z_0_000, P11_mu2_z_0_509, P11_mu2_z_0_989 smooth_data = [P11_mu2_z_0_000(), P11_mu2_z_0_509(), P11_mu2_z_0_989()] else: from pyRSD.data import P11_mu4_z_0_000, P11_mu4_z_0_509, P11_mu4_z_0_989 smooth_data = [P11_mu4_z_0_000(), P11_mu4_z_0_509(), P11_mu4_z_0_989()] else: d = os.path.join(self.root, "dark_matter") basename = "pkmu_chi_11_m_m_{z}_1-3_02-13binaaQ" if mu == "mu2": cols = [-4, -2] else: cols = [-3, -1] data = np.empty(len(redshifts), dtype=object) for i in range(len(redshifts)): if not smooth: filename = os.path.join(d, basename.format(z=redshifts[i])) if os.path.exists(filename): x = np.loadtxt(filename) else: data[i] = np.nan continue else: x = smooth_data[i] kedges = make_kedges(x) data_dict = {} data_dict["k"] = x[:, 0] if not smooth: data_dict["power"] = x[:, cols[0]] * x[:, 0] ** 2 data_dict["error"] = x[:, cols[1]] * x[:, 0] ** 2 else: data_dict["power"] = x[:, 1] data[i] = Power1dDataSet(kedges, data_dict, **meta) toret = SpectraSet(data, coords=[self.z], dims=["z"]) setattr(self, name, toret) return toret
def get_P01(self, smooth=False): """ Return the dark matter P01[mu^2] correlator in real-space """ tag = "_smooth" if smooth else "" name = "_P01%s" % tag try: return getattr(self, name) except AttributeError: redshifts = ["z007", "z005", "z004"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} if smooth: from pyRSD.data import P01_mu2_z_0_000, P01_mu2_z_0_509, P01_mu2_z_0_989 smooth_data = [P01_mu2_z_0_000(), P01_mu2_z_0_509(), P01_mu2_z_0_989()] else: d = os.path.join(self.root, "dark_matter") basename = "pkmu_chi_01_m_m_{z}_1-3_02-13binaaQ" data = np.empty(len(redshifts), dtype=object) for i in range(len(redshifts)): if not smooth: filename = os.path.join(d, basename.format(z=redshifts[i])) if os.path.exists(filename): x = np.loadtxt(filename) else: data[i] = np.nan continue else: x = smooth_data[i] kedges = make_kedges(x) data_dict = {} data_dict["k"] = x[:, 0] if not smooth: data_dict["power"] = x[:, -2] * 2 * x[:, 0] data_dict["error"] = x[:, -1] * 2 * x[:, 0] else: data_dict["power"] = x[:, 1] data[i] = Power1dDataSet(kedges, data_dict, **meta) toret = SpectraSet(data, coords=[self.z], dims=["z"]) setattr(self, name, toret) return toret
def get_galaxy_poles(self): """ Return galaxy multipoles in redshift space """ try: return getattr(self, "_poles") except AttributeError: samples = ["mono", "quad"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} basename = "Pgg_{sample}_z_0_509" data = np.empty(len(samples), dtype=object) for i in range(len(samples)): d = getattr(sim_data, basename.format(sample=samples[i]))() data[i] = load_data(d, "real", **meta) Pgal = SpectraSet(data, coords=[samples], dims=["sample"]) setattr(self, "_poles", Pgal) return Pgal
def get_Pgal_no_fog(self): """ Return galaxy component spectra in redshift space, with no FOG effect """ try: return getattr(self, "_Pgal_no_fog") except AttributeError: samples = ["cAs", "sAsA", "sAsB"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} basename = "P{sample}_no_fog_z_0_509" data = np.empty(len(samples), dtype=object) for i in range(len(samples)): d = getattr(sim_data, basename.format(sample=samples[i]))() data[i] = load_data(d, "redshift", **meta) Pgal = SpectraSet(data, coords=[samples], dims=["sample"]) setattr(self, "_Pgal_no_fog", Pgal) return Pgal
def get_Pmm(self, space="real"): """ Return Pmm in the space specified, either `real` or `redshift` """ try: return getattr(self, "_Pmm_" + space) except AttributeError: d = os.path.join(self.root, "dark_matter") redshifts = ["z007", "z005", "z004"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} basename = "pkmu_chi_00_m_m_{z}_1-3_02-13binaaQ" data = np.empty(len(redshifts), dtype=object) for i in range(len(redshifts)): filename = os.path.join(d, basename.format(z=redshifts[i])) if os.path.exists(filename): data[i] = load_data(np.loadtxt(filename), space, **meta) else: data[i] = np.nan Pmm = SpectraSet(data, coords=[self.z], dims=["z"]) setattr(self, "_Pmm_" + space, Pmm) return Pmm
def get_Pgal(self, space="real"): """ Return galaxy component spectra """ try: return getattr(self, "_Pgal_" + space) except AttributeError: samples = ["gg", "cc", "cAs", "sAsA", "sAsB"] meta = {"box_size": 1600.0, "N1": np.inf, "N2": np.inf} basename = "P{sample}_z_0_509" data = np.empty(len(samples), dtype=object) for i in range(len(samples)): d = getattr(sim_data, basename.format(sample=samples[i]))() if space == "real" and d.shape[-1] == 13 or space == "redshift": data[i] = load_data(d, space, **meta) else: data[i] = np.nan Pgal = SpectraSet(data, coords=[samples], dims=["sample"]) setattr(self, "_Pgal_" + space, Pgal) return Pgal