def region_write_test(self, imgtype, imgfile, outtype = None): """test region writing ..............................""" if not outtype: outtype = imgtype is_3d = False if imgtype == IMAGE_IMAGIC: is_3d = True imgbase = Util.remove_filename_ext(imgfile) ext = Util.get_filename_ext(imgfile) writefile_2d = imgbase + "_write_region_2d." + ext writefile_3d = imgbase + "_write_region_3d." + ext e = EMData() e.read_image(imgfile, 0, False, None, is_3d) TestUtil.check_image(imgfile, e) testlib.unlink_data_header_files(imgfile) ndims = e.get_ndim() e.write_image(writefile_2d, 0, outtype) if ndims == 3: e.write_image(writefile_3d, 0, outtype) (region_2d, region_3d) = self.create_dummy_region(e) zsize = e.get_zsize()/2 if zsize == 0: zsize = 1 e3 = EMData() e3.set_size(e.get_xsize()/2, e.get_ysize()/2, zsize) e3.to_zero() image_index = 0 if outtype == IMAGE_SPIDER: image_index = e.get_zsize()/2 e3.write_image(writefile_2d, image_index, outtype, False, region_2d) TestUtil.check_image(writefile_2d) if ndims == 3: e3.write_image(writefile_3d, image_index, outtype, False, region_3d) TestUtil.check_image(writefile_3d) if outtype == IMAGE_IMAGIC: (hed3d, img3d) = testlib.get_imagic_filename_pair(writefile_3d) os.unlink(hed3d) os.unlink(img3d) else: os.unlink(writefile_3d) if outtype == IMAGE_IMAGIC: (hed2d, img2d) = testlib.get_imagic_filename_pair(writefile_2d) os.unlink(hed2d) os.unlink(img2d) else: os.unlink(writefile_2d)
def region_read_test(self, imgtype, imgfile, outtype = None): """test region read .................................""" if not outtype: outtype = imgtype is_3d = False if imgtype == IMAGE_IMAGIC: is_3d = True imgbase = Util.remove_filename_ext(imgfile) ext = Util.get_filename_ext(imgfile) readfile_2d = imgbase + "_read_region_2d." + ext readfile_3d = imgbase + "_read_region_3d." + ext e = EMData() e.read_image(imgfile, 0, False, None, is_3d) TestUtil.check_image(imgfile, e) #testlib.unlink_data_header_files(imgfile) (region_2d, region_3d) = self.create_dummy_region(e) e2 = EMData() e2.read_image(imgfile, 0, False, region_2d, is_3d) TestUtil.check_image(readfile_2d, e2) e2.write_image(readfile_2d, 0, outtype) if region_3d: e4 = EMData() e4.read_image(imgfile, 0, False, region_3d, is_3d) e4.write_image(readfile_3d, 0, outtype) TestUtil.check_image(readfile_3d, e4) if outtype == IMAGE_IMAGIC: (hed3d, img3d) = testlib.get_imagic_filename_pair(readfile_3d) os.unlink(hed3d) os.unlink(img3d) else: os.unlink(readfile_3d) if outtype == IMAGE_IMAGIC: (hed2d, img2d) = testlib.get_imagic_filename_pair(readfile_2d) os.unlink(hed2d) os.unlink(img2d) else: os.unlink(readfile_2d)
def test_insert_beyond_existing_file(self): """test insert image beyond existing file ...........""" infile = "insert_beyond_existing_in.hed" TestUtil.make_image_file(infile, IMAGE_IMAGIC) e = EMData() e.read_image(infile, 0, False, None, True) nimg1 = EMUtil.get_image_count(infile) self.assertEqual(nimg1, 1) n2 = 9 e.write_image(infile, n2, IMAGE_IMAGIC) nimg2 = EMUtil.get_image_count(infile) self.assertEqual(nimg2, n2+1) # todo: verify images n3 = 14 e.write_image(infile, n3, IMAGE_IMAGIC) nimg3 = EMUtil.get_image_count(infile) self.assertEqual(nimg3, n3+1) # todo: verify images (hedfile, imgfile) = testlib.get_imagic_filename_pair(infile) os.unlink(hedfile) os.unlink(imgfile)
def no_test_imagicio_region(self): """test imagic io region ............................""" infile = "test_imagicio_region_11.hed" TestUtil.make_image_file(infile, IMAGE_IMAGIC, EM_FLOAT, 32,32,64) self.region_read_write_test(IMAGE_IMAGIC, infile) (hedfile1, imgfile1) = testlib.get_imagic_filename_pair(infile) os.unlink(hedfile1) os.unlink(imgfile1)
def no_test_insert_to_newfile(self): """test insert image to new file ....................""" img1 = "test_insert_to_newfile_in.hed" TestUtil.make_image_file(img1, IMAGE_IMAGIC) e = EMData() e.read_image(img1) outfile = "test_insert_to_newfile_out.hed" nimg = 4 e.write_image(outfile, nimg-1, IMAGE_IMAGIC) nimg2 = EMUtil.get_image_count(outfile) self.assertEqual(nimg2, nimg) (hedfile1, imgfile1) = testlib.get_imagic_filename_pair(img1) (hedfile2, imgfile2) = testlib.get_imagic_filename_pair(outfile) os.unlink(hedfile1) os.unlink(imgfile1) os.unlink(hedfile2) os.unlink(imgfile2)
def test_append_image(self): """test image appending .............................""" infile = "test_append_image.hed" TestUtil.make_image_file(infile, IMAGE_IMAGIC, EM_FLOAT, 16, 16, 10) e = EMData() all_imgs = e.read_images(infile) outfile1 = "test_append_image_out_" + str(os.getpid()) + ".hed" for img in all_imgs: img.append_image(outfile1) (infilehed, infileimg) = testlib.get_imagic_filename_pair(infile) (outfilehed, outfileimg) = testlib.get_imagic_filename_pair(outfile1) os.unlink(infilehed) os.unlink(infileimg) os.unlink(outfilehed) os.unlink(outfileimg)
def test_append_to_existing_file(self): """test append image to existing file ...............""" img1 = "test_append_to_existing_file_1.hed" TestUtil.make_image_file(img1, IMAGE_IMAGIC) e = EMData() e.read_image(img1, 0, False, None, True) e.append_image(img1, IMAGE_IMAGIC) # verify here (hedfile, imgfile) = testlib.get_imagic_filename_pair(img1) os.unlink(hedfile) os.unlink(imgfile)
def test_no_ext_filename(self): """test no extention file name ......................""" infile = "test_no_ext_filename.mrc" TestUtil.make_image_file(infile, IMAGE_MRC) outfile = "test_no_ext_filename_out" img = EMData() img.read_image(infile) img.write_image(outfile, 0, IMAGE_IMAGIC) (hedfile, imgfile) = testlib.get_imagic_filename_pair(outfile) os.unlink(infile) os.unlink(hedfile) os.unlink(imgfile)
def test_append_to_newfile(self): """test append image to new file ....................""" infile = "test_append_to_newfile_in.mrc" outfile = "test_append_to_newfile_in.img" TestUtil.make_image_file(infile, IMAGE_MRC) e = EMData() e.read_image(infile) e.append_image(outfile, IMAGE_IMAGIC) # check e (outhed, outimg) = testlib.get_imagic_filename_pair(outfile) os.unlink(infile) os.unlink(outhed) os.unlink(outimg)
def no_test_insert_inside_existing_file(self): """test insert image in existing file ...............""" infile = "test_insert_inside_existing_file_1.img" TestUtil.make_image_file(infile, IMAGE_IMAGIC, EM_FLOAT, 20, 30, 20) insertfile = "test_insert_inside_existing_file_2.mrc" TestUtil.make_image_file(insertfile, IMAGE_MRC, EM_FLOAT, 20, 30) e = EMData() e.read_image(insertfile) e.write_image(infile, 2, IMAGE_IMAGIC) # verify result (hedfile1, imgfile1) = testlib.get_imagic_filename_pair(infile) os.unlink(hedfile1) os.unlink(imgfile1) os.unlink(insertfile)