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

Some updates to specutils.analysis functions #937

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

chloe-mt-cheng
Copy link
Contributor

  • Updated _normalize_for_template_matching(): changed np.sum to np.nansum on lines 60 and 61. Due to resampling of the spectra (resampling methods fill arrays with NaNs to have points beyond the edges set to NaN), all redshifts compared in template_redshift() were producing a chi2 of NaN (even for a test case using the correct redshift).
  • Updated _chi_square_for_templates(): changed np.sum to np.nansum on line 137 for the same reason as above.
  • Updated template_redshift(): Added final_spectrum = redshifted_spectrum on line 292 and added final_spectrum to return instead of redshifted spectrum. This is important specifically for if you feed a list of redshifts - the function was not returning the spectrum redshifted by the best-fitting redshift (i.e. the one corresponding to chi2_min), but rather was returning the spectrum redshifted by the last redshift in the list (not necessarily the best-fitting one).

@rosteen
Copy link
Contributor

rosteen commented Mar 28, 2022

Thanks @chloe-mt-cheng! I'll take a look at updating the failing tests, but these seem like sensible changes.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…i_square_for_templates and _normalize_for_template_matching to accept NaNs
@rosteen rosteen force-pushed the template_redshift_032222 branch from 264b0c9 to 714fdc9 Compare January 30, 2024 21:04
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (08e77ce) 70.78% compared to head (34ad35d) 70.80%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #937      +/-   ##
==========================================
+ Coverage   70.78%   70.80%   +0.02%     
==========================================
  Files          61       61              
  Lines        4213     4216       +3     
==========================================
+ Hits         2982     2985       +3     
  Misses       1231     1231              

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

@rosteen
Copy link
Contributor

rosteen commented Jan 30, 2024

@chloe-mt-cheng Sorry that I dropped the ball on this for so long! I updated the tests after confirming that the differences make sense, and made one more change to ensure that the same number of bins get summed for the numerator and denominator in the nansums.

@rosteen rosteen added this to the v1.x milestone Jan 30, 2024
@rosteen rosteen added enhancement analysis Spectral analysis/measurement tools labels Jan 30, 2024
@rosteen rosteen merged commit 30575fc into astropy:main Jan 30, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Spectral analysis/measurement tools enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants