I am writing a Python script that should interactively allow the user to select and remove a datum from further calculations, however, because my y-axis data are in the range of e-9 to e-14 (a single analysis contains data over a single order of magnitude, but that order of magnitude may be between e-9 and e-14), and my x-axis data are in the range of 10-100, the differences in order of magnitude causes the y-axis to dominate the closest distance calculation. As a result, if I have two data represented by *
, and a click point represented by x
:
|
| *
|
|
|
|
| x *
|__________________
The click point is clearly closer to the lower datum, however, because the y-axis dominates the closest point calculation, it’s the higher datum that is selected.
I’ve tried scaling the time data (x-axis) down to the order of magnitude of the raw data (y-axis), and vice versa, as such:
# this finds the closest datum to the click point
def find_closest_index(analysis, click_coords, mass):
y_magnitude = np.floor(np.log10(np.max(analysis.raw_data[mass])))
scale_factor = 10**abs(y_magnitude - 1)
scaled_data = analysis.raw_data[mass] * scale_factor
distances = np.sqrt(
(analysis.time_sec - click_coords[0])**2 +
(scaled_data - click_coords[1])**2
)
# find the closest index
closest_index = distances.argmin()
return closest_index
Setting the scale_factor to y_magnitude - 1
produces scaled y-axis data on the order of 10-100, which should be correct, however, the behavior described above persists. Changing -1
to -3
or +3
ends up incorrectly selecting the maximum or minimum datum and I haven’t found an intermediate value that changes the fundamental behavior described above.
What can I do to resolve this behavior and ensure that the lower datum is correctly selected?
ohshitgorillas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.