Skip to content
Snippets Groups Projects
Commit dd2f4348 authored by Loïc Le Guyader's avatar Loïc Le Guyader
Browse files

Merge branch 'updates' into 'master'

Collection of small updates

Closes #7, #6, #8, and #5

See merge request SCS/tzpgcalc!14
parents f77282f9 24dcf15a
No related branches found
No related tags found
1 merge request!14Collection of small updates
This diff is collapsed.
from setuptools import setup, find_packages from setuptools import setup, find_packages
install_requires = [pandas, scipy, sympy, matplotlib, ipywidgets]
setup(name='TZPGcalc', setup(name='TZPGcalc',
version=1.0, version=1.0,
description='TZPG calculator for SCS', description='TZPG calculator for SCS',
...@@ -8,5 +10,6 @@ setup(name='TZPGcalc', ...@@ -8,5 +10,6 @@ setup(name='TZPGcalc',
url='https://in.xfel.eu/gitlab/SCS/tzpgcalc', url='https://in.xfel.eu/gitlab/SCS/tzpgcalc',
packages=find_packages('src'), packages=find_packages('src'),
package_dir={'': 'src'}, package_dir={'': 'src'},
install_requires=install_requires,
python_requires='>=3.8' python_requires='>=3.8'
) )
...@@ -113,6 +113,13 @@ class TZPGcalc(): ...@@ -113,6 +113,13 @@ class TZPGcalc():
for k in ['L', 'H']: for k in ['L', 'H']:
self.SpotSizes[d][k] = np.zeros((6, 2)) self.SpotSizes[d][k] = np.zeros((6, 2))
# spot center of all beams
self.SpotCenters = {}
for d in ['det', 'sam']:
self.SpotCenters[d] = {}
for k in ['L', 'H']:
self.SpotCenters[d][k] = np.zeros((6, 2))
self.UpdateFig() self.UpdateFig()
display(self.control) display(self.control)
...@@ -147,10 +154,10 @@ class TZPGcalc(): ...@@ -147,10 +154,10 @@ class TZPGcalc():
self.ax_det.set_ylim([-20, 50]) self.ax_det.set_ylim([-20, 50])
# red and blue shifted color of the beams # red and blue shifted color of the beams
c_rr = hsv_to_rgb([0/360, 50/100, 100/100]) c_rr = hsv_to_rgb([10/360, 100/100, 70/100])
c_rb = hsv_to_rgb([40/360, 50/100, 100/100]) c_rb = hsv_to_rgb([220/360, 100/100, 70/100])
c_gr = hsv_to_rgb([95/360, 60/100, 100/100]) c_gr = hsv_to_rgb([10/360, 100/100, 100/100])
c_gb = hsv_to_rgb([145/360, 60/100, 100/100]) c_gb = hsv_to_rgb([220/360, 100/100, 100/100])
self.samBeamsL = { self.samBeamsL = {
'F0G0': self.ax_sam.add_patch( 'F0G0': self.ax_sam.add_patch(
...@@ -216,11 +223,11 @@ class TZPGcalc(): ...@@ -216,11 +223,11 @@ class TZPGcalc():
'module': self.ax_det.add_patch( 'module': self.ax_det.add_patch(
Rectangle((0, 0), 1, 1, fill=False, facecolor='k')), Rectangle((0, 0), 1, 1, fill=False, facecolor='k')),
'Vfilter': self.ax_det.add_patch( 'Vfilter': self.ax_det.add_patch(
Rectangle((0, 0), 1, 1, facecolor="blue", alpha=0.4)), Rectangle((0, 0), 1, 1, facecolor="green", alpha=0.4)),
'Hfilter': self.ax_det.add_patch( 'Hfilter': self.ax_det.add_patch(
Rectangle((0, 0), 1, 1, facecolor="blue", alpha=0.4)), Rectangle((0, 0), 1, 1, facecolor="green", alpha=0.4)),
'diamond': self.ax_det.add_patch( 'diamond': self.ax_det.add_patch(
Rectangle((-8, -8), 16, 16, facecolor="blue", alpha=0.4, Rectangle((-8, -8), 16, 16, facecolor="green", alpha=0.4,
angle=45)) angle=45))
} }
...@@ -367,6 +374,8 @@ class TZPGcalc(): ...@@ -367,6 +374,8 @@ class TZPGcalc():
vs = corners[:, k] vs = corners[:, k]
self.SpotSizes[img['type']][conf['Energy']][z, k] = ( self.SpotSizes[img['type']][conf['Energy']][z, k] = (
1e3*(np.max(vs) - np.min(vs))) 1e3*(np.max(vs) - np.min(vs)))
self.SpotCenters[img['type']][conf['Energy']][z, k] = (
1e3*0.5*(np.max(vs) + np.min(vs)))
# 3 beams configuration # 3 beams configuration
b = self.widgets['3beams'].value b = self.widgets['3beams'].value
...@@ -554,6 +563,12 @@ class TZPGcalc(): ...@@ -554,6 +563,12 @@ class TZPGcalc():
columns=['H (um)', 'V (um)']) columns=['H (um)', 'V (um)'])
self.widgets[f'SpotSize{v}'].value = df.to_html( self.widgets[f'SpotSize{v}'].value = df.to_html(
float_format='{:.2f}'.format) float_format='{:.2f}'.format)
df = pd.DataFrame(self.SpotCenters['sam'][v],
index=['F0G-1', 'F0G0', 'F0G1',
'F1G-1', 'F1G0', 'F1G1'],
columns=['H (um)', 'V (um)'])
self.widgets[f'SpotCenter{v}'].value = df.to_html(
float_format='{:.2f}'.format)
# update the detector # update the detector
detXoff = self.widgets['detX'].value*1e-3 # [m] detXoff = self.widgets['detX'].value*1e-3 # [m]
...@@ -589,6 +604,19 @@ class TZPGcalc(): ...@@ -589,6 +604,19 @@ class TZPGcalc():
widgets.Label(value='High energy'), widgets.Label(value='High energy'),
self.widgets['SpotSizeH']]) self.widgets['SpotSizeH']])
]) ])
# Spot centers
self.widgets['SpotCenterL'] = widgets.HTML()
self.widgets['SpotCenterH'] = widgets.HTML()
SpotCenter = HBox([VBox([widgets.Label(value='Low energy'),
self.widgets['SpotCenterL']]),
VBox([
widgets.Label(value='High energy'),
self.widgets['SpotCenterH']])
])
SpotSizeAndCenter = HBox([
VBox([widgets.Label(value='Spot Size'), SpotSize]),
VBox([widgets.Label(value='Spot center'), SpotCenter])
])
# Source # Source
self.Reset = widgets.Button( self.Reset = widgets.Button(
...@@ -715,7 +743,7 @@ class TZPGcalc(): ...@@ -715,7 +743,7 @@ class TZPGcalc():
style=style, style=style,
layout=layout layout=layout
) )
self.widgets['TZPGwH'] = widgets.BoundedFloatText( self.widgets['TZPGwV'] = widgets.BoundedFloatText(
value=1.0, value=1.0,
min=.1, min=.1,
max=3.0, max=3.0,
...@@ -724,7 +752,7 @@ class TZPGcalc(): ...@@ -724,7 +752,7 @@ class TZPGcalc():
style=style, style=style,
layout=layout layout=layout
) )
self.widgets['TZPGwV'] = widgets.BoundedFloatText( self.widgets['TZPGwH'] = widgets.BoundedFloatText(
value=1.0, value=1.0,
min=.1, min=.1,
max=3.0, max=3.0,
...@@ -771,11 +799,11 @@ class TZPGcalc(): ...@@ -771,11 +799,11 @@ class TZPGcalc():
self.widgets['3beams']]), self.widgets['3beams']]),
HBox([self.widgets['dr_label_x'], HBox([self.widgets['dr_label_x'],
self.widgets['dr_label_y']]), self.widgets['dr_label_y']]),
HBox([widgets.Label(value='Energy range (eV):'), HBox([widgets.Label(value='Optics (mm):'),
self.widgets['nrjL'], self.widgets['nrjH']]),
HBox([widgets.Label(value='TZPG (mm):'),
self.widgets['TZPGwH'], self.widgets['TZPGwH'],
self.widgets['TZPGwV']]) self.widgets['TZPGwV']]),
HBox([widgets.Label(value='Energy range (eV):'),
self.widgets['nrjL'], self.widgets['nrjH']])
]) ])
# sample part # sample part
...@@ -959,8 +987,8 @@ class TZPGcalc(): ...@@ -959,8 +987,8 @@ class TZPGcalc():
tab3.set_title(0, 'Detector') tab3.set_title(0, 'Detector')
tab3.selected_index = 0 tab3.selected_index = 0
tab4 = widgets.Accordion([SpotSize]) tab4 = widgets.Accordion([SpotSizeAndCenter])
tab4.set_title(0, 'Spot sizes') tab4.set_title(0, 'Spot sizes and centers')
tab4.selected_index = 0 tab4.selected_index = 0
self.control = VBox([self.Update, tab0, tab1, tab2, tab3, tab4]) self.control = VBox([self.Update, tab0, tab1, tab2, tab3, tab4])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment