Skip to content

Commit

Permalink
MNT: Remove unused astropy version check, update doctest (#3114)
Browse files Browse the repository at this point in the history
* MNT: Remove unnecessary astropy version checks

* TST: Update model doctest
  • Loading branch information
pllim authored Jul 24, 2024
1 parent 6fb47ab commit 3de1b08
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 43 deletions.
19 changes: 3 additions & 16 deletions jdaviz/configs/cubeviz/plugins/tests/test_parsers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import astropy
import numpy as np
import pytest
from astropy import units as u
from astropy.utils.introspection import minversion
from astropy.wcs import WCS
from specutils import Spectrum1D
from glue.core.roi import XRangeROI
Expand All @@ -11,8 +9,6 @@

from jdaviz.utils import PRIHDR_KEY

ASTROPY_LT_5_3 = not minversion(astropy, "5.3")


@pytest.mark.filterwarnings('ignore')
def test_fits_image_hdu_parse(image_cube_hdu_obj, cubeviz_helper):
Expand Down Expand Up @@ -49,10 +45,7 @@ def test_fits_image_hdu_with_microns(image_cube_hdu_obj_microns, cubeviz_helper)
label_mouseover = cubeviz_helper.app.session.application._tools['g-coords-info']
label_mouseover._viewer_mouse_event(flux_viewer,
{'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
if ASTROPY_LT_5_3:
flux_unit_str = "erg / (Angstrom cm2 s)"
else:
flux_unit_str = "erg / (Angstrom s cm2)"
flux_unit_str = "erg / (Angstrom s cm2)"
assert label_mouseover.as_text() == (f'Pixel x=00.0 y=00.0 Value +5.00000e+00 1e-17 {flux_unit_str}', # noqa
'World 13h41m45.5759s +27d00m12.3044s (ICRS)',
'205.4398995981 27.0034178810 (deg)') # noqa
Expand Down Expand Up @@ -105,10 +98,7 @@ def test_fits_image_hdu_parse_from_file(tmpdir, image_cube_hdu_obj, cubeviz_help
label_mouseover = cubeviz_helper.app.session.application._tools['g-coords-info']
label_mouseover._viewer_mouse_event(flux_viewer,
{'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
if ASTROPY_LT_5_3:
flux_unit_str = "erg / (Angstrom cm2 s)"
else:
flux_unit_str = "erg / (Angstrom s cm2)"
flux_unit_str = "erg / (Angstrom s cm2)"
assert label_mouseover.as_text() == (f'Pixel x=00.0 y=00.0 Value +1.00000e+00 1e-17 {flux_unit_str}', # noqa
'World 13h41m46.5994s +26d59m58.6136s (ICRS)',
'205.4441642302 26.9996148973 (deg)')
Expand Down Expand Up @@ -138,10 +128,7 @@ def test_spectrum3d_parse(image_cube_hdu_obj, cubeviz_helper):
label_mouseover = cubeviz_helper.app.session.application._tools['g-coords-info']
label_mouseover._viewer_mouse_event(flux_viewer,
{'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
if ASTROPY_LT_5_3:
flux_unit_str = "erg / (Angstrom cm2 s)"
else:
flux_unit_str = "erg / (Angstrom s cm2)"
flux_unit_str = "erg / (Angstrom s cm2)"
assert label_mouseover.as_text() == (f'Pixel x=00.0 y=00.0 Value +1.00000e+00 1e-17 {flux_unit_str}', # noqa
'World 13h41m46.5994s +26d59m58.6136s (ICRS)',
'205.4441642302 26.9996148973 (deg)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from glue.core.roi import CircularROI, XRangeROI
from specutils import Spectrum1D

from jdaviz.configs.cubeviz.plugins.tests.test_parsers import ASTROPY_LT_5_3
from jdaviz.configs.default.plugins.model_fitting.initializers import MODELS

PYTEST_LT_8_0 = not minversion(pytest, "8.0.dev")
Expand Down Expand Up @@ -95,10 +94,7 @@ def test_register_model_with_uncertainty_weighting(specviz_helper, spectrum1d):
assert test_label in specviz_helper.app.data_collection

# Test that the parameter uncertainties were updated
if ASTROPY_LT_5_3:
expected_uncertainties = {'slope': 0.0003657, 'intercept': 2.529}
else:
expected_uncertainties = {'slope': 0.0007063584243707317, 'intercept': 4.885421320000062}
expected_uncertainties = {'slope': 0.0007063584243707317, 'intercept': 4.885421320000062}
result_model = modelfit_plugin._obj.component_models[0]
for param in result_model["parameters"]:
assert np.allclose(param["std"], expected_uncertainties[param["name"]], rtol=0.01)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import warnings
from datetime import datetime, timezone

import astropy
import numpy as np
from astropy import units as u
from astropy.modeling.fitting import LevMarLSQFitter
Expand All @@ -11,7 +10,6 @@
from astropy.time import Time
from glue.core.message import SubsetUpdateMessage
from ipywidgets import widget_serialization
from packaging.version import Version
from photutils.aperture import (ApertureStats, CircularAperture, EllipticalAperture,
RectangularAperture)
from traitlets import Any, Bool, Integer, List, Unicode, observe
Expand All @@ -27,8 +25,6 @@

__all__ = ['SimpleAperturePhotometry']

ASTROPY_LT_5_2 = Version(astropy.__version__) < Version('5.2')


@tray_registry('imviz-aper-phot-simple', label="Aperture Photometry")
class SimpleAperturePhotometry(PluginTemplateMixin, ApertureSubsetSelectMixin,
Expand Down Expand Up @@ -621,12 +617,8 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
gs = Gaussian1D(amplitude=y_max, mean=x_mean, stddev=std,
fixed={'amplitude': True},
bounds={'amplitude': (y_max * 0.5, y_max)})
if ASTROPY_LT_5_2:
fitter_kw = {}
else:
fitter_kw = {'filter_non_finite': True}
with warnings.catch_warnings(record=True) as warns:
fit_model = fitter(gs, x_data, y_data, **fitter_kw)
fit_model = fitter(gs, x_data, y_data, filter_non_finite=True)
if len(warns) > 0:
msg = os.linesep.join([str(w.message) for w in warns])
self.hub.broadcast(SnackbarMessage(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import pytest
import numpy as np
import astropy
import pytest
from astropy import units as u
from astropy.nddata import InverseVariance
from specutils import Spectrum1D
from astropy.utils.introspection import minversion
from astropy.wcs import WCS
from regions import PixCoord, CirclePixelRegion

ASTROPY_LT_5_3 = not minversion(astropy, "5.3")
from specutils import Spectrum1D


# On failure, should not crash; essentially a no-op.
Expand Down Expand Up @@ -112,7 +108,6 @@ def test_conv_no_data(specviz_helper, spectrum1d):
assert not hasattr(plg, 'flux_or_sb')


@pytest.mark.skipif(ASTROPY_LT_5_3, reason='this feature relies on astropy v5.3+')
def test_non_stddev_uncertainty(specviz_helper):
flux = np.ones(10) * u.Jy
stddev = 0.1
Expand Down
7 changes: 1 addition & 6 deletions jdaviz/models/physical_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"""
Models that have physical origins.
"""
# pylint: disable=invalid-name, no-member

import warnings

import numpy as np
Expand All @@ -17,9 +15,6 @@

__all__ = ["BlackBody"]

# ASTROPY_LT_5_3
__doctest_requires__ = {"BlackBody": ["astropy<5.3"]}


class BlackBody(Fittable1DModel):
"""
Expand Down Expand Up @@ -67,7 +62,7 @@ class BlackBody(Fittable1DModel):
>>> from astropy import units as u
>>> bb = models.BlackBody(temperature=5000*u.K)
>>> bb(6000 * u.AA) # doctest: +FLOAT_CMP
<Quantity 1.53254685e-05 erg / (cm2 Hz s sr)>
<Quantity 1.53254685e-05 erg / (Hz s sr cm2)>
.. plot::
:include-source:
Expand Down

0 comments on commit 3de1b08

Please sign in to comment.