Skip to content

Commit

Permalink
Merge pull request #193 from pycroscopy/plotly-support
Browse files Browse the repository at this point in the history
update
  • Loading branch information
gduscher authored Jan 31, 2025
2 parents e5c8dad + b51f369 commit b8c1679
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,7 @@ example_data/sto.hf5
example_data/sto2.hf5
example_data/sto3.hf5
example_data/00_sto.hf5
example_data/00_sto-1.hf5
example_data/00_sto-2.hf5
example_data/00_sto-3.hf5
example_data/2-STEM SI.dm4
50 changes: 37 additions & 13 deletions notebooks/Spectroscopy/Analyse_EELSs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-25T17:48:41.105440Z",
Expand All @@ -174,9 +174,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n",
"pyTEM version: 0.2024.09.1\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",
"Using kinematic_scattering library version {_version_ } by G.Duscher\n",
"pyTEM version: 0.2025.01.0\n"
]
}
],
Expand Down Expand Up @@ -219,7 +221,35 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "561a0dbaa40b4b348fe5a2b267f1e8b3",
"model_id": "d511383382c64143831832038a6c540e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(Tab(children=(GridspecLayout(children=(Dropdown(description='directory:', layout=Layout(gr…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"if 'google.colab' in sys.modules:\n",
" drive.mount(\"/content/drive\")\n",
"import pyTEMlib.info_widget \n",
"# filename = '../../example_data/AL-DFoffset0.00.dm3'\n",
"infoWidget= pyTEMlib.info_widget3.EELSWidget()\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "802942432a224b15a984e401e278a074",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -233,7 +263,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8d2cc9a74af445f89a3bd1e6e15034b3",
"model_id": "a47212009ee04ef0a1262cc8945b8bf4",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -1558,13 +1588,7 @@
"output_type": "display_data"
}
],
"source": [
"if 'google.colab' in sys.modules:\n",
" drive.mount(\"/content/drive\")\n",
"import pyTEMlib.info_widget \n",
"# filename = '../../example_data/AL-DFoffset0.00.dm3'\n",
"infoWidget= pyTEMlib.info_widget3.EELSWidget()"
]
"source": []
},
{
"cell_type": "code",
Expand Down
45 changes: 21 additions & 24 deletions pyTEMlib/eels_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,36 +1153,32 @@ def find_all_edges(edge_onset: float, maximal_chemical_shift: float=5.0, major_e
else:
text += new_text

return text

return text

def find_associated_edges(dataset: sidpy.Dataset) -> None:
onsets = []
edges = []
if 'edges' in dataset.metadata:
for key, edge in dataset.metadata['edges'].items():
if 'core_loss' in dataset.metadata:
for key, edge in dataset.metadata['core_loss'].items():
if key.isdigit():
element = edge['element']
pre_edge = 0. # edge['onset']-edge['start_exclude']
post_edge = edge['end_exclude'] - edge['onset']

for sym in edge['all_edges']: # TODO: Could be replaced with exclude
onsets.append(edge['all_edges'][sym]['onset'] + edge['chemical_shift']-pre_edge)
edges.append([key, f"{element}-{sym}", onsets[-1]])
for key, peak in dataset.metadata['peak_fit']['peaks'].items():
if key.isdigit():
distance = dataset.get_spectral_dims(return_axis=True)[0].values[-1]
index = -1
for ii, onset in enumerate(onsets):
if onset < peak['position'] < onset+post_edge:
if distance > np.abs(peak['position'] - onset):
distance = np.abs(peak['position'] - onset) # TODO: check whether absolute is good
distance_onset = peak['position'] - onset
index = ii
if index >= 0:
peak['associated_edge'] = edges[index][1] # check if more info is necessary
peak['distance_to_onset'] = distance_onset

onsets.append(edge['all_edges'][sym]['onset'] + edge['chemical_shift'])
edges.append([key, f"{edge['element']}-{sym}", onsets[-1]])
dataset.metadata['core_loss'][key]['associated_peaks'] = {}
print(onsets)
print(edges)
if 'peak_fit' in dataset.metadata:
p = dataset.metadata['peak_fit']['peak_out_list']

for key, peak in enumerate(p):
distances = onsets-peak[0]
distances[distances < -0.3] = 1e6
if np.min(distances) < 50:
index = np.argmin(distances)
dataset.metadata['core_loss'][edges[np.argmin(distances)][0]]['associated_peaks'][key] = edges[np.argmin(distances)][1]
# check if more info is necessary
# peak['distance_to_onset'] = np.min(distances)
print(dataset.metadata['core_loss'])

def find_white_lines(dataset: sidpy.Dataset) -> None:
if 'edges' in dataset.metadata:
Expand Down Expand Up @@ -2034,6 +2030,7 @@ def gaussian_mixture_model(dataset, p_in=None):
spectrum = dataset.view.get_spectrum()
else:
spectrum = dataset[0,0]
spectrum.data_type == 'SPECTRUM'
else:
spectrum = dataset
spectrum.data_type == 'SPECTRUM'
Expand Down

0 comments on commit b8c1679

Please sign in to comment.