Skip to content

Instantly share code, notes, and snippets.

@wjiang
Last active October 4, 2020 14:07
Show Gist options
  • Save wjiang/89c492751fc28042aeebd5163b341f1d to your computer and use it in GitHub Desktop.
Save wjiang/89c492751fc28042aeebd5163b341f1d to your computer and use it in GitHub Desktop.
generate Y-direction projection of 2D images
import os, sys
import numpy as np
import mrcfile
if len(sys.argv)!=2:
print(f"Usage: {sys.argv[0]} <mrc file>")
sys.exit(-1)
imageFile = sys.argv[1]
prefix = os.path.splitext(imageFile)[0]
m = mrcfile.open(imageFile)
apix = m.voxel_size.x
data = m.data
n = len(data)
for i in range(n):
d = data[i]
xy = np.zeros((d.shape[1], 2))
xy[:,0] = np.arange(d.shape[1])*apix
xy[:,1] = d.mean(axis=0)
txtFile = f"{prefix}.{i}.proj-y.txt"
np.savetxt(txtFile, xy, header="x unit: Angstrom")
print(f"\nY-projections of {n} images are saved to text files {prefix}.*.proj-y.txt")
print(f"Use any plotting program (e.g. qplot {prefix}.*.proj-y.txt) to plot them\n")
@wjiang
Copy link
Author

wjiang commented Oct 4, 2020

fixed for non-square images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment