-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxray_calibration.py
45 lines (36 loc) · 1.53 KB
/
xray_calibration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# ------------------------------------------------------------
# Copyright (c) All rights reserved
# SiLab, Institute of Physics, University of Bonn
# ------------------------------------------------------------
#
''' This script creates calibration plots from analyzed beam profiles,
using saved data in pickle format and plot functions from the xray_plotting class
'''
import os
import pickle
import logging
import coloredlogs
import xray
logger = logging.getLogger(__name__)
coloredlogs.install(level='INFO', logger=logger)
path = os.path.join('data', 'calibration')
calibration_filename = 'calibration.pkl'
xplt = xray.plotting()
filelist = xplt._create_filelist(path=path)
calibration = {}
for filename in filelist:
try:
distance = int(filename.split('/')[-1].split('cm')[0].split('_')[-1])
peak_intensity, beam_diameter = xplt.plot_data(filename=filename, background='auto', unit='rad', chip='none', distance=distance)
calibration.update({distance: {'peak_intensity': peak_intensity, 'beam_diameter': beam_diameter}})
logger.info('Processed "{}"'.format(filename))
except RuntimeError as e:
logger.error('Error loading {}/n{}'.format(filename, e))
# Save the analyzed calibration data
with open(calibration_filename, 'wb') as f:
pickle.dump(calibration, f, pickle.HIGHEST_PROTOCOL)
with open(calibration_filename, 'rb') as f:
data = pickle.load(f)
sorted_data = {k: v for k, v in sorted(data.items(), key=lambda item: item[0])}
xplt.plot_calibration_curves(path=path, data=sorted_data)