Path: blob/main/doc/source/cookbook/extract_fixed_resolution_data.py
928 views
# For this example we will use h5py to write to our output file.1import h5py23import yt45ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")67level = 28dims = ds.domain_dimensions * ds.refine_by**level910# We construct an object that describes the data region and structure we want11# In this case, we want all data up to the maximum "level" of refinement12# across the entire simulation volume. Higher levels than this will not13# contribute to our covering grid.14cube = ds.covering_grid(15level,16left_edge=[0.0, 0.0, 0.0],17dims=dims,18# And any fields to preload (this is optional!)19fields=[("gas", "density")],20)2122# Now we open our output file using h5py23# Note that we open with 'w' (write), which will overwrite existing files!24f = h5py.File("my_data.h5", mode="w")2526# We create a dataset at the root, calling it "density"27f.create_dataset("/density", data=cube["gas", "density"])2829# We close our file30f.close()3132# If we want to then access this datacube in the h5 file, we can now...33f = h5py.File("my_data.h5", mode="r")34print(f["density"][()])353637