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