Skip to content

Commit 3ca3426

Browse files
Replace calls to .take() with plain NumPy indexing
1 parent 39f1626 commit 3ca3426

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

skyfield/searchlib.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ def _find_discrete(ts, jd, f, epsilon, num):
5858
indices = flatnonzero(diff(y))
5959
if not len(indices):
6060
# Nothing found, so immediately return empty arrays.
61-
ends = jd.take(indices)
62-
y = y.take(indices)
61+
ends = jd[indices]
62+
y = y[indices]
6363
break
6464

65-
starts = jd.take(indices)
66-
ends = jd.take(indices + 1)
65+
starts = jd[indices]
66+
ends = jd[indices + 1]
6767

6868
# Since we start with equal intervals, they all should fall
6969
# below epsilon at around the same time; so for efficiency we
7070
# only test the first pair.
7171
if ends[0] - starts[0] <= epsilon:
72-
y = y.take(indices + 1)
72+
y = y[indices + 1]
7373
# Keep only the last of several zero crossings that might
7474
# possibly be separated by less than epsilon.
7575
mask = concatenate(((diff(ends) > 3.0 * epsilon), (True,)))
@@ -174,8 +174,8 @@ def find_maxima(start_time, end_time, f, epsilon=1.0 / DAY_S, num=12):
174174
jd = y = y[0:0]
175175
break
176176

177-
starts = jd.take(left)
178-
ends = jd.take(right)
177+
starts = jd[left]
178+
ends = jd[right]
179179

180180
jd = o(starts, start_alpha).flatten() + o(ends, end_alpha).flatten()
181181
jd = _remove_adjacent_duplicates(jd)
@@ -197,21 +197,21 @@ def _identify_maxima(x, y):
197197

198198
# Choose every point that is higher than the two adjacent points.
199199
indices = flatnonzero(dsd == -2) + 1
200-
peak_x = x.take(indices)
201-
peak_y = y.take(indices)
200+
peak_x = x[indices]
201+
peak_y = y[indices]
202202

203203
# Also choose the midpoint between the edges of a plateau, if both
204204
# edges are in view. First we eliminate runs of zeroes, then look
205205
# for adjacent -1 values, then map those back to the main array.
206206
indices = flatnonzero(dsd)
207-
dsd2 = dsd.take(indices)
207+
dsd2 = dsd[indices]
208208
minus_ones = dsd2 == -1
209209
plateau_indices = flatnonzero(minus_ones[:-1] & minus_ones[1:])
210-
plateau_left_indices = indices.take(plateau_indices)
211-
plateau_right_indices = indices.take(plateau_indices + 1) + 2
212-
plateau_x = x.take(plateau_left_indices) + x.take(plateau_right_indices)
210+
plateau_left_indices = indices[plateau_indices]
211+
plateau_right_indices = indices[plateau_indices + 1] + 2
212+
plateau_x = x[plateau_left_indices] + x[plateau_right_indices]
213213
plateau_x /= 2.0
214-
plateau_y = y.take(plateau_left_indices + 1)
214+
plateau_y = y[plateau_left_indices + 1]
215215

216216
x = concatenate((peak_x, plateau_x))
217217
y = concatenate((peak_y, plateau_y))

0 commit comments

Comments
 (0)