Skip to content

Commit

Permalink
Exorcise logging, use warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Jan 16, 2025
1 parent 3107b87 commit d425c46
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
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
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
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
28 changes: 13 additions & 15 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 @@ -4522,7 +4520,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)

0 comments on commit d425c46

Please sign in to comment.