[Yt-svn] yt-commit r927 - in trunk/yt: lagos raven
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Wed Nov 12 17:22:29 PST 2008
Author: mturk
Date: Wed Nov 12 17:22:28 2008
New Revision: 927
URL: http://yt.spacepope.org/changeset/927
Log:
Part one of the merge from yt-generalization.
Changed all data type names from "Enzo[something]" to "AMR[something]". (Old
names are still there, but I will be adding deprecation warnings to them.)
This should have NO IMPACT on anyone.
Changed projections to have an explicit used-map, rather than relying on
setting position to -1. This should have no impact on anyone.
Added some changes to use DomainRightEdge and DominaLeftEdge instead of 1.0 and
0.0 respectively.
Re-arranged methods and split Grid into AMRGridPatch and EnzoGridBase.
Added first draft of parallel_simple_proxy decorator.
Pulled in Jeff's CoordAxesCallback.
Changed a '1' to 'unitary'. There are probably more of these elsewhere.
Modified:
trunk/yt/lagos/BaseDataTypes.py
trunk/yt/lagos/BaseGridType.py
trunk/yt/lagos/ContourFinder.py
trunk/yt/lagos/HierarchyType.py
trunk/yt/lagos/ParallelTools.py
trunk/yt/lagos/PointCombine.c
trunk/yt/raven/Callbacks.py
trunk/yt/raven/PlotTypes.py
Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py (original)
+++ trunk/yt/lagos/BaseDataTypes.py Wed Nov 12 17:22:28 2008
@@ -72,7 +72,7 @@
class FakeGridForParticles(object):
"""
Mock up a grid to insert particle positions and radii
- into for purposes of confinement in an :class:`Enzo3DData`.
+ into for purposes of confinement in an :class:`AMR3DData`.
"""
def __init__(self, grid):
self._corners = grid._corners
@@ -97,9 +97,9 @@
else: tr = self.data[field]
return tr
-class EnzoData:
+class AMRData:
"""
- Generic EnzoData container. By itself, will attempt to
+ Generic AMRData container. By itself, will attempt to
generate field, read fields (method defined by derived classes)
and deal with passing back and forth field parameters.
"""
@@ -109,7 +109,7 @@
def __init__(self, pf, fields, **kwargs):
"""
Typically this is never called directly, but only due to inheritance.
- It associates a :class:`~yt.lagos.EnzoStaticOutput` with the class,
+ It associates a :class:`~yt.lagos.StaticOutput` with the class,
sets its initial set of fields, and the remainder of the arguments
are passed as field_parameters.
"""
@@ -162,7 +162,7 @@
def clear_data(self):
"""
- Clears out all data from the EnzoData instance, freeing memory.
+ Clears out all data from the AMRData instance, freeing memory.
"""
for key in self.data.keys():
del self.data[key]
@@ -307,10 +307,10 @@
__del_gridLevels)
-class Enzo1DData(EnzoData, GridPropertiesMixin):
+class AMR1DData(AMRData, GridPropertiesMixin):
_spatial = False
def __init__(self, pf, fields, **kwargs):
- EnzoData.__init__(self, pf, fields, **kwargs)
+ AMRData.__init__(self, pf, fields, **kwargs)
self._grids = None
def _generate_field_in_grids(self, field, num_ghost_zones=0):
@@ -354,14 +354,14 @@
[self._get_data_from_grid(grid, field)
for grid in self._grids])
-class EnzoOrthoRayBase(Enzo1DData):
+class AMROrthoRayBase(AMR1DData):
_key_fields = ['x','y','z','dx','dy','dz']
def __init__(self, axis, coords, fields=None, pf=None, **kwargs):
"""
Dimensionality is reduced to one, and an ordered list of points at an
(x,y) tuple along *axis* are available.
"""
- Enzo1DData.__init__(self, pf, fields, **kwargs)
+ AMR1DData.__init__(self, pf, fields, **kwargs)
self.axis = axis
self.px_ax = x_dict[self.axis]
self.py_ax = y_dict[self.axis]
@@ -399,14 +399,14 @@
gf = grid[field][sl]
return gf[na.where(grid.child_mask[sl])]
-class EnzoRayBase(Enzo1DData):
+class AMRRayBase(AMR1DData):
def __init__(self, start_point, end_point, fields=None, pf=None, **kwargs):
"""
We accept a start point and an end point and then get all the data
between those two.
"""
mylog.warning("This code is poorly tested. It may give bad data!")
- Enzo1DData.__init__(self, pf, fields, **kwargs)
+ AMR1DData.__init__(self, pf, fields, **kwargs)
self.start_point = na.array(start_point)
self.end_point = na.array(end_point)
self.vec = self.end_point - self.start_point
@@ -455,20 +455,20 @@
self.center, self.vec)
return mask
-class Enzo2DData(EnzoData, GridPropertiesMixin):
+class AMR2DData(AMRData, GridPropertiesMixin):
_key_fields = ['px','py','pdx','pdy']
"""
- Class to represent a set of :class:`EnzoData` that's 2-D in nature, and
+ Class to represent a set of :class:`AMRData` that's 2-D in nature, and
thus does not have as many actions as the 3-D data types.
"""
_spatial = False
def __init__(self, axis, fields, pf=None, **kwargs):
"""
- Prepares the Enzo2DData, normal to *axis*. If *axis* is 4, we are not
+ Prepares the AMR2DData, normal to *axis*. If *axis* is 4, we are not
aligned with any axis.
"""
self.axis = axis
- EnzoData.__init__(self, pf, fields, **kwargs)
+ AMRData.__init__(self, pf, fields, **kwargs)
self.set_field_parameter("axis",axis)
@@ -569,9 +569,9 @@
self[f] = array[i,:]
return True
-class EnzoSliceBase(Enzo2DData):
+class AMRSliceBase(AMR2DData):
"""
- EnzoSlice is an orthogonal slice through the data, taking all the points
+ AMRSlice is an orthogonal slice through the data, taking all the points
at the finest resolution available and then indexing them. It is more
appropriately thought of as a slice 'operator' than an object,
however, as its field and coordinate can both change.
@@ -585,7 +585,7 @@
Slice along *axis*:ref:`axis-specification`, at the coordinate *coord*.
Optionally supply fields.
"""
- Enzo2DData.__init__(self, axis, fields, pf, **kwargs)
+ AMR2DData.__init__(self, axis, fields, pf, **kwargs)
self.center = center
self.coord = coord
if node_name is False:
@@ -696,16 +696,16 @@
def _gen_node_name(self):
return "%s_%s_%s" % (self.fields[0], self.axis, self.coord)
-class EnzoCuttingPlaneBase(Enzo2DData):
+class AMRCuttingPlaneBase(AMR2DData):
"""
- EnzoCuttingPlane is an oblique plane through the data,
+ AMRCuttingPlane is an oblique plane through the data,
defined by a normal vector and a coordinate. It attempts to guess
an 'up' vector, which cannot be overridden, and then it pixelizes
the appropriate data onto the plane without interpolation.
"""
_plane = None
_top_node = "/CuttingPlanes"
- _key_fields = Enzo2DData._key_fields + ['pz','pdz']
+ _key_fields = AMR2DData._key_fields + ['pz','pdz']
def __init__(self, normal, center, fields = None, node_name = None,
**kwargs):
"""
@@ -713,7 +713,7 @@
the *normal* vector and the *center* to define the viewing plane.
The 'up' direction is guessed at automatically.
"""
- Enzo2DData.__init__(self, 4, fields, **kwargs)
+ AMR2DData.__init__(self, 4, fields, **kwargs)
self.center = center
self.set_field_parameter('center',center)
# Let's set up our plane equation
@@ -824,19 +824,19 @@
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):
+class AMRProjBase(AMR2DData, ParallelAnalysisInterface):
_top_node = "/Projections"
- _key_fields = Enzo2DData._key_fields + ['weight_field']
+ _key_fields = AMR2DData._key_fields + ['weight_field']
def __init__(self, axis, field, weight_field = None,
max_level = None, center = None, pf = None,
source=None, node_name = None, field_cuts = None, **kwargs):
"""
- EnzoProj is a projection of a *field* along an *axis*. The field
+ AMRProj 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, node_name = None, **kwargs)
+ AMR2DData.__init__(self, axis, field, pf, node_name = None, **kwargs)
if field_cuts is not None:
field_cuts = ['grid%s' % cut for cut in ensure_list(field_cuts)]
self._field_cuts = field_cuts
@@ -992,8 +992,9 @@
args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]]
args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]]
args.append(1) # Refinement factor
+ args.append(na.ones(args[0].shape, dtype='int64'))
kk = PointCombine.CombineGrids(*args)
- goodI = na.where(self.__retval_coords[grid2.id][0] > -1)
+ goodI = args[-1].astype('bool')
self.__retval_coords[grid2.id] = \
[coords[goodI] for coords in self.__retval_coords[grid2.id]]
self.__retval_fields[grid2.id] = \
@@ -1007,18 +1008,20 @@
% (level, self._max_level), len(grids))
for pi, grid1 in enumerate(grids):
pbar.update(pi)
- for grid2 in self.source._grids[grids_up][self.__overlap_masks[grid1.Parent.id]]:
- if self.__retval_coords[grid2.id][0].shape[0] == 0: continue
- args = []
- args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]]
- args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]]
- args.append(int(grid2.dx / grid1.dx))
- kk = PointCombine.CombineGrids(*args)
- goodI = (self.__retval_coords[grid2.id][0] > -1)
- self.__retval_coords[grid2.id] = \
- [coords[goodI] for coords in self.__retval_coords[grid2.id]]
- self.__retval_fields[grid2.id] = \
- [fields[goodI] for fields in self.__retval_fields[grid2.id]]
+ for parent in ensure_list(grid1.Parent):
+ for grid2 in self.source._grids[grids_up][self.__overlap_masks[parent.id]]:
+ if self.__retval_coords[grid2.id][0].shape[0] == 0: continue
+ args = []
+ args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]]
+ args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]]
+ args.append(int(grid2.dx / grid1.dx))
+ args.append(na.ones(args[0].shape, dtype='int64'))
+ kk = PointCombine.CombineGrids(*args)
+ goodI = args[-1].astype('bool')
+ self.__retval_coords[grid2.id] = \
+ [coords[goodI] for coords in self.__retval_coords[grid2.id]]
+ self.__retval_fields[grid2.id] = \
+ [fields[goodI] for fields in self.__retval_fields[grid2.id]]
for grid1 in self.source.select_grids(level-1):
if not self._check_region and self.__retval_coords[grid1.id][0].size != 0:
mylog.error("Something messed up, and %s still has %s points of data",
@@ -1134,7 +1137,7 @@
def _gen_node_name(self):
return "%s_%s_%s" % (self.fields[0], self._weight, self.axis)
-class Enzo3DData(EnzoData, GridPropertiesMixin):
+class AMR3DData(AMRData, GridPropertiesMixin):
_key_fields = ['x','y','z','dx','dy','dz']
"""
Class describing a cluster of data points, not necessarily sharing any
@@ -1144,11 +1147,11 @@
_num_ghost_zones = 0
def __init__(self, center, fields, pf = None, **kwargs):
"""
- Returns an instance of Enzo3DData, or prepares one. Usually only
+ Returns an instance of AMR3DData, or prepares one. Usually only
used as a base class. Note that *center* is supplied, but only used
for fields and quantities that require it.
"""
- EnzoData.__init__(self, pf, fields, **kwargs)
+ AMRData.__init__(self, pf, fields, **kwargs)
self.center = center
self.set_field_parameter("center",center)
self.coords = None
@@ -1335,14 +1338,14 @@
grid[field][self._get_point_indices()] = value
-class ExtractedRegionBase(Enzo3DData):
+class ExtractedRegionBase(AMR3DData):
"""
ExtractedRegions are arbitrarily defined containers of data, useful
for things like selection along a baryon field.
"""
def __init__(self, base_region, indices, **kwargs):
cen = base_region.get_field_parameter("center")
- Enzo3DData.__init__(self, center=cen,
+ AMR3DData.__init__(self, center=cen,
fields=None, pf=base_region.pf, **kwargs)
self._base_region = base_region # We don't weakly reference because
# It is not cyclic
@@ -1389,7 +1392,7 @@
# Yeah, if it's not true, we don't care.
return self._indices[grid.id-1]
-class EnzoCylinderBase(Enzo3DData):
+class AMRCylinderBase(AMR3DData):
"""
We can define a cylinder (or disk) to act as a data object.
"""
@@ -1400,7 +1403,7 @@
can define a cylinder of any proportion. Only cells whose centers are
within the cylinder will be selected.
"""
- Enzo3DData.__init__(self, na.array(center), fields, pf, **kwargs)
+ AMR3DData.__init__(self, na.array(center), fields, pf, **kwargs)
self._norm_vec = na.array(normal)/na.sqrt(na.dot(normal,normal))
self.set_field_parameter("height_vector", self._norm_vec)
self._height = height
@@ -1450,9 +1453,9 @@
& (r < self._radius))
return cm
-class EnzoRegionBase(Enzo3DData):
+class AMRRegionBase(AMR3DData):
"""
- EnzoRegions are rectangular prisms of data.
+ AMRRegions are rectangular prisms of data.
"""
def __init__(self, center, left_edge, right_edge, fields = None,
pf = None, **kwargs):
@@ -1461,7 +1464,7 @@
three *right_edge* coordinates, and a *center* that need not be the
center.
"""
- Enzo3DData.__init__(self, center, fields, pf, **kwargs)
+ AMR3DData.__init__(self, center, fields, pf, **kwargs)
self.left_edge = left_edge
self.right_edge = right_edge
self._refresh_data()
@@ -1487,9 +1490,9 @@
& (grid['z'] + 0.5*grid['dz'] >= self.left_edge[2]) )
return cm
-class EnzoPeriodicRegionBase(Enzo3DData):
+class AMRPeriodicRegionBase(AMR3DData):
"""
- EnzoRegions are rectangular prisms of data.
+ AMRRegions are rectangular prisms of data.
"""
def __init__(self, center, left_edge, right_edge, fields = None,
pf = None, **kwargs):
@@ -1498,7 +1501,7 @@
three *right_edge* coordinates, and a *center* that need not be the
center.
"""
- Enzo3DData.__init__(self, center, fields, pf, **kwargs)
+ AMR3DData.__init__(self, center, fields, pf, **kwargs)
self.left_edge = na.array(left_edge)
self.right_edge = na.array(right_edge)
self._refresh_data()
@@ -1539,7 +1542,7 @@
& (grid['z'] + grid['dz'] + off_z >= self.left_edge[2]) )
return cm
-class EnzoGridCollection(Enzo3DData):
+class AMRGridCollection(AMR3DData):
"""
An arbitrary selection of grids, within which we accept all points.
"""
@@ -1549,7 +1552,7 @@
By selecting an arbitrary *grid_list*, we can act on those grids.
Child cells are not returned.
"""
- Enzo3DData.__init__(self, center, fields, pf, **kwargs)
+ AMR3DData.__init__(self, center, fields, pf, **kwargs)
self._grids = na.array(grid_list)
self.fields = fields
self.connection_pool = True
@@ -1571,7 +1574,7 @@
pointI = na.where(k == True)
return pointI
-class EnzoSphereBase(Enzo3DData):
+class AMRSphereBase(AMR3DData):
"""
A sphere of points
"""
@@ -1580,7 +1583,7 @@
The most famous of all the data objects, we define it via a
*center* and a *radius*.
"""
- Enzo3DData.__init__(self, center, fields, pf, **kwargs)
+ AMR3DData.__init__(self, center, fields, pf, **kwargs)
if radius < self.hierarchy.get_smallest_dx():
raise SyntaxError("Your radius is smaller than your finest cell!")
self.set_field_parameter('radius',radius)
@@ -1612,7 +1615,7 @@
self._cut_masks[grid.id] = cm
return cm
-class EnzoCoveringGrid(Enzo3DData):
+class AMRCoveringGrid(AMR3DData):
"""
Covering grids represent fixed-resolution data over a given region.
In order to achieve this goal -- for instance in order to obtain ghost
@@ -1628,7 +1631,7 @@
generating fixed resolution data between *left_edge* and *right_edge*
that is *dims* (3-values) on a side.
"""
- Enzo3DData.__init__(self, center=None, fields=fields, pf=pf, **kwargs)
+ AMR3DData.__init__(self, center=None, fields=fields, pf=pf, **kwargs)
self.left_edge = na.array(left_edge)
self.right_edge = na.array(right_edge)
self.level = level
@@ -1647,6 +1650,7 @@
na.any(self.right_edge > self.pf["DomainRightEdge"]):
grids,ind = self.pf.hierarchy.get_periodic_box_grids(
self.left_edge, self.right_edge)
+ ind = slice(None)
else:
grids,ind = self.pf.hierarchy.get_box_grids(
self.left_edge, self.right_edge)
@@ -1658,7 +1662,7 @@
mylog.error("Sorry, dude, do it yourself, it's already in 3-D.")
def _refresh_data(self):
- Enzo3DData._refresh_data(self)
+ AMR3DData._refresh_data(self)
self['dx'] = self.dx * na.ones(self.ActiveDimensions, dtype='float64')
self['dy'] = self.dy * na.ones(self.ActiveDimensions, dtype='float64')
self['dz'] = self.dz * na.ones(self.ActiveDimensions, dtype='float64')
@@ -1734,24 +1738,30 @@
self.left_edge, self.right_edge, c_dx, c_fields,
ll, self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"])
-class EnzoSmoothedCoveringGrid(EnzoCoveringGrid):
+class AMRSmoothedCoveringGrid(AMRCoveringGrid):
def __init__(self, *args, **kwargs):
dlog2 = na.log10(kwargs['dims'])/na.log10(2)
if not na.all(na.floor(dlog2) == na.ceil(dlog2)):
mylog.warning("Must be power of two dimensions")
#raise ValueError
kwargs['num_ghost_zones'] = 0
- EnzoCoveringGrid.__init__(self, *args, **kwargs)
- if na.any(self.left_edge == 0):
+ AMRCoveringGrid.__init__(self, *args, **kwargs)
+ if na.any(self.left_edge == self.pf["DomainLeftEdge"]):
self.left_edge += self.dx
self.ActiveDimensions -= 1
- if na.any(self.right_edge == 0):
+ if na.any(self.right_edge == self.pf["DomainRightEdge"]):
self.right_edge -= self.dx
self.ActiveDimensions -= 1
def _get_list_of_grids(self):
- grids, ind = self.pf.hierarchy.get_box_grids(self.left_edge-self.dx,
- self.right_edge+self.dx)
+ if na.any(self.left_edge - self.dx < self.pf["DomainLeftEdge"]) or \
+ na.any(self.right_edge + self.dx > self.pf["DomainRightEdge"]):
+ grids,ind = self.pf.hierarchy.get_periodic_box_grids(
+ self.left_edge - self.dx, self.right_edge + self.dx)
+ ind = slice(None)
+ else:
+ grids,ind = self.pf.hierarchy.get_box_grids(
+ self.left_edge - self.dx, self.right_edge + self.dx)
level_ind = na.where(self.pf.hierarchy.gridLevels.ravel()[ind] <= self.level)
sort_ind = na.argsort(self.pf.h.gridLevels.ravel()[ind][level_ind])
self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)]
@@ -1834,3 +1844,18 @@
def flush_data(self, *args, **kwargs):
raise KeyError("Can't do this")
+
+
+class EnzoOrthoRayBase(AMROrthoRayBase): pass
+class EnzoRayBase(AMRRayBase): pass
+class EnzoSliceBase(AMRSliceBase): pass
+class EnzoCuttingPlaneBase(AMRCuttingPlaneBase): pass
+class EnzoProjBase(AMRProjBase): pass
+class EnzoCylinderBase(AMRCylinderBase): pass
+class EnzoRegionBase(AMRRegionBase): pass
+class EnzoPeriodicRegionBase(AMRPeriodicRegionBase): pass
+class EnzoGridCollection(AMRGridCollection): pass
+class EnzoSphereBase(AMRSphereBase): pass
+class EnzoCoveringGrid(AMRCoveringGrid): pass
+class EnzoSmoothedCoveringGrid(AMRSmoothedCoveringGrid): pass
+
Modified: trunk/yt/lagos/BaseGridType.py
==============================================================================
--- trunk/yt/lagos/BaseGridType.py (original)
+++ trunk/yt/lagos/BaseGridType.py Wed Nov 12 17:22:28 2008
@@ -27,22 +27,13 @@
#import yt.enki, gc
from yt.funcs import *
-class EnzoGridBase(EnzoData):
+class AMRGridPatch(AMRData):
_spatial = True
_num_ghost_zones = 0
- """
- Class representing a single Enzo Grid instance.
- """
_grids = None
+ _id_offset = 1
def __init__(self, id, filename=None, hierarchy = None):
- """
- Returns an instance of EnzoGrid with *id*, associated with
- *filename* and *hierarchy*.
- """
- #EnzoData's init function is a time-burglar.
- #All of the field parameters will be passed to us as needed.
- #EnzoData.__init__(self, None, [])
self.data = {}
self.field_parameters = {}
self.fields = []
@@ -52,29 +43,8 @@
if filename: self.set_filename(filename)
self.overlap_masks = [None, None, None]
self._overlap_grids = [None, None, None]
- self._file_access_pooling = False
-
- def __len__(self):
- return na.prod(self.ActiveDimensions)
-
- def _generate_field(self, field):
- if fieldInfo.has_key(field):
- # First we check the validator
- try:
- fieldInfo[field].check_available(self)
- except NeedsGridType, ngt_exception:
- # This is only going to be raised if n_gz > 0
- n_gz = ngt_exception.ghost_zones
- f_gz = ngt_exception.fields
- gz_grid = self.retrieve_ghost_zones(n_gz, f_gz)
- temp_array = fieldInfo[field](gz_grid)
- sl = [slice(n_gz,-n_gz)] * 3
- self[field] = temp_array[sl]
- else:
- self[field] = fieldInfo[field](self)
- else: # Can't find the field, try as it might
- raise exceptions.KeyError, field
-
+ self.pf = self.hierarchy.parameter_file # weakref already
+
def get_data(self, field):
"""
Returns a field or set of fields for a key or set of keys
@@ -101,111 +71,35 @@
self._generate_field(field)
return self.data[field]
- def clear_all_grid_references(self):
- """
- This clears out all references this grid has to any others, as
- well as the hierarchy. It's like extra-cleaning after clear_data.
- """
- self.clear_all_derived_quantities()
- if hasattr(self, 'hierarchy'):
- del self.hierarchy
- if hasattr(self, 'Parent'):
- if self.Parent != None:
- self.Parent.clear_all_grid_references()
- del self.Parent
- if hasattr(self, 'Children'):
- for i in self.Children:
- if i != None:
- del i
- del self.Children
-
- def _prepare_grid(self):
- """
- Copies all the appropriate attributes from the hierarchy
- """
- # This is definitely the slowest part of generating the hierarchy
- # Now we give it pointers to all of its attributes
- # Note that to keep in line with Enzo, we have broken PEP-8
- h = self.hierarchy # cache it
- self.Dimensions = h.gridDimensions[self.id-1]
- self.StartIndices = h.gridStartIndices[self.id-1]
- self.EndIndices = h.gridEndIndices[self.id-1]
- self.LeftEdge = h.gridLeftEdge[self.id-1]
- self.RightEdge = h.gridRightEdge[self.id-1]
- self.Level = h.gridLevels[self.id-1,0]
- self.Time = h.gridTimes[self.id-1,0]
- self.NumberOfParticles = h.gridNumberOfParticles[self.id-1,0]
- self.ActiveDimensions = (self.EndIndices - self.StartIndices + 1)
- self.Children = h.gridTree[self.id-1]
- pID = h.gridReverseTree[self.id-1]
- if pID != None and pID != -1:
- self.Parent = weakref.proxy(h.grids[pID - 1])
- else:
- self.Parent = None
+ def _generate_field(self, field):
+ if fieldInfo.has_key(field):
+ # First we check the validator
+ try:
+ fieldInfo[field].check_available(self)
+ except NeedsGridType, ngt_exception:
+ # This is only going to be raised if n_gz > 0
+ n_gz = ngt_exception.ghost_zones
+ f_gz = ngt_exception.fields
+ gz_grid = self.retrieve_ghost_zones(n_gz, f_gz)
+ temp_array = fieldInfo[field](gz_grid)
+ sl = [slice(n_gz,-n_gz)] * 3
+ self[field] = temp_array[sl]
+ else:
+ self[field] = fieldInfo[field](self)
+ else: # Can't find the field, try as it might
+ raise exceptions.KeyError, field
def _setup_dx(self):
# So first we figure out what the index is. We don't assume
# that dx=dy=dz , at least here. We probably do elsewhere.
- self.dx = self.hierarchy.gridDxs[self.id-1,0]
- self.dy = self.hierarchy.gridDys[self.id-1,0]
- self.dz = self.hierarchy.gridDzs[self.id-1,0]
+ id = self.id - self._id_offset
+ self.dx = self.hierarchy.gridDxs[id,0]
+ self.dy = self.hierarchy.gridDys[id,0]
+ self.dz = self.hierarchy.gridDzs[id,0]
self.data['dx'] = self.dx
self.data['dy'] = self.dy
self.data['dz'] = self.dz
- self._corners = self.hierarchy.gridCorners[:,:,self.id-1]
-
- def _guess_properties_from_parent(self):
- """
- We know that our grid boundary occurs on the cell boundary of our
- parent. This can be a very expensive process, but it is necessary
- in some hierarchys, where yt is unable to generate a completely
- space-filling tiling of grids, possibly due to the finite accuracy in a
- standard Enzo hierarchy file.
- """
- le = self.LeftEdge
- self.dx = self.Parent.dx/2.0
- self.dy = self.Parent.dy/2.0
- self.dz = self.Parent.dz/2.0
- ParentLeftIndex = na.rint((self.LeftEdge-self.Parent.LeftEdge)/self.Parent.dx)
- self.start_index = 2*(ParentLeftIndex + self.Parent.get_global_startindex()).astype('int64')
- self.LeftEdge = self.Parent.LeftEdge + self.Parent.dx * ParentLeftIndex
- self.RightEdge = self.LeftEdge + \
- self.ActiveDimensions*na.array([self.dx,self.dy,self.dz])
- self.hierarchy.gridDxs[self.id-1,0] = self.dx
- self.hierarchy.gridDys[self.id-1,0] = self.dy
- self.hierarchy.gridDzs[self.id-1,0] = self.dz
- self.hierarchy.gridLeftEdge[self.id-1,:] = self.LeftEdge
- self.hierarchy.gridRightEdge[self.id-1,:] = self.RightEdge
- self.hierarchy.gridCorners[:,:,self.id-1] = na.array([ # Unroll!
- [self.LeftEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.RightEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.RightEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.RightEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.LeftEdge[1], self.RightEdge[2]],
- [self.RightEdge[0], self.LeftEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.RightEdge[1], self.LeftEdge[2]],
- ], dtype='float64')
- self.__child_mask = None
- self.__child_index_mask = None
- self.__child_indices = None
- self._setup_dx()
-
- def get_global_startindex(self):
- """
- Return the integer starting index for each dimension at the current
- level.
- """
- if self.start_index != None:
- return self.start_index
- if self.Parent == None:
- start_index = self.LeftEdge / na.array([self.dx, self.dy, self.dz])
- return na.rint(start_index).astype('int64').ravel()
- pdx = na.array([self.Parent.dx, self.Parent.dy, self.Parent.dz]).ravel()
- start_index = (self.Parent.get_global_startindex()) + \
- na.rint((self.LeftEdge - self.Parent.LeftEdge)/pdx)
- self.start_index = (start_index*2).astype('int64').ravel()
- return self.start_index
+ self._corners = self.hierarchy.gridCorners[:,:,id]
def _generate_overlap_masks(self, axis, LE, RE):
"""
@@ -227,6 +121,24 @@
def __int__(self):
return self.id
+ def clear_all_grid_references(self):
+ """
+ This clears out all references this grid has to any others, as
+ well as the hierarchy. It's like extra-cleaning after clear_data.
+ """
+ self.clear_all_derived_quantities()
+ if hasattr(self, 'hierarchy'):
+ del self.hierarchy
+ if hasattr(self, 'Parent'):
+ if self.Parent != None:
+ self.Parent.clear_all_grid_references()
+ del self.Parent
+ if hasattr(self, 'Children'):
+ for i in self.Children:
+ if i != None:
+ del i
+ del self.Children
+
def clear_data(self):
"""
Clear out the following things: child_mask, child_indices,
@@ -238,21 +150,35 @@
del self.coarseData
if hasattr(self, 'retVal'):
del self.retVal
- EnzoData.clear_data(self)
+ AMRData.clear_data(self)
self._setup_dx()
- def set_filename(self, filename):
+ def _prepare_grid(self):
"""
- Intelligently set the filename.
+ Copies all the appropriate attributes from the hierarchy
"""
- if self.hierarchy._strip_path:
- self.filename = os.path.join(self.hierarchy.directory,
- os.path.basename(filename))
- elif filename[0] == os.path.sep:
- self.filename = filename
+ # This is definitely the slowest part of generating the hierarchy
+ # Now we give it pointers to all of its attributes
+ # Note that to keep in line with Enzo, we have broken PEP-8
+ h = self.hierarchy # cache it
+ self.Dimensions = h.gridDimensions[self.id-1]
+ self.StartIndices = h.gridStartIndices[self.id-1]
+ self.EndIndices = h.gridEndIndices[self.id-1]
+ self.LeftEdge = h.gridLeftEdge[self.id-1]
+ self.RightEdge = h.gridRightEdge[self.id-1]
+ self.Level = h.gridLevels[self.id-1,0]
+ self.Time = h.gridTimes[self.id-1,0]
+ self.NumberOfParticles = h.gridNumberOfParticles[self.id-1,0]
+ self.ActiveDimensions = (self.EndIndices - self.StartIndices + 1)
+ self.Children = h.gridTree[self.id-1]
+ pID = h.gridReverseTree[self.id-1]
+ if pID != None and pID != -1:
+ self.Parent = weakref.proxy(h.grids[pID - 1])
else:
- self.filename = os.path.join(self.hierarchy.directory, filename)
- return
+ self.Parent = None
+
+ def __len__(self):
+ return na.prod(self.ActiveDimensions)
def find_max(self, field):
"""
@@ -300,28 +226,6 @@
del self.child_mask
del self.child_ind
- def __get_enzo_grid(self):
- """
- **DO NOT USE**
-
- This attempts to get an instance of this particular grid from the SWIG
- interface. Note that it first checks to see if the ParameterFile has
- been instantiated.
- """
- if self.hierarchy.eiTopGrid == None:
- self.hierarchy.initializeEnzoInterface()
- p=re.compile("Grid = %s\n" % (self.id))
- h=open(self.hierarchyFilename,"r").read()
- m=re.search(p,h)
- h=open(self.hierarchyFilename,"r")
- retVal = yt.enki.EnzoInterface.fseek(h, long(m.end()), 0)
- self.eiGrid=yt.enki.EnzoInterface.grid()
- cwd = os.getcwd() # Hate doing this, need to for relative pathnames
- os.chdir(self.hierarchy.directory)
- self.eiGrid.ReadGrid(h, 1)
- os.chdir(cwd)
- mylog.debug("Grid read with SWIG")
-
def _set_child_mask(self, newCM):
if self.__child_mask != None:
mylog.warning("Overriding child_mask attribute! This is probably unwise!")
@@ -369,6 +273,16 @@
self.__child_index_mask = None
#@time_execution
+ def __fill_child_mask(self, child, mask, tofill):
+ startIndex = na.maximum(0, na.rint((child.LeftEdge - self.LeftEdge)/self.dx))
+ endIndex = na.minimum(na.rint((child.RightEdge - self.LeftEdge)/self.dx),
+ self.ActiveDimensions)
+ #startIndex + self.ActiveDimensions)
+ startIndex = na.maximum(0, startIndex)
+ mask[startIndex[0]:endIndex[0],
+ startIndex[1]:endIndex[1],
+ startIndex[2]:endIndex[2]] = tofill
+
def __generate_child_mask(self):
"""
Generates self.child_mask, which is zero where child grids exist (and
@@ -376,12 +290,7 @@
"""
self.__child_mask = na.ones(self.ActiveDimensions, 'int32')
for child in self.Children:
- # Now let's get our overlap
- startIndex = na.rint((child.LeftEdge - self.LeftEdge)/self.dx)
- endIndex = na.rint((child.RightEdge - self.LeftEdge)/self.dx)
- self.__child_mask[startIndex[0]:endIndex[0],
- startIndex[1]:endIndex[1],
- startIndex[2]:endIndex[2]] = 0
+ self.__fill_child_mask(child, self.__child_mask, 0)
self.__child_indices = (self.__child_mask==0) # bool, possibly redundant
def __generate_child_index_mask(self):
@@ -391,12 +300,7 @@
"""
self.__child_index_mask = na.zeros(self.ActiveDimensions, 'int32') - 1
for child in self.Children:
- # Now let's get our overlap
- startIndex = na.rint((child.LeftEdge - self.LeftEdge)/self.dx)
- endIndex = na.rint((child.RightEdge - self.LeftEdge)/self.dx)
- self.__child_index_mask[startIndex[0]:endIndex[0],
- startIndex[1]:endIndex[1],
- startIndex[2]:endIndex[2]] = child.id
+ self.__fill_child_mask(child, self.__child_mask, child.id)
def _get_coords(self):
if self.__coords == None: self._generate_coords()
@@ -468,3 +372,83 @@
for key in data.keys():
if key not in self.__current_data_keys:
del self.data[key]
+
+class EnzoGridBase(AMRGridPatch):
+ """
+ Class representing a single Enzo Grid instance.
+ """
+ def __init__(self, id, filename=None, hierarchy = None):
+ """
+ Returns an instance of EnzoGrid with *id*, associated with
+ *filename* and *hierarchy*.
+ """
+ #All of the field parameters will be passed to us as needed.
+ AMRGridPatch.__init__(self, id, filename, hierarchy)
+ self._file_access_pooling = False
+
+ def _guess_properties_from_parent(self):
+ """
+ We know that our grid boundary occurs on the cell boundary of our
+ parent. This can be a very expensive process, but it is necessary
+ in some hierarchys, where yt is unable to generate a completely
+ space-filling tiling of grids, possibly due to the finite accuracy in a
+ standard Enzo hierarchy file.
+ """
+ le = self.LeftEdge
+ self.dx = self.Parent.dx/2.0
+ self.dy = self.Parent.dy/2.0
+ self.dz = self.Parent.dz/2.0
+ ParentLeftIndex = na.rint((self.LeftEdge-self.Parent.LeftEdge)/self.Parent.dx)
+ self.start_index = 2*(ParentLeftIndex + self.Parent.get_global_startindex()).astype('int64')
+ self.LeftEdge = self.Parent.LeftEdge + self.Parent.dx * ParentLeftIndex
+ self.RightEdge = self.LeftEdge + \
+ self.ActiveDimensions*na.array([self.dx,self.dy,self.dz])
+ self.hierarchy.gridDxs[self.id-1,0] = self.dx
+ self.hierarchy.gridDys[self.id-1,0] = self.dy
+ self.hierarchy.gridDzs[self.id-1,0] = self.dz
+ self.hierarchy.gridLeftEdge[self.id-1,:] = self.LeftEdge
+ self.hierarchy.gridRightEdge[self.id-1,:] = self.RightEdge
+ self.hierarchy.gridCorners[:,:,self.id-1] = na.array([ # Unroll!
+ [self.LeftEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
+ [self.RightEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
+ [self.RightEdge[0], self.RightEdge[1], self.LeftEdge[2]],
+ [self.RightEdge[0], self.RightEdge[1], self.RightEdge[2]],
+ [self.LeftEdge[0], self.RightEdge[1], self.RightEdge[2]],
+ [self.LeftEdge[0], self.LeftEdge[1], self.RightEdge[2]],
+ [self.RightEdge[0], self.LeftEdge[1], self.RightEdge[2]],
+ [self.LeftEdge[0], self.RightEdge[1], self.LeftEdge[2]],
+ ], dtype='float64')
+ self.__child_mask = None
+ self.__child_index_mask = None
+ self.__child_indices = None
+ self._setup_dx()
+
+ def get_global_startindex(self):
+ """
+ Return the integer starting index for each dimension at the current
+ level.
+ """
+ if self.start_index != None:
+ return self.start_index
+ if self.Parent == None:
+ start_index = self.LeftEdge / na.array([self.dx, self.dy, self.dz])
+ return na.rint(start_index).astype('int64').ravel()
+ pdx = na.array([self.Parent.dx, self.Parent.dy, self.Parent.dz]).ravel()
+ start_index = (self.Parent.get_global_startindex()) + \
+ na.rint((self.LeftEdge - self.Parent.LeftEdge)/pdx)
+ self.start_index = (start_index*2).astype('int64').ravel()
+ return self.start_index
+
+ def set_filename(self, filename):
+ """
+ Intelligently set the filename.
+ """
+ if self.hierarchy._strip_path:
+ self.filename = os.path.join(self.hierarchy.directory,
+ os.path.basename(filename))
+ elif filename[0] == os.path.sep:
+ self.filename = filename
+ else:
+ self.filename = os.path.join(self.hierarchy.directory, filename)
+ return
+
Modified: trunk/yt/lagos/ContourFinder.py
==============================================================================
--- trunk/yt/lagos/ContourFinder.py (original)
+++ trunk/yt/lagos/ContourFinder.py Wed Nov 12 17:22:28 2008
@@ -103,7 +103,8 @@
my_queue.add(data_source._grids)
for i,grid in enumerate(my_queue):
max_before = grid["tempContours"].max()
- if na.all(grid.LeftEdge == 0.0) and na.all(grid.RightEdge == 1.0):
+ if na.all(grid.LeftEdge == grid.pf["DomainLeftEdge"]) and \
+ na.all(grid.RightEdge == grid.pf["DomainRightEdge"]):
cg = grid.retrieve_ghost_zones(0,["tempContours","GridIndices"])
else:
cg = grid.retrieve_ghost_zones(1,["tempContours","GridIndices"])
Modified: trunk/yt/lagos/HierarchyType.py
==============================================================================
--- trunk/yt/lagos/HierarchyType.py (original)
+++ trunk/yt/lagos/HierarchyType.py Wed Nov 12 17:22:28 2008
@@ -164,18 +164,18 @@
self._data_file = None
def _setup_classes(self, dd):
- self.proj = classobj("EnzoProj",(EnzoProjBase,), dd)
- self.slice = classobj("EnzoSlice",(EnzoSliceBase,), dd)
- self.region = classobj("EnzoRegion",(EnzoRegionBase,), dd)
- self.periodic_region = classobj("EnzoPeriodicRegion",(EnzoPeriodicRegionBase,), dd)
- self.covering_grid = classobj("EnzoCoveringGrid",(EnzoCoveringGrid,), dd)
- self.smoothed_covering_grid = classobj("EnzoSmoothedCoveringGrid",(EnzoSmoothedCoveringGrid,), dd)
- self.sphere = classobj("EnzoSphere",(EnzoSphereBase,), dd)
- self.cutting = classobj("EnzoCuttingPlane",(EnzoCuttingPlaneBase,), dd)
- self.ray = classobj("EnzoRay",(EnzoRayBase,), dd)
- self.ortho_ray = classobj("EnzoOrthoRay",(EnzoOrthoRayBase,), dd)
- self.disk = classobj("EnzoCylinder",(EnzoCylinderBase,), dd)
- self.grid_collection = classobj("EnzoGridCollection",(EnzoGridCollection,), dd)
+ self.proj = classobj("AMRProj",(AMRProjBase,), dd)
+ self.slice = classobj("AMRSlice",(AMRSliceBase,), dd)
+ self.region = classobj("AMRRegion",(AMRRegionBase,), dd)
+ self.periodic_region = classobj("AMRPeriodicRegion",(AMRPeriodicRegionBase,), dd)
+ self.covering_grid = classobj("AMRCoveringGrid",(AMRCoveringGrid,), dd)
+ self.smoothed_covering_grid = classobj("AMRSmoothedCoveringGrid",(AMRSmoothedCoveringGrid,), dd)
+ self.sphere = classobj("AMRSphere",(AMRSphereBase,), dd)
+ self.cutting = classobj("AMRCuttingPlane",(AMRCuttingPlaneBase,), dd)
+ self.ray = classobj("AMRRay",(AMRRayBase,), dd)
+ self.ortho_ray = classobj("AMROrthoRay",(AMROrthoRayBase,), dd)
+ self.disk = classobj("AMRCylinder",(AMRCylinderBase,), dd)
+ self.grid_collection = classobj("AMRGridCollection",(AMRGridCollection,), dd)
def _deserialize_hierarchy(self, harray):
mylog.debug("Cached entry found.")
Modified: trunk/yt/lagos/ParallelTools.py
==============================================================================
--- trunk/yt/lagos/ParallelTools.py (original)
+++ trunk/yt/lagos/ParallelTools.py Wed Nov 12 17:22:28 2008
@@ -108,6 +108,17 @@
if not self.just_list: self.pobj._finalize_parallel()
raise StopIteration
+def parallel_simple_proxy(func):
+ if not parallel_capable: return func
+ @wraps(func)
+ def single_proc_results(self, *args, **kwargs):
+ retval = None
+ if self._owned:
+ retval = func(self, *args, **kwargs)
+ MPI.COMM_WORLD.Bcast(retval)
+ return retval
+ return single_proc_results
+
def parallel_passthrough(func):
@wraps(func)
def passage(self, data):
Modified: trunk/yt/lagos/PointCombine.c
==============================================================================
--- trunk/yt/lagos/PointCombine.c (original)
+++ trunk/yt/lagos/PointCombine.c Wed Nov 12 17:22:28 2008
@@ -43,23 +43,29 @@
Py_CombineGrids(PyObject *obj, PyObject *args)
{
PyObject *ogrid_src_x, *ogrid_src_y, *ogrid_src_vals,
- *ogrid_src_mask, *ogrid_src_wgt;
+ *ogrid_src_mask, *ogrid_src_wgt, *ogrid_used_mask;
PyObject *ogrid_dst_x, *ogrid_dst_y, *ogrid_dst_vals,
*ogrid_dst_mask, *ogrid_dst_wgt;
PyArrayObject *grid_src_x, *grid_src_y, **grid_src_vals,
- *grid_src_mask, *grid_src_wgt;
+ *grid_src_mask, *grid_src_wgt, *grid_used_mask;
PyArrayObject *grid_dst_x, *grid_dst_y, **grid_dst_vals,
*grid_dst_mask, *grid_dst_wgt;
+ grid_src_x = grid_src_y = //grid_src_vals =
+ grid_src_mask = grid_src_wgt = grid_used_mask =
+ grid_dst_x = grid_dst_y = //grid_dst_vals =
+ grid_dst_mask = grid_dst_wgt = NULL;
+
int NumArrays, src_len, dst_len, refinement_factor;
+ NumArrays = 0;
- if (!PyArg_ParseTuple(args, "OOOOOOOOOOi",
+ if (!PyArg_ParseTuple(args, "OOOOOOOOOOiO",
&ogrid_src_x, &ogrid_src_y,
&ogrid_src_mask, &ogrid_src_wgt, &ogrid_src_vals,
&ogrid_dst_x, &ogrid_dst_y,
&ogrid_dst_mask, &ogrid_dst_wgt, &ogrid_dst_vals,
- &refinement_factor))
+ &refinement_factor, &ogrid_used_mask))
return PyErr_Format(_combineGridsError,
"CombineGrids: Invalid parameters.");
@@ -97,6 +103,15 @@
goto _fail;
}
+ grid_used_mask = (PyArrayObject *) PyArray_FromAny(ogrid_used_mask,
+ PyArray_DescrFromType(NPY_INT64), 1, 1,
+ NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL);
+ if((grid_used_mask == NULL) || (PyArray_SIZE(grid_used_mask) != src_len)) {
+ PyErr_Format(_combineGridsError,
+ "CombineGrids: src_x and used_mask must be the same shape.");
+ goto _fail;
+ }
+
grid_dst_x = (PyArrayObject *) PyArray_FromAny(ogrid_dst_x,
PyArray_DescrFromType(NPY_INT64), 1, 1,
NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL);
@@ -172,6 +187,7 @@
npy_int64 *src_y = (npy_int64 *) PyArray_GETPTR1(grid_src_y,0);
npy_float64 *src_wgt = (npy_float64 *) PyArray_GETPTR1(grid_src_wgt,0);
npy_int64 *src_mask = (npy_int64 *) PyArray_GETPTR1(grid_src_mask,0);
+ npy_int64 *src_used_mask = (npy_int64 *) PyArray_GETPTR1(grid_used_mask,0);
npy_int64 *dst_x = (npy_int64 *) PyArray_GETPTR1(grid_dst_x,0);
npy_int64 *dst_y = (npy_int64 *) PyArray_GETPTR1(grid_dst_y,0);
@@ -183,7 +199,7 @@
int num_found = 0;
for (si = 0; si < src_len; si++) {
- if (src_x[si] < 0) continue;
+ if (src_used_mask[si] == 0) continue;
init_x = refinement_factor * src_x[si];
init_y = refinement_factor * src_y[si];
for (x_off = 0; x_off < refinement_factor; x_off++) {
@@ -191,7 +207,6 @@
fine_x = init_x + x_off;
fine_y = init_y + y_off;
for (di = 0; di < dst_len; di++) {
- if (dst_x[di] < 0) continue;
if ((fine_x == dst_x[di]) &&
(fine_y == dst_y[di])) {
num_found++;
@@ -200,7 +215,7 @@
((refinement_factor != 1) && (dst_mask[di])));
// So if they are on the same level, then take the logical and
// otherwise, set it to the destination mask
- src_x[si] = -2;
+ src_used_mask[si] = 0;
for (i = 0; i < NumArrays; i++) {
dst_vals[i][di] += src_vals[i][si];
}
@@ -215,6 +230,7 @@
Py_DECREF(grid_src_y);
Py_DECREF(grid_src_mask);
Py_DECREF(grid_src_wgt);
+ Py_DECREF(grid_used_mask);
Py_DECREF(grid_dst_x);
Py_DECREF(grid_dst_y);
@@ -241,6 +257,7 @@
Py_XDECREF(grid_src_y);
Py_XDECREF(grid_src_wgt);
Py_XDECREF(grid_src_mask);
+ Py_XDECREF(grid_used_mask);
Py_XDECREF(grid_dst_x);
Py_XDECREF(grid_dst_y);
@@ -703,22 +720,14 @@
for(i=0;i<3;i++) {
itc = 1;
if (ac_le[i] < adl_edge[i]) {
- ac_le_p[i][itc ] = adr_edge[i] + ac_le[i];
- ac_re_p[i][itc++] = adr_edge[i] + ac_re[i];
- //fprintf(stderr, "le axis: %d (%d) le: %0.5f re: %0.5f\n",
- // i, itc-1, ac_le_p[i][itc-1], ac_re_p[i][itc-1]);
+ ac_le_p[i][itc ] = adr_edge[i] - (adl_edge[i] - ac_le[i]);
+ ac_re_p[i][itc++] = adr_edge[i] + (ac_re[i] - adl_edge[i]);
}
if (ac_re[i] > adr_edge[i]) {
- ac_le_p[i][itc ] = adl_edge[i] - (adr_edge[i]-adl_edge[i])
- + ac_le[i];
- ac_re_p[i][itc++] = adl_edge[i] - (adr_edge[i]-adl_edge[i])
- + ac_re[i];
- //fprintf(stderr, "re axis: %d (%d) le: %0.5f re: %0.5f\n",
- // i, itc-1, ac_le_p[i][itc-1], ac_re_p[i][itc-1]);
+ ac_le_p[i][itc ] = ac_le[i] - (adr_edge[i] - adl_edge[i]);
+ ac_re_p[i][itc++] = adl_edge[i] + (ac_re[i] - adr_edge[i]);
}
p_niter[i] = itc;
- //fprintf(stderr, "Iterating on %d %d (%d) times\n",
- // i, itc, p_niter[i]);
}
for (xg = 0; xg < g_data[0]->dimensions[0]; xg++) {
Modified: trunk/yt/raven/Callbacks.py
==============================================================================
--- trunk/yt/raven/Callbacks.py (original)
+++ trunk/yt/raven/Callbacks.py Wed Nov 12 17:22:28 2008
@@ -3,9 +3,11 @@
Author: Matthew Turk <matthewturk at gmail.com>
Affiliation: KIPAC/SLAC/Stanford
+Author: J. S. Oishi <jsoishi at astro.berkeley.edu>
+Affiliation: UC Berkeley
Homepage: http://yt.enzotools.org/
License:
- Copyright (C) 2008 Matthew Turk. All Rights Reserved.
+ Copyright (C) 2008 Matthew Turk, JS Oishi. All Rights Reserved.
This file is part of yt.
@@ -537,3 +539,69 @@
plot._axes.text(center_x, center_y, "%s" % i,
fontsize=self.font_size)
+class CoordAxesCallback(PlotCallback):
+ """Creates x and y axes for a VMPlot. In the future, it will
+ attempt to guess the proper units to use.
+
+ """
+ def __init__(self,unit=None,coords=False):
+ PlotCallback.__init__(self)
+ self.unit = unit
+ self.coords = coords
+
+ def __call__(self,plot):
+ # 1. find out what the domain is
+ # 2. pick a unit for it
+ # 3. run self._axes.set_xlabel & self._axes.set_ylabel to actually lay shit down.
+ # 4. adjust extent information to make sure labels are visable.
+
+ # put the plot into data coordinates
+ nx,ny = plot.image._A.shape
+ dx = (plot.xlim[1] - plot.xlim[0])/nx
+ dy = (plot.ylim[1] - plot.ylim[0])/ny
+
+ unit_conversion = plot.data.hierarchy[plot.im["Unit"]]
+ aspect = (plot.xlim[1]-plot.xlim[0])/(plot.ylim[1]-plot.ylim[0])
+
+ print "aspect ratio = ", aspect
+
+ # if coords is False, label axes relative to the center of the
+ # display. if coords is True, label axes with the absolute
+ # coordinates of the region.
+ xcenter = 0.
+ ycenter = 0.
+ if not self.coords:
+ center = plot.data.center
+ if plot.data.axis == 0:
+ xcenter = center[1]
+ ycenter = center[2]
+ elif plot.data.axis == 1:
+ xcenter = center[0]
+ ycenter = center[2]
+ else:
+ xcenter = center[0]
+ ycenter = center[1]
+
+
+ xformat_function = lambda a,b: '%7.1e' %((a*dx + plot.xlim[0] - xcenter)*unit_conversion)
+ yformat_function = lambda a,b: '%7.1e' %((a*dy + plot.ylim[0] - ycenter)*unit_conversion)
+ else:
+ xformat_function = lambda a,b: '%7.1e' %((a*dx + plot.xlim[0])*unit_conversion)
+ yformat_function = lambda a,b: '%7.1e' %((a*dy + plot.ylim[0])*unit_conversion)
+
+ xticker = matplotlib.ticker.FuncFormatter(xformat_function)
+ yticker = matplotlib.ticker.FuncFormatter(yformat_function)
+ plot._axes.xaxis.set_major_formatter(xticker)
+ plot._axes.yaxis.set_major_formatter(yticker)
+
+ xlabel = '%s (%s)' % (lagos.axis_labels[plot.data.axis][0],plot.im["Unit"])
+ ylabel = '%s (%s)' % (lagos.axis_labels[plot.data.axis][1],plot.im["Unit"])
+ xticksize = nx/4.
+ yticksize = ny/4.
+ plot._axes.xaxis.set_major_locator(matplotlib.ticker.FixedLocator([i*xticksize for i in range(0,5)]))
+ plot._axes.yaxis.set_major_locator(matplotlib.ticker.FixedLocator([i*yticksize for i in range(0,5)]))
+
+ plot._axes.set_xlabel(xlabel,visible=True)
+ plot._axes.set_ylabel(ylabel,visible=True)
+ plot._figure.subplots_adjust(left=0.1,right=0.8)
+
Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py (original)
+++ trunk/yt/raven/PlotTypes.py Wed Nov 12 17:22:28 2008
@@ -228,7 +228,7 @@
shrink=0.95)
else:
self.colorbar = None
- self.set_width(1,'1')
+ self.set_width(1,'unitary')
def _get_buff(self, width=None):
x0, x1 = self.xlim
More information about the yt-svn
mailing list