csiborgtools/scripts_independent/density_field_tng.py

57 lines
2 KiB
Python
Raw Normal View History

Overlap fixing and more (#107) * Update README * Update density field reader * Update name of SDSSxALFAFA * Fix quick bug * Add little fixes * Update README * Put back fit_init * Add paths to initial snapshots * Add export * Remove some choices * Edit README * Add Jens' comments * Organize imports * Rename snapshot * Add additional print statement * Add paths to initial snapshots * Add masses to the initial files * Add normalization * Edit README * Update README * Fix bug in CSiBORG1 so that does not read fof_00001 * Edit README * Edit README * Overwrite comments * Add paths to init lag * Fix Quijote path * Add lagpatch * Edit submits * Update README * Fix numpy int problem * Update README * Add a flag to keep the snapshots open when fitting * Add a flag to keep snapshots open * Comment out some path issue * Keep snapshots open * Access directly snasphot * Add lagpatch for CSiBORG2 * Add treatment of x-z coordinates flipping * Add radial velocity field loader * Update README * Add lagpatch to Quijote * Fix typo * Add setter * Fix typo * Update README * Add output halo cat as ASCII * Add import * Add halo plot * Update README * Add evaluating field at radial distanfe * Add field shell evaluation * Add enclosed mass computation * Add BORG2 import * Add BORG boxsize * Add BORG paths * Edit run * Add BORG2 overdensity field * Add bulk flow clauclation * Update README * Add new plots * Add nbs * Edit paper * Update plotting * Fix overlap paths to contain simname * Add normalization of positions * Add default paths to CSiBORG1 * Add overlap path simname * Fix little things * Add CSiBORG2 catalogue * Update README * Add import * Add TNG density field constructor * Add TNG density * Add draft of calculating BORG ACL * Fix bug * Add ACL of enclosed density * Add nmean acl * Add galaxy bias calculation * Add BORG acl notebook * Add enclosed mass calculation * Add TNG300-1 dir * Add TNG300 and BORG1 dir * Update nb
2024-01-30 16:14:07 +00:00
# Copyright (C) 2023 Richard Stiskalek
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Script to iteratively load particles of a TNG simulation and construct the DM
density field.
"""
from glob import glob
from os.path import join
import MAS_library as MASL
import numpy as np
from h5py import File
from tqdm import trange
if __name__ == "__main__":
# Some parameters
basepath = "/mnt/extraspace/rstiskalek/TNG300-1"
snap = str(99).zfill(3)
grid = 1024
boxsize = 205000.0 # kpc/h
mpart = 0.00398342749867548 * 1e10 # Msun/h, DM particles mass
MAS = "PCS"
# Get the snapshot files
files = glob(join(basepath, "output", f"snapdir_{snap}", f"snap_{snap}.*"))
print(f"Found {len(files)} snapshot files.")
# Iterate over the snapshot files and construct the density field
rho = np.zeros((grid, grid, grid), dtype=np.float32)
for i in trange(len(files), desc="Reading snapshot files"):
with File(files[i], 'r') as f:
pos = f["PartType1/Coordinates"][...].astype(np.float32)
MASL.MA(pos, rho, boxsize, MAS, verbose=False)
# Convert to units h^2 Msun / kpc^3
rho *= mpart / (boxsize / grid)**3
# Save to file
fname = join(basepath, "postprocessing", "density_field",
f"rho_dm_{snap}_{grid}_{MAS}.npy")
print(f"Saving to {fname}.", flush=True)
np.save(fname, rho)