Performing the same operation on a set of snapshots with snapshots_exec¶
Very often, it is useful to perform the same operation on a set of similar files, for example, the output snapshots of a simulation. pNbody offers a command to do so:
snapshots_exe
Just provide a set of files as well as a command to execute on the nb object, and it will to it:
snapshots_exec snapshots/* --exec "print(nb.nbody)"
This command is very useful to extract particles for a set of snapshots and store the sub-snapshots in a dedicated directory:
snapshots_exec snapshots/* --exec="nb = nb.select('stars')" -o snap
Scripts¶
snapshots_exec¶
usage: snapshots_exec [-h] [-o OUTPUT_DIRECTORY] [--do-not-skip-processed] [--exec EXEC]
[FILE ...]
Loop over a set of snapshot and apply the same command to each snapshot.
This command also allows to modify the snapshots or extract part of it and save it to another directory.
positional arguments:
FILE a list of snapshots
options:
-h, --help show this help message and exit
-o OUTPUT_DIRECTORY, --output_directory OUTPUT_DIRECTORY
output directory or output file
--do-not-skip-processed
force processing all files, even the ones already processed
--exec EXEC give command to execute before
Examples:
--------¨
single file
---------------
snapshots_exec snap.hdf5 --exec "print(nb.nbody)"
snapshots_exec snap.hdf5 --exec "nb.pos = nb.pos * 10" -o new_snap.hdf5
snapshots_exec snap.hdf5 --exec="nb = nb.select('stars')" -o new_snap.hdf5
snapshots_exec snap.hdf5 --exec="nb = nb.selecp(nb.num>1234)" -o new_snap.hdf5
snapshots_exec snap.hdf5 --exec="nb = nb.selecp(nb.num>1234)" --do-not-skip-processed -o new_snap.hdf5
multiple files
---------------
snapshots_exec snapshots/* --exec "print(nb.nbody)"
snapshots_exec snapshots/* --exec "nb.pos = nb.pos * 10" -o snap
snapshots_exec snapshots/* --exec="nb = nb.select('stars')" -o snap
snapshots_exec snapshots/* --exec="nb = nb.selecp(nb.num>1234)" -o snap
snapshots_exec snapshots/* --exec="nb = nb.selecp(nb.num>1234)" --do-not-skip-processed -o snap