From 4878b181fdb68fe2f51cb2b400976af58627897b Mon Sep 17 00:00:00 2001 From: rskoupy Date: Fri, 8 Dec 2023 19:01:04 +0100 Subject: [PATCH] After ER meeting --- .../ptychoScopy-checkpoint.ipynb | 360 +++++++++++++----- calibrations.xlsx | Bin 33397 -> 33439 bytes ptychoScopy.ipynb | 360 +++++++++++++----- 3 files changed, 546 insertions(+), 174 deletions(-) diff --git a/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb b/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb index 268e78d..1456a12 100644 --- a/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb +++ b/.ipynb_checkpoints/ptychoScopy-checkpoint.ipynb @@ -2,19 +2,10 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 79, "id": "7425242d-3c91-4c1e-a424-08625a38ee7a", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\skoupy_r\\Anaconda3\\lib\\site-packages\\scipy\\__init__.py:155: UserWarning: A NumPy version >=1.18.5 and <1.25.0 is required for this version of SciPy (detected version 1.26.1\n", - " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n" - ] - } - ], + "outputs": [], "source": [ "### Initial packages import ###################################################\n", "import numpy as np\n", @@ -25,7 +16,7 @@ "from pandas import read_excel\n", "from IPython.display import display\n", "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\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", @@ -300,31 +291,37 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 389, "id": "8055b802-cf83-4250-aea9-54e3e6b73db0", "metadata": {}, "outputs": [], "source": [ "### CONTROLS ##########################################\n", "\n", - "ali = dict(style = {'description_width': '60px','button_width': '33px'}, button_style='',disabled=False)\n", - "ali2 = dict(style = {'description_width': '60px','button_width': '90px'}, button_style='',disabled=False)\n", - "header = Button(description='STEM control panel',layout=Layout(width='auto', grid_area='header'), style=ButtonStyle(button_color='silver'))\n", + "ali = dict(style = {'description_width': '60px','button_width': '35px', '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", - "beam_set = Button(description='Electron beam settings',layout=Layout(width='auto', grid_area='beam_set'), style=ButtonStyle(button_color='lightsteelblue')) \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", "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", "\n", - "scanning_set = Button(description='Scanning parameters',layout=Layout(width='auto', grid_area='scanning_set'),style=ButtonStyle(button_color='lightsteelblue'))\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", "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", "\n", "\n", "\n", - "camera_set = Button(description='Detection',layout=Layout(width='auto', grid_area='camera_set'),style=ButtonStyle(button_color='lightsteelblue'))\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", @@ -348,7 +345,7 @@ "footer = Button(description='Footer',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='silver'))\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,footer],\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", @@ -375,49 +372,56 @@ "\n", "# SMALL CONTROLS\n", "\n", - "descr = '50px'\n", - "butt = '30px'\n", + "descr = '80px'\n", + "butt = '60px'\n", "\n", - "header = Button(description='Graph controls',layout=Layout(width='auto', grid_area='header'),style=ButtonStyle(button_color='whitesmoke'))\n", + "header = Button(description='Graph controls',layout=Layout(width='auto', grid_area='header'),style=ButtonStyle(button_color='whitesmoke', font_weight= 'bold'))\n", "\n", - "method = ToggleButtons(options=[('SSB','direct'), ('Iter','iterative')], description='Method', tooltips=['SSB', 'PIE, MLc, DM'],\n", - " layout=Layout(width='auto', grid_area='methods'), style = {'description_width': descr,'button_width': butt}, button_style='',disabled=False,)\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", "\n", - "graph_size = ToggleButtons(options=[('XXS', 50),('XS', 70),('S', 90), ('M', 100), ('L', 120)], value=100, description='Graphs size',\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,'button_width': butt}, disabled=False,) # Low angle approximation check - scattering angle < 10 deg\n", - "cl_check_pix = Checkbox(value=True, description='Recon. pixel < step size',indent=False,\n", - " layout=Layout(width='auto', grid_area='check2'), style = {'description_width': descr,'button_width': butt}, disabled=False,) # Reconstructed pixel size < scanning step size \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,'button_width': butt}, disabled=False,) # Is probe window big enough to accomodate defocused probe?\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,'button_width': butt}, disabled=False,) # Detector cover is lower than 1 α\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,'button_width': butt}, disabled=False,) # Detector cover is higher than 6 α\n", + " layout=Layout(width='auto', grid_area='check5'), style = {'description_width': descr}, disabled=False,) # Detector cover is higher than 6 α\n", "\n", - "footer = Button(description='Interactive results',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='whitesmoke'))\n", "\n", - "small_controls = GridBox(children=[header, method, graph_size, ctf_xaxis, cl_check_laa,cl_check_pix,cl_check_def, cl_check_1bf, cl_check_nbf, footer],\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='40% 20% 20% 20%',\n", + " grid_template_columns='50% 20% 30%',\n", " grid_template_areas='''\n", - " \"header header header header \"\n", - " \"methods ctxaxis check1 check2\"\n", - " \"gr_size ctxaxis check3 check5\"\n", - " \". ctxaxis check4 . \" \n", - " \"footer footer footer footer\"\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", "\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):\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", " \n", " ### SINGLE SETTING PARAMETERS ###\n", " wavelength = pty.get_wavelength(beam)*1e12\n", @@ -464,59 +468,90 @@ " pctf = pty.get_ssb_ctf()\n", " 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.linspace(0,points-1,points) * step_size_corr\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=[0, points*step_size_corr], showgrid=False, zeroline=False)\n", - " fig5.update_yaxes(range=[0, points*step_size_corr],showgrid=False, showticklabels=False)\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", " for x in range(len(wid)):\n", " fig5.add_trace(go.Scatter(showlegend=False, x=wid, y=np.ones(len(wid))*wid[x], marker_color='blue'),secondary_y=False)\n", " for x in range(len(wid)): \n", " 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", - " fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='blue', name='Step '+str(np.round(10*step_size,3))+' Å ('+str(np.round(10*step_size_corr,3))+')'))\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.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", " fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=0.9))\n", - " fig5.add_trace(go.Scatter(showlegend=False, x = points*step_size_corr*np.ones(len(yyy)), y=yyy, opacity=1,mode='markers',marker_symbol = \"triangle-down\",marker=dict(size=20, color=yyy, colorscale='rainbow_r', showscale=False)),secondary_y=True) \n", - " fig5.update_yaxes(title_text=\"Overlap %\", range=[0, 100],showgrid=False, showticklabels=True, tickvals = [0, 20, 40,50, 60,70, 80, 90, 100], secondary_y=True)\n", - " fig5.update_layout(title={'text': \"Sample\",'y':0.95, 'x':0.30,'xanchor': 'left','yanchor': 'top'})\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", "\n", " \n", + "\n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " ### DETECTOR PLANE ##########################################\n", - " fig6 = go.Figure() \n", - " fig6.update_xaxes(title_text=\"Pixels\", range=[1, num_pixels], zeroline=False)\n", - " fig6.update_yaxes(range=[1, num_pixels], showticklabels=False,)\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_color=\"gray\")\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\"))\n", + " fig6 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", " \n", - " fig6.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", fillcolor=\"#FF7F7F\", x0=num_pixels/2-beam_diameter_pix/2, y0=num_pixels/2-beam_diameter_pix/2, x1=num_pixels/2+beam_diameter_pix/2, y1=num_pixels/2+beam_diameter_pix/2,line_color=\"#FF7F7F\")\n", - " fig6.add_annotation(x=num_pixels/2-beam_diameter_pix/2, y=num_pixels/2, ax=num_pixels/2+beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\n", - " fig6.add_annotation(x=num_pixels/2+beam_diameter_pix/2,y=num_pixels/2, ax=num_pixels/2-beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y', text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\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", + " \n", + " fig6.add_shape(type=\"circle\",xref=\"x\", yref=\"y\",opacity=0.5, fillcolor=\"#FF7F7F\", x0=num_pixels/2-beam_diameter_pix/2, y0=num_pixels/2-beam_diameter_pix/2, x1=num_pixels/2+beam_diameter_pix/2, y1=num_pixels/2+beam_diameter_pix/2,line_color=\"#FF7F7F\",secondary_y=False)\n", + " fig6.add_annotation(x=num_pixels/2-beam_diameter_pix/2, y=num_pixels/2, ax=num_pixels/2+beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", + " fig6.add_annotation(x=num_pixels/2+beam_diameter_pix/2,y=num_pixels/2, ax=num_pixels/2-beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y', text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig6.add_annotation(x=num_pixels/2, y=num_pixels/2, text=str(np.round(beam_diameter_pix,1))+\" pix\", showarrow=False, yshift=10)\n", - " fig6.add_trace(go.Scatter(x=[1,1.5,1,1.5], y=[1,1,1.5,1.5], name='Pix ∠ ' +str(np.round(pixel_angle,2))+' mrad'))\n", - " fig6.add_trace(go.Scatter(x=[1,1.5,1,1.5], y=[1,1,1.5,1.5], name='Pixel size ' +str(np.round(size_pixel,2))+' um'))\n", - " fig6.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.80,xanchor=\"right\",x=1))\n", - " fig6.update_layout(title={'text': \"Detector\",'y':0.95, 'x':0.11,'xanchor': 'left','yanchor': 'top'})\n", - " fig6.update_layout(xaxis = dict(tickmode = 'array', tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels])) \n", - " fig6.update_layout(width=3.5*graph_size, height=3*graph_size, margin = dict(l=0.35*graph_size, r=0.65*graph_size, t=0.3*graph_size, b=0))\n", + " 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", "\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", " ### MICROSCOPE SCHEME ##########################################\n", @@ -654,20 +689,27 @@ " 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", - " ### SHOWING ###\n", - " right_column = VBox([go.FigureWidget(fig),HBox([go.FigureWidget(fig5),go.FigureWidget(fig6)]),go.FigureWidget(fig4)])\n", - " left_column = VBox([go.FigureWidget(fig8)])\n", - " \n", - "\n", + " \n", " \n", + " ### SHOWING ###\n", + " if chart == 'micr':\n", + " left_column = VBox([go.FigureWidget(fig8)])\n", + " total = HBox([left_column]) \n", " \n", - " total = HBox([left_column, right_column])\n", - " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px')\n", - " \n", + " elif chart == 'dedic':\n", + " right_column = VBox([go.FigureWidget(fig) ,HBox([go.FigureWidget(fig5),go.FigureWidget(fig6)]),go.FigureWidget(fig4)])\n", + " total = HBox([right_column])\n", + " \n", + " else: \n", + " 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", + " 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", + "\n", " \n", " \n", " if method == 'iterative': \n", @@ -781,7 +823,7 @@ " \n", " dictionary[i] = ToggleButtons(options=data_tuple, button_style=button_style, icons = icons, **align6)\n", " \n", - " legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. def. (nm)','Selected by CL ','Nominal CL (cm)',], \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", @@ -796,22 +838,32 @@ " \n", " \n", " \n", + " \n", " ### SHOWING ###\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", - " \n", - " \n", - " total = HBox([left_column, right_column])\n", - " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px')\n", - " \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", + " \n", + " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px') \n", " display(total)\n", + "\n", " \n", " 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}) \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" ] }, @@ -845,14 +897,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 390, "id": "7937f054-fcd0-4e67-a20f-7696f5903a94", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "47642ef0d8b94bceb11f878293997c33", + "model_id": "6f84c5e6c29142a9bb9db08cd48aefbd", "version_major": 2, "version_minor": 0 }, @@ -865,6 +917,7 @@ } ], "source": [ + "\n", "display(HBox([controls, VBox([small_controls, gui]) ]))" ] }, @@ -888,6 +941,139 @@ "# 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)" + ] } ], "metadata": { diff --git a/calibrations.xlsx b/calibrations.xlsx index db7ef42ab14f7cbabd0732d0dc783a0672c62a0d..10025df9cb36bf46f1519252a505c2f808e5d39a 100644 GIT binary patch delta 4376 zcmZWscQ~BQ7GJ%F=yjD4L``&}6KxYBdKcltCwlbq>OI;UQNofS1ZzdNI#Hv1h`M@B zq7xRYTsQZ*-@VVh=b!n_oH}RbnK|b;5;rdjw-QSTIB!5=D)1nXa1scF5(0tvy%h0v z^K`a#b8{B``VgKtmlWaQYYzm_wOQ2>l#iwAScT_Ot+%X zS!#GpOl4a7E_(Sp)5pfy`+gV96m=G3vG{_eqG<`yksvKuiZxFSpLv}iDq6TJ$dbxIBP8`(nk>iO z$Vp8ay6ed;KQ`hwOsCDbllY0l!`l1#faF>OMDL)K(Lg-Pa$FgzI!%$;;aS^d9si_;dQ`bq>VRHJ!zA9TZ(&NAP-Z>wi#XX8tsEjk$-@ zJ?9)OMP(6oP1(Wdc}>u!d^dmL;0nlBP%72ilt^xfu>wwcJX2Zj44sTBRp&f6-jbc=v9H}-Jk@K=0<_z1fU`x|%k-j?Z zJ}%vov&6-tkphR$0!w4at9bz`JAs~}5~TYpK07+o=sjk6m{?~L!gL<~$s3XM=@z1$ z+(nAKQ+Y@9?ELU5na3*61{o}(oldf0+v8CaUH{{aAW=i)3q4~MqLyM?A|GFyS4tlw zRJevzW_5);(+eSLw zcDQ~4PaO5#WhNyj%-_vj;(-r*XsgFa8EHvgUTz%SB7;EaL1lhs@D@7}fKEbl+>YK8 zIED)DLW2f7;;Xf*U!$Z9YvnCzf}4rN?*P2&bnx|0_HLL)F!>N@mljLS~@oUT`QMOXUgw#T_6^rk&|x=Jt_qF zYMXJow>5qLT6v6kZA%dY`~h=u2sP~Dx$8vz=tXI!V}I7u%s@s|1wo9)P#^)~p(?rN z#(e-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)tDN&2NNGPDax!SbzJgsZpmE?q@$cZp;%S z-Fz-5-=)<%+^27a!mh_xFg>>y14X_{LIo^yw7Ugbip`qRnt zUGlGdh3B~wihj*|;;g_Ha(3`Onz4G$|1mku|9=92#wa-H7cdW{NhZPoHY>A(q(SVw z|2!s0NVv}KB>%K2P&P=K@1J|;f5xSxev8BgLCK(3f5V|Oh*UmIaK}0>MzyO7L#5 qF`1X^?~bms4n^=FSoqK40EN)(q&%P^TA4Hx^g#=sOAY+H?*9R&a9U^p diff --git a/ptychoScopy.ipynb b/ptychoScopy.ipynb index 268e78d..1456a12 100644 --- a/ptychoScopy.ipynb +++ b/ptychoScopy.ipynb @@ -2,19 +2,10 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 79, "id": "7425242d-3c91-4c1e-a424-08625a38ee7a", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\skoupy_r\\Anaconda3\\lib\\site-packages\\scipy\\__init__.py:155: UserWarning: A NumPy version >=1.18.5 and <1.25.0 is required for this version of SciPy (detected version 1.26.1\n", - " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n" - ] - } - ], + "outputs": [], "source": [ "### Initial packages import ###################################################\n", "import numpy as np\n", @@ -25,7 +16,7 @@ "from pandas import read_excel\n", "from IPython.display import display\n", "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\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", @@ -300,31 +291,37 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 389, "id": "8055b802-cf83-4250-aea9-54e3e6b73db0", "metadata": {}, "outputs": [], "source": [ "### CONTROLS ##########################################\n", "\n", - "ali = dict(style = {'description_width': '60px','button_width': '33px'}, button_style='',disabled=False)\n", - "ali2 = dict(style = {'description_width': '60px','button_width': '90px'}, button_style='',disabled=False)\n", - "header = Button(description='STEM control panel',layout=Layout(width='auto', grid_area='header'), style=ButtonStyle(button_color='silver'))\n", + "ali = dict(style = {'description_width': '60px','button_width': '35px', '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", - "beam_set = Button(description='Electron beam settings',layout=Layout(width='auto', grid_area='beam_set'), style=ButtonStyle(button_color='lightsteelblue')) \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", "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", "\n", - "scanning_set = Button(description='Scanning parameters',layout=Layout(width='auto', grid_area='scanning_set'),style=ButtonStyle(button_color='lightsteelblue'))\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", "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", "\n", "\n", "\n", - "camera_set = Button(description='Detection',layout=Layout(width='auto', grid_area='camera_set'),style=ButtonStyle(button_color='lightsteelblue'))\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", @@ -348,7 +345,7 @@ "footer = Button(description='Footer',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='silver'))\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,footer],\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", @@ -375,49 +372,56 @@ "\n", "# SMALL CONTROLS\n", "\n", - "descr = '50px'\n", - "butt = '30px'\n", + "descr = '80px'\n", + "butt = '60px'\n", "\n", - "header = Button(description='Graph controls',layout=Layout(width='auto', grid_area='header'),style=ButtonStyle(button_color='whitesmoke'))\n", + "header = Button(description='Graph controls',layout=Layout(width='auto', grid_area='header'),style=ButtonStyle(button_color='whitesmoke', font_weight= 'bold'))\n", "\n", - "method = ToggleButtons(options=[('SSB','direct'), ('Iter','iterative')], description='Method', tooltips=['SSB', 'PIE, MLc, DM'],\n", - " layout=Layout(width='auto', grid_area='methods'), style = {'description_width': descr,'button_width': butt}, button_style='',disabled=False,)\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", "\n", - "graph_size = ToggleButtons(options=[('XXS', 50),('XS', 70),('S', 90), ('M', 100), ('L', 120)], value=100, description='Graphs size',\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,'button_width': butt}, disabled=False,) # Low angle approximation check - scattering angle < 10 deg\n", - "cl_check_pix = Checkbox(value=True, description='Recon. pixel < step size',indent=False,\n", - " layout=Layout(width='auto', grid_area='check2'), style = {'description_width': descr,'button_width': butt}, disabled=False,) # Reconstructed pixel size < scanning step size \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,'button_width': butt}, disabled=False,) # Is probe window big enough to accomodate defocused probe?\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,'button_width': butt}, disabled=False,) # Detector cover is lower than 1 α\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,'button_width': butt}, disabled=False,) # Detector cover is higher than 6 α\n", + " layout=Layout(width='auto', grid_area='check5'), style = {'description_width': descr}, disabled=False,) # Detector cover is higher than 6 α\n", "\n", - "footer = Button(description='Interactive results',layout=Layout(width='auto', grid_area='footer'),style=ButtonStyle(button_color='whitesmoke'))\n", "\n", - "small_controls = GridBox(children=[header, method, graph_size, ctf_xaxis, cl_check_laa,cl_check_pix,cl_check_def, cl_check_1bf, cl_check_nbf, footer],\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='40% 20% 20% 20%',\n", + " grid_template_columns='50% 20% 30%',\n", " grid_template_areas='''\n", - " \"header header header header \"\n", - " \"methods ctxaxis check1 check2\"\n", - " \"gr_size ctxaxis check3 check5\"\n", - " \". ctxaxis check4 . \" \n", - " \"footer footer footer footer\"\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", "\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):\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", " \n", " ### SINGLE SETTING PARAMETERS ###\n", " wavelength = pty.get_wavelength(beam)*1e12\n", @@ -464,59 +468,90 @@ " pctf = pty.get_ssb_ctf()\n", " 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.linspace(0,points-1,points) * step_size_corr\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=[0, points*step_size_corr], showgrid=False, zeroline=False)\n", - " fig5.update_yaxes(range=[0, points*step_size_corr],showgrid=False, showticklabels=False)\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", " for x in range(len(wid)):\n", " fig5.add_trace(go.Scatter(showlegend=False, x=wid, y=np.ones(len(wid))*wid[x], marker_color='blue'),secondary_y=False)\n", " for x in range(len(wid)): \n", " 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", - " fig5.add_trace(go.Scatter(showlegend=True, x=[-1], y=[-1],marker_size=12, marker_color='blue', name='Step '+str(np.round(10*step_size,3))+' Å ('+str(np.round(10*step_size_corr,3))+')'))\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.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", " fig5.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.85,xanchor=\"right\",x=0.9))\n", - " fig5.add_trace(go.Scatter(showlegend=False, x = points*step_size_corr*np.ones(len(yyy)), y=yyy, opacity=1,mode='markers',marker_symbol = \"triangle-down\",marker=dict(size=20, color=yyy, colorscale='rainbow_r', showscale=False)),secondary_y=True) \n", - " fig5.update_yaxes(title_text=\"Overlap %\", range=[0, 100],showgrid=False, showticklabels=True, tickvals = [0, 20, 40,50, 60,70, 80, 90, 100], secondary_y=True)\n", - " fig5.update_layout(title={'text': \"Sample\",'y':0.95, 'x':0.30,'xanchor': 'left','yanchor': 'top'})\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", "\n", " \n", + "\n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " ### DETECTOR PLANE ##########################################\n", - " fig6 = go.Figure() \n", - " fig6.update_xaxes(title_text=\"Pixels\", range=[1, num_pixels], zeroline=False)\n", - " fig6.update_yaxes(range=[1, num_pixels], showticklabels=False,)\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_color=\"gray\")\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\"))\n", + " fig6 = make_subplots(specs=[[{\"secondary_y\": True}]])\n", " \n", - " fig6.add_shape(type=\"circle\",xref=\"x\", yref=\"y\", fillcolor=\"#FF7F7F\", x0=num_pixels/2-beam_diameter_pix/2, y0=num_pixels/2-beam_diameter_pix/2, x1=num_pixels/2+beam_diameter_pix/2, y1=num_pixels/2+beam_diameter_pix/2,line_color=\"#FF7F7F\")\n", - " fig6.add_annotation(x=num_pixels/2-beam_diameter_pix/2, y=num_pixels/2, ax=num_pixels/2+beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\n", - " fig6.add_annotation(x=num_pixels/2+beam_diameter_pix/2,y=num_pixels/2, ax=num_pixels/2-beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y', text='', showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=1,arrowcolor='black')\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", + " \n", + " fig6.add_shape(type=\"circle\",xref=\"x\", yref=\"y\",opacity=0.5, fillcolor=\"#FF7F7F\", x0=num_pixels/2-beam_diameter_pix/2, y0=num_pixels/2-beam_diameter_pix/2, x1=num_pixels/2+beam_diameter_pix/2, y1=num_pixels/2+beam_diameter_pix/2,line_color=\"#FF7F7F\",secondary_y=False)\n", + " fig6.add_annotation(x=num_pixels/2-beam_diameter_pix/2, y=num_pixels/2, ax=num_pixels/2+beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y',text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", + " fig6.add_annotation(x=num_pixels/2+beam_diameter_pix/2,y=num_pixels/2, ax=num_pixels/2-beam_diameter_pix/2, ay=num_pixels/2, xref='x',yref='y',axref='x',ayref='y', text='', showarrow=True,arrowhead=2,arrowsize=2,arrowwidth=1,arrowcolor='black')\n", " fig6.add_annotation(x=num_pixels/2, y=num_pixels/2, text=str(np.round(beam_diameter_pix,1))+\" pix\", showarrow=False, yshift=10)\n", - " fig6.add_trace(go.Scatter(x=[1,1.5,1,1.5], y=[1,1,1.5,1.5], name='Pix ∠ ' +str(np.round(pixel_angle,2))+' mrad'))\n", - " fig6.add_trace(go.Scatter(x=[1,1.5,1,1.5], y=[1,1,1.5,1.5], name='Pixel size ' +str(np.round(size_pixel,2))+' um'))\n", - " fig6.update_layout(legend=dict(orientation=\"v\",yanchor=\"bottom\",y=0.80,xanchor=\"right\",x=1))\n", - " fig6.update_layout(title={'text': \"Detector\",'y':0.95, 'x':0.11,'xanchor': 'left','yanchor': 'top'})\n", - " fig6.update_layout(xaxis = dict(tickmode = 'array', tickvals = [1, num_pixels/4, num_pixels/2, 3*num_pixels/4, num_pixels])) \n", - " fig6.update_layout(width=3.5*graph_size, height=3*graph_size, margin = dict(l=0.35*graph_size, r=0.65*graph_size, t=0.3*graph_size, b=0))\n", + " 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", "\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", " ### MICROSCOPE SCHEME ##########################################\n", @@ -654,20 +689,27 @@ " 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", - " ### SHOWING ###\n", - " right_column = VBox([go.FigureWidget(fig),HBox([go.FigureWidget(fig5),go.FigureWidget(fig6)]),go.FigureWidget(fig4)])\n", - " left_column = VBox([go.FigureWidget(fig8)])\n", - " \n", - "\n", + " \n", " \n", + " ### SHOWING ###\n", + " if chart == 'micr':\n", + " left_column = VBox([go.FigureWidget(fig8)])\n", + " total = HBox([left_column]) \n", " \n", - " total = HBox([left_column, right_column])\n", - " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px')\n", - " \n", + " elif chart == 'dedic':\n", + " right_column = VBox([go.FigureWidget(fig) ,HBox([go.FigureWidget(fig5),go.FigureWidget(fig6)]),go.FigureWidget(fig4)])\n", + " total = HBox([right_column])\n", + " \n", + " else: \n", + " 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", + " 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", + "\n", " \n", " \n", " if method == 'iterative': \n", @@ -781,7 +823,7 @@ " \n", " dictionary[i] = ToggleButtons(options=data_tuple, button_style=button_style, icons = icons, **align6)\n", " \n", - " legend = ToggleButtons(options=['Ptycho pix. (Å)','Det. cover (mrad)','Det. cover (α)', 'Max. def. (nm)','Selected by CL ','Nominal CL (cm)',], \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", @@ -796,22 +838,32 @@ " \n", " \n", " \n", + " \n", " ### SHOWING ###\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", - " \n", - " \n", - " total = HBox([left_column, right_column])\n", - " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px')\n", - " \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", + " \n", + " total.layout = Layout(border='solid 0px gray',margin='10px 10px 10px 40px', padding='10px 10px 10px 10px') \n", " display(total)\n", + "\n", " \n", " 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}) \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" ] }, @@ -845,14 +897,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 390, "id": "7937f054-fcd0-4e67-a20f-7696f5903a94", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "47642ef0d8b94bceb11f878293997c33", + "model_id": "6f84c5e6c29142a9bb9db08cd48aefbd", "version_major": 2, "version_minor": 0 }, @@ -865,6 +917,7 @@ } ], "source": [ + "\n", "display(HBox([controls, VBox([small_controls, gui]) ]))" ] }, @@ -888,6 +941,139 @@ "# 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)" + ] } ], "metadata": {