Skip to content

permit corrupt MRC files #1292

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

Merged
merged 1 commit into from
Jun 17, 2025
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
2 changes: 1 addition & 1 deletion src/aspire/source/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, files, particle_size, max_rows, B, symmetry_group):
dtype = "float32"
# If file is MRC, we can get dtype from header.
if self._ext == ".mrc":
with mrcfile.open(first_mrc) as mrc:
with mrcfile.open(first_mrc, mode="r", permissive=True) as mrc:
# get dtype from first micrograph
mode = int(mrc.header.mode)
dtypes = {0: "int8", 1: "int16", 2: "float32", 6: "uint16"}
Expand Down
4 changes: 2 additions & 2 deletions src/aspire/source/relion.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(

# Peek into the first image and populate some attributes
first_mrc_filepath = metadata["__mrc_filepath"][0]
mrc = mrcfile.open(first_mrc_filepath)
mrc = mrcfile.open(first_mrc_filepath, mode="r", permissive=True)

# Get the 'mode' (data type) - TODO: There's probably a more direct way to do this.
mode = int(mrc.header.mode)
Expand Down Expand Up @@ -247,7 +247,7 @@ def _images(self, indices):
logger.debug(f"Indices: {indices}")

def load_single_mrcs(filepath, indices):
arr = mrcfile.open(filepath).data
arr = mrcfile.open(filepath, mode="r", permissive=True).data
# if the stack only contains one image, arr will have shape (resolution, resolution)
# the code below reshapes it to (1, resolution, resolution)
if len(arr.shape) == 2:
Expand Down
Loading