From 36256514b559abd2a73f31702f80afe9b62c3f70 Mon Sep 17 00:00:00 2001 From: Chris Leaman Date: Mon, 4 Mar 2019 15:40:47 +1100 Subject: [PATCH] Allow crossing function to detect crossings at end points --- src/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils.py b/src/utils.py index f375ea6..f5b8067 100644 --- a/src/utils.py +++ b/src/utils.py @@ -32,11 +32,20 @@ def crossings(profile_x, profile_z, constant_z): indicies = np.where(z[:-1] * z[1:] < 0)[0] # Use linear interpolation to find intersample crossings. - return [ + x_crossings = [ profile_x[i] - (profile_x[i] - profile_x[i + 1]) / (z[i] - z[i + 1]) * (z[i]) for i in indicies ] + # Also need to check the end points as the above will not include them if they are close + x_crossings += [ + profile_x[i] + for i in [0, len(profile_z) - 1] + if np.isclose(constant_z, profile_z[i]) + ] + + return sorted(x_crossings) + # TODO Think of a better way to do this than having to manually specify the coordinate systems def convert_coord_systems(