Skip to content

Fix for masked arrays and fitting when peak_method=gaussian - #329

Merged
cshanahan1 merged 1 commit into
astropy:mainfrom
cshanahan1:masked-fit-trace
Nov 18, 2026
Merged

cshanahan1 merged 1 commit into
astropy:mainfrom
cshanahan1:masked-fit-trace

Conversation

@cshanahan1

@cshanahan1 cshanahan1 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

FitTrace with peak_method="gaussian" fails with

TypeError: Inputs of type numpy.ma.MaskedArray are not supported.

when fitting against data/masks where scipy's stricter array-API input validation is active (SCIPY_ARRAY_API=1, which will become the default in the next scipy release and is currently causing test failures in jdaviz dev tests).

In FitTrace._fit_trace(), the calculation of ztot is done from img (ztot = img.mean(axis=self._disp_axis)), and img is always constructed as a masked array and so ztot remains a masked array when going through the fitter.

The fix is to exclude masked values before passing to the fitter, which is consistent with what is done elsewhere in specreduce with fitting (e.g fitter(profile_i, ilum2[~z_i.mask], z_i.data[~z_i.mask]), as well as in extract.py).

Existing tests already cover this scenario (and fail with scipy dev)

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.54%. Comparing base (333fb7b) to head (79e5be5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #329   +/-   ##
=======================================
  Coverage   92.54%   92.54%           
=======================================
  Files          18       18           
  Lines        2348     2348           
=======================================
  Hits         2173     2173           
  Misses        175      175           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cshanahan1 cshanahan1 changed the title Fix for masked arrays and fitting when peak_method=gaussian Fix for masked arrays and fitting when peak_method=gaussian, RTD build failure fix Nov 17, 2026
@cshanahan1 cshanahan1 changed the title Fix for masked arrays and fitting when peak_method=gaussian, RTD build failure fix Fix for masked arrays and fitting when peak_method=gaussian Nov 17, 2026

@kecnry kecnry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM - and confirmed that tests in the dev runner that are failing in other PRs are passing here. Thanks!

@cshanahan1
cshanahan1 merged commit f2a3083 into astropy:main Nov 18, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants