Add checking of inputs early in slope_from_profile

This allows us to exit early and suppresses the annoying warnings.
develop
Chris Leaman 6 years ago
parent 708606391f
commit 34ada7c12f

@ -316,7 +316,14 @@ def slope_from_profile(
""" """
# Need all data to get the slope # Need all data to get the slope
if any([x is None for x in [profile_x, profile_z, top_elevation, btm_elevation]]): # Check validity of profile arrays and return None if data is not good
for profile in [profile_x, profile_z]:
if all(np.isnan(profile)) or all(x is None for x in profile):
return None
# Check validity of elevation values
for ele in [top_elevation, btm_elevation]:
if np.isnan(ele) or ele is None:
return None return None
end_points = {"top": {"z": top_elevation}, "btm": {"z": btm_elevation}} end_points = {"top": {"z": top_elevation}, "btm": {"z": btm_elevation}}
@ -377,6 +384,11 @@ def slope_from_profile(
True if end_points["top"]["x"] < pts < end_points["btm"]["x"] else False True if end_points["top"]["x"] < pts < end_points["btm"]["x"] else False
for pts in profile_x for pts in profile_x
] ]
# Need at least two points to do linear regression
if sum(profile_mask) < 2:
return None
slope_x = np.array(profile_x)[profile_mask].tolist() slope_x = np.array(profile_x)[profile_mask].tolist()
slope_z = np.array(profile_z)[profile_mask].tolist() slope_z = np.array(profile_z)[profile_mask].tolist()
slope, _, _, _, _ = stats.linregress(slope_x, slope_z) slope, _, _, _, _ = stats.linregress(slope_x, slope_z)

Loading…
Cancel
Save