[yt-svn] commit/yt: MatthewTurk: Adding a load_uniform_grid function, which accepts a dict of data and then sets
Bitbucket
commits-noreply at bitbucket.org
Wed Aug 8 10:11:25 PDT 2012
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/changeset/b6c9c207677c/
changeset: b6c9c207677c
branch: yt
user: MatthewTurk
date: 2012-08-08 19:10:16
summary: Adding a load_uniform_grid function, which accepts a dict of data and then sets
up a StreamHandler.
affected #: 2 files
diff -r 5c1e00f021b0fabb1261775853a79e75d08a8075 -r b6c9c207677cbbd6e1c36d51189634797e002c6d yt/frontends/stream/api.py
--- a/yt/frontends/stream/api.py
+++ b/yt/frontends/stream/api.py
@@ -28,7 +28,8 @@
StreamGrid, \
StreamHierarchy, \
StreamStaticOutput, \
- StreamHandler
+ StreamHandler, \
+ load_uniform_grid
from .fields import \
KnownStreamFields, \
diff -r 5c1e00f021b0fabb1261775853a79e75d08a8075 -r b6c9c207677cbbd6e1c36d51189634797e002c6d yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -40,6 +40,8 @@
FieldInfoContainer, NullFunc
from yt.utilities.lib import \
get_box_grids_level
+from yt.utilities.definitions import \
+ mpc_conversion, sec_conversion
from .fields import \
StreamFieldInfo, \
@@ -288,3 +290,89 @@
@classmethod
def _is_valid(cls, *args, **kwargs):
return False
+
+class StreamDictFieldHandler(dict):
+
+ @property
+ def all_fields(self): return self[0].keys()
+
+def load_uniform_grid(data, domain_dimensions, domain_size_in_cm):
+ r"""Load a uniform grid of data into yt as a
+ :class:`~yt.frontends.stream.data_structures.StreamHandler`.
+
+ This should allow a uniform grid of data to be loaded directly into yt and
+ analyzed as would any others. This comes with several caveats:
+ * Units will be incorrect unless the data has already been converted to
+ cgs.
+ * Some functions may behave oddly, and parallelism will be
+ disappointing or non-existent in most cases.
+ * Particles may be difficult to integrate.
+
+ Parameters
+ ----------
+ data : dict
+ This is a dict of numpy arrays, where the keys are the field names.
+ domain_dimensiosn : array_like
+ This is the domain dimensions of the grid
+ domain_size_in_cm : float
+ The size of the domain, in centimeters
+
+ Examples
+ --------
+
+ >>> arr = na.random.random((256, 256, 256))
+ >>> data = dict(Density = arr)
+ >>> pf = load_uniform_grid(data, [256, 256, 256], 3.08e24)
+ """
+ sfh = StreamDictFieldHandler()
+ sfh.update({0:data})
+ domain_dimensions = na.array(domain_dimensions)
+ if na.unique(domain_dimensions).size != 1:
+ print "We don't support variably sized domains yet."
+ raise RuntimeError
+ domain_left_edge = na.zeros(3, 'float64')
+ domain_right_edge = na.ones(3, 'float64')
+ grid_left_edges = na.zeros(3, "int64").reshape((1,3))
+ grid_right_edges = na.array(domain_dimensions, "int64").reshape((1,3))
+
+ 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 = 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 = "UniformGridData"
+ 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 = StreamStaticOutput(handler)
+ spf.units["cm"] = domain_size_in_cm
+ spf.units['1'] = 1.0
+ spf.units["unitary"] = 1.0
+ box_in_mpc = domain_size_in_cm / mpc_conversion['cm']
+ for unit in mpc_conversion.keys():
+ spf.units[unit] = mpc_conversion[unit] * box_in_mpc
+ return spf
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list