labels to graph and removal of argparse
This commit is contained in:
@@ -9,7 +9,7 @@ given a regular array of crystfel folders with different detector distances
|
|||||||
script will generate a graph analysing the detector distance as a function of the unit-cell constants
|
script will generate a graph analysing the detector distance as a function of the unit-cell constants
|
||||||
|
|
||||||
# usage
|
# usage
|
||||||
python update-geom-from-lab6.py -f <path to top folder> either coarse or fine
|
python update-geom-from-lab6.py <path-to-scan-folder>
|
||||||
|
|
||||||
# output
|
# output
|
||||||
creates plots of the unit cell axis against clen
|
creates plots of the unit cell axis against clen
|
||||||
@@ -21,7 +21,9 @@ import regex as re
|
|||||||
import os
|
import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import argparse
|
import sys
|
||||||
|
from scipy.optimize import curve_fit
|
||||||
|
from scipy.signal import peak_widths, find_peaks
|
||||||
|
|
||||||
|
|
||||||
def scrub_clen( stream_pwd ):
|
def scrub_clen( stream_pwd ):
|
||||||
@@ -84,7 +86,7 @@ def scrub_us( stream ):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return np.nan
|
return np.nan
|
||||||
|
|
||||||
def find_clen_values(stats_df):
|
def find_clen_values( stats_df ):
|
||||||
|
|
||||||
def find_min_clen(col_name):
|
def find_min_clen(col_name):
|
||||||
min_val = stats_df[col_name].min()
|
min_val = stats_df[col_name].min()
|
||||||
@@ -92,17 +94,45 @@ def find_clen_values(stats_df):
|
|||||||
min_clen = min_row['clen'].values[0]
|
min_clen = min_row['clen'].values[0]
|
||||||
return min_val, min_clen
|
return min_val, min_clen
|
||||||
|
|
||||||
|
def gauss(x, *p):
|
||||||
|
|
||||||
|
A, mu, sigma = p
|
||||||
|
return A * np.exp(-(x-mu)**2/(2.*sigma**2))
|
||||||
|
|
||||||
|
p0 = [ 30, 0.111, 0.01 ]
|
||||||
|
parameters, covariance = curve_fit( gauss, stats_df.clen, stats_df.indexed, p0=p0 )
|
||||||
|
|
||||||
|
# Get the fitted curve
|
||||||
|
stats_df[ "gaus" ] = gauss( stats_df.clen, *parameters)
|
||||||
|
# find peak centre
|
||||||
|
peaks = find_peaks( stats_df.gaus.values )
|
||||||
|
|
||||||
|
# find full peak width
|
||||||
|
fwhm = peak_widths( stats_df.gaus.values, peaks[0], rel_height=0.5 )
|
||||||
|
|
||||||
|
fwhm_str = int( round( fwhm[2][0], 0 ) )
|
||||||
|
fwhm_end = int( round( fwhm[3][0], 0 ) )
|
||||||
|
|
||||||
|
# translate width into motor values
|
||||||
|
indexed_start = stats_df.iloc[ fwhm_str, 0 ]
|
||||||
|
indexed_end = stats_df.iloc[ fwhm_end, 0 ]
|
||||||
|
mid_gauss = stats_df.clen.iloc[ peaks[0] ].values[0]
|
||||||
|
|
||||||
|
# cut df to only include indexed patterns
|
||||||
|
stats_df = stats_df[ ( stats_df.clen < indexed_end ) & ( stats_df.clen > indexed_start ) ]
|
||||||
|
|
||||||
|
# calculate minimum values
|
||||||
min_alpha_val, min_alpha_clen = find_min_clen('std_alpha')
|
min_alpha_val, min_alpha_clen = find_min_clen('std_alpha')
|
||||||
min_beta_val, min_beta_clen = find_min_clen('std_beta')
|
min_beta_val, min_beta_clen = find_min_clen('std_beta')
|
||||||
min_gamma_val, min_gamma_clen = find_min_clen('std_gamma')
|
min_gamma_val, min_gamma_clen = find_min_clen('std_gamma')
|
||||||
min_c_val, min_c_clen = find_min_clen('std_c')
|
min_c_val, min_c_clen = find_min_clen('std_c')
|
||||||
|
|
||||||
|
# find possible clens
|
||||||
|
suggested_clen = (min_alpha_clen + min_beta_clen + min_gamma_clen )/3
|
||||||
|
suggested_clen = round(suggested_clen, 4)
|
||||||
|
|
||||||
print("The value of clen for the minimum alpha value of {} is {}".format(min_alpha_val, min_alpha_clen))
|
print( "middle of indexing gaussion fit of scan = {0}".format( mid_gauss ) )
|
||||||
print("The value of clen for the minimum beta value of {} is {}".format(min_beta_val, min_beta_clen))
|
print( "mean minimum of alpha, beta, gamma of scan = {0}".format( suggested_clen ) )
|
||||||
print("The value of clen for the minimum gamma value of {} is {}".format(min_gamma_val, min_gamma_clen))
|
|
||||||
print("The value of clen for the minimum c value of {} is {}".format(min_c_val, min_c_clen))
|
|
||||||
|
|
||||||
# return min_alpha_clen, min_beta_clen, min_gamma_clen, min_c_clen, min_alpha_val, min_beta_val, min_gamma_val, min_c_val
|
|
||||||
|
|
||||||
|
|
||||||
def plot_indexed_std( stats_df, ax1, ax2 ):
|
def plot_indexed_std( stats_df, ax1, ax2 ):
|
||||||
@@ -120,17 +150,16 @@ def plot_indexed_std( stats_df, ax1, ax2 ):
|
|||||||
ax2.tick_params(axis='y', labelcolor=color)
|
ax2.tick_params(axis='y', labelcolor=color)
|
||||||
|
|
||||||
# std_a plot
|
# std_a plot
|
||||||
color = "lightsteelblue"
|
color = "turquoise"
|
||||||
ax2.plot(stats_df.clen, stats_df.std_a, color=color)
|
ax2.plot(stats_df.clen, stats_df.std_a, color=color, label="a" )
|
||||||
|
|
||||||
# std_b plot
|
# std_b plot
|
||||||
color = "cornflowerblue"
|
color = "deepskyblue"
|
||||||
ax2.plot(stats_df.clen, stats_df.std_b, color=color)
|
ax2.plot(stats_df.clen, stats_df.std_b, color=color, label="b" )
|
||||||
|
|
||||||
# std_c plot
|
# std_c plot
|
||||||
color = "royalblue"
|
color = "royalblue"
|
||||||
ax2.plot(stats_df.clen, stats_df.std_c, color=color)
|
ax2.plot(stats_df.clen, stats_df.std_c, color=color, label="c" )
|
||||||
|
|
||||||
|
|
||||||
def plot_indexed_std_alpha_beta_gamma( stats_df, ax1, ax2 ):
|
def plot_indexed_std_alpha_beta_gamma( stats_df, ax1, ax2 ):
|
||||||
|
|
||||||
@@ -147,16 +176,16 @@ def plot_indexed_std_alpha_beta_gamma( stats_df, ax1, ax2 ):
|
|||||||
ax2.tick_params(axis='y', labelcolor=color)
|
ax2.tick_params(axis='y', labelcolor=color)
|
||||||
|
|
||||||
# std_alpha plot
|
# std_alpha plot
|
||||||
color = "limegreen"
|
color = "yellow"
|
||||||
ax2.plot(stats_df.clen, stats_df.std_alpha, color=color)
|
ax2.plot(stats_df.clen, stats_df.std_alpha, color=color, label="alpha" )
|
||||||
|
|
||||||
# std_beta plot
|
# std_beta plot
|
||||||
color = "darkgreen"
|
color = "green"
|
||||||
ax2.plot(stats_df.clen, stats_df.std_beta, color=color)
|
ax2.plot(stats_df.clen, stats_df.std_beta, color=color, label="beta" )
|
||||||
|
|
||||||
# std_gamma plot
|
# std_gamma plot
|
||||||
color = "green"
|
color = "darkolivegreen"
|
||||||
ax2.plot(stats_df.clen, stats_df.std_gamma, color=color)
|
ax2.plot(stats_df.clen, stats_df.std_gamma, color=color, label="gamma" )
|
||||||
|
|
||||||
def main( top_dir ):
|
def main( top_dir ):
|
||||||
|
|
||||||
@@ -175,7 +204,6 @@ def main( top_dir ):
|
|||||||
stream_pwd, clen = row[ "stream_pwd" ], row[ "clen" ]
|
stream_pwd, clen = row[ "stream_pwd" ], row[ "clen" ]
|
||||||
|
|
||||||
# open stream file
|
# open stream file
|
||||||
print( "scrubbing stream for clen={0}".format( clen ) )
|
|
||||||
stream = open( stream_pwd, "r" ).read()
|
stream = open( stream_pwd, "r" ).read()
|
||||||
|
|
||||||
# scrub unit cell information
|
# scrub unit cell information
|
||||||
@@ -208,7 +236,7 @@ def main( top_dir ):
|
|||||||
stats_df_1 = pd.DataFrame( stats )
|
stats_df_1 = pd.DataFrame( stats )
|
||||||
stats_df = pd.concat( ( stats_df, stats_df_1 ) )
|
stats_df = pd.concat( ( stats_df, stats_df_1 ) )
|
||||||
|
|
||||||
print( "done" )
|
print( "done" )
|
||||||
|
|
||||||
# reset index
|
# reset index
|
||||||
stats_df = stats_df.reset_index( drop=True )
|
stats_df = stats_df.reset_index( drop=True )
|
||||||
@@ -224,20 +252,12 @@ def main( top_dir ):
|
|||||||
plot_indexed_std(stats_df, ax1, ax2)
|
plot_indexed_std(stats_df, ax1, ax2)
|
||||||
plot_indexed_std_alpha_beta_gamma(stats_df, ax3, ax4)
|
plot_indexed_std_alpha_beta_gamma(stats_df, ax3, ax4)
|
||||||
|
|
||||||
|
fig.legend(loc="upper center")
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
stream_pwd = sys.argv[1]
|
||||||
parser.add_argument(
|
main( stream_pwd )
|
||||||
"-f",
|
|
||||||
"--scan_folder",
|
|
||||||
help="give the scan folder path used in the earlier part of the calculation",
|
|
||||||
type=str,
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
|
||||||
# run geom converter
|
|
||||||
main( args.scan_folder )
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user