54 lines
No EOL
1.3 KiB
Python
54 lines
No EOL
1.3 KiB
Python
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.") |