1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
import sys
sys.path.append("C:/Users/Pavel/.spyder-py3/geostatmodels")
from pathlib import PureWindowsPath
from PyQt5.QtCore import*
from PyQt5.QtWidgets import*
from PyQt5 import QtGui, QtCore, QtWidgets
import numpy as np
from pandas import DataFrame, Series
import utilities as utilities
import kriging as kriging
import variograms as variograms
import model as model
import geoplot as geoplot
from scipy.stats import norm
import os.path
import scipy.stats as stats
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
plt.style.use('ggplot')
# création de l'interface principale de mon application, elle sera
# dans une classe nomée "MonApp"
global topleft
class Messa_Fich(QWidget):
switch_window = QtCore.pyqtSignal()
def __init__(self):
super(Messa_Fich, self).__init__()
self.button_1 = QPushButton("""estimation de la pluie: determiner la
hauteur de la lame écoulé sur une section
pendant une période de temps""")
self.button_1.clicked.connect(self.simu_pluie)
self.spaceItem = QSpacerItem(150, 10, QSizePolicy.Expanding)
self.mainLayout = QVBoxLayout()
self.mainLayout.addSpacerItem(self.spaceItem)
# self.mainLayout.addStretch(1)
self.mainLayout.addWidget(self.button_1)
self.mainLayout.addSpacing(10)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.setLayout(self.mainLayout)
def simu_pluie(self):
global table
COLUMNS = ()
LINES = ()
self.r, self.c = 10000, 100
table = QTableWidget(self.r, self.c)
table.setHorizontalHeaderLabels(LINES)
table.setVerticalHeaderLabels(COLUMNS)
table.setSelectionMode(QAbstractItemView.ContiguousSelection)
table.setSelectionMode(QAbstractItemView.ExtendedSelection)
table.setEditTriggers(QAbstractItemView.NoEditTriggers)
table.setFocus()
table.setShowGrid(True)
filename = QFileDialog.getOpenFileName(self, 'fichier piezométrie',
" ","Files CSV (*.csv);;Text File (*.txt)")[0]
if filename:
with open(filename, 'r') as f:
for ind, line in enumerate(f):
if line:
cols = [li.strip().rstrip('\n') for li in line.split(';')]
for i, value in enumerate(cols):
table.setItem(ind, i, QTableWidgetItem(value))
name = PureWindowsPath(filename).name
topleft.addTab(table, name)
topleft.setTabsClosable(True)
self.switch_window.emit()
class WidgetPlot(QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self, *args, **kwargs)
self.setLayout(QVBoxLayout())
self.canvas = PlotCanvas(self, width =5, height = 4)
self.toolbar = NavigationToolbar(self.canvas, self)
self.layout().addWidget(self.toolbar)
self.layout().addWidget(self.canvas)
class PlotCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fige = Figure(figsize=(width, height), dpi=dpi)
FigureCanvas.__init__(self, fige)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QSizePolicy.Expanding,
QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
def vario_expe(text_1, text_2, text_3, text_4, text_5, text_6):
selected = table.selectedRanges()
x = []
y = []
z = []
index = []
index_j = []
d = []
sigma = []
for i in selected:
index.extend(range(i.topRow(), i.bottomRow() + 1))
for j in selected:
index_j.extend(range(j.leftColumn(), j.rightColumn()+1))
for l in index:
x.append(float(table.item(l, text_1).text()))
y.append(float(table.item(l, text_2).text()))
z.append(float(table.item(l, text_3).text()))
np_x = np.asarray(x,dtype=float).reshape(len(x),1)
np_y = np.asarray(y,dtype=float).reshape(len(y),1)
np_z = np.asarray(z,dtype=float).reshape(len(z),1)
coords = np.append(np_x,np_y,1)
points = np.append(coords, np_z, 1)
lags = np.arange(text_5, text_4, text_5*2)
vario = variograms.semivariogram(points, lags, text_6)
h, sv = vario[0], vario[1]
ax = self.figure.add_subplot(111)
ax.plot(h, sv, 'ko-')
ax.set_ylabel('gamma(h)')
ax.set_xlabel('Lag Distance')
ax.set_title('variogram')
self.draw()
class Vario_Para(QWidget):
""" classe qui permet d'introduire les paramètres de calcul du variogramme
expérimental ainsi que son tracé"""
switch_window_1 = QtCore.pyqtSignal()
def __init__(self):
QWidget.__init__(self)
self.setWindowTitle('paramètres variogrammme expérimental')
self.resize(300, 200)
plo = PlotCanvas(self)
layout = QGridLayout()
self.setLayout(layout)
self.x_val = QLabel("colonne des abscisses")
self.x_val.setWordWrap(True)
layout.addWidget(self.x_val, 0, 0)
self.y_val = QLabel("colonne des ordonnées")
self.y_val.setWordWrap(True)
layout.addWidget(self.y_val, 0, 1)
self.val = QLabel("colonne des valeurs")
self.val.setWordWrap(True)
layout.addWidget(self.val, 0, 2)
self.line_x = QLineEdit()
layout.addWidget(self.line_x, 1, 0)
self.line_y = QLineEdit()
layout.addWidget(self.line_y, 1, 1)
self.line_val = QLineEdit()
layout.addWidget(self.line_val, 1, 2)
self.dist = QLabel("pas")
self.dist.setWordWrap(True)
layout.addWidget(self.dist, 2, 1)
self.mdist = QLabel("distance max")
self.mdist.setWordWrap(True)
layout.addWidget(self.mdist, 2, 0)
self.tol = QLabel("tolerance")
self.tol.setWordWrap(True)
layout.addWidget(self.tol, 2, 2)
self.line_mdist = QLineEdit()
layout.addWidget(self.line_mdist, 3, 0)
self.line_dist = QLineEdit()
layout.addWidget(self.line_dist, 3, 1)
self.line_tol = QLineEdit()
layout.addWidget(self.line_tol, 3, 2)
self.push_ok = QPushButton('OK')
self.push_ok.clicked.connect(self.tracer_vario)
layout.addWidget(self.push_ok, 4, 2)
def tracer_vario(self):
topright.vario_expe((int(self.line_x.text())-1), (int(self.line_y.text())-1),
(int(self.line_val.text())-1), int(self.line_mdist.text()),
int(self.line_dist.text()), int(self.line_tol.text()))
self.switch_window_1.emit()
class MonApp(QMainWindow):
switch_window = QtCore.pyqtSignal()
switch_window_1 = QtCore.pyqtSignal()
def __init__(self):
QMainWindow.__init__(self)
global topright, topleft, table
self.setWindowTitle("H2MG-PATEF")
self.resize(900, 700)
self.statusBar()
#=====================================================================================
#création de la barre de Menu
## codage des differente action
# pour une simulation simple
simu_sim = QAction("simulation simple", self)
simu_sim.setStatusTip('lancer une nouvelle simulation simple')
simu_sim.triggered.connect(self.simu_sim)
# objet de la barre de menu
bar = self.menuBar()
file_menu = bar.addMenu("Fichier")
act_fich1 =file_menu.addMenu("Nouveau Projet")
act_fich1.addAction(simu_sim)
act_fich2 = QAction("Ouvir", self)
act_fich2.setShortcut("Ctrl+O")
file_menu.addAction(act_fich2)
save = QAction("Save", self)
save.setShortcut("Ctrl+S")
file_menu.addAction(save)
file_menu.addSeparator()
act_fich3 = QAction("Quit", self)
act_fich3.setShortcut("Alt+F4")
file_menu.addAction(act_fich3)
#
help_menu = self.menuBar().addMenu("Help")
act_help1 = QAction("simulation simple", self)
help_menu.addAction(act_help1)
act_help2 = QAction("simulation avancée", self)
help_menu.addAction(act_help2)
#création d'une barre d'outils
#
out_un = QAction(QtGui.QIcon('chat.gif'), 'variogramme experimental', self)
out_un.triggered.connect(self.para_var)
bar_un = self.addToolBar('krig')
bar_un.addAction(out_un)
#
#creation du widget central
hbox = QHBoxLayout()
topleft = QTabWidget(self)
topright = WidgetPlot()
splitter1 = QSplitter(Qt.Vertical)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
splitter1.setSizes([300, 400])
hbox.addWidget(splitter1)
self.setLayout(hbox)
widget = QWidget()
widget.setLayout(hbox)
self.setCentralWidget(widget)
# fonction utilisé pour les diffentes actions de la barre de menu
def simu_sim(self):
self.switch_window.emit()
def para_var(self):
self.switch_window_1.emit()
class Controller:
def __init__(self):
pass
def show_fen_p(self):
self.fen_p =MonApp()
self.fen_p.switch_window.connect(self.show_fen_1)
self.fen_p.switch_window_1.connect(self.show_fen_2)
self.fen_p.show()
def show_fen_1(self):
self.fen_1 = Messa_Fich()
self.fen_1.switch_window.connect(self.rshow_fen_p)
self.fen_1.show()
def show_fen_2(self):
self.fen_2 = Vario_Para()
self.fen_2.switch_window_1.connect(self.fen_2_off)
self.fen_2.show()
def rshow_fen_p(self):
self.fen_1.close()
def fen_2_off(self):
self.fen_2.close()
def main():
app = QtWidgets.QApplication(sys.argv)
controller = Controller()
controller.show_fen_p()
sys.exit(app.exec_())
if __name__=="__main__":
Controller.main() |
Partager