Skip to content

Commit

Permalink
Simplify code.
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Robitaille <thomas.robitaille@gmail.com>
  • Loading branch information
pllim and astrofrog committed Sep 29, 2023
1 parent 6c81a92 commit 8625317
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ def set_data_visibility(self, viewer_reference, data_label, visible=True, replac
viewer.add_data(data, percentile=95, color=viewer.color_cycler())

# Specviz removes the data from collection in viewer.py if flux unit incompatible.
if data_label not in self.data_collection.labels:
if data_label not in self.data_collection:
return

viewer.set_plot_axes()
Expand Down
16 changes: 8 additions & 8 deletions jdaviz/configs/specviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from astropy import units as u
from astropy.nddata import StdDevUncertainty, VarianceUncertainty, InverseVariance
from echo import delay_callback
from glue.config import data_translator
from glue.core import BaseData
from glue_astronomy.spectral_coordinates import SpectralCoordinates
from glue.core.exceptions import IncompatibleAttribute
from glue.core.units import UnitConverter
from glue.core.subset import Subset
from glue.core.subset_group import GroupedSubset
from glue.config import data_translator
from glue_astronomy.spectral_coordinates import SpectralCoordinates
from glue_jupyter.bqplot.profile import BqplotProfileView
from glue.core.exceptions import IncompatibleAttribute
from matplotlib.colors import cnames
from specutils import Spectrum1D

Expand All @@ -25,6 +26,7 @@

__all__ = ['SpecvizProfileView']

uc = UnitConverter()

uncertainty_str_to_cls_mapping = {
"std": StdDevUncertainty,
Expand Down Expand Up @@ -369,12 +371,10 @@ def add_data(self, data, color=None, alpha=None, **layer_state):
if len(self.layers) == 0:
reset_plot_axes = True
else:
# Check if the new data flux unit is actually compatible since flux not linked
data_flux_unit = u.Unit(y_units)
viewer_flux_unit = u.Unit(self.state.y_display_unit)
wav = 1 * u.Unit(self.state.x_display_unit)
# Check if the new data flux unit is actually compatible since flux not linked.
try:
(1 * data_flux_unit).to(viewer_flux_unit, u.spectral_density(wav)) # Error if incompatible # noqa: E501
uc.to_unit(data, data.find_component_id("flux"), [1, 1],
u.Unit(self.state.y_display_unit)) # Error if incompatible
except Exception as err:
# Raising exception here introduces a dirty state that messes up next load_data
# but not raising exception also causes weird behavior unless we remove the data
Expand Down

0 comments on commit 8625317

Please sign in to comment.