1818 image [j , ::] *= j
1919image = Spectrum1D (image * u .DN ,
2020 uncertainty = VarianceUncertainty (np .ones_like (image )))
21+ image_um = Spectrum1D (image .flux ,
22+ spectral_axis = np .arange (image .data .shape [1 ]) * u .um ,
23+ uncertainty = VarianceUncertainty (np .ones_like (image .data )))
2124
2225
2326def test_background ():
@@ -29,13 +32,22 @@ def test_background():
2932 trace = FlatTrace (image , trace_pos )
3033 bkg_sep = 5
3134 bkg_width = 2
32- # all the following should be equivalent:
35+
36+ # all the following should be equivalent, whether image's spectral axis
37+ # is in pixels or physical units:
3338 bg1 = Background (image , [trace - bkg_sep , trace + bkg_sep ], width = bkg_width )
3439 bg2 = Background .two_sided (image , trace , bkg_sep , width = bkg_width )
3540 bg3 = Background .two_sided (image , trace_pos , bkg_sep , width = bkg_width )
3641 assert np .allclose (bg1 .bkg_array , bg2 .bkg_array )
3742 assert np .allclose (bg1 .bkg_array , bg3 .bkg_array )
3843
44+ bg4 = Background (image_um , [trace - bkg_sep , trace + bkg_sep ], width = bkg_width )
45+ bg5 = Background .two_sided (image_um , trace , bkg_sep , width = bkg_width )
46+ bg6 = Background .two_sided (image_um , trace_pos , bkg_sep , width = bkg_width )
47+ assert np .allclose (bg1 .bkg_array , bg4 .bkg_array )
48+ assert np .allclose (bg1 .bkg_array , bg5 .bkg_array )
49+ assert np .allclose (bg1 .bkg_array , bg6 .bkg_array )
50+
3951 # test that creating a one_sided background works
4052 Background .one_sided (image , trace , bkg_sep , width = bkg_width )
4153
@@ -51,6 +63,14 @@ def test_background():
5163 # assert np.allclose(sub1.flux, sub2.flux)
5264 assert np .allclose (sub2 .flux , sub3 .flux )
5365
66+ # NOTE: uncomment sub4 test once Spectrum1D and Background subtraction works
67+ # sub4 = image_um - bg4
68+ sub5 = bg4 .sub_image (image_um )
69+ sub6 = bg4 .sub_image ()
70+ assert np .allclose (sub2 .flux , sub5 .flux )
71+ # assert np.allclose(sub4.flux, sub5.flux)
72+ assert np .allclose (sub5 .flux , sub6 .flux )
73+
5474 bkg_spec = bg1 .bkg_spectrum ()
5575 assert isinstance (bkg_spec , Spectrum1D )
5676 sub_spec = bg1 .sub_spectrum ()
0 commit comments