Better handling of signed bytes MRC files
- Dominant language
- Python
- Stars
- 86
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Description
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:
https://github.com/SBC-Utrecht/pytom-match-pick/pull/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!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing how mrcfile handles MRC mode 0 signed-byte data and compare that behavior with the referenced pytom-match-pick PR. Clarify the expected interpretation of IMOD-generated binary masks, then define tests covering the signed-byte case and the existing behavior before deciding what completion means.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100