Last active
October 4, 2020 14:07
-
-
Save wjiang/89c492751fc28042aeebd5163b341f1d to your computer and use it in GitHub Desktop.
generate Y-direction projection of 2D images
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
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fixed for non-square images