18
18
image [j , ::] *= j
19
19
image = Spectrum1D (image * u .DN ,
20
20
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 )))
21
24
22
25
23
26
def test_background ():
@@ -29,13 +32,22 @@ def test_background():
29
32
trace = FlatTrace (image , trace_pos )
30
33
bkg_sep = 5
31
34
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:
33
38
bg1 = Background (image , [trace - bkg_sep , trace + bkg_sep ], width = bkg_width )
34
39
bg2 = Background .two_sided (image , trace , bkg_sep , width = bkg_width )
35
40
bg3 = Background .two_sided (image , trace_pos , bkg_sep , width = bkg_width )
36
41
assert np .allclose (bg1 .bkg_array , bg2 .bkg_array )
37
42
assert np .allclose (bg1 .bkg_array , bg3 .bkg_array )
38
43
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
+
39
51
# test that creating a one_sided background works
40
52
Background .one_sided (image , trace , bkg_sep , width = bkg_width )
41
53
@@ -51,6 +63,14 @@ def test_background():
51
63
# assert np.allclose(sub1.flux, sub2.flux)
52
64
assert np .allclose (sub2 .flux , sub3 .flux )
53
65
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
+
54
74
bkg_spec = bg1 .bkg_spectrum ()
55
75
assert isinstance (bkg_spec , Spectrum1D )
56
76
sub_spec = bg1 .sub_spectrum ()
0 commit comments