diff --git a/elf/io/mrc_wrapper.py b/elf/io/mrc_wrapper.py old mode 100644 new mode 100755 index a9a24cf..ee0f98a --- a/elf/io/mrc_wrapper.py +++ b/elf/io/mrc_wrapper.py @@ -1,4 +1,6 @@ from collections.abc import Mapping +import numpy as np + try: import mrcfile except ImportError: @@ -7,7 +9,11 @@ class MRCDataset: def __init__(self, data_object): - self._data = data_object + im = data_object + # need to swap and flip to meet axes conventions + data0 = np.swapaxes(im, 0, -1) + data1 = np.fliplr(data0) + self._data = np.swapaxes(data1, 0, -1) @property def dtype(self): @@ -42,6 +48,7 @@ def attrs(self): class MRCFile(Mapping): """ Wrapper for an mrc file """ + def __init__(self, path, mode='r'): self.path = path self.mode = mode diff --git a/test/io_tests/test_mrc_wrapper.py b/test/io_tests/test_mrc_wrapper.py old mode 100644 new mode 100755 index bd0289e..61d18b9 --- a/test/io_tests/test_mrc_wrapper.py +++ b/test/io_tests/test_mrc_wrapper.py @@ -17,14 +17,19 @@ class TestMrcWrapper(unittest.TestCase): def setUp(self): os.makedirs(self.tmp_dir) - shape = (64, 64, 64) + shape = (16, 32, 64) self.data = np.random.rand(*shape).astype('float32') + # change axes order to fit MRC convention + data0 = np.swapaxes(self.data, 0, -1) + data1 = np.fliplr(data0) + out_data = np.swapaxes(data1, 0, -1) + with mrcfile.new(self.out) as f: - f.set_data(self.data) + f.set_data(out_data) with mrcfile.new(self.out_compressed, compression='gzip') as f: - f.set_data(self.data) + f.set_data(out_data) def tearDown(self): rmtree(self.tmp_dir)