[Yt-svn] yt: Proper handling of files that don't have particles... more i...

hg at spacepope.org hg at spacepope.org
Wed Sep 22 09:06:29 PDT 2010


hg Repository: yt
details:   yt/rev/de3ee7750230
changeset: 3404:de3ee7750230
user:      John ZuHone <jzuhone at gmail.com>
date:
Wed Sep 22 12:06:12 2010 -0400
description:
Proper handling of files that don't have particles... more issues may
crop up, however.

diffstat:

 yt/frontends/flash/data_structures.py |  10 +++++++---
 yt/frontends/flash/io.py              |  13 ++++++++-----
 2 files changed, 15 insertions(+), 8 deletions(-)

diffs (50 lines):

diff -r aa3179f8fd19 -r de3ee7750230 yt/frontends/flash/data_structures.py
--- a/yt/frontends/flash/data_structures.py	Tue Sep 21 09:55:14 2010 -0700
+++ b/yt/frontends/flash/data_structures.py	Wed Sep 22 12:06:12 2010 -0400
@@ -84,8 +84,9 @@
     def _detect_fields(self):
         ncomp = self._handle["/unknown names"].shape[0]
         self.field_list = [s.strip() for s in self._handle["/unknown names"][:].flat]
-        self.field_list += ["particle_" + s[0].strip() for s
-                            in self._handle["/particle names"][:]]
+        if ("/particle names" in self._handle) :
+            self.field_list += ["particle_" + s[0].strip() for s
+                                in self._handle["/particle names"][:]]
     
     def _setup_classes(self):
         dd = self._get_data_reader_dict()
@@ -114,7 +115,10 @@
             nxb, nyb, nzb = [int(f["/simulation parameters"]['n%sb' % ax])
                               for ax in 'xyz']
         self.grid_dimensions[:] *= (nxb, nyb, nzb)
-        self.grid_particle_count[:] = f["/localnp"][:][:,None]
+        try:
+            self.grid_particle_count[:] = f["/localnp"][:][:,None]
+        except KeyError:
+            self.grid_particle_count[:] = 0.0
         self._particle_indices = na.zeros(self.num_grids + 1, dtype='int64')
         na.add.accumulate(self.grid_particle_count, out=self._particle_indices[1:])
         # This will become redundant, as _prepare_grid will reset it to its
diff -r aa3179f8fd19 -r de3ee7750230 yt/frontends/flash/io.py
--- a/yt/frontends/flash/io.py	Tue Sep 21 09:55:14 2010 -0700
+++ b/yt/frontends/flash/io.py	Wed Sep 22 12:06:12 2010 -0400
@@ -39,11 +39,14 @@
         # Now we cache the particle fields
         self.pf = pf
         self._handle = h5py.File(self.pf.parameter_filename, "r")
-        particle_fields = [s[0].strip() for s in
-                           self._handle["/particle names"][:]]
-        self._particle_fields = dict([("particle_" + s, i) for i, s in
-                                     enumerate(particle_fields)])
-
+        try :
+            particle_fields = [s[0].strip() for s in
+                               self._handle["/particle names"][:]]
+            self._particle_fields = dict([("particle_" + s, i) for i, s in
+                                          enumerate(particle_fields)])
+        except KeyError:
+            self._particle_fields = {}
+            
     def _read_particles(self, fields_to_read, type, args, grid_list,
             count_list, conv_factors):
         pass



More information about the yt-svn mailing list