Changeset 5251ec6 in sasview for src/sas/sasgui/perspectives/pr
- 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/pr
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/pr/__init__.py
r959eb01 r5251ec6 1 1 PLUGIN_ID = "P(r) plug-in 1.0" 2 from pr import *2 from .pr import * -
src/sas/sasgui/perspectives/pr/explore_dialog.py
r20fa5fe r5251ec6 35 35 from sas.sasgui.plottools.plottables import Graph 36 36 37 from pr_widgets import PrTextCtrl37 from .pr_widgets import PrTextCtrl 38 38 39 39 # Default number of points on the output plot … … 416 416 results.pos_err.append(pos_err) 417 417 results.osc.append(osc) 418 except :418 except Exception as exc: 419 419 # This inversion failed, skip this D_max value 420 420 msg = "ExploreDialog: inversion failed " 421 msg += "for D_max=%s\n%s" % (str(d), sys.exc_value)421 msg += "for D_max=%s\n%s" % (str(d), exc) 422 422 logger.error(msg) 423 423 -
src/sas/sasgui/perspectives/pr/inversion_panel.py
rcb62bd5 r5251ec6 5 5 __revision__ = "$Revision: 1193 $" 6 6 7 import wx8 7 import os 9 8 import sys 10 9 import logging 10 11 import wx 11 12 from wx.lib.scrolledpanel import ScrolledPanel 13 12 14 from sas.sasgui.guiframe.events import StatusEvent 13 15 from sas.sasgui.guiframe.panel_base import PanelBase 14 from inversion_state import InversionState15 from pr_widgets import PrTextCtrl16 from pr_widgets import DataFileTextCtrl17 from pr_widgets import OutputTextCtrl18 16 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 17 18 from .inversion_state import InversionState 19 from .pr_widgets import PrTextCtrl 20 from .pr_widgets import DataFileTextCtrl 21 from .pr_widgets import OutputTextCtrl 19 22 20 23 logger = logging.getLogger(__name__) … … 752 755 except ValueError: 753 756 logger.error("InversionControl._on_accept_alpha got a value that was not a number: %s" % alpha ) 754 except :757 except Exception as exc: 755 758 # No estimate or bad estimate, either do nothing 756 logger.error("InversionControl._on_accept_alpha: %s" % sys.exc_value)759 logger.error("InversionControl._on_accept_alpha: %s" % exc) 757 760 758 761 def _on_accept_nterms(self, evt): … … 768 771 except ValueError: 769 772 logger.error("InversionControl._on_accept_nterms got a value that was not a number: %s" % nterms ) 770 except :773 except Exception as exc: 771 774 # No estimate or bad estimate, either do nothing 772 logger.error("InversionControl._on_accept_nterms: %s" % sys.exc_value)775 logger.error("InversionControl._on_accept_nterms: %s" % exc) 773 776 774 777 def clear_panel(self): … … 901 904 message += "than the number of points" 902 905 wx.PostEvent(self._manager.parent, StatusEvent(status=message)) 903 raise ValueError , message906 raise ValueError(message) 904 907 self.nfunc_ctl.SetBackgroundColour(wx.WHITE) 905 908 self.nfunc_ctl.Refresh() … … 957 960 Invoke the d_max exploration dialog 958 961 """ 959 from explore_dialog import ExploreDialog962 from .explore_dialog import ExploreDialog 960 963 if self._manager._last_pr is not None: 961 964 pr = self._manager._create_plot_pr() … … 1008 1011 self._on_invert(None) 1009 1012 self._set_analysis(True) 1010 except :1011 msg = "InversionControl._change_file: %s" % sys.exc_value1013 except Exception as exc: 1014 msg = "InversionControl._change_file: %s" % exc 1012 1015 logger.error(msg) 1013 1016 -
src/sas/sasgui/perspectives/pr/inversion_state.py
r2469df7 r5251ec6 18 18 import logging 19 19 from lxml import etree 20 20 21 from sas.sasgui.guiframe.dataFitting import Data1D 21 22 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader … … 238 239 msg = "InversionState no longer supports non-CanSAS" 239 240 msg += " format for P(r) files" 240 raise RuntimeError , msg241 raise RuntimeError(msg) 241 242 242 243 if node.get('version') and node.get('version') == '1.0': … … 252 253 try: 253 254 self.timestamp = float(entry.get('epoch')) 254 except :255 except Exception as exc: 255 256 msg = "InversionState.fromXML: Could not read " 256 msg += "timestamp\n %s" % sys.exc_value257 msg += "timestamp\n %s" % exc 257 258 logger.error(msg) 258 259 … … 432 433 state = InversionState() 433 434 state.fromXML(node=nodes[0]) 434 except :435 except Exception as exc: 435 436 msg = "XML document does not contain P(r) " 436 msg += "information.\n %s" % sys.exc_value437 msg += "information.\n %s" % exc 437 438 logger.info(msg) 438 439 … … 481 482 output.append(sas_entry) 482 483 else: 483 raise RuntimeError , "%s is not a file" % path484 raise RuntimeError("%s is not a file" % path) 484 485 485 486 # Return output consistent with the loader's api … … 525 526 msg = "The cansas writer expects a Data1D " 526 527 msg += "instance: %s" % str(datainfo.__class__.__name__) 527 raise RuntimeError , msg528 raise RuntimeError(msg) 528 529 529 530 # Create basic XML document -
src/sas/sasgui/perspectives/pr/pr.py
r2469df7 r5251ec6 18 18 19 19 import sys 20 import wx21 20 import logging 22 21 import time 23 22 import math 23 24 import wx 24 25 import numpy as np 25 26 import pylab 27 26 28 from sas.sasgui.guiframe.gui_manager import MDIFrame 27 29 from sas.sasgui.guiframe.dataFitting import Data1D … … 33 35 import sas.sascalc.dataloader 34 36 35 from pr_widgets import load_error36 37 from sas.sasgui.guiframe.plugin_base import PluginBase 38 39 from .inversion_state import Reader # .prv file reader 40 from .inversion_panel import InversionControl 41 #from .inversion_panel import HelpDialog 42 from .inversion_panel import PrDistDialog 43 from .pr_thread import CalcPr 44 from .pr_thread import EstimatePr 45 from .pr_thread import EstimateNT 46 from .pr_widgets import load_error 47 from .pr_widgets import DataDialog 37 48 38 49 logger = logging.getLogger(__name__) … … 106 117 self.list_plot_id = [] 107 118 108 # Associate the inversion state reader with .prv files109 from inversion_state import Reader110 111 119 # Create a CanSAS/Pr reader 112 120 self.state_reader = Reader(self.set_state) … … 151 159 msg = "Pr.set_state: datainfo parameter cannot " 152 160 msg += "be None in standalone mode" 153 raise RuntimeError , msg161 raise RuntimeError(msg) 154 162 155 163 # Ensuring that plots are coordinated correctly … … 184 192 title=self.current_plottable.title)) 185 193 self.control_panel.set_state(state) 186 except :187 logger.error("prview.set_state: %s" % sys.exc_value)194 except Exception as exc: 195 logger.error("prview.set_state: %s" % exc) 188 196 189 197 … … 195 203 196 204 """ 197 from inversion_panel import HelpDialog198 205 dialog = HelpDialog(None, -1) 199 206 if dialog.ShowModal() == wx.ID_OK: … … 369 376 Redisplay P(r) with a different number of points 370 377 """ 371 from inversion_panel import PrDistDialog372 378 dialog = PrDistDialog(None, -1) 373 379 dialog.set_content(self._pr_npts) … … 452 458 # Notify the user if we could not read the file 453 459 if dataread is None: 454 raise RuntimeError , "Invalid data"460 raise RuntimeError("Invalid data") 455 461 456 462 x = None … … 472 478 if dataread is None: 473 479 return x, y, err 474 raise RuntimeError , "This tool can only read 1D data"480 raise RuntimeError("This tool can only read 1D data") 475 481 476 482 self._current_file_data.x = x … … 511 517 data_y = np.append(data_y, y) 512 518 data_err = np.append(data_err, err) 513 except :514 logger.error( sys.exc_value)519 except Exception as exc: 520 logger.error(exc) 515 521 516 522 if scale is not None: … … 562 568 data_y = np.append(data_y, y) 563 569 data_err = np.append(data_err, err) 564 except :565 logger.error( sys.exc_value)570 except Exception as exc: 571 logger.error(exc) 566 572 elif line.find("The 6 columns") >= 0: 567 573 data_started = True … … 720 726 Start a calculation thread 721 727 """ 722 from pr_thread import CalcPr723 724 728 # If a thread is already started, stop it 725 729 if self.calc_thread is not None and self.calc_thread.isrunning(): … … 849 853 try: 850 854 pr = self._create_file_pr(data) 851 except :852 status = "Problem reading data: %s" % sys.exc_value855 except Exception as exc: 856 status = "Problem reading data: %s" % exc 853 857 wx.PostEvent(self.parent, StatusEvent(status=status)) 854 raise RuntimeError , status858 raise RuntimeError(status) 855 859 856 860 # If the file contains nothing, just return 857 861 if pr is None: 858 raise RuntimeError , "Loaded data is invalid"862 raise RuntimeError("Loaded data is invalid") 859 863 860 864 self.pr = pr … … 906 910 msg = "pr.save_data: the data being saved is not a" 907 911 msg += " sas.data_info.Data1D object" 908 raise RuntimeError , msg912 raise RuntimeError(msg) 909 913 910 914 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, … … 928 932 self.pr = pr 929 933 self.perform_inversion() 930 except :931 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))934 except Exception as exc: 935 wx.PostEvent(self.parent, StatusEvent(status=exc)) 932 936 933 937 def estimate_plot_inversion(self, alpha, nfunc, d_max, … … 952 956 self.pr = pr 953 957 self.perform_estimate() 954 except :955 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))958 except Exception as exc: 959 wx.PostEvent(self.parent, StatusEvent(status=exc)) 956 960 957 961 def _create_plot_pr(self, estimate=False): … … 1033 1037 self.pr = pr 1034 1038 self.perform_inversion() 1035 except :1036 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))1039 except Exception as exc: 1040 wx.PostEvent(self.parent, StatusEvent(status=exc)) 1037 1041 1038 1042 def estimate_file_inversion(self, alpha, nfunc, d_max, data, … … 1056 1060 self.pr = pr 1057 1061 self.perform_estimate() 1058 except :1059 wx.PostEvent(self.parent, StatusEvent(status= sys.exc_value))1062 except Exception as exc: 1063 wx.PostEvent(self.parent, StatusEvent(status=exc)) 1060 1064 1061 1065 def _create_file_pr(self, data): … … 1085 1089 self._current_file_data.err = data.dy 1086 1090 x, y, err = data.x, data.y, data.dy 1087 except :1088 load_error( sys.exc_value)1091 except Exception as exc: 1092 load_error(exc) 1089 1093 return None 1090 1094 … … 1124 1128 pr.slit_width = self.slit_width 1125 1129 return pr 1126 except :1127 load_error( sys.exc_value)1130 except Exception as exc: 1131 load_error(exc) 1128 1132 return None 1129 1133 … … 1132 1136 Perform parameter estimation 1133 1137 """ 1134 from pr_thread import EstimatePr1135 1136 1138 # If a thread is already started, stop it 1137 1139 if self.estimation_thread is not None and \ … … 1162 1164 Perform parameter estimation 1163 1165 """ 1164 from pr_thread import EstimateNT1165 1166 1166 # If a thread is already started, stop it 1167 1167 if self.estimation_thread is not None and self.estimation_thread.isrunning(): … … 1239 1239 Create and return a list of panel objects 1240 1240 """ 1241 from inversion_panel import InversionControl1242 1243 1241 self.parent = parent 1244 1242 self.frame = MDIFrame(self.parent, None, 'None', (100, 200)) … … 1262 1260 if data_list is None: 1263 1261 data_list = [] 1262 else: 1263 data_list = list(data_list) # force iterator to list 1264 1264 if len(data_list) >= 1: 1265 1265 if len(data_list) == 1: … … 1287 1287 msg += "Please select one.\n" 1288 1288 if len(data_list) > 1: 1289 from pr_widgets import DataDialog1290 1289 dlg = DataDialog(data_list=data_1d_list, text=msg) 1291 1290 if dlg.ShowModal() == wx.ID_OK: … … 1306 1305 self.data_id = data.id 1307 1306 self.control_panel._change_file(evt=None, data=data) 1308 except :1309 msg = "Prview Set_data: " + str( sys.exc_value)1307 except Exception as exc: 1308 msg = "Prview Set_data: " + str(exc) 1310 1309 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 1311 1310 else: -
src/sas/sasgui/perspectives/pr/pr_thread.py
rac07a3a r5251ec6 41 41 # Thread was interrupted, just proceed 42 42 pass 43 except :43 except Exception as exc: 44 44 if self.error_func is not None: 45 self.error_func("CalcPr.compute: %s" % sys.exc_value)45 self.error_func("CalcPr.compute: %s" % exc) 46 46 47 47 class EstimatePr(CalcThread): … … 69 69 # Thread was interrupted, just proceed 70 70 pass 71 except :71 except Exception as exc: 72 72 if self.error_func is not None: 73 self.error_func("EstimatePr.compute: %s" % sys.exc_value)73 self.error_func("EstimatePr.compute: %s" % exc) 74 74 75 75 class EstimateNT(CalcThread): … … 109 109 # Thread was interrupted, just proceed 110 110 pass 111 except :111 except Exception as exc: 112 112 if self.error_func is not None: 113 self.error_func("EstimatePr2.compute: %s" % sys.exc_value)113 self.error_func("EstimatePr2.compute: %s" % exc)
Note: See TracChangeset
for help on using the changeset viewer.