[yt-svn] commit/yt: xarthisius: Merged in MatthewTurk/yt (pull request #2259)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sat Jul 16 09:01:18 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/b58837b96e9d/
Changeset: b58837b96e9d
Branch: yt
User: xarthisius
Date: 2016-07-16 16:00:49+00:00
Summary: Merged in MatthewTurk/yt (pull request #2259)
[Not a new feature I promise] Adding a morton_index derived field
Affected #: 2 files
diff -r acc390b0a7fec1cb38db9030a9f0e22eac2dcbc2 -r b58837b96e9d93e200ec564f11db913ec4c515e0 yt/fields/geometric_fields.py
--- a/yt/fields/geometric_fields.py
+++ b/yt/fields/geometric_fields.py
@@ -32,6 +32,9 @@
get_cyl_z, get_sph_r, \
get_sph_theta, get_sph_phi
+from yt.utilities.lib.geometry_utils import \
+ compute_morton
+
@register_field_plugin
def setup_geometric_fields(registry, ftype="gas", slice_info=None):
unit_system = registry.ds.unit_system
@@ -111,6 +114,27 @@
units="",
display_field=False)
+ def _morton_index(field, data):
+ """This is the morton index, which is properly a uint64 field. Because
+ we make some assumptions that the fields returned by derived fields are
+ float64, this returns a "view" on the data that is float64. To get
+ back the original uint64, you need to call .view("uint64") on it;
+ however, it should be true that if you sort the uint64, you will get
+ the same order as if you sort the float64 view.
+ """
+ eps = np.finfo("f8").eps
+ uq = data.ds.domain_left_edge.uq
+ LE = data.ds.domain_left_edge - eps * uq
+ RE = data.ds.domain_right_edge + eps * uq
+ # .ravel() only copies if it needs to
+ morton = compute_morton(data["index", "x"].ravel(),
+ data["index", "y"].ravel(),
+ data["index", "z"].ravel(), LE, RE)
+ morton.shape = data["index", "x"].shape
+ return morton.view("f8")
+ registry.add_field(("index", "morton_index"), function=_morton_index,
+ units = "")
+
def _spherical_radius(field, data):
"""The spherical radius component of the positions of the mesh cells.
diff -r acc390b0a7fec1cb38db9030a9f0e22eac2dcbc2 -r b58837b96e9d93e200ec564f11db913ec4c515e0 yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -3,6 +3,7 @@
from yt import \
load
from yt.testing import \
+ fake_amr_ds, \
fake_random_ds, \
fake_particle_ds, \
assert_almost_equal, \
@@ -337,6 +338,15 @@
ds.field_info['all', 'particle_mass_alias']
+def test_morton_index():
+ ds = fake_amr_ds()
+ mi = ds.r["index", "morton_index"]
+ mi2 = mi.view("uint64")
+ assert_equal(np.unique(mi2).size, mi2.size)
+ a1 = np.argsort(mi)
+ a2 = np.argsort(mi2)
+ assert_array_equal(a1, a2)
+
if __name__ == "__main__":
setup()
for t in test_all_fields():
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