[2116] | 1 | #!/usr/bin/python -B |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | #--------------------------------------------------------------------------------# |
---|
[2696] | 4 | # This file is part of the PALM model system. |
---|
[2116] | 5 | # |
---|
| 6 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | # either version 3 of the License, or (at your option) any later version. |
---|
| 9 | # |
---|
| 10 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License along with |
---|
| 15 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | # |
---|
| 17 | # Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
| 18 | #--------------------------------------------------------------------------------# |
---|
| 19 | # |
---|
| 20 | # Current revisions: |
---|
| 21 | # ----------------- |
---|
| 22 | # |
---|
[2117] | 23 | # |
---|
[2116] | 24 | # Former revisions: |
---|
| 25 | # ----------------- |
---|
| 26 | # $Id: palm_gf 2696 2017-12-14 17:12:51Z raasch $ |
---|
| 27 | # |
---|
[2117] | 28 | # 2116 2017-01-16 16:15:24Z maronga |
---|
| 29 | # Initial revision |
---|
[2116] | 30 | # |
---|
[2117] | 31 | # |
---|
[2116] | 32 | # |
---|
| 33 | # Description: |
---|
| 34 | # ------------ |
---|
| 35 | # |
---|
| 36 | # |
---|
| 37 | # Instructions: |
---|
| 38 | # ------------- |
---|
| 39 | # |
---|
| 40 | #------------------------------------------------------------------------------! |
---|
| 41 | |
---|
| 42 | import sys |
---|
| 43 | import os |
---|
[2308] | 44 | import time |
---|
[2116] | 45 | import palm_gf_files.palm_gf_exec as execute_script |
---|
| 46 | import palm_gf_files.palm_gf_conf as config_wr |
---|
| 47 | import sqlite3 |
---|
| 48 | import subprocess as sub |
---|
| 49 | |
---|
[2308] | 50 | |
---|
| 51 | from PyQt4 import QtCore, QtGui, uic, Qt |
---|
| 52 | from PyQt4.QtCore import QCoreApplication |
---|
[2116] | 53 | from palm_gf_files.palm_gf_tools import MyApp3 |
---|
| 54 | |
---|
| 55 | # Determine PALM directories |
---|
| 56 | try: |
---|
| 57 | devnull = open(os.devnull, 'w') |
---|
| 58 | out = sub.check_output("echo $PALM_BIN", shell=True, stderr=sub.STDOUT) |
---|
| 59 | palm_bin = out.rstrip() |
---|
| 60 | palm_dir = out.split("palm")[0] + "palm/" + out.split("palm")[1].split("/")[1] |
---|
| 61 | out = None |
---|
| 62 | except: |
---|
| 63 | print "Error. $PALM_BIN is not set." |
---|
| 64 | raise SystemExit |
---|
| 65 | |
---|
| 66 | qtCreatorFile = palm_bin + '/palm_gf_files/palm_gf.ui' |
---|
| 67 | |
---|
| 68 | Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | class MyApp1(QtGui.QMainWindow, Ui_MainWindow): |
---|
[2308] | 72 | def __init__(self): |
---|
[2116] | 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | QtGui.QMainWindow.__init__(self) |
---|
| 77 | Ui_MainWindow.__init__(self) |
---|
| 78 | #self.setWindowTitle('Gridfinder') |
---|
| 79 | |
---|
| 80 | frameGm = self.frameGeometry() |
---|
| 81 | screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) |
---|
| 82 | centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() |
---|
| 83 | frameGm.moveCenter(centerPoint) |
---|
| 84 | self.move(frameGm.topLeft()) |
---|
| 85 | |
---|
[2308] | 86 | |
---|
| 87 | #centerPoint = str(centerPoint) |
---|
| 88 | #xcenter = centerPoint.split('(')[1].split(',')[0] |
---|
| 89 | #ycenter = centerPoint.split('(')[1].split(',')[1].split(')')[0] |
---|
| 90 | #print xcenter, ycenter |
---|
| 91 | #centerPoint = QtCore.QPoint(int(xcenter) - 418, int(ycenter)) |
---|
| 92 | #frameGm.moveCenter(centerPoint) |
---|
| 93 | #self.move(frameGm.topLeft()) |
---|
| 94 | |
---|
[2116] | 95 | self.setupUi(self) |
---|
[2308] | 96 | self.startbutton.clicked.connect(self.input_check) # starts grid_calculation |
---|
[2116] | 97 | self.psolver_box.currentIndexChanged.connect(self.vis) # triggers visibility of fft_method option |
---|
| 98 | self.save_button.clicked.connect(self.save_results) # saves .db file under given name |
---|
| 99 | self.fft_method_box.setVisible(False) |
---|
| 100 | self.fft_method_label.setVisible(False) |
---|
| 101 | self.result_headline.setVisible(False) |
---|
| 102 | self.result_label.setVisible(False) |
---|
[2308] | 103 | #self.line_res_up.setVisible(False) |
---|
[2116] | 104 | self.line_res_down.setVisible(False) |
---|
| 105 | self.view_result_button.setVisible(False) |
---|
[2308] | 106 | #self.tableWidget.setVisible(False) |
---|
[2116] | 107 | self.load_text_label.setVisible(False) |
---|
| 108 | self.nor_spinbox.setVisible(False) |
---|
| 109 | self.filename_line.setVisible(False) |
---|
| 110 | self.save_button.setVisible(False) |
---|
[2308] | 111 | self.testbar.setVisible(False) |
---|
| 112 | self.d_box.setVisible(False) |
---|
| 113 | self.tpn_box.setVisible(False) |
---|
| 114 | self.tolerance_bar.setVisible(False) |
---|
| 115 | self.tolerance_value.setVisible(False) |
---|
[2116] | 116 | self.view_result_button.clicked.connect(self.load_gui) |
---|
[2308] | 117 | self.threadclass = Threadclass() |
---|
| 118 | self.actionSetting.triggered.connect(self.settings) |
---|
| 119 | self.question_box.clicked.connect(self.settings) |
---|
| 120 | self.warning_label.setVisible(False) |
---|
[2116] | 121 | |
---|
| 122 | |
---|
| 123 | |
---|
[2308] | 124 | |
---|
| 125 | def closeEvent(self, QCloseEvent): |
---|
| 126 | |
---|
| 127 | config_wr.closing_cleanup() |
---|
| 128 | QCloseEvent.accept() |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | def input_check(self): |
---|
| 132 | |
---|
| 133 | if int(self.nx_min_box.value()) <= int(self.nx_max_box.value()) and int(self.ny_min_box.value()) <= int(self.nx_max_box.value()) and int(self.nz_min_box.value()) <= int(self.nz_max_box.value()): |
---|
| 134 | self.warning_label.setVisible(False) |
---|
| 135 | self.run_program() |
---|
| 136 | |
---|
| 137 | else: |
---|
| 138 | |
---|
| 139 | self.warning_label.setStyleSheet('color: red') |
---|
| 140 | self.warning_label.setVisible(True) |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | def settings(self): |
---|
| 149 | |
---|
| 150 | self.w = MyPopup() |
---|
| 151 | #self.w.setGeometry(Qt.QRect(100, 100, 400, 200)) |
---|
| 152 | frameGm = self.frameGeometry() |
---|
| 153 | screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) |
---|
| 154 | centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() |
---|
| 155 | frameGm.moveCenter(centerPoint) |
---|
| 156 | self.w.move(frameGm.topLeft()) |
---|
| 157 | self.w.show() |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | |
---|
[2116] | 161 | def vis(self): |
---|
| 162 | |
---|
| 163 | if str(self.psolver_box.currentIndex()) == str(1): |
---|
| 164 | self.fft_method_box.setVisible(True) |
---|
| 165 | self.fft_method_label.setVisible(True) |
---|
| 166 | |
---|
| 167 | if str(self.psolver_box.currentIndex()) != str(1): |
---|
| 168 | self.fft_method_box.setVisible(False) |
---|
| 169 | self.fft_method_label.setVisible(False) |
---|
| 170 | |
---|
| 171 | def load_gui(self): |
---|
| 172 | self.child_win = MyApp3() |
---|
| 173 | self.child_win.show() |
---|
| 174 | |
---|
[2308] | 175 | def run_transfer(self): |
---|
| 176 | self.threadclass = Threadclass() |
---|
| 177 | self.connect(self.threadclass, QtCore.SIGNAL('finish'), self.behind_run) |
---|
| 178 | #self.connect(self.threadclass, QtCore.SIGNAL('progress'), self.up2date) |
---|
| 179 | self.connect(self.threadclass, QtCore.SIGNAL('startqmsg'), self.takeoff) |
---|
| 180 | self.connect(self.threadclass, QtCore.SIGNAL('check'), self.checkme) |
---|
| 181 | self.threadclass.runx() |
---|
[2116] | 182 | |
---|
[2308] | 183 | def run_program(self): |
---|
[2116] | 184 | |
---|
| 185 | |
---|
[2308] | 186 | self.result_label.setText('Starting calculation...') |
---|
| 187 | #self.QtCore.QCoreApplication.processEvents() |
---|
| 188 | QtGui.QApplication.processEvents() |
---|
| 189 | #self.setEnabled(False) |
---|
[2116] | 190 | # self.Ui_MainWindow.setDisabled(True) |
---|
[2308] | 191 | #self.qmsg_wait(0) |
---|
| 192 | #print("bool state ", self.npex_npey_box.checkState()) # XXX |
---|
[2116] | 193 | np_min = str(self.np_min_box.value()) |
---|
| 194 | np_max = str(self.np_max_box.value()) |
---|
| 195 | nx_min = str(self.nx_min_box.value()) |
---|
| 196 | nx_max = str(self.nx_max_box.value()) |
---|
| 197 | ny_min = str(self.ny_min_box.value()) |
---|
| 198 | ny_max = str(self.ny_max_box.value()) |
---|
| 199 | nz_min = str(self.nz_min_box.value()) |
---|
| 200 | nz_max = str(self.nz_max_box.value()) |
---|
| 201 | tpn = str(self.tpn_box.value()) |
---|
| 202 | dnpexnpey = str(self.d_box.value()) |
---|
[2308] | 203 | dnpexnpey_tolerance = str(self.tolerance_value.value()) |
---|
[2116] | 204 | dnxny = str(self.dnxny_box.value()) |
---|
[2308] | 205 | myobject = MyPopup() |
---|
| 206 | ld_thrs = myobject.load_thres.value() |
---|
| 207 | rslt_thrs = myobject.result_thres.value() |
---|
[2116] | 208 | |
---|
| 209 | if str(self.psolver_box.currentIndex()) == str(1): |
---|
| 210 | poisfft = True |
---|
| 211 | switch = True |
---|
| 212 | if str(self.fft_method_box.currentIndex()) == str(2): |
---|
| 213 | temperton = True |
---|
| 214 | else: |
---|
| 215 | temperton = False |
---|
| 216 | else: |
---|
| 217 | poisfft = False |
---|
| 218 | temperton = False |
---|
| 219 | switch = False |
---|
| 220 | |
---|
| 221 | if str(self.psolver_box.currentIndex()) == str(2): |
---|
| 222 | mlt_grid = True |
---|
| 223 | else: |
---|
| 224 | mlt_grid = False |
---|
| 225 | |
---|
| 226 | if str(self.Oos_checkbox.checkState()) == str(2): |
---|
| 227 | spctre = True |
---|
| 228 | poisfft = True |
---|
| 229 | else: |
---|
| 230 | spctre = False |
---|
[2308] | 231 | |
---|
| 232 | if int(self.strict_box.checkState()) != 2: |
---|
| 233 | tpn = 0 |
---|
| 234 | |
---|
| 235 | if int(self.npex_npey_box.checkState()) != 2: |
---|
| 236 | dnpexnpey = 0 |
---|
| 237 | dnpexnpey_tolerance = 0 |
---|
| 238 | |
---|
| 239 | #print(poisfft, switch, temperton, mlt_grid, spctre) |
---|
| 240 | config_wr.write_config(np_min, np_max, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, tpn, dnpexnpey,dnpexnpey_tolerance, dnxny, |
---|
| 241 | str(poisfft), str(switch), str(temperton), str(mlt_grid), str(spctre), rslt_thrs, ld_thrs) |
---|
| 242 | #time.sleep(1) |
---|
| 243 | # execute_script.grid_executer() temp deactive |
---|
| 244 | self.testbar.setVisible(True) |
---|
| 245 | QtCore.QCoreApplication.processEvents() |
---|
| 246 | self.run_transfer() |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | def behind_run(self): |
---|
| 250 | trigger_bool = False |
---|
| 251 | #print("behind_run executed") |
---|
[2116] | 252 | checkfile = open(".palm_gf_tmp", "r") |
---|
[2308] | 253 | #self.result_label.setText(str(checkfile.readline())) |
---|
| 254 | res_text = str(checkfile.readline()) # XXX |
---|
| 255 | self.result_label.setText(res_text) |
---|
| 256 | result_nr = res_text.split(' ')[2] |
---|
[2116] | 257 | if int(checkfile.readline()) == 1: |
---|
| 258 | self.view_result_button.setVisible(True) |
---|
[2308] | 259 | trigger_bool = True |
---|
[2116] | 260 | self.result_label.setVisible(True) |
---|
| 261 | self.result_headline.setVisible(True) |
---|
| 262 | self.line_res_down.setVisible(True) |
---|
[2308] | 263 | #self.line_res_up.setVisible(True) |
---|
[2116] | 264 | self.load_text_label.setVisible(False) |
---|
| 265 | self.nor_spinbox.setVisible(False) |
---|
| 266 | checkfile.close() |
---|
[2308] | 267 | #self.setEnabled(True) |
---|
[2116] | 268 | self.filename_line.setVisible(True) |
---|
| 269 | self.save_button.setVisible(True) |
---|
[2308] | 270 | parameters = config_wr.read_config() |
---|
[2116] | 271 | |
---|
| 272 | |
---|
[2308] | 273 | if trigger_bool is True and int(result_nr) < int(parameters[18]): |
---|
| 274 | self.result_label.setText(res_text + 'Loading Ui...') |
---|
| 275 | self.load_gui() # XXXX |
---|
| 276 | self.result_label.setText(res_text) |
---|
| 277 | #self.close() |
---|
| 278 | #frameGm = self.frameGeometry() |
---|
| 279 | #screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) |
---|
| 280 | #centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() |
---|
| 281 | #frameGm = self.frameGeometry() |
---|
| 282 | #screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) |
---|
| 283 | #centerPoint = str(centerPoint) |
---|
| 284 | #xcenter = centerPoint.split('(')[1].split(',')[0] |
---|
| 285 | #ycenter = centerPoint.split('(')[1].split(',')[1].split(')')[0] |
---|
| 286 | ##print xcenter, ycenter |
---|
| 287 | #centerPoint = QtCore.QPoint(int(xcenter) - 292, int(ycenter)) |
---|
| 288 | #frameGm.moveCenter(centerPoint) |
---|
| 289 | #self.move(frameGm.topLeft()) |
---|
[2116] | 290 | |
---|
| 291 | |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | def get_path(wildcard): |
---|
| 298 | import wx |
---|
| 299 | app = wx.App(None) |
---|
| 300 | style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST |
---|
| 301 | dialog = wx.FileDialog(None, 'Open', wildcard='*.db') |
---|
| 302 | if dialog.ShowModal() == wx.ID_OK: |
---|
| 303 | path = dialog.GetPath() |
---|
[2308] | 304 | |
---|
| 305 | print(path, file) |
---|
[2116] | 306 | else: |
---|
| 307 | path = None |
---|
| 308 | dialog.Destroy() |
---|
| 309 | return |
---|
| 310 | |
---|
| 311 | |
---|
| 312 | |
---|
| 313 | def save_results(self): |
---|
| 314 | |
---|
| 315 | #self.get_path() |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | import os |
---|
| 320 | import shutil |
---|
| 321 | prvs = '.palm_gf_data.db' |
---|
| 322 | new = str(self.filename_line.text()) |
---|
| 323 | print(new) |
---|
| 324 | shutil.copy(prvs, new) |
---|
| 325 | print(prvs, new) |
---|
| 326 | |
---|
| 327 | def qmsg(self): |
---|
| 328 | msgbox = QtGui.QMessageBox() |
---|
| 329 | msgbox.setWindowTitle("Information") |
---|
| 330 | # msgbox.setVisible(False) |
---|
| 331 | msgbox.Information |
---|
| 332 | msgbox.setText("Calculating, please be patient.") |
---|
| 333 | # msgbox. |
---|
| 334 | msgbox.setModal(True) |
---|
| 335 | msgbox.exec_() |
---|
| 336 | |
---|
[2308] | 337 | def tester(self): |
---|
| 338 | #print("tester was executed from run method") |
---|
| 339 | pass |
---|
[2116] | 340 | |
---|
[2308] | 341 | def qmsg_wait(self, progress): |
---|
| 342 | global msgbox |
---|
| 343 | msgbox = QtGui.QMessageBox() |
---|
| 344 | layout = msgbox.layout() |
---|
| 345 | layout.itemAtPosition(layout.rowCount() - 1, 0).widget().hide() |
---|
| 346 | global progressx |
---|
| 347 | progressx = QtGui.QProgressBar() |
---|
| 348 | layout.addWidget(progressx, layout.rowCount(), 0, 1, layout.columnCount()) |
---|
| 349 | |
---|
| 350 | msgbox.setWindowTitle("Progress") |
---|
| 351 | msgbox.Information |
---|
| 352 | msgbox.setText("Calculating, please be patient.") |
---|
| 353 | |
---|
| 354 | progressx.setValue(int(progress)) |
---|
| 355 | #msgbox.setModal(False) |
---|
| 356 | msgbox.exec_() |
---|
| 357 | |
---|
| 358 | def up2date(self, progress): |
---|
| 359 | |
---|
| 360 | progressx.setValue(int(progress)) |
---|
| 361 | if progress == 100: |
---|
| 362 | msgbox.done(1) |
---|
| 363 | |
---|
| 364 | def takeoff(self): |
---|
| 365 | #self.qmsg_wait(0) |
---|
| 366 | pass |
---|
| 367 | |
---|
| 368 | def checkme(self, check): |
---|
| 369 | #print(check) |
---|
| 370 | self.testbar.setValue(int(check)) |
---|
| 371 | |
---|
| 372 | if check == 100: |
---|
| 373 | self.testbar.setVisible(False) |
---|
| 374 | QtGui.QApplication.processEvents() |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | class Threadclass(QtCore.QThread): |
---|
| 381 | def __init__(self, parent = None): |
---|
| 382 | super(Threadclass, self).__init__(parent) |
---|
| 383 | |
---|
| 384 | def runx(self): |
---|
| 385 | #print("runx exec.") |
---|
| 386 | self.execute() |
---|
| 387 | |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | def execute(self): |
---|
| 391 | self.emit(QtCore.SIGNAL('startqmsg'), 0) |
---|
| 392 | |
---|
| 393 | parameters = config_wr.read_config() |
---|
| 394 | min_procs = int(parameters[0]) |
---|
| 395 | max_procs = int(parameters[1]) |
---|
| 396 | tpn = int(parameters[2]) |
---|
| 397 | dnpexnpey = float(parameters[3]) |
---|
| 398 | dnpexnpey_tol = int(parameters[4]) |
---|
| 399 | dnxny = float(parameters[5]) |
---|
| 400 | nx_min = int(parameters[6]) |
---|
| 401 | nx_max = int(parameters[7]) |
---|
| 402 | ny_min = int(parameters[8]) |
---|
| 403 | ny_max = int(parameters[9]) |
---|
| 404 | nz_min = int(parameters[10]) |
---|
| 405 | nz_max = int(parameters[11]) |
---|
| 406 | poisfft = parameters[12] |
---|
| 407 | switch = parameters[13] |
---|
| 408 | tempterton = parameters[14] |
---|
| 409 | mlt_grid = parameters[15] |
---|
| 410 | spectr = parameters[16] |
---|
| 411 | result_thrs = parameters[17] |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | path = "/localdata/.palm_gf_data.db" |
---|
| 415 | pathx = parameters[19] + '/.palm_gf_data.db' |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | conn = sqlite3.connect(pathx) |
---|
| 419 | #conn = sqlite3.connect(".palm_gf_data.db") |
---|
| 420 | c = conn.cursor() |
---|
| 421 | c.execute("DROP TABLE IF EXISTS grid_current") |
---|
| 422 | c.execute("DROP TABLE IF EXISTS grid_limits") |
---|
| 423 | c.execute( |
---|
[2309] | 424 | "CREATE TABLE IF NOT EXISTS grid_current(nx INT, ny INT, nz INT, npex INT, npey INT, npxnpy FLOAT, np INT, ngpts INT, nxnpex FLOAT, nynpey FLOAT)") |
---|
[2308] | 425 | c.execute( |
---|
[2309] | 426 | "CREATE TABLE IF NOT EXISTS grid_limits(nx INT, ny INT, nz INT, npex INT, npey INT, npxnpy FLOAT, np INT, ngpts INT, nxnpex FLOAT, nynpey FLOAT)") |
---|
[2308] | 427 | conn.commit() |
---|
| 428 | main_bool = True |
---|
| 429 | |
---|
| 430 | |
---|
| 431 | |
---|
| 432 | |
---|
| 433 | if poisfft == str(True): |
---|
| 434 | poisfft = True |
---|
| 435 | else: |
---|
| 436 | poisfft = False |
---|
| 437 | |
---|
| 438 | if switch == str(True): |
---|
| 439 | switch = True |
---|
| 440 | else: |
---|
| 441 | switch = False |
---|
| 442 | |
---|
| 443 | if tempterton == str(True): |
---|
| 444 | tempterton = True |
---|
| 445 | else: |
---|
| 446 | tempterton = False |
---|
| 447 | |
---|
| 448 | if mlt_grid == str(True): |
---|
| 449 | mlt_grid = True |
---|
| 450 | else: |
---|
| 451 | mlt_grid = False |
---|
| 452 | |
---|
| 453 | if spectr == str(True): |
---|
| 454 | spectr = True |
---|
| 455 | else: |
---|
| 456 | spectr = False |
---|
| 457 | |
---|
| 458 | #print(spectr, type(spectr)) |
---|
| 459 | #print(poisfft, switch, tempterton, mlt_grid, spectr) |
---|
| 460 | |
---|
| 461 | np_used = min_procs |
---|
| 462 | counter = 0 |
---|
| 463 | |
---|
| 464 | nx = nx_min |
---|
| 465 | ny = ny_min |
---|
| 466 | nz = nz_min |
---|
| 467 | |
---|
| 468 | from math import floor |
---|
| 469 | |
---|
| 470 | def factors(n): |
---|
| 471 | result = [] |
---|
| 472 | for i in range(2, n + 1): # test all integers between 2 and n |
---|
| 473 | s = 0 |
---|
| 474 | while n / i == floor(n / float(i)): # is n/i an integer? |
---|
| 475 | n = n / float(i) |
---|
| 476 | s += 1 |
---|
| 477 | if s > 0: |
---|
| 478 | for k in range(s): |
---|
| 479 | result.append(i) # i is a pf s times |
---|
| 480 | if n == 1: |
---|
| 481 | return result |
---|
| 482 | |
---|
| 483 | while np_used <= max_procs: |
---|
| 484 | a = 1 |
---|
| 485 | |
---|
| 486 | while a <= np_used: |
---|
| 487 | prcs_var = np_used % a |
---|
| 488 | if prcs_var != 0: |
---|
| 489 | a += 1 |
---|
| 490 | elif prcs_var == 0: |
---|
| 491 | npex = a |
---|
| 492 | npey = int(np_used / npex) |
---|
| 493 | |
---|
| 494 | if tpn != 0: # XXX |
---|
| 495 | |
---|
| 496 | if np_used % tpn != 0: |
---|
| 497 | a += 1 |
---|
| 498 | continue |
---|
| 499 | |
---|
| 500 | if dnpexnpey != 0 and npex / npey != dnpexnpey: |
---|
| 501 | a += 1 |
---|
| 502 | continue |
---|
| 503 | |
---|
| 504 | if dnpexnpey != 0: |
---|
| 505 | |
---|
| 506 | |
---|
| 507 | if float(npex) / float(npey) < (dnpexnpey - dnpexnpey*dnpexnpey_tol/100): |
---|
| 508 | a += 1 |
---|
| 509 | continue |
---|
| 510 | |
---|
| 511 | if float(npex) / float(npey) > (dnpexnpey + dnpexnpey*dnpexnpey_tol/100): |
---|
| 512 | a += 1 |
---|
| 513 | continue |
---|
| 514 | |
---|
| 515 | while nx <= nx_max: |
---|
| 516 | if (nx + 1) % npex != 0: |
---|
| 517 | nx += 1 |
---|
| 518 | continue |
---|
| 519 | |
---|
| 520 | if mlt_grid is True and (nx + 1) % 2 != 0: |
---|
| 521 | nx += 1 |
---|
| 522 | continue |
---|
| 523 | |
---|
| 524 | if switch is True and (nx + 1) % npey != 0: |
---|
| 525 | nx += 1 |
---|
| 526 | continue |
---|
| 527 | if npex > nx: |
---|
| 528 | nx += 1 |
---|
| 529 | continue |
---|
| 530 | |
---|
| 531 | while ny <= ny_max: |
---|
| 532 | |
---|
| 533 | if dnxny != 0 and float(nx) / float(ny) != float(dnxny): |
---|
| 534 | ny += 1 |
---|
| 535 | continue |
---|
| 536 | if (ny + 1) % npey != 0: |
---|
| 537 | ny += 1 |
---|
| 538 | continue |
---|
| 539 | |
---|
| 540 | #if mlt_grid is True and ny % 2 != 0: mlt and mlt_noOpt have same cond. |
---|
| 541 | # ny += 1 |
---|
| 542 | # continue |
---|
| 543 | |
---|
| 544 | if (ny + 1) % npex != 0 and switch is True: |
---|
| 545 | ny += 1 |
---|
| 546 | continue |
---|
| 547 | if npey > ny: |
---|
| 548 | ny += 1 |
---|
| 549 | continue |
---|
| 550 | |
---|
| 551 | while nz <= nz_max: |
---|
| 552 | |
---|
| 553 | if mlt_grid is True and nz % 2 != 0: |
---|
| 554 | nz += 1 |
---|
| 555 | continue |
---|
| 556 | |
---|
| 557 | if poisfft is True and nz % npex != 0: |
---|
| 558 | nz += 1 |
---|
| 559 | continue |
---|
| 560 | |
---|
| 561 | if spectr is True and nz % npey != 0: |
---|
| 562 | nz += 1 |
---|
| 563 | continue |
---|
| 564 | |
---|
| 565 | if tempterton is True and nx > 1 and ny > 1: # and nz < 1: |
---|
| 566 | |
---|
| 567 | nx_list = factors(nx + 1) |
---|
| 568 | |
---|
| 569 | i = 0 |
---|
| 570 | nx_var = nx_list[i] |
---|
| 571 | |
---|
| 572 | |
---|
| 573 | while i < len(nx_list): |
---|
| 574 | if nx_var != 2 or nx_var != 3 or nx_var != 5: |
---|
| 575 | i += 1 |
---|
| 576 | continue |
---|
| 577 | |
---|
| 578 | i += 1 |
---|
| 579 | ny_list = factors(ny + 1) |
---|
| 580 | i = 0 |
---|
| 581 | ny_var = ny_list[i] |
---|
| 582 | while i < len(ny_list): |
---|
| 583 | if ny_var != 2 or ny_var != 3 or ny_var != 5: |
---|
| 584 | i += 1 |
---|
| 585 | continue |
---|
| 586 | i += 1 |
---|
| 587 | |
---|
| 588 | counter += 1 |
---|
| 589 | if counter > int(result_thrs): |
---|
| 590 | break |
---|
| 591 | |
---|
| 592 | npxnpy = format(float(npex) / float(npey), '.2f') |
---|
[2309] | 593 | nxpex = float(nx+1) /float(npex) |
---|
| 594 | nypey = float(ny+1) /float(npey) |
---|
| 595 | |
---|
[2308] | 596 | c.execute( |
---|
[2309] | 597 | """INSERT OR REPLACE INTO grid_current(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", |
---|
| 598 | (nx, ny, nz, npex, npey, npxnpy, (npex * npey), (nx * ny * nz), nxpex, nypey)) |
---|
[2308] | 599 | |
---|
| 600 | nz += 1 |
---|
| 601 | nz = nz_min |
---|
| 602 | ny += 1 |
---|
| 603 | ny = ny_min |
---|
| 604 | nx += 1 |
---|
| 605 | nx = nx_min |
---|
| 606 | a += 1 |
---|
| 607 | # a += 1 |
---|
| 608 | np_used += 1 |
---|
| 609 | progr_act = 100*(float(np_used-1)/float(max_procs)) |
---|
| 610 | self.emit(QtCore.SIGNAL('check'), progr_act) |
---|
| 611 | #print(np_used, max_procs, progr_act) |
---|
| 612 | self.emit(QtCore.SIGNAL('progress'), progr_act) |
---|
| 613 | |
---|
| 614 | conn.commit() |
---|
| 615 | |
---|
| 616 | conn.commit() |
---|
| 617 | #c.close() |
---|
| 618 | #conn.close() |
---|
| 619 | # |
---|
| 620 | ## ******************************** |
---|
| 621 | # |
---|
| 622 | #conn = sqlite3.connect(parameters[19] + '/.palm_gf_data.db') |
---|
| 623 | #print parameters[19] + '/.palm_gf_data.db' |
---|
| 624 | #c = conn.cursor() |
---|
| 625 | try: |
---|
| 626 | c.execute("SELECT nx FROM grid_current ORDER BY nx DESC LIMIT 1") |
---|
| 627 | mx_nx = c.fetchone()[0] |
---|
| 628 | # print(mx_nx) |
---|
| 629 | c.execute("SELECT nx FROM grid_current ORDER BY nx LIMIT 1") |
---|
| 630 | mn_nx = c.fetchone()[0] |
---|
| 631 | # print(mn_nx) |
---|
| 632 | c.execute("SELECT ny FROM grid_current ORDER BY ny DESC LIMIT 1") |
---|
| 633 | mx_ny = c.fetchone()[0] |
---|
| 634 | # print(mx_ny) |
---|
| 635 | c.execute("SELECT ny FROM grid_current ORDER BY ny LIMIT 1") |
---|
| 636 | mn_ny = c.fetchone()[0] |
---|
| 637 | # print(mn_ny) |
---|
| 638 | c.execute("SELECT nz FROM grid_current ORDER BY nz DESC LIMIT 1") |
---|
| 639 | mx_nz = c.fetchone()[0] |
---|
| 640 | # print(mx_nz) |
---|
| 641 | c.execute("SELECT nz FROM grid_current ORDER BY nz LIMIT 1") |
---|
| 642 | mn_nz = c.fetchone()[0] |
---|
| 643 | # print(mn_nz) |
---|
| 644 | c.execute("SELECT npex FROM grid_current ORDER BY npex DESC LIMIT 1") |
---|
| 645 | mx_npex = c.fetchone()[0] |
---|
| 646 | # print(mx_npex) |
---|
| 647 | c.execute("SELECT npex FROM grid_current ORDER BY npex LIMIT 1") |
---|
| 648 | mn_npex = c.fetchone()[0] |
---|
| 649 | # print(mn_npex) |
---|
| 650 | c.execute("SELECT npey FROM grid_current ORDER BY npey DESC LIMIT 1") |
---|
| 651 | mx_npey = c.fetchone()[0] |
---|
| 652 | # print(mx_npey) |
---|
| 653 | c.execute("SELECT npey FROM grid_current ORDER BY npey LIMIT 1") |
---|
| 654 | mn_npey = c.fetchone()[0] |
---|
| 655 | # print(mn_npey) |
---|
| 656 | c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy DESC LIMIT 1") |
---|
| 657 | mx_npxnpy = c.fetchone()[0] |
---|
| 658 | # print(mx_npxnpy) |
---|
| 659 | c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy LIMIT 1") |
---|
| 660 | mn_npxnpy = c.fetchone()[0] |
---|
| 661 | # print(mn_npxnpy) |
---|
| 662 | c.execute("SELECT np FROM grid_current ORDER BY np DESC LIMIT 1") |
---|
| 663 | mx_np = c.fetchone()[0] |
---|
| 664 | # print(mx_np) |
---|
| 665 | c.execute("SELECT np FROM grid_current ORDER BY np LIMIT 1") |
---|
| 666 | mn_np = c.fetchone()[0] |
---|
| 667 | # print(mn_np) |
---|
| 668 | c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts DESC LIMIT 1") |
---|
| 669 | mx_ngpts = c.fetchone()[0] |
---|
| 670 | # print(mx_ngpts) |
---|
| 671 | c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts LIMIT 1") |
---|
| 672 | mn_ngpts = c.fetchone()[0] |
---|
| 673 | # print(mn_ngpts) |
---|
[2309] | 674 | c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex DESC LIMIT 1") |
---|
| 675 | mx_nxpex = c.fetchone()[0] |
---|
| 676 | c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex LIMIT 1") |
---|
| 677 | mn_nxpex = c.fetchone()[0] |
---|
| 678 | c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey DESC LIMIT 1") |
---|
| 679 | mx_nypey = c.fetchone()[0] |
---|
| 680 | c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey LIMIT 1") |
---|
| 681 | mn_nypey = c.fetchone()[0] |
---|
[2308] | 682 | |
---|
[2309] | 683 | |
---|
| 684 | |
---|
[2308] | 685 | conn.commit() |
---|
| 686 | c.execute( |
---|
[2309] | 687 | """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", |
---|
| 688 | (mn_nx, mn_ny, mn_nz, mn_npex, mn_npey, mn_npxnpy, mn_np, mn_ngpts, mn_nxpex, mn_nypey)) |
---|
[2308] | 689 | |
---|
| 690 | c.execute( |
---|
[2309] | 691 | """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", |
---|
| 692 | (mx_nx, mx_ny, mx_nz, mx_npex, mx_npey, mx_npxnpy, mx_np, mx_ngpts, mx_nxpex, mx_nypey)) |
---|
[2308] | 693 | conn.commit() |
---|
| 694 | |
---|
| 695 | c.close() |
---|
| 696 | conn.close() |
---|
| 697 | except TypeError: |
---|
| 698 | |
---|
| 699 | checkfile = open(".palm_gf_tmp", "w") |
---|
| 700 | if counter != 0: |
---|
| 701 | checkfile.write("Gridfinder found " + str(counter) + " results.\n1") |
---|
| 702 | else: |
---|
| 703 | checkfile.write("Check input, no Results found.\n0") |
---|
| 704 | checkfile.close() |
---|
| 705 | |
---|
| 706 | checkfile = open(".palm_gf_tmp", "w") |
---|
| 707 | if counter != 0: |
---|
| 708 | checkfile.write("Gridfinder found " + str(counter) + " results.\n1") |
---|
| 709 | else: |
---|
| 710 | checkfile.write("Check input, no Results found.\n0") |
---|
| 711 | checkfile.close() |
---|
| 712 | self.emit(QtCore.SIGNAL('finish'), 1) |
---|
| 713 | #print("finished with main execute") |
---|
| 714 | |
---|
| 715 | |
---|
| 716 | |
---|
| 717 | |
---|
| 718 | |
---|
| 719 | qtpopupFile = palm_bin + '/palm_gf_files/palm_gf_settings.ui' |
---|
| 720 | Ui_Pop, QtBaseClass = uic.loadUiType(qtpopupFile) |
---|
| 721 | |
---|
| 722 | |
---|
| 723 | class MyPopup(QtGui.QWidget, Ui_Pop): |
---|
| 724 | |
---|
| 725 | def __init__(self): |
---|
| 726 | Qt.QWidget.__init__(self) |
---|
| 727 | Ui_Pop.__init__(self) |
---|
| 728 | |
---|
| 729 | self.setupUi(self) |
---|
| 730 | self.show |
---|
| 731 | self.savepath.clicked.connect(self.path_to_save) |
---|
| 732 | self.begin_check() |
---|
| 733 | self.buttonBox.accepted.connect(self.end_check) |
---|
| 734 | self.buttonBox.rejected.connect(self.close) |
---|
| 735 | |
---|
| 736 | |
---|
| 737 | def begin_check(self): |
---|
| 738 | file_check = palm_dir + '/trunk/SCRIPTS/.palm_gf_config' |
---|
| 739 | if os.path.isfile(file_check) is True: |
---|
| 740 | parameters = config_wr.read_config_settings() |
---|
| 741 | self.linepath.setText(parameters[0]) |
---|
| 742 | self.result_thres.setValue(int(parameters[1])) |
---|
| 743 | self.load_thres.setValue(int(parameters[2])) |
---|
| 744 | |
---|
| 745 | def end_check(self): |
---|
| 746 | config_wr.write_config_settings(self.linepath.text(), self.result_thres.value(), self.load_thres.value()) |
---|
| 747 | |
---|
| 748 | self.close() |
---|
| 749 | |
---|
| 750 | |
---|
| 751 | |
---|
| 752 | |
---|
| 753 | |
---|
| 754 | def path_to_save(self, wildcard= None): |
---|
| 755 | import wx |
---|
| 756 | app = wx.App(None) |
---|
| 757 | style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST |
---|
| 758 | dialog = wx.DirDialog(None, 'Open') |
---|
| 759 | if dialog.ShowModal() == wx.ID_OK: |
---|
| 760 | path = str(dialog.GetPath()) |
---|
| 761 | |
---|
| 762 | print(path) |
---|
| 763 | self.linepath.setText(path) |
---|
| 764 | |
---|
| 765 | |
---|
| 766 | |
---|
| 767 | else: |
---|
| 768 | path = None |
---|
| 769 | dialog.Destroy() |
---|
| 770 | return |
---|
| 771 | |
---|
| 772 | |
---|
| 773 | |
---|
| 774 | |
---|
| 775 | |
---|
| 776 | |
---|
| 777 | |
---|
| 778 | |
---|
[2116] | 779 | if __name__ == "__main__": |
---|
| 780 | import time |
---|
| 781 | app = QtGui.QApplication(sys.argv) |
---|
| 782 | window = MyApp1() |
---|
| 783 | window.setWindowTitle('Gridfinder') |
---|
| 784 | window.show() |
---|
| 785 | sys.exit(app.exec_()) |
---|