[Yt-svn] yt-commit r1059 - trunk/yt/lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Sun Dec 28 22:46:50 PST 2008


Author: mturk
Date: Sun Dec 28 22:46:49 2008
New Revision: 1059
URL: http://yt.spacepope.org/changeset/1059

Log:
Added an InLineExtractedRegionBase, to allow for eval'd field cuts for grid
point inclusion, similar to the routine Britton put in for projections.

data_object.cut_region(field_cuts) now returns an object; field_cuts is a
string or list of strings of functions that will be eval'd whenever points are
selected.

For instance:

data_object.cut_region(["grid['Density'] > 1e-31"])

would cut out exactly what you expect, but because it's done *on-the-fly*,
it can be used in lazy profiles without any added memory requirements.



Modified:
   trunk/yt/lagos/BaseDataTypes.py

Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py	(original)
+++ trunk/yt/lagos/BaseDataTypes.py	Sun Dec 28 22:46:49 2008
@@ -1319,6 +1319,13 @@
         k = (k | self._get_cut_particle_mask(grid))
         return na.where(k)
 
+    def cut_region(self, field_cuts):
+        """
+        Return an InLineExtractedRegion, where the grid cells are cut on the
+        fly with a set of field_cuts.
+        """
+        return InLineExtractedRegionBase(self, field_cuts)
+
     def extract_region(self, indices):
         """
         Return an ExtractedRegion where the points contained in it are defined
@@ -1428,6 +1435,33 @@
         # Yeah, if it's not true, we don't care.
         return self._indices[grid.id-1]
 
+class InLineExtractedRegionBase(AMR3DData):
+    """
+    In-line extracted regions accept a base region and a set of field_cuts to
+    determine which points in a grid should be included.
+    """
+    def __init__(self, base_region, field_cuts, **kwargs):
+        cen = base_region.get_field_parameter("center")
+        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
+        self._field_cuts = ensure_list(field_cuts)[:]
+        self._refresh_data()
+
+    def _get_list_of_grids(self):
+        self._grids = self._base_region._grids
+
+    def _is_fully_enclosed(self, grid):
+        return False
+
+    @cache_mask
+    def _get_cut_mask(self, grid):
+        point_mask = self._base_region._get_cut_mask(grid)
+        for cut in self._field_cuts:
+            point_mask *= eval(cut)
+        return point_mask
+
 class AMRCylinderBase(AMR3DData):
     """
     We can define a cylinder (or disk) to act as a data object.



More information about the yt-svn mailing list