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

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Wed Apr 2 10:13:44 PDT 2008


Author: mturk
Date: Wed Apr  2 10:13:42 2008
New Revision: 390
URL: http://yt.spacepope.org/changeset/390

Log:
Fixed up some particle problems.  Mainly, it now works to grab the particles,
in as many cases as I can figure.

There are still problems with the location of particles inside a region;
unfortunately, this looks like it will be another special case.  I am filing at
ticket ( #67 )



Modified:
   trunk/yt/lagos/BaseDataTypes.py
   trunk/yt/lagos/BaseGridType.py
   trunk/yt/lagos/DerivedFields.py

Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py	(original)
+++ trunk/yt/lagos/BaseDataTypes.py	Wed Apr  2 10:13:42 2008
@@ -936,7 +936,10 @@
     @restore_grid_state
     def _get_data_from_grid(self, grid, field):
         if fieldInfo.has_key(field) and fieldInfo[field].variable_length:
-            tr = grid[field]
+            try:
+                tr = grid[field]
+            except grid._read_exception:
+                tr = []
             return tr
         else:
             pointI = self._get_point_indices(grid)

Modified: trunk/yt/lagos/BaseGridType.py
==============================================================================
--- trunk/yt/lagos/BaseGridType.py	(original)
+++ trunk/yt/lagos/BaseGridType.py	Wed Apr  2 10:13:42 2008
@@ -94,7 +94,12 @@
                 conv_factor = 1.0
                 if fieldInfo.has_key(field):
                     conv_factor = fieldInfo[field]._convert_function(self)
-                self[field] = self.readDataFast(field) * conv_factor
+                try:
+                    self[field] = self.readDataFast(field) * conv_factor
+                except self._read_exception:
+                    if field in fieldInfo and fieldInfo[field].variable_length:
+                        self[field] = na.array([],dtype='float64')
+                    else: raise
             else:
                 self._generate_field(field)
         return self.data[field]

Modified: trunk/yt/lagos/DerivedFields.py
==============================================================================
--- trunk/yt/lagos/DerivedFields.py	(original)
+++ trunk/yt/lagos/DerivedFields.py	Wed Apr  2 10:13:42 2008
@@ -288,7 +288,7 @@
         try:
             particles = data._read_data("particle_%s" % p_field)
         except data._read_exception:
-            particles = na.array([], dtype=data["Density"].dtype)
+            particles = na.array([], dtype='float64')
         return particles
     return _Particles
 for pf in ["index","type"] + \
@@ -298,13 +298,13 @@
     add_field("particle_%s" % pf, function=pfunc,
               validators = [ValidateSpatial(0)],
               variable_length=True)
+add_field("particle mass", function=particle_func("particle mass"),
+          validators=[ValidateSpatial(0)], variable_length=True)
 
 def _ParticleMass(field, data):
-    try:
-        particles = data._read_data("particle mass").astype('float64')
-        particles *= just_one(data["CellVolumeCode"].ravel())
-    except data._read_exception:
-        particles = na.array([], dtype=data["Density"].dtype)
+    particles = data["particle mass"] * \
+                just_one(data["CellVolumeCode"].ravel())
+    # Note that we mandate grid-type here, so this is okay
     return particles
 def _convertParticleMass(data):
     return data.convert("Density")*(data.convert("cm")**3.0)



More information about the yt-svn mailing list