Add new Manticore field support

This commit is contained in:
rstiskalek 2024-09-20 12:58:28 +01:00
parent 45ef6046fa
commit b88804ea84

View file

@ -771,42 +771,90 @@ class CSiBORG2Field(BaseField):
class CSiBORG2XField(BaseField): class CSiBORG2XField(BaseField):
""" """
CSiBORG2X `z = 0` field class. CSiBORG2X `z = 0` field class based on the Manticore ICs.
Parameters Parameters
---------- ----------
nsim : int nsim : int
Simulation index. Simulation index.
version : str
Manticore version index.
paths : Paths, optional paths : Paths, optional
Paths object. By default, the paths are set to the `glamdring` paths. Paths object. By default, the paths are set to the `glamdring` paths.
""" """
def __init__(self, nsim, paths=None): def __init__(self, nsim, version, paths=None):
self.version = version
if version == 0:
self.nametag = "csiborg2X"
elif version == 1:
self.nametag = "manticore_2MPP_N128_DES_V1"
else:
raise ValueError("Invalid Manticore version.")
super().__init__(nsim, paths, False) super().__init__(nsim, paths, False)
def overdensity_field(self, **kwargs): def overdensity_field(self, **kwargs):
fpath = self.paths.field( if self.version == 0:
"overdensity", None, None, self.nsim, "csiborg2X") fpath = self.paths.field(
with File(fpath, "r") as f: "overdensity", None, None, self.nsim, self.nametag)
field = f["delta_cic"][...].astype(np.float32) with File(fpath, "r") as f:
field = f["delta_cic"][...].astype(np.float32)
else:
raise ValueError("Invalid Manticore version to read the "
"overdensity field.")
return field return field
def density_field(self, **kwargs): def density_field(self, **kwargs):
field = self.overdensity_field() if self.version == 0:
omega0 = simname2Omega_m("csiborg2X") field = self.overdensity_field()
rho_mean = omega0 * 277.53662724583074 # Msun / kpc^3 omega0 = simname2Omega_m(self.nametag)
field += 1 rho_mean = omega0 * 277.53662724583074 # Msun / kpc^3
field *= rho_mean field += 1
field *= rho_mean
elif self.version == 1:
MAS = kwargs["MAS"]
grid = kwargs["grid"]
fpath = self.paths.field(
"density", MAS, grid, self.nsim, self.nametag)
if MAS == "SPH":
with File(fpath, "r") as f:
field = f["density"][:]
field /= (681.1 * 1e3 / grid)**3 # Convert to h^2 Msun / kpc^3
else:
field = np.load(fpath)
else:
raise ValueError("Invalid Manticore version to read the "
"density field.")
return field return field
def velocity_field(self, **kwargs): def velocity_field(self, **kwargs):
fpath = self.paths.field( if self.version == 0:
"velocity", None, None, self.nsim, "csiborg2X") fpath = self.paths.field(
with File(fpath, "r") as f: "velocity", None, None, self.nsim, "csiborg2X")
v0 = f["v_0"][...] with File(fpath, "r") as f:
v1 = f["v_1"][...] v0 = f["v_0"][...]
v2 = f["v_2"][...] v1 = f["v_1"][...]
field = np.array([v0, v1, v2]) v2 = f["v_2"][...]
field = np.array([v0, v1, v2])
elif self.version == 1:
MAS = kwargs["MAS"]
grid = kwargs["grid"]
fpath = self.paths.field(
"velocity", MAS, grid, self.nsim, self.nametag)
if MAS:
with File(fpath, "r") as f:
density = f["density"][:]
v0 = f["p0"][:] / density
v1 = f["p1"][:] / density
v2 = f["p2"][:] / density
field = np.array([v0, v1, v2])
else:
field = np.load(fpath)
return field return field