From 4b54eafd8083fd2e55630909bb4135230f09507d Mon Sep 17 00:00:00 2001 From: "Pey Lian Lim (Github)" <2090236+pllim@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:04:43 -0500 Subject: [PATCH] Remove logging usage from Jdaviz. See JP-2280. Except for Cubeviz because that is being refactored at #1040 --- jdaviz/app.py | 6 +++--- jdaviz/cli.py | 5 +++-- jdaviz/configs/mosviz/helper.py | 23 ++++++++++------------- jdaviz/configs/mosviz/plugins/parsers.py | 10 ++++------ jdaviz/configs/specviz/helper.py | 14 +++++++------- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/jdaviz/app.py b/jdaviz/app.py index aac48a8de4..e1c817d76f 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -1,8 +1,8 @@ -import logging import os import pathlib import re import uuid +import warnings from inspect import isclass import ipyvue @@ -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) diff --git a/jdaviz/cli.py b/jdaviz/cli.py index e8226a7a14..b0a6bcc676 100644 --- a/jdaviz/cli.py +++ b/jdaviz/cli.py @@ -1,8 +1,7 @@ # Command-line interface for jdaviz -import logging -import pathlib import os +import pathlib import sys import tempfile @@ -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 diff --git a/jdaviz/configs/mosviz/helper.py b/jdaviz/configs/mosviz/helper.py index 991abd1f2d..bfe1c9931f 100644 --- a/jdaviz/configs/mosviz/helper.py +++ b/jdaviz/configs/mosviz/helper.py @@ -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 @@ -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) @@ -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) @@ -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) diff --git a/jdaviz/configs/mosviz/plugins/parsers.py b/jdaviz/configs/mosviz/plugins/parsers.py index 95c84bb966..7aa9d6fdf9 100644 --- a/jdaviz/configs/mosviz/plugins/parsers.py +++ b/jdaviz/configs/mosviz/plugins/parsers.py @@ -1,7 +1,6 @@ from collections.abc import Iterable import csv import glob -import logging import os from pathlib import Path import warnings @@ -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) @@ -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(): diff --git a/jdaviz/configs/specviz/helper.py b/jdaviz/configs/specviz/helper.py index 5f8158e0a0..05fe0d2462 100644 --- a/jdaviz/configs/specviz/helper.py +++ b/jdaviz/configs/specviz/helper.py @@ -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 @@ -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] @@ -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'