Skip to content

Commit

Permalink
Update test_background.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim authored Feb 28, 2025
1 parent ca209aa commit 02d8793
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions specreduce/tests/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ def test_background(mk_test_img_raw, mk_test_spec_no_spectral_axis,
assert np.isnan(bg.bkg_spectrum().flux).sum() == 0
assert np.isnan(bg.sub_spectrum().flux).sum() == 0

bkg_spec_avg = bg1.bkg_spectrum(bkg_statistic='average')
bkg_spec_avg = bg1.bkg_spectrum(bkg_statistic=np.nanmean)
assert_allclose(bkg_spec_avg.mean().value, 14.5, rtol=0.5)

bkg_spec_median = bg1.bkg_spectrum(bkg_statistic='median')
bkg_spec_median = bg1.bkg_spectrum(bkg_statistic=np.nanmedian)
assert_allclose(bkg_spec_median.mean().value, 14.5, rtol=0.5)

with pytest.raises(ValueError, match="Background statistic max is not supported. "
"Please choose from: average, median, or sum."):
bg1.bkg_spectrum(bkg_statistic='max')
# Also support whatever Spectrum1D.collapse() takes for some inputs
# but we do not advertise it.
bkg_spec_median_2 = bg1.bkg_spectrum(bkg_statistic="median") # np.nanmedian
assert_allclose(bkg_spec_median_2.mean().value, 14.5, rtol=0.5)


def test_warnings_errors(mk_test_spec_no_spectral_axis):
Expand Down

0 comments on commit 02d8793

Please sign in to comment.