Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update model fit result units after toggling flux/surface brightness #3113

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ New Features
------------

- Added flux/surface brightness translation and surface brightness
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088]
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088, #3113]

- Plugin tray is now open by default. [#2892]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def extract(self, return_bg=False, add_data=True, **kwargs):
spec = spec - bg_spec

# per https://jwst-docs.stsci.edu/jwst-near-infrared-camera/nircam-performance/nircam-absolute-flux-calibration-and-zeropoints # noqa
pix_scale_factor = self.aperture_area_along_spectral * self.spectral_cube.meta.get('PIXAR_SR', 1.0) # noqa
pix_scale_factor = self.spectral_cube.meta.get('PIXAR_SR', 1.0)
spec.meta['_pixel_scale_factor'] = pix_scale_factor

# inform the user if scale factor keyword not in metadata
Expand Down
13 changes: 12 additions & 1 deletion jdaviz/configs/default/plugins/model_fitting/model_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def __init__(self, *args, **kwargs):
self.component_models = []
self._initialized_models = {}
self._display_order = False
self._pixel_scale_factor = None

# create the label first so that when model_component defaults to the first selection,
# the label automatically defaults as well
Expand Down Expand Up @@ -328,10 +329,13 @@ def _dataset_selected_changed(self, event=None):
# during initial init, this can trigger before the component is initialized
return

selected_spec = self.dataset.selected_spectrum
selected_spec = self.dataset.selected_obj
if selected_spec is None:
return

if '_pixel_scale_factor' in selected_spec.meta:
self._pixel_scale_factor = selected_spec.meta['_pixel_scale_factor']
kecnry marked this conversation as resolved.
Show resolved Hide resolved

# Replace NaNs from collapsed Spectrum1D in Cubeviz
# (won't affect calculations because these locations are masked)
selected_spec.flux[np.isnan(selected_spec.flux)] = 0.0
Expand Down Expand Up @@ -842,6 +846,11 @@ def _fit_model_to_spectrum(self, add_data):
self.hub.broadcast(msg)
return

if self._pixel_scale_factor is not None:
fitted_spectrum.meta['_pixel_scale_factor'] = self._pixel_scale_factor
else:
print("No pixel scale factor!")

self._fitted_model = fitted_model
self._fitted_spectrum = fitted_spectrum

Expand Down Expand Up @@ -932,6 +941,8 @@ def _fit_model_to_cube(self, add_data):
self.app.fitted_models[temp_label] = m["model"]

output_cube = Spectrum1D(flux=fitted_spectrum.flux, wcs=fitted_spectrum.wcs)
if self._pixel_scale_factor is not None:
output_cube.meta['_pixel_scale_factor'] = self._pixel_scale_factor

# Create new data entry for glue
if add_data:
Expand Down
Loading