[yt-svn] commit/yt-3.0: MatthewTurk: Fixes to how container fields are accessed. I would like for this to be a

Bitbucket commits-noreply at bitbucket.org
Thu Aug 2 12:43:27 PDT 2012


1 new commit in yt-3.0:


https://bitbucket.org/yt_analysis/yt-3.0/changeset/78dc17559950/
changeset:   78dc17559950
branch:      yt-3.0
user:        MatthewTurk
date:        2012-08-02 21:43:18
summary:     Fixes to how container fields are accessed.  I would like for this to be a
better solution.  As it stands, because container fields do not have FieldInfo
affiliated with them, they are accessed like this.  I'm considering making
coordinates that are designed *only* for display be attributes rather than
dicts.

Slice plots now work.
affected #:  3 files

diff -r 3ff4f470014548d30377d71d8ee2937a8673d8a9 -r 78dc1755995073c6fecd814182c8ae4ba28e1c6f yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -202,7 +202,11 @@
         Returns a single field.  Will add if necessary.
         """
         if key not in self.field_data:
-            self.get_data(key)
+            if key in self._container_fields:
+                self.field_data[key] = self._generate_container_field(key)
+                return self.field_data[key]
+            else:
+                self.get_data(key)
         f = self._determine_fields(key)[0]
         return self.field_data[f]
 
@@ -226,7 +230,7 @@
     def _generate_field(self, field):
         ftype, fname = field
         if fname in self._container_fields:
-            return self._generate_container_field(field)
+            return self_generate_container_field(field)
         elif fname not in self.pf.field_info:
             raise KeyError(field)
         elif self.pf.field_info[fname].particle_type:
@@ -370,6 +374,9 @@
         fields = ensure_list(fields)
         explicit_fields = []
         for field in fields:
+            if field in self._container_fields:
+                explicit_fields.append((field, field))
+                continue
             if isinstance(field, types.TupleType):
                 if len(field) != 2 or \
                    not isinstance(field[0], types.StringTypes) or \


diff -r 3ff4f470014548d30377d71d8ee2937a8673d8a9 -r 78dc1755995073c6fecd814182c8ae4ba28e1c6f yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -245,6 +245,8 @@
         self.field_data.clear()
 
     def _generate_container_field(self, field):
+        if self._current_chunk is None:
+            self.hierarchy._identify_base_chunk(self)
         if field == "px":
             return self._current_chunk.fcoords[:,x_dict[self.axis]]
         elif field == "py":
@@ -451,6 +453,8 @@
         return frb
 
     def _generate_container_field(self, field):
+        if self._current_chunk is None:
+            self.hierarchy._identify_base_chunk(self)
         if field == "px":
             x = self._current_chunk.fcoords[:,0] - self.center[0]
             y = self._current_chunk.fcoords[:,1] - self.center[1]


diff -r 3ff4f470014548d30377d71d8ee2937a8673d8a9 -r 78dc1755995073c6fecd814182c8ae4ba28e1c6f yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -68,6 +68,14 @@
             s += "  It may lie on a grid face.  Try offsetting slightly."
         return s
 
+class YTFieldNotFound(YTException):
+    def __init__(self, fname, pf):
+        self.fname = fname
+        self.pf = pf
+
+    def __str__(self):
+        return "Could not find field '%s' in %s." % (self.fname, self.pf)
+
 class YTFieldTypeNotFound(YTException):
     def __init__(self, fname):
         self.fname = fname

Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list