[yt-svn] commit/yt: MatthewTurk: Merged in MatthewTurk/yt/yt-3.0 (pull request #883)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed May 7 11:50:59 PDT 2014
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/6347a1dcd087/
Changeset: 6347a1dcd087
Branch: yt-3.0
User: MatthewTurk
Date: 2014-05-07 20:50:51
Summary: Merged in MatthewTurk/yt/yt-3.0 (pull request #883)
Adding first pass at YTPositionArray.
Affected #: 2 files
diff -r bf7a69e38a890425e12e961bc09e9a534ec0113d -r 6347a1dcd0876cc6ab52ab378fa7708b6d41b653 yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -32,6 +32,9 @@
from yt.utilities.lib.geometry_utils import compute_morton
from yt.geometry.particle_oct_container import \
ParticleOctreeContainer
+from yt.units.yt_array import YTArray
+from yt.units.dimensions import length
+from yt.utilities.exceptions import YTInvalidPositionArray
def cell_count_cache(func):
def cc_cache_func(self, dobj):
@@ -333,3 +336,34 @@
@property
def dds(self):
return self._fwidth[0,0,0,self.ind,:]
+
+class YTPositionArray(YTArray):
+ @property
+ def morton(self):
+ self.validate()
+ eps = np.finfo(self.dtype).eps
+ LE = self.min(axis=0) - eps * self.uq
+ RE = self.max(axis=0) + eps * self.uq
+ morton = compute_morton(
+ self[:,0], self[:,1], self[:,2],
+ LE, RE)
+ return morton
+
+ def to_octree(self, over_refine_factor = 1, dims = (1,1,1),
+ n_ref = 64):
+ mi = self.morton
+ mi.sort()
+ eps = np.finfo(self.dtype).eps
+ LE = self.min(axis=0) - eps * self.uq
+ RE = self.max(axis=0) + eps * self.uq
+ octree = ParticleOctreeContainer(dims, LE, RE,
+ over_refine = over_refine_factor)
+ octree.n_ref = n_ref
+ octree.add(mi)
+ octree.finalize()
+ return octree
+
+ def validate(self):
+ if len(self.shape) != 2 or self.shape[1] != 3 \
+ or self.units.dimensions != length:
+ raise YTInvalidPositionArray(self.shape, self.units.dimensions)
diff -r bf7a69e38a890425e12e961bc09e9a534ec0113d -r 6347a1dcd0876cc6ab52ab378fa7708b6d41b653 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -367,3 +367,13 @@
But being asked to add it with:
%s""" % (self.field, self.old_spec, self.new_spec)
return r
+
+class YTInvalidPositionArray(Exception):
+ def __init__(self, shape, dimensions):
+ self.shape = shape
+ self.dimensions = dimensions
+
+ def __str__(self):
+ r = """Position arrays must be length and shape (N,3).
+ But this one has %s and %s.""" % (self.dimensions, self.shape)
+ return r
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