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):
"""
CSiBORG2X `z = 0` field class.
CSiBORG2X `z = 0` field class based on the Manticore ICs.
Parameters
----------
nsim : int
Simulation index.
version : str
Manticore version index.
paths : Paths, optional
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)
def overdensity_field(self, **kwargs):
fpath = self.paths.field(
"overdensity", None, None, self.nsim, "csiborg2X")
with File(fpath, "r") as f:
field = f["delta_cic"][...].astype(np.float32)
if self.version == 0:
fpath = self.paths.field(
"overdensity", None, None, self.nsim, self.nametag)
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
def density_field(self, **kwargs):
field = self.overdensity_field()
omega0 = simname2Omega_m("csiborg2X")
rho_mean = omega0 * 277.53662724583074 # Msun / kpc^3
field += 1
field *= rho_mean
if self.version == 0:
field = self.overdensity_field()
omega0 = simname2Omega_m(self.nametag)
rho_mean = omega0 * 277.53662724583074 # Msun / kpc^3
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
def velocity_field(self, **kwargs):
fpath = self.paths.field(
"velocity", None, None, self.nsim, "csiborg2X")
with File(fpath, "r") as f:
v0 = f["v_0"][...]
v1 = f["v_1"][...]
v2 = f["v_2"][...]
field = np.array([v0, v1, v2])
if self.version == 0:
fpath = self.paths.field(
"velocity", None, None, self.nsim, "csiborg2X")
with File(fpath, "r") as f:
v0 = f["v_0"][...]
v1 = f["v_1"][...]
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