Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace logging with warnings #3396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions jdaviz/configs/cubeviz/plugins/parsers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import warnings

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from specutils import SpectralRegion

from jdaviz import Cubeviz
Expand All @@ -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
Expand Down
24 changes: 13 additions & 11 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions jdaviz/configs/imviz/tests/test_helper.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/imviz/tests/test_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions jdaviz/configs/mosviz/tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions jdaviz/configs/rampviz/plugins/parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import warnings

import numpy as np
import astropy.units as u
from astropy.io import fits
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions jdaviz/configs/specviz/tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions jdaviz/configs/specviz2d/tests/test_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
from specutils import Spectrum1D

from jdaviz import Specviz


Expand All @@ -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
Expand Down
35 changes: 18 additions & 17 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions jdaviz/core/user_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import warnings

import astropy.units as u

__all__ = ['UserApiWrapper', 'PluginUserApi', 'ViewerUserApi']
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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>'

Expand All @@ -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)
Loading