Skip to content

Commit

Permalink
Merge pull request #130 from pycroscopy/use_dict_2
Browse files Browse the repository at this point in the history
Use dict 2
  • Loading branch information
gduscher authored Aug 11, 2023
2 parents b01f207 + 47da56f commit 14ed8eb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ example_data/EELS_STO2.dm3
notebooks/EELS/1-s2.0-S0925838823027585-main.pdf
notebooks/EELS/Analyse_Low_Loss2.ipynb
notebooks/EELS/Analysis_Core_Loss (1).ipynb
server_user_id.txt
44 changes: 26 additions & 18 deletions notebooks/EELS/Analysis_Core_Loss.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {
"hideCode": true,
"hidePrompt": false
Expand All @@ -124,12 +124,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"You don't have igor installed. If you wish to open igor files, you will need to install it (pip install igor) before attempting.\n",
"You don't have igor2 installed. If you wish to open igor files, you will need to install it (pip install igor2) before attempting.\n",
"You don't have gwyfile installed. If you wish to open .gwy files, you will need to install it (pip install gwyfile) before attempting.\n",
"Symmetry functions of spglib enabled\n",
"SimpleITK not installed; Registration Functions for Image Stacks not available\n",
"install with: conda install -c simpleitk simpleitk \n",
"pyTEMlib version: 0.2023.5.1\n"
"pyTEMlib version: 0.2023.8.0\n"
]
}
],
Expand All @@ -143,8 +143,14 @@
" from google.colab import output\n",
" output.enable_custom_widget_manager()\n",
" from google.colab import drive\n",
"else:\n",
" %gui qt5\n",
"\n",
"import sys\n",
"sys.path.insert(0, '../../../')\n",
"\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"\n",
"import pyTEMlib\n",
"import pyTEMlib.file_tools as ft # File input/ output library\n",
Expand Down Expand Up @@ -182,22 +188,24 @@
},
{
"cell_type": "code",
"execution_count": 141,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1824cedc141e47e0b21a232e23b6501a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Dropdown(description='directory:', layout=Layout(width='90%'), options=('C:\\\\Users\\\\gduscher\\\\D…"
]
},
"metadata": {},
"output_type": "display_data"
"ename": "NotImplementedError",
"evalue": "Cannot ",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNotImplementedError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[2], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m datasets \u001b[39m=\u001b[39m ft\u001b[39m.\u001b[39mopen_file(\u001b[39m'\u001b[39m\u001b[39m../../example_data/EELS_STO3.hf5\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m 6\u001b[0m \u001b[39melse\u001b[39;00m: \n\u001b[1;32m----> 7\u001b[0m fileWidget \u001b[39m=\u001b[39m ft\u001b[39m.\u001b[39;49mFileWidget()\n",
"File \u001b[1;32mc:\\Users\\gduscher\\Documents\\Github\\pyTEMlib\\notebooks\\EELS\\../..\\pyTEMlib\\file_tools.py:107\u001b[0m, in \u001b[0;36mFileWidget.__init__\u001b[1;34m(self, dir_name, extension)\u001b[0m\n\u001b[0;32m 98\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdatasets \u001b[39m=\u001b[39m{}\n\u001b[0;32m 99\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdataset \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[0;32m 101\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mselect_files \u001b[39m=\u001b[39m widgets\u001b[39m.\u001b[39mSelect(\n\u001b[0;32m 102\u001b[0m options\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdir_list,\n\u001b[0;32m 103\u001b[0m value\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdir_list[\u001b[39m0\u001b[39m],\n\u001b[0;32m 104\u001b[0m description\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mSelect file:\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[0;32m 105\u001b[0m disabled\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m,\n\u001b[0;32m 106\u001b[0m rows\u001b[39m=\u001b[39m\u001b[39m10\u001b[39m,\n\u001b[1;32m--> 107\u001b[0m layout\u001b[39m=\u001b[39mwidgets\u001b[39m.\u001b[39;49mLayout(width\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m70\u001b[39;49m\u001b[39m%\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[0;32m 108\u001b[0m )\n\u001b[0;32m 110\u001b[0m select_button \u001b[39m=\u001b[39m widgets\u001b[39m.\u001b[39mButton(description\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mSelect Main\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[0;32m 111\u001b[0m layout\u001b[39m=\u001b[39mwidgets\u001b[39m.\u001b[39mLayout(width\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mauto\u001b[39m\u001b[39m'\u001b[39m, grid_area\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mheader\u001b[39m\u001b[39m'\u001b[39m),\n\u001b[0;32m 112\u001b[0m style\u001b[39m=\u001b[39mwidgets\u001b[39m.\u001b[39mButtonStyle(button_color\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mlightblue\u001b[39m\u001b[39m'\u001b[39m))\n\u001b[0;32m 114\u001b[0m add_button \u001b[39m=\u001b[39m widgets\u001b[39m.\u001b[39mButton(description\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mAdd\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[0;32m 115\u001b[0m layout\u001b[39m=\u001b[39mwidgets\u001b[39m.\u001b[39mLayout(width\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mauto\u001b[39m\u001b[39m'\u001b[39m, grid_area\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mheader\u001b[39m\u001b[39m'\u001b[39m),\n\u001b[0;32m 116\u001b[0m style\u001b[39m=\u001b[39mwidgets\u001b[39m.\u001b[39mButtonStyle(button_color\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mlightblue\u001b[39m\u001b[39m'\u001b[39m))\n",
"File \u001b[1;32mc:\\Users\\gduscher\\AppData\\Local\\anaconda3\\lib\\site-packages\\ipywidgets\\widgets\\widget_layout.py:86\u001b[0m, in \u001b[0;36mLayout.__init__\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 83\u001b[0m \u001b[39mfor\u001b[39;00m side \u001b[39min\u001b[39;00m [\u001b[39m'\u001b[39m\u001b[39mtop\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mright\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mbottom\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mleft\u001b[39m\u001b[39m'\u001b[39m]:\n\u001b[0;32m 84\u001b[0m kwargs\u001b[39m.\u001b[39msetdefault(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mborder_\u001b[39m\u001b[39m{\u001b[39;00mside\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m, border)\n\u001b[1;32m---> 86\u001b[0m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39m\u001b[39m__init__\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
"File \u001b[1;32mc:\\Users\\gduscher\\AppData\\Local\\anaconda3\\lib\\site-packages\\ipywidgets\\widgets\\widget.py:504\u001b[0m, in \u001b[0;36mWidget.__init__\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 501\u001b[0m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39m\u001b[39m__init__\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 503\u001b[0m Widget\u001b[39m.\u001b[39m_call_widget_constructed(\u001b[39mself\u001b[39m)\n\u001b[1;32m--> 504\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mopen()\n",
"File \u001b[1;32mc:\\Users\\gduscher\\AppData\\Local\\anaconda3\\lib\\site-packages\\ipywidgets\\widgets\\widget.py:535\u001b[0m, in \u001b[0;36mWidget.open\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 531\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mipykernel\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcomm\u001b[39;00m \u001b[39mimport\u001b[39;00m Comm\n\u001b[0;32m 533\u001b[0m \u001b[39mreturn\u001b[39;00m Comm(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[1;32m--> 535\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcomm \u001b[39m=\u001b[39m create_comm(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39margs)\n",
"File \u001b[1;32mc:\\Users\\gduscher\\AppData\\Local\\anaconda3\\lib\\site-packages\\comm\\__init__.py:27\u001b[0m, in \u001b[0;36m_create_comm\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 22\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_create_comm\u001b[39m(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[0;32m 23\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Create a Comm.\u001b[39;00m\n\u001b[0;32m 24\u001b[0m \n\u001b[0;32m 25\u001b[0m \u001b[39m This method is intended to be replaced, so that it returns your Comm instance.\u001b[39;00m\n\u001b[0;32m 26\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 27\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mNotImplementedError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mCannot \u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[1;31mNotImplementedError\u001b[0m: Cannot "
]
}
],
"source": [
Expand Down
43 changes: 22 additions & 21 deletions pyTEMlib/info_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,24 @@ def get_sidebar():
style=ipywidgets.ButtonStyle(button_color='lightblue'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=7.5,description='Offset:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='20px'))
side_bar[row, 2] = ipywidgets.Label(value="eV", layout=ipywidgets.Layout(width='20px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Dispersion:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='20px'))
side_bar[row, 2] = ipywidgets.Label(value="eV", layout=ipywidgets.Layout(width='20px'))

row += 1
side_bar[row, :3] = ipywidgets.Button(description='Microscope',
layout=ipywidgets.Layout(width='auto', grid_area='header'),
style=ipywidgets.ButtonStyle(button_color='lightblue'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=7.5,description='Conv.Angle:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
side_bar[row, 2] = ipywidgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Coll.Angle:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
side_bar[row, 2] = ipywidgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Acc Voltage:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="keV", layout=ipywidgets.Layout(width='100px'))
side_bar[row, 2] = ipywidgets.Label(value="keV", layout=ipywidgets.Layout(width='100px'))
row += 1

side_bar[row, :3] = ipywidgets.Button(description='Quantification',
Expand All @@ -382,16 +382,16 @@ def get_sidebar():
layout=ipywidgets.Layout(width='100px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Exp_Time:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="s", layout=ipywidgets.Layout(width='100px'))
side_bar[row, 2] = ipywidgets.Label(value="s", layout=ipywidgets.Layout(width='100px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=7.5,description='Flux:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="Mcounts", layout=ipywidgets.Layout(width='100px'))
side_bar[row, 2] = ipywidgets.Label(value="Mcounts", layout=ipywidgets.Layout(width='100px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Conversion:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value=r"e$^-$/counts", layout=ipywidgets.Layout(width='100px'))
side_bar[row, 2] = ipywidgets.Label(value=r"e$^-$/counts", layout=ipywidgets.Layout(width='100px'))
row += 1
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Current:', disabled=False, color='black', layout=ipywidgets.Layout(width='200px'))
side_bar[row, 2] = ipywidgets.widgets.Label(value="pA", layout=ipywidgets.Layout(width='100px') )
side_bar[row, 2] = ipywidgets.Label(value="pA", layout=ipywidgets.Layout(width='100px') )

row += 1

Expand Down Expand Up @@ -430,13 +430,13 @@ def __init__(self, dset, spectrum_number=0, figure=None, **kwargs):
interactive=True,
props=dict(facecolor='blue', alpha=0.2))
#self.axis.legend()
display(self.panel)
#display(self.panel)

def line_select_callback(self, x_min, x_max):
self.start_cursor.value = np.round(x_min, 3)
self.end_cursor.value = np.round(x_max, 3)
self.start_channel = np.searchsorted(self.datasets[self.key].energy_loss, self.start_cursor.value)
self.end_channel = np.searchsorted(self.datasets[self.key].energy_loss, self.end_cursor.value)
self.start_channel = np.searchsorted(self.dset.energy_loss, self.start_cursor.value)
self.end_channel = np.searchsorted(self.dset.energy_loss, self.end_cursor.value)


class SIPlot(sidpy.viz.dataset_viz.SpectralImageVisualizer):
Expand Down Expand Up @@ -466,8 +466,8 @@ def __init__(self, dset, figure=None, horizontal=True, **kwargs):
def line_select_callback(self, x_min, x_max):
self.start_cursor.value = np.round(x_min, 3)
self.end_cursor.value = np.round(x_max, 3)
self.start_channel = np.searchsorted(self.datasets[self.key].energy_loss, self.start_cursor.value)
self.end_channel = np.searchsorted(self.datasets[self.key].energy_loss, self.end_cursor.value)
self.start_channel = np.searchsorted(self.dset.energy_loss, self.start_cursor.value)
self.end_channel = np.searchsorted(self.dset.energy_loss, self.end_cursor.value)

def _update(self, ev=None):

Expand Down Expand Up @@ -519,10 +519,10 @@ def __init__(self, datasets=None):
def get_spectrum(self):
if self.dataset.data_type == sidpy.DataType.SPECTRAL_IMAGE:
spectrum = self.dataset.view.get_spectrum()
self.axis = self.dataset.view.axes[1]
self.axis = self.view.axes[1]
else:
spectrum = np.array(self.dataset)
self.axis = self.dataset.view.axis
self.axis = self.view.axis

spectrum *= self.y_scale
return spectrum
Expand Down Expand Up @@ -591,19 +591,20 @@ def set_dataset(self, index=0):
if 'beam_current' not in self.datasets[self.key].metadata['experiment']:
self.datasets[self.key].metadata['experiment']['beam_current'] = 0
self.sidebar[13,0].value = self.datasets[self.key].metadata['experiment']['beam_current']

self.view = SIPlot(self.dataset)

if self.dataset.data_type =='SPECTRAL_IMAGE':
self.view = SIPlot(self.dataset)
else:
self.view = SpectrumPlot(self.dataset)
self.y_scale = 1.0
self.change_y_scale = 1.0


def cursor2energy_scale(self, value):

dispersion = (self.end_cursor.value - self.start_cursor.value) / (self.end_channel - self.start_channel)
dispersion = (self.view.end_cursor.value - self.view.start_cursor.value) / (self.view.end_channel - self.view.start_channel)
self.datasets[self.key].energy_loss *= (self.sidebar[3, 0].value/dispersion)
self.sidebar[3, 0].value = dispersion
offset = self.start_cursor.value - self.start_channel * dispersion
offset = self.view.start_cursor.value - self.view.start_channel * dispersion
self.datasets[self.key].energy_loss += (self.sidebar[2, 0].value-self.datasets[self.key].energy_loss[0])
self.sidebar[2, 0].value = offset
self.plot()
Expand Down
2 changes: 1 addition & 1 deletion pyTEMlib/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
version
"""
_version = '0.2023.8.0'
_version = '0.2023.8.1'
__version__ = _version
_time = '2023-08-09 19:58:26'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
author_email="[email protected]",

install_requires=['scipy', 'numpy', 'pillow', 'ase', 'tqdm', 'plotly', 'pandas', 'requests', 'lxml', 'ipympl',
'spglib', 'scikit-image', 'scikit-learn', 'pyNSID>=0.0.7', 'sidpy>=0.11.2', 'SciFiReaders>=0.0.8'], # 'PyQt5> 1.0'],#
'spglib', 'scikit-image', 'scikit-learn', 'pyNSID>=0.0.7', 'sidpy>=0.12.1', 'SciFiReaders>=0.0.8'], # 'PyQt5> 1.0'],#
setup_requires=['pytest-runner'],
tests_require=['pytest'],
platforms=['Linux', 'Mac OSX', 'Windows 11/10'],
Expand Down

0 comments on commit 14ed8eb

Please sign in to comment.