From 3f85ee2f0e41d1f2e8771c7f3d7ee8ac12f09ba3 Mon Sep 17 00:00:00 2001 From: Paul Garlick Date: Fri, 10 Jul 2020 12:45:10 +0100 Subject: python: slope.py: Use cell size in polyfit and plot functions. * python/slope.py (plot_curve)[PX]: New argument. --- python/slope.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/python/slope.py b/python/slope.py index 0bf99b3..cd1dea7 100755 --- a/python/slope.py +++ b/python/slope.py @@ -122,7 +122,11 @@ def detach_display(): fig.canvas.callbacks.disconnect(cid) #print(xMarker) -def plot_curve(): +def plot_curve(PX): + """ + Fit straight line to channel elevation data. Pixel size PX is + used to convert pixel indices to co-ordinate values. + """ # sort markers by y value #yx = list(zip(yMarker, xMarker)) #yx.sort() @@ -156,13 +160,13 @@ def plot_curve(): # Add to list. Repeat. # Fit with polyfit - m, c = np.polyfit([499.75 - y*0.5 for y in ych], zch, 1) + m, c = np.polyfit([499.75 - y*PX for y in ych], zch, 1) print('gradient =', m, 'intercept =', c) fig, ax = plt.subplots() - line1, = ax.plot([499.75 - y*0.5 for y in ych], zch) - line2, = ax.plot([499.75 - y*0.5 for y in ych], - [c + m*499.75 - m*y*0.5 for y in ych], '--') + line1, = ax.plot([499.75 - y*PX for y in ych], zch) + line2, = ax.plot([499.75 - y*PX for y in ych], + [c + m*499.75 - m*y*PX for y in ych], '--') ax.set_xlabel('Distance / m') ax.set_ylabel('Height / m') ax.set_title('Channel profile') @@ -206,7 +210,7 @@ while (True): elif(input_str == "m"): detach_display() elif(input_str == "p"): - plot_curve() + plot_curve(DY) elif(input_str == "s"): save_xyz() -- cgit