From e118dc3249796a12eca1ff6c284f7425db1d15f2 Mon Sep 17 00:00:00 2001 From: rskoupy Date: Mon, 11 Dec 2023 18:02:12 +0100 Subject: [PATCH] for JupyterLab 4.x --- .../ptychoScopy-checkpoint.ipynb | 536 ++++++------------ ptychoScopy.ipynb | 536 ++++++------------ 2 files changed, 320 insertions(+), 752 deletions(-) diff --git a/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb b/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb index 1456a12..61e1271 100644 --- a/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb +++ b/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb @@ -2,7 +2,33 @@ "cells": [ { "cell_type": "code", - "execution_count": 79, + "execution_count": null, + "id": "a007a116-5d9d-4dd9-9352-b719f3deb8bb", + "metadata": {}, + "outputs": [], + "source": [ + "# # Used packages\n", + "# import sys\n", + "# print (sys.version)\n", + "# import openpyxl\n", + "# print(\"Openpyxl version \", openpyxl.__version__)\n", + "# import numpy as np\n", + "# print(\"Numpy version \", np.__version__)\n", + "# import scipy\n", + "# print(\"Scipy version \", scipy.__version__)\n", + "# import plotly\n", + "# print(\"Plotly version \", plotly.__version__)\n", + "# import pandas\n", + "# print(\"Pandas version \", pandas.__version__)\n", + "# import IPython\n", + "# print(\"IPython version \", IPython.__version__)\n", + "# import ipywidgets\n", + "# print(\"Ipywidgets version \", ipywidgets.__version__)" + ] + }, + { + "cell_type": "code", + "execution_count": 134, "id": "7425242d-3c91-4c1e-a424-08625a38ee7a", "metadata": {}, "outputs": [], @@ -18,20 +44,13 @@ "from plotly.subplots import make_subplots\n", "from ipywidgets import interactive_output, HBox, VBox, Layout, Label, Valid, ToggleButtons, RadioButtons, Dropdown, IntSlider, Checkbox, Button, ButtonStyle, GridBox,IntSlider\n", "\n", - "# print(\"Numpy version \", np.__version__)\n", - "# print(\"Pandas version \", pd.__version__)\n", - "# print(\"Ipywidgets version \", widgets.__version__)\n", - "# print(\"Plotly version \", plotly.__version__)\n", - "\n", "### Function definitions ###################################################\n", - "\n", "calib = r'calibrations.xlsx' # Path to the calibration file\n", "\n", "class interaction: \n", " \"\"\"Loads calibration settings and ranges from .xlsx file.\n", " These are than used for widgets creation.\"\"\"\n", " \n", - "\n", " def __init__(self):\n", " self.calib = calib\n", "\n", @@ -89,17 +108,12 @@ "opt = interaction()\n", "\n", "\n", - "\n", - "\n", - "\n", "class ptychoScopy:\n", " \"\"\"Computes various characteristics describing used setting.\"\"\"\n", " \n", " def __init__(self):\n", " self.calib = calib\n", " \n", - " \n", - " \n", " def get_wavelength(self, beam):\n", " self.wavelength = cons.h/np.sqrt(2*cons.electron_mass*cons.elementary_charge*beam*1e3*(1+((cons.elementary_charge*beam*1e3)/(2*cons.electron_mass*cons.speed_of_light**2))))\n", " return self.wavelength\n", @@ -240,7 +254,6 @@ " pctf = (2/cons.pi)*(np.arccos(omega/2)-p3+p4-(omega/2*np.sqrt(1-(omega/2)**2)))\n", " return pctf\n", " \n", - " \n", " def cl4ssb(self, detector_cover_a_all):\n", " ssb_cl = deepcopy(detector_cover_a_all)\n", " ssb_cl[ssb_cl<1] = \"nan\"\n", @@ -251,7 +264,6 @@ " ssb_cl = np.array(cl_all[kde]) # Recommended cl\n", " return ssb_cl, kolik\n", " \n", - "\n", "pty = ptychoScopy() \n", " \n", "class interaction:\n", @@ -260,7 +272,6 @@ " def __init__(self):\n", " self.calib = calib\n", " \n", - " \n", " def show_wavelength(self,caller):\n", " beam_res.value = f'λ (pm) {str(\"{:.1f}\".format(pty.get_wavelength(caller.new)*1e12))}'\n", " return beam_res.value\n", @@ -284,78 +295,70 @@ " def show_cd_det(self,caller):\n", " cl_det_res.value = f'Detector CL (cm) {\"{:.1f}\".format(pty.get_cl_detector(caller.new))}' \n", " return cl_det_res.value\n", - " \n", - " \n", - "inte = interaction() \n" + "\n", + "inte = interaction() " ] }, { "cell_type": "code", - "execution_count": 389, + "execution_count": 249, "id": "8055b802-cf83-4250-aea9-54e3e6b73db0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "### CONTROLS ##########################################\n", - "\n", - "ali = dict(style = {'description_width': '60px','button_width': '35px', 'font_weight': 'bold'}, button_style='',disabled = False)\n", + "ali = dict(style = {'description_width': '80px','button_width': '55px', 'font_weight': 'bold'}, button_style='',disabled = False)\n", "ali2 = dict(style = {'description_width': '60px','button_width': '90px', 'font_weight': 'bold'}, button_style='',disabled = False)\n", "\n", + "# header = Button(description='Control panel',layout=Layout(width='auto', grid_area='header'), style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '20px',font_variant='small-caps',text_color='white'),disabled = False)\n", "\n", - "\n", - "\n", - "\n", - "\n", - "header = Button(description='STEM control panel',layout=Layout(width='auto', grid_area='header'), style=ButtonStyle(button_color='silver', font_weight= 'bold',))\n", - "\n", - "beam_set = Button(description='Electron beam settings',layout=Layout(width='auto', grid_area='beam_set'), style=ButtonStyle(button_color='lightsteelblue', font_weight= 'bold')) \n", - "beam = ToggleButtons(options=opt.energies(), value=200,description='E (keV)', layout=Layout(width='auto', grid_area='beam_set1'), **ali)\n", + "beam_set = Button(description='Electron beam settings',layout=Layout(width='auto', grid_area='beam_set'), style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'),disabled = False) \n", + "beam = ToggleButtons(options=opt.energies(), value=200,description='Beam energy (keV)', layout=Layout(width='auto', grid_area='beam_set1'), **ali )\n", "aperture = ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', layout=Layout(width='auto', grid_area='beam_set2'), **ali)\n", "probe = ToggleButtons(options=opt.probes(), value='8C', description='Probe', layout=Layout(width='auto', grid_area='beam_set3'), **ali)\n", - "defocus = IntSlider(description='Δf (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, layout=Layout(width='auto', grid_area='beam_set4'), **ali)\n", + "defocus = IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, layout=Layout(width='auto', grid_area='beam_set4'), **ali)\n", "\n", - "scanning_set = Button(description='Scanning parameters',layout=Layout(width='auto', grid_area='scanning_set'),style=ButtonStyle(button_color='lightsteelblue', font_weight= 'bold'))\n", - "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Mag. Mx', layout=Layout(width='auto', grid_area='scanning_set1'), **ali)\n", + "scanning_set = Button(description='Scanning parameters',layout=Layout(width='auto', grid_area='scanning_set'),style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'),disabled = False)\n", + "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Magnification Mx', layout=Layout(width='auto', grid_area='scanning_set1'), **ali)\n", "matrix = ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', layout=Layout(width='auto', grid_area='scanning_set2'), **ali)\n", - "dwell_time = ToggleButtons(options=opt.dwelltimes(), value=10, description='t (μs)', layout=Layout(width='auto', grid_area='scanning_set3'), **ali)\n", + "dwell_time = ToggleButtons(options=opt.dwelltimes(), value=10, description='Dwell time (μs)', layout=Layout(width='auto', grid_area='scanning_set3'), **ali)\n", + "print(len(opt.detectors()))\n", "\n", "\n", "\n", - "camera_set = Button(description='Detection',layout=Layout(width='auto', grid_area='camera_set'),style=ButtonStyle(button_color='lightsteelblue', font_weight= 'bold'))\n", - "cl = ToggleButtons(options=opt.cameralengths(), value=12, description='CL (cm)', layout=Layout(width='auto', grid_area='cl_set1'), **ali)\n", - "camera = ToggleButtons(options=opt.detectors(), description='Detector', layout=Layout(width='auto', grid_area='camera_set1'), **ali2)\n", - "restriction = ToggleButtons(options=[('.',False), ('..',True)], value = False, description='PAAR',icons = ['times','check'], layout=Layout(width='auto', grid_area='camera_set2'), **ali)\n", + "camera_set = Button(description='Detection',layout=Layout(width='auto', grid_area='camera_set'),style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'),disabled = False)\n", + "cl = ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal camera length (cm)', layout=Layout(width='auto', grid_area='cl_set1'), **ali)\n", + "camera = ToggleButtons(options=opt.detectors(), description='Detector', layout=Layout(width='auto', grid_area='camera_set1'), style = {'description_width': '60px','button_width': str(100/len(opt.detectors())-len(opt.detectors()))+'%', 'font_weight': 'bold'})\n", + "restriction = ToggleButtons(options=[('.',False), ('..',True)], value = False, description='PAAR',icons = ['times','check'], layout=Layout(width='auto', grid_area='camera_set2'),style = {'description_width': '80px','button_width': '48%', 'font_weight': 'bold'})\n", "binning = ToggleButtons(options=[('.',1), ('2×2',2), ('4×4',4), ('6×6',6), ('8×8',8)], value=1, description='Binning', icons = ['times','',''], layout=Layout(width='auto', grid_area='camera_set3'), **ali)\n", "\n", "beam_res = Label(value = f'λ (pm) '+ str(\"{:.1f}\".format(pty.get_wavelength(beam.value)*1e12)),layout=Layout(width='auto', grid_area='sidebar1'),)\n", "beam.observe(inte.show_wavelength, names='value') \n", - "\n", "aperture_res = Label(value = f'Probe semi-angle (mrad) '+ str(\"{:.1f}\".format(pty.get_angle(aperture.value))), layout=Layout(width='auto', grid_area='sidebar2'),)\n", "aperture.observe(inte.show_probe_angle, names='value') \n", - "\n", "aperture_res2 = Label(value = f'corr. '+ str(\"{:.2f}\".format(pty.get_angle_corr(aperture.value))),layout=Layout(width='auto', grid_area='sidebar5'),)\n", "aperture.observe(inte.show_corrprobe_angle, names='value') \n", - "\n", "fov_res = Label(value = f'FoV (nm) '+ str(\"{:.1f}\".format(pty.get_fov(mag.value))),layout=Layout(width='auto', grid_area='sidebar3'),) \n", "mag.observe(inte.show_fov, names='value') \n", - "\n", "dwell_time_res = Label(value = f'Rate (kHz) '+ str(\"{:.1f}\".format(pty.get_aq_frec(dwell_time.value))),layout=Layout(width='auto', grid_area='sidebar4'),) \n", "dwell_time.observe(inte.show_frame_rate, names='value') \n", "\n", - "footer = Button(description='Footer',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='silver'))\n", + "footer = Button(description='',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'))\n", "\n", - "\n", - "controls = GridBox(children=[header, beam_set, beam, aperture, probe, defocus, scanning_set, mag,matrix,dwell_time, cl,camera_set, camera, restriction, binning, beam_res, aperture_res,aperture_res2,fov_res, dwell_time_res],\n", - " layout=Layout(\n", - " width='22%',\n", - " grid_template_rows='auto auto auto',\n", - " grid_template_columns='30% 30% 20% 20%',\n", - " grid_template_areas='''\n", - " \"header header header header\"\n", + "controls = GridBox(children=[beam_set, beam, aperture, probe, defocus, scanning_set, mag,matrix,dwell_time, cl,camera_set, camera, restriction, binning, beam_res, aperture_res,aperture_res2,fov_res, dwell_time_res,footer],\n", + " layout=Layout(width='15%', grid_template_rows='auto auto auto', grid_template_columns='30% 30% 20% 20%', grid_template_areas='''\n", " \"beam_set beam_set beam_set beam_set \" \n", " \"beam_set1 beam_set1 beam_set1 beam_set1 \"\n", " \"beam_set2 beam_set2 beam_set2 beam_set2 \"\n", - " \". sidebar2 sidebar2 sidebar5 \"\n", + " \"sidebar2 sidebar2 sidebar5 sidebar5 \"\n", " \"beam_set3 beam_set3 beam_set3 beam_set3 \"\n", " \"beam_set4 beam_set4 beam_set4 beam_set4 \"\n", " \"scanning_set scanning_set scanning_set scanning_set \" \n", @@ -367,58 +370,43 @@ " \"camera_set1 camera_set1 camera_set1 camera_set1 \"\n", " \"camera_set3 camera_set3 camera_set3 camera_set3 \"\n", " \"camera_set2 camera_set2 camera_set2 camera_set2 \"\n", - " ''')\n", - " )\n", + " \"footer footer footer footer \"\n", + " '''))\n", "\n", "# SMALL CONTROLS\n", + "descr = '100px'\n", + "butt = '100px'\n", + "butt2 = '150px'\n", "\n", - "descr = '80px'\n", - "butt = '60px'\n", + "header1 = Button(description='Graph selection',layout=Layout(width='auto', grid_area='header1'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'), disabled = False)\n", + "header2 = Button(description='CTF graph',layout=Layout(width='auto', grid_area='header2'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'),disabled = False)\n", + "header3 = Button(description='CL limitations',layout=Layout(width='auto', grid_area='header3'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'),disabled = False)\n", + "method = ToggleButtons(options=[('SSB','direct'), ('Reconstruction ','iterative')], description='', icons = ['','refresh'], tooltips=['Single side band ptychography', 'Iterative reconstruction methods (PIE, ML, DM)'],\n", + " layout=Layout(width='auto', grid_area='methods'), style = {'description_width': descr, 'button_width': '48.5%', 'font_weight': 'bold'}, button_style='',disabled=False,)\n", + "graph_size = IntSlider(value=100,min=50,max=150,step=5, description='Graphs size', layout=Layout(width='auto', grid_area='gr_size'), style = {'description_width': descr,'button_width': butt}, button_style='',disabled=False,)\n", + "ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='x-axis:', layout=Layout(width='auto', grid_area='ctxaxis'), style = {'description_width': descr,'button_width': butt}, disabled=False)\n", "\n", - "header = Button(description='Graph controls',layout=Layout(width='auto', grid_area='header'),style=ButtonStyle(button_color='whitesmoke', font_weight= 'bold'))\n", + "cl_check_laa = Checkbox(value=True, description='Low anlge approximation', indent=False, layout=Layout(width='auto', grid_area='check1'), disabled=False,) # Low angle approximation check - scattering angle < 10 deg\n", + "cl_check_pix = Checkbox(value=True, description='Ptycho pixel < step size',indent=False, layout=Layout(width='auto', grid_area='check2'), disabled=False,) # Reconstructed pixel size < scanning step size \n", + "cl_check_def = Checkbox(value=True, description='Beam fits in probe window', indent=False, layout=Layout(width='auto', grid_area='check3'), disabled=False,) # Is probe window big enough to accomodate defocused probe?\n", + "cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', indent=False, layout=Layout(width='auto', grid_area='check4'), disabled=False,) # Detector cover is lower than 1 α\n", + "cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', indent=False, layout=Layout(width='auto', grid_area='check5'), disabled=False,) # Detector cover is higher than 6 α\n", "\n", - "method = ToggleButtons(options=[('SSB','direct'), ('Iterative','iterative')], description='Method', tooltips=['SSB', 'PIE, MLc, DM'],\n", - " layout=Layout(width='auto', grid_area='methods'), style = {'description_width': descr,'button_width': butt, 'font_weight': 'bold'}, button_style='',disabled=False,)\n", + "chart = ToggleButtons(options=[('Scheme ','micr'), ('Charts ','dedic'),('Both ','both')],value = 'both',icons = ['eye','eye','eye'], description='',\n", + " layout=Layout(width='auto', grid_area='charts'), style = {'description_width': descr,'button_width': '32%', 'font_weight': 'bold'}, button_style='',disabled=False,)\n", + "footer = Button(description='Interactive results',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'),disabled = False)\n", "\n", - "graph_size = IntSlider(value=100,min=10,max=200,step=5, description='Graphs size',\n", - " layout=Layout(width='auto', grid_area='gr_size'), style = {'description_width': descr,'button_width': butt}, button_style='',disabled=False,)\n", - "\n", - "ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='CTF x-axis:',\n", - " layout=Layout(width='auto', grid_area='ctxaxis'), style = {'description_width': descr,'button_width': butt}, disabled=False,)\n", - "\n", - "cl_check_laa = Checkbox(value=True, description='Low anlge approximation', indent=False,\n", - " layout=Layout(width='auto', grid_area='check1'), style = {'description_width': descr}, disabled=False,) # Low angle approximation check - scattering angle < 10 deg\n", - "cl_check_pix = Checkbox(value=True, description='Ptycho pixel < step size',indent=False,\n", - " layout=Layout(width='auto', grid_area='check2'), style = {'description_width': descr}, disabled=False,) # Reconstructed pixel size < scanning step size \n", - "cl_check_def = Checkbox(value=True, description='Beam fits in probe window', indent=False,\n", - " layout=Layout(width='auto', grid_area='check3'), style = {'description_width': descr}, disabled=False,) # Is probe window big enough to accomodate defocused probe?\n", - "cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', indent=False,\n", - " layout=Layout(width='auto', grid_area='check4'), style = {'description_width': descr}, disabled=False,) # Detector cover is lower than 1 α\n", - "cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', indent=False,\n", - " layout=Layout(width='auto', grid_area='check5'), style = {'description_width': descr}, disabled=False,) # Detector cover is higher than 6 α\n", - "\n", - "\n", - "chart = ToggleButtons(options=[('STEM','micr'), ('Charts','dedic'),('Both','both')],value = 'both', description='Show',\n", - " layout=Layout(width='auto', grid_area='charts'), style = {'description_width': descr,'button_width': butt, 'font_weight': 'bold'}, button_style='',disabled=False,)\n", - "\n", - "\n", - "footer = Button(description='Interactive results',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='whitesmoke', font_weight= 'bold'))\n", - "\n", - "small_controls = GridBox(children=[header, method, chart, graph_size, ctf_xaxis, cl_check_laa,cl_check_pix,cl_check_def, cl_check_1bf, cl_check_nbf, footer],\n", - " layout=Layout(\n", - " width='100%',\n", - " grid_template_rows='auto auto auto',\n", - " grid_template_columns='50% 20% 30%',\n", + "small_controls = GridBox(children=[header1,header2,header3, method, chart, graph_size, ctf_xaxis, cl_check_laa,cl_check_pix,cl_check_def, cl_check_1bf, cl_check_nbf, footer],\n", + " layout=Layout(width='100%',\n", + " grid_template_rows='auto auto auto auto auto',\n", + " grid_template_columns='2% 38% 10% 25% 25%',\n", " grid_template_areas='''\n", - " \"header header header \"\n", - " \"methods ctxaxis check1 \"\n", - " \"charts ctxaxis check2 \"\n", - " \"gr_size ctxaxis check3 \"\n", - " \". . check4 \"\n", - " \". . check5 \"\n", - " \"footer footer footer\"\n", - " ''')\n", - " )\n", + " \". header1 header2 header3 header3 \"\n", + " \". methods ctxaxis check1 check4\"\n", + " \". charts ctxaxis check2 check5\"\n", + " \". gr_size ctxaxis check3 .\"\n", + " \". footer footer footer footer\"\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, cl_check_laa, cl_check_pix, cl_check_def, cl_check_1bf, cl_check_nbf, graph_size, chart):\n", @@ -469,57 +457,45 @@ " apertury = opt.apertures()\n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - " \n", " ### SAMPLE PLANE ##########################################\n", " points = 5\n", " yyy = np.append(np.linspace(0,overlap,100), 200)\n", " wid = np.array([-2, -1, 0, 1, 2]) * step_size_corr\n", - " \n", " fig5 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", " fig5.update_xaxes(title_text=\"Sample plane (nm)\", range=[-4*step_size_corr, 4*step_size_corr], showgrid=False, zeroline=False)\n", " fig5.update_yaxes(range=[-4*step_size_corr, 4*step_size_corr],showgrid=False, showticklabels=False)\n", + " \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", + " \n", " for x in range(len(wid)): \n", " for y in range(len(wid)): \n", " fig5.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", opacity=0.1, fillcolor=\"#FF7F7F\",name=False, x0=wid[x]-beam_diameter/2, y0=wid[y]-beam_diameter/2, x1=wid[x]+beam_diameter/2, y1=wid[y]+beam_diameter/2, line_color=\"red\",secondary_y=False)\n", - "\n", + " \n", " fig5.add_annotation(x=-1*step_size_corr, y=-2*step_size_corr, ax=-2*step_size_corr, ay=-2*step_size_corr, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=-2*step_size_corr, y=-1*step_size_corr, ax=-2*step_size_corr, ay=-2*step_size_corr, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=-1.25*step_size_corr, y=-1.5*step_size_corr, text=str(np.round(10*step_size_corr,3))+' Å', showarrow=False, yshift=0)\n", - " \n", " fig5.add_annotation(x=2*step_size_corr-0.75*beam_diameter/2, y=-2*step_size_corr-0.75*beam_diameter/2, ax=2*step_size_corr, ay=-2*step_size_corr,xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=2*step_size_corr+0.75*beam_diameter/2, y=-2*step_size_corr+0.75*beam_diameter/2, ax=2*step_size_corr, ay=-2*step_size_corr,xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=2.25*step_size_corr, y=-2*step_size_corr, text=str(np.round(10*beam_diameter,2))+' Å', showarrow=False, yshift=-15)\n", " \n", - " \n", " if method == 'direct':\n", " xx = 2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100\n", " fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='green', name='Rec step '+str(np.round(xx[-1]/3,2))+' Å')) \n", - " \n", - " fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=0.9))\n", + "\n", + " if method == 'iterative':\n", + " fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='#FF7F7F', name='Beam ⌀ '+str(np.round(10*beam_diameter,2))+' Å')) \n", + "\n", + " fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=1.0,xanchor=\"right\",x=0.9))\n", " fig5.add_trace(go.Scatter(showlegend=False, x = -4*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(range=[0, 100], showgrid=False, showticklabels=False, secondary_y=True)\n", " fig5.update_yaxes(title_text=\"Overlap %\", showgrid=False, showticklabels=True, tickvals = [-4*step_size_corr, -2*step_size_corr, 0, 2*step_size_corr, 4*step_size_corr],ticktext = ['0', '25', '50', '75', '100'], secondary_y=False)\n", " fig5.update_layout(title={'text': \"Sample\",'y': 0.975, 'x': 0.30,'xanchor': 'left','yanchor': 'top'})\n", - " fig5.update_layout(width=4.5*graph_size, height=3.0*graph_size, margin =dict(l=1.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, b=0))\n", + " fig5.update_layout(width=4.25*graph_size, height=3.0*graph_size, margin =dict(l=1.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, b=0))\n", "\n", " \n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " ### DETECTOR PLANE ##########################################\n", " fig6 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", - " \n", " for x in np.linspace(1,int(np.round(covered_alfas)),int(np.round(covered_alfas))):\n", " fig6.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", x0=num_pixels/2-x*beam_diameter_pix, y0=num_pixels/2-x*beam_diameter_pix, x1=num_pixels/2+x*beam_diameter_pix, y1=num_pixels/2+x*beam_diameter_pix, line=dict(color=\"gray\",width=1,dash=\"dot\",),secondary_y=False)\n", " fig6.add_trace(go.Scatter(showlegend=False,x=[num_pixels/2],y=[num_pixels/2+x*beam_diameter_pix],mode=\"lines+text\", text=str(int(2*x))+\"α\",textposition=\"top center\"),secondary_y=False)\n", @@ -531,29 +507,19 @@ " fig6.add_annotation(x=num_pixels/2, y=num_pixels/2, text=\"1 pix = \"+str(np.round(pixel_angle,2))+\" mrad\", showarrow=False, yshift=-10)\n", " fig6.add_annotation(x=num_pixels/2, y=num_pixels/10, text=\"Real pixel size = \"+str(np.round(size_pixel,2))+\" μm\", showarrow=False, yshift=0)\n", " fig6.add_trace(go.Scatter(showlegend=True,x=[-1], y=[-1], marker_color='red', name = \"BF disk\"),secondary_y=False)\n", - " \n", " fig6.add_trace(go.Scatter(showlegend=False,x=[-1], y=[-1]),secondary_y=True)\n", - " \n", " fig6.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=1.00,xanchor=\"right\",x=0.9))\n", " fig6.update_layout(title={'text': \"Detector\",'y':0.975, 'x':0.11,'xanchor': 'left','yanchor': 'top'})\n", - " \n", " fig6.update_xaxes(title_text=\"Pixels\", range=[1, num_pixels], zeroline=False, tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels]) \n", " fig6.update_yaxes(range=[1, num_pixels], showticklabels=False, showgrid=False, secondary_y=False)\n", - " fig6.update_yaxes(title_text=\"Angular cover (mrad)\", range=[1, num_pixels], showticklabels=True, tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels], ticktext = ['', np.round(detector_cover/4,1), np.round(detector_cover/2,1), np.round(3*detector_cover/4,1), np.round(detector_cover,1)], secondary_y=True) \n", - " \n", - " fig6.update_layout(width=3.5*graph_size, height=3*graph_size, margin = dict(l=0.35*graph_size, r=0.48*graph_size, t=0.3*graph_size, b=0))\n", + " fig6.update_yaxes(title_text=\"Angular cover (mrad)\", range=[1, num_pixels], showticklabels=True, tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels],\n", + " ticktext = ['', np.round(detector_cover/4,1), np.round(detector_cover/2,1), np.round(3*detector_cover/4,1), np.round(detector_cover,1)], secondary_y=True) \n", + " fig6.update_layout(width=3.35*graph_size, height=3*graph_size, margin = dict(l=0.35*graph_size, r=0.48*graph_size, t=0.3*graph_size, b=0))\n", "\n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " focusdepth = wavelength/(semi_angle_corr/1000)**2/1000\n", " ssb_cl, kolik = pty.cl4ssb(detector_cover_a_all)\n", + " \n", " ### MICROSCOPE SCHEME ##########################################\n", " width = 500 # in-graph setting\n", " det_width = 400 # in-graph setting\n", @@ -570,10 +536,7 @@ " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=str(aperture), showarrow=False, yshift=-15)\n", " fig8.add_annotation(x=0.0*width, y=-y_down,text='Acquisition time (s) '+ str(np.round(matrix*matrix*dwell_time/1e6,1)), showarrow=False, yshift=-10)\n", " fig8.add_annotation(x=0, y=reduc*0.96*y_down,text='λ (pm) '+ str(np.round((pty.get_wavelength(beam)*1e12),2)), showarrow=False, yshift=0)\n", - " \n", - " \n", - " \n", - " \n", + "\n", " if defocus > 0:\n", " defo = np.log(defocus)/100\n", " else:\n", @@ -608,13 +571,14 @@ " # BF disk\n", " 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=\"#FF7F7F\", opacity=0.7,line=dict(color='#FF7F7F',width=1)))\n", " 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*width, y=-np.log(ssb_cl),text=\"\", showarrow=False,align= 'left', yshift=15)\n", + "\n", + " if method == 'direct':\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*width, y=-np.log(ssb_cl),text=\"\", 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=\"PAAR\", showarrow=False,align= 'left', yshift=15)\n", + " fig8.add_annotation(x=-0.35*width, y=-reduc*0.2*y_down,text=\"PAAR\", 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", @@ -639,12 +603,11 @@ " check3 = Valid(value= bool(beam_diameter/2 < probe_window/2), description='Beam ⌀ < window/2', **align_check) \n", " \n", "\n", - "\n", + " \n", " \n", " ### METHODS ########################################## \n", " if method == 'direct':\n", " \n", - " \n", " ### PROBE ##########################################\n", " fig = go.Figure() \n", " fig.update_yaxes(title_text=\"Contrast transfer func.\")\n", @@ -673,7 +636,6 @@ " # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n", " fig.update_layout(width=7.65*graph_size, height=2.25*graph_size, margin = dict(l=1.3*graph_size, r=0.3*graph_size, t=0.3*graph_size, b=0.3*graph_size))\n", " \n", - " \n", " ### CAMERA LENGTH GRAPH ##########################################\n", " fig4 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", " fig4.add_trace(go.Scatter(showlegend=False, x=opt.cameralengths(), y=detector_cover_all, marker_color='gray'), secondary_y=False,)\n", @@ -689,8 +651,6 @@ " fig4.update_layout(xaxis = dict(tickmode = 'array', tickvals = opt.cameralengths()))\n", " fig4.update_layout(width=8.0*graph_size, height=2.25*graph_size, margin =dict(l=1.3*graph_size, r=0.25*graph_size, t=0.3*graph_size, b=0.3*graph_size))\n", "\n", - " \n", - " \n", " ### SHOWING ###\n", " if chart == 'micr':\n", " left_column = VBox([go.FigureWidget(fig8)])\n", @@ -704,51 +664,46 @@ " right_column = VBox([go.FigureWidget(fig) ,HBox([go.FigureWidget(fig5),go.FigureWidget(fig6)]),go.FigureWidget(fig4)])\n", " left_column = VBox([go.FigureWidget(fig8)])\n", " total = HBox([left_column, right_column])\n", - " \n", - " \n", + " \n", " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px') \n", " display(total)\n", - " \n", "\n", - " \n", " \n", " if method == 'iterative': \n", - " \n", " ### PROBE ##########################################\n", - " fig = go.Figure() \n", - " fig.update_yaxes(title_text=\"Contrast transfer func.\")\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", + " fig = go.Figure() \n", + " fig.update_yaxes(title_text=\"Contrast transfer func.\")\n", + " match ctf_xaxis: \n", + " case 'α':\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", + " case '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", - " 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", + " case '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", + " 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", @@ -777,24 +732,21 @@ " fig7.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", opacity=0.9, fillcolor=color, x0=probe_window/2-beam_diameter/2, y0=probe_window/2-beam_diameter/2, x1=probe_window/2+beam_diameter/2, y1=probe_window/2+beam_diameter/2, line_color=color,)\n", " fig7.update_xaxes(title_text=\"Probe window (nm)\", range=[0, probe_window], tickvals = [0, np.round(probe_window/4,2), np.round(probe_window/2,2), np.round(3*probe_window/4,2), np.round(probe_window,2)-0.01])\n", " 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=3.2*graph_size, height=3.0*graph_size, margin =dict(l=0.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, b=0)) \n", + " fig7.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=1.0,xanchor=\"right\",x=1))\n", + " fig7.update_layout(title={'text': \"Probe\",'y':0.975, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n", + " fig7.update_layout(width=3.0*graph_size, height=3.0*graph_size, margin =dict(l=0.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, 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=str(int(graph_size/100*62))+'px') , style = {'description_width': '0px','button_width': str(int(graph_size/100*40))+'px'}, disabled=True,)\n", + " align6 = dict(layout=Layout(width=str(int(graph_size/100*62))+'px') , style = {'description_width': '0px','button_width': str(int(graph_size/100*60))+'px'}, disabled=True,)\n", " align7 = dict(layout=Layout(width='140px') , style = {'description_width': '0px','button_width': \"120px\"}, 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", " data_tuple = tuple(tab[0:4,int(i)]) + (\"\",tab[4,int(i)])\n", - " \n", - " \n", " icons=['','','','','']\n", " \n", " if cl_check_nbf == True: \n", @@ -818,42 +770,30 @@ " button_style = 'danger' \n", " \n", " if cl == data[4]:\n", - " icons=['','','','','check']\n", - " \n", + " icons=['','','','','check'] \n", " \n", - " dictionary[i] = ToggleButtons(options=data_tuple, button_style=button_style, icons = icons, **align6)\n", - " \n", + " dictionary[i] = ToggleButtons(options=data_tuple, text_color= 'red', button_style=button_style, icons = icons, **align6)\n", + "\n", " legend = ToggleButtons(options=['Ptycho pixel (Å)','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", - " 'Dependent on: detector, binning, beam energy, camera length, zero defocus beam diameter, probe semi-angle',\n", - " 'Just nominal camera length',\n", - " ],button_style='', **align7) \n", - " \n", + " tooltips=['Dependent on: detector, beam energy, camera length', 'Dependent on: detector, camera length', 'Dependent on: detector, camera length, probe semi-angle', \n", + " 'Dependent on: detector, binning, beam energy, camera length, zero defocus beam diameter, probe semi-angle', 'Just nominal camera length'],button_style='', **align7) \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 110px', padding='10px 10px 10px 10px')\n", - " \n", - " \n", - " \n", - " \n", + "\n", " ### SHOWING ###\n", - " if chart == 'micr':\n", - " left_column = VBox([go.FigureWidget(fig8)])\n", - " total = HBox([left_column]) \n", - " \n", - " elif chart == 'dedic':\n", - " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", - " right_column = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", - " total = HBox([right_column])\n", - " \n", - " else: \n", - " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", - " right_column = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", - " left_column = VBox([go.FigureWidget(fig8)]) \n", - " total = HBox([left_column, right_column]) \n", + " match chart:\n", + " case 'micr':\n", + " total = VBox([go.FigureWidget(fig8)])\n", + " case 'dedic':\n", + " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", + " total = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", + " case _:\n", + " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", + " right_column = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", + " left_column = go.FigureWidget(fig8)\n", + " total = HBox([left_column, right_column]) \n", " \n", " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px') \n", " display(total)\n", @@ -862,9 +802,8 @@ " return \n", " \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,\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, \"graph_size\": graph_size,\"chart\": chart}) \n", - "\n" + " \"binning\": binning, \"dwell_time\": dwell_time, \"restriction\": restriction, \"method\": method, \"ctf_xaxis\": ctf_xaxis, \"cl_check_laa\":cl_check_laa, \"cl_check_pix\": cl_check_pix, \"cl_check_def\": cl_check_def,\n", + " \"cl_check_1bf\": cl_check_1bf, \"cl_check_nbf\": cl_check_nbf, \"graph_size\": graph_size,\"chart\": chart}) \n" ] }, { @@ -891,25 +830,25 @@ "\n", "### Start the interactive gui by running the field\n", "```python\n", - "display(HBox([controls, VBox([small_controls, gui]) ]))\n", + "display(HBox([controls, VBox([small_controls, gui])]))\n", "```" ] }, { "cell_type": "code", - "execution_count": 390, + "execution_count": 250, "id": "7937f054-fcd0-4e67-a20f-7696f5903a94", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "6f84c5e6c29142a9bb9db08cd48aefbd", + "model_id": "6190870561a34612bdef3eaa3834f402", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "HBox(children=(GridBox(children=(Button(description='STEM control panel', layout=Layout(grid_area='header', wi…" + "HBox(children=(GridBox(children=(Button(description='Electron beam settings', layout=Layout(grid_area='beam_se…" ] }, "metadata": {}, @@ -917,162 +856,7 @@ } ], "source": [ - "\n", - "display(HBox([controls, VBox([small_controls, gui]) ]))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b939697a-2ab0-49b2-8c73-555bb62a2e0d", - "metadata": {}, - "outputs": [], - "source": [ - "# import numpy as np\n", - "# print(\"Numpy version \", np.__version__)\n", - "# import scipy\n", - "# print(\"scipy version \", scipy.__version__)\n", - "# import plotly\n", - "# print(\"Plotly version \", plotly.__version__)\n", - "# import pandas\n", - "# print(\"Pandas version \", pandas.__version__)\n", - "# import IPython\n", - "# print(\"IPython version \", IPython.__version__)\n", - "# import ipywidgets\n", - "# print(\"Ipywidgets version \", ipywidgets.__version__)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "33727cb4-c3d7-4134-be89-f10b9922fbda", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 75, - "id": "1cb358ba-42c4-420a-a0a6-0de425e670a6", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Ipywidgets version 7.6.5\n" - ] - } - ], - "source": [ - "import ipywidgets\n", - "print(\"Ipywidgets version \", ipywidgets.__version__)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a52ff861-8243-4d39-b7da-1ee8fb0ee494", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "61970cec-8678-4edf-99f6-4f832d2aad8d", - "metadata": {}, - "outputs": [], - "source": [ - "https://ipywidgets.readthedocs.io/en/latest/user_install.html" - ] - }, - { - "cell_type": "code", - "execution_count": 386, - "id": "a4628def-4c43-456e-a93b-95952e2a3dea", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 386, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from collections import defaultdict\n", - "from IPython.display import HTML\n", - "import ipywidgets\n", - "from pprint import pprint\n", - "\n", - "reverse_lut = defaultdict(set)\n", - "styles = set()\n", - "for export_name in dir(ipywidgets.widgets):\n", - " export = getattr(ipywidgets.widgets, export_name)\n", - " try:\n", - " if issubclass(export, ipywidgets.Widget) and 'style' in export.class_trait_names():\n", - " reverse_lut[export.style.klass.__name__].add(export.__name__)\n", - " styles.add(export.style.klass)\n", - " except TypeError:\n", - " pass\n", - "\n", - "html = '\"\n", - "HTML(html)" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "id": "54c1add7-f5ec-43f0-a447-e22dd03926a7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
AttributeToggleButtonsStyleButtonStyleDescriptionStyleProgressStyleSliderStyle
description_width
button_width
font_weight
bar_color
handle_color
button_color
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "attributes = defaultdict(set)\n", - "base_traits = set(ipywidgets.Style.class_trait_names())\n", - "\n", - "for s in styles:\n", - " for t in s.class_trait_names():\n", - " if not t.startswith(\"_\") and t not in base_traits:\n", - " attributes[s.__name__].add(t)\n", - "all_attributes = set().union(*attributes.values())\n", - "\n", - "html = '\\n'\n", - "html = f\"{html}{ ''.join(f'' for s in attributes.keys()) }\"\n", - "for a in all_attributes:\n", - " html = f\"\"\"{html}{ ''.join(f'' for attribs in attributes.values()) }\"\"\"\n", - "html += \"
Attribute{s}
{a}{\"✓\" if a in attribs else \"\"}
\"\n", - "HTML(html)" + "display(HBox([controls, VBox([small_controls, gui])]))" ] } ], @@ -1092,7 +876,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.5" }, "varInspector": { "cols": { diff --git a/ptychoScopy.ipynb b/ptychoScopy.ipynb index 1456a12..61e1271 100644 --- a/ptychoScopy.ipynb +++ b/ptychoScopy.ipynb @@ -2,7 +2,33 @@ "cells": [ { "cell_type": "code", - "execution_count": 79, + "execution_count": null, + "id": "a007a116-5d9d-4dd9-9352-b719f3deb8bb", + "metadata": {}, + "outputs": [], + "source": [ + "# # Used packages\n", + "# import sys\n", + "# print (sys.version)\n", + "# import openpyxl\n", + "# print(\"Openpyxl version \", openpyxl.__version__)\n", + "# import numpy as np\n", + "# print(\"Numpy version \", np.__version__)\n", + "# import scipy\n", + "# print(\"Scipy version \", scipy.__version__)\n", + "# import plotly\n", + "# print(\"Plotly version \", plotly.__version__)\n", + "# import pandas\n", + "# print(\"Pandas version \", pandas.__version__)\n", + "# import IPython\n", + "# print(\"IPython version \", IPython.__version__)\n", + "# import ipywidgets\n", + "# print(\"Ipywidgets version \", ipywidgets.__version__)" + ] + }, + { + "cell_type": "code", + "execution_count": 134, "id": "7425242d-3c91-4c1e-a424-08625a38ee7a", "metadata": {}, "outputs": [], @@ -18,20 +44,13 @@ "from plotly.subplots import make_subplots\n", "from ipywidgets import interactive_output, HBox, VBox, Layout, Label, Valid, ToggleButtons, RadioButtons, Dropdown, IntSlider, Checkbox, Button, ButtonStyle, GridBox,IntSlider\n", "\n", - "# print(\"Numpy version \", np.__version__)\n", - "# print(\"Pandas version \", pd.__version__)\n", - "# print(\"Ipywidgets version \", widgets.__version__)\n", - "# print(\"Plotly version \", plotly.__version__)\n", - "\n", "### Function definitions ###################################################\n", - "\n", "calib = r'calibrations.xlsx' # Path to the calibration file\n", "\n", "class interaction: \n", " \"\"\"Loads calibration settings and ranges from .xlsx file.\n", " These are than used for widgets creation.\"\"\"\n", " \n", - "\n", " def __init__(self):\n", " self.calib = calib\n", "\n", @@ -89,17 +108,12 @@ "opt = interaction()\n", "\n", "\n", - "\n", - "\n", - "\n", "class ptychoScopy:\n", " \"\"\"Computes various characteristics describing used setting.\"\"\"\n", " \n", " def __init__(self):\n", " self.calib = calib\n", " \n", - " \n", - " \n", " def get_wavelength(self, beam):\n", " self.wavelength = cons.h/np.sqrt(2*cons.electron_mass*cons.elementary_charge*beam*1e3*(1+((cons.elementary_charge*beam*1e3)/(2*cons.electron_mass*cons.speed_of_light**2))))\n", " return self.wavelength\n", @@ -240,7 +254,6 @@ " pctf = (2/cons.pi)*(np.arccos(omega/2)-p3+p4-(omega/2*np.sqrt(1-(omega/2)**2)))\n", " return pctf\n", " \n", - " \n", " def cl4ssb(self, detector_cover_a_all):\n", " ssb_cl = deepcopy(detector_cover_a_all)\n", " ssb_cl[ssb_cl<1] = \"nan\"\n", @@ -251,7 +264,6 @@ " ssb_cl = np.array(cl_all[kde]) # Recommended cl\n", " return ssb_cl, kolik\n", " \n", - "\n", "pty = ptychoScopy() \n", " \n", "class interaction:\n", @@ -260,7 +272,6 @@ " def __init__(self):\n", " self.calib = calib\n", " \n", - " \n", " def show_wavelength(self,caller):\n", " beam_res.value = f'λ (pm) {str(\"{:.1f}\".format(pty.get_wavelength(caller.new)*1e12))}'\n", " return beam_res.value\n", @@ -284,78 +295,70 @@ " def show_cd_det(self,caller):\n", " cl_det_res.value = f'Detector CL (cm) {\"{:.1f}\".format(pty.get_cl_detector(caller.new))}' \n", " return cl_det_res.value\n", - " \n", - " \n", - "inte = interaction() \n" + "\n", + "inte = interaction() " ] }, { "cell_type": "code", - "execution_count": 389, + "execution_count": 249, "id": "8055b802-cf83-4250-aea9-54e3e6b73db0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "### CONTROLS ##########################################\n", - "\n", - "ali = dict(style = {'description_width': '60px','button_width': '35px', 'font_weight': 'bold'}, button_style='',disabled = False)\n", + "ali = dict(style = {'description_width': '80px','button_width': '55px', 'font_weight': 'bold'}, button_style='',disabled = False)\n", "ali2 = dict(style = {'description_width': '60px','button_width': '90px', 'font_weight': 'bold'}, button_style='',disabled = False)\n", "\n", + "# header = Button(description='Control panel',layout=Layout(width='auto', grid_area='header'), style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '20px',font_variant='small-caps',text_color='white'),disabled = False)\n", "\n", - "\n", - "\n", - "\n", - "\n", - "header = Button(description='STEM control panel',layout=Layout(width='auto', grid_area='header'), style=ButtonStyle(button_color='silver', font_weight= 'bold',))\n", - "\n", - "beam_set = Button(description='Electron beam settings',layout=Layout(width='auto', grid_area='beam_set'), style=ButtonStyle(button_color='lightsteelblue', font_weight= 'bold')) \n", - "beam = ToggleButtons(options=opt.energies(), value=200,description='E (keV)', layout=Layout(width='auto', grid_area='beam_set1'), **ali)\n", + "beam_set = Button(description='Electron beam settings',layout=Layout(width='auto', grid_area='beam_set'), style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'),disabled = False) \n", + "beam = ToggleButtons(options=opt.energies(), value=200,description='Beam energy (keV)', layout=Layout(width='auto', grid_area='beam_set1'), **ali )\n", "aperture = ToggleButtons(options=opt.apertures(), value='30um', description='Aperture', layout=Layout(width='auto', grid_area='beam_set2'), **ali)\n", "probe = ToggleButtons(options=opt.probes(), value='8C', description='Probe', layout=Layout(width='auto', grid_area='beam_set3'), **ali)\n", - "defocus = IntSlider(description='Δf (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, layout=Layout(width='auto', grid_area='beam_set4'), **ali)\n", + "defocus = IntSlider(description='Defocus (nm)', value=0, min=0, max=1000, step=1, continuous_update=False, layout=Layout(width='auto', grid_area='beam_set4'), **ali)\n", "\n", - "scanning_set = Button(description='Scanning parameters',layout=Layout(width='auto', grid_area='scanning_set'),style=ButtonStyle(button_color='lightsteelblue', font_weight= 'bold'))\n", - "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Mag. Mx', layout=Layout(width='auto', grid_area='scanning_set1'), **ali)\n", + "scanning_set = Button(description='Scanning parameters',layout=Layout(width='auto', grid_area='scanning_set'),style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'),disabled = False)\n", + "mag = ToggleButtons(options=opt.magnifications(),value=3,description='Magnification Mx', layout=Layout(width='auto', grid_area='scanning_set1'), **ali)\n", "matrix = ToggleButtons(options=opt.mappings(), value=2048, description='Matrix', layout=Layout(width='auto', grid_area='scanning_set2'), **ali)\n", - "dwell_time = ToggleButtons(options=opt.dwelltimes(), value=10, description='t (μs)', layout=Layout(width='auto', grid_area='scanning_set3'), **ali)\n", + "dwell_time = ToggleButtons(options=opt.dwelltimes(), value=10, description='Dwell time (μs)', layout=Layout(width='auto', grid_area='scanning_set3'), **ali)\n", + "print(len(opt.detectors()))\n", "\n", "\n", "\n", - "camera_set = Button(description='Detection',layout=Layout(width='auto', grid_area='camera_set'),style=ButtonStyle(button_color='lightsteelblue', font_weight= 'bold'))\n", - "cl = ToggleButtons(options=opt.cameralengths(), value=12, description='CL (cm)', layout=Layout(width='auto', grid_area='cl_set1'), **ali)\n", - "camera = ToggleButtons(options=opt.detectors(), description='Detector', layout=Layout(width='auto', grid_area='camera_set1'), **ali2)\n", - "restriction = ToggleButtons(options=[('.',False), ('..',True)], value = False, description='PAAR',icons = ['times','check'], layout=Layout(width='auto', grid_area='camera_set2'), **ali)\n", + "camera_set = Button(description='Detection',layout=Layout(width='auto', grid_area='camera_set'),style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'),disabled = False)\n", + "cl = ToggleButtons(options=opt.cameralengths(), value=12, description='Nominal camera length (cm)', layout=Layout(width='auto', grid_area='cl_set1'), **ali)\n", + "camera = ToggleButtons(options=opt.detectors(), description='Detector', layout=Layout(width='auto', grid_area='camera_set1'), style = {'description_width': '60px','button_width': str(100/len(opt.detectors())-len(opt.detectors()))+'%', 'font_weight': 'bold'})\n", + "restriction = ToggleButtons(options=[('.',False), ('..',True)], value = False, description='PAAR',icons = ['times','check'], layout=Layout(width='auto', grid_area='camera_set2'),style = {'description_width': '80px','button_width': '48%', 'font_weight': 'bold'})\n", "binning = ToggleButtons(options=[('.',1), ('2×2',2), ('4×4',4), ('6×6',6), ('8×8',8)], value=1, description='Binning', icons = ['times','',''], layout=Layout(width='auto', grid_area='camera_set3'), **ali)\n", "\n", "beam_res = Label(value = f'λ (pm) '+ str(\"{:.1f}\".format(pty.get_wavelength(beam.value)*1e12)),layout=Layout(width='auto', grid_area='sidebar1'),)\n", "beam.observe(inte.show_wavelength, names='value') \n", - "\n", "aperture_res = Label(value = f'Probe semi-angle (mrad) '+ str(\"{:.1f}\".format(pty.get_angle(aperture.value))), layout=Layout(width='auto', grid_area='sidebar2'),)\n", "aperture.observe(inte.show_probe_angle, names='value') \n", - "\n", "aperture_res2 = Label(value = f'corr. '+ str(\"{:.2f}\".format(pty.get_angle_corr(aperture.value))),layout=Layout(width='auto', grid_area='sidebar5'),)\n", "aperture.observe(inte.show_corrprobe_angle, names='value') \n", - "\n", "fov_res = Label(value = f'FoV (nm) '+ str(\"{:.1f}\".format(pty.get_fov(mag.value))),layout=Layout(width='auto', grid_area='sidebar3'),) \n", "mag.observe(inte.show_fov, names='value') \n", - "\n", "dwell_time_res = Label(value = f'Rate (kHz) '+ str(\"{:.1f}\".format(pty.get_aq_frec(dwell_time.value))),layout=Layout(width='auto', grid_area='sidebar4'),) \n", "dwell_time.observe(inte.show_frame_rate, names='value') \n", "\n", - "footer = Button(description='Footer',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='silver'))\n", + "footer = Button(description='',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='navy', font_weight= 'bold',font_size= '16px',font_variant='small-caps',text_color='white'))\n", "\n", - "\n", - "controls = GridBox(children=[header, beam_set, beam, aperture, probe, defocus, scanning_set, mag,matrix,dwell_time, cl,camera_set, camera, restriction, binning, beam_res, aperture_res,aperture_res2,fov_res, dwell_time_res],\n", - " layout=Layout(\n", - " width='22%',\n", - " grid_template_rows='auto auto auto',\n", - " grid_template_columns='30% 30% 20% 20%',\n", - " grid_template_areas='''\n", - " \"header header header header\"\n", + "controls = GridBox(children=[beam_set, beam, aperture, probe, defocus, scanning_set, mag,matrix,dwell_time, cl,camera_set, camera, restriction, binning, beam_res, aperture_res,aperture_res2,fov_res, dwell_time_res,footer],\n", + " layout=Layout(width='15%', grid_template_rows='auto auto auto', grid_template_columns='30% 30% 20% 20%', grid_template_areas='''\n", " \"beam_set beam_set beam_set beam_set \" \n", " \"beam_set1 beam_set1 beam_set1 beam_set1 \"\n", " \"beam_set2 beam_set2 beam_set2 beam_set2 \"\n", - " \". sidebar2 sidebar2 sidebar5 \"\n", + " \"sidebar2 sidebar2 sidebar5 sidebar5 \"\n", " \"beam_set3 beam_set3 beam_set3 beam_set3 \"\n", " \"beam_set4 beam_set4 beam_set4 beam_set4 \"\n", " \"scanning_set scanning_set scanning_set scanning_set \" \n", @@ -367,58 +370,43 @@ " \"camera_set1 camera_set1 camera_set1 camera_set1 \"\n", " \"camera_set3 camera_set3 camera_set3 camera_set3 \"\n", " \"camera_set2 camera_set2 camera_set2 camera_set2 \"\n", - " ''')\n", - " )\n", + " \"footer footer footer footer \"\n", + " '''))\n", "\n", "# SMALL CONTROLS\n", + "descr = '100px'\n", + "butt = '100px'\n", + "butt2 = '150px'\n", "\n", - "descr = '80px'\n", - "butt = '60px'\n", + "header1 = Button(description='Graph selection',layout=Layout(width='auto', grid_area='header1'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'), disabled = False)\n", + "header2 = Button(description='CTF graph',layout=Layout(width='auto', grid_area='header2'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'),disabled = False)\n", + "header3 = Button(description='CL limitations',layout=Layout(width='auto', grid_area='header3'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'),disabled = False)\n", + "method = ToggleButtons(options=[('SSB','direct'), ('Reconstruction ','iterative')], description='', icons = ['','refresh'], tooltips=['Single side band ptychography', 'Iterative reconstruction methods (PIE, ML, DM)'],\n", + " layout=Layout(width='auto', grid_area='methods'), style = {'description_width': descr, 'button_width': '48.5%', 'font_weight': 'bold'}, button_style='',disabled=False,)\n", + "graph_size = IntSlider(value=100,min=50,max=150,step=5, description='Graphs size', layout=Layout(width='auto', grid_area='gr_size'), style = {'description_width': descr,'button_width': butt}, button_style='',disabled=False,)\n", + "ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='x-axis:', layout=Layout(width='auto', grid_area='ctxaxis'), style = {'description_width': descr,'button_width': butt}, disabled=False)\n", "\n", - "header = Button(description='Graph controls',layout=Layout(width='auto', grid_area='header'),style=ButtonStyle(button_color='whitesmoke', font_weight= 'bold'))\n", + "cl_check_laa = Checkbox(value=True, description='Low anlge approximation', indent=False, layout=Layout(width='auto', grid_area='check1'), disabled=False,) # Low angle approximation check - scattering angle < 10 deg\n", + "cl_check_pix = Checkbox(value=True, description='Ptycho pixel < step size',indent=False, layout=Layout(width='auto', grid_area='check2'), disabled=False,) # Reconstructed pixel size < scanning step size \n", + "cl_check_def = Checkbox(value=True, description='Beam fits in probe window', indent=False, layout=Layout(width='auto', grid_area='check3'), disabled=False,) # Is probe window big enough to accomodate defocused probe?\n", + "cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', indent=False, layout=Layout(width='auto', grid_area='check4'), disabled=False,) # Detector cover is lower than 1 α\n", + "cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', indent=False, layout=Layout(width='auto', grid_area='check5'), disabled=False,) # Detector cover is higher than 6 α\n", "\n", - "method = ToggleButtons(options=[('SSB','direct'), ('Iterative','iterative')], description='Method', tooltips=['SSB', 'PIE, MLc, DM'],\n", - " layout=Layout(width='auto', grid_area='methods'), style = {'description_width': descr,'button_width': butt, 'font_weight': 'bold'}, button_style='',disabled=False,)\n", + "chart = ToggleButtons(options=[('Scheme ','micr'), ('Charts ','dedic'),('Both ','both')],value = 'both',icons = ['eye','eye','eye'], description='',\n", + " layout=Layout(width='auto', grid_area='charts'), style = {'description_width': descr,'button_width': '32%', 'font_weight': 'bold'}, button_style='',disabled=False,)\n", + "footer = Button(description='Interactive results',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='lightgray', font_weight= 'bold',text_color='black'),disabled = False)\n", "\n", - "graph_size = IntSlider(value=100,min=10,max=200,step=5, description='Graphs size',\n", - " layout=Layout(width='auto', grid_area='gr_size'), style = {'description_width': descr,'button_width': butt}, button_style='',disabled=False,)\n", - "\n", - "ctf_xaxis = RadioButtons(options=['α','mrad', 'A'], description='CTF x-axis:',\n", - " layout=Layout(width='auto', grid_area='ctxaxis'), style = {'description_width': descr,'button_width': butt}, disabled=False,)\n", - "\n", - "cl_check_laa = Checkbox(value=True, description='Low anlge approximation', indent=False,\n", - " layout=Layout(width='auto', grid_area='check1'), style = {'description_width': descr}, disabled=False,) # Low angle approximation check - scattering angle < 10 deg\n", - "cl_check_pix = Checkbox(value=True, description='Ptycho pixel < step size',indent=False,\n", - " layout=Layout(width='auto', grid_area='check2'), style = {'description_width': descr}, disabled=False,) # Reconstructed pixel size < scanning step size \n", - "cl_check_def = Checkbox(value=True, description='Beam fits in probe window', indent=False,\n", - " layout=Layout(width='auto', grid_area='check3'), style = {'description_width': descr}, disabled=False,) # Is probe window big enough to accomodate defocused probe?\n", - "cl_check_1bf = Checkbox(value=True, description='Detector cover < 1α', indent=False,\n", - " layout=Layout(width='auto', grid_area='check4'), style = {'description_width': descr}, disabled=False,) # Detector cover is lower than 1 α\n", - "cl_check_nbf = Checkbox(value=True, description='Detector cover > 6α', indent=False,\n", - " layout=Layout(width='auto', grid_area='check5'), style = {'description_width': descr}, disabled=False,) # Detector cover is higher than 6 α\n", - "\n", - "\n", - "chart = ToggleButtons(options=[('STEM','micr'), ('Charts','dedic'),('Both','both')],value = 'both', description='Show',\n", - " layout=Layout(width='auto', grid_area='charts'), style = {'description_width': descr,'button_width': butt, 'font_weight': 'bold'}, button_style='',disabled=False,)\n", - "\n", - "\n", - "footer = Button(description='Interactive results',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='whitesmoke', font_weight= 'bold'))\n", - "\n", - "small_controls = GridBox(children=[header, method, chart, graph_size, ctf_xaxis, cl_check_laa,cl_check_pix,cl_check_def, cl_check_1bf, cl_check_nbf, footer],\n", - " layout=Layout(\n", - " width='100%',\n", - " grid_template_rows='auto auto auto',\n", - " grid_template_columns='50% 20% 30%',\n", + "small_controls = GridBox(children=[header1,header2,header3, method, chart, graph_size, ctf_xaxis, cl_check_laa,cl_check_pix,cl_check_def, cl_check_1bf, cl_check_nbf, footer],\n", + " layout=Layout(width='100%',\n", + " grid_template_rows='auto auto auto auto auto',\n", + " grid_template_columns='2% 38% 10% 25% 25%',\n", " grid_template_areas='''\n", - " \"header header header \"\n", - " \"methods ctxaxis check1 \"\n", - " \"charts ctxaxis check2 \"\n", - " \"gr_size ctxaxis check3 \"\n", - " \". . check4 \"\n", - " \". . check5 \"\n", - " \"footer footer footer\"\n", - " ''')\n", - " )\n", + " \". header1 header2 header3 header3 \"\n", + " \". methods ctxaxis check1 check4\"\n", + " \". charts ctxaxis check2 check5\"\n", + " \". gr_size ctxaxis check3 .\"\n", + " \". footer footer footer footer\"\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, cl_check_laa, cl_check_pix, cl_check_def, cl_check_1bf, cl_check_nbf, graph_size, chart):\n", @@ -469,57 +457,45 @@ " apertury = opt.apertures()\n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - " \n", " ### SAMPLE PLANE ##########################################\n", " points = 5\n", " yyy = np.append(np.linspace(0,overlap,100), 200)\n", " wid = np.array([-2, -1, 0, 1, 2]) * step_size_corr\n", - " \n", " fig5 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", " fig5.update_xaxes(title_text=\"Sample plane (nm)\", range=[-4*step_size_corr, 4*step_size_corr], showgrid=False, zeroline=False)\n", " fig5.update_yaxes(range=[-4*step_size_corr, 4*step_size_corr],showgrid=False, showticklabels=False)\n", + " \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", + " \n", " for x in range(len(wid)): \n", " for y in range(len(wid)): \n", " fig5.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", opacity=0.1, fillcolor=\"#FF7F7F\",name=False, x0=wid[x]-beam_diameter/2, y0=wid[y]-beam_diameter/2, x1=wid[x]+beam_diameter/2, y1=wid[y]+beam_diameter/2, line_color=\"red\",secondary_y=False)\n", - "\n", + " \n", " fig5.add_annotation(x=-1*step_size_corr, y=-2*step_size_corr, ax=-2*step_size_corr, ay=-2*step_size_corr, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=-2*step_size_corr, y=-1*step_size_corr, ax=-2*step_size_corr, ay=-2*step_size_corr, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=-1.25*step_size_corr, y=-1.5*step_size_corr, text=str(np.round(10*step_size_corr,3))+' Å', showarrow=False, yshift=0)\n", - " \n", " fig5.add_annotation(x=2*step_size_corr-0.75*beam_diameter/2, y=-2*step_size_corr-0.75*beam_diameter/2, ax=2*step_size_corr, ay=-2*step_size_corr,xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=2*step_size_corr+0.75*beam_diameter/2, y=-2*step_size_corr+0.75*beam_diameter/2, ax=2*step_size_corr, ay=-2*step_size_corr,xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig5.add_annotation(x=2.25*step_size_corr, y=-2*step_size_corr, text=str(np.round(10*beam_diameter,2))+' Å', showarrow=False, yshift=-15)\n", " \n", - " \n", " if method == 'direct':\n", " xx = 2*wavelength/(np.sin(semi_angle_corr*omega/1000))/100\n", " fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='green', name='Rec step '+str(np.round(xx[-1]/3,2))+' Å')) \n", - " \n", - " fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=0.9))\n", + "\n", + " if method == 'iterative':\n", + " fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='#FF7F7F', name='Beam ⌀ '+str(np.round(10*beam_diameter,2))+' Å')) \n", + "\n", + " fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=1.0,xanchor=\"right\",x=0.9))\n", " fig5.add_trace(go.Scatter(showlegend=False, x = -4*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(range=[0, 100], showgrid=False, showticklabels=False, secondary_y=True)\n", " fig5.update_yaxes(title_text=\"Overlap %\", showgrid=False, showticklabels=True, tickvals = [-4*step_size_corr, -2*step_size_corr, 0, 2*step_size_corr, 4*step_size_corr],ticktext = ['0', '25', '50', '75', '100'], secondary_y=False)\n", " fig5.update_layout(title={'text': \"Sample\",'y': 0.975, 'x': 0.30,'xanchor': 'left','yanchor': 'top'})\n", - " fig5.update_layout(width=4.5*graph_size, height=3.0*graph_size, margin =dict(l=1.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, b=0))\n", + " fig5.update_layout(width=4.25*graph_size, height=3.0*graph_size, margin =dict(l=1.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, b=0))\n", "\n", " \n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " ### DETECTOR PLANE ##########################################\n", " fig6 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", - " \n", " for x in np.linspace(1,int(np.round(covered_alfas)),int(np.round(covered_alfas))):\n", " fig6.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", x0=num_pixels/2-x*beam_diameter_pix, y0=num_pixels/2-x*beam_diameter_pix, x1=num_pixels/2+x*beam_diameter_pix, y1=num_pixels/2+x*beam_diameter_pix, line=dict(color=\"gray\",width=1,dash=\"dot\",),secondary_y=False)\n", " fig6.add_trace(go.Scatter(showlegend=False,x=[num_pixels/2],y=[num_pixels/2+x*beam_diameter_pix],mode=\"lines+text\", text=str(int(2*x))+\"α\",textposition=\"top center\"),secondary_y=False)\n", @@ -531,29 +507,19 @@ " fig6.add_annotation(x=num_pixels/2, y=num_pixels/2, text=\"1 pix = \"+str(np.round(pixel_angle,2))+\" mrad\", showarrow=False, yshift=-10)\n", " fig6.add_annotation(x=num_pixels/2, y=num_pixels/10, text=\"Real pixel size = \"+str(np.round(size_pixel,2))+\" μm\", showarrow=False, yshift=0)\n", " fig6.add_trace(go.Scatter(showlegend=True,x=[-1], y=[-1], marker_color='red', name = \"BF disk\"),secondary_y=False)\n", - " \n", " fig6.add_trace(go.Scatter(showlegend=False,x=[-1], y=[-1]),secondary_y=True)\n", - " \n", " fig6.update_layout(legend=dict(orientation=\"h\",yanchor=\"bottom\",y=1.00,xanchor=\"right\",x=0.9))\n", " fig6.update_layout(title={'text': \"Detector\",'y':0.975, 'x':0.11,'xanchor': 'left','yanchor': 'top'})\n", - " \n", " fig6.update_xaxes(title_text=\"Pixels\", range=[1, num_pixels], zeroline=False, tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels]) \n", " fig6.update_yaxes(range=[1, num_pixels], showticklabels=False, showgrid=False, secondary_y=False)\n", - " fig6.update_yaxes(title_text=\"Angular cover (mrad)\", range=[1, num_pixels], showticklabels=True, tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels], ticktext = ['', np.round(detector_cover/4,1), np.round(detector_cover/2,1), np.round(3*detector_cover/4,1), np.round(detector_cover,1)], secondary_y=True) \n", - " \n", - " fig6.update_layout(width=3.5*graph_size, height=3*graph_size, margin = dict(l=0.35*graph_size, r=0.48*graph_size, t=0.3*graph_size, b=0))\n", + " fig6.update_yaxes(title_text=\"Angular cover (mrad)\", range=[1, num_pixels], showticklabels=True, tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels],\n", + " ticktext = ['', np.round(detector_cover/4,1), np.round(detector_cover/2,1), np.round(3*detector_cover/4,1), np.round(detector_cover,1)], secondary_y=True) \n", + " fig6.update_layout(width=3.35*graph_size, height=3*graph_size, margin = dict(l=0.35*graph_size, r=0.48*graph_size, t=0.3*graph_size, b=0))\n", "\n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " focusdepth = wavelength/(semi_angle_corr/1000)**2/1000\n", " ssb_cl, kolik = pty.cl4ssb(detector_cover_a_all)\n", + " \n", " ### MICROSCOPE SCHEME ##########################################\n", " width = 500 # in-graph setting\n", " det_width = 400 # in-graph setting\n", @@ -570,10 +536,7 @@ " fig8.add_annotation(x=-0.7*width, y=reduc*0.8*y_down, text=str(aperture), showarrow=False, yshift=-15)\n", " fig8.add_annotation(x=0.0*width, y=-y_down,text='Acquisition time (s) '+ str(np.round(matrix*matrix*dwell_time/1e6,1)), showarrow=False, yshift=-10)\n", " fig8.add_annotation(x=0, y=reduc*0.96*y_down,text='λ (pm) '+ str(np.round((pty.get_wavelength(beam)*1e12),2)), showarrow=False, yshift=0)\n", - " \n", - " \n", - " \n", - " \n", + "\n", " if defocus > 0:\n", " defo = np.log(defocus)/100\n", " else:\n", @@ -608,13 +571,14 @@ " # BF disk\n", " 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=\"#FF7F7F\", opacity=0.7,line=dict(color='#FF7F7F',width=1)))\n", " 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*width, y=-np.log(ssb_cl),text=\"\", showarrow=False,align= 'left', yshift=15)\n", + "\n", + " if method == 'direct':\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*width, y=-np.log(ssb_cl),text=\"\", 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=\"PAAR\", showarrow=False,align= 'left', yshift=15)\n", + " fig8.add_annotation(x=-0.35*width, y=-reduc*0.2*y_down,text=\"PAAR\", 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", @@ -639,12 +603,11 @@ " check3 = Valid(value= bool(beam_diameter/2 < probe_window/2), description='Beam ⌀ < window/2', **align_check) \n", " \n", "\n", - "\n", + " \n", " \n", " ### METHODS ########################################## \n", " if method == 'direct':\n", " \n", - " \n", " ### PROBE ##########################################\n", " fig = go.Figure() \n", " fig.update_yaxes(title_text=\"Contrast transfer func.\")\n", @@ -673,7 +636,6 @@ " # fig3.update_layout(title={'text': \"CTF\",'y':0.93, 'x':0.12,'xanchor': 'left','yanchor': 'top'})\n", " fig.update_layout(width=7.65*graph_size, height=2.25*graph_size, margin = dict(l=1.3*graph_size, r=0.3*graph_size, t=0.3*graph_size, b=0.3*graph_size))\n", " \n", - " \n", " ### CAMERA LENGTH GRAPH ##########################################\n", " fig4 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", " fig4.add_trace(go.Scatter(showlegend=False, x=opt.cameralengths(), y=detector_cover_all, marker_color='gray'), secondary_y=False,)\n", @@ -689,8 +651,6 @@ " fig4.update_layout(xaxis = dict(tickmode = 'array', tickvals = opt.cameralengths()))\n", " fig4.update_layout(width=8.0*graph_size, height=2.25*graph_size, margin =dict(l=1.3*graph_size, r=0.25*graph_size, t=0.3*graph_size, b=0.3*graph_size))\n", "\n", - " \n", - " \n", " ### SHOWING ###\n", " if chart == 'micr':\n", " left_column = VBox([go.FigureWidget(fig8)])\n", @@ -704,51 +664,46 @@ " right_column = VBox([go.FigureWidget(fig) ,HBox([go.FigureWidget(fig5),go.FigureWidget(fig6)]),go.FigureWidget(fig4)])\n", " left_column = VBox([go.FigureWidget(fig8)])\n", " total = HBox([left_column, right_column])\n", - " \n", - " \n", + " \n", " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px') \n", " display(total)\n", - " \n", "\n", - " \n", " \n", " if method == 'iterative': \n", - " \n", " ### PROBE ##########################################\n", - " fig = go.Figure() \n", - " fig.update_yaxes(title_text=\"Contrast transfer func.\")\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", + " fig = go.Figure() \n", + " fig.update_yaxes(title_text=\"Contrast transfer func.\")\n", + " match ctf_xaxis: \n", + " case 'α':\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", + " case '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", - " 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", + " case '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", + " 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", @@ -777,24 +732,21 @@ " fig7.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", opacity=0.9, fillcolor=color, x0=probe_window/2-beam_diameter/2, y0=probe_window/2-beam_diameter/2, x1=probe_window/2+beam_diameter/2, y1=probe_window/2+beam_diameter/2, line_color=color,)\n", " fig7.update_xaxes(title_text=\"Probe window (nm)\", range=[0, probe_window], tickvals = [0, np.round(probe_window/4,2), np.round(probe_window/2,2), np.round(3*probe_window/4,2), np.round(probe_window,2)-0.01])\n", " 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=3.2*graph_size, height=3.0*graph_size, margin =dict(l=0.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, b=0)) \n", + " fig7.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=1.0,xanchor=\"right\",x=1))\n", + " fig7.update_layout(title={'text': \"Probe\",'y':0.975, 'x':0.10,'xanchor': 'left','yanchor': 'top'})\n", + " fig7.update_layout(width=3.0*graph_size, height=3.0*graph_size, margin =dict(l=0.3*graph_size, r=0.3*graph_size, t=0.1*graph_size, 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=str(int(graph_size/100*62))+'px') , style = {'description_width': '0px','button_width': str(int(graph_size/100*40))+'px'}, disabled=True,)\n", + " align6 = dict(layout=Layout(width=str(int(graph_size/100*62))+'px') , style = {'description_width': '0px','button_width': str(int(graph_size/100*60))+'px'}, disabled=True,)\n", " align7 = dict(layout=Layout(width='140px') , style = {'description_width': '0px','button_width': \"120px\"}, 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", " data_tuple = tuple(tab[0:4,int(i)]) + (\"\",tab[4,int(i)])\n", - " \n", - " \n", " icons=['','','','','']\n", " \n", " if cl_check_nbf == True: \n", @@ -818,42 +770,30 @@ " button_style = 'danger' \n", " \n", " if cl == data[4]:\n", - " icons=['','','','','check']\n", - " \n", + " icons=['','','','','check'] \n", " \n", - " dictionary[i] = ToggleButtons(options=data_tuple, button_style=button_style, icons = icons, **align6)\n", - " \n", + " dictionary[i] = ToggleButtons(options=data_tuple, text_color= 'red', button_style=button_style, icons = icons, **align6)\n", + "\n", " legend = ToggleButtons(options=['Ptycho pixel (Å)','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", - " 'Dependent on: detector, binning, beam energy, camera length, zero defocus beam diameter, probe semi-angle',\n", - " 'Just nominal camera length',\n", - " ],button_style='', **align7) \n", - " \n", + " tooltips=['Dependent on: detector, beam energy, camera length', 'Dependent on: detector, camera length', 'Dependent on: detector, camera length, probe semi-angle', \n", + " 'Dependent on: detector, binning, beam energy, camera length, zero defocus beam diameter, probe semi-angle', 'Just nominal camera length'],button_style='', **align7) \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 110px', padding='10px 10px 10px 10px')\n", - " \n", - " \n", - " \n", - " \n", + "\n", " ### SHOWING ###\n", - " if chart == 'micr':\n", - " left_column = VBox([go.FigureWidget(fig8)])\n", - " total = HBox([left_column]) \n", - " \n", - " elif chart == 'dedic':\n", - " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", - " right_column = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", - " total = HBox([right_column])\n", - " \n", - " else: \n", - " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", - " right_column = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", - " left_column = VBox([go.FigureWidget(fig8)]) \n", - " total = HBox([left_column, right_column]) \n", + " match chart:\n", + " case 'micr':\n", + " total = VBox([go.FigureWidget(fig8)])\n", + " case 'dedic':\n", + " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", + " total = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", + " case _:\n", + " sample_overlap = HBox([go.FigureWidget(fig5), go.FigureWidget(fig7), go.FigureWidget(fig6)]) \n", + " right_column = VBox([HBox([go.FigureWidget(fig),checks]), sample_overlap, cltab]) \n", + " left_column = go.FigureWidget(fig8)\n", + " total = HBox([left_column, right_column]) \n", " \n", " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px') \n", " display(total)\n", @@ -862,9 +802,8 @@ " return \n", " \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,\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, \"graph_size\": graph_size,\"chart\": chart}) \n", - "\n" + " \"binning\": binning, \"dwell_time\": dwell_time, \"restriction\": restriction, \"method\": method, \"ctf_xaxis\": ctf_xaxis, \"cl_check_laa\":cl_check_laa, \"cl_check_pix\": cl_check_pix, \"cl_check_def\": cl_check_def,\n", + " \"cl_check_1bf\": cl_check_1bf, \"cl_check_nbf\": cl_check_nbf, \"graph_size\": graph_size,\"chart\": chart}) \n" ] }, { @@ -891,25 +830,25 @@ "\n", "### Start the interactive gui by running the field\n", "```python\n", - "display(HBox([controls, VBox([small_controls, gui]) ]))\n", + "display(HBox([controls, VBox([small_controls, gui])]))\n", "```" ] }, { "cell_type": "code", - "execution_count": 390, + "execution_count": 250, "id": "7937f054-fcd0-4e67-a20f-7696f5903a94", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "6f84c5e6c29142a9bb9db08cd48aefbd", + "model_id": "6190870561a34612bdef3eaa3834f402", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "HBox(children=(GridBox(children=(Button(description='STEM control panel', layout=Layout(grid_area='header', wi…" + "HBox(children=(GridBox(children=(Button(description='Electron beam settings', layout=Layout(grid_area='beam_se…" ] }, "metadata": {}, @@ -917,162 +856,7 @@ } ], "source": [ - "\n", - "display(HBox([controls, VBox([small_controls, gui]) ]))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b939697a-2ab0-49b2-8c73-555bb62a2e0d", - "metadata": {}, - "outputs": [], - "source": [ - "# import numpy as np\n", - "# print(\"Numpy version \", np.__version__)\n", - "# import scipy\n", - "# print(\"scipy version \", scipy.__version__)\n", - "# import plotly\n", - "# print(\"Plotly version \", plotly.__version__)\n", - "# import pandas\n", - "# print(\"Pandas version \", pandas.__version__)\n", - "# import IPython\n", - "# print(\"IPython version \", IPython.__version__)\n", - "# import ipywidgets\n", - "# print(\"Ipywidgets version \", ipywidgets.__version__)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "33727cb4-c3d7-4134-be89-f10b9922fbda", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 75, - "id": "1cb358ba-42c4-420a-a0a6-0de425e670a6", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Ipywidgets version 7.6.5\n" - ] - } - ], - "source": [ - "import ipywidgets\n", - "print(\"Ipywidgets version \", ipywidgets.__version__)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a52ff861-8243-4d39-b7da-1ee8fb0ee494", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "61970cec-8678-4edf-99f6-4f832d2aad8d", - "metadata": {}, - "outputs": [], - "source": [ - "https://ipywidgets.readthedocs.io/en/latest/user_install.html" - ] - }, - { - "cell_type": "code", - "execution_count": 386, - "id": "a4628def-4c43-456e-a93b-95952e2a3dea", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
    \n", - "
  • DescriptionStyle: BoundedFloatText, BoundedIntText, Checkbox, ColorPicker, Combobox, DatePicker, Dropdown, FloatText, HTML, HTMLMath, IntText, Label, Password, Play, RadioButtons, Select, SelectMultiple, SelectionRangeSlider, SelectionSlider, Text, Textarea, ToggleButton, Valid
  • \n", - "
  • ButtonStyle: Button, FileUpload
  • \n", - "
  • SliderStyle: FloatLogSlider, FloatRangeSlider, FloatSlider, IntRangeSlider, IntSlider
  • \n", - "
  • ProgressStyle: FloatProgress, IntProgress
  • \n", - "
  • ToggleButtonsStyle: ToggleButtons
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 386, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from collections import defaultdict\n", - "from IPython.display import HTML\n", - "import ipywidgets\n", - "from pprint import pprint\n", - "\n", - "reverse_lut = defaultdict(set)\n", - "styles = set()\n", - "for export_name in dir(ipywidgets.widgets):\n", - " export = getattr(ipywidgets.widgets, export_name)\n", - " try:\n", - " if issubclass(export, ipywidgets.Widget) and 'style' in export.class_trait_names():\n", - " reverse_lut[export.style.klass.__name__].add(export.__name__)\n", - " styles.add(export.style.klass)\n", - " except TypeError:\n", - " pass\n", - "\n", - "html = '
    '\n", - "for style, widgets in reverse_lut.items():\n", - " html = f\"{html}\\n
  • {style}: {', '.join(sorted(widgets))}
  • \"\n", - "html += \"
\"\n", - "HTML(html)" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "id": "54c1add7-f5ec-43f0-a447-e22dd03926a7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
AttributeToggleButtonsStyleButtonStyleDescriptionStyleProgressStyleSliderStyle
description_width
button_width
font_weight
bar_color
handle_color
button_color
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "attributes = defaultdict(set)\n", - "base_traits = set(ipywidgets.Style.class_trait_names())\n", - "\n", - "for s in styles:\n", - " for t in s.class_trait_names():\n", - " if not t.startswith(\"_\") and t not in base_traits:\n", - " attributes[s.__name__].add(t)\n", - "all_attributes = set().union(*attributes.values())\n", - "\n", - "html = '\\n'\n", - "html = f\"{html}{ ''.join(f'' for s in attributes.keys()) }\"\n", - "for a in all_attributes:\n", - " html = f\"\"\"{html}{ ''.join(f'' for attribs in attributes.values()) }\"\"\"\n", - "html += \"
Attribute{s}
{a}{\"✓\" if a in attribs else \"\"}
\"\n", - "HTML(html)" + "display(HBox([controls, VBox([small_controls, gui])]))" ] } ], @@ -1092,7 +876,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.5" }, "varInspector": { "cols": {