Changeset 5251ec6 in sasview for src/sas/sasgui/perspectives/calculator
- 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
- Location:
- src/sas/sasgui/perspectives/calculator
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/calculator/__init__.py
r5a405bd r5251ec6 2 2 import os 3 3 from distutils.filelist import findall 4 from calculator import *4 from .calculator import * 5 5 N_DIR = 12 6 6 def get_data_path(media): -
src/sas/sasgui/perspectives/calculator/calculator.py
r61bfd36 r5251ec6 12 12 ################################################################################ 13 13 14 import logging 15 14 16 import wx 17 15 18 from sas.sasgui.guiframe.plugin_base import PluginBase 16 19 from sas.sasgui.perspectives.calculator.data_operator import DataOperatorWindow … … 26 29 from sas.sasgui.perspectives.calculator.image_viewer import ImageView 27 30 from sas.sasgui.perspectives.calculator.pyconsole import PyConsole 28 import logging29 31 30 32 logger = logging.getLogger(__name__) -
src/sas/sasgui/perspectives/calculator/collimation_editor.py
r959eb01 r5251ec6 1 1 """ 2 2 """ 3 import wx4 3 import sys 5 4 from copy import deepcopy 5 6 import wx 7 6 8 from sas.sascalc.dataloader.loader import Loader 7 9 from sas.sascalc.dataloader.data_info import Aperture, Collimation 8 from aperture_editor import ApertureDialog9 10 10 from sas.sasgui.guiframe.utils import check_float 11 12 from .aperture_editor import ApertureDialog 13 11 14 _BOX_WIDTH = 60 12 15 -
src/sas/sasgui/perspectives/calculator/data_editor.py
r235f514 r5251ec6 7 7 from sas.sascalc.dataloader.loader import Loader 8 8 from sas.sascalc.dataloader.data_info import Data2D 9 from detector_editor import DetectorDialog10 from collimation_editor import CollimationDialog11 from console import ConsoleDialog12 9 13 10 from sas.sasgui.guiframe.events import StatusEvent 11 12 from .detector_editor import DetectorDialog 13 from .collimation_editor import CollimationDialog 14 from .console import ConsoleDialog 15 14 16 15 17 … … 397 399 if data is None: 398 400 return 399 from sample_editor import SampleDialog401 from .sample_editor import SampleDialog 400 402 dlg = SampleDialog(parent=self, sample=data.sample) 401 403 dlg.set_manager(self) … … 409 411 if data is None: 410 412 return 411 from source_editor import SourceDialog413 from .source_editor import SourceDialog 412 414 dlg = SourceDialog(parent=self, source=data.source) 413 415 dlg.set_manager(self) … … 426 428 wlist = '|'.join(cards) 427 429 428 dlg = wx.FileDialog(self, "Choose a file", location, "", wlist, wx. OPEN)430 dlg = wx.FileDialog(self, "Choose a file", location, "", wlist, wx.FD_OPEN) 429 431 if dlg.ShowModal() == wx.ID_OK: 430 432 path = dlg.GetPath() … … 527 529 try: 528 530 #Load data 529 from load_thread import DataReader531 from .load_thread import DataReader 530 532 ## If a thread is already started, stop it 531 533 if self.reader is not None and self.reader.isrunning(): … … 535 537 updatefn=None) 536 538 self.reader.queue() 537 except :538 msg = "Data Editor: %s" % (sys.exc_value)539 except Exception as exc: 540 msg = "Data Editor: %s" % exc 539 541 load_error(msg) 540 542 return -
src/sas/sasgui/perspectives/calculator/data_operator.py
r7432acb r5251ec6 202 202 else: 203 203 text = name 204 state_list = self.get_datalist().values()205 204 name_list = [] 206 for state in s tate_list:205 for state in self.get_datalist().values(): 207 206 if state.data is None: 208 207 theory_list = state.get_theory() 209 theory, _ = theory_list.values()[0]208 theory, _ = list(theory_list.values())[0] 210 209 d_name = str(theory.name) 211 210 else: … … 393 392 try: 394 393 self.output = self.make_data_out(data1, data2) 395 except :394 except Exception as exc: 396 395 self._check_newname() 397 396 self._set_textctrl_color(self.data1_cbox, 'pink') 398 397 self._set_textctrl_color(self.data2_cbox, 'pink') 399 msg = "DataOperation: %s" % sys.exc_value398 msg = "DataOperation: %s" % exc 400 399 self.send_warnings(msg, 'error') 401 400 self.output = None … … 411 410 operator = self.operator_cbox.GetClientData(pos) 412 411 try: 413 exec "output = data1 %s data2" % operator 412 output = eval("data1 %s data2" % operator, 413 {"data1": data1, "data2": data2}) 414 414 except: 415 415 raise … … 532 532 self.data2_cbox.SetClientData(pos3, val) 533 533 dnames = [] 534 ids = self._data.keys() 535 for id in ids: 534 for id in self._data.keys(): 536 535 if id is not None: 537 536 if self._data[id].data is not None: … … 539 538 else: 540 539 theory_list = self._data[id].get_theory() 541 theory, _ = theory_list.values()[0]540 theory, _ = list(theory_list.values())[0] 542 541 dnames.append(theory.name) 543 542 ind = np.argsort(dnames) 544 543 if len(ind) > 0: 545 val_list = np.array( self._data.values())[ind]544 val_list = np.array(list(self._data.values()))[ind] 546 545 for datastate in val_list: 547 546 data = datastate.data … … 588 587 self.send_warnings('') 589 588 self.data_namectr.SetBackgroundColour('white') 590 state_list = self.get_datalist().values()591 589 name = self.data_namectr.GetValue().strip() 592 590 name_list = [] 593 for state in s tate_list:591 for state in self.get_datalist().values(): 594 592 if state.data is None: 595 593 theory_list = state.get_theory() 596 theory, _ = theory_list.values()[0]594 theory, _ = list(theory_list.values())[0] 597 595 d_name = str(theory.name) 598 596 else: … … 889 887 def _onProperties(self, event): 890 888 """ 891 when clicking on Properties on context menu , 892 The Property dialog is displayed 893 The user selects a transformation for x or y value and 894 a new plot is displayed 895 """ 896 list = [] 897 list = self.graph.returnPlottable() 898 if len(list.keys()) > 0: 899 first_item = list.keys()[0] 889 When clicking on Properties on context menu, the 890 Property dialog is displayed the user selects a 891 transformation for x or y value and a new plot is displayed 892 """ 893 plottables = self.graph.returnPlottable() 894 if plottables: 895 # TODO: key order is random prior to py 3.7 896 first_item = list(plottables.keys())[0] 900 897 if first_item.x != []: 901 898 from sas.sasgui.plottools.PropertyDialog import Properties … … 929 926 and set the scale 930 927 """ 931 list = []932 list = self.graph.returnPlottable()933 928 # Changing the scale might be incompatible with 934 929 # currently displayed data (for instance, going … … 940 935 _xscale = 'linear' 941 936 _yscale = 'linear' 942 for item in list:937 for item in self.graph.returnPlottable(): 943 938 item.setLabel(self.xLabel, self.yLabel) 944 939 # control axis labels from the panel itself -
src/sas/sasgui/perspectives/calculator/density_panel.py
r7432acb r5251ec6 362 362 self.molar_mass_ctl.SetValue(str(self._format_number(molar_mass))) 363 363 self.output_ctl.SetValue(str(output)) 364 except :364 except Exception as exc: 365 365 if self.base is not None: 366 msg = "Density/Volume Calculator: %s" % (sys.exc_value)366 msg = "Density/Volume Calculator: %s" % exc 367 367 wx.PostEvent(self.base, StatusEvent(status=msg)) 368 368 if event is not None: -
src/sas/sasgui/perspectives/calculator/detector_editor.py
ra1b8fee r5251ec6 34 34 self._do_layout() 35 35 self.set_values() 36 except :37 print("error", sys.exc_value)36 except Exception as exc: 37 print("error", exc) 38 38 39 39 def _define_structure(self): -
src/sas/sasgui/perspectives/calculator/gen_scatter_panel.py
r20fa5fe r5251ec6 228 228 sizer.Add(unit_title, (iy, ix), (1, 1), \ 229 229 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 230 key_list = params.keys() 231 key_list.sort() 232 for param in key_list: 230 for param in sorted(params.keys()): 233 231 iy += 1 234 232 ix = 0 … … 341 339 ix = 0 342 340 iy = 0 343 #key_list.sort()344 341 name = wx.StaticText(self, -1, 'No. of Qx (Qy) bins: ') 345 342 sizer.Add(name, (iy, ix), (1, 1), \ … … 509 506 wildcard = '|'.join(wildcard) 510 507 dlg = wx.FileDialog(self, "Choose a file", location, 511 "", wildcard, wx. OPEN)508 "", wildcard, wx.FD_OPEN) 512 509 if dlg.ShowModal() == wx.ID_OK: 513 510 path = dlg.GetPath() … … 556 553 self.reader.queue() 557 554 #self.load_update() 558 except :555 except Exception as exc: 559 556 self.ext = None 560 557 if self.parent.parent is None: 561 558 return 562 msg = "Generic SAS Calculator: %s" % (sys.exc_value)559 msg = "Generic SAS Calculator: %s" % exc 563 560 wx.PostEvent(self.parent.parent, 564 561 StatusEvent(status=msg, type='stop')) … … 774 771 if output.pix_type == 'atom': 775 772 # Get atom names not in the list 776 a_names = [symb for symb in pix_symbol \777 if symb not in color_dic .keys()]773 a_names = [symb for symb in pix_symbol 774 if symb not in color_dic] 778 775 a_name = a_names[0] 779 776 for name in a_names: … … 898 895 cal_out.queue() 899 896 900 except :901 msg = "%s." % sys.exc_value897 except Exception as exc: 898 msg = "%s." % exc 902 899 status_type = 'stop' 903 900 self._status_info(msg, status_type) … … 1344 1341 self.sld_data.is_data = False 1345 1342 self.sld_data.filename = "Default SLD Profile" 1346 except :1347 msg = "OMF Panel: %s" % sys.exc_value1343 except Exception as exc: 1344 msg = "OMF Panel: %s" % exc 1348 1345 infor = 'Error' 1349 1346 #logger.error(msg) … … 1441 1438 raise 1442 1439 sld_key_list = self._get_slds_key_list(omfdata) 1443 # Dic is not sorted1444 key_list = [key for key in sld_key_list.keys()]1445 # Sort here1446 key_list.sort()1447 1440 is_data = self.sld_data.is_data 1448 1441 sizer = wx.GridBagSizer(2, 3) 1449 1442 ix = 0 1450 1443 iy = -1 1451 for key in key_list: 1452 value = sld_key_list[key] 1444 for key, value in sorted(sld_key_list.items()): 1453 1445 iy += 1 1454 1446 ix = 0 … … 1485 1477 ix = 0 1486 1478 iy = -1 1487 for key, value in key_list.iteritems():1479 for key, value in sorted(key_list.items()): 1488 1480 iy += 1 1489 1481 ix = 0 … … 1520 1512 ix = 0 1521 1513 iy = -1 1522 #key_list.sort() 1523 for key, value in key_list.iteritems(): 1514 for key, value in sorted(key_list.items()): 1524 1515 iy += 1 1525 1516 ix = 0 -
src/sas/sasgui/perspectives/calculator/image_viewer.py
r412e9e8b r5251ec6 95 95 if location is None: 96 96 location = os.getcwd() 97 wildcard="Images (*.bmp;*.gif;*jpeg,*jpg;*.png;*tif;*.tiff)|*bmp;\ 98 *.gif; *.jpg; *.jpeg;*png;*.png;*.tif;*.tiff|"\ 99 "Bitmap (*.bmp)|*.bmp|"\ 100 "GIF (*.gif)|*.gif|"\ 101 "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|"\ 102 "PNG (*.png)|*.png|"\ 103 "TIFF (*.tif;*.tiff)|*.tif;*tiff|"\ 104 "All Files (*.*)|*.*|" 97 wildcard="|".join(( 98 "Images (*.bmp;*.gif;*jpeg,*jpg;*.png;*tif;*.tiff)" 99 "|*bmp;*.gif;*.jpg;*.jpeg;*png;*.png;*.tif;*.tiff", 100 "Bitmap (*.bmp)|*.bmp", 101 "GIF (*.gif)|*.gif", 102 "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg", 103 "PNG (*.png)|*.png", 104 "TIFF (*.tif;*.tiff)|*.tif;*tiff", 105 "All Files (*.*)|*.*", 106 )) 105 107 106 108 dlg = wx.FileDialog(self.parent, "Image Viewer: Choose an image file", -
src/sas/sasgui/perspectives/calculator/kiessig_calculator_panel.py
r7432acb r5251ec6 12 12 import sys 13 13 14 from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator 14 15 from sas.sasgui.guiframe.panel_base import PanelBase 15 from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator16 from calculator_widgets import OutputTextCtrl17 from calculator_widgets import InputTextCtrl18 16 from sas.sasgui.perspectives.calculator import calculator_widgets as widget 19 17 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 18 from .calculator_widgets import OutputTextCtrl 19 from .calculator_widgets import InputTextCtrl 20 20 21 21 _BOX_WIDTH = 77 -
src/sas/sasgui/perspectives/calculator/model_editor.py
r9bf40e7 r5251ec6 578 578 self.base = base 579 579 self.path = path 580 self.font = wx.SystemSettings _GetFont(wx.SYS_SYSTEM_FONT)580 self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT) 581 581 self.font.SetPointSize(10) 582 582 self.reader = None … … 781 781 if item.count("_") < 1: 782 782 try: 783 exec "float(math.%s)" % item783 exec("float(math.%s)" % item) 784 784 self.math_combo.Append(str(item)) 785 785 except Exception: -
src/sas/sasgui/perspectives/calculator/resolcal_thread.py
r20fa5fe r5251ec6 46 46 executing computation 47 47 """ 48 self.image = map(self.func, self.qx, self.qy,49 self.qx_min, self.qx_max,50 self.qy_min, self.qy_max)[0]48 self.image = list(map(self.func, self.qx, self.qy, 49 self.qx_min, self.qx_max, 50 self.qy_min, self.qy_max))[0] 51 51 elapsed = time.time() - self.starttime 52 52 -
src/sas/sasgui/perspectives/calculator/resolution_calculator_panel.py
r1cf490b6 r5251ec6 148 148 # Custom sorting 149 149 source_list = [] 150 for key, _ in self.source_mass.ite ritems():150 for key, _ in self.source_mass.items(): 151 151 name_source = str(key) 152 152 source_list.append(name_source) … … 667 667 Execute the computation of resolution 668 668 """ 669 # Clone the event before CallAfter; the event seems 670 # to delete the event when it is done processing, so 671 # the original will not be available when the call 672 # after method starts. 673 if event is not None: 674 event = event.Clone() 669 675 wx.CallAfter(self.on_compute_call, event) 670 676 … … 753 759 wx.MessageBox(msg, 'Warning') 754 760 return 755 #raise ValueError , "Invalid Q Input..."761 #raise ValueError("Invalid Q Input...") 756 762 757 763 # Validate the q inputs … … 934 940 def _sigma_strings(self): 935 941 """ 936 Recode sigmas as strin s942 Recode sigmas as strings 937 943 """ 938 944 sigma_r = self.format_number(self.resolution.sigma_1) … … 1082 1088 msg = "The numbers must be one or two (separated by ',')..." 1083 1089 self._status_info(msg, 'stop') 1084 raise RuntimeError , msg1090 raise RuntimeError(msg) 1085 1091 1086 1092 return new_string … … 1099 1105 value = float(string_split[ind]) 1100 1106 new_string.append(value) 1101 except :1102 logger.error( sys.exc_value)1107 except Exception as exc: 1108 logger.error(exc) 1103 1109 1104 1110 return new_string … … 1141 1147 out = self._string2inputlist(string) 1142 1148 return out 1143 except :1144 logger.error( sys.exc_value)1149 except Exception as exc: 1150 logger.error(exc) 1145 1151 1146 1152 def _on_xy_coordinate(self, event=None): … … 1269 1275 try: 1270 1276 basename = os.path.basename(path) 1271 if basename not in self.spectrum_dic .keys():1277 if basename not in self.spectrum_dic: 1272 1278 self.spectrum_cb.Append(basename) 1273 1279 self.spectrum_dic[basename] = self._read_file(path) … … 1286 1292 dlg = wx.FileDialog(self, 1287 1293 "Choose a wavelength spectrum file: Intensity vs. wavelength", 1288 self.parent.parent.get_save_location() , "", "*.*", wx. OPEN)1294 self.parent.parent.get_save_location() , "", "*.*", wx.FD_OPEN) 1289 1295 path = None 1290 1296 if dlg.ShowModal() == wx.ID_OK: … … 1318 1324 wavelength.append(wave) 1319 1325 intensity.append(intens) 1320 except :1326 except Exception as exc: 1321 1327 # Skip non-data lines 1322 logger.error( sys.exc_value)1328 logger.error(exc) 1323 1329 1324 1330 return [wavelength, intensity] -
src/sas/sasgui/perspectives/calculator/sld_panel.py
r2d220dd r5251ec6 363 363 364 364 """ 365 # TODO: use periodictable.elements object 366 # energy = xray_energy(periodictable.elements[element].K_alpha) 367 # TODO: code is very similar to sld helper 365 368 myformula = formula(str(element)) 366 369 if len(myformula.atoms) != 1: 367 370 return 368 element = myformula.atoms.keys()[0]371 element = list(myformula.atoms.keys())[0] 369 372 energy = xray_energy(element.K_alpha) 370 373 … … 413 416 msg += "Error for wavelength value :expect float" 414 417 elif (self.xray_source == 'Element'): 418 # TODO: use periodictable.elements instead of exec() hacks 419 # if self.xray_source_input not in periodictable.elements: 420 # ... 415 421 try: 416 422 import periodictable … … 447 453 448 454 """ 455 # TODO: use periodictable.elements object 456 # energy = xray_energy(periodictable.elements[element].K_alpha) 449 457 element_formula = formula(str(element)) 450 458 if len(element_formula.atoms) != 1: 451 459 return 452 element = element_formula.atoms.keys()[0]460 element = list(element_formula.atoms.keys())[0] 453 461 energy = xray_energy(element.K_alpha) 462 454 463 atom = molecule_formula.atoms 455 464 return xray_sld_from_atoms(atom, density=density, energy=energy) … … 505 514 #self.wavelength_ctl.SetValue(str(self.wavelength)) 506 515 #self.wavelength_ctl.SetValue(str(self.wavelength)) 507 except :516 except Exception as exc: 508 517 if self.base is not None: 509 msg = "SLD Calculator: %s" % (sys.exc_value)518 msg = "SLD Calculator: %s" % exc 510 519 wx.PostEvent(self.base, StatusEvent(status=msg)) 511 520 if event is not None: -
src/sas/sasgui/perspectives/calculator/slit_length_calculator_panel.py
rd788619 r5251ec6 17 17 from sas.sasgui.guiframe.events import StatusEvent 18 18 from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator 19 from calculator_widgets import OutputTextCtrl20 from calculator_widgets import InterActiveOutputTextCtrl21 19 from sas.sasgui.perspectives.calculator import calculator_widgets as widget 22 20 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 21 from .calculator_widgets import OutputTextCtrl 22 from .calculator_widgets import InterActiveOutputTextCtrl 23 23 24 24 _BOX_WIDTH = 76 … … 163 163 164 164 dlg = wx.FileDialog(self, "Choose a file", location, 165 "", wildcard, wx. OPEN)165 "", wildcard, wx.FD_OPEN) 166 166 if dlg.ShowModal() == wx.ID_OK: 167 167 path = dlg.GetPath() … … 223 223 self.reader.queue() 224 224 self.load_update() 225 except :225 except Exception as exc: 226 226 if self.parent.parent is None: 227 227 return 228 msg = "Slit Length Calculator: %s" % (sys.exc_value)228 msg = "Slit Length Calculator: %s" % exc 229 229 wx.PostEvent(self.parent.parent, 230 230 StatusEvent(status=msg, type='stop')) … … 264 264 if x == [] or x is None or y == [] or y is None: 265 265 msg = "The current data is empty please check x and y" 266 raise ValueError , msg266 raise ValueError(msg) 267 267 slit_length_calculator = SlitlengthCalculator() 268 268 slit_length_calculator.set_data(x=x, y=y) 269 269 slit_length = slit_length_calculator.calculate_slit_length() 270 except :270 except Exception as exc: 271 271 if self.parent.parent is None: 272 272 return 273 msg = "Slit Size Calculator: %s" % (sys.exc_value)273 msg = "Slit Size Calculator: %s" % exc 274 274 wx.PostEvent(self.parent.parent, 275 275 StatusEvent(status=msg, type='stop'))
Note: See TracChangeset
for help on using the changeset viewer.