updated to python3 and included now an arg.parse

This commit is contained in:
Beale John Henry
2023-07-12 16:10:36 +02:00
parent 0f2e8e700e
commit 3cfe47e761

View File

@@ -1,9 +1,25 @@
# IMPORTant stuff.... #!/usr/bin/env python3
import string
# written by Thomas Barends
# v. minor edits by J. Beale + conversion to python3
"""
# aim
visualise preferential orientations of crystals processed by CrystFEL
# usage
python update-geom-from-lab6.py -f <path-to-stream-file>, -r <reindex-or-not>, -s step-size
# output
creates 3 plots showing the orientations of the crystals along the 3 axes
"""
# modules
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d import Axes3D
import argparse
import os
def ProjectionPlot(X,Y,Z,C,title): def ProjectionPlot(X,Y,Z,C,title):
f=plt.figure() f=plt.figure()
@@ -35,43 +51,24 @@ def ProjectionPlot(X,Y,Z,C,title):
ax4.set_ylabel('Y (along jet)') ax4.set_ylabel('Y (along jet)')
ax4.set_aspect('equal', 'box') ax4.set_aspect('equal', 'box')
f.canvas.set_window_title(title) f.canvas.manager.set_window_title(title)
f.set_size_inches(9,7) f.set_size_inches(9,7)
plt.tight_layout() plt.tight_layout()
plt.savefig(title+'.png') plt.savefig(title+'.png')
plt.show() plt.show()
def main( stream_file, reindex=False, step=25 ):
# declare lists to read reciprocal vectors # declare lists to read reciprocal vectors
astar=[] astar=[]
bstar=[] bstar=[]
cstar=[] cstar=[]
# set path and filenames
#pathname='/lfs/l1/agorel/2018-03-20-shock-wave-8ns-cxim1816/2-indexing-pump-probe-zaef-nomulti/'
#filename='indexed_65T_pumpprobe_SNR4_THR100.stream.rogue.stream'
#pathname='/lfs/l1/agorel/2018-03-20-shock-wave-8ns-cxim1816/2-indexing-probe-zaef-nomulti/'
#filename='indexed_65T_probe_SNR4_THR100.stream'
pathname='./'
filename='FAP-dark.stream'
#pathname='./'
#filename='smalla.stream'
#reindex=True
reindex=False
# open stream file, read all lines and close again # open stream file, read all lines and close again
infile=open(pathname+filename,'r') infile=open(stream_file,'r')
inlines=infile.readlines() inlines=infile.readlines()
infile.close() infile.close()
# loop over lines and extract reciprocal cell axes # loop over lines and extract reciprocal cell axes
for line in inlines: for line in inlines:
if 'astar' in line: if 'astar' in line:
@@ -157,29 +154,25 @@ clen=np.asarray(clen)
f,((ax1,ax2,ax3))=plt.subplots(1,3) f,((ax1,ax2,ax3))=plt.subplots(1,3)
ax1.hist(10.*alen,int(5*np.sqrt(len(alen))),normed=1,facecolor='green',edgecolor='green') ax1.hist(10.*alen,int(5*np.sqrt(len(alen))),density=True,facecolor='green',edgecolor='green')
atitle=r'$\mathit{a}$' atitle=r'$\mathit{a}$'
ax1.set_title(atitle) ax1.set_title(atitle)
ax2.hist(10.*blen,int(5*np.sqrt(len(blen))),normed=1,facecolor='green',edgecolor='green') ax2.hist(10.*blen,int(5*np.sqrt(len(blen))),density=True,facecolor='green',edgecolor='green')
btitle=r'$\mathit{b}$' btitle=r'$\mathit{b}$'
ax2.set_title(btitle) ax2.set_title(btitle)
ax3.hist(10.*clen,int(5*np.sqrt(len(clen))),normed=1,facecolor='green',edgecolor='green') ax3.hist(10.*clen,int(5*np.sqrt(len(clen))),density=True,facecolor='green',edgecolor='green')
ctitle=r'$\mathit{c}$' ctitle=r'$\mathit{c}$'
ax3.set_title(ctitle) ax3.set_title(ctitle)
f.canvas.manager.set_window_title('Unit Cell Parameter Histograms')
f.canvas.set_window_title('Unit Cell Parameter Histograms')
f.set_size_inches(10,5) f.set_size_inches(10,5)
plt.tight_layout() plt.tight_layout()
plt.show() plt.show()
step=50 # plot every nth point only
# plot a, coloured by length of a (normalized to maximum length observed) # plot a, coloured by length of a (normalized to maximum length observed)
print 'I will plot every',step,'th point,',len(adir[::step,0]),'points in total...' print('I will plot every',step,'th point,',len(adir[::step,0]),'points in total...')
ProjectionPlot(adir[::step,0],adir[::step,1],adir[::step,2],(alen[::step]/np.max(alen)),'a_axis_direction') ProjectionPlot(adir[::step,0],adir[::step,1],adir[::step,2],(alen[::step]/np.max(alen)),'a_axis_direction')
@@ -187,5 +180,29 @@ ProjectionPlot(bdir[::step,0],bdir[::step,1],bdir[::step,2],(blen[::step]/np.max
ProjectionPlot(cdir[::step,0],cdir[::step,1],cdir[::step,2],(clen[::step]/np.max(clen)),'c_axis_direction') ProjectionPlot(cdir[::step,0],cdir[::step,1],cdir[::step,2],(clen[::step]/np.max(clen)),'c_axis_direction')
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-f",
"--stream_file",
help="stream file of interest for assessment of crystal orientations",
type=os.path.abspath
)
parser.add_argument(
"-r",
"--reindex",
help="do you need to adjust the cell parameters because CrystFEL has set a > b",
type=bool,
default=False
)
parser.add_argument(
"-s",
"--step",
help="how many points should i plot - every 1/10, 1/25?",
type=int,
default=25
)
args = parser.parse_args()
# run main
main( args.stream_file, args.reindex, args.step )
# FIN....