aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Garlick <pgarlick@tourbillion-technology.com>2020-07-14 10:45:17 +0100
committerPaul Garlick <pgarlick@tourbillion-technology.com>2020-07-14 10:45:17 +0100
commit2b62bd8e97b5fa22ee443faeeea0e7c155ef3e55 (patch)
tree3cdd772ee04a5439b71eac99d5b2ca5bd47762a5
parentdc6b9b8ac9c194ff7b5f7a913c0b8457323799b8 (diff)
downloadfullSWOF-utils-2b62bd8e97b5fa22ee443faeeea0e7c155ef3e55.tar.gz
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.
-rwxr-xr-xpython/slope.py27
1 files 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.")