def test_make_image(self): """test make hdf image file .........................""" imgfile = "test_make_image_1.h5" TestUtil.make_image_file(imgfile, IMAGE_HDF, EM_FLOAT) err = TestUtil.verify_image_file(imgfile, IMAGE_HDF, EM_FLOAT) self.assertEqual(err, 0) testlib.safe_unlink(imgfile)
def test_write_spider_stack(self): """test to write a spider stack image file .........""" try: if(os.path.isfile('test.spi')): testlib.safe_unlink('test.spi') e = EMData() e.set_size(100,100) e.process_inplace('testimage.squarecube', {'edge_length':20}) e.write_image('test.spi', 0) e.process_inplace('testimage.circlesphere', {'radius':20}) e.write_image('test.spi', 1) e.process_inplace('testimage.gaussian', {'sigma':20}) e.write_image('test.spi', 2) e.process_inplace('testimage.sinewave', {'wavelength':20}) e.set_attr('SPIDER.title', 'The fourth image in the stack') e.write_image('test.spi', 3) f = EMData() #read the overall herder f.read_image('test.spi', -1, True) d = f.get_attr_dict() img_num = d['SPIDER.maxim'] #read the individual image from a stack for i in range(img_num): f.read_image('test.spi', i) self.assertEqual(f.is_complex(), False) self.assertEqual(f.get_xsize(), 100) self.assertEqual(f.get_ysize(), 100) self.assertEqual(f.get_zsize(), 1) finally: testlib.safe_unlink('test.spi')
def test_hdf_8bit_IO(self): """test read/write 8 bit HDF5........................""" file = '8bit.hdf' e = test_image() e.write_image(file, -1, EMUtil.ImageType.IMAGE_HDF, False, None, EMUtil.EMDataType.EM_UCHAR) e2 = EMData(file) self.assertEqual(e2.get_attr('datatype'), EMUtil.EMDataType.EM_UCHAR) testlib.safe_unlink(file)
def test_RotateTranslateFlipAligner(self): """test RotateTranslateFlip Aligner .................""" e = EMData() e.set_size(32, 32, 1) e.process_inplace("testimage.noise.uniform.rand") e2 = EMData() e2.set_size(32, 32, 1) e2.process_inplace("testimage.noise.uniform.rand") e.align("rotate_translate_flip", e2, {"maxshift": 1}) for y in [64, 65]: for x in [64, 65]: size = (x, y) ref = test_image(0, size) ref.translate(4, 5, 0) # give it handedness for i in range(0, 20): mirror = Util.get_irand(0, 1) e = ref.copy() dx = Util.get_frand(-3, 3) dy = Util.get_frand(-3, 3) az = Util.get_frand(0, 360) t = Transform({"type": "2d", "alpha": az}) t.set_trans(Vec2f(dx, dy)) t.set_mirror(mirror) e.transform(t) e.write_image("e.hdf", -1) g = ref.align("rotate_translate_flip", e, {}, "phase") g.write_image("e.hdf", -1) t1 = g.get_attr("xform.align2d") # params = t1.get_params("2d") # params2 = t.get_params("2d") # t.invert() # print params2 # print params # print fabs(params["tx"] - params2["tx"]) # print fabs(params["ty"] - params2["ty"]) # # self.failIf(fabs(params["tx"] - params2["tx"]) > 1) # self.failIf(fabs(params["ty"] - params2["ty"]) > 1) # result = fabs(params["alpha"] - params2["alpha"]) # #print g.get_attr("align.az"), az # if result > 180 and result < 360: # result = 360-result # if result > 360: result = result-360 # self.failIf( result > 3 ) # 3 seems accurate enough # # # self.failIf( params2["mirror"] != params["mirror"] ) # 3 seems accurate enough # # we have to do it this way because of double to float conversions f = ref.process("xform", {"transform": t1}) dif = f - g dif.process_inplace("math.absvalue") self.failIf(dif["mean"] > 0.01) testlib.safe_unlink("e.hdf")
def test_RotateTranslateFlipAligner(self): """test RotateTranslateFlip Aligner .................""" e = EMData() e.set_size(32, 32, 1) e.process_inplace('testimage.noise.uniform.rand') e2 = EMData() e2.set_size(32, 32, 1) e2.process_inplace('testimage.noise.uniform.rand') e.align('rotate_translate_flip', e2, {'maxshift': 1}) for y in [64, 65]: for x in [64, 65]: size = (x, y) ref = test_image(0, size) ref.translate(4, 5, 0) # give it handedness for i in range(0, 20): mirror = Util.get_irand(0, 1) e = ref.copy() dx = Util.get_frand(-3, 3) dy = Util.get_frand(-3, 3) az = Util.get_frand(0, 360) t = Transform({"type": "2d", "alpha": az}) t.set_trans(Vec2f(dx, dy)) t.set_mirror(mirror) e.transform(t) e.write_image("e.hdf", -1) g = ref.align("rotate_translate_flip", e, {}, "phase") g.write_image("e.hdf", -1) t1 = g.get_attr("xform.align2d") # params = t1.get_params("2d") # params2 = t.get_params("2d") # t.invert() # print params2 # print params # print fabs(params["tx"] - params2["tx"]) # print fabs(params["ty"] - params2["ty"]) # # self.failIf(fabs(params["tx"] - params2["tx"]) > 1) # self.failIf(fabs(params["ty"] - params2["ty"]) > 1) # result = fabs(params["alpha"] - params2["alpha"]) # #print g.get_attr("align.az"), az # if result > 180 and result < 360: # result = 360-result # if result > 360: result = result-360 # self.failIf( result > 3 ) # 3 seems accurate enough # # # self.failIf( params2["mirror"] != params["mirror"] ) # 3 seems accurate enough # # we have to do it this way because of double to float conversions f = ref.process("xform", {"transform": t1}) dif = f - g dif.process_inplace("math.absvalue") self.failIf(dif["mean"] > 0.01) testlib.safe_unlink('e.hdf')
def test_overwrite_spider(self): """test overwrite spider image file .................""" try: file1 = "test_overwrite_spider.spi" nx1 = 24 ny1 = 32 TestUtil.make_image_file(file1, IMAGE_SINGLE_SPIDER, EM_FLOAT, nx1, ny1) TestUtil.make_image_file(file1, IMAGE_SINGLE_SPIDER, EM_FLOAT, nx1*2, ny1*2) finally: testlib.safe_unlink(file1)
def test_8bit_image(self): """test unsigned char df3 image I/O .................""" e = test_image() e.write_image(self.imgfile, -1, EMUtil.ImageType.IMAGE_DF3, False, None, EMUtil.EMDataType.EM_UCHAR) f = EMData() f.read_image(self.imgfile) self.assertEqual(f.get_attr('nx'), 128) self.assertEqual(f.get_attr('ny'), 128) self.assertEqual(f.get_attr('nz'), 1) testlib.safe_unlink(self.imgfile)
def no_test_write_transform_mrc(self): """test write mrc header info from Transform object .""" filename = 'test_write_transform.' img = EMData(32,32) img.process_inplace('testimage.noise.uniform.rand') t3d = Transform() t3d.set_rotation({'type':'imagic', 'alpha':1.56, 'beta':2.56, 'gamma':3.56}) t3d.set_trans(10.78, 20.78, 30.78) img.set_attr('xform.projection', t3d) img.write_image(filename+'mrc') del img img2 = EMData(filename+'mrc') self.assertAlmostEqual(img2.get_attr('MRC.alpha'), 1.56, 3) self.assertAlmostEqual(img2.get_attr('MRC.beta'), 2.56, 3) self.assertAlmostEqual(img2.get_attr('MRC.gamma'), 3.56, 3) self.assertAlmostEqual(img2.get_attr('origin_x'), 10.78, 3) self.assertAlmostEqual(img2.get_attr('origin_y'), 20.78, 3) self.assertAlmostEqual(img2.get_attr('origin_z'), 30.78, 3) trans = img2.get_attr('xform.projection') d = trans.get_params('imagic') self.assertAlmostEqual(d['alpha'], 0.0, 3) self.assertAlmostEqual(d['beta'], 0.0, 3) self.assertAlmostEqual(d['gamma'], 0.0, 3) self.assertAlmostEqual(d['MRC.nxstart'], 10.78, 3) self.assertAlmostEqual(d['MRC.nxstart'], 20.78, 3) self.assertAlmostEqual(d['MRC.nxstart'], 30.78, 3) del img2 testlib.safe_unlink(filename+'mrc') filename2 = 'test_write_transform2.' img = EMData(32,32,32) img.process_inplace('testimage.noise.uniform.rand') t3d = Transform() t3d.set_rotation({'type':'imagic', 'alpha':1.56, 'beta':2.56, 'gamma':3.56}) t3d.set_trans(10.78, 20.78, 30.78) img.set_attr('xform.align3d', t3d) img.write_image(filename2+'mrc') img2 = EMData(filename2+'mrc') self.assertAlmostEqual(img2.get_attr('MRC.alpha'), 1.56, 3) self.assertAlmostEqual(img2.get_attr('MRC.beta'), 2.56, 3) self.assertAlmostEqual(img2.get_attr('MRC.gamma'), 3.56, 3) self.assertAlmostEqual(img2.get_attr('origin_x'), 10.78, 3) self.assertAlmostEqual(img2.get_attr('origin_y'), 20.78, 3) self.assertAlmostEqual(img2.get_attr('origin_z'), 30.78, 3) trans2 = img2.get_attr('xform.align3d') d2 = trans2.get_params('imagic') self.assertAlmostEqual(d2['alpha'], 1.56, 3) self.assertAlmostEqual(d2['beta'], 2.56, 3) self.assertAlmostEqual(d2['gamma'], 3.56, 3) self.assertAlmostEqual(d2['tx'], 10.78, 3) self.assertAlmostEqual(d2['ty'], 20.78, 3) self.assertAlmostEqual(d2['tz'], 30.78, 3) testlib.safe_unlink(filename2+'mrc')
def test_variance(self): """test variance ....................................""" imgfile1 = "test_variance_1.mrc" TestUtil.make_image_file(imgfile1, IMAGE_MRC) e1 = EMData() e1.read_image(imgfile1) e2 = e1.copy() score = e2.cmp("sqeuclidean", e1) self.assertEqual(score, 0) testlib.safe_unlink(imgfile1)
def test_make_spider(self): """test make spider image file ......................""" try: file1 = "test_make_spider_1.spi" nx1 = 100 ny1 = 24 TestUtil.make_image_file(file1, IMAGE_SPIDER, EM_FLOAT, nx1, nx1) err = TestUtil.verify_image_file(file1, IMAGE_SPIDER, EM_FLOAT, nx1, nx1) self.assertEqual(err, 0) finally: testlib.safe_unlink(file1)
def test_hdf_overwrite(self): """test the overwriting of HDF5......................""" file = 'overwrite.hdf' e = EMData(2,2) e.to_zero() e.write_image(file) e.to_one() e.write_image(file) f = EMData(file) for i in range(2*2): self.assertEqual(1, f[i]) testlib.safe_unlink(file)
def no_test_pgm_region_io(self): """test pgm region io ...............................""" try: e = EMData() e.set_size(1024,1024) e.process_inplace('testimage.circlesphere', {'radius':300}) e.write_image('test_circle.pgm') f = EMData() #f.read_image('test_circle.pgm', 0, False, Region(300,300,200,200)) f.read_image('test_circle.pgm') finally: testlib.safe_unlink('test_circle.pgm')
def test_FourierReconstructor(self): """test FourierReconstructor ........................""" n = 32 e1 = EMData() e1.set_size(n, n, 1) e1.process_inplace('testimage.noise.uniform.rand') #e1.do_fft_inplace() e2 = EMData() e2.set_size(n, n, 1) e2.process_inplace('testimage.noise.uniform.rand') #e2.do_fft_inplace() e3 = EMData() e3.set_size(n, n, 1) e3.process_inplace('testimage.noise.uniform.rand') #e3.do_fft_inplace() r = Reconstructors.get('fourier', { 'size': (n, n, n), 'mode': 'gauss_2', 'sym': 'c1', 'quiet': True }) r.setup() r.insert_slice( e1, Transform({ 'type': 'eman', 'alt': 1.56, 'az': 2.56, 'phi': 3.56 })) r.insert_slice( e2, Transform({ 'type': 'eman', 'alt': 2.56, 'az': 3.56, 'phi': 4.56 })) r.insert_slice( e3, Transform({ 'type': 'eman', 'alt': 3.56, 'az': 4.56, 'phi': 5.56 })) result = r.finish(True) testlib.safe_unlink('density.mrc')
def test_is_file_exist(self): """test is_file_exist() function ....................""" imgfile1 = "test_is_file_exist.mrc" TestUtil.make_image_file(imgfile1, IMAGE_MRC) result1 = Util.is_file_exist(imgfile1) self.assertEqual(result1, True) result2 = Util.is_file_exist("__nosuchafile__.dm3") self.assertEqual(result2, False) result3 = Util.is_file_exist("") self.assertEqual(result3, False) testlib.safe_unlink(imgfile1)
def test_read_write_file(self): """test read/write file .............................""" xy = XYData() lx = range(10) ly = (i + 100 for i in range(10)) xy.set_xy_list(lx, ly) file = 'xydata.dat' xy.write_file(file) xy2 = XYData() xy2.read_file(file) self.assertAlmostEqual(5.0, xy2.get_x(5), 3) self.assertAlmostEqual(105.0, xy2.get_y(5), 3) self.assertAlmostEqual(106.0, xy2.get_yatx(6), 3) testlib.safe_unlink(file)
def test_read_write_file(self): """test read/write file .............................""" xy = XYData() lx = range(10) ly = (i+100 for i in range(10)) xy.set_xy_list(lx, ly) file = 'xydata.dat' xy.write_file(file) xy2 = XYData() xy2.read_file(file) self.assertAlmostEqual(5.0, xy2.get_x(5), 3) self.assertAlmostEqual(105.0, xy2.get_y(5), 3) self.assertAlmostEqual(106.0, xy2.get_yatx(6), 3) testlib.safe_unlink(file)
def test_OptVarianceCmp(self): """test OptVarianceCmp ..............................""" e = EMData() e.set_size(64,64,1) e.process_inplace('testimage.noise.uniform.rand') e2 = EMData() e2.set_size(64,64,1) e2.process_inplace('testimage.noise.uniform.rand') score = e.cmp('optvariance', e2, {}) #default argument score2 = e.cmp('optvariance', e2, {'invert':1, 'keepzero':1, 'matchfilt':2, 'radweight':2, 'debug':1}) testlib.safe_unlink('a.hdf') testlib.safe_unlink('dbug.optvar.txt')
def test_eman2ctf_io(self): """test EMAN2Ctf object I/O .........................""" filename = 'test_imagic_ctf2.hdf' img = EMData(32,32) img.process_inplace('testimage.noise.uniform.rand') ctf1 = EMAN2Ctf() ctf1.from_vector((1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0, 0, 0)) img.set_attr('ctf', ctf1) img.write_image(filename) img2 = EMData(filename) ctf2 = img2.get_attr('ctf') self.assertEqual(ctf1.to_string(), ctf2.to_string()) del ctf1, ctf2 testlib.safe_unlink(filename)
def test_read_write_pgm(self): """test pgm file read/write .........................""" try: e = EMData() e.set_size(64,64) e.process_inplace('testimage.noise.uniform.rand') e.write_image('test_image.pgm') f = EMData() f.read_image('test_image.pgm') #self.assertEqual(f==e,True) finally: testlib.safe_unlink('test_image.pgm')
def test_get_all_attibutes(self): """test get_all_attributes function .................""" e1 = test_image() e1.set_attr('name', 'Tom') e1.write_image('test.hdf', 0) e2 = test_image() e2.set_attr('name', 'Sam') e2.write_image('test.hdf', 1) e3 = test_image() e3.write_image('test.hdf', 2) l = EMUtil.get_all_attributes('test.hdf', 'name') self.assertEqual(l, ['Tom', 'Sam', None]) testlib.safe_unlink('test.hdf')
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_read_write_HDF_attribute(self): """test read/write single attribute from/to HDF5 file""" file = 'test.hdf' img = test_image() img.write_image(file, -1) img.write_image(file, -1) EMUtil.write_hdf_attribute(file, 'count', 100) EMUtil.write_hdf_attribute(file, 'count', 1000, 1) c100 = EMUtil.read_hdf_attribute(file, 'count') c1000 = EMUtil.read_hdf_attribute(file, 'count', 1) self.assertEqual(EMUtil.read_hdf_attribute(file, 'count'), 100) self.assertEqual(EMUtil.read_hdf_attribute(file, 'count', 1), 1000) EMUtil.delete_hdf_attribute(file, 'count') d = img.get_attr_dict() self.assertEqual(d.has_key('count'), False) testlib.safe_unlink(file)
def test_read_write_HDF_attribute(self): """test read/write single attribute from/to HDF5 file""" file = 'test.hdf' img = test_image() img.write_image(file, -1) img.write_image(file, -1) EMUtil.write_hdf_attribute(file, 'count', 100) EMUtil.write_hdf_attribute(file, 'count', 1000, 1) c100 = EMUtil.read_hdf_attribute(file, 'count') c1000 = EMUtil.read_hdf_attribute(file, 'count', 1) self.assertEqual(EMUtil.read_hdf_attribute(file, 'count'), 100) self.assertEqual(EMUtil.read_hdf_attribute(file, 'count', 1), 1000) EMUtil.delete_hdf_attribute(file, 'count') d = img.get_attr_dict() self.assertEqual('count' in d, False) testlib.safe_unlink(file)
def test_read_image(self): """test read hdf image file .........................""" nx = 20 ny = 30 nz = 2 imgfile = "test_read_image.h5" TestUtil.make_image_file(imgfile, IMAGE_HDF, EM_FLOAT, nx, ny, nz) e = EMData() e.read_image(imgfile) attrdict = e.get_attr_dict() self.assertEqual(attrdict["nx"], nx) self.assertEqual(attrdict["ny"], ny) self.assertEqual(attrdict["nz"], nz) self.assertEqual(attrdict["ImageEndian"], "big") self.assertEqual(attrdict["datatype"], EM_FLOAT) self.assertEqual(attrdict["is_complex"], 0) #self.assertEqual(attrdict["maximum"], 325.0) #self.assertEqual(attrdict["minimum"], 0.0) testlib.safe_unlink(imgfile)
def test_FourierReconstructor(self): """test FourierReconstructor ........................""" n = 32 e1 = EMData() e1.set_size(n,n,1) e1.process_inplace('testimage.noise.uniform.rand') #e1.do_fft_inplace() e2 = EMData() e2.set_size(n,n,1) e2.process_inplace('testimage.noise.uniform.rand') #e2.do_fft_inplace() e3 = EMData() e3.set_size(n,n,1) e3.process_inplace('testimage.noise.uniform.rand') #e3.do_fft_inplace() r = Reconstructors.get('fourier', {'size':(n,n,n), 'mode':'gauss_2', 'sym':'c1', 'quiet':True}) r.setup() r.insert_slice(e1, Transform({'type':'eman', 'alt':1.56, 'az':2.56, 'phi':3.56})) r.insert_slice(e2, Transform({'type':'eman', 'alt':2.56, 'az':3.56, 'phi':4.56})) r.insert_slice(e3, Transform({'type':'eman', 'alt':3.56, 'az':4.56, 'phi':5.56})) result = r.finish(True) testlib.safe_unlink('density.mrc')
def test_write_transform_to_euler(self): """test write Transform as euler angles .............""" filename = 'test_write_transform.' img = EMData(32,32) img.process_inplace('testimage.noise.uniform.rand') t3d = Transform() t3d.set_rotation({'type':'imagic', 'alpha':1.56, 'beta':2.56, 'gamma':3.56}) img.set_attr('xform.projection', t3d) img.write_image(filename+'img') del img img2 = EMData(filename+'img') self.assertAlmostEqual(img2.get_attr('euler_alpha'), 1.56, 3) self.assertAlmostEqual(img2.get_attr('euler_beta'), 2.56, 3) self.assertAlmostEqual(img2.get_attr('euler_gamma'), 3.56, 3) xform1 = img2.get_attr('xform.projection') d = xform1.get_rotation('imagic') self.assertAlmostEqual(d['alpha'], 1.56, 3) self.assertAlmostEqual(d['beta'], 2.56, 3) self.assertAlmostEqual(d['gamma'], 3.56, 3) del img2 testlib.safe_unlink(filename+'img') testlib.safe_unlink(filename+'hed') filename2 = 'test_write_transform2.' img = EMData(32,32,32) img.process_inplace('testimage.noise.uniform.rand') t3d = Transform() t3d.set_rotation({'type':'imagic', 'alpha':1.56, 'beta':2.56, 'gamma':3.56}) img.set_attr('xform.align3d', t3d) img.write_image(filename2+'img') img2 = EMData(filename2+'img') self.assertAlmostEqual(img2.get_attr('euler_alpha'), 1.56, 3) self.assertAlmostEqual(img2.get_attr('euler_beta'), 2.56, 3) self.assertAlmostEqual(img2.get_attr('euler_gamma'), 3.56, 3) xform2 = img2.get_attr('xform.align3d') d2 = xform2.get_rotation('imagic') self.assertAlmostEqual(d2['alpha'], 1.56, 3) self.assertAlmostEqual(d2['beta'], 2.56, 3) self.assertAlmostEqual(d2['gamma'], 3.56, 3) testlib.safe_unlink(filename2+'hed') testlib.safe_unlink(filename2+'img')
def test_main(): p = OptionParser() p.add_option("--t", action="store_true", help="test exception", default=False) global IS_TEST_EXCEPTION opt, args = p.parse_args() if opt.t: IS_TEST_EXCEPTION = True Log.logger().set_level(-1) # perfect solution for quenching the Log error information, thank Liwei suite = unittest.TestLoader().loadTestsFromTestCase(TestEMDataCuda) unittest.TextTestRunner(verbosity=2).run(suite) testlib.safe_unlink("mydb2") testlib.safe_unlink("mydb1") testlib.safe_unlink("mydb")
def test_main(): p = OptionParser() p.add_option('--t', action='store_true', help='test exception', default=False ) global IS_TEST_EXCEPTION opt, args = p.parse_args() if opt.t: IS_TEST_EXCEPTION = True Log.logger().set_level(-1) #perfect solution for quenching the Log error information, thank Liwei suite = unittest.TestLoader().loadTestsFromTestCase(TestEMDataCuda) unittest.TextTestRunner(verbosity=2).run(suite) testlib.safe_unlink('mydb2') testlib.safe_unlink('mydb1') testlib.safe_unlink('mydb')
def test_get_image_count(self): """test get_image_count function ....................""" e = test_image() e.write_image('test_image_count.mrc') self.assertEqual(EMUtil.get_image_count('test_image_count.mrc'), 1) testlib.safe_unlink('test_image_count.mrc') f = test_image() f.write_image('test_image_count.hdf', 0) f.write_image('test_image_count.hdf', 1) f.write_image('test_image_count.hdf', 2) self.assertEqual(EMUtil.get_image_count('test_image_count.hdf'), 3) testlib.safe_unlink('test_image_count.hdf') g = test_image() g.write_image('test_image_count.spi', 0, EMUtil.ImageType.IMAGE_SPIDER) g.write_image('test_image_count.spi', 1, EMUtil.ImageType.IMAGE_SPIDER) g.write_image('test_image_count.spi', 2, EMUtil.ImageType.IMAGE_SPIDER) self.assertEqual(EMUtil.get_image_count('test_image_count.spi'), 3) testlib.safe_unlink('test_image_count.spi')
def test_get_image_type(self): """test get_image_type function .....................""" e = test_image() e.write_image('mrcfile', 0, EMUtil.ImageType.IMAGE_MRC) self.assertEqual(EMUtil.get_image_type('mrcfile'), EMUtil.ImageType.IMAGE_MRC) testlib.safe_unlink('mrcfile') e2 = test_image() e2.write_image('hdffile', 0, EMUtil.ImageType.IMAGE_HDF) self.assertEqual(EMUtil.get_image_type('hdffile'), EMUtil.ImageType.IMAGE_HDF) testlib.safe_unlink('hdffile') #e.write_image('lstfile', 0, EMUtil.ImageType.IMAGE_LST) #self.assertEqual(EMUtil.get_image_type('lstfile'), EMUtil.ImageType.IMAGE_LST) #testlib.safe_unlink('lstfile') e3 = test_image() e3.write_image('spiderfile', 0, EMUtil.ImageType.IMAGE_SPIDER) self.assertEqual(EMUtil.get_image_type('spiderfile'), EMUtil.ImageType.IMAGE_SPIDER) testlib.safe_unlink('spiderfile') e3.write_image('sspiderfile', 0, EMUtil.ImageType.IMAGE_SINGLE_SPIDER) self.assertEqual(EMUtil.get_image_type('sspiderfile'), EMUtil.ImageType.IMAGE_SINGLE_SPIDER) testlib.safe_unlink('sspiderfile') #e.write_image('piffile', 0, EMUtil.ImageType.IMAGE_PIF) #self.assertEqual(EMUtil.get_image_type('piffile'), EMUtil.ImageType.IMAGE_PIF) #testlib.safe_unlink('piffile') platform = get_platform() if platform!='Windows' and platform!='win32': e4 = test_image() e4.write_image('pngfile', 0, EMUtil.ImageType.IMAGE_PNG) self.assertEqual(EMUtil.get_image_type('pngfile'), EMUtil.ImageType.IMAGE_PNG) testlib.safe_unlink('pngfile') e5 = test_image() e5.write_image('vtkfile', 0, EMUtil.ImageType.IMAGE_VTK) self.assertEqual(EMUtil.get_image_type('vtkfile'), EMUtil.ImageType.IMAGE_VTK) testlib.safe_unlink('vtkfile') e6 = test_image() e6.write_image('pgmfile', 0, EMUtil.ImageType.IMAGE_PGM) self.assertEqual(EMUtil.get_image_type('pgmfile'), EMUtil.ImageType.IMAGE_PGM) testlib.safe_unlink('pgmfile') e7 = test_image() e7.write_image('icosfile', 0, EMUtil.ImageType.IMAGE_ICOS) self.assertEqual(EMUtil.get_image_type('icosfile'), EMUtil.ImageType.IMAGE_ICOS) testlib.safe_unlink('icosfile') e8 = test_image() e8.write_image('xplorfile', 0, EMUtil.ImageType.IMAGE_XPLOR) self.assertEqual(EMUtil.get_image_type('xplorfile'), EMUtil.ImageType.IMAGE_XPLOR) testlib.safe_unlink('xplorfile') e9 = test_image() e9.write_image('emfile', 0, EMUtil.ImageType.IMAGE_EM) self.assertEqual(EMUtil.get_image_type('emfile'), EMUtil.ImageType.IMAGE_EM) testlib.safe_unlink('emfile') e10 = test_image() e10.write_image('imagicfile', 0, EMUtil.ImageType.IMAGE_IMAGIC) self.assertEqual(EMUtil.get_image_type('imagicfile.hed'), EMUtil.ImageType.IMAGE_IMAGIC) testlib.safe_unlink('imagicfile.hed') testlib.safe_unlink('imagicfile.img')
def test_write_transform_spider(self): """test write spi header info from Transform object .""" filename = 'test_write_transform.' img = EMData(32,32) img.process_inplace('testimage.noise.uniform.rand') t3d = Transform() t3d.set_rotation({'type':'spider', 'phi':1.56, 'theta':2.56, 'psi':3.56}) t3d.set_trans(10.78, 20.78, 30.78) t3d.set_scale(4.0) img.set_attr('xform.projection', t3d) img.write_image(filename+'spi') del img img2 = EMData(filename+'spi') self.assertAlmostEqual(img2.get_attr('SPIDER.phi'), 1.56, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.theta'), 2.56, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.gamma'), 3.56, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.dx'), 10.78, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.dy'), 20.78, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.dz'), 30.78, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.scale'), 4.0, 3) trans = img2.get_attr('xform.projection') d = trans.get_params('spider') self.assertAlmostEqual(d['phi'], 1.56, 3) self.assertAlmostEqual(d['theta'], 2.56, 3) self.assertAlmostEqual(d['psi'], 3.56, 3) self.assertAlmostEqual(d['tx'], 10.78, 3) self.assertAlmostEqual(d['ty'], 20.78, 3) self.assertAlmostEqual(d['tz'], 30.78, 3) self.assertAlmostEqual(d['scale'], 4.0, 3) del img2 testlib.safe_unlink(filename+'spi') filename2 = 'test_write_transform2.' img = EMData(32,32,32) img.process_inplace('testimage.noise.uniform.rand') t3d = Transform() t3d.set_rotation({'type':'spider', 'phi':1.56, 'theta':2.56, 'psi':3.56}) t3d.set_trans(10.78, 20.78, 30.78) t3d.set_scale(4.0) img.set_attr('xform.align3d', t3d) img.write_image(filename2+'spi') img2 = EMData(filename2+'spi') self.assertAlmostEqual(img2.get_attr('SPIDER.phi'), 1.56, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.theta'), 2.56, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.gamma'), 3.56, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.dx'), 10.78, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.dy'), 20.78, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.dz'), 30.78, 3) self.assertAlmostEqual(img2.get_attr('SPIDER.scale'), 4.0, 3) trans2 = img2.get_attr('xform.align3d') d2 = trans2.get_params('spider') self.assertAlmostEqual(d2['phi'], 1.56, 3) self.assertAlmostEqual(d2['theta'], 2.56, 3) self.assertAlmostEqual(d2['psi'], 3.56, 3) self.assertAlmostEqual(d2['tx'], 10.78, 3) self.assertAlmostEqual(d2['ty'], 20.78, 3) self.assertAlmostEqual(d2['tz'], 30.78, 3) self.assertAlmostEqual(d2['scale'], 4.0, 3) testlib.safe_unlink(filename2+'spi')