[yt-svn] commit/yt: ngoldbaum: Merged in ngoldbaum/yt (pull request #2453)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Dec 19 14:00:50 PST 2016
1 new commit in yt:
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