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

Fix for Astropy v7.0 incompatibility (#229) #232

Merged
merged 7 commits into from
Nov 27, 2024
24 changes: 16 additions & 8 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ API Changes
Bug Fixes
^^^^^^^^^

Other changes
^^^^^^^^^^^^^

1.4.2
------

Bug Fixes
^^^^^^^^^
- Fixed Astropy v7.0 incompatibility bug [#229] in ``tracing.FitTrace``: changed to use
``astropy.modeling.fitting.DogBoxLSQFitter`` when fitting a Gaussian peak model instead of
``astropy.modeling.fitting.LevMarLSQFitter`` that may be deprecated in the future. Also
changed to use ``fitting.LMLSQFitter`` instead of ``fitting.LevMarLSQFitter`` when fitting
a generic nonlinear trace model.

Other changes
^^^^^^^^^^^^^
- Changed ``tracing.FitTrace`` to use ``astropy.modeling.fitting.LinearLSQFitter``
if the trace model is linear.

1.4.1 (2024-06-20)
------------------

New Features
^^^^^^^^^^^^

API Changes
^^^^^^^^^^^

Bug Fixes
^^^^^^^^^
- Fix bug where Background one sided / two sided was not correctly assigning units to data. [#221]

Other changes
^^^^^^^^^^^^^

1.4.0 (2024-05-29)
------------------
Expand Down
6 changes: 3 additions & 3 deletions specreduce/tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,21 @@ def test_fit_trace_all_nan_cols(self):
4.6474359, 5.25, 5.8525641, 6.4551282, 7.0576923,
7.6602564]
max_trace = FitTrace(img, peak_method='max')
np.testing.assert_allclose(truth, max_trace.trace)
np.testing.assert_allclose(truth, max_trace.trace, atol=0.1)

# peak_method = 'gaussian'
truth = [1.947455, 2.383634, 2.8198131, 3.2559921, 3.6921712,
4.1283502, 4.5645293, 5.0007083, 5.4368874, 5.8730665,
6.3092455]
max_trace = FitTrace(img, peak_method='gaussian')
np.testing.assert_allclose(truth, max_trace.trace)
np.testing.assert_allclose(truth, max_trace.trace, atol=0.1)

# peak_method = 'centroid'
truth = [2.5318835, 2.782069, 3.0322546, 3.2824402, 3.5326257,
3.7828113, 4.0329969, 4.2831824, 4.533368, 4.7835536,
5.0337391]
max_trace = FitTrace(img, peak_method='centroid')
np.testing.assert_allclose(truth, max_trace.trace)
np.testing.assert_allclose(truth, max_trace.trace, atol=0.1)

@pytest.mark.filterwarnings("ignore:The fit may be unsuccessful")
@pytest.mark.filterwarnings("ignore:Model is linear in parameters")
Expand Down
17 changes: 11 additions & 6 deletions specreduce/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@
or `~astropy.modeling.spline.Spline1D`, optional
The 1-D polynomial model used to fit the trace to the bins' peak
pixels. Spline1D models are fit with Astropy's
'SplineSmoothingFitter', while the other models are fit with the
'LevMarLSQFitter'. [default: ``models.Polynomial1D(degree=1)``]
'SplineSmoothingFitter', generic linear models are fit with the
'LinearLSQFitter', while the other models are fit with the
'LMLSQFitter'. [default: ``models.Polynomial1D(degree=1)``]
peak_method : string, optional
One of ``gaussian``, ``centroid``, or ``max``.
``gaussian``: Fits a gaussian to the window within each bin and
Expand Down Expand Up @@ -295,7 +296,7 @@
offset_init = models.Const1D(np.ma.median(ztot))
profile = g1d_init + offset_init

fitter = fitting.LevMarLSQFitter()
fitter = fitting.DogBoxLSQFitter()
popt_tot = fitter(profile, yy, ztot)

# restrict fit to window (if one exists)
Expand Down Expand Up @@ -394,9 +395,13 @@
y_bins = y_bins[y_finite]

# use given model to bin y-values; interpolate over all wavelengths
fitter = (fitting.SplineSmoothingFitter()
if isinstance(self.trace_model, models.Spline1D)
else fitting.LevMarLSQFitter())
if isinstance(self.trace_model, models.Spline1D):
fitter = fitting.SplineSmoothingFitter()
elif self.trace_model.linear:
fitter = fitting.LinearLSQFitter()
else:
fitter = fitting.LMLSQFitter()

Check warning on line 403 in specreduce/tracing.py

View check run for this annotation

Codecov / codecov/patch

specreduce/tracing.py#L403

Added line #L403 was not covered by tests

self.trace_model_fit = fitter(self.trace_model, x_bins, y_bins)

trace_x = np.arange(img.shape[self._disp_axis])
Expand Down