Skip to content

Commit

Permalink
use correct spectral density equivalencies for marker unit changes (s…
Browse files Browse the repository at this point in the history
…pacetelescope#3219)

* get spectral density equivalencies from original quantities

* add change log

* remove using spectrum1d object

* add test coverage to ensure marker location updates with uc

* use input data instead of slice plugin for truth in tests
  • Loading branch information
gibsongreen authored Oct 17, 2024
1 parent 2170624 commit bef7a00
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ New Features

- Added flux/surface brightness translation and surface brightness
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088, #3111, #3113, #3129,
#3139, #3149, #3155, #3178, #3185, #3187, #3190, #3156, #3200, #3192, #3206, #3211, #3216]
#3139, #3149, #3155, #3178, #3185, #3187, #3190, #3156, #3200, #3192, #3206, #3211, #3216, #3219]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ def test_markers_cubeviz(tmp_path, cubeviz_helper, spectrum1d_cube):

mp._obj._on_viewer_key_event(sv, {'event': 'keydown',
'key': 'm'})

# test that markers update on unit conversion
uc = cubeviz_helper.plugins['Unit Conversion']
uc.flux_unit.selected = 'MJy'

# find the index of the marker's x-coordinate in the spectral axis of the original input data
spec = cubeviz_helper.get_data('Spectrum (sum)', use_display_units=True)
marker_index = np.where(spec.spectral_axis.value == mp._obj.marks['cubeviz-2'].x)
# use the index to find the associated flux value of the original input
flux_value = spec.flux[marker_index].value

# compare the marker's (y) flux value with the flux value of the original input data
assert_allclose(mp._obj.marks['cubeviz-2'].y[0], flux_value)

# now check if marks update with a unit that requires spectral density equivalency
uc.flux_unit.selected = 'erg / (Angstrom s cm2)'

spec = cubeviz_helper.get_data('Spectrum (sum)', use_display_units=True)
flux_value = spec.flux[marker_index].value

assert_allclose(mp._obj.marks['cubeviz-2'].y[0], flux_value)

assert len(mp.export_table()) == 3
assert len(_get_markers_from_viewer(fv).x) == 1
assert len(_get_markers_from_viewer(sv).x) == 2
Expand Down
4 changes: 3 additions & 1 deletion jdaviz/core/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ def set_y_unit(self, unit=None):

if self.yunit is not None and not np.all([s == 0 for s in self.y.shape]):
if self.viewer.default_class is Spectrum1D:
# used to obtain spectral density equivalencies with previous data and units
eqv = u.spectral_density(self.x*self.xunit)

spec = self.viewer.state.reference_data.get_object(cls=Spectrum1D)
eqv = u.spectral_density(spec.spectral_axis)

if ('_pixel_scale_factor' in spec.meta):
eqv += _eqv_pixar_sr(spec.meta['_pixel_scale_factor'])
Expand Down

0 comments on commit bef7a00

Please sign in to comment.