Update convert-scan-for-pyfai.py

This commit is contained in:
2023-03-22 13:13:29 +00:00
parent 7a7e565197
commit fc1cc47b88

View File

@@ -4,6 +4,7 @@
""" """
# aim # aim
- -16M=varient for large detectors
make image file to input into pyFAI for initial detector beam-centre and detector distance calibration make image file to input into pyFAI for initial detector beam-centre and detector distance calibration
refer to Cristallina8M-calibration for complete protocol refer to Cristallina8M-calibration for complete protocol
https://docs.google.com/document/d/1RoeUUogvRxX4M6uqGwkjf3dVJBabiMUx4ZxwcA5e9Dc/edit# https://docs.google.com/document/d/1RoeUUogvRxX4M6uqGwkjf3dVJBabiMUx4ZxwcA5e9Dc/edit#
@@ -36,25 +37,46 @@ import argparse
def convert_image( path_to_json, jungfrau, name ): def convert_image( path_to_json, jungfrau, name ):
# opens scan # opens scan
print( "opening scane" )
scan = SFScanInfo( path_to_json ) scan = SFScanInfo( path_to_json )
# step through scan and average files from each positions # steps in scane
mean_image = [] nsteps = len(scan)
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)
# define step ch and im_shape
step = scan[0]
ch = step[jungfrau]
img_shape = ch[0].shape
print("stepping through scan and averaging images at each step")
# step through scan and average files from each positions
imgs_shape = (nsteps, *img_shape)
imgs = np.empty(imgs_shape)
for i, subset in tqdm(enumerate(scan)):
# go through data in_batches so you don't run out of memory
ch = subset[jungfrau]
mean = np.zeros(img_shape)
for _indices, batch in ch.in_batches(size=2):
mean += np.mean(batch, axis=0)
# take mean of means for batch opened data
imgs[i] = mean
print( "done" )
# sum averaged imaged # sum averaged imaged
sum_image = np.sum( mean_image, axis=0 ) print( "final average" )
mean_image = imgs.mean(axis=0)
print("done")
# output to file # output to file
np.save( "{0}.npy".format( name ), sum_image ) print( "saving to .npy = {0}".format( name ) )
np.save( "{0}.npy".format( name ), mean_image )
print( "done" )
# create plot of summed, averaged scan # create plot of summed, averaged scan
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.imshow(sum_image, vmin=0, vmax=1000) ax.imshow(mean_image, vmin=0, vmax=1000)
plt.show() plt.show()
if __name__ == "__main__": if __name__ == "__main__":
@@ -78,7 +100,7 @@ if __name__ == "__main__":
"--name", "--name",
help="name of output file", help="name of output file",
type=str, type=str,
default="sum_mean_scan" default="mean_scan"
) )
args = parser.parse_args() args = parser.parse_args()