From 5f547ea5d05687089ce236b4e692556a69aba414 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:27:19 -0400 Subject: [PATCH] Use TRFLSQFitter instead of LevMarLSQFitter (#3202) * Use TRFLSQFitter instead of LevMarLSQFitter as per Astropy recommendation * Copy updated blackbody test code from astropy --- CHANGES.rst | 6 +++++ .../model_fitting/tests/test_blackbody.py | 27 ++++++++----------- .../aper_phot_simple/aper_phot_simple.py | 4 +-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b371412871..c651c91ebd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -95,11 +95,17 @@ Cubeviz - Custom Spectrum1D writer format ``jdaviz-cube`` is removed. Use ``wcs1d-fits`` from ``specutils`` instead. [#2094] +- Aperture Photometry plugin now uses TRFLSQFitter to fit radial profile because LevMarLSQFitter + is no longer recommended by Astropy. [#3202] + Imviz ^^^^^ - Deprecated Rotate Canvas plugin was removed; use Orientation plugin instead. [#2878] +- Aperture Photometry plugin now uses TRFLSQFitter to fit radial profile because LevMarLSQFitter + is no longer recommended by Astropy. [#3202] + Mosviz ^^^^^^ diff --git a/jdaviz/configs/default/plugins/model_fitting/tests/test_blackbody.py b/jdaviz/configs/default/plugins/model_fitting/tests/test_blackbody.py index fc75bebfe9..ee3876a995 100644 --- a/jdaviz/configs/default/plugins/model_fitting/tests/test_blackbody.py +++ b/jdaviz/configs/default/plugins/model_fitting/tests/test_blackbody.py @@ -1,23 +1,16 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst # copied and modified from astropy: https://github.com/astropy/astropy/pull/12304 -"""Tests for physical functions.""" -# pylint: disable=no-member, invalid-name +"""Tests for blackbody functions.""" import pytest import numpy as np -from jdaviz.models import BlackBody -from astropy.modeling.fitting import LevMarLSQFitter - -from astropy.tests.helper import assert_quantity_allclose from astropy import units as u +from astropy.modeling.fitting import TRFLSQFitter +from astropy.tests.helper import assert_quantity_allclose +from astropy.utils.compat.optional_deps import HAS_SCIPY from astropy.utils.exceptions import AstropyUserWarning -from astropy.utils.compat.optional_deps import HAS_SCIPY # noqa - -__doctest_skip__ = ["*"] - - -# BlackBody tests +from jdaviz.models import BlackBody @pytest.mark.parametrize("temperature", (3000 * u.K, 2726.85 * u.deg_C)) @@ -61,10 +54,12 @@ def test_blackbody_return_units(): assert b(1.0 * u.micron).unit == u.MJy / u.sr -@pytest.mark.skipif("not HAS_SCIPY") +@pytest.mark.skipif(not HAS_SCIPY, reason="requires scipy") def test_blackbody_fit(): - fitter = LevMarLSQFitter() + fitter = TRFLSQFitter() + rtol = 0.54 + atol = 1e-15 b = BlackBody(3000 * u.K, scale=5e-17, output_units=u.Jy / u.sr) @@ -73,8 +68,8 @@ def test_blackbody_fit(): b_fit = fitter(b, wav, fnu, maxiter=1000) - assert_quantity_allclose(b_fit.temperature, 2840.7438355865065 * u.K) - assert_quantity_allclose(b_fit.scale, 5.803783292762381e-17) + assert_quantity_allclose(b_fit.temperature, 2840.7438355865065 * u.K, rtol=rtol) + assert_quantity_allclose(b_fit.scale, 5.803783292762381e-17, atol=atol) def test_blackbody_overflow(): diff --git a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py index db21424a24..fc2636762c 100644 --- a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py +++ b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py @@ -4,7 +4,7 @@ import numpy as np from astropy import units as u -from astropy.modeling.fitting import LevMarLSQFitter +from astropy.modeling.fitting import TRFLSQFitter from astropy.modeling import Parameter from astropy.modeling.models import Gaussian1D from astropy.time import Time @@ -876,7 +876,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None, # Fit Gaussian1D to radial profile data. if self.fit_radial_profile: - fitter = LevMarLSQFitter() + fitter = TRFLSQFitter() y_max = y_data.max() x_mean = x_data[np.where(y_data == y_max)].mean() std = 0.5 * (phot_table['semimajor_sigma'][0] +