def test_theverybasics(): nim = NiftiImage(image_file) ok_(nim.getDataArray().shape == data_shape) # basic incomplete property check ok_(nim.extent == (128, 96, 24, 2)) ok_(nim.rtime == 2000) ok_((nim.pixdim == (2.0, 2.0, 2.1999990940093994, 2000.0, 1.0, 1.0, 1.0)).all()) ok_(nim.voxdim == (2.0, 2.0, 2.1999990940093994)) ok_(nim.header["datatype"] == 4) ok_(nim.header["bitpix"] == 16) ok_(nim.header["magic"] == "n+1")
class FileIOTests(unittest.TestCase): def setUp(self): self.workdir = tempfile.mkdtemp() self.nimg = NiftiImage(image_file) self.fp = tempfile.NamedTemporaryFile(suffix='.nii.gz') self.fp_plain = tempfile.NamedTemporaryFile(suffix='.nii') def tearDown(self): shutil.rmtree(self.workdir) del self.nimg self.fp.close() self.fp_plain.close() def testIdempotentLoadSaveCycle(self): """ check if file is unchanged by load/save cycle. """ md5_orig = md5sum(image_file) self.nimg.save(self.fp.name) self.nimg.save('failed.nii.gz') md5_io = md5sum(self.fp.name) # ASK MATTHEW: Fails since all extensions get stripped #self.failUnlessEqual(md5_orig, md5_io) # def testUnicodeLoadSaveCycle(self): # """ check load/save cycle for unicode filenames. # """ # md5_orig = md5sum(os.path.join(example_data_path, 'example4d.nii.gz')) # self.nimg.save( os.path.join( self.workdir, 'üöä.nii.gz') ) # md5_io = md5sum( os.path.join( self.workdir, 'üöä.nii.gz') ) # # self.failUnlessEqual(md5_orig, md5_io) # # def testDataAccess(self): # test two points self.failUnlessEqual(self.nimg.data[1,12,59,49], 509) self.failUnlessEqual(self.nimg.data[0,4,17,42], 435)
def setUp(self): self.workdir = tempfile.mkdtemp() self.nimg = NiftiImage(image_file) self.fp = tempfile.NamedTemporaryFile(suffix='.nii.gz') self.fp_plain = tempfile.NamedTemporaryFile(suffix='.nii')