Skip to content

Commit

Permalink
Use TRFLSQFitter instead of LevMarLSQFitter (#3202)
Browse files Browse the repository at this point in the history
* Use TRFLSQFitter instead of LevMarLSQFitter
as per Astropy recommendation

* Copy updated blackbody test code from astropy
  • Loading branch information
pllim authored Sep 26, 2024
1 parent 32bb09e commit 5f547ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^

Expand Down
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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)

Expand All @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] +
Expand Down

0 comments on commit 5f547ea

Please sign in to comment.