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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Dec 19 14:00:51 PST 2016


9 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/5d1da0aba76e/
Changeset:   5d1da0aba76e
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 18:31:02+00:00
Summary:     Ensure that fields sampled at surfaces are returned with units
Affected #:  3 files

diff -r bb7f23a27456bed189cbd20b0b5cdc968a2f31e0 -r 5d1da0aba76ec40d827fe5ef3fc6482dd8494696 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -56,6 +56,7 @@
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     parallel_objects, parallel_root_only, communication_system
 from yt.units.unit_object import Unit
+from yt.units.yt_array import uconcatenate
 import yt.geometry.particle_deposit as particle_deposit
 from yt.utilities.grid_data_format.writer import write_to_gdf
 from yt.fields.field_exceptions import \
@@ -1120,7 +1121,7 @@
         verts = self.comm.par_combine_object(verts, op='cat', datatype='array')
         self.vertices = verts
         if fields is not None:
-            samples = np.concatenate(samples)
+            samples = uconcatenate(samples)
             samples = self.comm.par_combine_object(samples, op='cat',
                                 datatype='array')
             if sample_type == "face":

diff -r bb7f23a27456bed189cbd20b0b5cdc968a2f31e0 -r 5d1da0aba76ec40d827fe5ef3fc6482dd8494696 yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -268,8 +268,9 @@
         fields = list(set(fields))
         new_fields = {}
         for field in fields:
-            new_fields[field] = np.zeros(self.ActiveDimensions + 1, dtype='float64')
-
+            finfo = self.ds._get_field_info(field)
+            new_fields[field] = self.ds.arr(
+                np.zeros(self.ActiveDimensions + 1), finfo.units)
         if no_ghost:
             for field in fields:
                 # Ensure we have the native endianness in this array.  Avoid making

diff -r bb7f23a27456bed189cbd20b0b5cdc968a2f31e0 -r 5d1da0aba76ec40d827fe5ef3fc6482dd8494696 yt/utilities/lib/marching_cubes.pyx
--- a/yt/utilities/lib/marching_cubes.pyx
+++ b/yt/utilities/lib/marching_cubes.pyx
@@ -20,6 +20,8 @@
 from libc.stdlib cimport malloc, free, abs
 from fixed_interpolator cimport *
 
+from yt.units.yt_array import YTArray
+
 cdef extern from "marching_cubes.h":
     int tri_table[256][16]
     int edge_table[256]
@@ -260,6 +262,8 @@
     sampled = np.zeros(triangles.count * nskip, dtype='float64')
     FillTriangleValues(sampled, triangles.first, nskip)
     FillAndWipeTriangles(vertices, triangles.first)
+    if hasattr(obj_sample, 'units'):
+        sampled = YTArray(sampled, obj_sample.units)
     return vertices, sampled
 
 @cython.boundscheck(False)


https://bitbucket.org/yt_analysis/yt/commits/a40bba34f9f0/
Changeset:   a40bba34f9f0
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 18:53:41+00:00
Summary:     ensure surface vertices have units attached
Affected #:  1 file

diff -r 5d1da0aba76ec40d827fe5ef3fc6482dd8494696 -r a40bba34f9f0e8e3f3416555438404bd68bccfe8 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1119,7 +1119,9 @@
                 verts.append(my_verts)
         verts = np.concatenate(verts).transpose()
         verts = self.comm.par_combine_object(verts, op='cat', datatype='array')
-        self.vertices = verts
+        # 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')
         if fields is not None:
             samples = uconcatenate(samples)
             samples = self.comm.par_combine_object(samples, op='cat',


https://bitbucket.org/yt_analysis/yt/commits/70d1e816805d/
Changeset:   70d1e816805d
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 18:53:51+00:00
Summary:     ensure isocontour fluxes are returned with units attached
Affected #:  1 file

diff -r a40bba34f9f0e8e3f3416555438404bd68bccfe8 -r 70d1e816805d9c5212827d3a8c1325961236fa44 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1225,11 +1225,18 @@
             ff = np.ones_like(vc_data[self.surface_field], dtype="float64")
         else:
             ff = vc_data[fluxing_field]
-
-        return march_cubes_grid_flux(
-            self.field_value, vc_data[self.surface_field], vc_data[field_x],
-            vc_data[field_y], vc_data[field_z], ff, mask, grid.LeftEdge,
-            grid.dds)
+        surf_vals = vc_data[self.surface_field]
+        field_x_vals = vc_data[field_x]
+        field_y_vals = vc_data[field_y]
+        field_z_vals = vc_data[field_z]
+        ret = march_cubes_grid_flux(
+            self.field_value, surf_vals, field_x_vals, field_y_vals, field_z_vals,
+            ff, mask, grid.LeftEdge, grid.dds)
+        # assumes all the fluxing fields have the same units
+        ret_units = field_x_vals.units * ff.units * grid.dds.units**2
+        ret = self.ds.arr(ret, ret_units)
+        ret.convert_to_units(self.ds.unit_system[ret_units.dimensions])
+        return ret
 
     @property
     def triangles(self):


https://bitbucket.org/yt_analysis/yt/commits/c1018a426bd7/
Changeset:   c1018a426bd7
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 20:34:11+00:00
Summary:     Convert isocontour tests to not yield asserts
Affected #:  1 file

diff -r 70d1e816805d9c5212827d3a8c1325961236fa44 -r c1018a426bd718eb73816bd2d7c0bea89a198f1f yt/data_objects/tests/test_fluxes.py
--- a/yt/data_objects/tests/test_fluxes.py
+++ b/yt/data_objects/tests/test_fluxes.py
@@ -11,9 +11,9 @@
     ds = fake_random_ds(64, nprocs = 4)
     dd = ds.all_data()
     surf = ds.surface(dd, "x", 0.51)
-    yield assert_equal, surf["x"], 0.51
+    assert_equal(surf["x"], 0.51)
     flux = surf.calculate_flux("ones", "zeros", "zeros", "ones")
-    yield assert_almost_equal, flux, 1.0, 12
+    assert_almost_equal(flux.value, 1.0, 12)
 
 def test_sampling():
     ds = fake_random_ds(64, nprocs = 4)
@@ -21,4 +21,4 @@
     for i, ax in enumerate('xyz'):
         surf = ds.surface(dd, ax, 0.51)
         surf.get_data(ax, "vertex")
-        yield assert_equal, surf.vertex_samples[ax], surf.vertices[i,:]
+        assert_equal(surf.vertex_samples[ax], surf.vertices[i,:])


https://bitbucket.org/yt_analysis/yt/commits/76c06441ca64/
Changeset:   76c06441ca64
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 21:02:55+00:00
Summary:     fix some numpy warnings about float indexing on python3
Affected #:  1 file

diff -r c1018a426bd718eb73816bd2d7c0bea89a198f1f -r 76c06441ca642664852b702179daef709bbf3af7 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1758,7 +1758,7 @@
             arr = np.empty(cs.shape[0], dtype=np.dtype(fs))
             self._color_samples(cs, color_log, color_map, arr)
         else:
-            arr = np.empty(nv/3, np.dtype(fs[:-3]))
+            arr = np.empty(nv//3, np.dtype(fs[:-3]))
         for i, ax in enumerate("xyz"):
             # Do the bounds first since we cast to f32
             tmp = self.vertices[i,:]
@@ -1771,7 +1771,7 @@
         v.tofile(f)
         arr["ni"][:] = 3
         vi = np.arange(nv, dtype="<i")
-        vi.shape = (nv/3, 3)
+        vi.shape = (nv//3, 3)
         arr["v1"][:] = vi[:,0]
         arr["v2"][:] = vi[:,1]
         arr["v3"][:] = vi[:,2]


https://bitbucket.org/yt_analysis/yt/commits/f065b3fafaa8/
Changeset:   f065b3fafaa8
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 21:39:22+00:00
Summary:     further int division fun
Affected #:  1 file

diff -r 76c06441ca642664852b702179daef709bbf3af7 -r f065b3fafaa8166a30546ecbf55ff680753a24c8 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1242,7 +1242,7 @@
     def triangles(self):
         if self.vertices is None:
             self.get_data()
-        vv = np.empty((self.vertices.shape[1]/3, 3, 3), dtype="float64")
+        vv = np.empty((self.vertices.shape[1]//3, 3, 3), dtype="float64")
         for i in range(3):
             for j in range(3):
                 vv[:,i,j] = self.vertices[j,i::3]
@@ -1445,16 +1445,16 @@
             fmtl.write("# www.yt-project.com\n\n")
         #(0) formulate vertices
         nv = self.vertices.shape[1] # number of groups of vertices
-        f = np.empty(nv/self.vertices.shape[0], dtype=ftype) # store sets of face colors
+        f = np.empty(nv//self.vertices.shape[0], dtype=ftype) # store sets of face colors
         v = np.empty(nv, dtype=vtype) # stores vertices
         if color_field is not None:
             cs = self[color_field]
         else:
-            cs = np.empty(self.vertices.shape[1]/self.vertices.shape[0])
+            cs = np.empty(self.vertices.shape[1]//self.vertices.shape[0])
         if emit_field is not None:
             em = self[emit_field]
         else:
-            em = np.empty(self.vertices.shape[1]/self.vertices.shape[0])
+            em = np.empty(self.vertices.shape[1]//self.vertices.shape[0])
         self._color_samples_obj(cs, em, color_log, emit_log, color_map, f,
                                 color_field_max, color_field_min,  color_field,
                                 emit_field_max, emit_field_min, emit_field) # map color values to color scheme


https://bitbucket.org/yt_analysis/yt/commits/07d2528504b0/
Changeset:   07d2528504b0
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 21:40:58+00:00
Summary:     correct units in export_obj example
Affected #:  1 file

diff -r f065b3fafaa8166a30546ecbf55ff680753a24c8 -r 07d2528504b02feb6bd4bbc91b876225fb6e9b64 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -1324,7 +1324,8 @@
         >>> def _Emissivity(field, data):
         ...     return (data['density']*data['density'] *
         ...             np.sqrt(data['temperature']))
-        >>> ds.add_field("emissivity", function=_Emissivity, units=r"g*K/cm**6")
+        >>> ds.add_field("emissivity", function=_Emissivity,
+        ...              sampling_type='cell', units=r"g**2*sqrt(K)/cm**6")
         >>> for i, r in enumerate(rhos):
         ...     surf = ds.surface(sp,'density',r)
         ...     surf.export_obj("my_galaxy", transparency=trans[i],


https://bitbucket.org/yt_analysis/yt/commits/beb8260ce976/
Changeset:   beb8260ce976
Branch:      yt
User:        ngoldbaum
Date:        2016-12-01 21:41:44+00:00
Summary:     Add export_obj and export_ply tests
Affected #:  1 file

diff -r 07d2528504b02feb6bd4bbc91b876225fb6e9b64 -r beb8260ce976dbe5cf138c430b57b2eb10fb7ce5 yt/data_objects/tests/test_fluxes.py
--- a/yt/data_objects/tests/test_fluxes.py
+++ b/yt/data_objects/tests/test_fluxes.py
@@ -1,7 +1,19 @@
+import os
+import shutil
+import tempfile
+
+import numpy as np
+
+from unittest import TestCase
+
 from yt.testing import \
     fake_random_ds, \
     assert_almost_equal, \
-    assert_equal
+    assert_equal, \
+    requires_file
+
+from yt.convenience import \
+    load
 
 def setup():
     from yt.config import ytcfg
@@ -14,6 +26,7 @@
     assert_equal(surf["x"], 0.51)
     flux = surf.calculate_flux("ones", "zeros", "zeros", "ones")
     assert_almost_equal(flux.value, 1.0, 12)
+    assert_equal(str(flux.units), 'cm**2')
 
 def test_sampling():
     ds = fake_random_ds(64, nprocs = 4)
@@ -22,3 +35,69 @@
         surf = ds.surface(dd, ax, 0.51)
         surf.get_data(ax, "vertex")
         assert_equal(surf.vertex_samples[ax], surf.vertices[i,:])
+        assert_equal(str(surf.vertices.units), 'code_length')
+        dens = surf['density']
+        vert_shape = surf.vertices.shape
+        assert_equal(dens.shape[0], vert_shape[1]//vert_shape[0])
+        assert_equal(str(dens.units), 'g/cm**3')
+
+ISOGAL = 'IsolatedGalaxy/galaxy0030/galaxy0030'
+
+class ExporterTests(TestCase):
+
+    def setUp(self):
+        self.curdir = os.getcwd()
+        self.tmpdir = tempfile.mkdtemp()
+        os.chdir(self.tmpdir)
+
+    def tearDown(self):
+        os.chdir(self.curdir)
+        shutil.rmtree(self.tmpdir)
+
+    def test_export_ply(self):
+        ds = fake_random_ds(64, nprocs = 4)
+        dd = ds.all_data()
+        surf = ds.surface(dd, 'x', 0.51)
+        surf.export_ply('my_ply.ply', bounds=[(0, 1), (0, 1), (0, 1)])
+        assert os.path.exists('my_ply.ply')
+
+    @requires_file(ISOGAL)
+    def test_export_obj(self):
+        ds = load(ISOGAL)
+        sp = ds.sphere("max", (10, "kpc"))
+        trans = 1.0
+        distf = 3.1e18*1e3 # distances into kpc
+        surf = ds.surface(sp, "density", 5e-27)
+        surf.export_obj("my_galaxy", transparency=trans, dist_fac = distf)
+        assert os.path.exists('my_galaxy.obj')
+        assert os.path.exists('my_galaxy.mtl')
+
+        mi, ma = sp.quantities.extrema('temperature')
+        rhos = [1e-24, 1e-25]
+        trans = [0.5, 1.0]
+        for i, r in enumerate(rhos):
+            surf = ds.surface(sp,'density',r)
+            surf.export_obj("my_galaxy_color".format(i),
+                            transparency=trans[i],
+                            color_field='temperature', dist_fac = distf,
+                            plot_index = i, color_field_max = ma,
+                            color_field_min = mi)
+
+        assert os.path.exists('my_galaxy_color.obj')
+        assert os.path.exists('my_galaxy_color.mtl')
+
+        def _Emissivity(field, data):
+            return (data['density']*data['density'] *
+                    np.sqrt(data['temperature']))
+        ds.add_field("emissivity", sampling_type='cell', function=_Emissivity,
+                     units=r"g**2*sqrt(K)/cm**6")
+        for i, r in enumerate(rhos):
+            surf = ds.surface(sp,'density',r)
+            surf.export_obj("my_galaxy_emis".format(i),
+                            transparency=trans[i],
+                            color_field='temperature',
+                            emit_field='emissivity',
+                            dist_fac = distf, plot_index = i)
+
+        assert os.path.exists('my_galaxy_emis.obj')
+        assert os.path.exists('my_galaxy_emis.mtl')


https://bitbucket.org/yt_analysis/yt/commits/97ae0cc375fb/
Changeset:   97ae0cc375fb
Branch:      yt
User:        ngoldbaum
Date:        2016-12-19 22:00:24+00:00
Summary:     Merged in ngoldbaum/yt (pull request #2453)

[API change?] Units overhaul for isocontours
Affected #:  4 files

diff -r 3b3b2900d417d4574e977175b883f7e3375dd1a7 -r 97ae0cc375fb2ec473e7c95e2afe27c4b152a53a yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -56,6 +56,7 @@
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     parallel_objects, parallel_root_only, communication_system
 from yt.units.unit_object import Unit
+from yt.units.yt_array import uconcatenate
 import yt.geometry.particle_deposit as particle_deposit
 from yt.utilities.grid_data_format.writer import write_to_gdf
 from yt.fields.field_exceptions import \
@@ -1120,9 +1121,11 @@
                 verts.append(my_verts)
         verts = np.concatenate(verts).transpose()
         verts = self.comm.par_combine_object(verts, op='cat', datatype='array')
-        self.vertices = verts
+        # 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')
         if fields is not None:
-            samples = np.concatenate(samples)
+            samples = uconcatenate(samples)
             samples = self.comm.par_combine_object(samples, op='cat',
                                 datatype='array')
             if sample_type == "face":
@@ -1224,17 +1227,24 @@
             ff = np.ones_like(vc_data[self.surface_field], dtype="float64")
         else:
             ff = vc_data[fluxing_field]
-
-        return march_cubes_grid_flux(
-            self.field_value, vc_data[self.surface_field], vc_data[field_x],
-            vc_data[field_y], vc_data[field_z], ff, mask, grid.LeftEdge,
-            grid.dds)
+        surf_vals = vc_data[self.surface_field]
+        field_x_vals = vc_data[field_x]
+        field_y_vals = vc_data[field_y]
+        field_z_vals = vc_data[field_z]
+        ret = march_cubes_grid_flux(
+            self.field_value, surf_vals, field_x_vals, field_y_vals, field_z_vals,
+            ff, mask, grid.LeftEdge, grid.dds)
+        # assumes all the fluxing fields have the same units
+        ret_units = field_x_vals.units * ff.units * grid.dds.units**2
+        ret = self.ds.arr(ret, ret_units)
+        ret.convert_to_units(self.ds.unit_system[ret_units.dimensions])
+        return ret
 
     @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 = np.empty((self.vertices.shape[1]//3, 3, 3), dtype="float64")
         for i in range(3):
             for j in range(3):
                 vv[:,i,j] = self.vertices[j,i::3]
@@ -1316,7 +1326,8 @@
         >>> def _Emissivity(field, data):
         ...     return (data['density']*data['density'] *
         ...             np.sqrt(data['temperature']))
-        >>> ds.add_field("emissivity", function=_Emissivity, units=r"g*K/cm**6")
+        >>> ds.add_field("emissivity", function=_Emissivity,
+        ...              sampling_type='cell', units=r"g**2*sqrt(K)/cm**6")
         >>> for i, r in enumerate(rhos):
         ...     surf = ds.surface(sp,'density',r)
         ...     surf.export_obj("my_galaxy", transparency=trans[i],
@@ -1437,16 +1448,16 @@
             fmtl.write("# www.yt-project.com\n\n")
         #(0) formulate vertices
         nv = self.vertices.shape[1] # number of groups of vertices
-        f = np.empty(nv/self.vertices.shape[0], dtype=ftype) # store sets of face colors
+        f = np.empty(nv//self.vertices.shape[0], dtype=ftype) # store sets of face colors
         v = np.empty(nv, dtype=vtype) # stores vertices
         if color_field is not None:
             cs = self[color_field]
         else:
-            cs = np.empty(self.vertices.shape[1]/self.vertices.shape[0])
+            cs = np.empty(self.vertices.shape[1]//self.vertices.shape[0])
         if emit_field is not None:
             em = self[emit_field]
         else:
-            em = np.empty(self.vertices.shape[1]/self.vertices.shape[0])
+            em = np.empty(self.vertices.shape[1]//self.vertices.shape[0])
         self._color_samples_obj(cs, em, color_log, emit_log, color_map, f,
                                 color_field_max, color_field_min,  color_field,
                                 emit_field_max, emit_field_min, emit_field) # map color values to color scheme
@@ -1750,7 +1761,7 @@
             arr = np.empty(cs.shape[0], dtype=np.dtype(fs))
             self._color_samples(cs, color_log, color_map, arr)
         else:
-            arr = np.empty(nv/3, np.dtype(fs[:-3]))
+            arr = np.empty(nv//3, np.dtype(fs[:-3]))
         for i, ax in enumerate("xyz"):
             # Do the bounds first since we cast to f32
             tmp = self.vertices[i,:]
@@ -1763,7 +1774,7 @@
         v.tofile(f)
         arr["ni"][:] = 3
         vi = np.arange(nv, dtype="<i")
-        vi.shape = (nv/3, 3)
+        vi.shape = (nv//3, 3)
         arr["v1"][:] = vi[:,0]
         arr["v2"][:] = vi[:,1]
         arr["v3"][:] = vi[:,2]

diff -r 3b3b2900d417d4574e977175b883f7e3375dd1a7 -r 97ae0cc375fb2ec473e7c95e2afe27c4b152a53a yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -268,8 +268,9 @@
         fields = list(set(fields))
         new_fields = {}
         for field in fields:
-            new_fields[field] = np.zeros(self.ActiveDimensions + 1, dtype='float64')
-
+            finfo = self.ds._get_field_info(field)
+            new_fields[field] = self.ds.arr(
+                np.zeros(self.ActiveDimensions + 1), finfo.units)
         if no_ghost:
             for field in fields:
                 # Ensure we have the native endianness in this array.  Avoid making

diff -r 3b3b2900d417d4574e977175b883f7e3375dd1a7 -r 97ae0cc375fb2ec473e7c95e2afe27c4b152a53a yt/data_objects/tests/test_fluxes.py
--- a/yt/data_objects/tests/test_fluxes.py
+++ b/yt/data_objects/tests/test_fluxes.py
@@ -1,7 +1,19 @@
+import os
+import shutil
+import tempfile
+
+import numpy as np
+
+from unittest import TestCase
+
 from yt.testing import \
     fake_random_ds, \
     assert_almost_equal, \
-    assert_equal
+    assert_equal, \
+    requires_file
+
+from yt.convenience import \
+    load
 
 def setup():
     from yt.config import ytcfg
@@ -11,9 +23,10 @@
     ds = fake_random_ds(64, nprocs = 4)
     dd = ds.all_data()
     surf = ds.surface(dd, "x", 0.51)
-    yield assert_equal, surf["x"], 0.51
+    assert_equal(surf["x"], 0.51)
     flux = surf.calculate_flux("ones", "zeros", "zeros", "ones")
-    yield assert_almost_equal, flux, 1.0, 12
+    assert_almost_equal(flux.value, 1.0, 12)
+    assert_equal(str(flux.units), 'cm**2')
 
 def test_sampling():
     ds = fake_random_ds(64, nprocs = 4)
@@ -21,4 +34,70 @@
     for i, ax in enumerate('xyz'):
         surf = ds.surface(dd, ax, 0.51)
         surf.get_data(ax, "vertex")
-        yield assert_equal, surf.vertex_samples[ax], surf.vertices[i,:]
+        assert_equal(surf.vertex_samples[ax], surf.vertices[i,:])
+        assert_equal(str(surf.vertices.units), 'code_length')
+        dens = surf['density']
+        vert_shape = surf.vertices.shape
+        assert_equal(dens.shape[0], vert_shape[1]//vert_shape[0])
+        assert_equal(str(dens.units), 'g/cm**3')
+
+ISOGAL = 'IsolatedGalaxy/galaxy0030/galaxy0030'
+
+class ExporterTests(TestCase):
+
+    def setUp(self):
+        self.curdir = os.getcwd()
+        self.tmpdir = tempfile.mkdtemp()
+        os.chdir(self.tmpdir)
+
+    def tearDown(self):
+        os.chdir(self.curdir)
+        shutil.rmtree(self.tmpdir)
+
+    def test_export_ply(self):
+        ds = fake_random_ds(64, nprocs = 4)
+        dd = ds.all_data()
+        surf = ds.surface(dd, 'x', 0.51)
+        surf.export_ply('my_ply.ply', bounds=[(0, 1), (0, 1), (0, 1)])
+        assert os.path.exists('my_ply.ply')
+
+    @requires_file(ISOGAL)
+    def test_export_obj(self):
+        ds = load(ISOGAL)
+        sp = ds.sphere("max", (10, "kpc"))
+        trans = 1.0
+        distf = 3.1e18*1e3 # distances into kpc
+        surf = ds.surface(sp, "density", 5e-27)
+        surf.export_obj("my_galaxy", transparency=trans, dist_fac = distf)
+        assert os.path.exists('my_galaxy.obj')
+        assert os.path.exists('my_galaxy.mtl')
+
+        mi, ma = sp.quantities.extrema('temperature')
+        rhos = [1e-24, 1e-25]
+        trans = [0.5, 1.0]
+        for i, r in enumerate(rhos):
+            surf = ds.surface(sp,'density',r)
+            surf.export_obj("my_galaxy_color".format(i),
+                            transparency=trans[i],
+                            color_field='temperature', dist_fac = distf,
+                            plot_index = i, color_field_max = ma,
+                            color_field_min = mi)
+
+        assert os.path.exists('my_galaxy_color.obj')
+        assert os.path.exists('my_galaxy_color.mtl')
+
+        def _Emissivity(field, data):
+            return (data['density']*data['density'] *
+                    np.sqrt(data['temperature']))
+        ds.add_field("emissivity", sampling_type='cell', function=_Emissivity,
+                     units=r"g**2*sqrt(K)/cm**6")
+        for i, r in enumerate(rhos):
+            surf = ds.surface(sp,'density',r)
+            surf.export_obj("my_galaxy_emis".format(i),
+                            transparency=trans[i],
+                            color_field='temperature',
+                            emit_field='emissivity',
+                            dist_fac = distf, plot_index = i)
+
+        assert os.path.exists('my_galaxy_emis.obj')
+        assert os.path.exists('my_galaxy_emis.mtl')

diff -r 3b3b2900d417d4574e977175b883f7e3375dd1a7 -r 97ae0cc375fb2ec473e7c95e2afe27c4b152a53a yt/utilities/lib/marching_cubes.pyx
--- a/yt/utilities/lib/marching_cubes.pyx
+++ b/yt/utilities/lib/marching_cubes.pyx
@@ -21,6 +21,8 @@
 from libc.math cimport sqrt
 from fixed_interpolator cimport *
 
+from yt.units.yt_array import YTArray
+
 cdef extern from "marching_cubes.h":
     int tri_table[256][16]
     int edge_table[256]
@@ -261,6 +263,8 @@
     sampled = np.zeros(triangles.count * nskip, dtype='float64')
     FillTriangleValues(sampled, triangles.first, nskip)
     FillAndWipeTriangles(vertices, triangles.first)
+    if hasattr(obj_sample, 'units'):
+        sampled = YTArray(sampled, obj_sample.units)
     return vertices, sampled
 
 @cython.boundscheck(False)

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