updated to include argparse and figs in a fucntion
This commit is contained in:
@@ -1,4 +1,19 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# author J.Beale, T.Mason
|
||||||
|
|
||||||
|
"""
|
||||||
|
# aim
|
||||||
|
given a regular array of crystfel folders with different detector distances
|
||||||
|
- naming covention = #.###/#.###.stream
|
||||||
|
script will generate a graph analysing the detector distance as a function of the unit-cell constants
|
||||||
|
|
||||||
|
# usage
|
||||||
|
python update-geom-from-lab6.py -f <path to top folder> either coarse or fine
|
||||||
|
|
||||||
|
# output
|
||||||
|
creates plots of the unit cell axis against clen
|
||||||
|
"""
|
||||||
|
|
||||||
# modules
|
# modules
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -6,6 +21,7 @@ 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
|
||||||
|
|
||||||
|
|
||||||
def scrub_clen( stream_pwd ):
|
def scrub_clen( stream_pwd ):
|
||||||
@@ -67,6 +83,80 @@ def scrub_us( stream ):
|
|||||||
return cells
|
return cells
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return np.nan
|
return np.nan
|
||||||
|
|
||||||
|
def find_clen_values(stats_df):
|
||||||
|
|
||||||
|
def find_min_clen(col_name):
|
||||||
|
min_val = stats_df[col_name].min()
|
||||||
|
min_row = stats_df[stats_df[col_name] == min_val]
|
||||||
|
min_clen = min_row['clen'].values[0]
|
||||||
|
return min_val, min_clen
|
||||||
|
|
||||||
|
min_alpha_val, min_alpha_clen = find_min_clen('std_alpha')
|
||||||
|
min_beta_val, min_beta_clen = find_min_clen('std_beta')
|
||||||
|
min_gamma_val, min_gamma_clen = find_min_clen('std_gamma')
|
||||||
|
min_c_val, min_c_clen = find_min_clen('std_c')
|
||||||
|
|
||||||
|
print("The value of clen for the minimum alpha value of {} is {}".format(min_alpha_val, min_alpha_clen))
|
||||||
|
print("The value of clen for the minimum beta value of {} is {}".format(min_beta_val, min_beta_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 ):
|
||||||
|
|
||||||
|
# indexed images plot
|
||||||
|
color = "tab:red"
|
||||||
|
ax1.set_xlabel("clen")
|
||||||
|
ax1.set_ylabel("indexed", color=color)
|
||||||
|
ax1.plot(stats_df.clen, stats_df.indexed, color=color)
|
||||||
|
ax1.tick_params(axis="y", labelcolor=color)
|
||||||
|
|
||||||
|
# label color
|
||||||
|
color = "tab:blue"
|
||||||
|
ax2.set_ylabel("a,b,c st.deviation", color=color)
|
||||||
|
ax2.tick_params(axis='y', labelcolor=color)
|
||||||
|
|
||||||
|
# std_a plot
|
||||||
|
color = "lightsteelblue"
|
||||||
|
ax2.plot(stats_df.clen, stats_df.std_a, color=color)
|
||||||
|
|
||||||
|
# std_b plot
|
||||||
|
color = "cornflowerblue"
|
||||||
|
ax2.plot(stats_df.clen, stats_df.std_b, color=color)
|
||||||
|
|
||||||
|
# std_c plot
|
||||||
|
color = "royalblue"
|
||||||
|
ax2.plot(stats_df.clen, stats_df.std_c, color=color)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_indexed_std_alpha_beta_gamma( stats_df, ax1, ax2 ):
|
||||||
|
|
||||||
|
# indexed images plot
|
||||||
|
color = "tab:red"
|
||||||
|
ax1.set_xlabel("clen")
|
||||||
|
ax1.set_ylabel("indexed", color=color)
|
||||||
|
ax1.plot(stats_df.clen, stats_df.indexed, color=color)
|
||||||
|
ax1.tick_params(axis="y", labelcolor=color)
|
||||||
|
|
||||||
|
# label color
|
||||||
|
color = "tab:green"
|
||||||
|
ax2.set_ylabel("alpha, beta, gamma st.deviation", color=color)
|
||||||
|
ax2.tick_params(axis='y', labelcolor=color)
|
||||||
|
|
||||||
|
# std_alpha plot
|
||||||
|
color = "limegreen"
|
||||||
|
ax2.plot(stats_df.clen, stats_df.std_alpha, color=color)
|
||||||
|
|
||||||
|
# std_beta plot
|
||||||
|
color = "darkgreen"
|
||||||
|
ax2.plot(stats_df.clen, stats_df.std_beta, color=color)
|
||||||
|
|
||||||
|
# std_gamma plot
|
||||||
|
color = "green"
|
||||||
|
ax2.plot(stats_df.clen, stats_df.std_gamma, color=color)
|
||||||
|
|
||||||
def main( top_dir ):
|
def main( top_dir ):
|
||||||
|
|
||||||
@@ -76,7 +166,7 @@ def main( top_dir ):
|
|||||||
print( "done" )
|
print( "done" )
|
||||||
|
|
||||||
# making results df for unit cell and index no.
|
# making results df for unit cell and index no.
|
||||||
results_df = pd.DataFrame()
|
stats_df = pd.DataFrame()
|
||||||
|
|
||||||
# loop through stream files and collect unit_cell information
|
# loop through stream files and collect unit_cell information
|
||||||
print( "looping through stream files to collect unit cell, indexed information" )
|
print( "looping through stream files to collect unit cell, indexed information" )
|
||||||
@@ -101,55 +191,53 @@ def main( top_dir ):
|
|||||||
std_a = cells_df.a.std()
|
std_a = cells_df.a.std()
|
||||||
std_b = cells_df.b.std()
|
std_b = cells_df.b.std()
|
||||||
std_c = cells_df.c.std()
|
std_c = cells_df.c.std()
|
||||||
|
std_alpha = cells_df.alpha.std()
|
||||||
|
std_beta = cells_df.beta.std()
|
||||||
|
std_gamma = cells_df.gamma.std()
|
||||||
|
|
||||||
# put stats in results df
|
# put stats in results df
|
||||||
stats = [ { "clen" : clen,
|
stats = [ { "clen" : clen,
|
||||||
"indexed" : indexed,
|
"indexed" : indexed,
|
||||||
"std_a" : std_a,
|
"std_a" : std_a,
|
||||||
"std_b" : std_b,
|
"std_b" : std_b,
|
||||||
"std_c" : std_c
|
"std_c" : std_c,
|
||||||
|
"std_alpha" : std_alpha,
|
||||||
|
"std_beta" : std_beta,
|
||||||
|
"std_gamma" : std_gamma,
|
||||||
} ]
|
} ]
|
||||||
results_df_1 = pd.DataFrame( stats )
|
stats_df_1 = pd.DataFrame( stats )
|
||||||
results_df = pd.concat( ( results_df, results_df_1 ) )
|
stats_df = pd.concat( ( stats_df, stats_df_1 ) )
|
||||||
|
|
||||||
print( "done" )
|
print( "done" )
|
||||||
|
|
||||||
# reset index
|
# reset index
|
||||||
results_df = results_df.reset_index( drop=True )
|
stats_df = stats_df.reset_index( drop=True )
|
||||||
|
|
||||||
|
#print clen for minimum alpha, beta, and gamma values
|
||||||
|
find_clen_values(stats_df)
|
||||||
|
|
||||||
# plot results
|
# plot results
|
||||||
fig, ax1 = plt.subplots()
|
fig, (ax1, ax3) = plt.subplots(1, 2)
|
||||||
|
|
||||||
# indexed images plot
|
|
||||||
color = "tab:red"
|
|
||||||
ax1.set_xlabel( "clen" )
|
|
||||||
ax1.set_ylabel( "indexed", color=color )
|
|
||||||
ax1.plot( results_df.clen, results_df.indexed, color=color)
|
|
||||||
ax1.tick_params( axis="y", labelcolor=color)
|
|
||||||
|
|
||||||
# instantiate a second axes that shares the same x-axis
|
|
||||||
ax2 = ax1.twinx()
|
ax2 = ax1.twinx()
|
||||||
|
ax4 = ax3.twinx()
|
||||||
|
|
||||||
# std_a plot
|
plot_indexed_std(stats_df, ax1, ax2)
|
||||||
color = "tab:blue"
|
plot_indexed_std_alpha_beta_gamma(stats_df, ax3, ax4)
|
||||||
ax2.set_ylabel( "st.deviation", color=color )
|
|
||||||
ax2.plot( results_df.clen, results_df.std_a, color=color )
|
|
||||||
ax2.tick_params(axis='y', labelcolor=color)
|
|
||||||
|
|
||||||
# std_b plot
|
fig.tight_layout()
|
||||||
ax2.plot( results_df.clen, results_df.std_b, color=color )
|
|
||||||
ax2.tick_params(axis='y', labelcolor=color)
|
|
||||||
|
|
||||||
# std_b plot
|
|
||||||
ax2.plot( results_df.clen, results_df.std_c, color=color )
|
|
||||||
ax2.tick_params(axis='y', labelcolor=color)
|
|
||||||
|
|
||||||
fig.tight_layout() # otherwise the right y-label is slightly clipped
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
# variables
|
|
||||||
top_dir = "/sf/cristallina/data/p20590/work/process/jhb/detector_refinement/coarse_scan"
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"-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 )
|
||||||
|
|
||||||
main( top_dir )
|
|
||||||
|
|||||||
Reference in New Issue
Block a user