Skip to content

Commit

Permalink
Update model fit result units after toggling flux/surface brightness (#…
Browse files Browse the repository at this point in the history
…3113)

* Enabling model fitting results to convert between flux and surface brightness

* Switch to using selected_obj, clean up pixel scale retrieval

* Changelog

* Don't store pixel scale factor

* Fix missing variable

* Update test value due to updated pixel scale factor
  • Loading branch information
rosteen authored Jul 29, 2024
1 parent 3de1b08 commit dc2186e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
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
10 changes: 9 additions & 1 deletion jdaviz/configs/default/plugins/model_fitting/model_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ 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

Expand Down Expand Up @@ -842,6 +842,10 @@ def _fit_model_to_spectrum(self, add_data):
self.hub.broadcast(msg)
return

selected_spec = self.dataset.selected_obj
if '_pixel_scale_factor' in selected_spec.meta:
fitted_spectrum.meta['_pixel_scale_factor'] = selected_spec.meta['_pixel_scale_factor']

self._fitted_model = fitted_model
self._fitted_spectrum = fitted_spectrum

Expand Down Expand Up @@ -933,6 +937,10 @@ def _fit_model_to_cube(self, add_data):

output_cube = Spectrum1D(flux=fitted_spectrum.flux, wcs=fitted_spectrum.wcs)

selected_spec = self.dataset.selected_obj
if '_pixel_scale_factor' in selected_spec.meta:
output_cube.meta['_pixel_scale_factor'] = selected_spec.meta['_pixel_scale_factor']

# Create new data entry for glue
if add_data:
self.add_results.add_results_from_plugin(output_cube)
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_to_unit(cubeviz_helper):

# will be a uniform array since not wavelength dependent
# so test first value in array
assert np.allclose(value[0], 4.800000041882413e-08)
assert np.allclose(value[0], 8e-11)

# Change from Fnu to Flam (with values shape matching spectral axis)

Expand Down

0 comments on commit dc2186e

Please sign in to comment.