Skip to content

Commit 99fd9df

Browse files
committed
Display Gaussian1D results in GUI
and some bug fixes
1 parent 0b4a770 commit 99fd9df

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

docs/imviz/plugins.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ an interactively selected region. A typical workflow is as follows:
171171
However, if NaN exists in data, it will be treated as 0.
172172

173173
When calculation is complete, a plot would show the radial profile
174-
of the background subtracted data and the photometry results are displayed under the
175-
:guilabel:`CALCULATE` button.
174+
of the background subtracted data and the photometry and model fitting (if requested)
175+
results are displayed under the :guilabel:`CALCULATE` button.
176176

177177
.. figure:: img/imviz_radial_profile.png
178178
:alt: Imviz radial profile plot.

jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
from astropy import units as u
88
from astropy.modeling.fitting import LevMarLSQFitter
9+
from astropy.modeling import Parameter
910
from astropy.modeling.models import Gaussian1D
1011
from astropy.table import QTable
1112
from astropy.time import Time
@@ -68,6 +69,7 @@ def __init__(self, *args, **kwargs):
6869
self._fig = bqplot.Figure()
6970
self.plot_types = ["Curve of Growth", "Radial Profile", "Radial Profile (Raw)"]
7071
self.current_plot_type = self.plot_types[0]
72+
self._fitted_model_name = 'phot_radial_profile'
7173

7274
def reset_results(self):
7375
self.result_available = False
@@ -223,6 +225,11 @@ def vue_do_aper_phot(self, *args, **kwargs):
223225
data = self._selected_data
224226
reg = self._selected_subset
225227

228+
# Reset last fitted model
229+
fit_model = None
230+
if self._fitted_model_name in self.app.fitted_models:
231+
del self.app.fitted_models[self._fitted_model_name]
232+
226233
try:
227234
comp = data.get_component(data.main_components[0])
228235
try:
@@ -373,7 +380,7 @@ def vue_do_aper_phot(self, *args, **kwargs):
373380
self.hub.broadcast(SnackbarMessage(
374381
f"Radial profile fitting: {msg}", color='warning', sender=self))
375382
y_fit = fit_model(x_data)
376-
self.app.fitted_models['phot_radial_profile'] = fit_model
383+
self.app.fitted_models[self._fitted_model_name] = fit_model
377384
bqplot_fit = bqplot.Lines(x=x_data, y=y_fit, marker=None,
378385
scales={'x': line_x_sc, 'y': line_y_sc},
379386
colors='magenta', line_style='dashed')
@@ -410,6 +417,15 @@ def vue_do_aper_phot(self, *args, **kwargs):
410417
f'{x:.4e} ({phot_table["aperture_sum_counts_err"][0]:.4e})'})
411418
else:
412419
tmp.append({'function': key, 'result': str(x)})
420+
# Also display fit results
421+
if fit_model is not None and isinstance(fit_model, Gaussian1D):
422+
model_name = fit_model.__class__.__name__
423+
for param in ('fwhm', 'mean', 'amplitude'):
424+
p_val = getattr(fit_model, param)
425+
if isinstance(p_val, Parameter):
426+
p_val = p_val.value
427+
tmp.append({'function': f'{model_name}_{param}',
428+
'result': f'{p_val:.4e}'})
413429
self.results = tmp
414430
self.result_available = True
415431
self.radial_plot = self._fig

notebooks/concepts/imviz_simple_aper_phot.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"id": "b45fcdfe",
196196
"metadata": {},
197197
"source": [
198-
"If you fitted Gaussian to radial profile, you can get it back out like this."
198+
"If you fitted Gaussian to radial profile, you can get it back out like this. If it does not exist, you will get `None`."
199199
]
200200
},
201201
{
@@ -205,14 +205,14 @@
205205
"metadata": {},
206206
"outputs": [],
207207
"source": [
208-
"my_gaussian = imviz.app.fitted_models['phot_radial_profile']\n",
208+
"my_gaussian = imviz.app.fitted_models.get('phot_radial_profile', None)\n",
209209
"my_gaussian"
210210
]
211211
},
212212
{
213213
"cell_type": "code",
214214
"execution_count": null,
215-
"id": "1e546682",
215+
"id": "b7c59fef",
216216
"metadata": {},
217217
"outputs": [],
218218
"source": []

0 commit comments

Comments
 (0)