Last active
November 22, 2021 16:40
-
-
Save DustinMorado/cf4269a7ccdb35e0e9114546a797f004 to your computer and use it in GitHub Desktop.
print FEI2 extended header info
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 mrcfile | |
import numpy | |
import argparse | |
parser = argparse.ArgumentParser(description='Print MRC extended header') | |
parser.add_argument('input_mrc', help='input mrc file') | |
parser.add_argument('-f', '--field', help='specific key to print') | |
args = parser.parse_args() | |
with mrcfile.open(args.input_mrc, header_only=True) as mrc: | |
if args.field is not None and args.field in mrc.extended_header.dtype.names: | |
if mrc.extended_header[args.field].dtype == mrc.extended_header['Application'].dtype: | |
print('{:35}: {}'.format(args.field, mrc.extended_header[args.field][0].decode(encoding='UTF-8', errors='ignore'))) | |
else: | |
print('{:35}: {}'.format(args.field, mrc.extended_header[args.field][0])) | |
else: | |
for exthead_field in mrc.extended_header.dtype.names: | |
if exthead_field == 'Unused range': | |
continue | |
elif mrc.extended_header[exthead_field].dtype == mrc.extended_header['Application'].dtype: | |
print('{:35}: {}'.format(exthead_field, mrc.extended_header[exthead_field][0].decode(encoding='UTF-8',errors='ignore'))) | |
else: | |
print('{:35}: {}'.format(exthead_field, mrc.extended_header[exthead_field][0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment