Version 0.08

This commit is contained in:
rskoupy
2023-11-29 13:53:56 +01:00
parent c72b6f1c57
commit 1c4addafc7
3 changed files with 90 additions and 100 deletions

View File

@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 170,
"id": "7425242d-3c91-4c1e-a424-08625a38ee7a",
"metadata": {},
"outputs": [],
@ -339,7 +339,7 @@
" return dwell_time_res.value\n",
" \n",
" def show_cd_det(self,caller):\n",
" cl_det_res.value = f'Detector camera length (cm) {pty.get_cl_detector(caller.new)}' \n",
" cl_det_res.value = f'Detector CL (cm) {pty.get_cl_detector(caller.new)}' \n",
" return cl_det_res.value\n",
" \n",
" \n",
@ -349,18 +349,18 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 179,
"id": "8055b802-cf83-4250-aea9-54e3e6b73db0",
"metadata": {},
"outputs": [],
"source": [
"### CONTROLS ##########################################\n",
"align = dict(layout=widgets.Layout(width='385px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary',disabled=False,)\n",
"align2 = dict(layout=widgets.Layout(width='250px') , style = {'description_width': '100px','button_width': '50px'}, disabled=False,)\n",
"align3 = dict(layout=widgets.Layout(width='230px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary', disabled=False,)\n",
"to_right = dict(layout=widgets.Layout(display=\"flex\", justify_content=\"flex-end\", width=\"95%\", ))\n",
"\n",
"to_right2 = dict(layout=widgets.Layout(display=\"flex\", justify_content=\"flex-end\", width=\"35%\", ))\n",
"### Main controls ###\n",
"beam = widgets.Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align)\n",
"beam = widgets.Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align3)\n",
"aperture = widgets.ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', **align, tooltips=['', ''])\n",
"probe = widgets.ToggleButtons(options=opt.probes(), value='8C', description='Probe', **align, tooltips=['', ''])\n",
"defocus = widgets.IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, **align )\n",
@ -368,20 +368,21 @@
"mag = widgets.ToggleButtons(options=opt.magnifications(),value=3,description='Mag. (Mx)', **align) \n",
"matrix = widgets.ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', **align, tooltips=['', ''])\n",
"cl = widgets.ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal (cm)', **align, tooltips=['', ''])\n",
"camera = widgets.Dropdown(options=opt.detectors(), description='Detector', **align, tooltips=['', ''])\n",
"restriction = widgets.ToggleButtons(options=[('NO',False), ('YES',True)], description='Use PAAR',**align, tooltips=['', ''])\n",
"camera = widgets.Dropdown(options=opt.detectors(), description='Detector', **align3, tooltips=['', ''])\n",
"restriction = widgets.ToggleButtons(options=[('NO',False), ('YES',True)], description='Use PAAR',**align3, tooltips=['', ''])\n",
"binning = widgets.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",
"dwell_time = widgets.ToggleButtons(options=opt.dwelltimes(), value=10, description='Dwell time (μs)', **align, tooltips=['', ''])\n",
"\n",
"### Small controls ###\n",
"method = widgets.ToggleButtons(options=[('Direct','direct'), ('Iterative','iterative')], description='Methods', **align2, button_style='primary', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"align2 = dict(layout=widgets.Layout(width='200px') , style = {'description_width': '100px','button_width': '50px'}, disabled=False,)\n",
"method = widgets.ToggleButtons(options=[('Direct','direct'), ('Iterative','iterative')], description='Methods', **align2, button_style='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"ssb_freq_length = widgets.RadioButtons(options=['mrad', 'A'], description='CTF-SSB x-axis:', **align2) \n",
"scans = widgets.RadioButtons(options=[4,6,8,10],description='Scan points:',continuous_update=False, **align2)\n",
"\n",
"### Live update ### \n",
"beam_res = widgets.Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), **to_right)\n",
"beam_res = widgets.Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), **to_right2)\n",
"beam.observe(inte.show_wavelength, names='value')\n",
"camera_res = widgets.Label(value = f'Detector full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), **to_right)\n",
"camera_res = widgets.Label(value = f'Full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), **to_right2)\n",
"camera.observe(inte.show_detector, names='value')\n",
"pixel_size_res = widgets.Label(value = f'Native pixel size (μm) '+ str(\"{:.0f}\".format(pty.get_det_orig_pixel_size(camera.value))),**to_right)\n",
"camera.observe(inte.show_pixel_size, names='value')\n",
@ -393,33 +394,18 @@
"mag.observe(inte.show_fov, names='value') \n",
"dwell_time_res = widgets.Label(value = f'Frame rate (kHz) '+ str(pty.get_aq_frec(dwell_time.value)),**to_right)\n",
"dwell_time.observe(inte.show_frame_rate, names='value') \n",
"cl_det_res = widgets.Label(value = f'Detector camera length (cm) '+ str(pty.get_cl_detector(cl.value)),**to_right)\n",
"cl_det_res = widgets.Label(value = f'Detector CL (cm) '+ str(pty.get_cl_detector(cl.value)),**to_right2)\n",
"cl.observe(inte.show_cd_det, names='value') \n",
"\n",
"box_layout = widgets.Layout(border='solid 1px blue',margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"col1 = widgets.VBox([widgets.Label('Beam'), beam, aperture, probe, defocus])\n",
"col1.layout = box_layout\n",
"col2 = widgets.VBox([widgets.Label('Scanning'), mag, matrix])\n",
"col2.layout = box_layout\n",
"col3 = widgets.VBox([widgets.Label('Camera length'), cl, restriction])\n",
"col3.layout = box_layout\n",
"col4 = widgets.VBox([widgets.Label('Detection'), camera, binning, dwell_time])\n",
"col4.layout = box_layout\n",
"box_layout = widgets.Layout(border='solid 2px #1976D2',margin='0px 0px 0px 0px', padding='5px 5px 5px 5px')\n",
"col1 = widgets.VBox([widgets.Label('Beam'), widgets.HBox([beam ,beam_res]), aperture, probe, defocus], layout=box_layout) # aperture_res, aperture_res2,\n",
"col2 = widgets.VBox([widgets.Label('Scanning'), mag, fov_res, matrix], layout=box_layout)\n",
"col3 = widgets.VBox([widgets.Label('Camera length'), cl, widgets.HBox([restriction, cl_det_res])], layout=box_layout)\n",
"col4 = widgets.VBox([widgets.Label('Detection'), widgets.HBox([camera, camera_res]), pixel_size_res, binning, dwell_time, dwell_time_res], layout=box_layout)\n",
"\n",
"descriptions_beam = widgets.VBox([widgets.Label('Characteristics beam'), beam_res, aperture_res, aperture_res2])\n",
"descriptions_beam.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"descriptions_scan = widgets.VBox([widgets.Label('Characteristics scanning'), fov_res])\n",
"descriptions_scan.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"descriptions_cl = widgets.VBox([widgets.Label('Characteristics camera length'), cl_det_res])\n",
"descriptions_cl.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"descriptions_det = widgets.VBox([widgets.Label('Characteristics detector'), camera_res, pixel_size_res,dwell_time_res])\n",
"descriptions_det.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"\n",
"small_control = widgets.VBox([widgets.Label('Graph controls'),method, ssb_freq_length, scans, descriptions_beam, descriptions_scan, descriptions_cl, descriptions_det])\n",
"small_control = widgets.VBox([widgets.Label('Graph controls'),method, ssb_freq_length, scans], layout = widgets.Layout(border='dashed 0px gray',margin='32px 30px 00px 10px', padding='5px 5px 5px 5px'))\n",
"controls = widgets.HBox([widgets.VBox([widgets.Label(''), col1, col2, col3, col4]), small_control])\n",
"\n",
"\n",
"\n",
"def ptycho_interact(beam, aperture, probe, cl, matrix, defocus, mag, camera, binning, dwell_time, restriction, method, ssb_freq_length, scans):\n",
" \n",
" ### SINGLE SETTING PARAMETERS ###\n",
@ -483,7 +469,7 @@
" 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=2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (A?)\",range=[0, 2.5], type=\"log\", zeroline=False)\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\", range=[0, 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",
@ -495,10 +481,8 @@
" wid = np.linspace(0,scans-1,scans) * step_size_corr\n",
" \n",
" fig5 = make_subplots(specs=[[{\"secondary_y\": True}]])\n",
" fig5.update_xaxes(title_text=\"Sample plane (nm)\", range=[0, scans*step_size_corr], zeroline=False)\n",
" fig5.update_yaxes(range=[0, scans*step_size_corr], showticklabels=False)\n",
" \n",
" fig5.add_trace(go.Scatter(showlegend=False, x = scans*step_size_corr*np.ones(len(yyy)), y=yyy, opacity=1,mode='markers',marker_symbol = \"triangle-down\",marker=dict(size=20, color=yyy, colorscale='rainbow_r', showscale=False)),secondary_y=True) \n",
" fig5.update_xaxes(title_text=\"Sample plane (nm)\", range=[0, scans*step_size_corr], showgrid=False, zeroline=False)\n",
" fig5.update_yaxes(range=[0, scans*step_size_corr],showgrid=False, showticklabels=False)\n",
" for x in range(len(wid)):\n",
" fig5.add_trace(go.Scatter(showlegend=False, x=wid, y=np.ones(len(wid))*wid[x], marker_color='blue'),secondary_y=False)\n",
" for x in range(len(wid)): \n",
@ -509,7 +493,9 @@
" fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='#FF7F7F', name='Beam ⌀ '+ str(np.round(beam_diameter,2))+\" nm\"))\n",
" fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=0.9))\n",
" fig5.add_trace(go.Scatter(showlegend=False, x = scans*step_size_corr*np.ones(len(yyy)), y=yyy, opacity=1,mode='markers',marker_symbol = \"triangle-down\",marker=dict(size=20, color=yyy, colorscale='rainbow_r', showscale=False)),secondary_y=True) \n",
" fig5.update_yaxes(title_text=\"Overlap %\", range=[0, 100], showticklabels=True, tickvals = [0, 20, 40,50, 60,70, 80, 90, 100], secondary_y=True)\n",
" \n",
" \n",
" fig5.update_yaxes(title_text=\"Overlap %\", range=[0, 100],showgrid=False, showticklabels=True, tickvals = [0, 20, 40,50, 60,70, 80, 90, 100], secondary_y=True)\n",
" fig5.update_layout(title={'text': \"Sample\",'y':0.95, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
" fig5.update_layout(width=430, height=380, margin =dict(l=30, r=30, t=10, b=0))\n",
"\n",
@ -586,6 +572,10 @@
" fig8.add_trace(go.Scatter(showlegend=False, x=[-width, width], y=[-np.log(ssb_cl), -np.log(ssb_cl)], opacity=0.8, line=dict(color='green',width=3)))\n",
" fig8.add_annotation(x=-0.7*width, y=-np.log(ssb_cl),text=\"<b>REC for SSB</b>\", showarrow=False,align= 'left', yshift=-15)\n",
" \n",
" if restriction == True:\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-250, -4*semi_angle, None, 4*semi_angle, 250], y=[-reduc*0.2*y_down,-reduc*0.2*y_down,None,-reduc*0.2*y_down, -reduc*0.2*y_down],mode='lines', line=dict(color='black',width=7)))\n",
" fig8.add_annotation(x=-0.35*width, y=-reduc*0.2*y_down,text=\"<b>PAAR</b>\", showarrow=False,align= 'left', yshift=15)\n",
" \n",
" # Cover\n",
" fig8.add_annotation(x=0, y=-1.05*np.log(cl), ax=det_width, ay=-1.05*np.log(cl), xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\n",
" fig8.add_annotation(x=det_width,y=-1.05*np.log(cl), ax=0, ay=-1.05*np.log(cl), xref='x',yref='y',axref='x',ayref='y', text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\n",
@ -599,22 +589,27 @@
"\n",
" fig8.update_xaxes(title_text=\"\")\n",
" # fig8.update_layout(title={'text': \"Microscope\" ,'y':1, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
" fig8.update_layout(width=350, height=550, margin = dict(l=10, r=30, t=0, b=0))\n",
" fig8.update_layout(width=350, height=570, margin = dict(l=10, r=30, t=20, b=0))\n",
" fig8.update_layout(plot_bgcolor='white')\n",
" \n",
" \n",
" ### FINAL CHECKS ########################################## \n",
" align3 = dict(layout=widgets.Layout(width='250px') , style = {'description_width': '150px','button_width': \"100px\"}, disabled=True,) \n",
" align3 = dict(layout=widgets.Layout(width='200px') , style = {'description_width': '150px','button_width': \"100px\"}, disabled=True,) \n",
" \n",
" check1 = widgets.Valid(value= bool(overlap > 60), description='Overlap > 60 %', **align3)\n",
" check2 = widgets.Valid(value= bool(step_size_corr*10 > (wavelength * cl_det)/(num_pixels*size_pixel/1e6)/1e4), description='Ptycho pix < step size', **align3)\n",
" check3 = widgets.Valid(value= bool(beam_diameter/2 < probe_window/2), description='Beam ⌀ < window/2', **align3) \n",
" \n",
" electron_dose = widgets.Label(value = f'Electron dose (e/Å2) '+ str(np.round(dose,1)), **align3) \n",
" checks = widgets.VBox([widgets.Label('Final checks'),check1,check2, check3,electron_dose]) \n",
" checks.layout = widgets.Layout(border='solid 1px gray',margin='10px 10px 10px 10px', padding='10px 10px 10px 10px')\n",
"\n",
" \n",
" acquisition_time = widgets.Label(value = f'Acquisition time (s) '+ str(np.round(matrix*matrix*dwell_time/1e6,1)), **align3) \n",
" \n",
" focusdepth = widgets.Label(value = f'Depth of focus (nm) '+ str(np.round(wavelength/(semi_angle_corr/1000)**2/1000,1)), **align3) \n",
" \n",
" checks = widgets.VBox([widgets.Label('Final checks'),check1,check2, check3,electron_dose,focusdepth, acquisition_time]) \n",
" checks.layout = widgets.Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
"\n",
"\n",
" ### METHODS ########################################## \n",
" if method == 'direct':\n",
" \n",
@ -626,10 +621,10 @@
" fig4.add_trace(go.Scatter(x=np.array(ssb_cl), y=np.array(kolik),marker_size=12, marker_color='green', name = \"Rec SSB CL\"), secondary_y=True,) \n",
" fig4.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.65,xanchor=\"right\",x=0.9))\n",
" # fig4.update_layout(title={'text': \"CL to α\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig4.update_xaxes(title_text=\"Camera length (cm)\", type=\"log\", tickvals = opt.cameralengths())\n",
" fig4.update_xaxes(title_text=\"Nominal camera length (cm)\", type=\"log\", tickvals = opt.cameralengths())\n",
" fig4.update_layout(xaxis = dict(tickmode = 'array', tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels]))\n",
" fig4.update_yaxes(title_text=\" Cover angle (<b>mrad</b>)\", secondary_y=False)\n",
" fig4.update_yaxes(title_text=\" Cover angle (<b>α</b>)\", secondary_y=True)\n",
" fig4.update_yaxes(title_text=\" Cover angle (mrad)\", secondary_y=False)\n",
" fig4.update_yaxes(title_text=\" Cover angle (α)\",showgrid=False, secondary_y=True)\n",
" fig4.update_layout(xaxis = dict(tickmode = 'array', tickvals = opt.cameralengths()))\n",
" fig4.update_layout(width=800, height=225, margin =dict(l=110, r=30, t=30, b=30))\n",
" \n",
@ -734,19 +729,19 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 180,
"id": "7937f054-fcd0-4e67-a20f-7696f5903a94",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7a6580d06f9d47f8a76d6f13079ad042",
"model_id": "3ff56079396a4d12814896dd2a44263f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), Dropdown(des…"
"HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), HBox(childre…"
]
},
"metadata": {},

Binary file not shown.

View File

@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 170,
"id": "7425242d-3c91-4c1e-a424-08625a38ee7a",
"metadata": {},
"outputs": [],
@ -339,7 +339,7 @@
" return dwell_time_res.value\n",
" \n",
" def show_cd_det(self,caller):\n",
" cl_det_res.value = f'Detector camera length (cm) {pty.get_cl_detector(caller.new)}' \n",
" cl_det_res.value = f'Detector CL (cm) {pty.get_cl_detector(caller.new)}' \n",
" return cl_det_res.value\n",
" \n",
" \n",
@ -349,18 +349,18 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 179,
"id": "8055b802-cf83-4250-aea9-54e3e6b73db0",
"metadata": {},
"outputs": [],
"source": [
"### CONTROLS ##########################################\n",
"align = dict(layout=widgets.Layout(width='385px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary',disabled=False,)\n",
"align2 = dict(layout=widgets.Layout(width='250px') , style = {'description_width': '100px','button_width': '50px'}, disabled=False,)\n",
"align3 = dict(layout=widgets.Layout(width='230px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary', disabled=False,)\n",
"to_right = dict(layout=widgets.Layout(display=\"flex\", justify_content=\"flex-end\", width=\"95%\", ))\n",
"\n",
"to_right2 = dict(layout=widgets.Layout(display=\"flex\", justify_content=\"flex-end\", width=\"35%\", ))\n",
"### Main controls ###\n",
"beam = widgets.Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align)\n",
"beam = widgets.Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align3)\n",
"aperture = widgets.ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', **align, tooltips=['', ''])\n",
"probe = widgets.ToggleButtons(options=opt.probes(), value='8C', description='Probe', **align, tooltips=['', ''])\n",
"defocus = widgets.IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, **align )\n",
@ -368,20 +368,21 @@
"mag = widgets.ToggleButtons(options=opt.magnifications(),value=3,description='Mag. (Mx)', **align) \n",
"matrix = widgets.ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', **align, tooltips=['', ''])\n",
"cl = widgets.ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal (cm)', **align, tooltips=['', ''])\n",
"camera = widgets.Dropdown(options=opt.detectors(), description='Detector', **align, tooltips=['', ''])\n",
"restriction = widgets.ToggleButtons(options=[('NO',False), ('YES',True)], description='Use PAAR',**align, tooltips=['', ''])\n",
"camera = widgets.Dropdown(options=opt.detectors(), description='Detector', **align3, tooltips=['', ''])\n",
"restriction = widgets.ToggleButtons(options=[('NO',False), ('YES',True)], description='Use PAAR',**align3, tooltips=['', ''])\n",
"binning = widgets.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",
"dwell_time = widgets.ToggleButtons(options=opt.dwelltimes(), value=10, description='Dwell time (μs)', **align, tooltips=['', ''])\n",
"\n",
"### Small controls ###\n",
"method = widgets.ToggleButtons(options=[('Direct','direct'), ('Iterative','iterative')], description='Methods', **align2, button_style='primary', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"align2 = dict(layout=widgets.Layout(width='200px') , style = {'description_width': '100px','button_width': '50px'}, disabled=False,)\n",
"method = widgets.ToggleButtons(options=[('Direct','direct'), ('Iterative','iterative')], description='Methods', **align2, button_style='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
"ssb_freq_length = widgets.RadioButtons(options=['mrad', 'A'], description='CTF-SSB x-axis:', **align2) \n",
"scans = widgets.RadioButtons(options=[4,6,8,10],description='Scan points:',continuous_update=False, **align2)\n",
"\n",
"### Live update ### \n",
"beam_res = widgets.Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), **to_right)\n",
"beam_res = widgets.Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), **to_right2)\n",
"beam.observe(inte.show_wavelength, names='value')\n",
"camera_res = widgets.Label(value = f'Detector full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), **to_right)\n",
"camera_res = widgets.Label(value = f'Full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), **to_right2)\n",
"camera.observe(inte.show_detector, names='value')\n",
"pixel_size_res = widgets.Label(value = f'Native pixel size (μm) '+ str(\"{:.0f}\".format(pty.get_det_orig_pixel_size(camera.value))),**to_right)\n",
"camera.observe(inte.show_pixel_size, names='value')\n",
@ -393,33 +394,18 @@
"mag.observe(inte.show_fov, names='value') \n",
"dwell_time_res = widgets.Label(value = f'Frame rate (kHz) '+ str(pty.get_aq_frec(dwell_time.value)),**to_right)\n",
"dwell_time.observe(inte.show_frame_rate, names='value') \n",
"cl_det_res = widgets.Label(value = f'Detector camera length (cm) '+ str(pty.get_cl_detector(cl.value)),**to_right)\n",
"cl_det_res = widgets.Label(value = f'Detector CL (cm) '+ str(pty.get_cl_detector(cl.value)),**to_right2)\n",
"cl.observe(inte.show_cd_det, names='value') \n",
"\n",
"box_layout = widgets.Layout(border='solid 1px blue',margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"col1 = widgets.VBox([widgets.Label('Beam'), beam, aperture, probe, defocus])\n",
"col1.layout = box_layout\n",
"col2 = widgets.VBox([widgets.Label('Scanning'), mag, matrix])\n",
"col2.layout = box_layout\n",
"col3 = widgets.VBox([widgets.Label('Camera length'), cl, restriction])\n",
"col3.layout = box_layout\n",
"col4 = widgets.VBox([widgets.Label('Detection'), camera, binning, dwell_time])\n",
"col4.layout = box_layout\n",
"box_layout = widgets.Layout(border='solid 2px #1976D2',margin='0px 0px 0px 0px', padding='5px 5px 5px 5px')\n",
"col1 = widgets.VBox([widgets.Label('Beam'), widgets.HBox([beam ,beam_res]), aperture, probe, defocus], layout=box_layout) # aperture_res, aperture_res2,\n",
"col2 = widgets.VBox([widgets.Label('Scanning'), mag, fov_res, matrix], layout=box_layout)\n",
"col3 = widgets.VBox([widgets.Label('Camera length'), cl, widgets.HBox([restriction, cl_det_res])], layout=box_layout)\n",
"col4 = widgets.VBox([widgets.Label('Detection'), widgets.HBox([camera, camera_res]), pixel_size_res, binning, dwell_time, dwell_time_res], layout=box_layout)\n",
"\n",
"descriptions_beam = widgets.VBox([widgets.Label('Characteristics beam'), beam_res, aperture_res, aperture_res2])\n",
"descriptions_beam.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"descriptions_scan = widgets.VBox([widgets.Label('Characteristics scanning'), fov_res])\n",
"descriptions_scan.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"descriptions_cl = widgets.VBox([widgets.Label('Characteristics camera length'), cl_det_res])\n",
"descriptions_cl.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"descriptions_det = widgets.VBox([widgets.Label('Characteristics detector'), camera_res, pixel_size_res,dwell_time_res])\n",
"descriptions_det.layout = widgets.Layout(border='solid 1px gray', margin='0px 10px 10px 0px', padding='5px 5px 5px 5px')\n",
"\n",
"small_control = widgets.VBox([widgets.Label('Graph controls'),method, ssb_freq_length, scans, descriptions_beam, descriptions_scan, descriptions_cl, descriptions_det])\n",
"small_control = widgets.VBox([widgets.Label('Graph controls'),method, ssb_freq_length, scans], layout = widgets.Layout(border='dashed 0px gray',margin='32px 30px 00px 10px', padding='5px 5px 5px 5px'))\n",
"controls = widgets.HBox([widgets.VBox([widgets.Label(''), col1, col2, col3, col4]), small_control])\n",
"\n",
"\n",
"\n",
"def ptycho_interact(beam, aperture, probe, cl, matrix, defocus, mag, camera, binning, dwell_time, restriction, method, ssb_freq_length, scans):\n",
" \n",
" ### SINGLE SETTING PARAMETERS ###\n",
@ -483,7 +469,7 @@
" 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=2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100, y=pctf, marker_color='red', name=str(np.round(semi_angle_corr,2))+ ' mrad',))\n",
" fig.update_xaxes(title_text=\"Spacial frequency (A?)\",range=[0, 2.5], type=\"log\", zeroline=False)\n",
" fig.update_xaxes(title_text=\"Real space distance (Å)\", range=[0, 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",
@ -495,10 +481,8 @@
" wid = np.linspace(0,scans-1,scans) * step_size_corr\n",
" \n",
" fig5 = make_subplots(specs=[[{\"secondary_y\": True}]])\n",
" fig5.update_xaxes(title_text=\"Sample plane (nm)\", range=[0, scans*step_size_corr], zeroline=False)\n",
" fig5.update_yaxes(range=[0, scans*step_size_corr], showticklabels=False)\n",
" \n",
" fig5.add_trace(go.Scatter(showlegend=False, x = scans*step_size_corr*np.ones(len(yyy)), y=yyy, opacity=1,mode='markers',marker_symbol = \"triangle-down\",marker=dict(size=20, color=yyy, colorscale='rainbow_r', showscale=False)),secondary_y=True) \n",
" fig5.update_xaxes(title_text=\"Sample plane (nm)\", range=[0, scans*step_size_corr], showgrid=False, zeroline=False)\n",
" fig5.update_yaxes(range=[0, scans*step_size_corr],showgrid=False, showticklabels=False)\n",
" for x in range(len(wid)):\n",
" fig5.add_trace(go.Scatter(showlegend=False, x=wid, y=np.ones(len(wid))*wid[x], marker_color='blue'),secondary_y=False)\n",
" for x in range(len(wid)): \n",
@ -509,7 +493,9 @@
" fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='#FF7F7F', name='Beam ⌀ '+ str(np.round(beam_diameter,2))+\" nm\"))\n",
" fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=0.9))\n",
" fig5.add_trace(go.Scatter(showlegend=False, x = scans*step_size_corr*np.ones(len(yyy)), y=yyy, opacity=1,mode='markers',marker_symbol = \"triangle-down\",marker=dict(size=20, color=yyy, colorscale='rainbow_r', showscale=False)),secondary_y=True) \n",
" fig5.update_yaxes(title_text=\"Overlap %\", range=[0, 100], showticklabels=True, tickvals = [0, 20, 40,50, 60,70, 80, 90, 100], secondary_y=True)\n",
" \n",
" \n",
" fig5.update_yaxes(title_text=\"Overlap %\", range=[0, 100],showgrid=False, showticklabels=True, tickvals = [0, 20, 40,50, 60,70, 80, 90, 100], secondary_y=True)\n",
" fig5.update_layout(title={'text': \"Sample\",'y':0.95, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
" fig5.update_layout(width=430, height=380, margin =dict(l=30, r=30, t=10, b=0))\n",
"\n",
@ -586,6 +572,10 @@
" fig8.add_trace(go.Scatter(showlegend=False, x=[-width, width], y=[-np.log(ssb_cl), -np.log(ssb_cl)], opacity=0.8, line=dict(color='green',width=3)))\n",
" fig8.add_annotation(x=-0.7*width, y=-np.log(ssb_cl),text=\"<b>REC for SSB</b>\", showarrow=False,align= 'left', yshift=-15)\n",
" \n",
" if restriction == True:\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-250, -4*semi_angle, None, 4*semi_angle, 250], y=[-reduc*0.2*y_down,-reduc*0.2*y_down,None,-reduc*0.2*y_down, -reduc*0.2*y_down],mode='lines', line=dict(color='black',width=7)))\n",
" fig8.add_annotation(x=-0.35*width, y=-reduc*0.2*y_down,text=\"<b>PAAR</b>\", showarrow=False,align= 'left', yshift=15)\n",
" \n",
" # Cover\n",
" fig8.add_annotation(x=0, y=-1.05*np.log(cl), ax=det_width, ay=-1.05*np.log(cl), xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\n",
" fig8.add_annotation(x=det_width,y=-1.05*np.log(cl), ax=0, ay=-1.05*np.log(cl), xref='x',yref='y',axref='x',ayref='y', text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\n",
@ -599,22 +589,27 @@
"\n",
" fig8.update_xaxes(title_text=\"\")\n",
" # fig8.update_layout(title={'text': \"Microscope\" ,'y':1, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
" fig8.update_layout(width=350, height=550, margin = dict(l=10, r=30, t=0, b=0))\n",
" fig8.update_layout(width=350, height=570, margin = dict(l=10, r=30, t=20, b=0))\n",
" fig8.update_layout(plot_bgcolor='white')\n",
" \n",
" \n",
" ### FINAL CHECKS ########################################## \n",
" align3 = dict(layout=widgets.Layout(width='250px') , style = {'description_width': '150px','button_width': \"100px\"}, disabled=True,) \n",
" align3 = dict(layout=widgets.Layout(width='200px') , style = {'description_width': '150px','button_width': \"100px\"}, disabled=True,) \n",
" \n",
" check1 = widgets.Valid(value= bool(overlap > 60), description='Overlap > 60 %', **align3)\n",
" check2 = widgets.Valid(value= bool(step_size_corr*10 > (wavelength * cl_det)/(num_pixels*size_pixel/1e6)/1e4), description='Ptycho pix < step size', **align3)\n",
" check3 = widgets.Valid(value= bool(beam_diameter/2 < probe_window/2), description='Beam ⌀ < window/2', **align3) \n",
" \n",
" electron_dose = widgets.Label(value = f'Electron dose (e/Å2) '+ str(np.round(dose,1)), **align3) \n",
" checks = widgets.VBox([widgets.Label('Final checks'),check1,check2, check3,electron_dose]) \n",
" checks.layout = widgets.Layout(border='solid 1px gray',margin='10px 10px 10px 10px', padding='10px 10px 10px 10px')\n",
"\n",
" \n",
" acquisition_time = widgets.Label(value = f'Acquisition time (s) '+ str(np.round(matrix*matrix*dwell_time/1e6,1)), **align3) \n",
" \n",
" focusdepth = widgets.Label(value = f'Depth of focus (nm) '+ str(np.round(wavelength/(semi_angle_corr/1000)**2/1000,1)), **align3) \n",
" \n",
" checks = widgets.VBox([widgets.Label('Final checks'),check1,check2, check3,electron_dose,focusdepth, acquisition_time]) \n",
" checks.layout = widgets.Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
"\n",
"\n",
" ### METHODS ########################################## \n",
" if method == 'direct':\n",
" \n",
@ -626,10 +621,10 @@
" fig4.add_trace(go.Scatter(x=np.array(ssb_cl), y=np.array(kolik),marker_size=12, marker_color='green', name = \"Rec SSB CL\"), secondary_y=True,) \n",
" fig4.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.65,xanchor=\"right\",x=0.9))\n",
" # fig4.update_layout(title={'text': \"CL to α\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n",
" fig4.update_xaxes(title_text=\"Camera length (cm)\", type=\"log\", tickvals = opt.cameralengths())\n",
" fig4.update_xaxes(title_text=\"Nominal camera length (cm)\", type=\"log\", tickvals = opt.cameralengths())\n",
" fig4.update_layout(xaxis = dict(tickmode = 'array', tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels]))\n",
" fig4.update_yaxes(title_text=\" Cover angle (<b>mrad</b>)\", secondary_y=False)\n",
" fig4.update_yaxes(title_text=\" Cover angle (<b>α</b>)\", secondary_y=True)\n",
" fig4.update_yaxes(title_text=\" Cover angle (mrad)\", secondary_y=False)\n",
" fig4.update_yaxes(title_text=\" Cover angle (α)\",showgrid=False, secondary_y=True)\n",
" fig4.update_layout(xaxis = dict(tickmode = 'array', tickvals = opt.cameralengths()))\n",
" fig4.update_layout(width=800, height=225, margin =dict(l=110, r=30, t=30, b=30))\n",
" \n",
@ -734,19 +729,19 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 180,
"id": "7937f054-fcd0-4e67-a20f-7696f5903a94",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7a6580d06f9d47f8a76d6f13079ad042",
"model_id": "3ff56079396a4d12814896dd2a44263f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), Dropdown(des…"
"HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), HBox(childre…"
]
},
"metadata": {},