From 2dba58b800b6795717c043a56d349f741c51a052 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 8 Jan 2019 20:21:51 +1300 Subject: [PATCH 01/14] enhancement: show depth/WSE, n and slope in cross-section display --- flow_estimator_dialog.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index 7975df3..f96c918 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -132,7 +132,12 @@ def plotter(self): if Q != 0: self.axes.plot(xWater, yWater, 'blue') self.axes.fill_between(xWater, yWater, yWater0, where=yWater>=yWater0, facecolor='blue', interpolate=True, alpha = 0.1) - self.outText = 'R: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth) + if self.calcType == 'DEM': + self.outText = 'INPUT\n\nSlope: {7:.5f}\nRoughness: {8:.2f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbWSE.value()) + elif self.calcType == 'UD': + self.outText = 'INPUT\n\nSlope: {7:.5f}\nRoughness: {8:.2f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbUDwse.value()) + else: + self.outText = 'INPUT\n\nSlope: {7:.5f}\nRoughness: {8:.2f}\nDepth: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.depth.value()) self.axes.set_xlabel('Station, '+self.units) self.axes.set_ylabel('Elevation, '+self.units) self.axes.set_title('Cross Section') @@ -145,7 +150,7 @@ def plotter(self): def refreshPlotText(self): - self.axes.annotate(self.outText, xy=(.8,.35), xycoords='figure fraction') + self.axes.annotate(self.outText, xy=(.8,0.17), xycoords='figure fraction') #at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") #self.axes.add_artist(at) self.mplCanvas.draw() @@ -510,7 +515,7 @@ def accept(self): wseMin = self.cbUDwse.minimum() else: - outHeader += '\n'*5 + 'Type:\tTrapizodal Channel\nUnits:\t{0}\nChannel Slope:\t{1:.06f}\nMannings n:\t{2:.02f}\nBottom Width:\t{3:.02f}\nRight Side Slope:\t{4:.02f}\nLeft Side Slope:\t{5:.02f}\n'.format(self.units, self.slope.value(), self.n.value(), self.botWidth.value(), self.rightSS.value(), self.leftSS.value()) + outHeader += '\n'*5 + 'Type:\tTrapezoidal Channel\nUnits:\t{0}\nChannel Slope:\t{1:.06f}\nMannings n:\t{2:.02f}\nBottom Width:\t{3:.02f}\nRight Side Slope:\t{4:.02f}\nLeft Side Slope:\t{5:.02f}\n'.format(self.units, self.slope.value(), self.n.value(), self.botWidth.value(), self.rightSS.value(), self.leftSS.value()) outFile.write(outHeader) wseMax = self.depth.value() wseMin = 0.0 From cee590a8c013c1a319c34ddba597efad074ba651 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Wed, 24 Jul 2019 16:01:03 +1200 Subject: [PATCH 02/14] remove rubbish files --- .DS_Store | Bin 6148 -> 0 bytes flow_estimator_dialog_base.ui.autosave | 602 ------------------------- 2 files changed, 602 deletions(-) delete mode 100644 .DS_Store delete mode 100644 flow_estimator_dialog_base.ui.autosave diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index a9d21b6942c9bcfdb65cf6d72d4c1dd96e379376..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5ZAgIN> zLDKcY*n|1|R5UsMBLld12J5hZg{=E^|GaJ}lC)BJTy5vlU7r` z??m`%r){k?dch^6HryyU7K!jgDAFslfKS_69S%3EJ7v3C-5QncVXamHd%H3km3ZDX z*Veao4^O+J>zmuV`-jJ;=NGjN94kjzQZOE0#}*mH05L!e%qj!=1T+_CwLq$i7$63I z%>bScHYlQ_F;ggy4j5z$0BC?)3fS07V2-WP(U>WO6%ejc0aYs3Ee2QV;J0<0qcKyc z(izvy2iITbx+pVChBNLcq>&gP1|}JpQ&S7?|AU|V|H&kp5d*})OfkTX{pNlh zO44`hRB?FM+MpMpC>WP19H)RGuVRSBt9TVu3ixd_03D5)LhyjlkAS3s24dh(8TbHv CCSF?r diff --git a/flow_estimator_dialog_base.ui.autosave b/flow_estimator_dialog_base.ui.autosave deleted file mode 100644 index 7d7421b..0000000 --- a/flow_estimator_dialog_base.ui.autosave +++ /dev/null @@ -1,602 +0,0 @@ - - - DrainageChannelFlowEstimatorDialogBase - - - - 0 - 0 - 616 - 644 - - - - Drainage Channel Flow Estimator - - - true - - - - QLayout::SetMinimumSize - - - - - - 0 - 250 - - - - - - - - - - - - - QTabWidget::East - - - 0 - - - - Program - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 16777215 - 373 - - - - Inputs - - - - - - - 0 - 164 - - - - 0 - - - - Trapezoidal Channel - - - - - - 0.010000000000000 - - - 0.250000000000000 - - - 2.000000000000000 - - - - - - - 0.010000000000000 - - - 0.250000000000000 - - - 2.000000000000000 - - - - - - - 0.010000000000000 - - - 999.000000000000000 - - - 5.000000000000000 - - - - - - - 0.010000000000000 - - - 0.500000000000000 - - - 5.000000000000000 - - - - - - - Bottom Width - - - - - - - Water Depth - - - - - - - Right Side Slope (width/height ratio) - - - true - - - - - - - Left Side Slope (width/height ratio) - - - true - - - - - - - - Channel from DEM - - - - - - - - Water Surface Elevation - - - - - - - 2 - - - 999999.000000000000000 - - - 0.100000000000000 - - - - - - - DEM - - - - - - - - - - - - - - - 0 - 0 - - - - Draw Cross Section (looking downstream from left to right) - - - true - - - - - - - Draw Cross Section - - - - - - - - - - - Use DEM to estimate slope - - - - - - - Estimate slope from DEM - - - - - - - - - - User Defined Channel - - - - - - - - Water Surface Elevation - - - - - - - - 100 - 16777215 - - - - 2 - - - 999999.989999999990687 - - - 0.100000000000000 - - - - - - - - - - - Text File of Station and Elevation Values (space or tab delimited, no header) - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - ... - - - - - - - - - - - - - - 0 - 14 - - - - - - - Units - - - - - - - - 0 - 0 - - - - - - - ft - - - true - - - - - - - m - - - - - - - - - - Manning's Roughness Coefficent - - - true - - - - - - - 3 - - - 0.001000000000000 - - - 0.005000000000000 - - - 0.040000000000000 - - - - - - - 5 - - - 0.000000000000000 - - - 0.000010000000000 - - - 0.000500000000000 - - - - - - - - 0 - 0 - - - - Slope of Channel - - - true - - - - - - - - - - - - - - Documentation - - - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface'; font-size:18pt; font-weight:600;">Flow Estimator - A Uniform, Steady Open Channel Flow Calculator for QGIS</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface'; font-size:18pt; font-weight:600;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface'; font-weight:600;">Description</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface'; font-weight:600;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">This plugin calculates flow and velocity using the Manning equation for uniform, steady flow. </span><span style=" font-family:'.Helvetica Neue DeskInterface'; font-weight:600;">If you've never heard of the Manning equation or taken a course in open channel hydraulics you won't understand what this tool is doing</span><span style=" font-family:'.Helvetica Neue DeskInterface';">.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">If you are familar with open channel hydraulics and want a quick refresher check out this information from the Univeristy of Delaware:</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">http://udel.edu/~inamdar/EGTE215/Open_channel.pdf</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">A great reference for Mannings n values can be found from the USGS here:</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">http://pubs.usgs.gov/wsp/2339/report.pdf</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface'; font-weight:600;">User Defined Cross Section</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">The user defined cross section option allows the use of a tab or space delimited text file without a header. The first column should contain the station values and the following column should contain elevation values.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface'; font-weight:600;">Final Considerations</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">Make sure the steady, uniform flow assumption is valid!</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">When sampling a DEM cross-section be sure to make the cross-section perpendicular to flow at a location that is representative of the stream or drainage channel.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.Helvetica Neue DeskInterface';">When sampling DEM cross-sections and slopes, make sure the DEM is in the same CRS as the project CRS (but you knew that already right!).</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';"><br /></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface'; font-size:18pt; font-weight:600;"><br /></p></body></html> - - - - - - - - - - - - - Output Directory - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - ... - - - - - - - - 16777215 - 16777215 - - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Ok - - - - - - - - - tabWidget - depth - botWidth - leftSS - rightSS - ft - m - slope - n - cbWSE - cbDEM - btnSampleSlope - - - - - buttonBox - accepted() - DrainageChannelFlowEstimatorDialogBase - accept() - - - 414 - 634 - - - 20 - 20 - - - - - buttonBox - rejected() - DrainageChannelFlowEstimatorDialogBase - reject() - - - 414 - 634 - - - 20 - 20 - - - - - From 2cfa638bf6bcd9dba64f353208394b83af10a162 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Fri, 26 Jul 2019 12:48:01 +1200 Subject: [PATCH 03/14] use modern (i.e. metric) units by default --- flow_estimator_dialog_base.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flow_estimator_dialog_base.ui b/flow_estimator_dialog_base.ui index 7d7421b..c35d86f 100644 --- a/flow_estimator_dialog_base.ui +++ b/flow_estimator_dialog_base.ui @@ -371,9 +371,6 @@ ft - - true - @@ -381,6 +378,9 @@ m + + true + From a4f246a5801d1d520f1796817a6b574c24a102d8 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Fri, 26 Jul 2019 12:57:46 +1200 Subject: [PATCH 04/14] Bugfixes and minor enhancements I've been using for months. Fix typos. --- flow_estimator_dialog.py | 39 +++++++++++++++++++++++++++++++---- flow_estimator_dialog_base.ui | 4 ++-- ptmaptool.py | 5 +++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index f96c918..ed335f5 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -7,7 +7,7 @@ ------------------- begin : 2015-05-21 git sha : $Format:%H$ - copyright : (C) 2015 by M. Weier - North Dakota State Water Commision + copyright : (C) 2015 by M. Weier - North Dakota State Water Commission email : mweier@nd.gov ***************************************************************************/ @@ -63,6 +63,8 @@ def __init__(self, iface, parent=None): self.btnClose = self.buttonBox.button(QtGui.QDialogButtonBox.Close) self.btnBrowse.clicked.connect(self.writeDirName) self.btnLoadTXT.clicked.connect(self.loadTxt) + # ajh trying to make it work + #self.inputFile.textChanged.connect(self.run) self.btnSampleLine.setEnabled(False) self.btnSampleSlope.setEnabled(False) self.calcType = 'Trap' @@ -101,6 +103,8 @@ def __init__(self, iface, parent=None): self.ft.clicked.connect(self.run) self.m.clicked.connect(self.run) self.cbUDwse.valueChanged.connect(self.run) + #ajh: this doesn't fix it + #self.btnRefresh.clicked.connect(self.run) self.manageGui() @@ -178,6 +182,7 @@ def run(self): try: self.calcType = 'UD' + #print 'self.cbUDwse.value(), self.n.value(), self.slope.value(), staElev = self.staElev, units = self.units' self.args = flowEstimator(self.cbUDwse.value(), self.n.value(), self.slope.value(), staElev = self.staElev, units = self.units) self.plotter() except: @@ -187,7 +192,10 @@ def run(self): def sampleLine(self): try: - self.deactivate() + # ajh: this doesn't seem to do anything on Windows + self.iface.deactivate() + # ajh: this causes an error + #self.iface.mainWindow.setWindowState(Qt.WindowNoState) except: pass self.btnSampleLine.setEnabled(False) @@ -218,7 +226,7 @@ def rubberBand(self): else: self.tool = ProfiletoolMapTool(self.canvas, self.btnSampleSlope) #the mouselistener self.pointstoDraw = None #Polyline in mapcanvas CRS analysed - self.dblclktemp = False #enable disctinction between leftclick and doubleclick + self.dblclktemp = False #enable distinction between leftclick and doubleclick self.selectionmethod = 0 #The selection method defined in option self.saveTool = self.canvas.mapTool() #Save the standard mapttool for restoring it at the end self.textquit0 = "Click for polyline and double click to end (right click to cancel then quit)" @@ -278,6 +286,13 @@ def rightClicked(self,position): #used to quit the current action self.rubberband.reset(self.polygon) else: self.cleaning() + # ajh: need this otherwise the plugin needs to be restarted to reenable the button + if self.sampleBtnCode == 'sampleLine': + self.btnSampleLine.setEnabled(True) + else : + self.btnSampleSlope.setEnabled(True) + # ajh: need to raise the window + self.activateWindow() @@ -310,6 +325,7 @@ def doubleClicked(self,position): self.staElev, error = self.doRubberbandProfile() if error: self.deactivate() + #ajh it would be good to restart the selection again after an error else: self.doIrregularProfileFlowEstimator() self.btnSampleLine.setEnabled(True) @@ -318,6 +334,7 @@ def doubleClicked(self,position): staElev, error = self.doRubberbandProfile() if error: self.deactivate() + #ajh it would be good to restart the selection again after an error else: self.doRubberbandSlopeEstimator(staElev) self.btnSampleSlope.setEnabled(True) @@ -329,7 +346,19 @@ def doubleClicked(self,position): #temp point to distinct leftclick and dbleclick self.dblclktemp = newPoints self.iface.mainWindow().statusBar().showMessage(self.textquit0) - self.iface.mainWindow().activateWindow() + + # ajh trying to make something like this work: + #self.iface.mainWindow.setWindowState(self.iface.mainWindow.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) + #self.iface.mainWindow.raise_() + #self.iface.mainWindow.show() + + # ajh: thought this just wasn't working on windows as per + # https://stackoverflow.com/questions/22815608/how-to-find-the-active-pyqt-window-and-bring-it-to-the-front + # see https://forum.qt.io/topic/1939/activatewindow-does-not-send-window-to-front/11 + #self.iface.mainWindow.activateWindow() + + # but actually, this is the solution: + self.activateWindow() return @@ -482,6 +511,8 @@ def loadTxt(self): self.calcType = 'UD' self.doIrregularProfileFlowEstimator() except: + if (filePath == ('')): # null string for cancel + return QMessageBox.warning(self,'Error', 'Please check that the text file is space or tab delimited and does not contain header information') diff --git a/flow_estimator_dialog_base.ui b/flow_estimator_dialog_base.ui index c35d86f..eadc43a 100644 --- a/flow_estimator_dialog_base.ui +++ b/flow_estimator_dialog_base.ui @@ -421,10 +421,10 @@ 0.000000000000000 - 0.000010000000000 + 0.001000000000000 - 0.000500000000000 + 0.0050000000000000 diff --git a/ptmaptool.py b/ptmaptool.py index d95fc0a..083bb20 100644 --- a/ptmaptool.py +++ b/ptmaptool.py @@ -54,8 +54,9 @@ def canvasDoubleClickEvent(self,event): def activate(self): QgsMapTool.activate(self) self.canvas.setCursor(self.cursor) - self.button.setCheckable(True) - self.button.setChecked(True) + # ajh: I don't think this is necessary. You could say that it indicates the button has been used, but that doesn't mean the graph is necessarily showing output matching it (the user could have subsequently used Trapezoidal Channel etc) + #self.button.setCheckable(True) + #self.button.setChecked(True) def deactivate(self): From dd82f64b76f9b08993489aa963c00f5153bcd4da Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Fri, 26 Jul 2019 14:26:49 +1200 Subject: [PATCH 05/14] fix more typos --- FlowEstimator_utils.py | 2 +- Makefile | 2 +- __init__.py | 2 +- flow_estimator.py | 2 +- flow_estimator_dialog.py | 2 +- help/source/conf.py | 6 +++--- metadata.txt | 2 +- pb_tool.cfg | 2 +- test/test_flow_estimator_dialog.py | 2 +- test/test_resources.py | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/FlowEstimator_utils.py b/FlowEstimator_utils.py index ef91953..044e98c 100644 --- a/FlowEstimator_utils.py +++ b/FlowEstimator_utils.py @@ -7,7 +7,7 @@ ------------------- begin : 2015-05-21 git sha : $Format:%H$ - copyright : (C) 2015 by M. Weier - North Dakota State Water Commision + copyright : (C) 2015 by M. Weier - North Dakota State Water Commission email : mweier@nd.gov ***************************************************************************/ diff --git a/Makefile b/Makefile index 23713c8..5db285b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ # ------------------- # begin : 2015-05-21 # git sha : $Format:%H$ -# copyright : (C) 2015 by M. Weier - North Dakota State Water Commision +# copyright : (C) 2015 by M. Weier - North Dakota State Water Commission # email : mweier@nd.gov # ***************************************************************************/ # diff --git a/__init__.py b/__init__.py index 51484a0..2ceafe1 100644 --- a/__init__.py +++ b/__init__.py @@ -6,7 +6,7 @@ Estimates steady, uniform flow using the Manning equation for trapezoidal and DEM sampled channels. ------------------- begin : 2015-05-21 - copyright : (C) 2015 by M. Weier - North Dakota State Water Commision + copyright : (C) 2015 by M. Weier - North Dakota State Water Commission email : mweier@nd.gov git sha : $Format:%H$ ***************************************************************************/ diff --git a/flow_estimator.py b/flow_estimator.py index 94ccac7..8d8f3b4 100644 --- a/flow_estimator.py +++ b/flow_estimator.py @@ -7,7 +7,7 @@ ------------------- begin : 2015-05-21 git sha : $Format:%H$ - copyright : (C) 2015 by M. Weier - North Dakota State Water Commision + copyright : (C) 2015 by M. Weier - North Dakota State Water Commission email : mweier@nd.gov ***************************************************************************/ diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index ed335f5..bb49388 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -220,7 +220,7 @@ def rubberBand(self): print 'rubberband ' self.canvas = self.iface.mapCanvas() - #Init classe variables + #Init class variables if self.sampleBtnCode=='sampleLine': self.tool = ProfiletoolMapTool(self.canvas, self.btnSampleLine) #the mouselistener else: diff --git a/help/source/conf.py b/help/source/conf.py index af70957..663fdc0 100644 --- a/help/source/conf.py +++ b/help/source/conf.py @@ -41,7 +41,7 @@ # General information about the project. project = u'FlowEstimator' -copyright = u'2013, M. Weier - North Dakota State Water Commision' +copyright = u'2013, M. Weier - North Dakota State Water Commission' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -179,7 +179,7 @@ # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'FlowEstimator.tex', u'FlowEstimator Documentation', - u'M. Weier - North Dakota State Water Commision', 'manual'), + u'M. Weier - North Dakota State Water Commission', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -212,5 +212,5 @@ # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'TemplateClass', u'FlowEstimator Documentation', - [u'M. Weier - North Dakota State Water Commision'], 1) + [u'M. Weier - North Dakota State Water Commission'], 1) ] diff --git a/metadata.txt b/metadata.txt index 85c1cc5..75365b5 100644 --- a/metadata.txt +++ b/metadata.txt @@ -10,7 +10,7 @@ name=Flow Estimator qgisMinimumVersion=2.0 description=Estimates steady, uniform flow using the Manning equation for trapezoidal and DEM sampled channels. Intended for use by engineers and hydrologists. Requires numpy, and matplotlib libraires -version=0.15 +version=0.20 author=M. Weier - North Dakota State Water Commision email=mweier@nd.gov diff --git a/pb_tool.cfg b/pb_tool.cfg index 424730f..1bdd537 100644 --- a/pb_tool.cfg +++ b/pb_tool.cfg @@ -4,7 +4,7 @@ # Configuration file for plugin builder tool (pb_tool) # ------------------- # begin : 2015-05-21 -# copyright : (C) 2015 by M. Weier - North Dakota State Water Commision +# copyright : (C) 2015 by M. Weier - North Dakota State Water Commission # email : mweier@nd.gov # ***************************************************************************/ # diff --git a/test/test_flow_estimator_dialog.py b/test/test_flow_estimator_dialog.py index 6370a42..45959cb 100644 --- a/test/test_flow_estimator_dialog.py +++ b/test/test_flow_estimator_dialog.py @@ -10,7 +10,7 @@ __author__ = 'mweier@nd.gov' __date__ = '2015-05-21' -__copyright__ = 'Copyright 2015, M. Weier - North Dakota State Water Commision' +__copyright__ = 'Copyright 2015, M. Weier - North Dakota State Water Commission' import unittest diff --git a/test/test_resources.py b/test/test_resources.py index 8c729fe..dbabf1f 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -10,7 +10,7 @@ __author__ = 'mweier@nd.gov' __date__ = '2015-05-21' -__copyright__ = 'Copyright 2015, M. Weier - North Dakota State Water Commision' +__copyright__ = 'Copyright 2015, M. Weier - North Dakota State Water Commission' import unittest From 70a87f62c5d6d0ce45eafee5060bf5c3eed11a30 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 6 Aug 2019 00:09:02 +1200 Subject: [PATCH 06/14] fix output saving for user defined channel --- flow_estimator_dialog.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index bb49388..09b4838 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -538,7 +538,6 @@ def accept(self): wseMax = self.cbWSE.value() wseMin = self.cbWSE.minimum() elif self.calcType =='UD': - proj4 = utils.getRasterLayerByName(self.cbDEM.currentText().split(' EPSG')[0]).crs().toProj4() outHeader += '\n'*5 + 'Type:\tUser Defined Cross Section\nUnits:\t{0}\nChannel Slope:\t{1:.06f}\nMannings n:\t{2:.02f}\n\n\n\nstation\televation\n'.format(self.units, self.slope.value(), self.n.value()) outFile.write(outHeader) np.savetxt(outFile, self.staElev, fmt = '%.3f', delimiter = '\t') From 1341a7087144f523d8b81188438d2188deac123c Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 6 Aug 2019 00:12:43 +1200 Subject: [PATCH 07/14] try to fix windows file lock issues affecting output files --- flow_estimator_dialog.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index 09b4838..b1cf26b 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -528,6 +528,10 @@ def accept(self): os.makedirs(outPath) os.chdir(outPath) fileName = 'FlowEstimatorResults.txt' + # ajh not sure how to reliably reproduce, but on Windows it seems sometimes a lock is kept on the file until QGIS is closed + # one way to prevent it may be to open like this: + # outFile = open(fileName, 'w', False) + # another way may be to do outFile = None after closing outFile = open(fileName,'w') outHeader = '*'*20 + '\nFlow Estimator - A QGIS plugin\nEstimates uniform, steady flow in a channel using Mannings equation\n' + '*'*20 if self.calcType == 'DEM': @@ -580,6 +584,8 @@ def accept(self): outFile.close() + #ajh this may help force the file lock to be released + outFile = None self.iface.messageBar().pushMessage("Flow Estimator", 'Output files located here {}. Please delete when finished'.format(outPath),duration=30) From 59416dd918e9beb8857d90366cdf4dbe01bec684 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 6 Aug 2019 00:15:46 +1200 Subject: [PATCH 08/14] remove unnecessary exhortation to the user to tidy up (i.e. delete the output files) --- flow_estimator_dialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index b1cf26b..f6b276a 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -587,5 +587,5 @@ def accept(self): #ajh this may help force the file lock to be released outFile = None - self.iface.messageBar().pushMessage("Flow Estimator", 'Output files located here {}. Please delete when finished'.format(outPath),duration=30) + self.iface.messageBar().pushMessage("Flow Estimator", 'Output files saved to {}'.format(outPath),duration=30) From eb11afa15e420a2285793394b6a23707c6d436f3 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 6 Aug 2019 00:18:40 +1200 Subject: [PATCH 09/14] fix more typos --- openChannel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openChannel.py b/openChannel.py index 9e1dc59..3d1bcfe 100644 --- a/openChannel.py +++ b/openChannel.py @@ -10,7 +10,7 @@ def channelBuilder(wsDepth, rightSS, leftSS, widthBottom): """ - Builds trapziodal channel station/elevation array given depth, + Builds trapezoidal channel station/elevation array given depth, right side slope, left side slope, and bottom width """ leftToe = wsDepth*1.25*leftSS @@ -55,7 +55,7 @@ def channelPerimeter(corners): def flowEstimator(wsElev, n, channelSlope, **kwargs): """ Estimates uniform flow using the Manning equation for - a user defined trapziodal channel or a manually defined channel using + a user defined trapezoidal channel or a manually defined channel using a station/elevation file """ if kwargs.get("elevFile") is not None: From 0a18a5252507fe1d424c740956fcf4b785df9186 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Mon, 2 Sep 2019 18:53:39 +1200 Subject: [PATCH 10/14] change units precision etc --- flow_estimator_dialog_base.ui | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/flow_estimator_dialog_base.ui b/flow_estimator_dialog_base.ui index eadc43a..d51670a 100644 --- a/flow_estimator_dialog_base.ui +++ b/flow_estimator_dialog_base.ui @@ -128,6 +128,12 @@ 5.000000000000000 + + 0.500000000000000 + + + 3 + @@ -136,11 +142,14 @@ 0.010000000000000 - 0.500000000000000 + 0.050000000000000 5.000000000000000 + + 3 + @@ -196,13 +205,13 @@ - 2 + 4 999999.000000000000000 - 0.100000000000000 + 0.050000000000000 @@ -288,13 +297,13 @@ - 2 + 4 999999.989999999990687 - 0.100000000000000 + 0.050000000000000 From b01654eacae027fa84f74301291805dc246f2f53 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Mon, 2 Sep 2019 18:54:58 +1200 Subject: [PATCH 11/14] create the output directory if it does not exist --- flow_estimator_dialog.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index f6b276a..40de165 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -194,6 +194,8 @@ def sampleLine(self): try: # ajh: this doesn't seem to do anything on Windows self.iface.deactivate() + # ajh: neither does this! + #self.iface.showMinimized() # ajh: this causes an error #self.iface.mainWindow.setWindowState(Qt.WindowNoState) except: @@ -462,7 +464,8 @@ def doIrregularProfileFlowEstimator(self): else: return - self.run() + # ajh: I don't think this was doing anything + #self.run() def doRubberbandSlopeEstimator(self, staElev): @@ -524,8 +527,9 @@ def accept(self): if outPath == '': outPath = os.path.join(home,'Desktop','QGIS2FlowEstimatorFiles') self.outputDir.setText(outPath) - if not os.path.exists(outPath): - os.makedirs(outPath) + # Note that in Python 3.2+ we will be able to just do: os.makedirs("path/to/directory", exist_ok=True) + if not os.path.exists(outPath): + os.makedirs(outPath) os.chdir(outPath) fileName = 'FlowEstimatorResults.txt' # ajh not sure how to reliably reproduce, but on Windows it seems sometimes a lock is kept on the file until QGIS is closed From 17c4e04e983a192c4acb26bf0eecabb6dc7c8da4 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 10 Sep 2019 11:20:38 +1200 Subject: [PATCH 12/14] use more sane precision (but allow less sane precision for depth, so the user can tweak it to get exactly the flow they want) --- flow_estimator_dialog.py | 6 +++--- flow_estimator_dialog_base.ui | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index 40de165..9635c10 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -137,11 +137,11 @@ def plotter(self): self.axes.plot(xWater, yWater, 'blue') self.axes.fill_between(xWater, yWater, yWater0, where=yWater>=yWater0, facecolor='blue', interpolate=True, alpha = 0.1) if self.calcType == 'DEM': - self.outText = 'INPUT\n\nSlope: {7:.5f}\nRoughness: {8:.2f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbWSE.value()) + self.outText = 'INPUT\n\nSlope: {7:.3f}\nRoughness: {8:.3f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.3f} {5}$^3$/s\nVelocity {4:,.1f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbWSE.value()) elif self.calcType == 'UD': - self.outText = 'INPUT\n\nSlope: {7:.5f}\nRoughness: {8:.2f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbUDwse.value()) + self.outText = 'INPUT\n\nSlope: {7:.3f}\nRoughness: {8:.3f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.3f} {5}$^3$/s\nVelocity {4:,.1f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbUDwse.value()) else: - self.outText = 'INPUT\n\nSlope: {7:.5f}\nRoughness: {8:.2f}\nDepth: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.depth.value()) + self.outText = 'INPUT\n\nSlope: {7:.3f}\nRoughness: {8:.3f}\nDepth: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.3f} {5}$^3$/s\nVelocity {4:,.1f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.depth.value()) self.axes.set_xlabel('Station, '+self.units) self.axes.set_ylabel('Elevation, '+self.units) self.axes.set_title('Cross Section') diff --git a/flow_estimator_dialog_base.ui b/flow_estimator_dialog_base.ui index d51670a..f0a3bcb 100644 --- a/flow_estimator_dialog_base.ui +++ b/flow_estimator_dialog_base.ui @@ -148,7 +148,7 @@ 5.000000000000000 - 3 + 4 @@ -424,13 +424,13 @@ - 5 + 3 0.000000000000000 - 0.001000000000000 + 0.005000000000000 0.0050000000000000 From fade135a5e27ef9638efa7b9eb10f16595835def Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 10 Sep 2019 11:41:31 +1200 Subject: [PATCH 13/14] use "save" stock button rather than "ok" --- flow_estimator_dialog.py | 5 +++-- flow_estimator_dialog_base.ui | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/flow_estimator_dialog.py b/flow_estimator_dialog.py index 9635c10..bcb79f7 100644 --- a/flow_estimator_dialog.py +++ b/flow_estimator_dialog.py @@ -58,8 +58,9 @@ def __init__(self, iface, parent=None): self.iface = iface self.setupUi(self) - self.btnOk = self.buttonBox.button(QtGui.QDialogButtonBox.Ok) - self.btnOk.setText("Save Data") + self.btnOk = self.buttonBox.button(QtGui.QDialogButtonBox.Save) + #ajh: it seems this wasn't working, so I have changed from a stock OK button to a stock Save button + #self.btnOk.setText("Save Data") self.btnClose = self.buttonBox.button(QtGui.QDialogButtonBox.Close) self.btnBrowse.clicked.connect(self.writeDirName) self.btnLoadTXT.clicked.connect(self.loadTxt) diff --git a/flow_estimator_dialog_base.ui b/flow_estimator_dialog_base.ui index f0a3bcb..6f7d5c0 100644 --- a/flow_estimator_dialog_base.ui +++ b/flow_estimator_dialog_base.ui @@ -551,7 +551,7 @@ p, li { white-space: pre-wrap; } Qt::Horizontal - QDialogButtonBox::Close|QDialogButtonBox::Ok + QDialogButtonBox::Close|QDialogButtonBox::Save From b3f0867973a04feca2ed472892b05596cb563649 Mon Sep 17 00:00:00 2001 From: Alister Hood Date: Tue, 10 Sep 2019 11:52:50 +1200 Subject: [PATCH 14/14] might as well be more accurate with unit conversion for feet --- openChannel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openChannel.py b/openChannel.py index 3d1bcfe..c102e08 100644 --- a/openChannel.py +++ b/openChannel.py @@ -72,7 +72,7 @@ def flowEstimator(wsElev, n, channelSlope, **kwargs): if kwargs.get("units") == "m": const = 1.0 else: - const = 1.49 + const = 1.4859 intersectList = [] for i in range(0, len(staElev)):