[Yt-svn] yt-commit r795 - in trunk/yt: lagos raven
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Sat Sep 20 04:12:32 PDT 2008
Author: mturk
Date: Sat Sep 20 04:12:31 2008
New Revision: 795
URL: http://yt.spacepope.org/changeset/795
Log:
Serialization now works with all the 2D datatypes.
You can call _serialize(node_name) with node_name being optional and you can
also feed in a node_name=True or node_name="some_name" to get the node on
startup.
Nice for cutting planes... The projection will continue to try to grab it
automatically, and the slices & cutting planes won't.
Modified:
trunk/yt/lagos/BaseDataTypes.py
trunk/yt/raven/PlotCollection.py
Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py (original)
+++ trunk/yt/lagos/BaseDataTypes.py Sat Sep 20 04:12:31 2008
@@ -390,7 +390,7 @@
return gf[na.where(grid.child_mask[sl])]
class Enzo2DData(EnzoData, GridPropertiesMixin):
- _key_fields = ['x','y','z','dx','dy','dz']
+ _key_fields = ['px','py','pdx','pdy']
"""
Class to represent a set of :class:`EnzoData` that's 2-D in nature, and
thus does not have as many actions as the 3-D data types.
@@ -404,6 +404,7 @@
self.axis = axis
EnzoData.__init__(self, pf, fields, **kwargs)
self.set_field_parameter("axis",axis)
+
#@time_execution
def get_data(self, fields = None):
@@ -472,6 +473,30 @@
zi = 10**(zi)
return [xi,yi,zi]
+ _okay_to_serialize = True
+ def _should_i_write(self): return True
+
+ def _serialize(self, node_name = None):
+ if not self._should_i_write(): return
+ mylog.info("Serializing data...")
+ if node_name is None: node_name = self._gen_node_name()
+ mylog.info("nodeName: %s", node_name)
+ array2d = na.array([self[i] for i in self._key_fields + [self.fields[0]]])
+ self.hierarchy.save_data(array2d, self._top_node, node_name)
+ mylog.info("Done serializing...")
+
+ def _deserialize(self, node_name = None):
+ if not self._okay_to_serialize: return
+ if node_name is None: node_name = self._gen_node_name()
+ mylog.debug("Trying to get node %s", node_name)
+ array=self.hierarchy.get_data(self._top_node, node_name)
+ if array == None:
+ mylog.debug("Didn't find it!")
+ return
+ for i, f in enumerate(self._key_fields + [self.fields[0]]):
+ self[f] = array[i,:]
+ return True
+
class EnzoSliceBase(Enzo2DData):
"""
EnzoSlice is an orthogonal slice through the data, taking all the points
@@ -480,8 +505,10 @@
however, as its field and coordinate can both change.
"""
+ _top_node = "/Slices"
#@time_execution
- def __init__(self, axis, coord, fields = None, center=None, pf=None, **kwargs):
+ def __init__(self, axis, coord, fields = None, center=None, pf=None,
+ node_name = False, **kwargs):
"""
Slice along *axis*:ref:`axis-specification`, at the coordinate *coord*.
Optionally supply fields.
@@ -489,7 +516,11 @@
Enzo2DData.__init__(self, axis, fields, pf, **kwargs)
self.center = center
self.coord = coord
- self._refresh_data()
+ if node_name is False:
+ self._refresh_data()
+ else:
+ if node_name is True: self._deserialize()
+ else: self._deserialize(node_name)
def reslice(self, coord):
"""
@@ -590,6 +621,9 @@
dataVals = dv.ravel()[grid.child_mask[sl].ravel() == 1]
return dataVals
+ def _gen_node_name(self):
+ return "%s_%s_%s" % (self.fields[0], self.axis, self.coord)
+
class EnzoCuttingPlaneBase(Enzo2DData):
"""
EnzoCuttingPlane is an oblique plane through the data,
@@ -598,7 +632,10 @@
the appropriate data onto the plane without interpolation.
"""
_plane = None
- def __init__(self, normal, center, fields = None, **kwargs):
+ _top_node = "/CuttingPlanes"
+ _key_fields = Enzo2DData._key_fields + ['pz','pdz']
+ def __init__(self, normal, center, fields = None, node_name = None,
+ **kwargs):
"""
The Cutting Plane slices at an oblique angle, where we use
the *normal* vector and the *center* to define the viewing plane.
@@ -624,7 +661,11 @@
self.set_field_parameter('cp_x_vec',self._x_vec)
self.set_field_parameter('cp_y_vec',self._y_vec)
self.set_field_parameter('cp_z_vec',self._norm_vec)
- self._refresh_data()
+ if node_name is False:
+ self._refresh_data()
+ else:
+ if node_name is True: self._deserialize()
+ else: self._deserialize(node_name)
def _get_list_of_grids(self):
# Recall that the projection of the distance vector from a point
@@ -706,18 +747,23 @@
if use_child_mask: k = (k & grid.child_mask)
return na.where(k)
+ def _gen_node_name(self):
+ cen_name = ("%s" % self.center).replace(" ","_")[1:-1]
+ L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1]
+ return "%s_c%s_L%s" % (self.fields[0], cen_name, L_name)
+
class EnzoProjBase(Enzo2DData, ParallelAnalysisInterface):
- _key_fields = ['px','py','pdx','pdy']
+ _top_node = "/Projections"
def __init__(self, axis, field, weight_field = None,
max_level = None, center = None, pf = None,
- source=None, **kwargs):
+ source=None, node_name = None, **kwargs):
"""
EnzoProj is a projection of a *field* along an *axis*. The field
can have an associated *weight_field*, in which case the values are
multiplied by a weight before being summed, and then divided by the sum
of that weight.
"""
- Enzo2DData.__init__(self, axis, field, pf, **kwargs)
+ Enzo2DData.__init__(self, axis, field, pf, node_name = None, **kwargs)
self.center = center
self._initialize_source()
self._grids = self.source._grids
@@ -733,7 +779,7 @@
self.__retval_coarse = {}
self.__overlap_masks = {}
self._temp = {}
- if not self._deserialize():
+ if not self._deserialize(node_name):
self.__calculate_overlap()
if self.hierarchy.data_style == 6 and False:
self.__cache_data()
@@ -785,31 +831,6 @@
pbar.finish()
mylog.info("Finished calculating overlap.")
- def _serialize(self):
- if not self._should_i_write(): return
- mylog.info("Serializing data...")
- node_name = "%s_%s_%s" % (self.fields[0], self._weight, self.axis)
- mylog.info("nodeName: %s", node_name)
- projArray = na.array([self['px'], self['py'],
- self['pdx'], self['pdy'], self[self.fields[0]]])
- self.hierarchy.save_data(projArray, "/Projections", node_name)
- mylog.info("Done serializing...")
-
- def _deserialize(self):
- if not self._okay_to_serialize: return
- node_name = "%s_%s_%s" % (self.fields[0], self._weight, self.axis)
- mylog.debug("Trying to get node %s", node_name)
- array=self.hierarchy.get_data("/Projections", node_name)
- if array == None:
- mylog.debug("Didn't find it!")
- return
- self['px'] = array[0,:]
- self['py'] = array[1,:]
- self['pdx'] = array[2,:]
- self['pdy']= array[3,:]
- self[self.fields[0]] = array[4,:]
- return True
-
def __get_dls(self, grid, fields):
# Place holder for a time when maybe we will not be doing just
# a single dx for every field.
@@ -1025,6 +1046,9 @@
if grid.id == 1: self._temp[grid.id] = d
return d
+ def _gen_node_name(self):
+ return "%s_%s_%s" % (self.fields[0], self._weight, self.axis)
+
class Enzo3DData(EnzoData, GridPropertiesMixin):
_key_fields = ['x','y','z','dx','dy','dz']
"""
Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py (original)
+++ trunk/yt/raven/PlotCollection.py Sat Sep 20 04:12:31 2008
@@ -158,7 +158,7 @@
def __add_slice(self, ptype, field, axis, coord=None, center=None,
use_colorbar=True, figure = None, axes = None, fig_size=None,
- periodic = False):
+ periodic = False, **kwargs):
"""
Generate a slice through *field* along *axis*, optionally at
[axis]=*coord*, with the *center* attribute given (some
@@ -171,7 +171,7 @@
center = self.c
if coord == None:
coord = center[axis]
- slice = self.pf.hierarchy.slice(axis, coord, field, center)
+ slice = self.pf.hierarchy.slice(axis, coord, field, center, **kwargs)
p = self._add_plot(ptype(slice, field, use_colorbar=use_colorbar,
axes=axes, figure=figure,
size=fig_size, periodic=periodic))
@@ -190,7 +190,8 @@
def add_cutting_plane(self, field, normal,
center=None, use_colorbar=True,
- figure = None, axes = None, fig_size=None, obj=None):
+ figure = None, axes = None, fig_size=None, obj=None,
+ **kwargs):
"""
Generate a cutting plane of *field* with *normal*, centered at *center*
(defaults to PlotCollection center) with *use_colorbar*
@@ -202,7 +203,7 @@
if center == None:
center = self.c
if not obj:
- cp = self.pf.hierarchy.cutting(normal, center, field)
+ cp = self.pf.hierarchy.cutting(normal, center, field, **kwargs)
else:
cp = obj
p = self._add_plot(PlotTypes.CuttingPlanePlot(cp, field,
@@ -216,7 +217,7 @@
def add_projection(self, field, axis, weight_field=None,
center=None, use_colorbar=True,
figure = None, axes = None, fig_size=None,
- periodic = False):
+ periodic = False, **kwargs):
"""
Generate a projection of *field* along *axis*, optionally giving
a *weight_field*-weighted average with *use_colorbar*
@@ -226,7 +227,8 @@
"""
if center == None:
center = self.c
- proj = self.pf.hierarchy.proj(axis, field, weight_field, center=center)
+ proj = self.pf.hierarchy.proj(axis, field, weight_field, center=center,
+ **kwargs)
p = self._add_plot(PlotTypes.ProjectionPlot(proj, field,
use_colorbar=use_colorbar, axes=axes, figure=figure,
size=fig_size, periodic=periodic))
More information about the yt-svn
mailing list