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