From 2b62bd8e97b5fa22ee443faeeea0e7c155ef3e55 Mon Sep 17 00:00:00 2001
From: Paul Garlick <pgarlick@tourbillion-technology.com>
Date: Tue, 14 Jul 2020 10:45:17 +0100
Subject: python: slope.py: Use distance measured from botttom boundary.

* python/slope.py (plot_curve): Remove MY argument.  Use y co-ordinate
for fitting and plotting.
(save_xyz): Remove MY argument.  Use x and y co-ordinates for output.
---
 python/slope.py | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/python/slope.py b/python/slope.py
index c545b9f..e0ca3e1 100755
--- a/python/slope.py
+++ b/python/slope.py
@@ -122,11 +122,10 @@ def detach_display():
     fig.canvas.callbacks.disconnect(cid)
     #print(xMarker)
 
-def plot_curve(MY, PX):
+def plot_curve(PX):
     """
     Fit straight line to channel elevation data.  Pixel size PX is
-    used to convert pixel indices to co-ordinate values.  The maximum
-    co-ordinate value in the y-direction is MY.
+    used to convert pixel indices to co-ordinate values.
     """
     # sort markers by y value
     #yx = list(zip(yMarker, xMarker))
@@ -161,14 +160,13 @@ def plot_curve(MY, PX):
     # Add to list.  Repeat.
 
     # Fit with polyfit
-    m, c = np.polyfit([MY - y*PX for y in ych], zch, 1)
+    m, c = np.polyfit([(0.5 + y)*PX for y in ych], zch, 1)
     print('gradient =', m, 'intercept =', c)
-    # print('MY =', MY)
 
     fig, ax = plt.subplots()
-    line1, = ax.plot([MY - y*PX for y in ych], zch)
-    line2, = ax.plot([MY - y*PX for y in ych],
-                     [c + m*MY - m*y*PX for y in ych], '--')
+    line1, = ax.plot([(0.5 + y)*PX for y in ych], zch)
+    line2, = ax.plot([(0.5 + y)*PX for y in ych],
+                     [c + m*(0.5 + y)*PX for y in ych], '--')
     ax.set_xlabel('Distance / m')
     ax.set_ylabel('Height / m')
     ax.set_title('Channel profile')
@@ -181,18 +179,17 @@ def plot_curve(MY, PX):
     #fig.canvas.draw()
     #fig.canvas.flush_events()
 
-def save_xyz(MY, PX):
+def save_xyz(PX):
     """
     Write channel elevation data to file.  Pixel size PX is used to
-    convert pixel indices to co-ordinate values.  The maximum
-    co-ordinate value in the y-direction is MY.
+    convert pixel indices to co-ordinate values.
     """
     with open('1D.txt', 'w') as f:
         for xitem, yitem, zitem in zip(reversed(xch),
                                        reversed(ych),
                                        reversed(zch)):
-            f.write('{:.2f} {:.2f} {:.4f}\n'.format(PX/2.0+xitem*PX,
-                                                    MY-yitem*PX,
+            f.write('{:.2f} {:.2f} {:.4f}\n'.format((0.5 + xitem)*PX,
+                                                    (0.5 + yitem)*PX,
                                                     zitem))
     
 
@@ -217,8 +214,8 @@ while (True):
     elif(input_str == "m"):
         detach_display()
     elif(input_str == "p"):
-        plot_curve(ytp[-1], DY)
+        plot_curve(DY)
     elif(input_str == "s"):
-        save_xyz(ytp[-1], DY)
+        save_xyz(DY)
     
 #print("End.")
-- 
cgit