Commits

Matthew Turk committed 3e24db7

Getting closer to full active particle analysis for Enzo 3.0 datasets.

Comments (0)

Files changed (5)

yt/data_objects/data_containers.py

             gen_obj = self._current_chunk.objs[0]
         try:
             self.pf.field_info[fname].check_available(gen_obj)
-        except NeedsGridType, ngt_exception:
+        except NeedsGridType as ngt_exception:
             rv = np.empty(self.size, dtype="float64")
             ind = 0
             ngz = ngt_exception.ghost_zones
         try:
             finfo = self._get_field_info(*field)
             finfo.check_available(gen_obj)
-        except NeedsGridType, ngt_exception:
+        except NeedsGridType as ngt_exception:
             if ngt_exception.ghost_zones != 0:
                 raise NotImplementedError
             size = self._count_particles(ftype)
                 for i,chunk in enumerate(self.chunks(field, "spatial")):
                     x, y, z = (self[ftype, 'particle_position_%s' % ax]
                                for ax in 'xyz')
+                    if x.size == 0: continue
                     mask = self._current_chunk.objs[0].select_particles(
                         self.selector, x, y, z)
                     if mask is None: continue
             for i,chunk in enumerate(self.chunks([], "spatial")):
                 x, y, z = (self[ftype, 'particle_position_%s' % ax]
                             for ax in 'xyz')
+                if x.size == 0: continue
                 size += self._current_chunk.objs[0].count_particles(
                     self.selector, x, y, z)
         return size
         if (ftype, fname) in self.pf.field_info:
             return self.pf.field_info[(ftype, fname)]
         if fname in self.pf.field_info:
-           return self.pf.field_info[fname]
+            return self.pf.field_info[fname]
         raise YTFieldNotFound((fname, ftype), self.pf)
 
     def _determine_fields(self, fields):

yt/data_objects/field_info_container.py

         self.display_name = display_name
         self.not_in_all = not_in_all
 
+    def _copy_def(self):
+        dd = {}
+        dd['name'] = self.name
+        dd['convert_function'] = self._convert_function
+        dd['particle_convert_function'] = self._particle_convert_function
+        dd['units'] = self._units
+        dd['projected_units'] = self._projected_units,
+        dd['take_log'] = self.take_log
+        dd['validators'] = self.validators.copy()
+        dd['particle_type'] = self.particle_type
+        dd['vector_field'] = self.vector_field
+        dd['display_field'] = True
+        dd['not_in_all'] = self.not_in_all
+        dd['display_name'] = self.display_name
+        dd['projection_conversion'] = self.projection_conversion
+        return dd
+
     def check_available(self, data):
         """
         This raises an exception of the appropriate type if the set of

yt/frontends/enzo/data_structures.py

         if handle is not None: handle.close()
         return set(fields)
 
+    def _setup_derived_fields(self):
+        super(EnzoHierarchy, self)._setup_derived_fields()
+        aps = self.parameter_file.parameters["AppendActiveParticleType"]
+        for fname, field in self.pf.field_info.items():
+            if not field.particle_type: continue
+            if isinstance(fname, tuple): continue
+            if field._function is NullFunc: continue
+            for apt in aps:
+                dd = field._copy_def()
+                dd.pop("name")
+                add_field((apt, fname), **dd)
+
     def _detect_fields(self):
         self.field_list = []
         # Do this only on the root processor to save disk work.

yt/frontends/enzo/fields.py

 
 import yt.utilities.lib as amr_utils
 
+def _check_ftype(field):
+    if isinstance(field.name, tuple):
+        return field.name[0]
+    return "all"
+
 EnzoFieldInfo = FieldInfoContainer.create_with_fallback(FieldInfo, "EFI")
 add_field = EnzoFieldInfo.add_field
 
 
 # Particle functions
 
-def particle_func(p_field, dtype='float64'):
-    def _Particles(field, data):
-        io = data.hierarchy.io
-        if not data.NumberOfParticles > 0:
-            return np.array([], dtype=dtype)
-        try:
-            return io._read_data_set(data, p_field).astype(dtype)
-        except io._read_exception:
-            pass
-        # This is bad.  But it's the best idea I have right now.
-        return data._read_data(p_field.replace("_"," ")).astype(dtype)
-    return _Particles
 for pf in ["type", "mass"] + \
           ["position_%s" % ax for ax in 'xyz']:
-    pfunc = particle_func("particle_%s" % (pf))
-    add_enzo_field("particle_%s" % pf, function=pfunc,
-              validators = [ValidateSpatial(0)],
-              particle_type=True)
+    add_enzo_field("particle_%s" % pf, NullFunc, particle_type=True)
     
 def _convRetainInt(data):
     return 1
-add_enzo_field("particle_index", function=particle_func("particle_index", "int64"),
-          validators = [ValidateSpatial(0)], particle_type=True,
-          convert_function=_convRetainInt)
+add_enzo_field("particle_index", function=NullFunc,
+          particle_type=True, convert_function=_convRetainInt)
 
 def _get_vel_convert(ax):
     def _convert_p_vel(data):
     return _convert_p_vel
 for ax in 'xyz':
     pf = "particle_velocity_%s" % ax
-    pfunc = particle_func(pf)
     cfunc = _get_vel_convert(ax)
-    add_enzo_field(pf, function=pfunc, convert_function=cfunc,
-              validators = [ValidateSpatial(0)],
+    add_enzo_field(pf, function=NullFunc, convert_function=cfunc,
               particle_type=True)
 
 for pf in ["creation_time", "dynamical_time", "metallicity_fraction"]:
-    pfunc = particle_func(pf)
-    add_enzo_field(pf, function=pfunc,
-              validators = [ValidateSpatial(0),
-                            ValidateDataField(pf)],
+    add_enzo_field(pf, function=NullFunc,
+              validators = [ValidateDataField(pf)],
               particle_type=True)
-add_field("particle_mass", function=particle_func("particle_mass"),
-          particle_type=True)
+add_field("particle_mass", function=NullFunc, particle_type=True)
 
 def _ParticleAge(field, data):
     current_time = data.pf.current_time
           particle_type=True, convert_function=_convertParticleAge)
 
 def _ParticleMass(field, data):
-    particles = data["particle_mass"].astype('float64') * \
+    ftype = _check_ftype(field)
+    particles = data[ftype, "particle_mass"].astype('float64') * \
                 just_one(data["CellVolumeCode"].ravel())
     # Note that we mandate grid-type here, so this is okay
     return particles
 add_enzo_1d_field("z-velocity", function=_zvel)
 add_enzo_1d_field("y-velocity", function=_yvel)
 
+for ax in 'xyz':
+    add_field(("CenOstriker","particle_position_%s" % ax),
+               function=TranslationFunc(("CenOstriker","position_%s" % ax)),
+               particle_type = True)
+

yt/geometry/geometry_handler.py

 
 class YTDataChunk(object):
 
-    def __init__(self, dobj, chunk_type, objs, data_size):
+    def __init__(self, dobj, chunk_type, objs, data_size, field_type = None):
         self.dobj = dobj
         self.chunk_type = chunk_type
         self.objs = objs
         self._data_size = data_size
+        self._field_type = field_type
 
     @property
     def data_size(self):