Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Mar 25, 2024
1 parent c7fe46f commit 1d45f37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions specreduce/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,27 @@ def mk_gaussian_img(nrows=20, ncols=16, mean=10, stddev=4):

return col_model(index_arr.T)


def mk_img_non_flat_trace(nrows=40, ncols=100, amp=10, stddev=2):
"""
Makes an image with a gaussian source that has a non-flat trace dispersed
along the x axis.
"""
spec2d = np.zeros((nrows, ncols))
spec2dvar = np.ones((nrows, ncols))

for ii in range(spec2d.shape[1]):
mgaus = models.Gaussian1D(amplitude=amp,
mean=(9.+(20/spec2d.shape[1])*ii),
stddev=stddev)
rg = np.arange(0, spec2d.shape[0], 1)
gaus = mgaus(rg)
spec2d[:,ii] = gaus
spec2d[:, ii] = gaus

return spec2d


class TestMeasureCrossDispersionProfile():


@pytest.mark.parametrize('pixel', [None, 1, [1, 2, 3]])
def test_measure_cross_dispersion_profile(self, pixel):
"""
Expand All @@ -59,7 +58,7 @@ def test_measure_cross_dispersion_profile(self, pixel):
images.append(dat) # test unitless
images.append(dat * u.DN)
images.append(NDData(dat * u.DN))
images.append(Spectrum1D(flux = dat * u.DN))
images.append(Spectrum1D(flux=dat * u.DN))

for img in images:

Expand Down Expand Up @@ -104,7 +103,7 @@ def test_cross_dispersion_profile_non_flat_trace(self):
# the shape of the trace
peak_locs = [9, 10, 12, 13, 15, 16, 17, 19, 20, 22, 23, 24, 26, 27, 29]
for i, pixel in enumerate(range(0, image.shape[1], 7)):
profile = measure_cross_dispersion_profile(image,
profile = measure_cross_dispersion_profile(image,
trace=trace_fit,
width=None,
pixel=pixel,
Expand All @@ -116,10 +115,10 @@ def test_cross_dispersion_profile_non_flat_trace(self):
# not change since (there is some wiggling around though due to the
# fact that the trace is rolled to the nearest integer value. this can
# be smoothed with an interpolation option later on, but it is 'rough'
# for now). In this test case, the peak positions will all either
# for now). In this test case, the peak positions will all either
# be at pixel 20 or 21.
for i, pixel in enumerate(range(0, image.shape[1], 7)):
profile = measure_cross_dispersion_profile(image,
profile = measure_cross_dispersion_profile(image,
trace=trace_fit,
width=None,
pixel=pixel,
Expand All @@ -128,7 +127,6 @@ def test_cross_dispersion_profile_non_flat_trace(self):
peak_loc = (np.where(profile == max(profile))[0][0])
assert peak_loc in [20, 21]


def test_errors_warnings(self):
img = mk_gaussian_img(nrows=10, ncols=10)
with pytest.raises(ValueError,
Expand Down
6 changes: 3 additions & 3 deletions specreduce/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def measure_cross_dispersion_profile(image, trace=None, crossdisp_axis=0,
crossdisp_axis : int, optional
The index of the image's cross-dispersion axis. [default: 0]
width : tuple of int or None
Width around 'trace' to calculate profile. If None, then all rows in the cross-dispersion axis
will be used. [default: None]
Width around 'trace' to calculate profile. If None, then all rows in the
cross-dispersion axis will be used. [default: None]
pixel: int, list of int, or None
Pixel value(s) along the dispersion axis to return cross-dispersion profile.
If several specified in list, then the average (method set by `statistic`)
Expand Down Expand Up @@ -165,7 +165,7 @@ def measure_cross_dispersion_profile(image, trace=None, crossdisp_axis=0,
aligned_trace = None
if align_along_trace:
if not isinstance(trace, FlatTrace):
# note: image was transposed according to `crossdisp_axis`, so disp_axis will always be 1
# note: img was transposed according to `crossdisp_axis`: disp_axis will always be 1
aligned_trace = _align_along_trace(image, trace.trace,
disp_axis=1,
crossdisp_axis=0)
Expand Down

0 comments on commit 1d45f37

Please sign in to comment.