diff --git a/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb b/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb
index 1bbf74f..c60e0f7 100644
--- a/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb
+++ b/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb
@@ -2,10 +2,19 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 741,
+ "execution_count": 1,
"id": "7425242d-3c91-4c1e-a424-08625a38ee7a",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\skoupy_r\\Anaconda3\\lib\\site-packages\\scipy\\__init__.py:155: UserWarning: A NumPy version >=1.18.5 and <1.25.0 is required for this version of SciPy (detected version 1.26.1\n",
+ " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n"
+ ]
+ }
+ ],
"source": [
"### Initial packages import ###################################################\n",
"import numpy as np\n",
@@ -299,78 +308,80 @@
},
{
"cell_type": "code",
- "execution_count": 743,
+ "execution_count": 36,
"id": "8055b802-cf83-4250-aea9-54e3e6b73db0",
"metadata": {},
"outputs": [],
"source": [
"### CONTROLS ##########################################\n",
- "align = dict(layout=Layout(width='385px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary',disabled=False,)\n",
- "align3 = dict(layout=Layout(width='230px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary', disabled=False,)\n",
- "to_right = dict(layout=Layout(display=\"flex\", justify_content=\"flex-end\", width=\"95%\", ))\n",
- "to_right2 = dict(layout=Layout(display=\"flex\", justify_content=\"flex-end\", width=\"35%\", ))\n",
+ "align_controls = dict(layout=Layout(width='100%'),style = {'description_width': '90px','button_width': '35px'}, button_style='primary',disabled=False,)\n",
+ "\n",
+ "# align_controls = dict(layout=Layout(button_width='10%',style = {'description_width': '5%','button_width': '10%'}, button_style='primary',disabled=False,))\n",
+ "\n",
+ "# to_right = dict(layout=Layout(display=\"flex\", justify_content=\"flex-end\", width=\"95%\", ))\n",
+ "\n",
+ "# align_small = dict(layout=Layout(width='100%'), style = {'description_width': '60%'}, disabled=False)\n",
+ "# align_small2 = dict(layout=Layout(width='95%'), disabled=False)\n",
+ "\n",
+ "box_layout_controls = Layout(width='100%', border='solid 1px gray') # display='flex'\n",
+ "\n",
"\n",
"### Main controls ###\n",
- "beam = Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align3)\n",
- "aperture = ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', **align, tooltips=['', ''])\n",
- "probe = ToggleButtons(options=opt.probes(), value='8C', description='Probe', **align, tooltips=['', ''])\n",
- "defocus = IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, **align )\n",
+ "beam = Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align_controls)\n",
+ "aperture = ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', **align_controls, tooltips=['', ''])\n",
+ "probe = ToggleButtons(options=opt.probes(), value='8C', description='Probe', **align_controls, tooltips=['', ''])\n",
+ "defocus = IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, **align_controls )\n",
"defocus.style.handle_color = 'blue'\n",
- "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Mag. (Mx)', **align) \n",
- "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), ('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",
+ "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Mag. (Mx)', **align_controls) \n",
+ "matrix = ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', **align_controls, tooltips=['', ''])\n",
+ "cl = ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal (cm)', **align_controls, tooltips=['', ''])\n",
+ "camera = Dropdown(options=opt.detectors(), description='Detector', **align_controls, tooltips=['', ''])\n",
+ "restriction = ToggleButtons(options=[('No',False), ('Yes',True)], description='Use PAAR',**align_controls, tooltips=['', ''])\n",
+ "binning = ToggleButtons(options=[('No',1), ('2x2',2), ('4x4',4)], value=1, description='Binning', **align_controls, 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_controls, 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=[('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",
+ "method = ToggleButtons(options=[('SSB','direct'), ('Iterative recon.','iterative')], description='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
+ "ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='CTF x-axis:', ) \n",
+ "scans = RadioButtons(options=[4,6,8,10],description='Beam positions:',continuous_update=False,)\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_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",
+ "cl_check_laa = Checkbox(value=True, description='Low ∠ approx.', indent=False,) # Low angle approximation check - scattering angle < 10 deg\n",
+ "cl_check_pix = Checkbox(value=True, description='Rec. pix. < step',indent=False,) # Reconstructed pixel size < scanning step size \n",
+ "cl_check_def = Checkbox(value=True, description='Beam fits in win.', indent=False,) # Is probe window big enough to accomodate defocused probe?\n",
+ "cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', indent=False,) # Detector cover is lower than 1 α; orange\n",
+ "cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', indent=False,) # Detector cover is lower than 1 α; orange\n",
" \n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n",
"### Live update ### \n",
- "beam_res = Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), **to_right2)\n",
+ "beam_res = Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), )\n",
"beam.observe(inte.show_wavelength, names='value')\n",
- "camera_res = Label(value = f'Full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), **to_right2)\n",
+ "camera_res = Label(value = f'Full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), )\n",
"camera.observe(inte.show_detector, names='value')\n",
- "pixel_size_res = Label(value = f'Native pixel size (μm) '+ str(\"{:.0f}\".format(pty.get_det_orig_pixel_size(camera.value))),**to_right)\n",
+ "pixel_size_res = Label(value = f'Native pixel size (μm) '+ str(\"{:.0f}\".format(pty.get_det_orig_pixel_size(camera.value))),)\n",
"camera.observe(inte.show_pixel_size, names='value')\n",
- "# aperture_res = Label(value = f'Probe semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle(aperture.value))), **to_right)\n",
- "# aperture.observe(inte.show_probe_angle, names='value') \n",
- "# aperture_res2 = Label(value = f'Corrected semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle_corr(aperture.value))), **to_right)\n",
- "# aperture.observe(inte.show_corrprobe_angle, names='value') \n",
- "fov_res = Label(value = f'Field of view (nm) '+ str(\"{:.2f}\".format(pty.get_fov(mag.value))), **to_right)\n",
+ "aperture_res = Label(value = f'Probe semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle(aperture.value))), )\n",
+ "aperture.observe(inte.show_probe_angle, names='value') \n",
+ "aperture_res2 = Label(value = f'Corrected semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle_corr(aperture.value))), )\n",
+ "aperture.observe(inte.show_corrprobe_angle, names='value') \n",
+ "fov_res = Label(value = f'Field of view (nm) '+ str(\"{:.2f}\".format(pty.get_fov(mag.value))), )\n",
"mag.observe(inte.show_fov, names='value') \n",
- "dwell_time_res = Label(value = f'Frame rate (kHz) '+ str(\"{:.2f}\".format(pty.get_aq_frec(dwell_time.value))),**to_right)\n",
+ "dwell_time_res = Label(value = f'Frame rate (kHz) '+ str(\"{:.2f}\".format(pty.get_aq_frec(dwell_time.value))),)\n",
"dwell_time.observe(inte.show_frame_rate, names='value') \n",
- "cl_det_res = Label(value = f'Detector CL (cm) '+ str(\"{:.1f}\".format(pty.get_cl_detector(cl.value))),**to_right2)\n",
+ "cl_det_res = Label(value = f'Detector CL (cm) '+ str(\"{:.1f}\".format(pty.get_cl_detector(cl.value))),)\n",
"cl.observe(inte.show_cd_det, names='value') \n",
"\n",
"### Controls layout ###\n",
- "box_layout = Layout(border='solid 2px #1976D2',margin='0px 0px 0px 0px', padding='5px 5px 5px 5px')\n",
- "col1 = VBox([Label('Beam'), HBox([beam ,beam_res]), aperture, probe, defocus], layout=box_layout) # aperture_res, aperture_res2,\n",
- "col2 = VBox([Label('Scanning'), mag, fov_res, matrix], layout=box_layout)\n",
- "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",
+ "col1 = VBox([Label('Beam'), beam ,beam_res, aperture, aperture_res, aperture_res2, probe, defocus], layout=box_layout_controls)\n",
+ "col2 = VBox([Label('Scanning'), mag, fov_res, matrix], layout=box_layout_controls)\n",
+ "col3 = VBox([Label('Camera length'), cl, cl_det_res, restriction ], layout=box_layout_controls)\n",
+ "col4 = VBox([Label('Detection'), camera, camera_res, pixel_size_res, binning, dwell_time, dwell_time_res], layout=box_layout_controls)\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_1bf, 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])])\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_1bf, cl_check_nbf):\n",
+ "\n",
+ "\n",
+ "\n",
+ "def ptycho_interact(beam, aperture, aperture_res, aperture_res2, 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",
@@ -439,7 +450,7 @@
" \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",
+ " fig5.update_layout(width=350, height=300, margin =dict(l=30, r=30, t=10, b=0))\n",
"\n",
" \n",
" ### DETECTOR PLANE ##########################################\n",
@@ -458,15 +469,15 @@
" fig6.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=1))\n",
" # fig6.update_layout(title={'text': \"Detector\",'y':0.925, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
" fig6.update_layout(xaxis = dict(tickmode = 'array', tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels])) \n",
- " fig6.update_layout(width=350, height=280, margin = dict(l=40, r=60, t=0, b=0))\n",
+ " fig6.update_layout(width=250, height=230, margin = dict(l=20, r=20, t=0, b=0))\n",
"\n",
- " \n",
+ " focusdepth = wavelength/(semi_angle_corr/1000)**2/1000\n",
" ssb_cl, kolik = pty.cl4ssb(detector_cover_a_all)\n",
" ### MICROSCOPE SCHEME ##########################################\n",
- " width = 500 \n",
- " det_width = 400\n",
+ " width = 500 # in-graph setting\n",
+ " det_width = 400 # in-graph setting\n",
" y_down = np.log(np.max(opt.cameralengths()))\n",
- " reduc = 0.4\n",
+ " reduc = 0.4 # in-graph setting\n",
" \n",
" fig8 = go.Figure() \n",
" fig8.update_xaxes(range=[-width, width], showticklabels=False,zeroline=False)\n",
@@ -474,9 +485,9 @@
"\n",
" fig8.add_shape(type=\"rect\",xref=\"x\", yref=\"y\",opacity=0.7, fillcolor=\"red\", x0=-100, y0=reduc*0.8*y_down, x1=100, y1=reduc*0.9*y_down,line_color=\"red\")\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-150, -2*semi_angle, None, 2*semi_angle, 150], y=[reduc*0.8*y_down,reduc*0.8*y_down,None,reduc*0.8*y_down, reduc*0.8*y_down],mode='lines', line=dict(color='black',width=7)))\n",
- " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=\"Aperture \"+str(aperture), showarrow=False, yshift=2)\n",
- " fig8.add_annotation(x=semi_angle, y=reduc*0.7*y_down, text=\"α \"+str(np.round(semi_angle,2))+\" mrad (\"+str(np.round(semi_angle_corr,2))+\")\", showarrow=True, ax=100, ay=0, yshift=0)\n",
- "\n",
+ " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=\"Aperture \", showarrow=False, yshift=2)\n",
+ " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=str(aperture), showarrow=False, yshift=-15)\n",
+ " \n",
" if defocus > 0:\n",
" defo = np.log(defocus)/100\n",
" else:\n",
@@ -485,7 +496,7 @@
" # Beam\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, 2*semi_angle, 0, 0], y=[defo*y_down, reduc*0.8*y_down, reduc*0.8*y_down, defo*y_down], mode='lines',fill=\"toself\", fillcolor=\"#FF7F7F\", opacity=0.7,line=dict(color='#FF7F7F',width=1)))\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, 0, -2*semi_angle, 0], y=[defo*y_down, reduc*0.8*y_down, reduc*0.8*y_down, defo*y_down],mode='lines', fill=\"toself\", fillcolor=\"red\", opacity=0.7,line=dict(color='red',width=1)))\n",
- " fig8.add_annotation(x=0, y=reduc*0.5*y_down,text=\"Current \"+str(np.round(current,1))+\" pA\", showarrow=True,ax=100, ay=0, yshift=0)\n",
+ " fig8.add_annotation(x=0, y=reduc*0.5*y_down,text=\"Current \"+str(np.round(current,1))+\" pA\", showarrow=True,ax=70, ay=0, yshift=0)\n",
" \n",
" if defocus > 0:\n",
" fig8.add_annotation(x=-0.05*width, y=0, ax=-0.05*width, ay=defo*y_down, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=1,arrowsize=1,arrowwidth=1,arrowcolor='black')\n",
@@ -494,15 +505,16 @@
"\n",
" # Sample\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-0.8*width, 0.8*width], y=[0, 0], line=dict(color='magenta',width=7), opacity=0.5))\n",
- " fig8.add_annotation(x=-0.8*width, y=0,text=\"Sample\", showarrow=False, yshift=15)\n",
+ " fig8.add_annotation(x=-0.7*width, y=0,text=\"Sample\", showarrow=False, yshift=15)\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-np.log(fov)/20*width, np.log(fov)/20*width, np.log(fov)/20*width, -np.log(fov)/20*width, -np.log(fov)/20*width], y=[-0.01*y_down, -0.01*y_down, 0.01*y_down, 0.01*y_down, -0.01*y_down],mode='lines', fill=\"toself\", fillcolor=\"black\", line=dict(color='black',width=1), opacity=0.5))\n",
- " fig8.add_annotation(x=0.35*width, y=0.05*y_down,text=\"FoV \"+str(np.round(fov,2))+\" nm\", showarrow=False, ax=50, ay=-30, yshift=0)\n",
- " \n",
+ " fig8.add_annotation(x=0.4*width, y=0.05*y_down,text=\"FoV \"+str(np.round(fov,2))+\" nm\", showarrow=False, yshift=0)\n",
+ " fig8.add_annotation(x=0.5*width, y=0.05*y_down,text=\"Dose \"+str(np.round(dose,1))+\" e/Å2\", showarrow=False, yshift=-30)\n",
+ " fig8.add_annotation(x=-0.5*width, y=0.05*y_down,text=\"DoF \"+str(np.round(focusdepth,1))+\" nm\", showarrow=False, yshift=-30)\n",
" # Detector\n",
" y = -np.log(cl)*np.ones(int(num_pixels)+1)\n",
" x = np.linspace(-det_width,det_width, int(num_pixels)+1)\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=x, y=y, mode='markers', marker_symbol=\"line-ns\",marker_line_width=0.5))\n",
- " fig8.add_annotation(x=-0.8*width, y=-np.log(cl),text=\"Detector\", showarrow=False,align= 'left', yshift=15)\n",
+ " fig8.add_annotation(x=-0.7*width, y=-np.log(cl),text=\"Detector\", showarrow=False,align= 'left', yshift=15)\n",
" \n",
" # Scattering\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, det_width, -det_width, 0], y=[defo*y_down, -np.log(cl), -np.log(cl), -np.log(cl), defo*y_down],mode='lines', fill=\"toself\", fillcolor=\"gray\", opacity=0.1,line=dict(color='black',width=1)))\n",
@@ -512,7 +524,7 @@
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, -det_width/covered_alfas, det_width/covered_alfas, 0], y=[defo*y_down, -np.log(cl), -np.log(cl), -np.log(cl), defo*y_down],mode='lines', fill=\"toself\", fillcolor=\"red\", opacity=0.7,line=dict(color='#FF7F7F',width=1)))\n",
" \n",
" 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=\"REC for SSB\", showarrow=False,align= 'left', yshift=-15)\n",
+ " fig8.add_annotation(x=-0.7*width, y=-np.log(ssb_cl),text=\"for SSB\", 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",
@@ -524,14 +536,14 @@
" fig8.add_annotation(x=det_width/2, y=-1.05*np.log(cl), text=\"Cover \"+str(np.round(detector_cover,1)) + \" mrad;\" + str(np.round(covered_alfas,1))+\"α\", showarrow=False, yshift=-10, xshift=-10)\n",
"\n",
" # CLs\n",
- " fig8.add_annotation(x=0.9*width, y=-np.log(1.5),text=\"CL cm\", showarrow=False, yshift=0)\n",
+ " fig8.add_annotation(x=0.85*width, y=-np.log(1.5),text=\"CL cm\", showarrow=False, yshift=0)\n",
" for x in opt.cameralengths():\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-width, width], y=[-np.log(x), -np.log(x)], opacity=0.3, line=dict(color='gray',width=1)))\n",
" fig8.add_annotation(x=0.9*width, y=-np.log(x),text=str(x), showarrow=False, yshift=8)\n",
"\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=570, margin = dict(l=10, r=30, t=20, b=0))\n",
+ " fig8.update_layout(width=250, height=570, margin = dict(l=0, r=0, t=20, b=0))\n",
" fig8.update_layout(plot_bgcolor='white')\n",
" \n",
" \n",
@@ -542,11 +554,13 @@
" check2 = Valid(value= bool(step_size_corr*10 > (wavelength * cl_det)/(num_pixels*size_pixel/1e6)/1e4), description='Ptycho pix < step size', **align3)\n",
" check3 = Valid(value= bool(beam_diameter/2 < probe_window/2), description='Beam ⌀ < window/2', **align3) \n",
" \n",
- " electron_dose = Label(value = f'Electron dose (e/Å2) '+ str(np.round(dose,1)), **align3) \n",
" acquisition_time = Label(value = f'Acquisition time (s) '+ str(np.round(matrix*matrix*dwell_time/1e6,1)), **align3) \n",
- " focusdepth = Label(value = f'Depth of focus (nm) '+ str(np.round(wavelength/(semi_angle_corr/1000)**2/1000,1)), **align3) \n",
"\n",
"\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
" ### METHODS ########################################## \n",
" if method == 'direct':\n",
" \n",
@@ -577,7 +591,7 @@
"\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",
+ " fig.update_layout(width=600, height=225, margin = dict(l=100, 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",
@@ -595,17 +609,22 @@
" fig4.update_yaxes(title_text=\" Cover angle (mrad)\", range=[0, 1.1*np.max(detector_cover_all)], secondary_y=False)\n",
" fig4.update_yaxes(title_text=\" Cover angle (α)\", range=[0, 1.1*np.max(detector_cover_a_all)], 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",
+ " fig4.update_layout(width=600, height=225, margin =dict(l=110, r=30, t=30, b=30))\n",
" \n",
" \n",
- " checks = VBox([Label('Final checks'), electron_dose, ssb_sampling, focusdepth, acquisition_time]) \n",
+ " checks = VBox([Label('Final checks'), ssb_sampling, acquisition_time]) \n",
" checks.layout = Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
" \n",
" \n",
" ### SHOWING ###\n",
- " right_column = VBox([go.FigureWidget(fig),go.FigureWidget(fig5),go.FigureWidget(fig4)])\n",
+ "\n",
+ " \n",
+ " right_column = VBox([go.FigureWidget(fig),go.FigureWidget(fig5),go.FigureWidget(fig4),checks])\n",
" left_column = VBox([go.FigureWidget(fig8), go.FigureWidget(fig6)])\n",
- " display(HBox([left_column, right_column, checks]))\n",
+ " \n",
+ "\n",
+ " \n",
+ " display(HBox([left_column, right_column]))\n",
" \n",
" \n",
" \n",
@@ -651,13 +670,13 @@
"\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",
+ " fig.update_layout(width=600, 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 = VBox([Label('Final checks'),check1, check2, check3, acquisition_time]) \n",
" checks.layout = Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
" \n",
" \n",
@@ -682,14 +701,14 @@
" fig7.update_yaxes(range=[0, probe_window], showticklabels=False,)\n",
" fig7.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.9,xanchor=\"right\",x=1))\n",
" fig7.update_layout(title={'text': \"Probe window \",'y':0.925, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
- " fig7.update_layout(width=400, height=380, margin =dict(l=30, r=30, t=10, b=0)) \n",
+ " fig7.update_layout(width=320, height=300, margin =dict(l=30, r=30, t=10, b=0)) \n",
" \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), 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",
+ " align7 = dict(layout=Layout(width='120px') , style = {'description_width': '0px','button_width': \"105px\"}, disabled=True,)\n",
" \n",
" for i in range(0,12):\n",
" button_style = 'success'\n",
@@ -726,7 +745,7 @@
" \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)','Selected by CL ','Nominal CL (cm)',], \n",
+ " legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. def. (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",
@@ -743,14 +762,14 @@
" \n",
" ### SHOWING ###\n",
" sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7)]) \n",
- " right_column = VBox([go.FigureWidget(fig), sample_overlap, cltab ]) \n",
+ " right_column = VBox([go.FigureWidget(fig), sample_overlap, cltab, checks ]) \n",
" left_column = VBox([go.FigureWidget(fig8), go.FigureWidget(fig6)]) \n",
" \n",
- " display(HBox([left_column, right_column, checks]))\n",
+ " display(HBox([left_column, right_column]))\n",
" \n",
" return \n",
" \n",
- "gui = interactive_output(ptycho_interact, {\"beam\": beam, \"aperture\": aperture, \"probe\": probe, \"cl\": cl, \"matrix\": matrix, \"defocus\": defocus, \"mag\": mag, \"camera\": camera,\n",
+ "gui = interactive_output(ptycho_interact, {\"beam\": beam, \"aperture\": aperture,\"aperture_res\": aperture_res,\"aperture_res2\": aperture_res2, \"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_1bf\": cl_check_1bf, \"cl_check_nbf\": cl_check_nbf}) \n",
"\n"
@@ -786,19 +805,19 @@
},
{
"cell_type": "code",
- "execution_count": 744,
+ "execution_count": 37,
"id": "7937f054-fcd0-4e67-a20f-7696f5903a94",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "068f3d20c5e7439d92f4ec64e94490b0",
+ "model_id": "1e35fd918b334d70b6eca967055cf6ce",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
- "HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), HBox(childre…"
+ "HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), Dropdown(des…"
]
},
"metadata": {},
@@ -806,6 +825,8 @@
}
],
"source": [
+ "\n",
+ "\n",
"display(HBox([controls, gui]))"
]
},
@@ -835,23 +856,10 @@
},
{
"cell_type": "code",
- "execution_count": 734,
+ "execution_count": null,
"id": "b939697a-2ab0-49b2-8c73-555bb62a2e0d",
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Numpy version 1.26.1\n",
- "scipy version 1.9.1\n",
- "Plotly version 5.9.0\n",
- "Pandas version 2.1.2\n",
- "IPython version 7.31.1\n",
- "Ipywidgets version 7.6.5\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"# import numpy as np\n",
"# print(\"Numpy version \", np.__version__)\n",
diff --git a/ptychoScopy.ipynb b/ptychoScopy.ipynb
index 1bbf74f..c60e0f7 100644
--- a/ptychoScopy.ipynb
+++ b/ptychoScopy.ipynb
@@ -2,10 +2,19 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 741,
+ "execution_count": 1,
"id": "7425242d-3c91-4c1e-a424-08625a38ee7a",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\skoupy_r\\Anaconda3\\lib\\site-packages\\scipy\\__init__.py:155: UserWarning: A NumPy version >=1.18.5 and <1.25.0 is required for this version of SciPy (detected version 1.26.1\n",
+ " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n"
+ ]
+ }
+ ],
"source": [
"### Initial packages import ###################################################\n",
"import numpy as np\n",
@@ -299,78 +308,80 @@
},
{
"cell_type": "code",
- "execution_count": 743,
+ "execution_count": 36,
"id": "8055b802-cf83-4250-aea9-54e3e6b73db0",
"metadata": {},
"outputs": [],
"source": [
"### CONTROLS ##########################################\n",
- "align = dict(layout=Layout(width='385px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary',disabled=False,)\n",
- "align3 = dict(layout=Layout(width='230px') , style = {'description_width': '80px','button_width': \"35px\"}, button_style='primary', disabled=False,)\n",
- "to_right = dict(layout=Layout(display=\"flex\", justify_content=\"flex-end\", width=\"95%\", ))\n",
- "to_right2 = dict(layout=Layout(display=\"flex\", justify_content=\"flex-end\", width=\"35%\", ))\n",
+ "align_controls = dict(layout=Layout(width='100%'),style = {'description_width': '90px','button_width': '35px'}, button_style='primary',disabled=False,)\n",
+ "\n",
+ "# align_controls = dict(layout=Layout(button_width='10%',style = {'description_width': '5%','button_width': '10%'}, button_style='primary',disabled=False,))\n",
+ "\n",
+ "# to_right = dict(layout=Layout(display=\"flex\", justify_content=\"flex-end\", width=\"95%\", ))\n",
+ "\n",
+ "# align_small = dict(layout=Layout(width='100%'), style = {'description_width': '60%'}, disabled=False)\n",
+ "# align_small2 = dict(layout=Layout(width='95%'), disabled=False)\n",
+ "\n",
+ "box_layout_controls = Layout(width='100%', border='solid 1px gray') # display='flex'\n",
+ "\n",
"\n",
"### Main controls ###\n",
- "beam = Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align3)\n",
- "aperture = ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', **align, tooltips=['', ''])\n",
- "probe = ToggleButtons(options=opt.probes(), value='8C', description='Probe', **align, tooltips=['', ''])\n",
- "defocus = IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, **align )\n",
+ "beam = Dropdown(options=opt.energies(),value=200,description='Energy (keV)', **align_controls)\n",
+ "aperture = ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', **align_controls, tooltips=['', ''])\n",
+ "probe = ToggleButtons(options=opt.probes(), value='8C', description='Probe', **align_controls, tooltips=['', ''])\n",
+ "defocus = IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, **align_controls )\n",
"defocus.style.handle_color = 'blue'\n",
- "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Mag. (Mx)', **align) \n",
- "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), ('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",
+ "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Mag. (Mx)', **align_controls) \n",
+ "matrix = ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', **align_controls, tooltips=['', ''])\n",
+ "cl = ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal (cm)', **align_controls, tooltips=['', ''])\n",
+ "camera = Dropdown(options=opt.detectors(), description='Detector', **align_controls, tooltips=['', ''])\n",
+ "restriction = ToggleButtons(options=[('No',False), ('Yes',True)], description='Use PAAR',**align_controls, tooltips=['', ''])\n",
+ "binning = ToggleButtons(options=[('No',1), ('2x2',2), ('4x4',4)], value=1, description='Binning', **align_controls, 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_controls, 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=[('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",
+ "method = ToggleButtons(options=[('SSB','direct'), ('Iterative recon.','iterative')], description='', tooltips=['SSB', 'PIE, MLc, DM'])\n",
+ "ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='CTF x-axis:', ) \n",
+ "scans = RadioButtons(options=[4,6,8,10],description='Beam positions:',continuous_update=False,)\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_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",
+ "cl_check_laa = Checkbox(value=True, description='Low ∠ approx.', indent=False,) # Low angle approximation check - scattering angle < 10 deg\n",
+ "cl_check_pix = Checkbox(value=True, description='Rec. pix. < step',indent=False,) # Reconstructed pixel size < scanning step size \n",
+ "cl_check_def = Checkbox(value=True, description='Beam fits in win.', indent=False,) # Is probe window big enough to accomodate defocused probe?\n",
+ "cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', indent=False,) # Detector cover is lower than 1 α; orange\n",
+ "cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', indent=False,) # Detector cover is lower than 1 α; orange\n",
" \n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n",
"### Live update ### \n",
- "beam_res = Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), **to_right2)\n",
+ "beam_res = Label(value = f'Wavelength (pm) '+ str(\"{:.2f}\".format(pty.get_wavelength(beam.value)*1e12)), )\n",
"beam.observe(inte.show_wavelength, names='value')\n",
- "camera_res = Label(value = f'Full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), **to_right2)\n",
+ "camera_res = Label(value = f'Full pixel array '+ str(\"{:.0f}\".format(pty.get_det_resolution(camera.value))), )\n",
"camera.observe(inte.show_detector, names='value')\n",
- "pixel_size_res = Label(value = f'Native pixel size (μm) '+ str(\"{:.0f}\".format(pty.get_det_orig_pixel_size(camera.value))),**to_right)\n",
+ "pixel_size_res = Label(value = f'Native pixel size (μm) '+ str(\"{:.0f}\".format(pty.get_det_orig_pixel_size(camera.value))),)\n",
"camera.observe(inte.show_pixel_size, names='value')\n",
- "# aperture_res = Label(value = f'Probe semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle(aperture.value))), **to_right)\n",
- "# aperture.observe(inte.show_probe_angle, names='value') \n",
- "# aperture_res2 = Label(value = f'Corrected semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle_corr(aperture.value))), **to_right)\n",
- "# aperture.observe(inte.show_corrprobe_angle, names='value') \n",
- "fov_res = Label(value = f'Field of view (nm) '+ str(\"{:.2f}\".format(pty.get_fov(mag.value))), **to_right)\n",
+ "aperture_res = Label(value = f'Probe semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle(aperture.value))), )\n",
+ "aperture.observe(inte.show_probe_angle, names='value') \n",
+ "aperture_res2 = Label(value = f'Corrected semi angle (mrad) '+ str(\"{:.2f}\".format(pty.get_angle_corr(aperture.value))), )\n",
+ "aperture.observe(inte.show_corrprobe_angle, names='value') \n",
+ "fov_res = Label(value = f'Field of view (nm) '+ str(\"{:.2f}\".format(pty.get_fov(mag.value))), )\n",
"mag.observe(inte.show_fov, names='value') \n",
- "dwell_time_res = Label(value = f'Frame rate (kHz) '+ str(\"{:.2f}\".format(pty.get_aq_frec(dwell_time.value))),**to_right)\n",
+ "dwell_time_res = Label(value = f'Frame rate (kHz) '+ str(\"{:.2f}\".format(pty.get_aq_frec(dwell_time.value))),)\n",
"dwell_time.observe(inte.show_frame_rate, names='value') \n",
- "cl_det_res = Label(value = f'Detector CL (cm) '+ str(\"{:.1f}\".format(pty.get_cl_detector(cl.value))),**to_right2)\n",
+ "cl_det_res = Label(value = f'Detector CL (cm) '+ str(\"{:.1f}\".format(pty.get_cl_detector(cl.value))),)\n",
"cl.observe(inte.show_cd_det, names='value') \n",
"\n",
"### Controls layout ###\n",
- "box_layout = Layout(border='solid 2px #1976D2',margin='0px 0px 0px 0px', padding='5px 5px 5px 5px')\n",
- "col1 = VBox([Label('Beam'), HBox([beam ,beam_res]), aperture, probe, defocus], layout=box_layout) # aperture_res, aperture_res2,\n",
- "col2 = VBox([Label('Scanning'), mag, fov_res, matrix], layout=box_layout)\n",
- "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",
+ "col1 = VBox([Label('Beam'), beam ,beam_res, aperture, aperture_res, aperture_res2, probe, defocus], layout=box_layout_controls)\n",
+ "col2 = VBox([Label('Scanning'), mag, fov_res, matrix], layout=box_layout_controls)\n",
+ "col3 = VBox([Label('Camera length'), cl, cl_det_res, restriction ], layout=box_layout_controls)\n",
+ "col4 = VBox([Label('Detection'), camera, camera_res, pixel_size_res, binning, dwell_time, dwell_time_res], layout=box_layout_controls)\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_1bf, 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])])\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_1bf, cl_check_nbf):\n",
+ "\n",
+ "\n",
+ "\n",
+ "def ptycho_interact(beam, aperture, aperture_res, aperture_res2, 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",
@@ -439,7 +450,7 @@
" \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",
+ " fig5.update_layout(width=350, height=300, margin =dict(l=30, r=30, t=10, b=0))\n",
"\n",
" \n",
" ### DETECTOR PLANE ##########################################\n",
@@ -458,15 +469,15 @@
" fig6.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=1))\n",
" # fig6.update_layout(title={'text': \"Detector\",'y':0.925, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
" fig6.update_layout(xaxis = dict(tickmode = 'array', tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels])) \n",
- " fig6.update_layout(width=350, height=280, margin = dict(l=40, r=60, t=0, b=0))\n",
+ " fig6.update_layout(width=250, height=230, margin = dict(l=20, r=20, t=0, b=0))\n",
"\n",
- " \n",
+ " focusdepth = wavelength/(semi_angle_corr/1000)**2/1000\n",
" ssb_cl, kolik = pty.cl4ssb(detector_cover_a_all)\n",
" ### MICROSCOPE SCHEME ##########################################\n",
- " width = 500 \n",
- " det_width = 400\n",
+ " width = 500 # in-graph setting\n",
+ " det_width = 400 # in-graph setting\n",
" y_down = np.log(np.max(opt.cameralengths()))\n",
- " reduc = 0.4\n",
+ " reduc = 0.4 # in-graph setting\n",
" \n",
" fig8 = go.Figure() \n",
" fig8.update_xaxes(range=[-width, width], showticklabels=False,zeroline=False)\n",
@@ -474,9 +485,9 @@
"\n",
" fig8.add_shape(type=\"rect\",xref=\"x\", yref=\"y\",opacity=0.7, fillcolor=\"red\", x0=-100, y0=reduc*0.8*y_down, x1=100, y1=reduc*0.9*y_down,line_color=\"red\")\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-150, -2*semi_angle, None, 2*semi_angle, 150], y=[reduc*0.8*y_down,reduc*0.8*y_down,None,reduc*0.8*y_down, reduc*0.8*y_down],mode='lines', line=dict(color='black',width=7)))\n",
- " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=\"Aperture \"+str(aperture), showarrow=False, yshift=2)\n",
- " fig8.add_annotation(x=semi_angle, y=reduc*0.7*y_down, text=\"α \"+str(np.round(semi_angle,2))+\" mrad (\"+str(np.round(semi_angle_corr,2))+\")\", showarrow=True, ax=100, ay=0, yshift=0)\n",
- "\n",
+ " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=\"Aperture \", showarrow=False, yshift=2)\n",
+ " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=str(aperture), showarrow=False, yshift=-15)\n",
+ " \n",
" if defocus > 0:\n",
" defo = np.log(defocus)/100\n",
" else:\n",
@@ -485,7 +496,7 @@
" # Beam\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, 2*semi_angle, 0, 0], y=[defo*y_down, reduc*0.8*y_down, reduc*0.8*y_down, defo*y_down], mode='lines',fill=\"toself\", fillcolor=\"#FF7F7F\", opacity=0.7,line=dict(color='#FF7F7F',width=1)))\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, 0, -2*semi_angle, 0], y=[defo*y_down, reduc*0.8*y_down, reduc*0.8*y_down, defo*y_down],mode='lines', fill=\"toself\", fillcolor=\"red\", opacity=0.7,line=dict(color='red',width=1)))\n",
- " fig8.add_annotation(x=0, y=reduc*0.5*y_down,text=\"Current \"+str(np.round(current,1))+\" pA\", showarrow=True,ax=100, ay=0, yshift=0)\n",
+ " fig8.add_annotation(x=0, y=reduc*0.5*y_down,text=\"Current \"+str(np.round(current,1))+\" pA\", showarrow=True,ax=70, ay=0, yshift=0)\n",
" \n",
" if defocus > 0:\n",
" fig8.add_annotation(x=-0.05*width, y=0, ax=-0.05*width, ay=defo*y_down, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=1,arrowsize=1,arrowwidth=1,arrowcolor='black')\n",
@@ -494,15 +505,16 @@
"\n",
" # Sample\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-0.8*width, 0.8*width], y=[0, 0], line=dict(color='magenta',width=7), opacity=0.5))\n",
- " fig8.add_annotation(x=-0.8*width, y=0,text=\"Sample\", showarrow=False, yshift=15)\n",
+ " fig8.add_annotation(x=-0.7*width, y=0,text=\"Sample\", showarrow=False, yshift=15)\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-np.log(fov)/20*width, np.log(fov)/20*width, np.log(fov)/20*width, -np.log(fov)/20*width, -np.log(fov)/20*width], y=[-0.01*y_down, -0.01*y_down, 0.01*y_down, 0.01*y_down, -0.01*y_down],mode='lines', fill=\"toself\", fillcolor=\"black\", line=dict(color='black',width=1), opacity=0.5))\n",
- " fig8.add_annotation(x=0.35*width, y=0.05*y_down,text=\"FoV \"+str(np.round(fov,2))+\" nm\", showarrow=False, ax=50, ay=-30, yshift=0)\n",
- " \n",
+ " fig8.add_annotation(x=0.4*width, y=0.05*y_down,text=\"FoV \"+str(np.round(fov,2))+\" nm\", showarrow=False, yshift=0)\n",
+ " fig8.add_annotation(x=0.5*width, y=0.05*y_down,text=\"Dose \"+str(np.round(dose,1))+\" e/Å2\", showarrow=False, yshift=-30)\n",
+ " fig8.add_annotation(x=-0.5*width, y=0.05*y_down,text=\"DoF \"+str(np.round(focusdepth,1))+\" nm\", showarrow=False, yshift=-30)\n",
" # Detector\n",
" y = -np.log(cl)*np.ones(int(num_pixels)+1)\n",
" x = np.linspace(-det_width,det_width, int(num_pixels)+1)\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=x, y=y, mode='markers', marker_symbol=\"line-ns\",marker_line_width=0.5))\n",
- " fig8.add_annotation(x=-0.8*width, y=-np.log(cl),text=\"Detector\", showarrow=False,align= 'left', yshift=15)\n",
+ " fig8.add_annotation(x=-0.7*width, y=-np.log(cl),text=\"Detector\", showarrow=False,align= 'left', yshift=15)\n",
" \n",
" # Scattering\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, det_width, -det_width, 0], y=[defo*y_down, -np.log(cl), -np.log(cl), -np.log(cl), defo*y_down],mode='lines', fill=\"toself\", fillcolor=\"gray\", opacity=0.1,line=dict(color='black',width=1)))\n",
@@ -512,7 +524,7 @@
" fig8.add_trace(go.Scatter(showlegend=False, x=[0, -det_width/covered_alfas, det_width/covered_alfas, 0], y=[defo*y_down, -np.log(cl), -np.log(cl), -np.log(cl), defo*y_down],mode='lines', fill=\"toself\", fillcolor=\"red\", opacity=0.7,line=dict(color='#FF7F7F',width=1)))\n",
" \n",
" 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=\"REC for SSB\", showarrow=False,align= 'left', yshift=-15)\n",
+ " fig8.add_annotation(x=-0.7*width, y=-np.log(ssb_cl),text=\"for SSB\", 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",
@@ -524,14 +536,14 @@
" fig8.add_annotation(x=det_width/2, y=-1.05*np.log(cl), text=\"Cover \"+str(np.round(detector_cover,1)) + \" mrad;\" + str(np.round(covered_alfas,1))+\"α\", showarrow=False, yshift=-10, xshift=-10)\n",
"\n",
" # CLs\n",
- " fig8.add_annotation(x=0.9*width, y=-np.log(1.5),text=\"CL cm\", showarrow=False, yshift=0)\n",
+ " fig8.add_annotation(x=0.85*width, y=-np.log(1.5),text=\"CL cm\", showarrow=False, yshift=0)\n",
" for x in opt.cameralengths():\n",
" fig8.add_trace(go.Scatter(showlegend=False, x=[-width, width], y=[-np.log(x), -np.log(x)], opacity=0.3, line=dict(color='gray',width=1)))\n",
" fig8.add_annotation(x=0.9*width, y=-np.log(x),text=str(x), showarrow=False, yshift=8)\n",
"\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=570, margin = dict(l=10, r=30, t=20, b=0))\n",
+ " fig8.update_layout(width=250, height=570, margin = dict(l=0, r=0, t=20, b=0))\n",
" fig8.update_layout(plot_bgcolor='white')\n",
" \n",
" \n",
@@ -542,11 +554,13 @@
" check2 = Valid(value= bool(step_size_corr*10 > (wavelength * cl_det)/(num_pixels*size_pixel/1e6)/1e4), description='Ptycho pix < step size', **align3)\n",
" check3 = Valid(value= bool(beam_diameter/2 < probe_window/2), description='Beam ⌀ < window/2', **align3) \n",
" \n",
- " electron_dose = Label(value = f'Electron dose (e/Å2) '+ str(np.round(dose,1)), **align3) \n",
" acquisition_time = Label(value = f'Acquisition time (s) '+ str(np.round(matrix*matrix*dwell_time/1e6,1)), **align3) \n",
- " focusdepth = Label(value = f'Depth of focus (nm) '+ str(np.round(wavelength/(semi_angle_corr/1000)**2/1000,1)), **align3) \n",
"\n",
"\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
" ### METHODS ########################################## \n",
" if method == 'direct':\n",
" \n",
@@ -577,7 +591,7 @@
"\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",
+ " fig.update_layout(width=600, height=225, margin = dict(l=100, 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",
@@ -595,17 +609,22 @@
" fig4.update_yaxes(title_text=\" Cover angle (mrad)\", range=[0, 1.1*np.max(detector_cover_all)], secondary_y=False)\n",
" fig4.update_yaxes(title_text=\" Cover angle (α)\", range=[0, 1.1*np.max(detector_cover_a_all)], 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",
+ " fig4.update_layout(width=600, height=225, margin =dict(l=110, r=30, t=30, b=30))\n",
" \n",
" \n",
- " checks = VBox([Label('Final checks'), electron_dose, ssb_sampling, focusdepth, acquisition_time]) \n",
+ " checks = VBox([Label('Final checks'), ssb_sampling, acquisition_time]) \n",
" checks.layout = Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
" \n",
" \n",
" ### SHOWING ###\n",
- " right_column = VBox([go.FigureWidget(fig),go.FigureWidget(fig5),go.FigureWidget(fig4)])\n",
+ "\n",
+ " \n",
+ " right_column = VBox([go.FigureWidget(fig),go.FigureWidget(fig5),go.FigureWidget(fig4),checks])\n",
" left_column = VBox([go.FigureWidget(fig8), go.FigureWidget(fig6)])\n",
- " display(HBox([left_column, right_column, checks]))\n",
+ " \n",
+ "\n",
+ " \n",
+ " display(HBox([left_column, right_column]))\n",
" \n",
" \n",
" \n",
@@ -651,13 +670,13 @@
"\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",
+ " fig.update_layout(width=600, 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 = VBox([Label('Final checks'),check1, check2, check3, acquisition_time]) \n",
" checks.layout = Layout(border='dashed 1px gray',margin='30px 5px 5px 5px', padding='10px 10px 10px 10px')\n",
" \n",
" \n",
@@ -682,14 +701,14 @@
" fig7.update_yaxes(range=[0, probe_window], showticklabels=False,)\n",
" fig7.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.9,xanchor=\"right\",x=1))\n",
" fig7.update_layout(title={'text': \"Probe window \",'y':0.925, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n",
- " fig7.update_layout(width=400, height=380, margin =dict(l=30, r=30, t=10, b=0)) \n",
+ " fig7.update_layout(width=320, height=300, margin =dict(l=30, r=30, t=10, b=0)) \n",
" \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), 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",
+ " align7 = dict(layout=Layout(width='120px') , style = {'description_width': '0px','button_width': \"105px\"}, disabled=True,)\n",
" \n",
" for i in range(0,12):\n",
" button_style = 'success'\n",
@@ -726,7 +745,7 @@
" \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)','Selected by CL ','Nominal CL (cm)',], \n",
+ " legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. def. (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",
@@ -743,14 +762,14 @@
" \n",
" ### SHOWING ###\n",
" sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7)]) \n",
- " right_column = VBox([go.FigureWidget(fig), sample_overlap, cltab ]) \n",
+ " right_column = VBox([go.FigureWidget(fig), sample_overlap, cltab, checks ]) \n",
" left_column = VBox([go.FigureWidget(fig8), go.FigureWidget(fig6)]) \n",
" \n",
- " display(HBox([left_column, right_column, checks]))\n",
+ " display(HBox([left_column, right_column]))\n",
" \n",
" return \n",
" \n",
- "gui = interactive_output(ptycho_interact, {\"beam\": beam, \"aperture\": aperture, \"probe\": probe, \"cl\": cl, \"matrix\": matrix, \"defocus\": defocus, \"mag\": mag, \"camera\": camera,\n",
+ "gui = interactive_output(ptycho_interact, {\"beam\": beam, \"aperture\": aperture,\"aperture_res\": aperture_res,\"aperture_res2\": aperture_res2, \"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_1bf\": cl_check_1bf, \"cl_check_nbf\": cl_check_nbf}) \n",
"\n"
@@ -786,19 +805,19 @@
},
{
"cell_type": "code",
- "execution_count": 744,
+ "execution_count": 37,
"id": "7937f054-fcd0-4e67-a20f-7696f5903a94",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "068f3d20c5e7439d92f4ec64e94490b0",
+ "model_id": "1e35fd918b334d70b6eca967055cf6ce",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
- "HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), HBox(childre…"
+ "HBox(children=(HBox(children=(VBox(children=(Label(value=''), VBox(children=(Label(value='Beam'), Dropdown(des…"
]
},
"metadata": {},
@@ -806,6 +825,8 @@
}
],
"source": [
+ "\n",
+ "\n",
"display(HBox([controls, gui]))"
]
},
@@ -835,23 +856,10 @@
},
{
"cell_type": "code",
- "execution_count": 734,
+ "execution_count": null,
"id": "b939697a-2ab0-49b2-8c73-555bb62a2e0d",
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Numpy version 1.26.1\n",
- "scipy version 1.9.1\n",
- "Plotly version 5.9.0\n",
- "Pandas version 2.1.2\n",
- "IPython version 7.31.1\n",
- "Ipywidgets version 7.6.5\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"# import numpy as np\n",
"# print(\"Numpy version \", np.__version__)\n",