def test_slice_interpolate_cubic(self): # Construct a 3D array that is a quadratic function. data = sp.arange(140, dtype=float) data.shape = (5, 4, 7) vect = info_header.InfoArray(data) vect = vector.vect_array(vect, axis_names=('freq', 'a', 'b')) v = vect a = sp.arange(-2, 3)**2 a.shape = (5, 1, 1) b = sp.arange(-1, 3)**2 b.shape = (1, 4, 1) c = sp.arange(-1, 6)**2 c.shape = (1, 1, 7) v[:, :, :] = a + b + c v.set_axis_info('freq', 0, 1) v.set_axis_info('a', 1, 1) v.set_axis_info('b', 2, 1) #### First test the weights. # Test cubic conv interpolations in multi D. points, weights = v.slice_interpolate_weights([0, 1, 2], [0, 0, 0], 'cubic') self.assertTrue(1. in weights) self.assertTrue(weights.tolist().count(0) == 63) self.assertTrue(points[sp.where(weights == 1)[0][0]][0] == 2) self.assertTrue(points[sp.where(weights == 1)[0][0]][1] == 1) self.assertTrue(points[sp.where(weights == 1)[0][0]][2] == 1) points, weights = v.slice_interpolate_weights([0, 1, 2], [1.5, 0.5, 0], 'cubic') self.assertTrue(points.shape[0] == 64) self.assertTrue(weights.shape[0] == 64) # Test full interpolation. out = v.slice_interpolate([0, 1, 2], [0, 0, 0], 'cubic') self.assertTrue(sp.allclose(out, 0.0)) out = v.slice_interpolate([0, 1, 2], [-1.34, 0.55, 0.86], 'cubic') self.assertTrue(sp.allclose(out, 2.8377)) # Test partial interpolation. out = v.slice_interpolate([0, 2], [1.4, -0.3], 'cubic') out1 = v.slice_interpolate([0, 1, 2], [1.4, -1, -0.3], 'cubic') out2 = v.slice_interpolate([0, 1, 2], [1.4, 0, -0.3], 'cubic') out3 = v.slice_interpolate([0, 1, 2], [1.4, 1, -0.3], 'cubic') out4 = v.slice_interpolate([0, 1, 2], [1.4, 2, -0.3], 'cubic') self.assertTrue(sp.allclose(out, [out1, out2, out3, out4]))
def setUp(self): data = sp.arange(30, dtype=float) data.shape = (5, 2, 3) self.vect = info_header.InfoArray(data) self.vect = vector.vect_array(self.vect, axis_names=('freq', 'a', 'b')) data = sp.arange(120, dtype=float) self.mat = info_header.InfoArray(data) self.mat.shape = (5, 4, 6) self.mat = matrix.mat_array(self.mat, row_axes=(0, 1), col_axes=(0, 2), axis_names=('freq', 'mode1', 'mode2'))
def test_to_from_file(self): """Test that vects and mats can be written to and from file and have all thier properties preserved.""" # For vectors. file_io.save('temp.npy', self.vect) new_vect = vector.vect_array(file_io.load('temp.npy')) self.assertTrue(sp.allclose(self.vect, new_vect)) self.assertEqual(self.vect.axes, new_vect.axes) # For matricies. file_io.save('temp.npy', self.mat) new_mat = matrix.mat_array(file_io.load('temp.npy')) self.assertTrue(sp.allclose(self.mat, new_mat)) self.assertEqual(self.mat.axes, new_mat.axes) # Messing with stuf should raise exceptions. new_mat = file_io.load('temp.npy') new_mat.info['cols'] = (0, 3) self.assertRaises(ValueError, matrix.mat_array, new_mat) # Clean up os.remove('temp.npy') os.remove('temp.npy.meta')
def test_make_vector_named(self): self.array = vector.vect_array(self.array, ('freq', None, 'ra')) self.assertEqual(self.array.info['axes'], ('freq', None, 'ra')) self.assertEqual(self.array.axes, ('freq', None, 'ra'))
def test_make_vector(self): self.array = vector.vect_array(self.array) self.assertEqual(self.array.info['type'], 'vect') self.assertEqual(self.array.axes, (None, None, None)) self.assertTrue(isinstance(self.array, vector.VectorObject)) self.assertTrue(isinstance(self.array, info_header.InfoArray))