[yt-svn] commit/yt: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Jul 9 14:48:32 PDT 2016


2 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/6bcc8c23a4bf/
Changeset:   6bcc8c23a4bf
Branch:      yt
User:        ngoldbaum
Date:        2016-06-25 22:22:26+00:00
Summary:     Convert mutable Dataset attributes to be descriptors that return copies

This avoids the subtle issue that led to Issue #1007.
Affected #:  5 files

diff -r cc4cf45b51d65ea9588a01e12df7c4e0f7a476e6 -r 6bcc8c23a4bf1426383649c345abdb8c23c797b2 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -140,6 +140,22 @@
             return getattr(self.ds.index, name)
         raise AttributeError
 
+class MutableAttribute(object):
+    """A descriptor for mutable data"""
+    def __init__(self):
+        self.data = weakref.WeakKeyDictionary()
+
+    def __get__(self, instance, owner):
+        ret = self.data.get(instance, None)
+        try:
+            ret = ret.copy()
+        except AttributeError:
+            pass
+        return ret
+
+    def __set__(self, instance, value):
+        self.data[instance] = value
+
 def requires_index(attr_name):
     @property
     def ireq(self):
@@ -288,6 +304,12 @@
         except ImportError:
             return s.replace(";", "*")
 
+    domain_left_edge = MutableAttribute()
+    domain_right_edge = MutableAttribute()
+    domain_width = MutableAttribute()
+    domain_dimensions = MutableAttribute()
+    domain_center = MutableAttribute()
+
     @property
     def _mrep(self):
         return MinimalDataset(self)

diff -r cc4cf45b51d65ea9588a01e12df7c4e0f7a476e6 -r 6bcc8c23a4bf1426383649c345abdb8c23c797b2 yt/frontends/athena/data_structures.py
--- a/yt/frontends/athena/data_structures.py
+++ b/yt/frontends/athena/data_structures.py
@@ -317,7 +317,8 @@
         # know the extent of all the grids.
         glis = np.round((glis - self.dataset.domain_left_edge.ndarray_view())/gdds).astype('int')
         new_dre = np.max(gres,axis=0)
-        self.dataset.domain_right_edge[:] = np.round(new_dre, decimals=12)[:]
+        dre_units = self.dataset.domain_right_edge.uq
+        self.dataset.domain_right_edge = np.round(new_dre, decimals=12)*dre_units
         self.dataset.domain_width = \
                 (self.dataset.domain_right_edge -
                  self.dataset.domain_left_edge)

diff -r cc4cf45b51d65ea9588a01e12df7c4e0f7a476e6 -r 6bcc8c23a4bf1426383649c345abdb8c23c797b2 yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -486,11 +486,11 @@
 
         if pluto_ini_file_exists:
             lines=[line.strip() for line in open(pluto_ini_filename)]
-            self.domain_left_edge = np.zeros(self.dimensionality)
-            self.domain_right_edge = np.zeros(self.dimensionality)
+            domain_left_edge = np.zeros(self.dimensionality)
+            domain_right_edge = np.zeros(self.dimensionality)
             for il,ll in enumerate(lines[lines.index('[Grid]')+2:lines.index('[Grid]')+2+self.dimensionality]):
-                self.domain_left_edge[il] = float(ll.split()[2])
-                self.domain_right_edge[il] = float(ll.split()[-1])
+                domain_left_edge[il] = float(ll.split()[2])
+                domain_right_edge[il] = float(ll.split()[-1])
             self.periodicity = [0]*3
             for il,ll in enumerate(lines[lines.index('[Boundary]')+2:lines.index('[Boundary]')+2+6:2]):
                 self.periodicity[il] = (ll.split()[1] == 'periodic')
@@ -498,6 +498,8 @@
             for il,ll in enumerate(lines[lines.index('[Parameters]')+2:]):
                 if (ll.split()[0] == 'GAMMA'):
                     self.gamma = float(ll.split()[1])
+            self.domain_left_edge = domain_left_edge
+            self.domain_right_edge = domain_right_edge
         else:
             self.domain_left_edge = self._calc_left_edge()
             self.domain_right_edge = self._calc_right_edge()

diff -r cc4cf45b51d65ea9588a01e12df7c4e0f7a476e6 -r 6bcc8c23a4bf1426383649c345abdb8c23c797b2 yt/frontends/flash/data_structures.py
--- a/yt/frontends/flash/data_structures.py
+++ b/yt/frontends/flash/data_structures.py
@@ -465,8 +465,9 @@
         # fix the domain dimensions
         super(FLASHParticleDataset, self)._parse_parameter_file()
         nz = 1 << self.over_refine_factor
-        self.domain_dimensions = np.zeros(3, "int32")
-        self.domain_dimensions[:self.dimensionality] = nz
+        domain_dimensions = np.zeros(3, "int32")
+        domain_dimensions[:self.dimensionality] = nz
+        self.domain_dimensions = domain_dimensions
         self.filename_template = self.parameter_filename
         self.file_count = 1
 

diff -r cc4cf45b51d65ea9588a01e12df7c4e0f7a476e6 -r 6bcc8c23a4bf1426383649c345abdb8c23c797b2 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -225,8 +225,8 @@
         if self.bounding_box is None and (
                 self.domain_left_edge is None or
                 self.domain_right_edge is None):
-            self.domain_left_edge = np.nan
-            self.domain_right_edge = np.nan
+            self.domain_left_edge = np.array([np.nan, np.nan, np.nan])
+            self.domain_right_edge = np.array([np.nan, np.nan, np.nan])
             self.index
         super(TipsyDataset, self)._set_derived_attrs()
 


https://bitbucket.org/yt_analysis/yt/commits/142714a92cbb/
Changeset:   142714a92cbb
Branch:      yt
User:        xarthisius
Date:        2016-07-09 21:48:01+00:00
Summary:     Merged in ngoldbaum/yt (pull request #2251)

Convert mutable Dataset attributes to be properties that return copies
Affected #:  5 files

diff -r 3520f6d302a37e450621cb1dc01229c8b8a91312 -r 142714a92cbb18866fbdb7b94cf064c10be848ad yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -142,6 +142,22 @@
             return getattr(self.ds.index, name)
         raise AttributeError
 
+class MutableAttribute(object):
+    """A descriptor for mutable data"""
+    def __init__(self):
+        self.data = weakref.WeakKeyDictionary()
+
+    def __get__(self, instance, owner):
+        ret = self.data.get(instance, None)
+        try:
+            ret = ret.copy()
+        except AttributeError:
+            pass
+        return ret
+
+    def __set__(self, instance, value):
+        self.data[instance] = value
+
 def requires_index(attr_name):
     @property
     def ireq(self):
@@ -294,6 +310,12 @@
         except ImportError:
             return s.replace(";", "*")
 
+    domain_left_edge = MutableAttribute()
+    domain_right_edge = MutableAttribute()
+    domain_width = MutableAttribute()
+    domain_dimensions = MutableAttribute()
+    domain_center = MutableAttribute()
+
     @property
     def _mrep(self):
         return MinimalDataset(self)

diff -r 3520f6d302a37e450621cb1dc01229c8b8a91312 -r 142714a92cbb18866fbdb7b94cf064c10be848ad yt/frontends/athena/data_structures.py
--- a/yt/frontends/athena/data_structures.py
+++ b/yt/frontends/athena/data_structures.py
@@ -317,7 +317,8 @@
         # know the extent of all the grids.
         glis = np.round((glis - self.dataset.domain_left_edge.ndarray_view())/gdds).astype('int')
         new_dre = np.max(gres,axis=0)
-        self.dataset.domain_right_edge[:] = np.round(new_dre, decimals=12)[:]
+        dre_units = self.dataset.domain_right_edge.uq
+        self.dataset.domain_right_edge = np.round(new_dre, decimals=12)*dre_units
         self.dataset.domain_width = \
                 (self.dataset.domain_right_edge -
                  self.dataset.domain_left_edge)

diff -r 3520f6d302a37e450621cb1dc01229c8b8a91312 -r 142714a92cbb18866fbdb7b94cf064c10be848ad yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -486,11 +486,11 @@
 
         if pluto_ini_file_exists:
             lines=[line.strip() for line in open(pluto_ini_filename)]
-            self.domain_left_edge = np.zeros(self.dimensionality)
-            self.domain_right_edge = np.zeros(self.dimensionality)
+            domain_left_edge = np.zeros(self.dimensionality)
+            domain_right_edge = np.zeros(self.dimensionality)
             for il,ll in enumerate(lines[lines.index('[Grid]')+2:lines.index('[Grid]')+2+self.dimensionality]):
-                self.domain_left_edge[il] = float(ll.split()[2])
-                self.domain_right_edge[il] = float(ll.split()[-1])
+                domain_left_edge[il] = float(ll.split()[2])
+                domain_right_edge[il] = float(ll.split()[-1])
             self.periodicity = [0]*3
             for il,ll in enumerate(lines[lines.index('[Boundary]')+2:lines.index('[Boundary]')+2+6:2]):
                 self.periodicity[il] = (ll.split()[1] == 'periodic')
@@ -498,6 +498,8 @@
             for il,ll in enumerate(lines[lines.index('[Parameters]')+2:]):
                 if (ll.split()[0] == 'GAMMA'):
                     self.gamma = float(ll.split()[1])
+            self.domain_left_edge = domain_left_edge
+            self.domain_right_edge = domain_right_edge
         else:
             self.domain_left_edge = self._calc_left_edge()
             self.domain_right_edge = self._calc_right_edge()

diff -r 3520f6d302a37e450621cb1dc01229c8b8a91312 -r 142714a92cbb18866fbdb7b94cf064c10be848ad yt/frontends/flash/data_structures.py
--- a/yt/frontends/flash/data_structures.py
+++ b/yt/frontends/flash/data_structures.py
@@ -462,8 +462,9 @@
         # fix the domain dimensions
         super(FLASHParticleDataset, self)._parse_parameter_file()
         nz = 1 << self.over_refine_factor
-        self.domain_dimensions = np.zeros(3, "int32")
-        self.domain_dimensions[:self.dimensionality] = nz
+        domain_dimensions = np.zeros(3, "int32")
+        domain_dimensions[:self.dimensionality] = nz
+        self.domain_dimensions = domain_dimensions
         self.filename_template = self.parameter_filename
         self.file_count = 1
 

diff -r 3520f6d302a37e450621cb1dc01229c8b8a91312 -r 142714a92cbb18866fbdb7b94cf064c10be848ad yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -225,8 +225,8 @@
         if self.bounding_box is None and (
                 self.domain_left_edge is None or
                 self.domain_right_edge is None):
-            self.domain_left_edge = np.nan
-            self.domain_right_edge = np.nan
+            self.domain_left_edge = np.array([np.nan, np.nan, np.nan])
+            self.domain_right_edge = np.array([np.nan, np.nan, np.nan])
             self.index
         super(TipsyDataset, self)._set_derived_attrs()

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

--

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