convert snapshot to density script
This commit is contained in:
parent
302f635485
commit
f63a20bf5b
1 changed files with 54 additions and 0 deletions
54
convert_snapshot_to_density.py
Normal file
54
convert_snapshot_to_density.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from pysbmy.density import get_density_pm_snapshot
|
||||
from pysbmy.snapshot import read_snapshot
|
||||
import argparse
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Convert snapshot to density.")
|
||||
parser.add_argument(
|
||||
"-S",
|
||||
"--snapshot",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Path to the snapshot file.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Path to the output density file.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-N",
|
||||
"--N",
|
||||
type=int,
|
||||
default=None,
|
||||
help="Size of the density field grid (N x N x N).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--corner",
|
||||
type=float,
|
||||
nargs=3,
|
||||
default=[0.0, 0.0, 0.0],
|
||||
help="Corner of the box (x, y, z).",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Read the snapshot
|
||||
print("Reading snapshot...")
|
||||
snap = read_snapshot(args.snapshot)
|
||||
|
||||
if args.N is None:
|
||||
N = snap.Np0
|
||||
else:
|
||||
N = args.N
|
||||
|
||||
print("Calculating density...")
|
||||
F=get_density_pm_snapshot(snap, N,N,N, args.corner[0],args.corner[1],args.corner[2])
|
||||
|
||||
print("Writing density...")
|
||||
F.write(args.output)
|
||||
print("Density written to", args.output)
|
||||
print("Done.")
|
Loading…
Add table
Reference in a new issue