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

Remove logging, handle test warnings, etc #922

Merged
merged 2 commits into from
Feb 17, 2022
Merged
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Bug Fixes
Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Logger usage is removed. Warnings now issued using Python ``warnings`` module.
This enables more granular warning control for downstream packages. [#922]

1.6.0 (2022-01-27)
------------------

Expand Down
20 changes: 16 additions & 4 deletions docs/fitting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ uncertainty, we will produce an estimate of the uncertainty by calling the

.. code-block:: python

>>> import warnings
>>> from specutils.manipulation import noise_region_uncertainty
>>> noise_region = SpectralRegion(0*u.um, 3*u.um)
>>> spectrum = noise_region_uncertainty(spectrum, noise_region)

>>> from specutils.fitting import find_lines_threshold
>>> lines = find_lines_threshold(spectrum, noise_factor=3)
>>> with warnings.catch_warnings(): # Ignore warnings
... warnings.simplefilter('ignore')
... lines = find_lines_threshold(spectrum, noise_factor=3)

>>> lines[lines['line_type'] == 'emission'] # doctest:+FLOAT_CMP
<QTable length=4>
Expand Down Expand Up @@ -95,8 +98,11 @@ An example using the `~specutils.fitting.find_lines_derivative`:
>>> noise_region = SpectralRegion(0*u.um, 3*u.um)

>>> # Derivative technique
>>> import warnings
>>> from specutils.fitting import find_lines_derivative
>>> lines = find_lines_derivative(spectrum, flux_threshold=0.75)
>>> with warnings.catch_warnings(): # Ignore warnings
... warnings.simplefilter('ignore')
... lines = find_lines_derivative(spectrum, flux_threshold=0.75)

>>> lines[lines['line_type'] == 'emission'] # doctest:+FLOAT_CMP
<QTable length=2>
Expand Down Expand Up @@ -632,6 +638,7 @@ convenience functions to perform exactly this task. An example is shown below.
:align: center
:context: close-figs

>>> import warnings
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from astropy.modeling import models
Expand All @@ -649,7 +656,9 @@ convenience functions to perform exactly this task. An example is shown below.

>>> spectrum = Spectrum1D(flux=y*u.Jy, spectral_axis=x*u.um)

>>> g1_fit = fit_generic_continuum(spectrum)
>>> with warnings.catch_warnings(): # Ignore warnings
... warnings.simplefilter('ignore')
... g1_fit = fit_generic_continuum(spectrum)

>>> y_continuum_fitted = g1_fit(x*u.um)

Expand Down Expand Up @@ -685,6 +694,7 @@ is specified by a sequence:
:align: center
:context: close-figs

>>> import warnings
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import astropy.units as u
Expand All @@ -700,7 +710,9 @@ is specified by a sequence:

>>> spectrum = Spectrum1D(flux=y * u.Jy, spectral_axis=x * u.um)
>>> region = [(1 * u.um, 5 * u.um), (7 * u.um, 10 * u.um)]
>>> fitted_continuum = fit_continuum(spectrum, window=region)
>>> with warnings.catch_warnings(): # Ignore warnings
... warnings.simplefilter('ignore')
... fitted_continuum = fit_continuum(spectrum, window=region)
>>> y_fit = fitted_continuum(x*u.um)

>>> f, ax = plt.subplots() # doctest: +IGNORE_OUTPUT
Expand Down
5 changes: 4 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ may have downloaded from some archive, or reduced from your own observations.
Now maybe you want the equivalent width of a spectral line. That requires
normalizing by a continuum estimate:

>>> import warnings
>>> from specutils.fitting import fit_generic_continuum
>>> cont_norm_spec = spec / fit_generic_continuum(spec)(spec.spectral_axis) # doctest: +REMOTE_DATA
>>> with warnings.catch_warnings(): # Ignore warnings
... warnings.simplefilter('ignore')
... cont_norm_spec = spec / fit_generic_continuum(spec)(spec.spectral_axis) # doctest: +REMOTE_DATA

>>> f, ax = plt.subplots() # doctest: +IGNORE_OUTPUT
>>> ax.step(cont_norm_spec.wavelength, cont_norm_spec.flux) # doctest: +IGNORE_OUTPUT +REMOTE_DATA
Expand Down
1 change: 0 additions & 1 deletion docs/spectral_regions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,4 @@ Reference/API
:skip: test
:skip: Spectrum1D
:skip: SpectrumCollection
:skip: UnsupportedPythonError
:skip: SpectralAxis
1 change: 0 additions & 1 deletion docs/spectrum1d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,3 @@ Reference/API
:skip: test
:skip: SpectrumCollection
:skip: SpectralRegion
:skip: UnsupportedPythonError
17 changes: 9 additions & 8 deletions docs/spectrum_collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ a list of :class:`~specutils.Spectrum1D`:

.. code:: python

>>> from specutils import Spectrum1D, SpectrumCollection
>>> import astropy.units as u
>>> import warnings
>>> import numpy as np
>>> from astropy import units as u
>>> from specutils import Spectrum1D, SpectrumCollection
>>> spec = Spectrum1D(spectral_axis=np.linspace(0, 50, 50) * u.AA,
... flux=np.random.randn(50) * u.Jy,
... uncertainty=StdDevUncertainty(np.random.sample(50), unit='Jy'))
>>> spec1 = Spectrum1D(spectral_axis=np.linspace(20, 60, 50) * u.AA,
... flux=np.random.randn(50) * u.Jy,
... uncertainty=StdDevUncertainty(np.random.sample(50), unit='Jy'))

>>> spec_coll = SpectrumCollection.from_spectra([spec, spec1])
>>> with warnings.catch_warnings(): # Ignore warnings
... warnings.simplefilter('ignore')
... spec1 = Spectrum1D(spectral_axis=np.linspace(20, 60, 50) * u.AA,
... flux=np.random.randn(50) * u.Jy,
... uncertainty=StdDevUncertainty(np.random.sample(50), unit='Jy'))
... spec_coll = SpectrumCollection.from_spectra([spec, spec1])

>>> spec_coll.shape
(2,)
Expand Down Expand Up @@ -106,5 +108,4 @@ Reference/API
:skip: test
:skip: Spectrum1D
:skip: SpectralRegion
:skip: UnsupportedPythonError
:skip: SpectralAxis
32 changes: 32 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ asdf_extensions =

[tool:pytest]
testpaths = "specutils" "docs"
xfail_strict = true
astropy_header = true
doctest_plus = enabled
text_file_format = rst
addopts = --doctest-rst
asdf_schema_root = specutils/io/asdf/schemas
asdf_schema_tests_enabled = true
filterwarnings =
error
ignore:distutils Version classes are deprecated:DeprecationWarning
ignore:unclosed file:ResourceWarning
ignore:numpy\.ndarray size changed:RuntimeWarning
ignore:invalid value encountered in .*divide:RuntimeWarning
ignore:.*contains multiple slashes:astropy.units.core.UnitsWarning
ignore::astropy.wcs.wcs.FITSFixedWarning
ignore:Input WCS indicates that the spectral axis is not last:UserWarning
ignore:No velocity defined on frame:astropy.coordinates.spectral_coordinate.NoVelocityWarning
ignore:No observer defined on WCS:astropy.utils.exceptions.AstropyUserWarning

[coverage:run]
omit =
Expand Down Expand Up @@ -86,6 +98,26 @@ exclude_lines =
# Don't complain about IPython completion helper
def _ipython_key_completions_

# TODO: Un-ignore and fix these warnings.
# E126 continuation line over-indented for hanging indent
# E127 continuation line over-indented for visual indent
# E128 continuation line under-indented for visual indent
# E201 whitespace after '{'
# E202 whitespace before ']'
# E203 whitespace before ','
# E221 multiple spaces before operator
# E225 missing whitespace around operator
# E226 missing whitespace around arithmetic operator
# E227 missing whitespace around bitwise or shift operator
# E231 missing whitespace after ','
# E251 unexpected spaces around keyword / parameter equals
# E501 line too long
# E731 do not assign a lambda expression, use a def
# E741 ambiguous variable name 'l'
# W503 line break before binary operator
# W504 line break after binary operator
# W505 doc line too long
[flake8]
max-line-length = 100
max-doc-length = 79
ignore = E126,E127,E128,E201,E202,E203,E221,E225,E226,E227,E231,E251,E501,E731,E741,W503,W504,W505
19 changes: 3 additions & 16 deletions specutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,11 @@
from astropy import config as _config
# ----------------------------------------------------------------------------

# Enforce Python version check during package import.
# This is the same check as the one at the top of setup.py
import sys

__minimum_python_version__ = "3.5"


class UnsupportedPythonError(Exception):
pass


if sys.version_info < tuple((int(val) for val in __minimum_python_version__.split('.'))):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this. This is now defined in setup.cfg.

raise UnsupportedPythonError("packagename does not support Python < {}".format(__minimum_python_version__))

if not _ASTROPY_SETUP_:
if not _ASTROPY_SETUP_: # noqa
# For egg_info test builds to pass, put package imports here.

# Allow loading spectrum object from top level module
from .spectra import *
from .spectra import * # noqa

# Load the IO functions
from .io.default_loaders import * # noqa
Expand All @@ -49,4 +35,5 @@ class Conf(_config.ConfigNamespace):
'to zero. If it is not within ``threshold`` then a warning is raised.'
)


conf = Conf()
1 change: 1 addition & 0 deletions specutils/analysis/template_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _uncertainty_to_standard_deviation(uncertainty):

return stddev


def _normalize_for_template_matching(observed_spectrum, template_spectrum, stddev=None):
"""
Calculate a scale factor to be applied to the template spectrum so the
Expand Down
3 changes: 1 addition & 2 deletions specutils/analysis/width.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

import numpy as np
from astropy.stats.funcs import gaussian_sigma_to_fwhm
from astropy.modeling.models import Gaussian1D
from ..manipulation import extract_region
from . import centroid
from .utils import computation_wrapper
from scipy.signal import chirp, find_peaks, peak_widths
from scipy.signal import find_peaks, peak_widths


__all__ = ['gaussian_sigma_width', 'gaussian_fwhm', 'fwhm', 'fwzi']
Expand Down
Loading