[yt-svn] commit/yt-3.0: MatthewTurk: Adding the first Nose-compatible test! Thanks to Anthony for walking me

Bitbucket commits-noreply at bitbucket.org
Thu Sep 20 13:23:36 PDT 2012


1 new commit in yt-3.0:


https://bitbucket.org/yt_analysis/yt-3.0/changeset/da10ffc17f6d/
changeset:   da10ffc17f6d
branch:      yt-3.0
user:        MatthewTurk
date:        2012-09-20 04:16:13
summary:     Adding the first Nose-compatible test!  Thanks to Anthony for walking me
through it.  More to come!
affected #:  2 files

diff -r c525efb0940c86e8c42d273c8ee17007f7967a38 -r da10ffc17f6d483fca3eabef4dc7f9db10efdf3b yt/utilities/linear_interpolators.py
--- a/yt/utilities/linear_interpolators.py
+++ b/yt/utilities/linear_interpolators.py
@@ -53,7 +53,8 @@
 
         my_vals = np.zeros(x_vals.shape, dtype='float64')
         lib.UnilinearlyInterpolate(self.table, x_vals, self.x_bins, x_i, my_vals)
-        return my_vals.reshape(orig_shape)
+        my_vals.shape = orig_shape
+        return my_vals
 
 class BilinearFieldInterpolator:
     def __init__(self, table, boundaries, field_names, truncate=False):
@@ -86,7 +87,8 @@
         lib.BilinearlyInterpolate(self.table,
                                  x_vals, y_vals, self.x_bins, self.y_bins,
                                  x_i, y_i, my_vals)
-        return my_vals.reshape(orig_shape)
+        my_vals.shape = orig_shape
+        return my_vals
 
 class TrilinearFieldInterpolator:
     def __init__(self, table, boundaries, field_names, truncate = False):
@@ -125,31 +127,8 @@
                                  x_vals, y_vals, z_vals,
                                  self.x_bins, self.y_bins, self.z_bins,
                                  x_i, y_i, z_i, my_vals)
-        return my_vals.reshape(orig_shape)
-
-        # Use notation from Paul Bourke's page on interpolation
-        # http://local.wasp.uwa.edu.au/~pbourke/other/interpolation/
-        x = (x_vals - self.x_bins[x_i]) / (self.x_bins[x_i+1] - self.x_bins[x_i])
-        y = (y_vals - self.y_bins[y_i]) / (self.y_bins[y_i+1] - self.y_bins[y_i])
-        z = (z_vals - self.z_bins[z_i]) / (self.z_bins[z_i+1] - self.z_bins[z_i])
-        xm = (self.x_bins[x_i+1] - x_vals) / (self.x_bins[x_i+1] - self.x_bins[x_i])
-        ym = (self.y_bins[y_i+1] - y_vals) / (self.y_bins[y_i+1] - self.y_bins[y_i])
-        zm = (self.z_bins[z_i+1] - z_vals) / (self.z_bins[z_i+1] - self.z_bins[z_i])
-        if np.any(np.isnan(self.table)):
-            raise ValueError
-        if np.any(np.isnan(x) | np.isnan(y) | np.isnan(z)):
-            raise ValueError
-        if np.any(np.isnan(xm) | np.isnan(ym) | np.isnan(zm)):
-            raise ValueError
-        my_vals  = self.table[x_i  ,y_i  ,z_i  ] * (xm*ym*zm)
-        my_vals += self.table[x_i+1,y_i  ,z_i  ] * (x *ym*zm)
-        my_vals += self.table[x_i  ,y_i+1,z_i  ] * (xm*y *zm)
-        my_vals += self.table[x_i  ,y_i  ,z_i+1] * (xm*ym*z )
-        my_vals += self.table[x_i+1,y_i  ,z_i+1] * (x *ym*z )
-        my_vals += self.table[x_i  ,y_i+1,z_i+1] * (xm*y *z )
-        my_vals += self.table[x_i+1,y_i+1,z_i  ] * (x *y *zm)
-        my_vals += self.table[x_i+1,y_i+1,z_i+1] * (x *y *z )
-        return my_vals.reshape(orig_shape)
+        my_vals.shape = orig_shape
+        return my_vals
 
 def get_centers(pf, filename, center_cols, radius_col, unit='1'):
     """


diff -r c525efb0940c86e8c42d273c8ee17007f7967a38 -r da10ffc17f6d483fca3eabef4dc7f9db10efdf3b yt/utilities/tests/test_interpolators.py
--- /dev/null
+++ b/yt/utilities/tests/test_interpolators.py
@@ -0,0 +1,13 @@
+import numpy as np
+from numpy.testing import assert_array_equal
+import yt.utilities.linear_interpolators as lin
+
+def setup():
+    pass
+
+
+def test_linear_interpolator():
+    random_data = np.random.random(128)
+    x = {"Random":np.mgrid[0.0:1.0:128j]}
+    ufi = lin.UnilinearFieldInterpolator(random_data, (0.0, 1.0), "Random", True)
+    assert_array_equal(ufi(x), random_data)

Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/

--

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