def test_basic(self): path = '/path/to/image' loc2 = emc.ImageLocation('/path/to/image') self.assertEqual(loc2.index, emc.ImageLocation.FIRST) self.assertEqual(loc2.path, path) loc3 = emc.ImageLocation(path, 2) self.assertEqual(loc3.path, path) self.assertNotEqual(loc2, loc3) loc3.index = emc.ImageLocation.FIRST self.assertEqual(loc2, loc3)
def createImageModel(cls, path): """ Create an ImageModel reading path as an emc.Image. """ image = emc.Image() loc = emc.ImageLocation(path) image.read(loc) return models.ImageModel(data=np.array(image, copy=False), location=(loc.index, loc.path))
def test_readMrc(self): mrcIO = emc.ImageFile() testDataPath = os.environ.get("EM_TEST_DATA", None) if testDataPath: # 2D image (a big one): micrograph micName = "xmipp_tutorial/micrographs/BPV_1386.mrc" micDim = emc.ArrayDim(9216, 9441, 1, 1) # 2D stack of particles stackName = "emx/alignment/Test2/stack2D.mrc" stackDim = emc.ArrayDim(128, 128, 1, 100) # 3D volumes vol1Name = "resmap/t20s_proteasome_full.map" vol1Dim = emc.ArrayDim(300, 300, 300, 1) fileDims = { micName: (micDim, 87008256), stackName: (stackDim, 65536), # 128 * 128 * 4 vol1Name: (vol1Dim, 108000000) } for fn, (dim, size) in fileDims.items(): img = emc.Image() loc = emc.ImageLocation(os.path.join(testDataPath, fn), 1) print(">>> Reading image: ", loc.path) img.read(loc) dim.n = 1 self.assertEqual(img.getDim(), dim) self.assertEqual(img.getDataSize(), size) # Test that we can read also from string # that will be converted to ImageLocation img = emc.Image() try: img.read(emc.ImageLocation(os.path.join(testDataPath, micName))) import numpy as np a = np.array(img, copy=False) except Exception as ex: raise ex self.assertEqual(img.getDim(), micDim)
def test_VolumeModel(self): volName = self.getDataPaths()[2] print("Checking %s" % volName) volModel = dv.models.VolumeModel( data=emv.utils.ImageManager().getData(volName)) minValue, maxValue = volModel.getMinMax() def _check(model): self.assertEqual(model.getDim(), (300, 300, 300)) self.assertAlmostEqual(minValue, -0.011036, places=5) self.assertAlmostEqual(maxValue, 0.027878, places=5) self.assertIsNotNone(model.getData()) _check(volModel) sliceModel = volModel.getSlicesModel(dv.models.AXIS_Z) _check(sliceModel) imageModel = volModel.getSliceImageModel(dv.models.AXIS_Z, 0) self.assertEqual(imageModel.getDim(), (300, 300)) volModel.setData(None) self.assertIsNone(volModel.getData()) self.assertIsNone(volModel.getDim()) return # 2D stack of particles stackName = "emx/alignment/Test2/stack2D.mrc" stackDim = emc.ArrayDim(128, 128, 1, 100) # 3D volumes vol1Name = "resmap/t20s_proteasome_full.map" vol1Dim = emc.ArrayDim(300, 300, 300, 1) fileDims = { volName: (micDim, 87008256), stackName: (stackDim, 65536), # 128 * 128 * 4 vol1Name: (vol1Dim, 108000000) } for fn, (dim, size) in fileDims.items(): img = emc.Image() loc = emc.ImageLocation(os.path.join(testDataPath, fn), 1) print(">>> Reading image: ", loc.path) img.read(loc) dim.n = 1 self.assertEqual(img.getDim(), dim) self.assertEqual(img.getDataSize(), size)
#!/usr/bin/env python from __future__ import print_function import emcore as emc import numpy as np import sys if __name__ == '__main__': if len(sys.argv) < 2: print("Provide input file(s). ") sys.exit(1) img = emc.Image() print("Computing stats with numpy: ") for fn in sys.argv[1:]: loc = emc.ImageLocation(fn) img.read(loc) data = np.array(img, copy=False) print("\nFile: ", fn, "\nmin:", np.amin(data), "max:", np.amax(data), "mean: %0.5f" % np.mean(data), "std: %0.5f" % np.std(data))
mrcIO = emc.ImageFile('mrc') dataPath = os.environ.get("EM_TEST_DATA", None) if dataPath: micName = "xmipp_tutorial/micrographs/BPV_1386.mrc" micDim = emc.ArrayDim(9216, 9441, 1, 1) stackName = "emx/alignment/Test2/stack2D.mrc" stackDim = emc.ArrayDim(128, 128, 1, 100) fileDims = {micName: micDim, stackName: stackDim} n = 5 m = 5 img = emc.Image() try: loc = emc.ImageLocation(os.path.join(dataPath, stackName)) # Read many images from the particles stack and put them # together using a numpy array and showing in matplotlib for i in range(n * m): loc.index = i + 1 img.read(loc) a = np.array(img, copy=False) dim = img.getDim() iy = i / m ix = i % m print("dim: ", dim, "type: ", img.getType()) print("i: ", i, "iy: ", iy, "ix: ", ix) if i == 0: # only first time aa = np.zeros((dim.y * n, dim.x * m), dtype=a.dtype)
if __name__ == '__main__': mrcIO = emc.ImageFile('mrc') dataPath = os.environ.get("EM_TEST_DATA", None) if dataPath: vol1Name = "resmap/t20s_proteasome_full.map" vol1Dim = emc.ArrayDim(300, 300, 300, 1) n = 5 m = 5 img = emc.Image() try: loc = emc.ImageLocation(os.path.join(dataPath, vol1Name), 1) img.read(loc) a = np.array(img, copy=False) dim = img.getDim() # show central slice on each axis aa = np.zeros((dim.y, dim.x * 3), dtype=a.dtype) sliceZ = dim.z / 2 aa[:, 0:dim.x] = a[sliceZ, :, :] sliceY = dim.y / 2 aa[:, dim.x:2*dim.x] = a[:, sliceY, :] sliceX = dim.x / 2 aa[:, 2*dim.x:3*dim.x] = a[:, :, sliceX]