diff --git a/jdaviz/configs/cubeviz/plugins/parsers.py b/jdaviz/configs/cubeviz/plugins/parsers.py index 017cde1264..9cce81d361 100644 --- a/jdaviz/configs/cubeviz/plugins/parsers.py +++ b/jdaviz/configs/cubeviz/plugins/parsers.py @@ -1,4 +1,3 @@ -import logging import os import warnings @@ -282,12 +281,12 @@ def _parse_hdulist(app, hdulist, file_name=None, try: flux_unit = u.Unit(hdu.header['BUNIT']) except Exception: - logging.warning("Invalid BUNIT, using count as data unit") + warnings.warn("Invalid BUNIT, using count as data unit", UserWarning) flux_unit = u.count elif data_type == 'mask': # DQ flags have no unit flux_unit = u.dimensionless_unscaled else: - logging.warning("Invalid BUNIT, using count as data unit") + warnings.warn("Invalid BUNIT, using count as data unit", UserWarning) flux_unit = u.count flux = hdu.data << flux_unit diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py index 2cc950a742..65f09f9e57 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py @@ -1,3 +1,4 @@ +import pytest from specutils import SpectralRegion from jdaviz import Cubeviz @@ -17,6 +18,8 @@ def test_nested_helper(cubeviz_helper): assert spec_viewer.jdaviz_helper == cubeviz_helper +# Some API might be going through deprecation, so ignore the warning. +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_plugin_user_apis(cubeviz_helper): for plugin_name, plugin_api in cubeviz_helper.plugins.items(): plugin = plugin_api._obj diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 526ad276e2..a1a011ebf4 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -1,14 +1,11 @@ -import logging import math import os +import warnings + import matplotlib import numpy as np - -from astropy.visualization import ManualInterval, ContrastBiasStretch - from echo import delay_callback -from traitlets import Any, Dict, Float, Bool, Int, List, Unicode, observe - +from astropy.visualization import ManualInterval, ContrastBiasStretch from glue.core.subset_group import GroupedSubset from glue.config import stretches as glue_stretches from glue.viewers.scatter.state import ScatterViewerState @@ -18,6 +15,8 @@ from glue.viewers.image.composite_array import COLOR_CONVERTER from glue_jupyter.bqplot.image.state import BqplotImageLayerState from glue_jupyter.common.toolbar_vuetify import read_icon +from scipy.interpolate import PchipInterpolator +from traitlets import Any, Dict, Float, Bool, Int, List, Unicode, observe from jdaviz.core.registries import tray_registry from jdaviz.core.template_mixin import (PluginTemplateMixin, ViewerSelectMixin, LayerSelect, @@ -30,9 +29,6 @@ # by importing from utils, glue_colormaps will include the custom Random colormap from jdaviz.utils import is_not_wcs_only, cmap_samples, glue_colormaps - -from scipy.interpolate import PchipInterpolator - __all__ = ['PlotOptions'] RANDOM_SUBSET_SIZE = 10_000 @@ -663,12 +659,18 @@ def user_api(self): @property def multiselect(self): - logging.warning(f"DeprecationWarning: multiselect has been replaced by separate viewer_multiselect and layer_multiselect and will be removed in the future. This currently evaluates viewer_multiselect or layer_multiselect") # noqa + warnings.warn( + "multiselect has been replaced by separate viewer_multiselect and " + "layer_multiselect and will be removed in the future. " + "This currently evaluates viewer_multiselect or layer_multiselect", DeprecationWarning) return self.viewer_multiselect or self.layer_multiselect @multiselect.setter def multiselect(self, value): - logging.warning(f"DeprecationWarning: multiselect has been replaced by separate viewer_multiselect and layer_multiselect and will be removed in the future. This currently sets viewer_multiselect and layer_multiselect") # noqa + warnings.warn( + "multiselect has been replaced by separate viewer_multiselect and " + "layer_multiselect and will be removed in the future. " + "This currently sets viewer_multiselect and layer_multiselect", DeprecationWarning) self.viewer_multiselect = value self.layer_multiselect = value diff --git a/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py b/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py index db18a7e16b..6631cf5337 100644 --- a/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py @@ -346,7 +346,8 @@ def test_track_mixed_states(imviz_helper): po.image_color.value = rgb_colors[i] # Switch to multiselect to test mixing and unmixing of states - po.multiselect = True + po.viewer_multiselect = True + po.layer_multiselect = True po.viewer_selected = ["imviz-0", "imviz-1"] assert po.layer.items[-1]["label"] == "array_2" # The corresponding layer in each viewer is the same color, diff --git a/jdaviz/configs/imviz/tests/test_helper.py b/jdaviz/configs/imviz/tests/test_helper.py index f2e4410cb7..73a762f13f 100644 --- a/jdaviz/configs/imviz/tests/test_helper.py +++ b/jdaviz/configs/imviz/tests/test_helper.py @@ -1,6 +1,9 @@ import numpy as np +import pytest +# Some API might be going through deprecation, so ignore the warning. +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_plugin_user_apis(imviz_helper): for plugin_name, plugin_api in imviz_helper.plugins.items(): plugin = plugin_api._obj diff --git a/jdaviz/configs/imviz/tests/test_viewers.py b/jdaviz/configs/imviz/tests/test_viewers.py index c948a96e2c..da226fb165 100644 --- a/jdaviz/configs/imviz/tests/test_viewers.py +++ b/jdaviz/configs/imviz/tests/test_viewers.py @@ -27,7 +27,8 @@ def test_create_destroy_viewer(imviz_helper, desired_name, actual_name): assert sorted(imviz_helper.plugins['Compass'].viewer.labels) == viewer_names po = imviz_helper.plugins['Plot Options'] - po.multiselect = True + po.viewer_multiselect = True + po.layer_multiselect = True po.viewer = viewer_names imviz_helper.destroy_viewer(actual_name) diff --git a/jdaviz/configs/mosviz/tests/test_helper.py b/jdaviz/configs/mosviz/tests/test_helper.py index a55031b741..918df5de3a 100644 --- a/jdaviz/configs/mosviz/tests/test_helper.py +++ b/jdaviz/configs/mosviz/tests/test_helper.py @@ -115,6 +115,8 @@ def test_redshift_column(mosviz_helper, mos_image, spectrum1d, mos_spectrum2d): assert_allclose(mosviz_helper.get_spectrum_1d(apply_slider_redshift=True, row=1).redshift.value, 0.0) # noqa: E501 +# Some API might be going through deprecation, so ignore the warning. +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_plugin_user_apis(mosviz_helper): for plugin_name, plugin_api in mosviz_helper.plugins.items(): plugin = plugin_api._obj diff --git a/jdaviz/configs/rampviz/plugins/parsers.py b/jdaviz/configs/rampviz/plugins/parsers.py index 4d30c8c90a..d1a43f8b6f 100644 --- a/jdaviz/configs/rampviz/plugins/parsers.py +++ b/jdaviz/configs/rampviz/plugins/parsers.py @@ -1,5 +1,6 @@ -import logging import os +import warnings + import numpy as np import astropy.units as u from astropy.io import fits @@ -277,10 +278,10 @@ def _parse_hdulist( try: flux_unit = u.Unit(hdu.header['BUNIT']) except Exception: - logging.warning("Invalid BUNIT, using DN as data unit") + warnings.warn("Invalid BUNIT, using DN as data unit", UserWarning) flux_unit = u.DN else: - logging.warning("Invalid BUNIT, using DN as data unit") + warnings.warn("Invalid BUNIT, using DN as data unit", UserWarning) flux_unit = u.DN # index the ramp array by the integration to load. returns all groups and pixels. diff --git a/jdaviz/configs/specviz/tests/test_helper.py b/jdaviz/configs/specviz/tests/test_helper.py index 3c0f7f5223..1163bd7fde 100644 --- a/jdaviz/configs/specviz/tests/test_helper.py +++ b/jdaviz/configs/specviz/tests/test_helper.py @@ -454,6 +454,8 @@ def test_plot_uncertainties(specviz_helper, spectrum1d): assert len([m for m in specviz_viewer.figure.marks if isinstance(m, LineUncertainties)]) == 0 +# Some API might be going through deprecation, so ignore the warning. +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_plugin_user_apis(specviz_helper): for plugin_name, plugin_api in specviz_helper.plugins.items(): plugin = plugin_api._obj diff --git a/jdaviz/configs/specviz2d/tests/test_helper.py b/jdaviz/configs/specviz2d/tests/test_helper.py index a6eb3a203b..2090d720b8 100644 --- a/jdaviz/configs/specviz2d/tests/test_helper.py +++ b/jdaviz/configs/specviz2d/tests/test_helper.py @@ -1,4 +1,6 @@ +import pytest from specutils import Spectrum1D + from jdaviz import Specviz @@ -13,6 +15,8 @@ def test_helper(specviz2d_helper, mos_spectrum2d): assert isinstance(returned_data, Spectrum1D) +# Some API might be going through deprecation, so ignore the warning. +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_plugin_user_apis(specviz2d_helper): for plugin_name, plugin_api in specviz2d_helper.plugins.items(): plugin = plugin_api._obj diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 4bfeaebee0..4b5136cf16 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -1,20 +1,19 @@ -from astropy.coordinates.sky_coordinate import SkyCoord -from astropy.nddata import NDData -from astropy.table import QTable -from astropy.table.row import Row as QTableRow -import astropy.units as u -import bqplot -from contextlib import contextmanager -import numpy as np import inspect -import logging import os import threading import time import warnings +from contextlib import contextmanager +from functools import cached_property +import astropy.units as u +import bqplot +import numpy as np +from astropy.coordinates.sky_coordinate import SkyCoord +from astropy.nddata import NDData +from astropy.table import QTable +from astropy.table.row import Row as QTableRow from echo import delay_callback -from functools import cached_property from ipyvuetify import VuetifyTemplate from glue.config import colormaps from glue.core import Data, HubListener @@ -31,16 +30,15 @@ from glue_jupyter.bqplot.image import BqplotImageView from glue_jupyter.registries import viewer_registry from glue_jupyter.widgets.linked_dropdown import get_choices as _get_glue_choices +from ipywidgets import widget_serialization +from ipypopout import PopoutButton +from ipypopout.popout_button import get_kernel_id from photutils.aperture import CircularAperture, EllipticalAperture, RectangularAperture from regions import PixelRegion from specutils import Spectrum1D from specutils.manipulation import extract_region from traitlets import Any, Bool, Dict, Float, HasTraits, List, Unicode, observe -from ipywidgets import widget_serialization -from ipypopout import PopoutButton -from ipypopout.popout_button import get_kernel_id - from jdaviz.components.toolbar_nested import NestedJupyterToolbar from jdaviz.configs.cubeviz.plugins.viewers import WithSliceIndicator from jdaviz.core.custom_traitlets import FloatHandleEmpty @@ -472,8 +470,11 @@ def get_api_text(name, obj): if type(obj).__name__ == 'method': return f"{name}{inspect.signature(obj)}" return name - self.api_methods = sorted([get_api_text(name, obj) - for name, obj in inspect.getmembers(self.user_api)]) + with warnings.catch_warnings(): + # Some API might be going through deprecation, so ignore the warning. + warnings.filterwarnings("ignore", category=DeprecationWarning) + self.api_methods = sorted([get_api_text(name, obj) + for name, obj in inspect.getmembers(self.user_api)]) def new(self): new = self.__class__(app=self.app) @@ -4522,7 +4523,7 @@ def _on_value_changed(self, msg): setattr(self.plugin, self._spinner, True) if self._glue_name == 'color_mode' and msg['new'] == 'Monochromatic': - logging.warning("DeprecationWarning: 'Monochromatic' renamed to 'Color'") + warnings.warn("'Monochromatic' renamed to 'Color'", DeprecationWarning) self.value = 'One color per layer' return diff --git a/jdaviz/core/user_api.py b/jdaviz/core/user_api.py index b4ed875481..a98d5c654c 100644 --- a/jdaviz/core/user_api.py +++ b/jdaviz/core/user_api.py @@ -1,4 +1,5 @@ -import logging +import warnings + import astropy.units as u __all__ = ['UserApiWrapper', 'PluginUserApi', 'ViewerUserApi'] @@ -36,7 +37,7 @@ def __getattr__(self, attr): return super().__getattribute__(attr) if attr in self._deprecated: - logging.warning("DeprecationWarning: %s is deprecated" % attr) + warnings.warn(f"{attr} is deprecated", DeprecationWarning) exp_obj = getattr(self._obj, attr) return getattr(exp_obj, 'user_api', exp_obj) @@ -141,7 +142,7 @@ def __init__(self, plugin, expose=[], readonly=[], excl_from_dict=[], deprecated def __repr__(self): if self._deprecation_msg: - logging.warning("DeprecationWarning: %s" % self._deprecation_msg) + warnings.warn(self._deprecation_msg, DeprecationWarning) super().__setattr__('_deprecation_msg', None) return f'<{self._obj._registry_label} API>' @@ -164,12 +165,12 @@ def __repr__(self): def __getattr__(self, *args, **kwargs): if super().__getattr__('_deprecation_msg'): - logging.warning(f"DeprecationWarning: {self._deprecation_msg}") + warnings.warn(self._deprecation_msg, DeprecationWarning) super().__setattr__('_deprecation_msg', None) return super().__getattr__(*args, **kwargs) def __setattr__(self, *args, **kwargs): if hasattr(self, '_deprecation_msg') and self._deprecation_msg: - logging.warning(f"DeprecationWarning: {self._deprecation_msg}") + warnings.warn(self._deprecation_msg, DeprecationWarning) super().__setattr__('_deprecation_msg', None) return super().__setattr__(*args, **kwargs)