Skip to content

pytipsy

Ben Keller edited this page Nov 10, 2021 · 1 revision

pytipsy

While pynbody is an excellent analysis tool, sometimes you want to access tipsy snapshots at a lower level, without a wrapper of units and additional functions that pynbody provides. For that, I've written pytipsy https://github.com/bwkeller/pytipsy, a simple bare-python+numpy set of tipsy utilities. pytipsy will let you interact with python dictionaries for dark, star, and gas particles, containing numpy arrays for each particle property.

rtipsy

pytipsy.rtipsy() is the reader function in pytipsy. It will automatically infer the endian-ness of the file passed to it and return 4 dictionaries: a header, gas particles, DM particles, and star particles:

from pytipsy import rtipsy
h,g,d,s = rtipsy("inputfile.std")

Each of these dictionaries will contain the information in the tipsy snapshot, as outlined in the tipsy format wiki page.

wtipsy

pytipsy.wtipsy() is the writer function in pytipsy. As you might expect, you feed it in a filename plus the 4 dictionaries that would be output by pytipsy.wtipsy(). For example, if you wanted to increase the temperature of all gas particles in a simulation, you would use the following snippet:

from pytipsy import rtipsy,wtipsy
h,g,d,s = rtipsy("inputfile.std")
g['tempg'] *= 10
wtipsy("hotter.std",h,g,d,s)

Be aware that this utility only reads tipsy files, not auxiliary outputs. If you want to work with those, use pynbody

starlog

pytipsy.starlog() reads the binary starlog file created by gasoline and ChaNGa, and outputs a dictionary containing a numpy array for each quantity stored there.

from pytipsy import starlog
slog = starlog("example.starlog")

bwk 10/11/2021

Clone this wiki locally