Skip to content

Commit b570316

Browse files
committed
Used tempfile to store the mrcfile inside native
1 parent 682b6ab commit b570316

2 files changed

Lines changed: 154 additions & 110 deletions

File tree

gridData/mrc.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"""
3636
import numpy as np
3737
import mrcfile
38+
import tempfile, os
3839

3940

4041
class MRC(object):
@@ -104,7 +105,7 @@ def __init__(self, filename=None, assume_volumetric=False):
104105
@classmethod
105106
def from_grid(cls, grid, **kwargs):
106107
"""Create MRC object from a Grid.
107-
108+
108109
If the Grid was originally created from an mrcfile (and thus has
109110
the ``Grid._mrc_header`` attribute), the MRC header will be copied
110111
into the returned MRC instance.
@@ -139,7 +140,7 @@ def from_grid(cls, grid, **kwargs):
139140
@property
140141
def native(self):
141142
"""Return the native mrcfile.MrcFile object.
142-
143+
143144
Returns
144145
-------
145146
mrcfile.mrcfile.MrcFile
@@ -149,7 +150,12 @@ def native(self):
149150
.. versionadded:: 1.2.0
150151
151152
"""
152-
return self
153+
fd, temp_path = tempfile.mkstemp(suffix=".mrc")
154+
155+
os.close(fd)
156+
self.write(temp_path)
157+
158+
return mrcfile.open(temp_path)
153159

154160
def read(self, filename, assume_volumetric=False):
155161
"""Populate the instance from the MRC/CCP4 file *filename*."""

0 commit comments

Comments
 (0)