Source

yt.workshop2012.frontends / scripts / stream_load.py

Full commit
from yt.mods import *
import h5py
import yt.frontends.stream.api as stream

center = na.array([0.5, 0.5, 0.5])

f = h5py.File("spec.h5")

class StreamFieldHandler(object):
    def __init__(self):
        self.cached = {}

    def __getitem__(self, key):
        if field != "Density": raise KeyError
        return f["/data"][:]

    @property
    def all_fields(self):
        return ("Density",)

sfh = StreamFieldHandler()

grid_left_edges = na.array([
  [0, 0, 0],
], dtype='int64')

grid_right_edges = na.array([
  [269, 269, 269],
], dtype='int64')

domain_dimensions = na.array([269, 269, 269])

domain_left_edge = na.zeros(3, 'float64')
domain_right_edge = na.ones(3, 'float64')    

grid_levels = na.array([0], dtype='int32').reshape((1,1))
grid_dimensions = grid_right_edges - grid_left_edges

grid_left_edges  = grid_left_edges.astype("float64")
grid_left_edges /= domain_dimensions*2**grid_levels
grid_left_edges *= domain_right_edge - domain_left_edge
grid_left_edges += domain_left_edge

grid_right_edges  = grid_right_edges.astype("float64")
grid_right_edges /= domain_dimensions*2**grid_levels
grid_right_edges *= domain_right_edge - domain_left_edge
grid_right_edges += domain_left_edge

handler = stream.StreamHandler(
    grid_left_edges,
    grid_right_edges,
    grid_dimensions,
    grid_levels,
    na.array([-1], dtype='int64'),
    na.zeros(1, dtype='int64').reshape((1,1)),
    na.zeros(1).reshape((1,1)),
    sfh,
)

handler.name = "simple_test"
handler.domain_left_edge = domain_left_edge
handler.domain_right_edge = domain_right_edge
handler.refine_by = 2
handler.dimensionality = 3
handler.domain_dimensions = domain_dimensions
handler.simulation_time = 0.0
handler.cosmology_simulation = 0

spf = stream.StreamStaticOutput(handler)
spf.units["cm"] = 1.0
spf.units["unitary"] = 1.0