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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu May 25 14:20:15 PDT 2017


7 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/ebb80870ce28/
Changeset:   ebb80870ce28
User:        ngoldbaum
Date:        2017-05-19 17:02:28+00:00
Summary:     Ensure the field value of an isocontour are in the field's units. Closes #1406.
Affected #:  1 file

diff -r 2c99a58e7aed85ec4948345fefb6cb39e392aaf9 -r ebb80870ce28680a566f03209485720628a0a48e yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1092,7 +1092,7 @@
     surface_field : string
         Any field that can be obtained in a data object.  This is the field
         which will be isocontoured.
-    field_value : float
+    field_value : float, YTQuantity, or unit tuple
         The value at which the isocontour should be calculated.
 
     Examples
@@ -1120,11 +1120,19 @@
     vertices = None
     def __init__(self, data_source, surface_field, field_value, ds=None):
         self.data_source = data_source
-        self.surface_field = surface_field
-        self.field_value = field_value
+        self.surface_field = data_source._determine_fields(surface_field)[0]
+        finfo = data_source.ds.field_info[self.surface_field]
+        try:
+            self.field_value = field_value.to(finfo.units)
+        except AttributeError:
+            if isinstance(field_value, tuple):
+                self.field_value = data_source.ds.quan(*field_value)
+                self.field_value = self.field_value.to(finfo.units)
+            else:
+                self.field_value = data_source.ds.quan(field_value, finfo.units)
         self.vertex_samples = YTFieldData()
         center = data_source.get_field_parameter("center")
-        super(YTSurface, self).__init__(center = center, ds=ds)
+        super(YTSurface, self).__init__(center=center, ds=ds)
 
     def _generate_container_field(self, field):
         self.get_data(field)


https://bitbucket.org/yt_analysis/yt/commits/22eba4320d50/
Changeset:   22eba4320d50
User:        ngoldbaum
Date:        2017-05-19 17:04:25+00:00
Summary:     Make the vertices attribute of the surface data object a property
Affected #:  1 file

diff -r ebb80870ce28680a566f03209485720628a0a48e -r 22eba4320d509115b32ae7d56207f66887589dd4 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1117,7 +1117,6 @@
                          ("index", "x"),
                          ("index", "y"),
                          ("index", "z"))
-    vertices = None
     def __init__(self, data_source, surface_field, field_value, ds=None):
         self.data_source = data_source
         self.surface_field = data_source._determine_fields(surface_field)[0]
@@ -1161,7 +1160,7 @@
         verts = self.comm.par_combine_object(verts, op='cat', datatype='array')
         # verts is an ndarray here and will always be in code units, so we
         # expose it in the public API as a YTArray
-        self.vertices = self.ds.arr(verts, 'code_length')
+        self._vertices = self.ds.arr(verts, 'code_length')
         if fields is not None:
             samples = uconcatenate(samples)
             samples = self.comm.par_combine_object(samples, op='cat',
@@ -1278,11 +1277,17 @@
         ret.convert_to_units(self.ds.unit_system[ret_units.dimensions])
         return ret
 
+    _vertices = None
+    @property
+    def vertices(self):
+        if self._vertices is None:
+            self.get_data()
+        return self._vertices
+
     @property
     def triangles(self):
-        if self.vertices is None:
-            self.get_data()
         vv = np.empty((self.vertices.shape[1]//3, 3, 3), dtype="float64")
+        vv = self.ds.arr(vv, self.vertices.units)
         for i in range(3):
             for j in range(3):
                 vv[:,i,j] = self.vertices[j,i::3]


https://bitbucket.org/yt_analysis/yt/commits/546d0e200c5f/
Changeset:   546d0e200c5f
User:        ngoldbaum
Date:        2017-05-19 17:05:05+00:00
Summary:     Only log the field extraction process if we're extracting a non-Null field
Affected #:  1 file

diff -r 22eba4320d509115b32ae7d56207f66887589dd4 -r 546d0e200c5f748504a9fc735b66ff6efd2ccc00 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1144,7 +1144,8 @@
         elif isinstance(fields, list):
             fields = fields[0]
         # Now we have a "fields" value that is either a string or None
-        mylog.info("Extracting (sampling: %s)" % (fields,))
+        if fields is not None:
+            mylog.info("Extracting (sampling: %s)" % (fields,))
         verts = []
         samples = []
         for io_chunk in parallel_objects(self.data_source.chunks([], "io")):


https://bitbucket.org/yt_analysis/yt/commits/1a6ad3a58801/
Changeset:   1a6ad3a58801
User:        ngoldbaum
Date:        2017-05-19 17:05:37+00:00
Summary:     Add a new surface area property of the isosurface data object
Affected #:  1 file

diff -r 546d0e200c5f748504a9fc735b66ff6efd2ccc00 -r 1a6ad3a58801058952a6a62b43faf593aa6c3346 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1294,6 +1294,22 @@
                 vv[:,i,j] = self.vertices[j,i::3]
         return vv
 
+    _surface_area = None
+    @property
+    def surface_area(self):
+        if self._surface_area is not None:
+            return self._surface_area
+        tris = self.triangles
+        x = tris[:, 1, :] - tris[:, 0, :]
+        y = tris[:, 2, :] - tris[:, 0, :]
+        areas = 0.5*np.sqrt(
+            (x[:, 1]*y[:, 2] - x[:, 2]*y[:, 1])**2 +
+            (x[:, 2]*y[:, 0] - x[:, 0]*y[:, 2])**2 +
+            (x[:, 0]*y[:, 1] - x[:, 1]*y[:, 0])**2
+        )
+        self._surface_area = areas.sum()
+        return self._surface_area
+
     def export_obj(self, filename, transparency = 1.0, dist_fac = None,
                    color_field = None, emit_field = None, color_map = None,
                    color_log = True, emit_log = True, plot_index = None,


https://bitbucket.org/yt_analysis/yt/commits/b9669388736e/
Changeset:   b9669388736e
User:        ngoldbaum
Date:        2017-05-19 17:06:24+00:00
Summary:     Set field parameters on blocks. Closes #1407
Affected #:  2 files

diff -r 1a6ad3a58801058952a6a62b43faf593aa6c3346 -r b9669388736e18cfe10c216c42bcf6ddabe34927 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1166,9 +1166,12 @@
                 # For grids this will be a grid object, and for octrees it will
                 # be an OctreeSubset.  Note that we delegate to the sub-object.
                 o = self._current_chunk.objs[0]
+                cache_fp = o.field_parameters.copy()
+                o.field_parameters.update(self.field_parameters)
                 for b, m in o.select_blocks(self.selector):
                     if m is None: continue
                     yield b, m
+                o.field_parameters = cache_fp
 
 class GenerationInProgress(Exception):
     def __init__(self, fields):

diff -r 1a6ad3a58801058952a6a62b43faf593aa6c3346 -r b9669388736e18cfe10c216c42bcf6ddabe34927 yt/data_objects/tests/test_fluxes.py
--- a/yt/data_objects/tests/test_fluxes.py
+++ b/yt/data_objects/tests/test_fluxes.py
@@ -111,3 +111,21 @@
     Nmax = sp1.max('HI_Density')
     sur = ds.surface(sp1,"HI_Density", .5*Nmax)
     sur['x'][0]
+
+ at requires_file(ISOGAL)
+def test_radius_surface():
+    # see #1407
+    ds = load(ISOGAL)
+    reg = ds.all_data()
+    sp = ds.sphere(ds.domain_center, (0.5, 'code_length'))
+    for obj in [reg, sp]:
+        for rad in [0.05, .1, .4]:
+            surface = ds.surface(obj, 'radius', (rad, 'code_length'))
+            assert_almost_equal(
+                surface.surface_area.v, 4*np.pi*rad**2, decimal=2)
+            verts = surface.vertices
+            for i in range(3):
+                assert_almost_equal(
+                    verts[i, :].min().v, 0.5-rad, decimal=2)
+                assert_almost_equal(
+                    verts[i, :].max().v, 0.5+rad, decimal=2)


https://bitbucket.org/yt_analysis/yt/commits/cf28256012b9/
Changeset:   cf28256012b9
User:        ngoldbaum
Date:        2017-05-23 14:13:37+00:00
Summary:     attempt to be more memory efficient when calculating surface areas
Affected #:  1 file

diff -r b9669388736e18cfe10c216c42bcf6ddabe34927 -r cf28256012b94b7dacf5e90a185fe6b3c252a755 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1302,12 +1302,11 @@
         tris = self.triangles
         x = tris[:, 1, :] - tris[:, 0, :]
         y = tris[:, 2, :] - tris[:, 0, :]
-        areas = 0.5*np.sqrt(
-            (x[:, 1]*y[:, 2] - x[:, 2]*y[:, 1])**2 +
-            (x[:, 2]*y[:, 0] - x[:, 0]*y[:, 2])**2 +
-            (x[:, 0]*y[:, 1] - x[:, 1]*y[:, 0])**2
-        )
-        self._surface_area = areas.sum()
+        areas = (x[:, 1]*y[:, 2] - x[:, 2]*y[:, 1])**2
+        np.add(areas, (x[:, 2]*y[:, 0] - x[:, 0]*y[:, 2])**2, out=areas)
+        np.add(areas, (x[:, 0]*y[:, 1] - x[:, 1]*y[:, 0])**2, out=areas)
+        np.sqrt(areas, out=areas)
+        self._surface_area = 0.5*areas.sum()
         return self._surface_area
 
     def export_obj(self, filename, transparency = 1.0, dist_fac = None,


https://bitbucket.org/yt_analysis/yt/commits/795a34ed60c0/
Changeset:   795a34ed60c0
User:        ngoldbaum
Date:        2017-05-25 21:19:57+00:00
Summary:     Merge pull request #1409 from ngoldbaum/surface-fix

Isocontour fixes and enhancements
Affected #:  3 files

diff -r 46b86fe1b681c4deee58e4d9850df853b4d86ec6 -r 795a34ed60c0658469eefa15b8845e2ec5f28ead yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1092,7 +1092,7 @@
     surface_field : string
         Any field that can be obtained in a data object.  This is the field
         which will be isocontoured.
-    field_value : float
+    field_value : float, YTQuantity, or unit tuple
         The value at which the isocontour should be calculated.
 
     Examples
@@ -1117,14 +1117,21 @@
                          ("index", "x"),
                          ("index", "y"),
                          ("index", "z"))
-    vertices = None
     def __init__(self, data_source, surface_field, field_value, ds=None):
         self.data_source = data_source
-        self.surface_field = surface_field
-        self.field_value = field_value
+        self.surface_field = data_source._determine_fields(surface_field)[0]
+        finfo = data_source.ds.field_info[self.surface_field]
+        try:
+            self.field_value = field_value.to(finfo.units)
+        except AttributeError:
+            if isinstance(field_value, tuple):
+                self.field_value = data_source.ds.quan(*field_value)
+                self.field_value = self.field_value.to(finfo.units)
+            else:
+                self.field_value = data_source.ds.quan(field_value, finfo.units)
         self.vertex_samples = YTFieldData()
         center = data_source.get_field_parameter("center")
-        super(YTSurface, self).__init__(center = center, ds=ds)
+        super(YTSurface, self).__init__(center=center, ds=ds)
 
     def _generate_container_field(self, field):
         self.get_data(field)
@@ -1137,7 +1144,8 @@
         elif isinstance(fields, list):
             fields = fields[0]
         # Now we have a "fields" value that is either a string or None
-        mylog.info("Extracting (sampling: %s)" % (fields,))
+        if fields is not None:
+            mylog.info("Extracting (sampling: %s)" % (fields,))
         verts = []
         samples = []
         for io_chunk in parallel_objects(self.data_source.chunks([], "io")):
@@ -1153,7 +1161,7 @@
         verts = self.comm.par_combine_object(verts, op='cat', datatype='array')
         # verts is an ndarray here and will always be in code units, so we
         # expose it in the public API as a YTArray
-        self.vertices = self.ds.arr(verts, 'code_length')
+        self._vertices = self.ds.arr(verts, 'code_length')
         if fields is not None:
             samples = uconcatenate(samples)
             samples = self.comm.par_combine_object(samples, op='cat',
@@ -1270,16 +1278,37 @@
         ret.convert_to_units(self.ds.unit_system[ret_units.dimensions])
         return ret
 
+    _vertices = None
+    @property
+    def vertices(self):
+        if self._vertices is None:
+            self.get_data()
+        return self._vertices
+
     @property
     def triangles(self):
-        if self.vertices is None:
-            self.get_data()
         vv = np.empty((self.vertices.shape[1]//3, 3, 3), dtype="float64")
+        vv = self.ds.arr(vv, self.vertices.units)
         for i in range(3):
             for j in range(3):
                 vv[:,i,j] = self.vertices[j,i::3]
         return vv
 
+    _surface_area = None
+    @property
+    def surface_area(self):
+        if self._surface_area is not None:
+            return self._surface_area
+        tris = self.triangles
+        x = tris[:, 1, :] - tris[:, 0, :]
+        y = tris[:, 2, :] - tris[:, 0, :]
+        areas = (x[:, 1]*y[:, 2] - x[:, 2]*y[:, 1])**2
+        np.add(areas, (x[:, 2]*y[:, 0] - x[:, 0]*y[:, 2])**2, out=areas)
+        np.add(areas, (x[:, 0]*y[:, 1] - x[:, 1]*y[:, 0])**2, out=areas)
+        np.sqrt(areas, out=areas)
+        self._surface_area = 0.5*areas.sum()
+        return self._surface_area
+
     def export_obj(self, filename, transparency = 1.0, dist_fac = None,
                    color_field = None, emit_field = None, color_map = None,
                    color_log = True, emit_log = True, plot_index = None,

diff -r 46b86fe1b681c4deee58e4d9850df853b4d86ec6 -r 795a34ed60c0658469eefa15b8845e2ec5f28ead yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1166,9 +1166,12 @@
                 # For grids this will be a grid object, and for octrees it will
                 # be an OctreeSubset.  Note that we delegate to the sub-object.
                 o = self._current_chunk.objs[0]
+                cache_fp = o.field_parameters.copy()
+                o.field_parameters.update(self.field_parameters)
                 for b, m in o.select_blocks(self.selector):
                     if m is None: continue
                     yield b, m
+                o.field_parameters = cache_fp
 
 class GenerationInProgress(Exception):
     def __init__(self, fields):

diff -r 46b86fe1b681c4deee58e4d9850df853b4d86ec6 -r 795a34ed60c0658469eefa15b8845e2ec5f28ead yt/data_objects/tests/test_fluxes.py
--- a/yt/data_objects/tests/test_fluxes.py
+++ b/yt/data_objects/tests/test_fluxes.py
@@ -111,3 +111,21 @@
     Nmax = sp1.max('HI_Density')
     sur = ds.surface(sp1,"HI_Density", .5*Nmax)
     sur['x'][0]
+
+ at requires_file(ISOGAL)
+def test_radius_surface():
+    # see #1407
+    ds = load(ISOGAL)
+    reg = ds.all_data()
+    sp = ds.sphere(ds.domain_center, (0.5, 'code_length'))
+    for obj in [reg, sp]:
+        for rad in [0.05, .1, .4]:
+            surface = ds.surface(obj, 'radius', (rad, 'code_length'))
+            assert_almost_equal(
+                surface.surface_area.v, 4*np.pi*rad**2, decimal=2)
+            verts = surface.vertices
+            for i in range(3):
+                assert_almost_equal(
+                    verts[i, :].min().v, 0.5-rad, decimal=2)
+                assert_almost_equal(
+                    verts[i, :].max().v, 0.5+rad, decimal=2)

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