Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mrc import axes #52

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion elf/io/mrc_wrapper.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from collections.abc import Mapping
import numpy as np

try:
import mrcfile
except ImportError:
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions test/io_tests/test_mrc_wrapper.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down