Skip to content

Better handling of signed bytes MRC files #69

@rdrighetto

Description

@rdrighetto

Hi @colinpalmer, hope you are doing well!

I see that mrcfile reads MRC files with signed bytes 'literally'. A tomogram mask generated with IMOD and saved as signed bytes (not intentionally) has the 0's represented as -128 and 1's represented as -127. Of course, bad things happen down the line if you read this mask with mrcfile and naively multiply your tomogram with it.

I recently made a PR to pytom-match-pick to be able to handle this case:
SBC-Utrecht/pytom-match-pick#270

But as @sroet suggested, maybe this is something that mrcfile should be able to handle properly by itself? Or am I missing something?

Below I leave the header of one such file (from IMOD's header command):

RO image file on unit   1 : 28.mrc     Size=     736561 K

 Number of columns, rows, sections .....    1023    1440     512
 Map mode ..............................    0   (bytes - signed in file)
 Start cols, rows, sects, grid x,y,z ...    0     0     0    1023   1440    512
 Pixel spacing (Angstroms)..............   10.74      10.74      10.74
 Cell angles ...........................   90.000   90.000   90.000
 Fast, medium, slow axes ...............    X    Y    Z
 Origin on x,y,z .......................    0.000       0.000       0.000
 Minimum density .......................   0.0000     (  -128.00     in file)
 Maximum density .......................   1.0000     (  -127.00     in file)
 Mean density ..........................  0.52643E-03 (  -128.00     in file)
 tilt angles (original,current) ........   0.0   0.0   0.0   0.0   0.0   0.0
 Space group,# extra bytes,idtype,lens .        0        0        0        0

     2 Titles :
Created by mrcfile.py                                       2024-10-22 19:08:37
clip: Subtract                                          03-Mar-25  10:46:13

It became a signed bytes file after the IMOD clip command. But IMOD somehow knows that this is a binary mask, while other programs don't 🤔

Any thoughts on how to go about this?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions