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