Created
April 4, 2024 20:55
-
-
Save PlethoraChutney/5f01dca37cdf82cd9a5851024bc1d9fa to your computer and use it in GitHub Desktop.
Header to read 16-bit MRC files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import struct | |
with open(sys.argv[1], "rb") as f: | |
[nx, ny, nz] = [x[0] for x in struct.iter_unpack('i', f.read(12))] | |
# don't care about mode, start | |
_ = f.read(16) | |
[mx] = struct.unpack('i', f.read(4)) | |
_ = f.read(8) | |
[xlen] = struct.unpack('f', f.read(4)) | |
_ = f.read(8) | |
apix = round(xlen / mx, 4) | |
# don't care about cell angles or mapping | |
_ = f.read(24) | |
[amin] = struct.unpack('f', f.read(4)) | |
[amax] = struct.unpack('f', f.read(4)) | |
[amean] = struct.unpack('f', f.read(4)) | |
amin = round(amin, 3) | |
amax = round(amax, 3) | |
amean = round(amean, 3) | |
print() | |
print("Width\t", f"{ny:.>30}", sep = "") | |
print("Height\t", f"{nx:.>30}", sep = "") | |
print("Frames\t", f"{nz:.>30}", sep = "") | |
print() | |
print("A/pix\t", f"{apix:.>30}", sep = "") | |
print() | |
print("Min\t", f"{amin:.>30}", sep = "") | |
print("Mean\t", f"{amean:.>30}", sep = "") | |
print("Max\t", f"{amax:.>30}", sep = "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment