mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-07-02 04:21:12 +00:00
SPH for CSiBORG1 support (#109)
* Add edited files * Update scripts * Updates * Little fix * Little ifx
This commit is contained in:
parent
f0ab6fc9b4
commit
b88c0703f6
2 changed files with 68 additions and 30 deletions
|
@ -16,11 +16,11 @@
|
|||
Script to construct the density and velocity fields for a simulation snapshot.
|
||||
The SPH filter is implemented in the cosmotool package.
|
||||
"""
|
||||
from argparse import ArgumentParser
|
||||
from os import remove
|
||||
from os.path import join, exists
|
||||
import subprocess
|
||||
from argparse import ArgumentParser
|
||||
from datetime import datetime
|
||||
from os import remove
|
||||
from os.path import exists, join
|
||||
|
||||
import hdf5plugin # noqa
|
||||
import numpy as np
|
||||
|
@ -137,7 +137,7 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
|
|||
SPH_executable : str
|
||||
Path to the `simple3DFilter` executable [1].
|
||||
snapshot_kind : str
|
||||
Kind of the simulation snapshot. Currently only `gadget4` is supported.
|
||||
Kind of the simulation snapshot.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
@ -147,12 +147,24 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
|
|||
----------
|
||||
[1] https://bitbucket.org/glavaux/cosmotool/src/master/sample/simple3DFilter.cpp # noqa
|
||||
"""
|
||||
if snapshot_kind != "gadget4":
|
||||
raise NotImplementedError("Only GADGET HDF5 snapshots are supported.")
|
||||
# First get the temporary file path.
|
||||
if snapshot_kind == "gadget4":
|
||||
temporary_output_path = join(
|
||||
scratch_space, generate_unique_id(snapshot_path))
|
||||
elif snapshot_kind == "ramses":
|
||||
temporary_output_path = snapshot_path
|
||||
else:
|
||||
raise NotImplementedError("Only GADGET HDF5 or preprocessed RAMSES "
|
||||
"snapshots are supported.")
|
||||
|
||||
if not temporary_output_path.endswith(".hdf5"):
|
||||
raise RuntimeError("Temporary output path must end with `.hdf5`.")
|
||||
|
||||
# Print the job information.
|
||||
print("---------- SPH Density & Velocity Field Job Information ----------")
|
||||
print(f"Snapshot path: {snapshot_path}")
|
||||
print(f"Output path: {output_path}")
|
||||
print(f"Temporary path: {temporary_output_path}")
|
||||
print(f"Resolution: {resolution}")
|
||||
print(f"Scratch space: {scratch_space}")
|
||||
print(f"SPH executable: {SPH_executable}")
|
||||
|
@ -160,24 +172,28 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
|
|||
print("------------------------------------------------------------------")
|
||||
print(flush=True)
|
||||
|
||||
temporary_output_path = join(
|
||||
scratch_space, generate_unique_id(snapshot_path))
|
||||
|
||||
if not temporary_output_path.endswith(".hdf5"):
|
||||
raise RuntimeError("Temporary output path must end with `.hdf5`.")
|
||||
|
||||
print(f"{now()}: preparing snapshot...", flush=True)
|
||||
boxsize = prepare_gadget(snapshot_path, temporary_output_path)
|
||||
print(f"{now()}: wrote temporary data to {temporary_output_path}.",
|
||||
flush=True)
|
||||
# Prepare or read-off the temporary snapshot file.
|
||||
if snapshot_kind == "gadget4":
|
||||
print(f"{now()}: preparing snapshot...", flush=True)
|
||||
boxsize = prepare_gadget(snapshot_path, temporary_output_path)
|
||||
print(f"{now()}: wrote temporary data to {temporary_output_path}.",
|
||||
flush=True)
|
||||
else:
|
||||
boxsize = 677.7 # Mpc/h
|
||||
print(f"{now()}: CAREFUL, forcefully setting the boxsize to {boxsize} Mpc / h.", # noqa
|
||||
flush=True)
|
||||
|
||||
# Run the SPH filter.
|
||||
run_sph_filter(temporary_output_path, output_path, boxsize, resolution,
|
||||
SPH_executable)
|
||||
print(f"{now()}: removing the temporary snapshot file.", flush=True)
|
||||
try:
|
||||
remove(temporary_output_path)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
# Remove the temporary snapshot file if it was created.
|
||||
if snapshot_kind == "gadget4":
|
||||
print(f"{now()}: removing the temporary snapshot file.", flush=True)
|
||||
try:
|
||||
remove(temporary_output_path)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -193,7 +209,7 @@ if __name__ == "__main__":
|
|||
parser.add_argument("--SPH_executable", type=str, required=True,
|
||||
help="Path to the `simple3DFilter` executable.")
|
||||
parser.add_argument("--snapshot_kind", type=str, required=True,
|
||||
choices=["gadget4"],
|
||||
choices=["gadget4", "ramses"],
|
||||
help="Kind of the simulation snapshot.")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue