File: extract_fixed_resolution_data.py

package info (click to toggle)
yt 4.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,084 kB
  • sloc: python: 132,484; ansic: 5,628; cpp: 1,588; javascript: 352; makefile: 138; sh: 43; csh: 36
file content (35 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# For this example we will use h5py to write to our output file.
import h5py

import yt

ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")

level = 2
dims = ds.domain_dimensions * ds.refine_by**level

# We construct an object that describes the data region and structure we want
# In this case, we want all data up to the maximum "level" of refinement
# across the entire simulation volume.  Higher levels than this will not
# contribute to our covering grid.
cube = ds.covering_grid(
    level,
    left_edge=[0.0, 0.0, 0.0],
    dims=dims,
    # And any fields to preload (this is optional!)
    fields=[("gas", "density")],
)

# Now we open our output file using h5py
# Note that we open with 'w' (write), which will overwrite existing files!
f = h5py.File("my_data.h5", mode="w")

# We create a dataset at the root, calling it "density"
f.create_dataset("/density", data=cube["gas", "density"])

# We close our file
f.close()

# If we want to then access this datacube in the h5 file, we can now...
f = h5py.File("my_data.h5", mode="r")
print(f["density"][()])