Version 0.12

This commit is contained in:
rskoupy
2023-12-01 15:47:37 +01:00
parent 5641f0adbd
commit 4c839d9843
2 changed files with 284 additions and 94 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 90,
"id": "7425242d-3c91-4c1e-a424-08625a38ee7a",
"metadata": {},
"outputs": [],
@ -11,6 +11,7 @@
"import numpy as np\n",
"import scipy.constants as cons\n",
"import plotly.graph_objects as go\n",
"from scipy.interpolate import splrep, BSpline \n",
"from copy import deepcopy\n",
"from pandas import read_excel\n",
"from IPython.display import display\n",
@ -298,7 +299,7 @@
},
{
"cell_type": "code",
"execution_count": 68,
"execution_count": 723,
"id": "8055b802-cf83-4250-aea9-54e3e6b73db0",
"metadata": {},
"outputs": [],
@ -319,23 +320,22 @@
"matrix = ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', **align, tooltips=['', ''])\n",
"cl = ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal (cm)', **align, tooltips=['', ''])\n",
"camera = Dropdown(options=opt.detectors(), description='Detector', **align3, tooltips=['', ''])\n",
"restriction = ToggleButtons(options=[('NO',False), ('YES',True)], description='Use PAAR',**align3, tooltips=['', ''])\n",
"binning = ToggleButtons(options=[('NO',1), ('2×2',2), ('4×4',4),('6×6',6),('8×8',8)], description='Binning', **align, tooltips=['Full detector resolution', 'Binning 2x2 - detector resolution /2, pixel size *2', 'Binning 4x4'])\n",
"restriction = ToggleButtons(options=[('No',False), ('Yes',True)], description='Use PAAR',**align3, tooltips=['', ''])\n",
"binning = ToggleButtons(options=[('No',1), ('2x2',2), ('4x4',4),('6×6',6),('8×8',8)], description='Binning', **align, tooltips=['Full detector resolution', 'Binning 2x2 - detector resolution /2, pixel size *2', 'Binning 4x4'])\n",
"dwell_time = ToggleButtons(options=opt.dwelltimes(), value=10, description='Dwell time (μs)', **align, tooltips=['', ''])\n",
"\n",
"### Small controls ###\n",
"align2 = dict(layout=Layout(width='200px') , style = {'description_width': '100px','button_width': '100px'}, disabled=False,)\n",
"method = ToggleButtons(options=[('Direct methods','direct'), ('Iterative methods','iterative')], description='', **align2, button_style='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"ctf_xaxis = RadioButtons(options=['mrad', 'A'], description='CTF-SSB x-axis:', **align2) \n",
"method = ToggleButtons(options=[('SSB','direct'), ('Iterative recon.','iterative')], description='', **align2, button_style='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='CTF x-axis:', **align2) \n",
"scans = RadioButtons(options=[4,6,8,10],description='Beam positions:',continuous_update=False, **align2)\n",
"\n",
"\n",
"cl_check_laa = Checkbox(value=True, description='Low angle approximation', disabled=False, indent=False,) # Low angle approximation check - scattering angle < 10 deg\n",
"cl_check_pix = Checkbox(value=True, description='Ptycho pixel < step size', disabled=False, indent=False,) # Reconstructed pixel size < scanning step size \n",
"cl_check_def = Checkbox(value=True, description='Beam fits in probe window', disabled=False, indent=False,) # Is probe window big enough to accomodate defocused probe?\n",
"cl_check_nbf = Checkbox(value=True, description='Detector cover < 1α', disabled=False, indent=False,) # Detector cover is lower than 1 α; orange\n",
"\n",
"\n",
"cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', disabled=False, indent=False,) # Detector cover is lower than 1 α; orange\n",
"cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', disabled=False, indent=False,) # Detector cover is lower than 1 α; orange\n",
" \n",
"\n",
"\n",
@ -367,10 +367,10 @@
"col3 = VBox([Label('Camera length'), cl, HBox([restriction, cl_det_res])], layout=box_layout)\n",
"col4 = VBox([Label('Detection'), HBox([camera, camera_res]), pixel_size_res, binning, dwell_time, dwell_time_res], layout=box_layout)\n",
"\n",
"small_control = VBox([Label('Graph controls'),method, ctf_xaxis, scans, VBox([Label('Camera length check list'), cl_check_laa, cl_check_pix, cl_check_def, cl_check_nbf])], layout = Layout(border='dashed 0px gray',margin='32px 30px 00px 10px', padding='5px 5px 5px 5px'))\n",
"small_control = VBox([Label('Graph controls'),method, ctf_xaxis, scans, VBox([Label('Camera length check list'), cl_check_laa, cl_check_pix, cl_check_def, cl_check_1bf, cl_check_nbf])], layout = Layout(border='dashed 0px gray',margin='32px 30px 00px 10px', padding='5px 5px 5px 5px'))\n",
"controls = HBox([VBox([Label(''), col1, col2, col3, col4]), small_control])\n",
"\n",
"def ptycho_interact(beam, aperture, probe, cl, matrix, defocus, mag, camera, binning, dwell_time, restriction, method, ctf_xaxis, scans, cl_check_laa, cl_check_pix, cl_check_def, cl_check_nbf):\n",
"def ptycho_interact(beam, aperture, probe, cl, matrix, defocus, mag, camera, binning, dwell_time, restriction, method, ctf_xaxis, scans, cl_check_laa, cl_check_pix, cl_check_def, cl_check_1bf, cl_check_nbf):\n",
" \n",
" ### SINGLE SETTING PARAMETERS ###\n",
" wavelength = pty.get_wavelength(beam)*1e12\n",
@ -417,30 +417,7 @@
" pctf = pty.get_ssb_ctf()\n",
" apertury = opt.apertures()\n",
" \n",
" ### PROBE ##########################################\n",
" fig = go.Figure() \n",
" fig.update_yaxes(title_text=\" CTF-SSB\")\n",
" xx = 2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100\n",
" if ctf_xaxis == 'mrad': \n",
" for x in apertury:\n",
" fig.add_trace(go.Scatter(showlegend=False, x=pty.get_angle_corr(x) *omega, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
" \n",
" fig.add_trace(go.Scatter(x=semi_angle_corr*omega, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (mrad)\", range=[0, 60], zeroline=False)\n",
"\n",
" elif ctf_xaxis == 'A':\n",
" for x in apertury:\n",
" d = 2*wavelength/(np.sin(pty.get_angle_corr(x)*omega/1000))/100\n",
" fig.add_trace(go.Scatter(showlegend=False, x=d, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
" \n",
" fig.add_trace(go.Scatter(x=xx, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\", range=[0.0001, 2.5], type=\"log\", zeroline=False)\n",
" \n",
" fig.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=0.75,xanchor=\"right\",x=1))\n",
" # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig.update_layout(width=800, height=225, margin = dict(l=110, r=30, t=30, b=30))\n",
"\n",
" \n",
" \n",
" ### SAMPLE PLANE ##########################################\n",
" yyy = np.append(np.linspace(0,overlap,100), 200)\n",
" wid = np.linspace(0,scans-1,scans) * step_size_corr\n",
@ -574,6 +551,35 @@
" if method == 'direct':\n",
" \n",
" \n",
" ### PROBE ##########################################\n",
" fig = go.Figure() \n",
" fig.update_yaxes(title_text=\" CTF\")\n",
" xx = 2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100\n",
" \n",
" if ctf_xaxis == 'α': \n",
" fig.add_trace(go.Scatter(x=omega, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Scattering angle (α)\", range=[0, 2], zeroline=False)\n",
" \n",
" if ctf_xaxis == 'mrad': \n",
" for x in apertury:\n",
" fig.add_trace(go.Scatter(showlegend=False, x=pty.get_angle_corr(x) *omega, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
"\n",
" fig.add_trace(go.Scatter(x=semi_angle_corr*omega, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (mrad)\", range=[0, 60], zeroline=False)\n",
"\n",
" elif ctf_xaxis == 'A':\n",
" for x in apertury:\n",
" d = 2*wavelength/(np.sin(pty.get_angle_corr(x)*omega/1000))/100\n",
" fig.add_trace(go.Scatter(showlegend=False, x=d, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
"\n",
" fig.add_trace(go.Scatter(x=xx, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\", range=[-0.5, 2.5], type=\"log\", zeroline=False)\n",
"\n",
" fig.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=0.75,xanchor=\"right\",x=1))\n",
" # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig.update_layout(width=800, height=225, margin = dict(l=110, r=30, t=30, b=30))\n",
" \n",
" \n",
" ssb_sampling = Label(value = f'Recommended sampling (Å) '+ str(np.round(xx[-1]/3,2)), **align3) \n",
" \n",
" ### CAMERA LENGTH GRAPH ##########################################\n",
@ -605,7 +611,51 @@
" \n",
" \n",
" \n",
" if method == 'iterative':\n",
" if method == 'iterative': \n",
" \n",
" ### PROBE ##########################################\n",
" fig = go.Figure() \n",
" fig.update_yaxes(title_text=\" CTF\")\n",
" \n",
" \n",
" omega =np.array([0, 0.07, 0.125 ,0.25, 0.50, 0.75, 1.00, 1.25, 1.50, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.00, 4.25, 4.500, 4.750, 5.000])\n",
" pctf = np.array([0, 0.8, 0.95 ,0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.80, 0.6, 0.40, 0.3, 0.20, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01, 0.005, 0.002, 0.001])\n",
" \n",
" tck = splrep(omega, pctf, s=0.01)\n",
" xnew = np.linspace(1e-6,5,100)\n",
" pctf_new = BSpline(*tck)(xnew)\n",
" \n",
" if ctf_xaxis == 'α': \n",
" fig.add_trace(go.Scatter(showlegend=False, x=xnew, y=pctf_new, marker_color='red',))\n",
" fig.update_xaxes(title_text=\"Scattering angle (α)\", range=[0, 5], zeroline=False)\n",
" pctf_upper = pctf_new+xnew/30\n",
" pctf_lower = pctf_new-xnew/30\n",
" fig.add_trace(go.Scatter(showlegend=False, x=np.concatenate((xnew,xnew[::-1])), y=np.concatenate((pctf_lower,pctf_upper[::-1])),fill='toself', fillcolor='rgba(0,100,80,0.2)', line=dict(color='rgba(255,255,255,0)'),hoverinfo=\"skip\",))\n",
" fig.update_yaxes(range=[0, 1.1])\n",
" \n",
" if ctf_xaxis == 'mrad': \n",
" for x in apertury:\n",
" fig.add_trace(go.Scatter(showlegend=False, x=pty.get_angle_corr(x) *xnew, y=pctf_new, marker_color='gray', name='',))\n",
"\n",
" fig.add_trace(go.Scatter(x=semi_angle_corr*xnew, y=pctf_new, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (mrad)\", range=[0, 100], zeroline=False)\n",
"\n",
" elif ctf_xaxis == 'A':\n",
" for x in apertury:\n",
" d = 2*wavelength/(np.sin(pty.get_angle_corr(x)*xnew/1000))/100\n",
" fig.add_trace(go.Scatter(showlegend=False, x=d, y=pctf_new, marker_color='gray', name='CTF',))\n",
" \n",
" xx = 2*wavelength/(np.sin(semi_angle_corr*xnew/1000))/100\n",
" fig.add_trace(go.Scatter(x=xx, y=pctf_new, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\",range=[-0.5, 2], type=\"log\", zeroline=False) # \n",
"\n",
" fig.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=0.75,xanchor=\"right\",x=1))\n",
" # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig.update_layout(width=800, height=225, margin = dict(l=110, r=30, t=30, b=30))\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" checks = VBox([Label('Final checks'),check1, check2, check3,electron_dose,focusdepth, acquisition_time]) \n",
" checks.layout = Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
@ -636,14 +686,24 @@
" \n",
" ### CAMERA LENGTH TABLE ########################################## \n",
" dictionary = {}\n",
" tab = np.array([np.round(ptycho_pixel_size_all,2),np.round(detector_cover_all,1), np.round(detector_cover_a_all,1), np.round(max_defocus_all,1), np.array(opt.cameralengths())])\n",
" \n",
" tab = np.array([np.round(ptycho_pixel_size_all,2),np.round(detector_cover_all,1), np.round(detector_cover_a_all,1), np.round(max_defocus_all,1), opt.cameralengths()])\n",
"\n",
" align6 = dict(layout=Layout(width='50px') , style = {'description_width': '0px','button_width': \"33px\"}, disabled=True,)\n",
" align7 = dict(layout=Layout(width='130px') , style = {'description_width': '0px','button_width': \"110px\"}, disabled=True,)\n",
" \n",
" for i in range(0,12):\n",
" button_style = 'success'\n",
" data = tab[:,int(i)] # 0. ptycho pix, 1.det cov 2.det cov a, 3.max def, 4.cl\n",
"\n",
" \n",
" data_tuple = tuple(tab[0:4,int(i)]) + (\"\",tab[4,int(i)])\n",
" \n",
" \n",
" icons=['','','','','']\n",
" \n",
" if cl_check_nbf == True: \n",
" if data[2] > 6:\n",
" button_style = 'warning' \n",
" \n",
" if cl_check_laa == True:\n",
" if data[1] > 1000*np.radians(10):\n",
" button_style = 'danger' \n",
@ -656,13 +716,17 @@
" if data[3] < defocus:\n",
" button_style = 'danger'\n",
" \n",
" if cl_check_nbf == True: \n",
" if cl_check_1bf == True: \n",
" if data[2] < 1:\n",
" button_style = 'danger' \n",
" \n",
" if cl == data[4]:\n",
" icons=['','','','','check']\n",
" \n",
" \n",
" dictionary[i] = ToggleButtons(options=data, description='',button_style=button_style, **align6)\n",
" dictionary[i] = ToggleButtons(options=data_tuple, button_style=button_style, icons = icons, **align6)\n",
" \n",
" legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. defocus (nm)','Nominal CL (cm)'], \n",
" legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. defocus (nm)','Selected by CL ','Nominal CL (cm)',], \n",
" tooltips=['Dependent on: detector, beam energy, camera length',\n",
" 'Dependent on: detector, camera length',\n",
" 'Dependent on: detector, camera length, probe semi-angle',\n",
@ -671,8 +735,6 @@
" ],button_style='', **align7) \n",
" \n",
" \n",
" \n",
" \n",
" cltab = HBox([legend,dictionary[0],dictionary[1],dictionary[2],dictionary[3],dictionary[4],dictionary[5],dictionary[6],dictionary[7],dictionary[8],dictionary[9], dictionary[10],dictionary[11]])\n",
" cltab = VBox([Label('Chose your reconstructed ptychographic pixe size, check needed defocus and set CL'), cltab])\n",
" cltab.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 10px', padding='10px 10px 10px 10px')\n",
@ -690,7 +752,8 @@
" \n",
"gui = interactive_output(ptycho_interact, {\"beam\": beam, \"aperture\": aperture, \"probe\": probe, \"cl\": cl, \"matrix\": matrix, \"defocus\": defocus, \"mag\": mag, \"camera\": camera,\n",
" \"binning\": binning, \"dwell_time\": dwell_time, \"restriction\": restriction, \"method\": method, \"ctf_xaxis\": ctf_xaxis, \"scans\": scans,\n",
" \"cl_check_laa\":cl_check_laa, \"cl_check_pix\": cl_check_pix, \"cl_check_def\": cl_check_def, \"cl_check_nbf\": cl_check_nbf}) "
" \"cl_check_laa\":cl_check_laa, \"cl_check_pix\": cl_check_pix, \"cl_check_def\": cl_check_def, \"cl_check_1bf\": cl_check_1bf, \"cl_check_nbf\": cl_check_nbf}) \n",
"\n"
]
},
{
@ -723,14 +786,14 @@
},
{
"cell_type": "code",
"execution_count": 69,
"execution_count": 724,
"id": "7937f054-fcd0-4e67-a20f-7696f5903a94",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0d132191d4f0427aaa01278a955425f0",
"model_id": "c5196eb493e44de8a1d09eccbeee46ad",
"version_major": 2,
"version_minor": 0
},
@ -745,6 +808,38 @@
"source": [
"display(HBox([controls, gui]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79e73498-4e48-4617-9085-95b6c01597c9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0661a5fa-f65c-45cf-a6f4-39d1f9f186cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ba255a1-e209-4107-8a8f-0a1cac8cce90",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b939697a-2ab0-49b2-8c73-555bb62a2e0d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 90,
"id": "7425242d-3c91-4c1e-a424-08625a38ee7a",
"metadata": {},
"outputs": [],
@ -11,6 +11,7 @@
"import numpy as np\n",
"import scipy.constants as cons\n",
"import plotly.graph_objects as go\n",
"from scipy.interpolate import splrep, BSpline \n",
"from copy import deepcopy\n",
"from pandas import read_excel\n",
"from IPython.display import display\n",
@ -298,7 +299,7 @@
},
{
"cell_type": "code",
"execution_count": 68,
"execution_count": 723,
"id": "8055b802-cf83-4250-aea9-54e3e6b73db0",
"metadata": {},
"outputs": [],
@ -319,23 +320,22 @@
"matrix = ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', **align, tooltips=['', ''])\n",
"cl = ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal (cm)', **align, tooltips=['', ''])\n",
"camera = Dropdown(options=opt.detectors(), description='Detector', **align3, tooltips=['', ''])\n",
"restriction = ToggleButtons(options=[('NO',False), ('YES',True)], description='Use PAAR',**align3, tooltips=['', ''])\n",
"binning = ToggleButtons(options=[('NO',1), ('2×2',2), ('4×4',4),('6×6',6),('8×8',8)], description='Binning', **align, tooltips=['Full detector resolution', 'Binning 2x2 - detector resolution /2, pixel size *2', 'Binning 4x4'])\n",
"restriction = ToggleButtons(options=[('No',False), ('Yes',True)], description='Use PAAR',**align3, tooltips=['', ''])\n",
"binning = ToggleButtons(options=[('No',1), ('2x2',2), ('4x4',4),('6×6',6),('8×8',8)], description='Binning', **align, tooltips=['Full detector resolution', 'Binning 2x2 - detector resolution /2, pixel size *2', 'Binning 4x4'])\n",
"dwell_time = ToggleButtons(options=opt.dwelltimes(), value=10, description='Dwell time (μs)', **align, tooltips=['', ''])\n",
"\n",
"### Small controls ###\n",
"align2 = dict(layout=Layout(width='200px') , style = {'description_width': '100px','button_width': '100px'}, disabled=False,)\n",
"method = ToggleButtons(options=[('Direct methods','direct'), ('Iterative methods','iterative')], description='', **align2, button_style='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"ctf_xaxis = RadioButtons(options=['mrad', 'A'], description='CTF-SSB x-axis:', **align2) \n",
"method = ToggleButtons(options=[('SSB','direct'), ('Iterative recon.','iterative')], description='', **align2, button_style='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='CTF x-axis:', **align2) \n",
"scans = RadioButtons(options=[4,6,8,10],description='Beam positions:',continuous_update=False, **align2)\n",
"\n",
"\n",
"cl_check_laa = Checkbox(value=True, description='Low angle approximation', disabled=False, indent=False,) # Low angle approximation check - scattering angle < 10 deg\n",
"cl_check_pix = Checkbox(value=True, description='Ptycho pixel < step size', disabled=False, indent=False,) # Reconstructed pixel size < scanning step size \n",
"cl_check_def = Checkbox(value=True, description='Beam fits in probe window', disabled=False, indent=False,) # Is probe window big enough to accomodate defocused probe?\n",
"cl_check_nbf = Checkbox(value=True, description='Detector cover < 1α', disabled=False, indent=False,) # Detector cover is lower than 1 α; orange\n",
"\n",
"\n",
"cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', disabled=False, indent=False,) # Detector cover is lower than 1 α; orange\n",
"cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', disabled=False, indent=False,) # Detector cover is lower than 1 α; orange\n",
" \n",
"\n",
"\n",
@ -367,10 +367,10 @@
"col3 = VBox([Label('Camera length'), cl, HBox([restriction, cl_det_res])], layout=box_layout)\n",
"col4 = VBox([Label('Detection'), HBox([camera, camera_res]), pixel_size_res, binning, dwell_time, dwell_time_res], layout=box_layout)\n",
"\n",
"small_control = VBox([Label('Graph controls'),method, ctf_xaxis, scans, VBox([Label('Camera length check list'), cl_check_laa, cl_check_pix, cl_check_def, cl_check_nbf])], layout = Layout(border='dashed 0px gray',margin='32px 30px 00px 10px', padding='5px 5px 5px 5px'))\n",
"small_control = VBox([Label('Graph controls'),method, ctf_xaxis, scans, VBox([Label('Camera length check list'), cl_check_laa, cl_check_pix, cl_check_def, cl_check_1bf, cl_check_nbf])], layout = Layout(border='dashed 0px gray',margin='32px 30px 00px 10px', padding='5px 5px 5px 5px'))\n",
"controls = HBox([VBox([Label(''), col1, col2, col3, col4]), small_control])\n",
"\n",
"def ptycho_interact(beam, aperture, probe, cl, matrix, defocus, mag, camera, binning, dwell_time, restriction, method, ctf_xaxis, scans, cl_check_laa, cl_check_pix, cl_check_def, cl_check_nbf):\n",
"def ptycho_interact(beam, aperture, probe, cl, matrix, defocus, mag, camera, binning, dwell_time, restriction, method, ctf_xaxis, scans, cl_check_laa, cl_check_pix, cl_check_def, cl_check_1bf, cl_check_nbf):\n",
" \n",
" ### SINGLE SETTING PARAMETERS ###\n",
" wavelength = pty.get_wavelength(beam)*1e12\n",
@ -417,30 +417,7 @@
" pctf = pty.get_ssb_ctf()\n",
" apertury = opt.apertures()\n",
" \n",
" ### PROBE ##########################################\n",
" fig = go.Figure() \n",
" fig.update_yaxes(title_text=\" CTF-SSB\")\n",
" xx = 2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100\n",
" if ctf_xaxis == 'mrad': \n",
" for x in apertury:\n",
" fig.add_trace(go.Scatter(showlegend=False, x=pty.get_angle_corr(x) *omega, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
" \n",
" fig.add_trace(go.Scatter(x=semi_angle_corr*omega, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (mrad)\", range=[0, 60], zeroline=False)\n",
"\n",
" elif ctf_xaxis == 'A':\n",
" for x in apertury:\n",
" d = 2*wavelength/(np.sin(pty.get_angle_corr(x)*omega/1000))/100\n",
" fig.add_trace(go.Scatter(showlegend=False, x=d, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
" \n",
" fig.add_trace(go.Scatter(x=xx, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\", range=[0.0001, 2.5], type=\"log\", zeroline=False)\n",
" \n",
" fig.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=0.75,xanchor=\"right\",x=1))\n",
" # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig.update_layout(width=800, height=225, margin = dict(l=110, r=30, t=30, b=30))\n",
"\n",
" \n",
" \n",
" ### SAMPLE PLANE ##########################################\n",
" yyy = np.append(np.linspace(0,overlap,100), 200)\n",
" wid = np.linspace(0,scans-1,scans) * step_size_corr\n",
@ -574,6 +551,35 @@
" if method == 'direct':\n",
" \n",
" \n",
" ### PROBE ##########################################\n",
" fig = go.Figure() \n",
" fig.update_yaxes(title_text=\" CTF\")\n",
" xx = 2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100\n",
" \n",
" if ctf_xaxis == 'α': \n",
" fig.add_trace(go.Scatter(x=omega, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Scattering angle (α)\", range=[0, 2], zeroline=False)\n",
" \n",
" if ctf_xaxis == 'mrad': \n",
" for x in apertury:\n",
" fig.add_trace(go.Scatter(showlegend=False, x=pty.get_angle_corr(x) *omega, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
"\n",
" fig.add_trace(go.Scatter(x=semi_angle_corr*omega, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (mrad)\", range=[0, 60], zeroline=False)\n",
"\n",
" elif ctf_xaxis == 'A':\n",
" for x in apertury:\n",
" d = 2*wavelength/(np.sin(pty.get_angle_corr(x)*omega/1000))/100\n",
" fig.add_trace(go.Scatter(showlegend=False, x=d, y=pctf, marker_color='gray', name='SSB-CTF',))\n",
"\n",
" fig.add_trace(go.Scatter(x=xx, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\", range=[-0.5, 2.5], type=\"log\", zeroline=False)\n",
"\n",
" fig.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=0.75,xanchor=\"right\",x=1))\n",
" # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig.update_layout(width=800, height=225, margin = dict(l=110, r=30, t=30, b=30))\n",
" \n",
" \n",
" ssb_sampling = Label(value = f'Recommended sampling (Å) '+ str(np.round(xx[-1]/3,2)), **align3) \n",
" \n",
" ### CAMERA LENGTH GRAPH ##########################################\n",
@ -605,7 +611,51 @@
" \n",
" \n",
" \n",
" if method == 'iterative':\n",
" if method == 'iterative': \n",
" \n",
" ### PROBE ##########################################\n",
" fig = go.Figure() \n",
" fig.update_yaxes(title_text=\" CTF\")\n",
" \n",
" \n",
" omega =np.array([0, 0.07, 0.125 ,0.25, 0.50, 0.75, 1.00, 1.25, 1.50, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.00, 4.25, 4.500, 4.750, 5.000])\n",
" pctf = np.array([0, 0.8, 0.95 ,0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.80, 0.6, 0.40, 0.3, 0.20, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01, 0.005, 0.002, 0.001])\n",
" \n",
" tck = splrep(omega, pctf, s=0.01)\n",
" xnew = np.linspace(1e-6,5,100)\n",
" pctf_new = BSpline(*tck)(xnew)\n",
" \n",
" if ctf_xaxis == 'α': \n",
" fig.add_trace(go.Scatter(showlegend=False, x=xnew, y=pctf_new, marker_color='red',))\n",
" fig.update_xaxes(title_text=\"Scattering angle (α)\", range=[0, 5], zeroline=False)\n",
" pctf_upper = pctf_new+xnew/30\n",
" pctf_lower = pctf_new-xnew/30\n",
" fig.add_trace(go.Scatter(showlegend=False, x=np.concatenate((xnew,xnew[::-1])), y=np.concatenate((pctf_lower,pctf_upper[::-1])),fill='toself', fillcolor='rgba(0,100,80,0.2)', line=dict(color='rgba(255,255,255,0)'),hoverinfo=\"skip\",))\n",
" fig.update_yaxes(range=[0, 1.1])\n",
" \n",
" if ctf_xaxis == 'mrad': \n",
" for x in apertury:\n",
" fig.add_trace(go.Scatter(showlegend=False, x=pty.get_angle_corr(x) *xnew, y=pctf_new, marker_color='gray', name='',))\n",
"\n",
" fig.add_trace(go.Scatter(x=semi_angle_corr*xnew, y=pctf_new, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (mrad)\", range=[0, 100], zeroline=False)\n",
"\n",
" elif ctf_xaxis == 'A':\n",
" for x in apertury:\n",
" d = 2*wavelength/(np.sin(pty.get_angle_corr(x)*xnew/1000))/100\n",
" fig.add_trace(go.Scatter(showlegend=False, x=d, y=pctf_new, marker_color='gray', name='CTF',))\n",
" \n",
" xx = 2*wavelength/(np.sin(semi_angle_corr*xnew/1000))/100\n",
" fig.add_trace(go.Scatter(x=xx, y=pctf_new, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\",range=[-0.5, 2], type=\"log\", zeroline=False) # \n",
"\n",
" fig.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=0.75,xanchor=\"right\",x=1))\n",
" # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig.update_layout(width=800, height=225, margin = dict(l=110, r=30, t=30, b=30))\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" checks = VBox([Label('Final checks'),check1, check2, check3,electron_dose,focusdepth, acquisition_time]) \n",
" checks.layout = Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
@ -636,14 +686,24 @@
" \n",
" ### CAMERA LENGTH TABLE ########################################## \n",
" dictionary = {}\n",
" tab = np.array([np.round(ptycho_pixel_size_all,2),np.round(detector_cover_all,1), np.round(detector_cover_a_all,1), np.round(max_defocus_all,1), np.array(opt.cameralengths())])\n",
" \n",
" tab = np.array([np.round(ptycho_pixel_size_all,2),np.round(detector_cover_all,1), np.round(detector_cover_a_all,1), np.round(max_defocus_all,1), opt.cameralengths()])\n",
"\n",
" align6 = dict(layout=Layout(width='50px') , style = {'description_width': '0px','button_width': \"33px\"}, disabled=True,)\n",
" align7 = dict(layout=Layout(width='130px') , style = {'description_width': '0px','button_width': \"110px\"}, disabled=True,)\n",
" \n",
" for i in range(0,12):\n",
" button_style = 'success'\n",
" data = tab[:,int(i)] # 0. ptycho pix, 1.det cov 2.det cov a, 3.max def, 4.cl\n",
"\n",
" \n",
" data_tuple = tuple(tab[0:4,int(i)]) + (\"\",tab[4,int(i)])\n",
" \n",
" \n",
" icons=['','','','','']\n",
" \n",
" if cl_check_nbf == True: \n",
" if data[2] > 6:\n",
" button_style = 'warning' \n",
" \n",
" if cl_check_laa == True:\n",
" if data[1] > 1000*np.radians(10):\n",
" button_style = 'danger' \n",
@ -656,13 +716,17 @@
" if data[3] < defocus:\n",
" button_style = 'danger'\n",
" \n",
" if cl_check_nbf == True: \n",
" if cl_check_1bf == True: \n",
" if data[2] < 1:\n",
" button_style = 'danger' \n",
" \n",
" if cl == data[4]:\n",
" icons=['','','','','check']\n",
" \n",
" \n",
" dictionary[i] = ToggleButtons(options=data, description='',button_style=button_style, **align6)\n",
" dictionary[i] = ToggleButtons(options=data_tuple, button_style=button_style, icons = icons, **align6)\n",
" \n",
" legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. defocus (nm)','Nominal CL (cm)'], \n",
" legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. defocus (nm)','Selected by CL ','Nominal CL (cm)',], \n",
" tooltips=['Dependent on: detector, beam energy, camera length',\n",
" 'Dependent on: detector, camera length',\n",
" 'Dependent on: detector, camera length, probe semi-angle',\n",
@ -671,8 +735,6 @@
" ],button_style='', **align7) \n",
" \n",
" \n",
" \n",
" \n",
" cltab = HBox([legend,dictionary[0],dictionary[1],dictionary[2],dictionary[3],dictionary[4],dictionary[5],dictionary[6],dictionary[7],dictionary[8],dictionary[9], dictionary[10],dictionary[11]])\n",
" cltab = VBox([Label('Chose your reconstructed ptychographic pixe size, check needed defocus and set CL'), cltab])\n",
" cltab.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 10px', padding='10px 10px 10px 10px')\n",
@ -690,7 +752,8 @@
" \n",
"gui = interactive_output(ptycho_interact, {\"beam\": beam, \"aperture\": aperture, \"probe\": probe, \"cl\": cl, \"matrix\": matrix, \"defocus\": defocus, \"mag\": mag, \"camera\": camera,\n",
" \"binning\": binning, \"dwell_time\": dwell_time, \"restriction\": restriction, \"method\": method, \"ctf_xaxis\": ctf_xaxis, \"scans\": scans,\n",
" \"cl_check_laa\":cl_check_laa, \"cl_check_pix\": cl_check_pix, \"cl_check_def\": cl_check_def, \"cl_check_nbf\": cl_check_nbf}) "
" \"cl_check_laa\":cl_check_laa, \"cl_check_pix\": cl_check_pix, \"cl_check_def\": cl_check_def, \"cl_check_1bf\": cl_check_1bf, \"cl_check_nbf\": cl_check_nbf}) \n",
"\n"
]
},
{
@ -723,14 +786,14 @@
},
{
"cell_type": "code",
"execution_count": 69,
"execution_count": 724,
"id": "7937f054-fcd0-4e67-a20f-7696f5903a94",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0d132191d4f0427aaa01278a955425f0",
"model_id": "c5196eb493e44de8a1d09eccbeee46ad",
"version_major": 2,
"version_minor": 0
},
@ -745,6 +808,38 @@
"source": [
"display(HBox([controls, gui]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79e73498-4e48-4617-9085-95b6c01597c9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0661a5fa-f65c-45cf-a6f4-39d1f9f186cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ba255a1-e209-4107-8a8f-0a1cac8cce90",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b939697a-2ab0-49b2-8c73-555bb62a2e0d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {