Changeset 5251ec6 in sasview for src/sas/sasgui/perspectives/invariant/invariant_state.py
- Timestamp:
- Oct 11, 2018 2:20:56 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1249
- Children:
- 98b9f32
- Parents:
- 67ed543
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/invariant/invariant_state.py
re9920cd r5251ec6 2 2 State class for the invariant UI 3 3 """ 4 from __future__ import print_function 4 5 5 6 # import time … … 140 141 141 142 # text ctl general inputs ( excluding extrapolation text ctl) 142 for key, value in self.input_list.ite ritems():143 for key, value in self.input_list.items(): 143 144 if value == '': 144 145 continue … … 166 167 low_off = False 167 168 high_off = False 168 for key, value in self.input_list.ite ritems():169 for key, value in self.input_list.items(): 169 170 key_split = key.split('_') 170 171 max_ind = len(key_split) - 1 … … 216 217 # other outputs than Q* 217 218 name = item[0] + "_tcl" 218 if name in self.saved_state .keys():219 if name in self.saved_state: 219 220 value = self.saved_state[name] 220 221 … … 301 302 top_element.appendChild(state) 302 303 303 for name, value in self.saved_state.ite ritems():304 for name, value in self.saved_state.items(): 304 305 element = newdoc.createElement(str(name)) 305 306 element.appendChild(newdoc.createTextNode(str(value))) … … 310 311 top_element.appendChild(history) 311 312 312 for name, value in self.state_list.ite ritems():313 for name, value in self.state_list.items(): 313 314 history_element = newdoc.createElement('state_' + str(name)) 314 for state_name, state_value in value.ite ritems():315 for state_name, state_value in value.items(): 315 316 state_element = newdoc.createElement(str(state_name)) 316 317 child = newdoc.createTextNode(str(state_value)) … … 325 326 top_element.appendChild(bookmark) 326 327 item_list = ['time', 'date', 'state', 'comp_state'] 327 for name, value_list in self.bookmark_list.ite ritems():328 for name, value_list in self.bookmark_list.items(): 328 329 element = newdoc.createElement('mark_' + str(name)) 329 330 _, date, state, comp_state = value_list … … 334 335 state_list_element = newdoc.createElement('state') 335 336 comp_state_list_element = newdoc.createElement('comp_state') 336 for state_name, state_value in value_list[2].ite ritems():337 for state_name, state_value in value_list[2].items(): 337 338 state_element = newdoc.createElement(str(state_name)) 338 339 child = newdoc.createTextNode(str(state_value)) 339 340 state_element.appendChild(child) 340 341 state_list_element.appendChild(state_element) 341 for comp_name, comp_value in value_list[3].ite ritems():342 for comp_name, comp_value in value_list[3].items(): 342 343 comp_element = newdoc.createElement(str(comp_name)) 343 344 comp_element.appendChild(newdoc.createTextNode(str(comp_value))) … … 368 369 msg = "InvariantSate no longer supports non-CanSAS" 369 370 msg += " format for invariant files" 370 raise RuntimeError , msg371 raise RuntimeError(msg) 371 372 372 373 if node.get('version')\ … … 383 384 try: 384 385 timestamp = (entry.get('epoch')) 385 except :386 except Exception as exc: 386 387 msg = "InvariantSate.fromXML: Could not read" 387 msg += " timestamp\n %s" % sys.exc_value388 msg += " timestamp\n %s" % exc 388 389 logger.error(msg) 389 390 … … 453 454 Get the values (strings) from __str__ for report 454 455 """ 455 strings = self.__str__()456 457 456 # default string values 458 for num in range(1, 19): 459 exec "s_%s = 'NA'" % str(num) 460 lines = strings.split('\n') 457 s = {num: 'NA' for num in range(1, 19)} 461 458 # get all string values from __str__() 462 for line in range(0, len(lines)): 463 if line == 1: 464 s_1 = lines[1] 465 elif line == 2: 466 s_2 = lines[2] 459 lines = str(self).split('\n') 460 for line_num, line in enumerate(lines): 461 if line_num == 1: 462 s[1] = line 463 elif line_num == 2: 464 s[2] = line 467 465 else: 468 item = line s[line].split(':')466 item = line.split(':') 469 467 item[0] = item[0].strip() 470 468 if item[0] == "scale": 471 s _3= item[1]469 s[3] = item[1] 472 470 elif item[0] == "porod constant": 473 s _4= item[1]471 s[4] = item[1] 474 472 elif item[0] == "background": 475 s _5= item[1]473 s[5] = item[1] 476 474 elif item[0] == "contrast": 477 s _6= item[1]475 s[6] = item[1] 478 476 elif item[0] == "Extrapolation": 479 477 extra = item[1].split(";") 480 478 bool_0 = extra[0].split("=") 481 479 bool_1 = extra[1].split("=") 482 s _8= " " + bool_0[0] + "Q region = " + bool_0[1]483 s _7= " " + bool_1[0] + "Q region = " + bool_1[1]480 s[8] = " " + bool_0[0] + "Q region = " + bool_0[1] 481 s[7] = " " + bool_1[0] + "Q region = " + bool_1[1] 484 482 elif item[0] == "npts low": 485 s _9= item[1]483 s[9] = item[1] 486 484 elif item[0] == "npts high": 487 s _10= item[1]485 s[10] = item[1] 488 486 elif item[0] == "volume fraction": 489 487 val = item[1].split("+-")[0].strip() 490 488 error = item[1].split("+-")[1].strip() 491 s _17= val + " ± " + error489 s[17] = val + " ± " + error 492 490 elif item[0] == "specific surface": 493 491 val = item[1].split("+-")[0].strip() 494 492 error = item[1].split("+-")[1].strip() 495 s _18= val + " ± " + error493 s[18] = val + " ± " + error 496 494 elif item[0].split("(")[0].strip() == "power low": 497 s _11= item[0] + " =" + item[1]495 s[11] = item[0] + " =" + item[1] 498 496 elif item[0].split("(")[0].strip() == "power high": 499 s _12= item[0] + " =" + item[1]497 s[12] = item[0] + " =" + item[1] 500 498 elif item[0].split("[")[0].strip() == "Q* from low Q extrapolation": 501 499 # looks messy but this way the symbols +_ and % work on html … … 504 502 err = error.split("%")[0].strip() 505 503 percent = error.split("%")[1].strip() 506 s _13= val + " ± " + err + "%" + percent504 s[13] = val + " ± " + err + "%" + percent 507 505 elif item[0].split("[")[0].strip() == "Q* from data": 508 506 val = item[1].split("+-")[0].strip() … … 510 508 err = error.split("%")[0].strip() 511 509 percent = error.split("%")[1].strip() 512 s _14= val + " ± " + err + "%" + percent510 s[14] = val + " ± " + err + "%" + percent 513 511 elif item[0].split("[")[0].strip() == "Q* from high Q extrapolation": 514 512 val = item[1].split("+-")[0].strip() … … 516 514 err = error.split("%")[0].strip() 517 515 percent = error.split("%")[1].strip() 518 s _15= val + " ± " + err + "%" + percent516 s[15] = val + " ± " + err + "%" + percent 519 517 elif item[0].split("[")[0].strip() == "total Q*": 520 518 val = item[1].split("+-")[0].strip() 521 519 error = item[1].split("+-")[1].strip() 522 s _16= val + " ± " + error520 s[16] = val + " ± " + error 523 521 else: 524 522 continue 525 523 526 s _1 = self._check_html_format(s_1)524 s[1] = self._check_html_format(s[1]) 527 525 file_name = self._check_html_format(self.file) 528 526 … … 530 528 self.set_plot_state(extra_high=bool_0[1], extra_low=bool_1[1]) 531 529 # get ready for report with setting all the html strings 532 self.report_str = str(self.template_str) % (s_1, s_2, 533 s_3, s_4, s_5, s_6, s_7, s_8, 534 s_9, s_10, s_11, s_12, s_13, s_14, s_15, 535 s_16, s_17, s_18, file_name, "%s") 530 self.report_str = str(self.template_str) % ( 531 s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], 532 s[12], s[13], s[14], s[15], s[16], s[17], s[18], file_name, "%s") 536 533 537 534 def _check_html_format(self, name): … … 692 689 state = InvariantState() 693 690 state.fromXML(node=nodes[0]) 694 except :691 except Exception as exc: 695 692 msg = "XML document does not contain invariant" 696 msg += " information.\n %s" % sys.exc_value693 msg += " information.\n %s" % exc 697 694 logger.info(msg) 698 695 return state … … 736 733 output.append(sas_entry) 737 734 else: 738 raise RuntimeError , "%s is not a file" % path735 raise RuntimeError("%s is not a file" % path) 739 736 740 737 # Return output consistent with the loader's api … … 782 779 msg = "The cansas writer expects a Data1D" 783 780 msg += " instance: %s" % str(datainfo.__class__.__name__) 784 raise RuntimeError , msg781 raise RuntimeError(msg) 785 782 # make sure title and data run is filled up. 786 783 if datainfo.title is None or datainfo.title == '':
Note: See TracChangeset
for help on using the changeset viewer.