Skip to content

Commit

Permalink
Merge pull request #187 from pycroscopy/use_dict3
Browse files Browse the repository at this point in the history
Use dict3
  • Loading branch information
gduscher authored Dec 17, 2024
2 parents e764247 + ae1f98e commit 6d36f87
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
34 changes: 17 additions & 17 deletions notebooks/Spectroscopy/Analyse_Low_Loss.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-25T17:48:50.060660Z",
Expand All @@ -206,7 +206,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "24d5e4408b284b4b8f51f8bcbdf62af4",
"model_id": "71ad1392b8164a899ff8186c459d546d",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -228,37 +228,37 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"\n",
"infoWidget._update()\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
"21"
]
},
"execution_count": 47,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"#infoWidget.datasets['_dif'] = infoWidget.spectrum\n",
"\n",
"infoWidget.x"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -8018,7 +8018,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.8"
},
"toc": {
"base_numbering": "3",
Expand Down
14 changes: 10 additions & 4 deletions pyTEMlib/info_widget3.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,12 @@ def plot_spectrum(self):
for key in self.added_spectra:
self.added_spectra[key]
spectrum = self.get_additional_spectrum(key)

self.spectrum_plot.add_trace(go.Scatter(x=self.energy_scale, y=spectrum, mode='markers+lines', marker_size=.1, name=self.added_spectra[key]))

if key == 'zero_loss':
self.low_loss.low_loss_tab[14, 1].value = np.round(np.log(self.spectrum.sum()/spectrum.sum()), 4)


def _update(self, ev=None):
self.get_spectrum()
self.plot_spectrum()
Expand Down Expand Up @@ -589,7 +592,6 @@ def get_spectrum(self):

@out.capture(clear_output=True)
def click_callback(self, trace, points, selector):
self.status_message(f'click_callback: {selector}')
if selector.shift:
self.spectrum_plot.add_trace(go.Scatter(x=self.energy_scale,
y=self.dataset[points.point_inds[0][1], points.point_inds[0][0]],
Expand All @@ -598,11 +600,14 @@ def click_callback(self, trace, points, selector):
else:
if selector.ctrl:
self.spectrum_plot.data =[self.spectrum_plot.data[0]]
self.spectrum_plot.data[0].y= self.dataset[points.point_inds[0][1],points.point_inds[0][0]]
self.spectrum_plot.data[0].name = 'spectrum'+str(points.point_inds[0])


self.image_plot.data[1].x = [points.point_inds[0][1]]
self.image_plot.data[1].y = [points.point_inds[0][0]]
self.x = points.point_inds[0][1]
self.y = points.point_inds[0][0]

self._update()

@out.capture(clear_output=True)
def selection_fn(self, trace,points,selector):
Expand All @@ -626,6 +631,7 @@ def plot_spectrum_image(self):
else:
self.image_plot.data[0].z=np.array(self.image).T
self.plot_spectrum()
self.image_plot.data = [self.image_plot.data[0]]
self.image_plot.add_trace(
go.Scatter(mode="markers", x=[0], y=[0], marker_symbol=[101],
marker_color="darkgray",
Expand Down
14 changes: 7 additions & 7 deletions pyTEMlib/low_loss_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def get_drude(self, value=0):

if 'low_loss_model' not in self.parent.datasets.keys():
self.parent.datasets['low_loss_model'] = self.parent.dataset.copy()*0

self.parent.status_message(str(self.parent.x))
plasmon = eels_tools.fit_plasmon(self.parent.spectrum, fit_start, fit_end)

p = plasmon.metadata['plasmon']['parameter']
Expand Down Expand Up @@ -383,12 +383,12 @@ def _update(self, ev=0):
low_loss = None
plasmon = None
resolution_function = None
if 'zero_loss' in self.get_additional_spectrum.keys():
del self.get_additional_spectrum['zero_loss']
if 'plasmon' in self.get_additional_spectrum.keys():
del self.get_additional_spectrum['plasmon']
if 'low_loss_model' in self.get_additional_spectrum.keys():
del self.get_additional_spectrum['low_loss_model']
if 'zero_loss' in self.parent.added_spectra.keys():
del self.parent.added_spectra['zero_loss']
if 'plasmon' in self.parent.added_spectra.keys():
del self.parent.added_spectra['plasmon']
if 'low_loss_model' in self.parent.added_spectra.keys():
del self.parent.added_spectra['low_loss_model']

if self .low_loss_tab[3, 0].value:
if 'zero_loss' in self.parent.datasets.keys():
Expand Down
2 changes: 2 additions & 0 deletions pyTEMlib/probe_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def make_lorentz(size_x, size_y, gamma=1.0, x0=0., y0=0., intensity=1.):
x, y = np.mgrid[-size_x:size_x, -size_y:size_y]
g = gamma / (2 * np.pi) / np.power(((x - x0) ** 2 + (y - y0) ** 2 + gamma ** 2), 1.5)
probe = g / g.sum() * intensity

return probe


Expand All @@ -46,6 +47,7 @@ def zero_loss_peak_weight():
y = [0.0143, 0.0193, 0.0281, 0.0440, 0.0768, 0.1447, 0.2785, 0.4955, 0.7442, 0.9380, 1.0000, 0.9483, 0.8596,
0.7620, 0.6539, 0.5515, 0.4478, 0.3500, 0.2683, 0.1979, 0.1410, 0.1021, 0.0752, 0.0545, 0.0401, 0.0300,
0.0229, 0.0176, 0.0139]

return x, y


Expand Down

0 comments on commit 6d36f87

Please sign in to comment.