|
6 | 6 | import numpy as np |
7 | 7 | from astropy import units as u |
8 | 8 | from astropy.modeling.fitting import LevMarLSQFitter |
| 9 | +from astropy.modeling import Parameter |
9 | 10 | from astropy.modeling.models import Gaussian1D |
10 | 11 | from astropy.table import QTable |
11 | 12 | from astropy.time import Time |
@@ -68,6 +69,7 @@ def __init__(self, *args, **kwargs): |
68 | 69 | self._fig = bqplot.Figure() |
69 | 70 | self.plot_types = ["Curve of Growth", "Radial Profile", "Radial Profile (Raw)"] |
70 | 71 | self.current_plot_type = self.plot_types[0] |
| 72 | + self._fitted_model_name = 'phot_radial_profile' |
71 | 73 |
|
72 | 74 | def reset_results(self): |
73 | 75 | self.result_available = False |
@@ -223,6 +225,11 @@ def vue_do_aper_phot(self, *args, **kwargs): |
223 | 225 | data = self._selected_data |
224 | 226 | reg = self._selected_subset |
225 | 227 |
|
| 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 | + |
226 | 233 | try: |
227 | 234 | comp = data.get_component(data.main_components[0]) |
228 | 235 | try: |
@@ -373,7 +380,7 @@ def vue_do_aper_phot(self, *args, **kwargs): |
373 | 380 | self.hub.broadcast(SnackbarMessage( |
374 | 381 | f"Radial profile fitting: {msg}", color='warning', sender=self)) |
375 | 382 | 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 |
377 | 384 | bqplot_fit = bqplot.Lines(x=x_data, y=y_fit, marker=None, |
378 | 385 | scales={'x': line_x_sc, 'y': line_y_sc}, |
379 | 386 | colors='magenta', line_style='dashed') |
@@ -410,6 +417,15 @@ def vue_do_aper_phot(self, *args, **kwargs): |
410 | 417 | f'{x:.4e} ({phot_table["aperture_sum_counts_err"][0]:.4e})'}) |
411 | 418 | else: |
412 | 419 | 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}'}) |
413 | 429 | self.results = tmp |
414 | 430 | self.result_available = True |
415 | 431 | self.radial_plot = self._fig |
|
0 commit comments