diff --git a/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py b/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py index 8d9f3f22fd..f930203f97 100644 --- a/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py +++ b/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py @@ -329,7 +329,7 @@ def calculate_moment(self, add_data=True): # only flux<> flux conversions will occur, so we only # need the spectral_density equivalency. should I just # be using the mean wavelength here? - eqv = u.spectral_density(np.mean(slab.spectral_axis)) + eqv = u.spectral_density(np.nanmean(slab.spectral_axis)) self.moment = flux_conversion_general(self.moment.value, u.Unit(self.moment.unit) / x_unit, diff --git a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py index 96ddc99ceb..3a65e5a6ee 100644 --- a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py +++ b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py @@ -355,15 +355,23 @@ def test_correct_output_spectral_y_units(cubeviz_helper, spectrum1d_cube_custom_ @pytest.mark.parametrize("flux_angle_unit", [(u.Unit(x), u.sr) for x in SPEC_PHOTON_FLUX_DENSITY_UNITS] + [(u.Unit(x), PIX2) for x in SPEC_PHOTON_FLUX_DENSITY_UNITS]) # noqa +@pytest.mark.parametrize("new_flux_unit", [u.Unit(x)for x in SPEC_PHOTON_FLUX_DENSITY_UNITS]) def test_moment_zero_unit_flux_conversions(cubeviz_helper, spectrum1d_cube_custom_fluxunit, - flux_angle_unit): + flux_angle_unit, + new_flux_unit): """ Test the calculation of the 0th moment and all possible flux unit conversions. Tests all units in SPEC_PHOTON_FLUX_DENSITY_UNITS against one another, since they are all valid selections in the unit conversion plugin. """ flux_unit, angle_unit = flux_angle_unit + flux_unit_str = flux_unit.to_string() + new_flux_unit_str = new_flux_unit.to_string() + + if flux_unit == new_flux_unit: # would result in no conversion, skip + return + cube_unit = flux_unit / angle_unit sb_cube = spectrum1d_cube_custom_fluxunit(fluxunit=cube_unit) @@ -381,46 +389,44 @@ def test_moment_zero_unit_flux_conversions(cubeviz_helper, flux_viewer = cubeviz_helper.app.get_viewer(cubeviz_helper._default_flux_viewer_reference_name) label_mouseover = cubeviz_helper.app.session.application._tools['g-coords-info'] - for new_flux_unit in SPEC_PHOTON_FLUX_DENSITY_UNITS: - if new_flux_unit != flux_unit: # dont compare same units - # first set back to original flux unit, so we're not converting from - # the unit set during the last iteration - uc.flux_unit.selected = flux_unit.to_string() + # first set back to original flux unit, so we're not converting from + # the unit set during the last iteration + uc.flux_unit.selected = flux_unit_str - # then convert to new flux unit - uc.flux_unit.selected = new_flux_unit + # then convert to new flux unit + uc.flux_unit.selected = new_flux_unit_str - new_mm_unit = (u.Unit(new_flux_unit) * u.m / u.Unit(angle_unit)).to_string() - assert mm.output_unit_items[0]['label'] == 'Surface Brightness' - assert mm.output_unit_items[0]['unit_str'] == new_mm_unit + new_mm_unit = (new_flux_unit * u.m / u.Unit(angle_unit)).to_string() + assert mm.output_unit_items[0]['label'] == 'Surface Brightness' + assert mm.output_unit_items[0]['unit_str'] == new_mm_unit - # calculate moment with new output label and plot in flux viewer - mm.add_results.label = new_flux_unit - mm.add_results.viewer.selected = cubeviz_helper._default_flux_viewer_reference_name - mm.calculate_moment() + # calculate moment with new output label and plot in flux viewer + mm.add_results.label = new_flux_unit_str + mm.add_results.viewer.selected = cubeviz_helper._default_flux_viewer_reference_name + mm.calculate_moment() - assert mm.moment.unit == new_mm_unit - - # make sure mouseover info in flux unit is new moment map unit - # which should be flux/sb unit times spectral axis unit (e.g. MJy m / sr) - label_mouseover._viewer_mouse_event(flux_viewer, - {'event': 'mousemove', - 'domain': {'x': 0, 'y': 0}}) - m_orig = label_mouseover.as_text()[0] - assert (u.Unit(new_flux_unit / angle_unit) * u.m).to_string() in m_orig - - # 'jiggle' mouse so we can move it back - label_mouseover._viewer_mouse_event(flux_viewer, - {'event': 'mousemove', - 'domain': {'x': 1, 'y': 1}}) - - # when flux unit is changed, the mouseover unit conversion should be - # skipped so that the plotted moment map remains in its original - # unit. setting back to the original flux unit also ensures that - # each iteration begins on the same unit so that every comparison - # is tested - uc.flux_unit.selected = new_flux_unit - label_mouseover._viewer_mouse_event(flux_viewer, - {'event': 'mousemove', - 'domain': {'x': 0, 'y': 0}}) - assert m_orig == label_mouseover.as_text()[0] + assert mm.moment.unit == new_mm_unit + + # make sure mouseover info in flux unit is new moment map unit + # which should be flux/sb unit times spectral axis unit (e.g. MJy m / sr) + label_mouseover._viewer_mouse_event(flux_viewer, + {'event': 'mousemove', + 'domain': {'x': 0, 'y': 0}}) + m_orig = label_mouseover.as_text()[0] + assert ((new_flux_unit / angle_unit) * u.m).to_string() in m_orig + + # 'jiggle' mouse so we can move it back + label_mouseover._viewer_mouse_event(flux_viewer, + {'event': 'mousemove', + 'domain': {'x': 1, 'y': 1}}) + + # when flux unit is changed, the mouseover unit conversion should be + # skipped so that the plotted moment map remains in its original + # unit. setting back to the original flux unit also ensures that + # each iteration begins on the same unit so that every comparison + # is tested + uc.flux_unit.selected = new_flux_unit_str + label_mouseover._viewer_mouse_event(flux_viewer, + {'event': 'mousemove', + 'domain': {'x': 0, 'y': 0}}) + assert m_orig == label_mouseover.as_text()[0]