Skip to content

Commit

Permalink
Remove logging usage from Jdaviz.
Browse files Browse the repository at this point in the history
See JP-2280. Except for Cubeviz because that is being refactored at spacetelescope#1040
  • Loading branch information
pllim committed Feb 16, 2022
1 parent ddd3c25 commit 4b54eaf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
6 changes: 3 additions & 3 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import os
import pathlib
import re
import uuid
import warnings
from inspect import isclass

import ipyvue
Expand Down Expand Up @@ -1128,8 +1128,8 @@ def _update_selected_data_items(self, viewer_id, selected_items):
if x['id'] == data_id), None)

if label is None:
logging.warning(f"No data item with id '{data_id}' found in "
f"viewer '{viewer_id}'.")
warnings.warn(f"No data item with id '{data_id}' found in "
f"viewer '{viewer_id}'.")
continue

active_data_labels.append(label)
Expand Down
5 changes: 3 additions & 2 deletions jdaviz/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Command-line interface for jdaviz

import logging
import pathlib
import os
import pathlib
import sys
import tempfile

Expand Down Expand Up @@ -66,6 +65,8 @@ def main(filename, layout='default', browser='default', theme='light', verbosity
hotreload: bool
Whether to enable hot-reloading of the UI (for development)
"""
import logging # Local import to avoid possibly messing with JWST pipeline logger.

# Tornado Webserver py3.8 compatibility hotfix for windows
if sys.platform == 'win32':
import asyncio
Expand Down
23 changes: 10 additions & 13 deletions jdaviz/configs/mosviz/helper.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging

import numpy as np
import warnings
from copy import deepcopy
from pathlib import Path
from time import time

import astropy.units as u
from astropy.table import QTable
import numpy as np
from astropy import units as u
from astropy.coordinates import SkyCoord
from glue.core.exceptions import IncompatibleAttribute
from astropy.table import QTable
from echo import delay_callback
from copy import deepcopy
from glue.core.exceptions import IncompatibleAttribute

from jdaviz.core.helpers import ConfigHelper
from jdaviz.core.events import SnackbarMessage, TableClickMessage, RedshiftMessage, RowLockMessage
Expand Down Expand Up @@ -357,7 +356,6 @@ def _get_sp_attribute(table_data, row, attr, fill=None):
if sp1_val is not None and sp1_val != sp2_val:
# then there was a conflict
msg = f"Warning: value for {attr} in row {row} in disagreement between Spectrum1D and Spectrum2D" # noqa
logging.warning(msg)
msg = SnackbarMessage(msg, color='warning', sender=self)
self.app.hub.broadcast(msg)

Expand Down Expand Up @@ -458,7 +456,6 @@ def load_data(self, spectra_1d=None, spectra_2d=None, images=None,
msg = "Warning: Please set valid values for the load_data() method"

if msg:
logging.warning(msg)
msg = SnackbarMessage(msg, color='warning', sender=self)
self.app.hub.broadcast(msg)

Expand Down Expand Up @@ -927,10 +924,10 @@ def _get_spectrum(self, column, row=None, apply_slider_redshift="Warn"):
else:
redshift = self.get_column("Redshift")[row]
if apply_slider_redshift == "Warn":
logging.warning("Warning: Applying the value from the redshift "
"slider to the output spectra. To avoid seeing this "
"warning, explicitly set the apply_slider_redshift "
"argument to True or False.")
warnings.warn("Warning: Applying the value from the redshift "
"slider to the output spectra. To avoid seeing this "
"warning, explicitly set the apply_slider_redshift "
"argument to True or False.")

return _apply_redshift_to_spectra(spectra, redshift)

Expand Down
10 changes: 4 additions & 6 deletions jdaviz/configs/mosviz/plugins/parsers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import Iterable
import csv
import glob
import logging
import os
from pathlib import Path
import warnings
Expand Down Expand Up @@ -173,10 +172,9 @@ def mos_nirspec_directory_parser(app, data_obj, data_labels=None):
mos_meta_parser(app, images, ids=images)
mos_image_parser(app, images)
else:
msg = "The number of images in this directory does not match the" \
" number of spectra 1d and 2d files, please make the " \
"amounts equal or load images separately."
logging.warning(msg)
msg = ("The number of images in this directory does not match the"
" number of spectra 1d and 2d files, please make the "
"amounts equal or load images separately.")
msg = SnackbarMessage(msg, color='warning', sender=app)
app.hub.broadcast(msg)

Expand Down Expand Up @@ -449,7 +447,7 @@ def mos_meta_parser(app, data_obj, ids=None, spectra=False, sp1d=False):
else:
# TODO: Come up with more robust metadata parsing, perhaps from
# the spectra files.
logging.warning("Could not parse metadata from input images.")
warnings.warn("Could not parse metadata from input images.")
return

with app.data_collection.delay_link_manager_update():
Expand Down
14 changes: 7 additions & 7 deletions jdaviz/configs/specviz/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import warnings

import astropy.units as u
from astropy import units as u
from specutils import SpectralRegion, Spectrum1D

from jdaviz.core.helpers import ConfigHelper
Expand Down Expand Up @@ -60,10 +60,10 @@ def get_spectra(self, data_label=None, apply_slider_redshift="Warn"):
output_spectra[key] = _apply_redshift_to_spectra(spectra[key], self._redshift)

if apply_slider_redshift == "Warn":
logging.warning("Warning: Applying the value from the redshift "
"slider to the output spectra. To avoid seeing this "
"warning, explicitly set the apply_slider_redshift "
"argument to True or False.")
warnings.warn("Warning: Applying the value from the redshift "
"slider to the output spectra. To avoid seeing this "
"warning, explicitly set the apply_slider_redshift "
"argument to True or False.")

if data_label is not None:
output_spectra = output_spectra[data_label]
Expand Down Expand Up @@ -203,7 +203,7 @@ def set_spectrum_tick_format(self, fmt, axis=None):
"""
if axis not in [0, 1]:
logging.warning("Please use either 0 or 1 for the axis value")
warnings.warn("Please use either 0 or 1 for the axis value")
return

# Examples of values for fmt are '0.1e' or '0.2f'
Expand Down

0 comments on commit 4b54eaf

Please sign in to comment.