Skip to content

Commit

Permalink
automatic recognition of water depth + bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patricev committed Apr 5, 2016
1 parent ce631df commit 0ab55c6
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 89 deletions.
14 changes: 13 additions & 1 deletion dialogs/posttelemacpropertiesdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def __init__(self, layer1, parent=None):
self.pushButton_9.clicked.connect(self.set_utilcrs)
self.pushButton_2.clicked.connect(self.create_shp_points)

#raster creation
self.pushButton_createraster.clicked.connect(self.postutils.rasterCreation)

#final action
self.initTreewidgettoolsindextab()
self.treeWidget_utils.expandAll()
Expand Down Expand Up @@ -428,6 +431,7 @@ def open_def_variables(self, lst_param):
self.populatecombobox_param()
self.layer.updateSelafinValues()
self.setTreeWidgetIndex(self.treeWidget_parameters,0,index)


def delete_def_variables(self):
"""
Expand All @@ -440,6 +444,11 @@ def delete_def_variables(self):
self.layer.parametres[index:index+1] = []
self.populatecombobox_param()
self.setTreeWidgetIndex(self.treeWidget_parameters,0,index-1)
#checkkeysparameter
self.layer.parametreh = None
self.layer.parametrevx = None
self.layer.parametrevy = None

self.layer.updateSelafinValues()

#Display tools - contour - color ramp things ***********************************************
Expand Down Expand Up @@ -699,9 +708,11 @@ def populatecombobox_param(self):
Populate parameters comboboxes on dialog update
"""
self.comboBox_parametreschooser.clear()
self.comboBox_parametreschooser_2.clear()
for i in range(len(self.layer.parametres)):
temp1 = [str(self.layer.parametres[i][0])+" : "+str(self.layer.parametres[i][1])]
self.comboBox_parametreschooser.addItems(temp1)
self.comboBox_parametreschooser_2.addItems(temp1)

self.treeWidget_parameters.clear()
itms = []
Expand Down Expand Up @@ -770,7 +781,8 @@ def initTreewidgettoolsindextab(self):
[[-1,6],7, 'Max res' ] ,
[[7,0],8,'2shape contour' ],
[[7,1],9,'2shape mesh' ],
[[7,2],10,'2shape point' ]]
[[7,2],10,'2shape point' ],
[[8,0],11,'Raster creation']]


def changepannelutils(self):
Expand Down
29 changes: 29 additions & 0 deletions libs/caduc/rasterinterpolator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
ld=qgis.analysis.QgsIDWInterpolator.LayerData
ld.vectorLayer=iface.activeLayer()
ld.zCoordInterpolation=0
ld.interpolationAttribute=5
ld.mInputType=0
#print str( qgis.analysis.QgsIDWInterpolator.layerData() )
"""

ld1 = qgis.analysis.QgsInterpolator.LayerData()
ld1.vectorLayer=iface.activeLayer()
ld1.zCoordInterpolation=0
ld1.interpolationAttribute=5
ld1.mInputType=0

#print dir(qgis.analysis.QgsIDWInterpolator)
#print dir(qgis.analysis.QgsInterpolator.LayerData)

itp=qgis.analysis.QgsIDWInterpolator([ld1])


rect = iface.mapCanvas().extent()
ncol = 10
res = 1.0
test = qgis.analysis.QgsGridFileWriter(itp,'c:/test1.asc',rect,ncol,ncol,res,res)
test.writeFile(True)

60 changes: 40 additions & 20 deletions libs/post_telemac_pluginlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import scipy
#from scipy.spatial import cKDTree
#import matplotlib
#from matplotlib import tri
from matplotlib import tri
from matplotlib import colors
#import PyQT
from PyQt4.QtCore import *
Expand Down Expand Up @@ -251,24 +251,43 @@ def initSelafinParameters(self):
if len(self.parametrestoload)>0: #case of virtual parameters when loadin a selafin layer
for param in self.parametrestoload:
self.parametres.append([len(self.parametres),param[1],param[2],len(self.parametres)])
try: #load velocity parameters
self.parametrevx = self.propertiesdialog.postutils.getParameterName("VITESSEU")[0]
self.parametrevy = self.propertiesdialog.postutils.getParameterName("VITESSEV")[0]
self.propertiesdialog.tab_velocity.setEnabled(True)
for widget in self.propertiesdialog.tab_velocity.children():
widget.setEnabled(True)
for widget in self.propertiesdialog.groupBox_schowvel.children():
widget.setEnabled(True)
self.propertiesdialog.groupBox_schowvel.setChecked(True)
self.propertiesdialog.groupBox_schowvel.setChecked(False)
except Exception, e:
self.propertiesdialog.tab_velocity.setEnabled(False)
#TODO : disable utils dependant on velocity (flow, show velocity)
try: #load water depth parameters
self.parametreh = self.propertiesdialog.postutils.getParameterName("HAUTEUR")[0]
except Exception, e:
pass
#TODO : disable utils dependant on velocity (flow, show velocity)

self.identifyKeysParameters()


def identifyKeysParameters(self):
#load velocity parameters
if (self.parametrevx == None and self.parametrevy == None) :

if self.propertiesdialog.postutils.getParameterName("VITESSEU") == None and self.propertiesdialog.postutils.getParameterName("VITESSEV") == None:
self.propertiesdialog.tab_velocity.setEnabled(False)
else:
self.parametrevx = self.propertiesdialog.postutils.getParameterName("VITESSEU")[0]
self.parametrevy = self.propertiesdialog.postutils.getParameterName("VITESSEV")[0]
self.propertiesdialog.tab_velocity.setEnabled(True)
for widget in self.propertiesdialog.tab_velocity.children():
widget.setEnabled(True)
for widget in self.propertiesdialog.groupBox_schowvel.children():
widget.setEnabled(True)
self.propertiesdialog.groupBox_schowvel.setChecked(True)
self.propertiesdialog.groupBox_schowvel.setChecked(False)

#load water depth parameters
if self.parametreh == None :
if self.propertiesdialog.postutils.getParameterName("HAUTEUR") == None:
paramfreesurface = self.propertiesdialog.postutils.getParameterName("SURFACELIBRE")[0]
parambottom = self.propertiesdialog.postutils.getParameterName("BATHYMETRIE")[0]
self.parametreh = len(self.parametres)
self.parametres.append([len(self.parametres),"HAUTEUR D'EAU",'V'+str(paramfreesurface)+' - V'+str(parambottom),len(self.parametres)])
else:
self.parametreh = self.propertiesdialog.postutils.getParameterName("HAUTEUR")[0]

if self.parametreh != None and self.parametrevx != None and self.parametrevy != None:
self.propertiesdialog.page_flow.setEnabled(True)
else:
self.propertiesdialog.page_flow.setEnabled(False)



def clearParameters(self):
self.param_displayed = None
Expand Down Expand Up @@ -304,6 +323,7 @@ def updateSelafinValues(self, onlyparamtimeunchanged = -1 ):
It emits a signal, because this method is redirected to a different method in comparetool
when tool "compare" is activated
"""
self.identifyKeysParameters()
self.updatevalue.emit(onlyparamtimeunchanged)

updatevalue = pyqtSignal(int)
Expand Down Expand Up @@ -576,7 +596,7 @@ def identify(self,qgspointfromcanvas,multiparam = False):
return (True,d)

def initTriinterpolator(self):
self.triinterp = [tri.LinearTriInterpolator(self.hydrauparser.triangulation, self.values[i]) for i in range(len(self.parametres))]
self.triinterp = [matplotlib.tri.LinearTriInterpolator(self.hydrauparser.triangulation, self.values[i]) for i in range(len(self.parametres))]

#****************************************************************************************************
#************Method for saving/loading project with selafinlayer file***********************************
Expand Down
41 changes: 39 additions & 2 deletions libs/posttelemac_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtCore import SIGNAL, Qt
import qgis
#import numpy
import numpy as np
#import time
Expand Down Expand Up @@ -342,7 +343,7 @@ def launchThread(self,geom):


def workerFinished(self,list1,list2,list3 = None):

if self.graphtodo ==0:
ax = self.selafinlayer.propertiesdialog.ax
if not self.selafinlayer.propertiesdialog.checkBox.isChecked():
Expand Down Expand Up @@ -634,7 +635,43 @@ def workerFinishedHillshade(self,strpath):
#self.selafinlayer.propertiesdialog.textBrowser_main.append(ctime() + " - "+ str(os.path.basename(strpath).split('.')[0]) + self.tr(" created"))
self.selafinlayer.propertiesdialog.normalMessage(str(os.path.basename(strpath).split('.')[0]) + self.tr(" created"))


def rasterCreation(self):
#print 'ok'
#Points
layerstring = self.selafinlayer.hydraufilepath+'[' + str(self.selafinlayer.time_displayed) + ']'
print layerstring
layerpoint = QgsVectorLayer(layerstring, 'test', "ogr")
#Layerpoint for interpolation
ld1 = qgis.analysis.QgsInterpolator.LayerData()
ld1.vectorLayer=layerpoint
ld1.zCoordInterpolation=False
ld1.interpolationAttribute=self.selafinlayer.propertiesdialog.comboBox_parametreschooser_2.currentIndex()
ld1.mInputType=0

#interpolator
#itp=qgis.analysis.QgsIDWInterpolator([ld1])
itp=qgis.analysis.QgsTINInterpolator([ld1])

if self.selafinlayer.propertiesdialog.comboBox_rasterextent.currentIndex() == 0 :
rect = iface.mapCanvas().extent()
elif self.selafinlayer.propertiesdialog.comboBox_rasterextent.currentIndex() == 1 :
rect = layerpoint.extent()

#raster creation
res = self.selafinlayer.propertiesdialog.spinBox_rastercellsize.value()
ncol = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
print str(ncol)
ncol = 300
rasterfilepath = os.path.join(os.path.dirname(self.selafinlayer.hydraufilepath),'raster2.asc')
print rasterfilepath
test = qgis.analysis.QgsGridFileWriter(itp,rasterfilepath,rect,ncol,ncol,res,res)
print 'ok1'
test.writeFile(False)







#****************************************************************************************************
Expand Down
16 changes: 8 additions & 8 deletions libs/posttelemac_util_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ def computeFlowMain(self):
try:
if i==0: #init
try:
h2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameterh])[0][0])
h2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameterh],self.selafinlayer.parametres)[0][0])
except Exception , e :
self.status.emit('method 011 : ' + str(e))
uv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameteruv])[0][0])
uv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameteruv],self.selafinlayer.parametres)[0][0])
uv2 = np.array([[value,0.0] for value in uv2])
vv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parametervv])[0][0])
vv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parametervv],self.selafinlayer.parametres)[0][0])
vv2 = np.array([[0.0,value] for value in vv2])
v2vect = uv2 + vv2
#xy2 = [self.slf.MESHX[elem],self.slf.MESHY[elem]]
Expand All @@ -108,10 +108,10 @@ def computeFlowMain(self):
h1 = h2
v1vect = v2vect
xy1 = xy2
h2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameterh])[0][0])
uv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameteruv])[0][0])
h2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameterh],self.selafinlayer.parametres)[0][0])
uv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parameteruv],self.selafinlayer.parametres)[0][0])
uv2 = np.array([[value,0.0] for value in uv2])
vv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parametervv])[0][0])
vv2 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([elem + 1],[parametervv],self.selafinlayer.parametres)[0][0])
vv2 = np.array([[0.0,value] for value in vv2])
v2vect = uv2 + vv2
#xy2 = [self.slf.MESHX[elem],self.slf.MESHY[elem]]
Expand Down Expand Up @@ -384,8 +384,8 @@ def computeFlowBetweenPoints(self,xy1,h1,v1vect,xy2,h2,v2vect):

def valuebetweenEdges(self,xy,edges,param):
xytemp = np.array(xy)
h11 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([edges[0] + 1],[param])[0][0]) #getseries begins at 1
h12 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([edges[1] + 1 ],[param])[0][0])
h11 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([edges[0] + 1],[param],self.selafinlayer.parametres)[0][0]) #getseries begins at 1
h12 = np.array(self.selafinlayer.hydrauparser.getTimeSerie([edges[1] + 1 ],[param],self.selafinlayer.parametres)[0][0])
"""
e1 = np.array([self.selafinlayer.slf.MESHX[edges[0]],self.selafinlayer.slf.MESHY[edges[0]]])
e2 = np.array([self.selafinlayer.slf.MESHX[edges[1]],self.selafinlayer.slf.MESHY[edges[1]]])
Expand Down
61 changes: 14 additions & 47 deletions libs/posttelemac_util_graphtemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,62 +57,29 @@ def createGraphTemp(self):
abscisse = self.selafinlayer.hydrauparser.getTimes().tolist()

param=self.selafinlayer.propertiesdialog.comboBox_parametreschooser.currentIndex()
#param = self.selafinlayer.propertiesdialog.getTreeWidgetSelectedIndex(self.selafinlayer.propertiesdialog.treeWidget_parameters)[1]
if self.selafinlayer.parametres[param][2]:
dico = self.getDico(self.selafinlayer.parametres[param][2], self.selafinlayer.parametres, self.selafinlayer.values,enumpoint)
tempordonees = eval(self.selafinlayer.parametres[param][2],{}, dico)

if self.compare :
triangles,numpointsfinal,pointsfinal,coef = self.selafinlayer.propertiesdialog.postutils.compareprocess.hydrauparsercompared.getInterpFactorInTriangleFromPoint([x],[y])
self.status.emit(str(triangles)+' ' +str(numpointsfinal)+' ' +str(pointsfinal)+' ' +str(coef))
layer2serie = 0
print str(numpointsfinal[0])
for i, numpoint in enumerate(numpointsfinal[0]):
#layer2serie += float(coef[0][i]) * self.selafinlayer.propertiesdialog.postutils.compareprocess.hydrauparsercompared.getTimeSerie([numpoint],[self.selafinlayer.parametres[param[0]][3]],self.selafinlayer.parametres)
layer2serie += float(coef[0][i]) * self.selafinlayer.propertiesdialog.postutils.compareprocess.hydrauparsercompared.getTimeSerie([numpoint +1],[self.selafinlayer.parametres[param][3]],self.selafinlayer.parametres)
print 'ok1'
layer1serie = self.selafinlayer.hydrauparser.getTimeSerie([enumpoint + 1],[param],self.selafinlayer.parametres)
tempordonees = layer2serie - layer1serie
else:
#tempordonees = self.selafinlayer.slf.getSERIES([enumpoint + 1],[param],False) #points in getseries begin with 1
#tempordonees = self.selafinlayer.hydrauparser.getTimeSerie([enumpoint + 1],[param]) #points in getseries begin with 1
tempordonees = self.getGraphTempSeries([enumpoint + 1],[param]) #points in getseries bein with 1
tempordonees = self.selafinlayer.hydrauparser.getTimeSerie([enumpoint + 1],[param],self.selafinlayer.parametres)

ordonnees = tempordonees[0][0].tolist()
list1.append(abscisse)
list2.append(ordonnees)
self.finished.emit(list1,list2)
except Exception, e:
self.status.emit(str(e))
self.finished.emit([],[])


def getDico(self,expr, parametres, values,enumpoint):
dico = {}
try:

dico['sin'] = sin
dico['cos'] = cos
dico['abs'] = abs
dico['int'] = int
dico['if_then_else'] = self.selafinlayer.if_then_else
a = 'V{}'
nb_var = len(values)
i = 0
num_var = 0
while num_var < nb_var:
if not parametres[i][2]:
#dico[a.format(i)] = self.selafinlayer.hydrauparser.getTimeSerie([enumpoint + 1],[i])
dico[a.format(i)] = self.getGraphTempSeries([enumpoint + 1],[i])
num_var += 1
i += 1
except Exception, e:
print str(e)
return dico

def getGraphTempSeries(self,num,param):
if self.compare :
x,y = self.selafinlayer.hydrauparser.getXYFromNumPoint(num)[0]
triangles,numpointsfinal,pointsfinal,coef = self.selafinlayer.propertiesdialog.postutils.compareprocess.hydrauparsercompared.getInterpFactorInTriangleFromPoint([x],[y])
layer2serie = 0
for i, numpoint in enumerate(numpointsfinal[0]):
layer2serie += float(coef[0][i]) * self.selafinlayer.propertiesdialog.postutils.compareprocess.hydrauparsercompared.getTimeSerie([numpoint],[self.selafinlayer.parametres[param[0]][3]])
layer1serie = self.selafinlayer.hydrauparser.getTimeSerie(num,param)
return layer2serie - layer1serie
else:
return self.selafinlayer.hydrauparser.getTimeSerie(num,param)





progress = QtCore.pyqtSignal(int)
status = QtCore.pyqtSignal(str)
error = QtCore.pyqtSignal(str)
Expand Down
Loading

0 comments on commit 0ab55c6

Please sign in to comment.