Skip to content

Commit 74472c6

Browse files
authored
Merge pull request #41 from SWIFTSIM/bug_stretch_final_bin
Bug in plots with adaptive binning
2 parents ec20f65 + ca7e039 commit 74472c6

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

velociraptor/tools/adaptive.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,18 @@ def create_adaptive_bins(
190190
number_in_bin.append(current_bin_count)
191191
elif current_bin_count == 1:
192192
# Extend the previous bin (otherwise error is consistent with zero)
193-
bin_edges_right[-1] = value
194-
number_in_bin[-1] += 1
195-
bin_medians[-1] = np.median(sorted_values[-number_in_bin[-1] :])
196-
# We don't need the next bin now.
197-
bin_edges_left = bin_edges_left[:-1]
193+
try:
194+
bin_edges_right[-1] = value
195+
number_in_bin[-1] += 1
196+
bin_medians[-1] = np.median(sorted_values[-number_in_bin[-1]:])
197+
# We don't need the next bin now.
198+
bin_edges_left = bin_edges_left[:-1]
199+
200+
# There is no previous bin because we have just one bin in total
201+
except IndexError:
202+
bin_edges_right.append(value)
203+
number_in_bin.append(1)
204+
bin_medians.append(sorted_values[-1])
198205
else:
199206
# This bin doesn't exist anyway, boo...
200207
bin_edges_left = bin_edges_left[:-1]

velociraptor/tools/mass_functions.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,18 @@ def create_adaptive_mass_function(
272272
number_in_bin.append(current_bin_count)
273273
elif current_bin_count == 1:
274274
# Extend the previous bin (otherwise error is consistent with zero)
275-
bin_edges_right[-1] = mass
276-
number_in_bin[-1] += 1
277-
bin_medians[-1] = np.median(sorted_masses[-number_in_bin[-1] :])
278-
# We don't need the next bin now.
279-
bin_edges_left = bin_edges_left[:-1]
275+
try:
276+
bin_edges_right[-1] = mass
277+
number_in_bin[-1] += 1
278+
bin_medians[-1] = np.median(sorted_masses[-number_in_bin[-1] :])
279+
# We don't need the next bin now.
280+
bin_edges_left = bin_edges_left[:-1]
281+
282+
# There is no previous bin because we have just one bin in total
283+
except IndexError:
284+
bin_edges_right.append(mass)
285+
number_in_bin.append(1)
286+
bin_medians.append(sorted_masses[-1])
280287
else:
281288
# This bin doesn't exist anyway, boo...
282289
bin_edges_left = bin_edges_left[:-1]

0 commit comments

Comments
 (0)