Skip to content

Commit 7e4095e

Browse files
committed
Wrote min_ind_range function
1 parent 7ca875c commit 7e4095e

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

unit_tests.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_sigma_clipping_no_failures(self):
2323
self.assertTrue(new_xvals.all() == xvalues.all()
2424
and new_yvals.all() == yvalues.all())
2525

26+
27+
print("sigma_clipping no failures passed...")
28+
2629

2730
def test_sortxy(self):
2831
"""
@@ -41,6 +44,8 @@ def test_sortxy(self):
4144
self.assertTrue(list(sortedx) == list(range(1, 101)))
4245
self.assertTrue(list(sortedy) == list(range(401, 501)))
4346

47+
print("sortxy() passed...")
48+
4449

4550

4651
def test_sigma_clipping_failures1(self):
@@ -62,6 +67,8 @@ def test_sigma_clipping_failures1(self):
6267
self.assertTrue(np.array_equal(xvalues, new_xvals))
6368
self.assertTrue(np.array_equal(yvalues, new_yvals))
6469

70+
print("sigma_clipping_failures1 passed...")
71+
6572
def test_sigma_clipping_failures2(self):
6673
"""
6774
Tests sigma clipping function on failing the first and last elements.
@@ -81,33 +88,25 @@ def test_sigma_clipping_failures2(self):
8188
self.assertTrue(np.array_equal(xvalues, new_xvals))
8289
self.assertTrue(np.array_equal(yvalues, new_yvals))
8390

84-
# def test_sigma_clipping_failures3(self):
85-
# """
86-
# This ensures that the alert message is displayed if over 10% of
87-
# the pixels are removed.
88-
# """
89-
# xvalues = np.arange(10)
90-
# yvalues = np.random.normal(10, 3, 10)
91-
# yvalues[3] = -5
92-
# yvalues[5] = 100
93-
94-
# new_xvals, new_yvals = util.sigma_clip(xvalues, yvalues)
95-
96-
# xvalues = np.delete(xvalues, [3, 5])
97-
# yvalues = np.delete(yvalues, [3, 5])
98-
99-
# message = "Over 10% of pixels have been rejected in the sigma_clip routine."
100-
101-
# expected = """
102-
# ==========================
103-
# Warning: %s
104-
# ==========================
105-
# """
106-
# captured = sys.__stdout__
107-
# print(sys.__stdout__)
108-
# print(expected % message)
109-
110-
# self.assertEqual(expected, captured)
91+
print("sigma_clipping_failures2 passed...")
92+
93+
94+
def test_min_ind_range(self):
95+
test_array1 = [1, 3, 4, 5, 9, 0, 3, 4, -1, 30]
96+
start, end = 2, 5
97+
min_ind = util.min_ind_range(test_array1, start, end)
98+
self.assertTrue(min_ind == 2)
99+
100+
start, end = 0, len(test_array1)//2
101+
min_ind = util.min_ind_range(test_array1, start, end)
102+
self.assertTrue(min_ind == 0)
103+
104+
start, end = len(test_array1)//2, len(test_array1)
105+
min_ind = util.min_ind_range(test_array1, start, end)
106+
self.assertTrue(min_ind == 8)
107+
108+
print("min_ind_range() tests passed...")
109+
111110

112111

113112
if __name__ == "__main__":

util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ def plot(self):
199199
plt.plot(x, y, color=color)
200200

201201

202+
def min_ind_range(array, start, end):
203+
"""
204+
Obtains the indices of the absolute minima of the first parameter
205+
in the range provided by the 2nd and 3rd parameter.
206+
"""
207+
temp = array[start:end]
208+
min_ind_temp = np.argmin(temp)
209+
min_ind_real = start + min_ind_temp
210+
return min_ind_real
202211

203212

204213
def get_vmin_vmax(image):

0 commit comments

Comments
 (0)