From 9fb67f43024cdab229190052001dd8b08c9c7c86 Mon Sep 17 00:00:00 2001 From: Beale John Henry Date: Thu, 9 Mar 2023 15:00:55 +0100 Subject: [PATCH] first scripts --- convert-scan-for-pyfai.py | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 convert-scan-for-pyfai.py diff --git a/convert-scan-for-pyfai.py b/convert-scan-for-pyfai.py new file mode 100644 index 0000000..d53a47a --- /dev/null +++ b/convert-scan-for-pyfai.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +""" +# aim +make image file for input into pyFAI for initial detector + +# protocol +take scan of LaB6 +vanile settings for crystallina 8M are 100 scan positions, 10 shots per position +run this on output + +# usage +python make-tiff.py -j -s -n + +# output +creates a .npy file that can be loaded directly into pyFAI +""" + +# modules +from matplotlib import pyplot as plt +import numpy as np +from sfdata import SFScanInfo +from tqdm import tqdm +import argparse + +def convert_image( path_to_json, jungfrau, name ): + + # opens scan + scan = SFScanInfo( path_to_json ) + + # step through scan and average files from each positions + mean_image = [] + for step in tqdm( enumerate(scan) ): + # step is a SFDataFiles object + subset = step[1] + mean = np.mean( subset[ jungfrau ].data, axis=0 ) + mean_image.append(mean) + + # sum averaged imaged + sum_image = np.sum( mean_image, axis=0 ) + + # output to file + np.save( "{0}.npy".format( name ), sum_image ) + + # create plot of summed, averaged scan + fig, ax = plt.subplots() + ax.imshow(sum_image, vmin=0, vmax=1000) + plt.show() + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-j", + "--jungfrau", + help="name of the jungfrau used", + type=str, + default="JF17T16V01" + ) + parser.add_argument( + "-s", + "--scan", + help="path to json scan file", + type=str, + default="/sf/cristallina/data/p20590/raw/run0003/meta/scan.json" + ) + parser.add_argument( + "-n", + "--name", + help="name of output file", + type=str, + default="sum_mean_scan" + ) + args = parser.parse_args() + + convert_image( args.scan, args.jungfrau, args.name )