[Yt-svn] yt-commit r940 - in branches/yt-non-3d: data yt yt/lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Sun Nov 16 21:13:41 PST 2008


Author: mturk
Date: Sun Nov 16 21:13:39 2008
New Revision: 940
URL: http://yt.spacepope.org/changeset/940

Log:
Added 1D data.

However, this raises a new point: RefineBy is going to have to start showing up
places...



Modified:
   branches/yt-non-3d/data/make_slice.py
   branches/yt-non-3d/yt/lagos/BaseGridType.py
   branches/yt-non-3d/yt/lagos/DataReadingFuncs.py
   branches/yt-non-3d/yt/lagos/EnzoFields.py
   branches/yt-non-3d/yt/lagos/FieldInfoContainer.py
   branches/yt-non-3d/yt/lagos/HierarchyType.py
   branches/yt-non-3d/yt/lagos/OutputTypes.py
   branches/yt-non-3d/yt/mods.py

Modified: branches/yt-non-3d/data/make_slice.py
==============================================================================
--- branches/yt-non-3d/data/make_slice.py	(original)
+++ branches/yt-non-3d/data/make_slice.py	Sun Nov 16 21:13:39 2008
@@ -2,7 +2,7 @@
 
 pf = EnzoStaticOutput("DD0003/sb_L2x2_0003")
 
-lagos.fieldInfo["VelocityMagnitude"].take_log = True
+EnzoFieldInfo["VelocityMagnitude"].take_log = True
 
 pc = PlotCollection(pf, center=[0.5,0.5,0.5])
 
@@ -13,6 +13,6 @@
 
 pc.set_width(0.9, '1')
 
-pc.add_phase_sphere(1.0, '1', ["Density", "TotalEnergy", "VelocityMagnitude"], weight=None)
+pc.add_phase_sphere(1.0, '1', ["Density", "TotalEnergy", "VelocityMagnitude"])
 
 pc.save("hi")

Modified: branches/yt-non-3d/yt/lagos/BaseGridType.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/BaseGridType.py	(original)
+++ branches/yt-non-3d/yt/lagos/BaseGridType.py	Sun Nov 16 21:13:39 2008
@@ -163,19 +163,20 @@
         # 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]
+        my_ind = self.id - self._id_offset
+        self.Dimensions = h.gridDimensions[my_ind]
+        self.StartIndices = h.gridStartIndices[my_ind]
+        self.EndIndices = h.gridEndIndices[my_ind]
+        self.LeftEdge = h.gridLeftEdge[my_ind]
+        self.RightEdge = h.gridRightEdge[my_ind]
+        self.Level = h.gridLevels[my_ind,0]
+        self.Time = h.gridTimes[my_ind,0]
+        self.NumberOfParticles = h.gridNumberOfParticles[my_ind,0]
         self.ActiveDimensions = (self.EndIndices - self.StartIndices + 1)
-        self.Children = h.gridTree[self.id-1]
-        pID = h.gridReverseTree[self.id-1]
+        self.Children = h.gridTree[my_ind]
+        pID = h.gridReverseTree[my_ind]
         if pID != None and pID != -1:
-            self.Parent = weakref.proxy(h.grids[pID - 1])
+            self.Parent = weakref.proxy(h.grids[pID - self._id_offset])
         else:
             self.Parent = None
 
@@ -396,6 +397,7 @@
         space-filling tiling of grids, possibly due to the finite accuracy in a
         standard Enzo hierarchy file.
         """
+        my_ind = self.id - self._id_offset
         le = self.LeftEdge
         self.dx = self.Parent.dx/2.0
         self.dy = self.Parent.dy/2.0
@@ -405,12 +407,12 @@
         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.hierarchy.gridDxs[my_ind,0] = self.dx
+        self.hierarchy.gridDys[my_ind,0] = self.dy
+        self.hierarchy.gridDzs[my_ind,0] = self.dz
+        self.hierarchy.gridLeftEdge[my_ind,:] = self.LeftEdge
+        self.hierarchy.gridRightEdge[my_ind,:] = self.RightEdge
+        self.hierarchy.gridCorners[:,:,my_ind] = 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]],

Modified: branches/yt-non-3d/yt/lagos/DataReadingFuncs.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/DataReadingFuncs.py	(original)
+++ branches/yt-non-3d/yt/lagos/DataReadingFuncs.py	Sun Nov 16 21:13:39 2008
@@ -180,6 +180,21 @@
                     (grid.id, field)).transpose()
     return t
 
+def readDataSlicePacked1D(self, grid, field, axis, coord):
+    """
+    Reads a slice through the HDF5 data
+
+    @param grid: Grid to slice
+    @type grid: L{EnzoGrid<EnzoGrid>}
+    @param field: field to get
+    @type field: string
+    @param sl: region to get
+    @type sl: SliceType
+    """
+    t = HDF5LightReader.ReadData(grid.filename, "/Grid%08i/%s" %
+                    (grid.id, field))
+    return t
+
 class BaseDataQueue(object):
 
     def __init__(self):
@@ -276,3 +291,11 @@
 
     def modify(self, field):
         pass
+
+class DataQueuePacked1D(BaseDataQueue):
+    def _read_set(self, grid, field):
+        return HDF5LightReader.ReadData(grid.filename,
+            "/Grid%08i/%s" % (grid.id, field)).transpose()[:,None,None]
+
+    def modify(self, field):
+        pass

Modified: branches/yt-non-3d/yt/lagos/EnzoFields.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/EnzoFields.py	(original)
+++ branches/yt-non-3d/yt/lagos/EnzoFields.py	Sun Nov 16 21:13:39 2008
@@ -25,6 +25,12 @@
 
 from UniversalFields import *
 
+class EnzoFieldContainer(CodeFieldInfoContainer):
+    _shared_state = {}
+    _field_list = {}
+EnzoFieldInfo = EnzoFieldContainer()
+add_enzo_field = EnzoFieldInfo.add_field
+
 add_field = add_enzo_field
 
 _speciesList = ["HI","HII","Electron",
@@ -162,3 +168,82 @@
 
 EnzoFieldInfo["Temperature"].units = r"K"
 
+#
+# Now we do overrides for 2D fields
+#
+
+class Enzo2DFieldContainer(CodeFieldInfoContainer):
+    _shared_state = {}
+    _field_list = EnzoFieldContainer._field_list.copy()
+# We make a copy of the dict from the other, so we
+# can now update it...
+Enzo2DFieldInfo = Enzo2DFieldContainer()
+add_enzo_2d_field = Enzo2DFieldInfo.add_field
+
+def _CellArea(field, data):
+    if data['dx'].size == 1:
+        try:
+            return data['dx']*data['dy']*\
+                na.ones(data.ActiveDimensions, dtype='float64')
+        except AttributeError:
+            return data['dx']*data['dy']
+    return data["dx"]*data["dy"]
+def _ConvertCellAreaMpc(data):
+    return data.convert("mpc")**2.0
+def _ConvertCellAreaCGS(data):
+    return data.convert("cm")**2.0
+add_enzo_2d_field("CellAreaCode", units=r"\rm{BoxArea}^2",
+          function=_CellArea)
+add_enzo_2d_field("CellAreaMpc", units=r"\rm{Mpc}^2",
+          function=_CellArea,
+          convert_function=_ConvertCellAreaMpc)
+add_enzo_2d_field("CellArea", units=r"\rm{cm}^2",
+          function=_CellArea,
+          convert_function=_ConvertCellAreaCGS)
+
+for a in ["Code", "Mpc", ""]:
+    Enzo2DFieldInfo["CellVolume%s" % a] = \
+        Enzo2DFieldInfo["CellArea%s" % a]
+
+def _zvel(field, data):
+    return na.zeros(data["x-velocity"].shape,
+                    dtype='float64')
+add_enzo_2d_field("z-velocity", function=_zvel)
+
+
+#
+# Now we do overrides for 1D fields
+#
+
+class Enzo1DFieldContainer(CodeFieldInfoContainer):
+    _shared_state = {}
+    _field_list = EnzoFieldContainer._field_list.copy()
+# We make a copy of the dict from the other, so we
+# can now update it...
+Enzo1DFieldInfo = Enzo1DFieldContainer()
+add_enzo_1d_field = Enzo1DFieldInfo.add_field
+
+def _CellLength(field, data):
+    return data["dx"]
+def _ConvertCellLengthMpc(data):
+    return data.convert("mpc")
+def _ConvertCellLengthCGS(data):
+    return data.convert("cm")
+add_enzo_1d_field("CellLengthCode", units=r"\rm{BoxArea}^2",
+          function=_CellLength)
+add_enzo_1d_field("CellLengthMpc", units=r"\rm{Mpc}^2",
+          function=_CellLength,
+          convert_function=_ConvertCellLengthMpc)
+add_enzo_1d_field("CellLength", units=r"\rm{cm}^2",
+          function=_CellLength,
+          convert_function=_ConvertCellLengthCGS)
+
+for a in ["Code", "Mpc", ""]:
+    Enzo1DFieldInfo["CellVolume%s" % a] = \
+        Enzo1DFieldInfo["CellLength%s" % a]
+
+def _yvel(field, data):
+    return na.zeros(data["x-velocity"].shape,
+                    dtype='float64')
+add_enzo_1d_field("z-velocity", function=_zvel)
+add_enzo_1d_field("y-velocity", function=_yvel)

Modified: branches/yt-non-3d/yt/lagos/FieldInfoContainer.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/FieldInfoContainer.py	(original)
+++ branches/yt-non-3d/yt/lagos/FieldInfoContainer.py	Sun Nov 16 21:13:39 2008
@@ -82,12 +82,6 @@
             return self._universal_field_list[key]
         raise KeyError
 
-class EnzoFieldContainer(CodeFieldInfoContainer):
-    _shared_state = {}
-    _field_list = {}
-EnzoFieldInfo = EnzoFieldContainer()
-add_enzo_field = EnzoFieldInfo.add_field
-
 class OrionFieldContainer(CodeFieldInfoContainer):
     _shared_state = {}
     _field_list = {}

Modified: branches/yt-non-3d/yt/lagos/HierarchyType.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/HierarchyType.py	(original)
+++ branches/yt-non-3d/yt/lagos/HierarchyType.py	Sun Nov 16 21:13:39 2008
@@ -34,8 +34,8 @@
      5: (readDataHDF5, readAllDataHDF5, getFieldsHDF5, readDataSliceHDF5, getExceptionHDF5),
      6: (readDataPacked, readAllDataPacked, getFieldsPacked, readDataSlicePacked, getExceptionHDF5),
      8: (readDataInMemory, readAllDataInMemory, getFieldsInMemory, readDataSliceInMemory, getExceptionInMemory),
-     'enzo_packed_2d': (readDataPacked, readAllDataPacked, getFieldsPacked,
-readDataSlicePacked2D, getExceptionHDF5),
+     'enzo_packed_2d': (readDataPacked, readAllDataPacked, getFieldsPacked, readDataSlicePacked2D, getExceptionHDF5),
+     'enzo_packed_1d': (readDataPacked, readAllDataPacked, getFieldsPacked, readDataSlicePacked1D, getExceptionHDF5),
    }
 
 class AMRHierarchy:
@@ -946,6 +946,17 @@
             random_sample = na.mgrid[0:max(len(gg)-1,1)].astype("int32")
         return gg[(random_sample,)]
 
+class EnzoHierarchy1D(EnzoHierarchy):
+    def __init__(self, *args, **kwargs):
+        EnzoHierarchy.__init__(self, *args, **kwargs)
+        self.gridRightEdge[:,1:2] = 1.0
+        self.gridDimensions[:,1:2] = 1.0
+        self.gridDys[:,0] = 1.0
+        self.gridDzs[:,0] = 1.0
+        for g in self.grids:
+            g._prepare_grid()
+            g._setup_dx()
+
 class EnzoHierarchy2D(EnzoHierarchy):
     def __init__(self, *args, **kwargs):
         EnzoHierarchy.__init__(self, *args, **kwargs)

Modified: branches/yt-non-3d/yt/lagos/OutputTypes.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/OutputTypes.py	(original)
+++ branches/yt-non-3d/yt/lagos/OutputTypes.py	Sun Nov 16 21:13:39 2008
@@ -139,13 +139,25 @@
         cp = os.path.join(self.directory, "cool_rates.out")
         if os.path.exists(cp):
             self.cool = EnzoTable(cp, cool_out_key)
-        self.field_info = self._fieldinfo_class()
 
         # Now fixes for different types of Hierarchies
-        if self["TopGridRank"] == 2: self._setup_2d()
+        # This includes changing the fieldinfo class!
+        if self["TopGridRank"] == 1: self._setup_1d()
+        elif self["TopGridRank"] == 2: self._setup_2d()
+
+        self.field_info = self._fieldinfo_class()
+
+    def _setup_1d(self):
+        self._hierarchy_class = EnzoHierarchy1D
+        self._fieldinfo_class = Enzo1DFieldContainer
+        self.parameters["DomainLeftEdge"] = \
+            na.concatenate([self["DomainLeftEdge"], [0.0, 0.0]])
+        self.parameters["DomainRightEdge"] = \
+            na.concatenate([self["DomainRightEdge"], [1.0, 1.0]])
 
     def _setup_2d(self):
         self._hierarchy_class = EnzoHierarchy2D
+        self._fieldinfo_class = Enzo2DFieldContainer
         self.parameters["DomainLeftEdge"] = \
             na.concatenate([self["DomainLeftEdge"], [0.0]])
         self.parameters["DomainRightEdge"] = \

Modified: branches/yt-non-3d/yt/mods.py
==============================================================================
--- branches/yt-non-3d/yt/mods.py	(original)
+++ branches/yt-non-3d/yt/mods.py	Sun Nov 16 21:13:39 2008
@@ -40,7 +40,7 @@
 # Now individual component imports from lagos
 from yt.lagos import EnzoStaticOutput, \
     BinnedProfile1D, BinnedProfile2D, BinnedProfile3D, \
-    add_field, \
+    add_field, EnzoFieldInfo, Enzo2DFieldInfo, OrionFieldInfo, \
     Clump, write_clump_hierarchy, find_clumps, write_clumps
 
 # Now individual component imports from raven



More information about the yt-svn mailing list