Add CLONES support (#145)

* Add submit script

* Add support for gadget2

* Add OMP

* Lower resolution

* Update resolution again

* Add selection on galactic latitude

* Update name

* Update nb

* Update nb

* Add CLONES params

* Add import

* Add CLONES path

* Add CLONES reader

* Quick fix

* Add CLONES

* Update slice nb

* Update nb

* Update nb

* Tiny updates

* Update nb

* Add name

* Add CLONES support

* Add CF4 field

* Add CLONES

* Update script

* Update nb

* Update nb
This commit is contained in:
Richard Stiskalek 2024-09-12 17:04:25 +02:00 committed by GitHub
parent a4d02b4cc4
commit 32e36afdc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 874 additions and 214 deletions

View file

@ -23,6 +23,7 @@ from os import remove
from os.path import exists, join
import hdf5plugin # noqa
import readgadget
import numpy as np
from h5py import File
@ -84,6 +85,28 @@ def prepare_gadget(snapshot_path, temporary_output_path):
return boxsize
def prepara_gadget2(snapshot_path, temporary_output_path):
ptype = [1]
header = readgadget.header(snapshot_path)
boxsize = header.boxsize / 1000
npart = header.nall[1]
mpart = header.massarr[1] * 1e10
print(f"{'Boxsize':<20}: {boxsize}")
print(f"{'Npart':<20}: {npart}")
print(f"{'Mpart':<20}: {mpart}")
with File(temporary_output_path, 'w') as target:
dset = target.create_dataset("particles", (npart, 7), dtype=np.float32)
dset[:, :3] = readgadget.read_block(snapshot_path, "POS ", ptype) / 1000 # noqa
dset[:, 3:6] = readgadget.read_block(snapshot_path, "VEL ", ptype)
dset[:, 6] = np.ones(npart, dtype=np.float32) * mpart
return boxsize
def run_sph_filter(particles_path, output_path, boxsize, resolution,
SPH_executable):
"""
@ -148,7 +171,7 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
[1] https://bitbucket.org/glavaux/cosmotool/src/master/sample/simple3DFilter.cpp # noqa
"""
# First get the temporary file path.
if snapshot_kind == "gadget4":
if snapshot_kind in ["gadget2", "gadget4"]:
temporary_output_path = join(
scratch_space, generate_unique_id(snapshot_path))
elif snapshot_kind == "ramses":
@ -158,9 +181,10 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
"snapshots are supported.")
if not temporary_output_path.endswith(".hdf5"):
raise RuntimeError("Temporary output path must end with `.hdf5`.")
temporary_output_path += ".hdf5"
# Print the job information.
print()
print("---------- SPH Density & Velocity Field Job Information ----------")
print(f"Snapshot path: {snapshot_path}")
print(f"Output path: {output_path}")
@ -178,6 +202,10 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
boxsize = prepare_gadget(snapshot_path, temporary_output_path)
print(f"{now()}: wrote temporary data to {temporary_output_path}.",
flush=True)
elif snapshot_kind == "gadget2":
print(f"{now()}: preparing snapshot...", flush=True)
boxsize = prepara_gadget2(snapshot_path, temporary_output_path)
print(f"{now()}: wrote temporary data to {temporary_output_path}.")
else:
boxsize = 677.7 # Mpc/h
print(f"{now()}: CAREFUL, forcefully setting the boxsize to {boxsize} Mpc / h.", # noqa
@ -209,9 +237,12 @@ 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", "ramses"],
choices=["gadget4", "gadget2", "ramses"],
help="Kind of the simulation snapshot.")
args = parser.parse_args()
if not args.output_path.endswith(".hdf5"):
raise RuntimeError("Output path must end with `.hdf5`.")
main(args.snapshot_path, args.output_path, args.resolution,
args.scratch_space, args.SPH_executable, args.snapshot_kind)

View file

@ -0,0 +1,39 @@
#!/bin/bash
nthreads=28
memory=7
on_login=${1}
queue="berg"
env="/mnt/zfsusers/rstiskalek/csiborgtools/venv_csiborg/bin/python"
file="field_sph_gadget.py"
# Guilhem says higher resolution is better
resolution=1024
SPH_executable="/mnt/users/rstiskalek/cosmotool/bld/sample/simple3DFilter"
scratch_space="/mnt/extraspace/rstiskalek/dump/"
snapshot_kind="gadget2"
snapshot_path="/mnt/extraspace/rstiskalek/CLONES/s8/cf2gvpecc1pt5elmo73_sig6distribsbvoldi_RZA3Derrv2_512_500_ss8_zinit60_000"
output_path="/mnt/extraspace/rstiskalek/CLONES/s8/cf2gvpecc1pt5elmo73_sig6distribsbvoldi_RZA3Derrv2_512_500_ss8_zinit60_000.hdf5"
# Check if `on_login` is either 0 or 1
# Check if on_login is not empty and is a valid integer (0 or 1)
if [ -z "$on_login" ] || ! [[ "$on_login" =~ ^[0-1]$ ]]; then
echo "First argument must be either 0 or 1. Received: $on_login"
exit 1
fi
export OMP_NUM_THREADS={nthreads}
export OMP_NESTED=true
pythoncm="$env $file --snapshot_path $snapshot_path --output_path $output_path --resolution $resolution --scratch_space $scratch_space --SPH_executable $SPH_executable --snapshot_kind $snapshot_kind"
if [ $on_login -eq 1 ]; then
echo $pythoncm
$pythoncm
else
cm="addqueue -s -q $queue -n 1x$nthreads -m $memory $pythoncm"
echo "Submitting:"
echo $cm
echo
eval $cm
fi