def test_em2numpy(self): """test em2numpy ....................................""" imgfile1 = "test_em2numpy_1.mrc" nx0 = 100 ny0 = 200 TestUtil.make_image_file(imgfile1, IMAGE_MRC, EM_FLOAT, nx0, ny0) e = EMData() e.read_image(imgfile1) nx = e.get_xsize() ny = e.get_ysize() a = EMNumPy.em2numpy(e) n = old_div(ny, 2) for i in range(nx): self.assertEqual(e.get_value_at(i, n), a[n][i]) self.assertEqual(a.shape, (ny0, nx0)) self.assertEqual(a.dtype, "f") for x in range(nx): for y in range(n): a[y][x] = 0 testlib.check_emdata(e, sys.argv[0]) b = a.copy() e2 = EMNumPy.numpy2em(b) testlib.check_emdata(e2, sys.argv[0]) os.unlink(imgfile1)
def test_em2numpy(self): """test em2numpy ....................................""" imgfile1 = "test_em2numpy_1.mrc" nx0 = 100 ny0 = 200 TestUtil.make_image_file(imgfile1, IMAGE_MRC, EM_FLOAT, nx0, ny0) e = EMData() e.read_image(imgfile1) nx = e.get_xsize() ny = e.get_ysize() a = EMNumPy.em2numpy(e) n = ny/2 for i in range(nx): self.assertEqual(e.get_value_at(i, n), a[n][i]) self.assertEqual(a.shape, (ny0, nx0)) self.assertEqual(a.dtype, "f") for x in range(nx): for y in range(n): a[y][x] = 0 testlib.check_emdata(e, sys.argv[0]) b = a.copy() e2 = EMNumPy.numpy2em(b) testlib.check_emdata(e2, sys.argv[0]) os.unlink(imgfile1)
def test_numpy2em(self): """test numpy2em .................................... """ n = 100 l = list(range(2 * n * n)) a = numpy.reshape(numpy.array(l, numpy.float32), (2 * n, n)) self.assertEqual(a.shape, (2 * n, n)) self.assertEqual(a.dtype, "float32") e = EMNumPy.numpy2em(a) testlib.check_emdata(e, sys.argv[0]) for i in range(n): self.assertEqual(e.get_value_at(i, 0), i)
def test_numpy2em(self): """test numpy2em .................................... """ n = 100 l = range(2*n*n) a = numpy.reshape(numpy.array(l, numpy.float32), (2*n, n)) self.assertEqual(a.shape, (2*n, n)) self.assertEqual(a.dtype, "float32") e = EMNumPy.numpy2em(a) testlib.check_emdata(e, sys.argv[0]) for i in range(n): self.assertEqual(e.get_value_at(i, 0), i)
def test_defaultargs(self): """test default arguments ...........................""" imgfile1 = "test_defaultargs_1.mrc" imgfile2 = "test_defaultargs_2.mrc" TestUtil.make_image_file(imgfile1, IMAGE_MRC) TestUtil.make_image_file(imgfile2, IMAGE_MRC) image1 = EMData() image1.read_image(imgfile1) image2 = EMData() image2.read_image(imgfile2) image3 = image1.calc_ccf(image2) testlib.check_emdata(image3, sys.argv[0]) testlib.safe_unlink(imgfile1) testlib.safe_unlink(imgfile2)
def test_Point_and_Size_class(self): """test point and Size class ........................""" imgfile1 = "test_Point_and_Size_class_1.mrc" TestUtil.make_image_file(imgfile1, IMAGE_MRC, EM_FLOAT, 32, 32, 32) img1 = EMData() img1.read_image(imgfile1) ptuple1 = (16, 16, 16) plist1 = list(ptuple1) img2 = img1.get_rotated_clip(Transform(), plist1, 1.0) img3 = img1.get_rotated_clip(Transform(), ptuple1, 1.0) testlib.check_emdata(img2, sys.argv[0]) testlib.check_emdata(img3, sys.argv[0]) os.unlink(imgfile1)
def test_Point_and_Size_class(self): """test point and Size class ........................""" imgfile1 = "test_Point_and_Size_class_1.mrc" TestUtil.make_image_file(imgfile1, IMAGE_MRC, EM_FLOAT, 32,32,32) img1 = EMData() img1.read_image(imgfile1) ptuple1 = (16,16,16) plist1 = list(ptuple1) img2=img1.get_rotated_clip(Transform(), plist1, 1.0) img3=img1.get_rotated_clip(Transform(), ptuple1, 1.0) testlib.check_emdata(img2, sys.argv[0]) testlib.check_emdata(img3, sys.argv[0]) os.unlink(imgfile1)