Example #1
0
def view_surface():
    from enthought.mayavi import mlab
    g = Grid(surface_param)
    xyz_grid = g[-1:1:201j, -1:1:101j]
    x, y, z = xyz_grid.transposed_values
    mlab.mesh(x, y, z)
    mlab.draw()
Example #2
0
def test_grid():
    g = Grid(surface_param)
    xyz_grid = g[-1:1:201j, -1:1:101j]
    x, y, z = xyz_grid.transposed_values
    yield assert_equal, x.shape, (201, 101)
    yield assert_equal, y.shape, (201, 101)
    yield assert_equal, z.shape, (201, 101)
Example #3
0
def test_grid():
    input = CoordinateSystem('ij', 'input')
    output = CoordinateSystem('xy', 'output')
    def f(ij):
        i = ij[:,0]
        j = ij[:,1]
        return np.array([i**2+j,j**3+i]).T
    cmap = CoordinateMap(input, output, f)
    grid = Grid(cmap)
    eval = ArrayCoordMap.from_shape(cmap, (50,40))
    assert_true(np.allclose(grid[0:50,0:40].values, eval.values))
Example #4
0
def test_grid32():
    # Check that we can use a float32 input and output
    uv32 = CoordinateSystem('uv', 'input', np.float32)
    xyz32 = CoordinateSystem('xyz', 'output', np.float32)
    surface32 = CoordinateMap(uv32, xyz32, parametric_mapping)
    g = Grid(surface32)
    xyz_grid = g[-1:1:201j, -1:1:101j]
    x, y, z = xyz_grid.transposed_values
    yield assert_equal, x.shape, (201, 101)
    yield assert_equal, y.shape, (201, 101)
    yield assert_equal, z.shape, (201, 101)
    yield assert_equal, x.dtype, np.dtype(np.float32)
Example #5
0
def test_grid32_c128():
    # Check that we can use a float32 input and complex128 output
    uv32 = CoordinateSystem('uv', 'input', np.float32)
    xyz128 = CoordinateSystem('xyz', 'output', np.complex128)

    def par_c128(x):
        return parametric_mapping(x).astype(np.complex128)

    surface = CoordinateMap(uv32, xyz128, par_c128)
    g = Grid(surface)
    xyz_grid = g[-1:1:201j, -1:1:101j]
    x, y, z = xyz_grid.transposed_values
    yield assert_equal, x.shape, (201, 101)
    yield assert_equal, y.shape, (201, 101)
    yield assert_equal, z.shape, (201, 101)
    yield assert_equal, x.dtype, np.dtype(np.complex128)
Example #6
0
def test_eval_slice():
    input = CoordinateSystem('ij', 'input')
    output = CoordinateSystem('xy', 'output')
    def f(ij):
        i = ij[:,0]
        j = ij[:,1]
        return np.array([i**2+j,j**3+i]).T

    cmap = CoordinateMap(input, output, f)

    cmap = CoordinateMap(input, output, f)
    grid = Grid(cmap)
    e = grid[0:50,0:40]
    ee = e[0:20:3]

    yield assert_equal, ee.shape, (7,40)
    yield assert_equal, ee.values.shape, (280,2)
    yield assert_equal, ee.transposed_values.shape, (2,7,40)

    ee = e[0:20:2,3]
    yield assert_equal, ee.values.shape, (10,2)
    yield assert_equal, ee.transposed_values.shape, (2,10)
    yield assert_equal, ee.shape, (10,)