Commits

Matthew Turk committed 44cc722

Change spatial objects to use select_* for coordinate fields.

This changeset modifies spatial objects, such as oct domain subsets and grid
patches, to use the construction select_* for fwidth, fcoords, icoords, ires,
rather than overloading the existing properties fwidth, fcoords, ires, icoords.
In doing so we allow them to generate these coordinate fields.

Additionally, I have implemented fixes for cutting planes, and implemented
covering grid spatial fields via container_fields. The covering grid spatial
fields are now tested.

  • Participants
  • Parent commits 8bc4e5a

Comments (0)

Files changed (11)

File yt/data_objects/construction_data_containers.py

     _spatial = True
     _type_name = "covering_grid"
     _con_args = ('level', 'left_edge', 'ActiveDimensions')
+    _container_fields = ("dx", "dy", "dz", "x", "y", "z")
     _base_grid = None
     def __init__(self, level, left_edge, dims, fields = None,
                  pf = None, num_ghost_zones = 0, use_pbar = True, 
         for name, v in zip(fields, output_fields):
             self[name] = v
 
+    def _generate_container_field(self, field):
+        rv = np.ones(self.ActiveDimensions, dtype="float64")
+        if field == "dx":
+            np.multiply(rv, self.dds[0], rv)
+        elif field == "dy":
+            np.multiply(rv, self.dds[1], rv)
+        elif field == "dz":
+            np.multiply(rv, self.dds[2], rv)
+        elif field == "x":
+            x = np.mgrid[self.left_edge[0] + 0.5*self.dds[0]:
+                         self.right_edge[0] - 0.5*self.dds[0]:
+                         self.ActiveDimensions[0] * 1j]
+            np.multiply(rv, x[:,None,None], rv)
+        elif field == "y":
+            y = np.mgrid[self.left_edge[1] + 0.5*self.dds[1]:
+                         self.right_edge[1] - 0.5*self.dds[1]:
+                         self.ActiveDimensions[1] * 1j]
+            np.multiply(rv, y[None,:,None], rv)
+        elif field == "z":
+            z = np.mgrid[self.left_edge[2] + 0.5*self.dds[2]:
+                         self.right_edge[2] - 0.5*self.dds[2]:
+                         self.ActiveDimensions[2] * 1j]
+            np.multiply(rv, z[None,None,:], rv)
+        else:
+            raise KeyError(field)
+        return rv
+
 class LevelState(object):
     current_dx = None
     current_dims = None

File yt/data_objects/grid_patch.py

 
         return new_field
 
-    def icoords(self, dobj):
+    def select_icoords(self, dobj):
         mask = self.select(dobj.selector)
         if mask is None: return np.empty((0,3), dtype='int64')
         coords = convert_mask_to_indices(mask, mask.sum())
         coords += self.get_global_startindex()[None, :]
         return coords
 
-    def fcoords(self, dobj):
+    def select_fcoords(self, dobj):
         mask = self.select(dobj.selector)
         if mask is None: return np.empty((0,3), dtype='float64')
         coords = convert_mask_to_indices(mask, mask.sum()).astype("float64")
         coords += self.LeftEdge[None, :]
         return coords
 
-    def fwidth(self, dobj):
+    def select_fwidth(self, dobj):
         mask = self.select(dobj.selector)
         if mask is None: return np.empty((0,3), dtype='float64')
         coords = np.empty((mask.sum(), 3), dtype='float64')
             coords[:,axis] = self.dds[axis]
         return coords
 
-    def ires(self, dobj):
+    def select_ires(self, dobj):
         mask = self.select(dobj.selector)
         if mask is None: return np.empty(0, dtype='int64')
         coords = np.empty(mask.sum(), dtype='int64')

File yt/data_objects/selection_data_containers.py

         """
         normal = self.normal
         center = self.center
-        if fields == None:
-            if self.fields == None:
-                raise SyntaxError("The fields keyword argument must be set")
-        else:
-            self.fields = ensure_list(fields)
- 
         from yt.visualization.plot_window import \
             GetObliqueWindowParameters, PWViewerMPL
         from yt.visualization.fixed_resolution import ObliqueFixedResolutionBuffer

File yt/data_objects/tests/test_covering_grid.py

             dn = pf.refine_by**level 
             cg = pf.h.covering_grid(level, [0.0, 0.0, 0.0],
                     dn * pf.domain_dimensions)
+            # Test coordinate generation
+            yield assert_equal, np.unique(cg["dx"]).size, 1
+            xmi = cg["x"].min()
+            xma = cg["x"].max()
+            dx = cg["dx"][0]
+            yield assert_equal, xmi, 0.0 + dx/2.0
+            yield assert_equal, xmi, cg["x"][0,0,0]
+            yield assert_equal, xmi, cg["x"][0,1,1]
+            yield assert_equal, xma, 1.0 - dx/2.0
+            yield assert_equal, xma, cg["x"][-1,0,0]
+            yield assert_equal, xma, cg["x"][-1,1,1]
+            yield assert_equal, np.unique(cg["dy"]).size, 1
+            ymi = cg["y"].min()
+            yma = cg["y"].max()
+            dy = cg["dy"][0]
+            yield assert_equal, ymi, 0.0 + dy/2.0
+            yield assert_equal, ymi, cg["y"][0,0,0]
+            yield assert_equal, ymi, cg["y"][1,0,1]
+            yield assert_equal, yma, 1.0 - dy/2.0
+            yield assert_equal, yma, cg["y"][0,-1,0]
+            yield assert_equal, yma, cg["y"][1,-1,1]
+            yield assert_equal, np.unique(cg["dz"]).size, 1
+            zmi = cg["z"].min()
+            zma = cg["z"].max()
+            dz = cg["dz"][0]
+            yield assert_equal, zmi, 0.0 + dz/2.0
+            yield assert_equal, zmi, cg["z"][0,0,0]
+            yield assert_equal, zmi, cg["z"][1,1,0]
+            yield assert_equal, zma, 1.0 - dz/2.0
+            yield assert_equal, zma, cg["z"][0,0,-1]
+            yield assert_equal, zma, cg["z"][1,1,-1]
+            # Now we test other attributes
             yield assert_equal, cg["Ones"].max(), 1.0
             yield assert_equal, cg["Ones"].min(), 1.0
             yield assert_equal, cg["GridLevel"], 0

File yt/data_objects/tests/test_cutting_plane.py

         center = [0.5,0.5,0.5]
         normal = [1,1,1]
         fns = []
-        cut = pf.h.cutting(normal, center, ["Ones", "Density"])
+        cut = pf.h.cutting(normal, center)
         yield assert_equal, cut["Ones"].sum(), cut["Ones"].size
         yield assert_equal, cut["Ones"].min(), 1.0
         yield assert_equal, cut["Ones"].max(), 1.0

File yt/frontends/art/data_structures.py

         level_counts[0] = 0
         self.level_counts = np.add.accumulate(level_counts)
 
-    def icoords(self, dobj):
+    def select_icoords(self, dobj):
         return self.oct_handler.icoords(self.domain.domain_id, self.mask,
                                         self.cell_count,
                                         self.level_counts.copy())
 
-    def fcoords(self, dobj):
+    def select_fcoords(self, dobj):
         return self.oct_handler.fcoords(self.domain.domain_id, self.mask,
                                         self.cell_count,
                                         self.level_counts.copy())
 
-    def ires(self, dobj):
+    def select_ires(self, dobj):
         return self.oct_handler.ires(self.domain.domain_id, self.mask,
                                      self.cell_count,
                                      self.level_counts.copy())
 
-    def fwidth(self, dobj):
+    def select_fwidth(self, dobj):
         base_dx = 1.0/self.domain.pf.domain_dimensions
         widths = np.empty((self.cell_count, 3), dtype="float64")
         dds = (2**self.ires(dobj))

File yt/frontends/artio/data_structures.py

         self.ncum_masked_level = np.add.accumulate(ncum_masked_level)
         print 'cumulative masked level counts',self.ncum_masked_level
         
-    def icoords(self, dobj):
+    def select_icoords(self, dobj):
         return self.oct_handler.icoords(self.domain.domain_id, self.mask,
                                         self.masked_cell_count,
                                         self.ncum_masked_level.copy())
 
-    def fcoords(self, dobj):
+    def select_fcoords(self, dobj):
         return self.oct_handler.fcoords(self.domain.domain_id, self.mask,
                                         self.masked_cell_count,
                                         self.ncum_masked_level.copy())
 
-    def fwidth(self, dobj):
+    def select_fwidth(self, dobj):
         # Recall domain_dimensions is the number of cells, not octs
         # snl FIX: please don't hardcode this here 
 #        DRE = self.oct_handler.parameter_file.domain_right_edge 
             widths[:,i] = base_dx[i] / dds
         return widths
 
-    def ires(self, dobj):
+    def select_ires(self, dobj):
         return self.oct_handler.ires(self.domain.domain_id, self.mask,
                                      self.masked_cell_count,
                                      self.ncum_masked_level.copy())

File yt/frontends/ramses/data_structures.py

         level_counts[0] = 0
         self.level_counts = np.add.accumulate(level_counts)
 
-    def icoords(self, dobj):
+    def select_icoords(self, dobj):
         return self.oct_handler.icoords(self.domain.domain_id, self.mask,
                                         self.cell_count,
                                         self.level_counts.copy())
 
-    def fcoords(self, dobj):
+    def select_fcoords(self, dobj):
         return self.oct_handler.fcoords(self.domain.domain_id, self.mask,
                                         self.cell_count,
                                         self.level_counts.copy())
 
-    def fwidth(self, dobj):
+    def select_fwidth(self, dobj):
         # Recall domain_dimensions is the number of cells, not octs
         base_dx = 1.0/self.domain.pf.domain_dimensions
         widths = np.empty((self.cell_count, 3), dtype="float64")
             widths[:,i] = base_dx[i] / dds
         return widths
 
-    def ires(self, dobj):
+    def select_ires(self, dobj):
         return self.oct_handler.ires(self.domain.domain_id, self.mask,
                                      self.cell_count,
                                      self.level_counts.copy())

File yt/frontends/sph/data_structures.py

         level_counts[0] = 0
         self.level_counts = np.add.accumulate(level_counts)
 
-    def icoords(self, dobj):
+    def select_icoords(self, dobj):
         return self.oct_handler.icoords(self.domain.domain_id, self.mask,
                                         self.cell_count)
 
-    def fcoords(self, dobj):
+    def select_fcoords(self, dobj):
         return self.oct_handler.fcoords(self.domain.domain_id, self.mask,
                                         self.cell_count)
 
-    def fwidth(self, dobj):
+    def select_fwidth(self, dobj):
         # Recall domain_dimensions is the number of cells, not octs
         base_dx = 1.0/self.domain.pf.domain_dimensions
         widths = np.empty((self.cell_count, 3), dtype="float64")
             widths[:,i] = base_dx[i] / dds
         return widths
 
-    def ires(self, dobj):
+    def select_ires(self, dobj):
         return self.oct_handler.ires(self.domain.domain_id, self.mask,
                                      self.cell_count)
 

File yt/geometry/cartesian_fields.py

 CartesianFieldInfo.name = id(CartesianFieldInfo)
 add_cart_field = CartesianFieldInfo.add_field
 
-
 def _dx(field, data):
     return data.pf.domain_width[0] * data.fwidth[:,0]
 add_cart_field('dx', function=_dx, display_field=False)

File yt/geometry/geometry_handler.py

         if self.data_size == 0: return self._fcoords
         ind = 0
         for obj in self.objs:
-            c = obj.fcoords(self.dobj)
+            c = obj.select_fcoords(self.dobj)
             if c.shape[0] == 0: continue
             ci[ind:ind+c.shape[0], :] = c
             ind += c.shape[0]
         if self.data_size == 0: return self._icoords
         ind = 0
         for obj in self.objs:
-            c = obj.icoords(self.dobj)
+            c = obj.select_icoords(self.dobj)
             if c.shape[0] == 0: continue
             ci[ind:ind+c.shape[0], :] = c
             ind += c.shape[0]
         if self.data_size == 0: return self._fwidth
         ind = 0
         for obj in self.objs:
-            c = obj.fwidth(self.dobj)
+            c = obj.select_fwidth(self.dobj)
             if c.shape[0] == 0: continue
             ci[ind:ind+c.shape[0], :] = c
             ind += c.shape[0]
         if self.data_size == 0: return self._ires
         ind = 0
         for obj in self.objs:
-            c = obj.ires(self.dobj)
+            c = obj.select_ires(self.dobj)
             if c.shape == 0: continue
             ci[ind:ind+c.size] = c
             ind += c.size