Exemple #1
0
    def test_inv(self):
        pos = np.array([[0., 0., 0.]])
        tracer_pos = np.array([[0.001, 0, 0], [-0.001, 0, 0], [0, 0.001, 0],
                               [0, -0.001, 0], [0, 0, 0.001], [0, 0, -0.001]])
        # Basically we interpolate something based on the average position
        # change, because it's easy for me to visualize.
        interp_data = tracer_pos * 2

        interp = interpolation.interpolant('inv', 6, 3)
        interp.set_scene(tracer_pos, pos, interp_data)

        local = interp.interpolate()
        np.testing.assert_array_equal(local, np.zeros((1, 3)))

        jac = interp.eulerian_jacobian()
        self.failUnless(np.all(jac[:, [0, 1, 2], [0, 1, 2]] != 0))

        # Above test is symmetric. This would catch derivation direction
        # bugs:
        np.testing.assert_array_equal(np.sign(jac[:, [0, 1, 2], [0, 1, 2]]),
                                      np.ones((1, 3)))

        # Check compared to numeric:
        numeric = interpolation.GeneralInterpolant.eulerian_jacobian(interp,
                                                                     eps=1e-6)
        np.testing.assert_array_almost_equal(jac, numeric)

        # Non-diagonal elements:
        jac[:, [0, 1, 2], [0, 1, 2]] = 0
        self.failUnless(np.all(jac == 0))
Exemple #2
0
    def test_interp_rbf(self):
        """Interpolating with rbf method finishes"""
        r = np.r_[0.001, 0.002, 0.003]
        theta = np.r_[:360:45] * np.pi / 180
        tracer_pos = np.array(
            (r[:, None] * np.cos(theta), r[:, None] * np.sin(theta),
             np.zeros((len(r), len(theta))))).transpose().reshape(-1, 3)

        interp_points = np.zeros((1, 3))
        data = np.random.rand(tracer_pos.shape[0], 3)

        interp = interpolation.interpolant('rbf', 4, param=1e5)
        interp.set_scene(tracer_pos, interp_points, data)
Exemple #3
0
 def setUp(self):
     # Tracers are radially placed around one poor particle.
     r = np.r_[0.001, 0.002, 0.003]
     theta = np.r_[:360:45]*np.pi/180
     tracer_pos = np.array((
         r[:,None]*np.cos(theta), r[:,None]*np.sin(theta), 
         np.zeros((len(r), len(theta))) )).transpose().reshape(-1,3)
     self.num_tracers = tracer_pos.shape[0]
     
     interp_points = np.zeros((1,3))
     self.data = np.random.rand(tracer_pos.shape[0], 3)
     
     self.interp = interpolation.interpolant('inv', 4, param=1.5)
     self.interp.set_scene(tracer_pos, interp_points, self.data)
Exemple #4
0
    def setUp(self):
        # Tracers are radially placed around one poor particle.
        r = np.r_[0.001, 0.002, 0.003]
        theta = np.r_[:360:45] * np.pi / 180
        tracer_pos = np.array(
            (r[:, None] * np.cos(theta), r[:, None] * np.sin(theta),
             np.zeros((len(r), len(theta))))).transpose().reshape(-1, 3)
        self.num_tracers = tracer_pos.shape[0]

        interp_points = np.zeros((1, 3))
        self.data = np.random.rand(tracer_pos.shape[0], 3)

        self.interp = interpolation.interpolant('inv', 4, param=1.5)
        self.interp.set_scene(tracer_pos, interp_points, self.data)
Exemple #5
0
 def test_interp_rbf(self):
     """Interpolating with rbf method finishes"""
     r = np.r_[0.001, 0.002, 0.003]
     theta = np.r_[:360:45]*np.pi/180
     tracer_pos = np.array((
         r[:,None]*np.cos(theta), r[:,None]*np.sin(theta), 
         np.zeros((len(r), len(theta))) )).transpose().reshape(-1,3)
     
     interp_points = np.zeros((1,3))
     data = np.random.rand(tracer_pos.shape[0], 3)
     
     interp = interpolation.interpolant('rbf', 4, param=1e5)
     interp.set_scene(tracer_pos, interp_points, data)
     
     interped = interp.interpolate()
     use_parts = interp.current_active_neighbs()
Exemple #6
0
 def test_radius(self):
     """finding neighbours by radius"""
     r = np.r_[0.001, 0.002, 0.003]
     theta = np.r_[:360:45]*np.pi/180
     tracer_pos = np.array((
         r[:,None]*np.cos(theta), r[:,None]*np.sin(theta), 
         np.zeros((len(r), len(theta))) )).transpose().reshape(-1,3)
     
     interp_points = np.zeros((1,3))
     data = np.random.rand(tracer_pos.shape[0], 3)
     
     interp = interpolation.interpolant(
         'inv', num_neighbs=8, radius=0.0015, param=1.5)
     interp.set_scene(tracer_pos, interp_points, data)
     
     interped = interp.interpolate()
     correct_interped = data[::3].mean(axis=0)
     
     np.testing.assert_array_almost_equal(interped[0], correct_interped)
Exemple #7
0
    def test_radius(self):
        """finding neighbours by radius"""
        r = np.r_[0.001, 0.002, 0.003]
        theta = np.r_[:360:45] * np.pi / 180
        tracer_pos = np.array(
            (r[:, None] * np.cos(theta), r[:, None] * np.sin(theta),
             np.zeros((len(r), len(theta))))).transpose().reshape(-1, 3)

        interp_points = np.zeros((1, 3))
        data = np.random.rand(tracer_pos.shape[0], 3)

        interp = interpolation.interpolant('inv',
                                           num_neighbs=8,
                                           radius=0.0015,
                                           param=1.5)
        interp.set_scene(tracer_pos, interp_points, data)

        interped = interp.interpolate()
        correct_interped = data[::3].mean(axis=0)

        np.testing.assert_array_almost_equal(interped[0], correct_interped)
Exemple #8
0
 def test_inv(self):
     pos = np.array([[0.,0.,0.]])
     tracer_pos = np.array([
         [ 0.001, 0, 0],
         [-0.001, 0, 0],
         [0,  0.001, 0],
         [0, -0.001, 0],
         [0, 0,  0.001],
         [0, 0, -0.001]
     ])
     # Basically we interpolate something based on the average position
     # change, because it's easy for me to visualize.
     interp_data = tracer_pos*2
     
     interp = interpolation.interpolant('inv', 6, 3)
     interp.set_scene(tracer_pos, pos, interp_data)
     
     local = interp.interpolate()
     np.testing.assert_array_equal(local, np.zeros((1,3)))
     
     jac = interp.eulerian_jacobian()
     self.failUnless(np.all(jac[:, [0,1,2], [0,1,2]] != 0))
     
     # Above test is symmetric. This would catch derivation direction 
     # bugs:
     np.testing.assert_array_equal(np.sign(jac[:, [0,1,2], [0,1,2]]),
         np.ones((1, 3)))
     
     # Check compared to numeric:
     numeric = interpolation.GeneralInterpolant.eulerian_jacobian(
         interp, eps=1e-6)
     np.testing.assert_array_almost_equal(jac, numeric)
     
     # Non-diagonal elements:
     jac[:, [0,1,2], [0,1,2]] = 0
     self.failUnless(np.all(jac == 0))
Exemple #9
0
Created on Sun Aug 10 17:22:04 2014

@author: yosef
"""

from flowtracks.scene import read_dual_scene
from flowtracks.analysis import analysis, FluidVelocitiesAnalyser
    
if __name__ == "__main__":
    from flowtracks.interpolation import interpolant
    
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('config', help="file containing configuration values.")
    parser.add_argument('output', help="A directory where the generated data "\
        "should be saved as one file per trajectory.")
    parser.add_argument("--method", choices=['inv', 'rbf', 'corrfun'], 
        default='inv', help="Interpolation method (*inv*, rbf, corrfun)")
    parser.add_argument("--neighbs", type=int, help="Number of closest "
        "neighbours from which to interpolate.", default=4)
    parser.add_argument('--param', '-p', help="Interpolation adjustment "
        "parameter. Inverse power for inv, epsilon for RBF, filename for corrfun")
    args = parser.parse_args()
    
    interp = interpolant(args.method, args.neighbs, args.param)
    scene = read_dual_scene(args.config)
    analysers = [ FluidVelocitiesAnalyser(interp) ]
    analysis(scene, args.output, args.config, analysers)