Skip to content

Commit 18a2192

Browse files
Tests
Did asked changes in changelog and core and added more test
1 parent 38b5f4b commit 18a2192

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

CHANGELOG

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,8 @@ The rules for this file:
1313
* accompany each entry with github issue/PR number (Issue #xyz)
1414

1515
------------------------------------------------------------------------------
16-
12/12/2025 Pradyumn-cloud
17-
* 1.1.0
18-
19-
Changes
20-
21-
* Added MRC file writing support (Issue #108)
22-
* Implemented MRC.write() method with proper coordinate transformations
23-
* Added Grid.export() integration for MRC format
24-
* Preserved header information (mapc/mapr/maps, nstart, cell dimensions)
25-
* Added comprehensive tests
2616

27-
??/??/???? IAlibay, ollyfutur, conradolandia, orbeckst
17+
??/??/???? IAlibay, ollyfutur, conradolandia, orbeckst, Pradyumn-cloud
2818
* 1.1.0
2919

3020
Changes
@@ -39,6 +29,7 @@ The rules for this file:
3929
* `Grid` now accepts binary operations with any operand that can be
4030
broadcasted to the grid's shape according to `numpy` broadcasting rules
4131
(PR #142)
32+
* Added MRC file writing support (Issue #108)
4233

4334
Fixes
4435

gridData/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def _export_mrc(self, filename, **kwargs):
699699
information (including axis ordering) is preserved
700700
* For new grids, standard ordering (mapc=1, mapr=2, maps=3) is used
701701
702-
.. versionadded:: 0.8.0
702+
.. versionadded:: 1.1.0
703703
"""
704704
# Create MRC object and populate with Grid data
705705
mrc_file = mrc.MRC()

gridData/tests/test_mrc.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,47 @@ def test_grid_export_mrc_preserves_header(self, tmpdir):
256256
assert g_read._mrc_header.mapc == orig_mapc
257257
assert g_read._mrc_header.mapr == orig_mapr
258258
assert g_read._mrc_header.maps == orig_maps
259+
260+
def test_mrc_write_4x4x4_with_header(self, tmpdir):
261+
"""Test writing 4x4x4 MRC file with custom header values."""
262+
263+
# Create 4x4x4 data
264+
data = np.arange(64, dtype=np.float32).reshape((4, 4, 4))
265+
outfile = str(tmpdir / "test_with_header.mrc")
266+
267+
# Create and write MRC
268+
m = mrc.MRC()
269+
m.array = data
270+
m.delta = np.diag([1.5, 2.0, 2.5])
271+
m.origin = np.array([10.0, 20.0, 30.0])
272+
m.rank = 3
273+
m.write(outfile)
274+
275+
# Read back and verify
276+
m_read = mrc.MRC(outfile)
277+
assert_allclose(m_read.array, data)
278+
assert_allclose(np.diag(m_read.delta), [1.5, 2.0, 2.5])
279+
assert_allclose(m_read.origin, [10.0, 20.0, 30.0], rtol=1e-4, atol=1.0)
280+
281+
282+
def test_mrc_write_4x4x4_without_header(self, tmpdir):
283+
"""Test writing 4x4x4 MRC file with default header."""
284+
285+
# Create 4x4x4 random data
286+
np.random.seed(42)
287+
data = np.random.rand(4, 4, 4).astype(np.float32)
288+
outfile = str(tmpdir / "test_without_header.mrc")
289+
290+
# Create and write MRC
291+
m = mrc.MRC()
292+
m.array = data
293+
m.delta = np.diag([1.0, 1.0, 1.0])
294+
m.origin = np.array([0.0, 0.0, 0.0])
295+
m.rank = 3
296+
m.write(outfile)
297+
298+
# Read back and verify
299+
m_read = mrc.MRC(outfile)
300+
assert_allclose(m_read.array, data)
301+
assert_allclose(np.diag(m_read.delta), [1.0, 1.0, 1.0])
302+
assert_allclose(m_read.origin, [0.0, 0.0, 0.0], rtol=1e-4, atol=1.0)

0 commit comments

Comments
 (0)