Oftentimes you will want to export data from yt to plot in another plotting package, or to compare against another set of data elsewhere. (Although, note should be made that ever effort has been made to make yt into a publication-quality plotter.)
Data objects all have the write_out() method, which accepts a field list and a filename. This will dump to text.
However, if you have PyTables installed, you can also export things in a different way.
The following code snippet (cookbook_extract_data.py) will generate an HDF5 file with the “Density” array from our smoothed cube at the root node, and called “my_cube_density”. With PyTables you can nest these, set attributes, and access the data through any application that can read HDF5.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from yt.mods import *
import tables
pf = get_pf()
DIMS = 64
cube = pf.h.smoothed_covering_grid(2, left_edge=[0.25]*3,
right_edge=[0.75]*3,
dims=[DIMS]*3,
fields=["Density"])
f = tables.openFile("my_cube.h5","w")
f.createArray("/","my_cube_density", cube["Density"])
f.close()
|