- Timestamp:
- Jun 2, 2016 10:14:35 AM (9 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ec30905
- Parents:
- 6afc14b (diff), 70305bd2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas
- Files:
-
- 1 added
- 2 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/librefl.c
r9e531f2 r4c29e4d 8 8 #include <stdlib.h> 9 9 #if defined(_MSC_VER) 10 # include "winFuncs.h"10 #define NEED_ERF 11 11 #endif 12 13 14 15 #if defined(NEED_ERF) 16 /* erf.c - public domain implementation of error function erf(3m) 17 18 reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten 19 (New Algorithm handbook in C language) (Gijyutsu hyouron 20 sha, Tokyo, 1991) p.227 [in Japanese] */ 21 22 23 #ifdef _WIN32 24 # include <float.h> 25 # if !defined __MINGW32__ || defined __NO_ISOCEXT 26 # ifndef isnan 27 # define isnan(x) _isnan(x) 28 # endif 29 # ifndef isinf 30 # define isinf(x) (!_finite(x) && !_isnan(x)) 31 # endif 32 # ifndef finite 33 # define finite(x) _finite(x) 34 # endif 35 # endif 36 #endif 37 38 static double q_gamma(double, double, double); 39 40 /* Incomplete gamma function 41 1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt */ 42 static double p_gamma(double a, double x, double loggamma_a) 43 { 44 int k; 45 double result, term, previous; 46 47 if (x >= 1 + a) return 1 - q_gamma(a, x, loggamma_a); 48 if (x == 0) return 0; 49 result = term = exp(a * log(x) - x - loggamma_a) / a; 50 for (k = 1; k < 1000; k++) { 51 term *= x / (a + k); 52 previous = result; result += term; 53 if (result == previous) return result; 54 } 55 fprintf(stderr, "erf.c:%d:p_gamma() could not converge.", __LINE__); 56 return result; 57 } 58 59 /* Incomplete gamma function 60 1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt */ 61 static double q_gamma(double a, double x, double loggamma_a) 62 { 63 int k; 64 double result, w, temp, previous; 65 double la = 1, lb = 1 + x - a; /* Laguerre polynomial */ 66 67 if (x < 1 + a) return 1 - p_gamma(a, x, loggamma_a); 68 w = exp(a * log(x) - x - loggamma_a); 69 result = w / lb; 70 for (k = 2; k < 1000; k++) { 71 temp = ((k - 1 - a) * (lb - la) + (k + x) * lb) / k; 72 la = lb; lb = temp; 73 w *= (k - 1 - a) / k; 74 temp = w / (la * lb); 75 previous = result; result += temp; 76 if (result == previous) return result; 77 } 78 fprintf(stderr, "erf.c:%d:q_gamma() could not converge.", __LINE__); 79 return result; 80 } 81 82 #define LOG_PI_OVER_2 0.572364942924700087071713675675 /* log_e(PI)/2 */ 83 84 double erf(double x) 85 { 86 if (!finite(x)) { 87 if (isnan(x)) return x; /* erf(NaN) = NaN */ 88 return (x>0 ? 1.0 : -1.0); /* erf(+-inf) = +-1.0 */ 89 } 90 if (x >= 0) return p_gamma(0.5, x * x, LOG_PI_OVER_2); 91 else return - p_gamma(0.5, x * x, LOG_PI_OVER_2); 92 } 93 94 double erfc(double x) 95 { 96 if (!finite(x)) { 97 if (isnan(x)) return x; /* erfc(NaN) = NaN */ 98 return (x>0 ? 0.0 : 2.0); /* erfc(+-inf) = 0.0, 2.0 */ 99 } 100 if (x >= 0) return q_gamma(0.5, x * x, LOG_PI_OVER_2); 101 else return 1 + p_gamma(0.5, x * x, LOG_PI_OVER_2); 102 } 103 #endif // NEED_ERF 12 104 13 105 complex cassign(real, imag) -
src/sas/sascalc/calculator/c_extensions/sld2i.cpp
r9e531f2 rb523c0e 164 164 //Assume that pixel volumes are given in vol_pix in A^3 unit 165 165 // Loop over q-values and multiply apply matrix 166 for( size_t i=0; i<npoints; i++){166 for(int i=0; i<npoints; i++){ 167 167 sumj =0.0; 168 for( size_t j=0; j<n_pix; j++){168 for(int j=0; j<n_pix; j++){ 169 169 //Isotropic: Assumes all slds are real (no magnetic) 170 170 //Also assumes there is no polarization: No dependency on spin … … 183 183 //full calculation 184 184 //pragma omp parallel for 185 for( size_t k=0; k<n_pix; k++){185 for(int k=0; k<n_pix; k++){ 186 186 sld_j = sldn_val[j] * sldn_val[k] * vol_pix[j] * vol_pix[k]; 187 187 qr = (x_val[j]-x_val[k])*(x_val[j]-x_val[k])+ -
src/sas/sascalc/calculator/c_extensions/sld2i.hh
r9e531f2 r4c29e4d 39 39 double s_theta); 40 40 // compute function 41 v irtual void genicomXY(int npoints, double* qx, double* qy, double *I_out);42 v irtual void genicom(int npoints, double* q, double *I_out);41 void genicomXY(int npoints, double* qx, double* qy, double *I_out); 42 void genicom(int npoints, double* q, double *I_out); 43 43 }; 44 44 -
src/sas/sascalc/calculator/c_extensions/sld2i_module.cpp
r9e531f2 rb523c0e 153 153 initsld2i(void) 154 154 { 155 PyObject* m; 156 157 m = Py_InitModule3("sld2i", module_methods, 158 "Sld2i module"); 155 Py_InitModule3("sld2i", module_methods, "Sld2i module"); 159 156 } -
src/sas/sascalc/data_util/calcthread.py
rb699768 r934ce649 119 119 120 120 def __init__(self, completefn=None, updatefn=None, 121 yieldtime=0.01, worktime=0.01): 121 yieldtime=0.01, worktime=0.01, 122 exception_handler=None): 122 123 """Prepare the calculator""" 123 124 self.yieldtime = yieldtime … … 125 126 self.completefn = completefn 126 127 self.updatefn = updatefn 128 self.exception_handler = exception_handler 127 129 self._interrupting = False 128 130 self._running = False … … 199 201 200 202 def update(self, **kwargs): 201 202 203 """Update GUI with the lastest results from the current work unit.""" 203 204 if self.updatefn != None and clock() > self._time_for_update: … … 225 226 """Perform a work unit. The subclass will provide details of 226 227 the arguments.""" 227 raise NotImplemented, "Calculation thread needs compute method" 228 raise NotImplemented("Calculation thread needs compute method") 229 230 def exception(self): 231 """ 232 An exception occurred during computation, so call the exception handler 233 if there is one. If not, then log the exception and continue. 234 """ 235 # If we have an exception handler, let it try to handle the exception. 236 # If it fails fall through to log the failure to handle the exception 237 # (the original exception will be lost). If there is no exception 238 # handler, just log the exception in compute that we are responding to. 239 if self.exception_handler: 240 try: 241 self.exception_handler(*sys.exc_info()) 242 return 243 except Exception: 244 pass 245 import logging 246 logging.error(traceback.format_exc()) 247 #print 'CalcThread exception', 228 248 229 249 def _run(self): … … 250 270 pass 251 271 except: 252 traceback.print_exc() 253 #print 'CalcThread exception', 272 self.exception() 254 273 self._running = False 255 274 -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r45d90b9 raf09f48 221 221 output.append(return_value) 222 222 else: 223 output.append("Invalid XML at: {0}".format(\224 self.find_invalid_xml()) )223 raise RuntimeError, "Invalid XML at: {0}".format(\ 224 self.find_invalid_xml()) 225 225 except: 226 226 # If the file does not match the schema, raise this error -
src/sas/sascalc/pr/c_extensions/Cinvertor.c
rb699768 rb523c0e 115 115 116 116 //self->params.x = data; 117 self->params.npoints = ndata;117 self->params.npoints = (int)ndata; 118 118 return Py_BuildValue("i", self->params.npoints); 119 119 } … … 180 180 181 181 //self->params.y = data; 182 self->params.ny = ndata;182 self->params.ny = (int)ndata; 183 183 return Py_BuildValue("i", self->params.ny); 184 184 } … … 245 245 246 246 //self->params.err = data; 247 self->params.nerr = ndata;247 self->params.nerr = (int)ndata; 248 248 return Py_BuildValue("i", self->params.nerr); 249 249 } … … 523 523 residuals = PyList_New(self->params.npoints); 524 524 525 regterm = reg_term(pars, self->params.d_max, npars, nslice);525 regterm = reg_term(pars, self->params.d_max, (int)npars, nslice); 526 526 527 527 for(i=0; i<self->params.npoints; i++) { 528 diff = self->params.y[i] - iq(pars, self->params.d_max, npars, self->params.x[i]);528 diff = self->params.y[i] - iq(pars, self->params.d_max, (int)npars, self->params.x[i]); 529 529 residual = diff*diff / (self->params.err[i]*self->params.err[i]); 530 530 … … 573 573 residuals = PyList_New(self->params.npoints); 574 574 575 regterm = reg_term(pars, self->params.d_max, npars, nslice);575 regterm = reg_term(pars, self->params.d_max, (int)npars, nslice); 576 576 577 577 578 578 for(i=0; i<self->params.npoints; i++) { 579 diff = self->params.y[i] - pr(pars, self->params.d_max, npars, self->params.x[i]);579 diff = self->params.y[i] - pr(pars, self->params.d_max, (int)npars, self->params.x[i]); 580 580 residual = diff*diff / (self->params.err[i]*self->params.err[i]); 581 581 … … 611 611 OUTVECTOR(data_obj,pars,npars); 612 612 613 iq_value = iq(pars, self->params.d_max, npars, q);613 iq_value = iq(pars, self->params.d_max, (int)npars, q); 614 614 return Py_BuildValue("f", iq_value); 615 615 } … … 636 636 OUTVECTOR(data_obj,pars,npars); 637 637 638 iq_value = iq_smeared(pars, self->params.d_max, npars,638 iq_value = iq_smeared(pars, self->params.d_max, (int)npars, 639 639 self->params.slit_height, self->params.slit_width, 640 640 q, 21); … … 661 661 OUTVECTOR(data_obj,pars,npars); 662 662 663 pr_value = pr(pars, self->params.d_max, npars, r);663 pr_value = pr(pars, self->params.d_max, (int)npars, r); 664 664 return Py_BuildValue("f", pr_value); 665 665 } … … 689 689 690 690 if (err_obj == Py_None) { 691 pr_value = pr(pars, self->params.d_max, npars, r);691 pr_value = pr(pars, self->params.d_max, (int)npars, r); 692 692 pr_err_value = 0.0; 693 693 } else { 694 694 OUTVECTOR(err_obj,pars_err,npars2); 695 pr_err(pars, pars_err, self->params.d_max, npars, r, &pr_value, &pr_err_value);695 pr_err(pars, pars_err, self->params.d_max, (int)npars, r, &pr_value, &pr_err_value); 696 696 } 697 697 return Py_BuildValue("ff", pr_value, pr_err_value); … … 728 728 OUTVECTOR(data_obj,pars,npars); 729 729 730 oscill = reg_term(pars, self->params.d_max, npars, 100);731 norm = int_p2(pars, self->params.d_max, npars, 100);730 oscill = reg_term(pars, self->params.d_max, (int)npars, 100); 731 norm = int_p2(pars, self->params.d_max, (int)npars, 100); 732 732 return Py_BuildValue("f", sqrt(oscill/norm)/acos(-1.0)*self->params.d_max ); 733 733 … … 749 749 OUTVECTOR(data_obj,pars,npars); 750 750 751 count = npeaks(pars, self->params.d_max, npars, 100);751 count = npeaks(pars, self->params.d_max, (int)npars, 100); 752 752 753 753 return Py_BuildValue("i", count ); … … 770 770 OUTVECTOR(data_obj,pars,npars); 771 771 772 fraction = positive_integral(pars, self->params.d_max, npars, 100);772 fraction = positive_integral(pars, self->params.d_max, (int)npars, 100); 773 773 774 774 return Py_BuildValue("f", fraction ); … … 795 795 OUTVECTOR(err_obj,pars_err,npars2); 796 796 797 fraction = positive_errors(pars, pars_err, self->params.d_max, npars, 51);797 fraction = positive_errors(pars, pars_err, self->params.d_max, (int)npars, 51); 798 798 799 799 return Py_BuildValue("f", fraction ); … … 815 815 OUTVECTOR(data_obj,pars,npars); 816 816 817 value = rg(pars, self->params.d_max, npars, 101);817 value = rg(pars, self->params.d_max, (int)npars, 101); 818 818 819 819 return Py_BuildValue("f", value ); … … 835 835 OUTVECTOR(data_obj,pars,npars); 836 836 837 value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, npars, 101);837 value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, (int)npars, 101); 838 838 839 839 return Py_BuildValue("f", value ); -
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
rd85c194 rfaa3ae7 155 155 """ 156 156 data_error = False 157 for error_data in item.errors: 157 if hasattr(item, 'errors'): 158 for error_data in item.errors: 159 data_error = True 160 message += "\tError: {0}\n".format(error_data) 161 else: 162 logging.error("Loader returned an invalid object:\n %s" % str(item)) 158 163 data_error = True 159 message += "\tError: {0}\n".format(error_data)164 160 165 data = self.parent.create_gui_data(item, p_file) 161 166 output[data.id] = data … … 203 208 error_message) 204 209 except: 210 logging.error(sys.exc_value) 205 211 any_error = True 206 212 if any_error or error_message != "": -
src/sas/sasgui/perspectives/calculator/model_editor.py
rcb4ef58 rbb841ef 30 30 from wx.py.editwindow import EditWindow 31 31 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 32 from .pyconsole import show_model_output, check_model 32 33 33 34 … … 45 46 PANEL_WIDTH = 500 46 47 _BOX_WIDTH = 55 47 48 49 def _compile_file(path):50 """51 Compile the file in the path52 """53 try:54 import py_compile55 py_compile.compile(file=path, doraise=True)56 return ''57 except:58 _, value, _ = sys.exc_info()59 return value60 48 61 49 def _delete_file(path): … … 384 372 name2 = label[1] 385 373 self.write_string(fname, name1, name2) 386 self.compile_file(fname) 387 self.parent.update_custom_combo() 374 success = show_model_output(self, fname) 375 if success: 376 self.parent.update_custom_combo() 388 377 msg = self._notes 389 378 info = 'Info' … … 618 607 """ 619 608 path = self.fname 620 _compile_file(path)609 show_model_output(self, path) 621 610 622 611 def delete_file(self, path): … … 954 943 info = 'Info' 955 944 msg = '' 945 result, check_err = '', '' 956 946 # Sort out the errors if occur 957 947 # First check for valid python name then if the name already exists … … 969 959 self.write_file(self.fname, name, description, param_str, 970 960 pd_param_str, func_str) 961 try: 962 result, msg = check_model(self.fname), None 963 except Exception: 964 import traceback 965 result, msg = None, "error building model" 966 check_err = "\n"+traceback.format_exc(limit=2) 967 971 968 # Modified compiling test, as it will fail for sasmodels.sasview_model class 972 969 # Should add a test to check that the class is correctly built … … 1031 1028 color = 'red' 1032 1029 else: 1033 msg = "Successful! " 1030 self._notes = result 1031 msg = "Successful! Please look for %s in Customized Models."%name 1034 1032 msg += " " + self._notes 1035 msg += " Please look for it in the Customized Models."1036 1033 info = 'Info' 1037 1034 color = 'blue' … … 1041 1038 if self.base != None: 1042 1039 from sas.sasgui.guiframe.events import StatusEvent 1043 wx.PostEvent(self.base.parent, StatusEvent(status=msg, info=info)) 1040 wx.PostEvent(self.base.parent, 1041 StatusEvent(status=msg+check_err, info=info)) 1044 1042 self.warning = msg 1045 1043 … … 1333 1331 import copy 1334 1332 1335 import nu ympy1333 import numpy 1336 1334 1337 1335 from sas.sascalc.fit.pluginmodel import Model1DPlugin -
src/sas/sasgui/perspectives/calculator/pyconsole.py
rd85c194 r26d6e045 4 4 import sys 5 5 import os 6 7 import numpy as np 8 6 9 import wx 7 import wx.lib.dialogs 10 from wx.lib.dialogs import ScrolledMessageDialog 8 11 import wx.py.editor as editor 9 import wx.py.frame as frame10 import py_compile11 12 12 13 if sys.platform.count("win32") > 0: … … 18 19 PANEL_HEIGHT = 730 19 20 FONT_VARIANT = 1 20 ID_C OMPILE= wx.NewId()21 ID_CHECK_MODEL = wx.NewId() 21 22 ID_RUN = wx.NewId() 22 23 23 def c ompile_file(path):24 def check_model(path): 24 25 """ 25 C ompile a python file26 Check that the model on the path can run. 26 27 """ 28 # try running the model 29 from sasmodels.core import load_model, call_kernel 30 model = load_model(path) 31 32 q = np.array([0.01, 0.1]) 33 kernel = model.make_kernel([q]) 34 Iq = call_kernel(kernel, {}) 35 36 qx, qy = np.array([0.01, 0.01]), np.array([0.1, 0.1]) 37 kernel = model.make_kernel([qx, qy]) 38 Iqxy = call_kernel(kernel, {}) 39 40 result = """ 41 Iq(%s) = %s 42 Iqxy(%s, %s) = %s 43 """%(q, Iq, qx, qy, Iqxy) 44 45 return result 46 47 def show_model_output(parent, fname): 48 # Make sure we have a python file; not sure why we care though... 49 if not (fname and os.path.exists(fname) and fname.endswith('.py')): 50 mssg = "\n This is not a python file." 51 wx.MessageBox(str(mssg), 'Error', style=wx.ICON_ERROR) 52 return False 53 27 54 try: 28 import py_compile 29 py_compile.compile(file=path, doraise=True) 30 except: 31 type, value, traceback = sys.exc_info() 32 return value 33 return None 55 result, errmsg = check_model(fname), None 56 except Exception: 57 import traceback 58 result, errmsg = None, traceback.format_exc(limit=2) 59 60 parts = ["Running model '%s'..." % os.path.basename(fname)] 61 if errmsg is not None: 62 parts.extend(["", "Error occurred:", errmsg, ""]) 63 title, icon = "Error", wx.ICON_ERROR 64 else: 65 parts.extend(["", "Success:", result, ""]) 66 title, icon = "Info", wx.ICON_INFORMATION 67 text = "\n".join(parts) 68 dlg = ScrolledMessageDialog(parent, text, title, size=((550, 250))) 69 fnt = wx.Font(10, wx.TELETYPE, wx.NORMAL, wx.NORMAL) 70 dlg.GetChildren()[0].SetFont(fnt) 71 dlg.GetChildren()[0].SetInsertionPoint(0) 72 dlg.ShowModal() 73 dlg.Destroy() 74 return errmsg is None 34 75 35 76 class PyConsole(editor.EditorNotebookFrame): … … 65 106 self.Bind(wx.EVT_MENU, self.OnSaveFile, id=wx.ID_SAVE) 66 107 self.Bind(wx.EVT_MENU, self.OnSaveAsFile, id=wx.ID_SAVEAS) 67 self.Bind(wx.EVT_MENU, self.OnC ompile, id=ID_COMPILE)108 self.Bind(wx.EVT_MENU, self.OnCheckModel, id=ID_CHECK_MODEL) 68 109 self.Bind(wx.EVT_MENU, self.OnRun, id=ID_RUN) 69 self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateCompileMenu, id=ID_C OMPILE)110 self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateCompileMenu, id=ID_CHECK_MODEL) 70 111 self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateCompileMenu, id=ID_RUN) 71 112 self.Bind(wx.EVT_CLOSE, self.on_close) … … 81 122 """ 82 123 self.compileMenu = wx.Menu() 83 self.compileMenu.Append(ID_C OMPILE, 'Compile',84 ' Compile the file')124 self.compileMenu.Append(ID_CHECK_MODEL, 'Check model', 125 'Loading and run the model') 85 126 self.compileMenu.AppendSeparator() 86 127 self.compileMenu.Append(ID_RUN, 'Run in Shell', … … 192 233 Run 193 234 """ 194 if self._check_changed():235 if not self._check_saved(): 195 236 return True 196 237 if self.buffer and self.buffer.doc.filepath: … … 207 248 icon = wx.ICON_ERROR 208 249 wx.MessageBox(str(mssg), title, style=icon) 209 return 0210 211 def OnC ompile(self, event):250 return False 251 252 def OnCheckModel(self, event): 212 253 """ 213 254 Compile 214 255 """ 215 if self._check_changed():256 if not self._check_saved(): 216 257 return True 217 run_out = self.OnRun(None) 218 if self._get_err_msg(run_out): 219 if self._manager != None and self.panel != None: 220 self._manager.set_edit_menu_helper(self.parent) 221 # Update custom model list in fitpage combobox 222 wx.CallAfter(self._manager.update_custom_combo) 223 224 def _check_changed(self): 258 fname = self.editor.getStatus()[0] 259 success = show_model_output(self, fname) 260 261 # Update custom model list in fitpage combobox 262 if success and self._manager != None and self.panel != None: 263 self._manager.set_edit_menu_helper(self.parent) 264 wx.CallAfter(self._manager.update_custom_combo) 265 266 def _check_saved(self): 225 267 """ 226 268 If content was changed, suggest to save it first … … 228 270 if self.bufferHasChanged() and self.buffer.doc.filepath: 229 271 cancel = self.bufferSuggestSave() 230 if cancel: 231 return cancel 232 233 def _get_err_msg(self, text=''): 234 """ 235 Get err_msg 236 """ 237 name = None 238 mssg = "\n This is not a python file." 239 title = 'Error' 240 icon = wx.ICON_ERROR 241 try: 242 fname = self.editor.getStatus()[0] 243 name = os.path.basename(fname) 244 if name.split('.')[-1] != 'py': 245 wx.MessageBox(str(mssg), title, style=icon) 246 return False 247 msg = compile_file(fname) 248 except: 249 msg = None 250 if name == None: 251 wx.MessageBox(str(mssg), title, style=icon) 252 return False 253 mssg = "Compiling '%s'...\n" % name 254 if msg != None: 255 mssg += "Error occurred:\n" 256 mssg += str(msg) + "\n\n" 257 if text: 258 mssg += "Run-Test results:\n" 259 mssg += str(text) 260 title = 'Warning' 261 icon = wx.ICON_WARNING 262 else: 263 mssg += "Successful.\n\n" 264 if text: 265 if text.count('Failed') or text.count('Error:') > 0: 266 mssg += "But Simple Test FAILED: Please check your code.\n" 267 mssg += "Run-Test results:\n" 268 mssg += str(text) 269 title = 'Info' 270 icon = wx.ICON_INFORMATION 271 dlg = wx.lib.dialogs.ScrolledMessageDialog(self, mssg, title, 272 size=((550, 250))) 273 fnt = wx.Font(10, wx.TELETYPE, wx.NORMAL, wx.NORMAL) 274 dlg.GetChildren()[0].SetFont(fnt) 275 dlg.GetChildren()[0].SetInsertionPoint(0) 276 dlg.ShowModal() 277 dlg.Destroy() 272 return not cancel 278 273 return True 279 274 … … 286 281 event.Enable(True) 287 282 try: 288 if id == ID_C OMPILEor id == ID_RUN:283 if id == ID_CHECK_MODEL or id == ID_RUN: 289 284 menu_on = False 290 285 if self.buffer and self.buffer.doc.filepath: -
src/sas/sasgui/perspectives/fitting/__init__.py
r9e531f2 ra7c4ad2 39 39 data_files = [] 40 40 path = os.path.dirname(__file__) 41 #p_path = os.path.join(path, 'plugin_models')42 #for f in findall(p_path):43 #data_files.append(('plugin_models', [f]))41 p_path = os.path.join(path, 'plugin_models') 42 for f in findall(p_path): 43 data_files.append(('plugin_models', [f])) 44 44 # path = get_data_path(media="media") 45 45 for f in findall(path): -
src/sas/sasgui/perspectives/fitting/fitpage.py
rcb4ef58 r934ce649 1330 1330 qmin=float(self.qmin_x), 1331 1331 qmax=float(self.qmax_x), 1332 enable_smearer=enable_smearer, 1333 draw=True) 1332 enable_smearer=enable_smearer) 1334 1333 if flag: 1335 1334 #self.compute_chisqr(smearer= temp_smearer) … … 2606 2605 qmin=float(self.qmin_x), 2607 2606 qmax=float(self.qmax_x), 2608 enable_smearer=enable_smearer, 2609 draw=True) 2607 enable_smearer=enable_smearer) 2610 2608 2611 2609 self.state.enable_smearer = self.enable_smearer.GetValue() -
src/sas/sasgui/perspectives/fitting/fitpanel.py
rf60251f r05228b0 17 17 import models 18 18 _BOX_WIDTH = 80 19 20 19 21 20 class FitPanel(nb, PanelBase): … … 154 153 """ 155 154 """ 156 from bumps.options import FIT_CONFIG157 current = FIT_CONFIG.selected_name158 self.parent.SetTitle(self.window_name + " - Active Fitting Optimizer: " + current)159 155 pos = self.GetSelection() 160 156 if pos != -1: -
src/sas/sasgui/perspectives/fitting/fitting.py
r86b049b r934ce649 19 19 import time 20 20 from copy import deepcopy 21 import models21 import traceback 22 22 23 23 from sas.sascalc.dataloader.loader import Loader … … 46 46 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 47 47 48 from . import models 49 48 50 MAX_NBR_DATA = 4 49 51 … … 56 58 ON_MAC = True 57 59 58 60 import bumps.options 61 from bumps.gui.fit_dialog import show_fit_config 62 try: 63 from bumps.gui.fit_dialog import EVT_FITTER_CHANGED 64 except ImportError: 65 # CRUFT: bumps 0.7.5.8 and below 66 EVT_FITTER_CHANGED = None # type: wx.PyCommandEvent 59 67 60 68 class Plugin(PluginBase): … … 254 262 msg += "and try it again." 255 263 wx.MessageBox(msg, 'Info') 256 # wx.PostEvent(self.parent, StatusEvent(status=msg, type='stop',257 # info='warning'))264 #evt = StatusEvent(status=msg, type='stop', info='warning') 265 #wx.PostEvent(self.parent, evt) 258 266 else: 259 267 self.delete_menu.Delete(event_id) … … 262 270 self.edit_menu.DeleteItem(item) 263 271 msg = "The custom model, %s, has been deleted." % label 264 wx.PostEvent(self.parent, StatusEvent(status=msg,265 type='stop', info='info'))272 evt = StatusEvent(status=msg, type='stop', info='info') 273 wx.PostEvent(self.parent, evt) 266 274 break 267 275 except: … … 501 509 self.parent.Bind(EVT_SLICER_PANEL, self._on_slicer_event) 502 510 self.parent.Bind(EVT_SLICER_PARS_UPDATE, self._onEVT_SLICER_PANEL) 511 512 # CRUFT: EVT_FITTER_CHANGED is not None for bumps 0.7.5.9 and above 513 if EVT_FITTER_CHANGED is not None: 514 self.parent.Bind(EVT_FITTER_CHANGED, self.on_fitter_changed) 515 self._set_fitter_label(bumps.options.FIT_CONFIG) 516 503 517 #self.parent._mgr.Bind(wx.aui.EVT_AUI_PANE_CLOSE,self._onclearslicer) 504 518 #Create reader when fitting panel are created … … 567 581 except: 568 582 msg = "Fitting: cannot deal with the theory received" 583 evt = StatusEvent(status=msg, info="error") 569 584 logging.error("set_theory " + msg + "\n" + str(sys.exc_value)) 570 wx.PostEvent(self.parent, 571 StatusEvent(status=msg, info="error")) 585 wx.PostEvent(self.parent, evt) 572 586 573 587 def set_state(self, state=None, datainfo=None, format=None): … … 763 777 Open the bumps options panel. 764 778 """ 765 try: 766 from bumps.gui.fit_dialog import show_fit_config 767 show_fit_config(self.parent, help=self.on_help) 768 except ImportError: 769 # CRUFT: Bumps 0.7.5.6 and earlier do not have the help button 770 from bumps.gui.fit_dialog import OpenFitOptions 771 OpenFitOptions() 779 show_fit_config(self.parent, help=self.on_help) 780 781 def on_fitter_changed(self, event): 782 self._set_fitter_label(event.config) 783 784 def _set_fitter_label(self, config): 785 self.fit_panel.parent.SetTitle(self.fit_panel.window_name 786 + " - Active Fitting Optimizer: " 787 + config.selected_name) 772 788 773 789 def on_help(self, algorithm_id): … … 954 970 if not page.param_toFit: 955 971 msg = "No fitting parameters for %s" % page.window_caption 956 wx.PostEvent(page.parent.parent, 957 StatusEvent(status=msg, info="error", 958 type="stop")) 972 evt = StatusEvent(status=msg, info="error", type="stop") 973 wx.PostEvent(page.parent.parent, evt) 959 974 return False 960 975 if not page._update_paramv_on_fit(): … … 962 977 msg += " invalid in %s" % \ 963 978 page.window_caption 964 wx.PostEvent(page.parent.parent, 965 StatusEvent(status=msg, info="error", 966 type="stop")) 979 evt = StatusEvent(status=msg, info="error", type="stop") 980 wx.PostEvent(page.parent.parent, evt) 967 981 return False 968 982 … … 985 999 except KeyboardInterrupt: 986 1000 msg = "Fitting terminated" 987 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info",988 type="stop"))1001 evt = StatusEvent(status=msg, info="info", type="stop") 1002 wx.PostEvent(self.parent, evt) 989 1003 return True 990 1004 except: 991 1005 raise 992 1006 msg = "Fitting error: %s" % str(sys.exc_value) 993 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error",994 type="stop"))1007 evt = StatusEvent(status=msg, info="error", type="stop") 1008 wx.PostEvent(self.parent, evt) 995 1009 return False 996 1010 ## If a thread is already started, stop it … … 1087 1101 # add data associated to the page created 1088 1102 if page != None: 1089 wx.PostEvent(self.parent, StatusEvent(status="Page Created",1090 info="info"))1103 evt = StatusEvent(status="Page Created", info="info") 1104 wx.PostEvent(self.parent, evt) 1091 1105 else: 1092 1106 msg = "Page was already Created" 1093 wx.PostEvent(self.parent, StatusEvent(status=msg,1094 info="warning"))1107 evt = StatusEvent(status=msg, info="warning") 1108 wx.PostEvent(self.parent, evt) 1095 1109 except: 1096 1110 msg = "Creating Fit page: %s" % sys.exc_value … … 1254 1268 msg = "Fit completed on %s \n" % str_time 1255 1269 msg += "Duration time: %s s.\n" % str(elapsed) 1256 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info",1257 type="stop"))1270 evt = StatusEvent(status=msg, info="info", type="stop") 1271 wx.PostEvent(self.parent, evt) 1258 1272 1259 1273 if batch_outputs is None: … … 1405 1419 batch_inputs=batch_inputs) 1406 1420 1407 wx.PostEvent(self.parent, StatusEvent(status=msg, error="info",1408 type="stop"))1421 evt = StatusEvent(status=msg, error="info", type="stop") 1422 wx.PostEvent(self.parent, evt) 1409 1423 # Remove parameters that are not shown 1410 1424 cpage = self.fit_panel.get_page_by_id(uid) … … 1485 1499 msg = "Fit completed on %s \n" % str_time 1486 1500 msg += "Duration time: %s s.\n" % str(elapsed) 1487 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info",1488 type="stop"))1501 evt = StatusEvent(status=msg, info="info", type="stop") 1502 wx.PostEvent(self.parent, evt) 1489 1503 wx.PostEvent(self.result_panel, PlotResultEvent(result=result)) 1490 1504 wx.CallAfter(self._update_fit_button, page_id) … … 1510 1524 not numpy.all(numpy.isfinite(res.pvec)): 1511 1525 msg = "Fitting did not converge!!!" 1512 wx.PostEvent(self.parent, 1513 StatusEvent(status=msg, 1514 info="warning", 1515 type="stop")) 1526 evt = StatusEvent(status=msg, info="warning", type="stop") 1527 wx.PostEvent(self.parent, evt) 1516 1528 wx.CallAfter(self._update_fit_button, page_id) 1517 1529 else: … … 1537 1549 except KeyboardInterrupt: 1538 1550 msg = "Singular point: Fitting Stoped." 1539 wx.PostEvent(self.parent, StatusEvent(status=msg, 1540 info="info", 1541 type="stop")) 1551 evt = StatusEvent(status=msg, info="info", type="stop") 1552 wx.PostEvent(self.parent, evt) 1542 1553 except: 1543 1554 msg = "Singular point: Fitting Error occurred." 1544 wx.PostEvent(self.parent, StatusEvent(status=msg, 1545 info="error", 1546 type="stop")) 1555 evt = StatusEvent(status=msg, info="error", type="stop") 1556 wx.PostEvent(self.parent, evt) 1547 1557 1548 1558 except: … … 1550 1560 % sys.exc_value) 1551 1561 #import traceback; msg = "\n".join((traceback.format_exc(), msg)) 1552 wx.PostEvent(self.parent, StatusEvent(status=msg, info="warning",1553 type="stop"))1562 evt = StatusEvent(status=msg, info="warning", type="stop") 1563 wx.PostEvent(self.parent, evt) 1554 1564 1555 1565 def _update_fit_button(self, page_id): … … 1588 1598 ## post a message to status bar 1589 1599 msg = "Set Chain Fitting: %s" % str(not self.batch_reset_flag) 1590 wx.PostEvent(self.parent, 1591 StatusEvent(status=msg)) 1600 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1592 1601 1593 1602 … … 1735 1744 raise 1736 1745 1746 def _calc_exception(self, etype, value, tb): 1747 """ 1748 Handle exception from calculator by posting it as an error. 1749 """ 1750 logging.error("".join(traceback.format_exception(etype, value, tb))) 1751 msg = traceback.format_exception(etype, value, tb, limit=1) 1752 evt = StatusEvent(status="".join(msg), type="stop", info="error") 1753 wx.PostEvent(self.parent, evt) 1754 1737 1755 def _update2D(self, output, time=None): 1738 1756 """ 1739 1757 Update the output of plotting model 1740 1758 """ 1741 wx.PostEvent(self.parent, StatusEvent(status="Plot \ 1742 #updating ... ", type="update")) 1743 #self.ready_fit() 1759 msg = "Plot updating ... " 1760 wx.PostEvent(self.parent, StatusEvent(msg, type="update")) 1744 1761 1745 1762 def _complete2D(self, image, data, model, page_id, elapsed, index, qmin, … … 1847 1864 time.sleep(0.1) 1848 1865 self.calc_2D = Calc2D(model=model, 1849 data=data, 1850 page_id=page_id, 1851 smearer=smearer, 1852 qmin=qmin, 1853 qmax=qmax, 1854 weight=weight, 1855 fid=fid, 1856 toggle_mode_on=toggle_mode_on, 1857 state=state, 1858 completefn=self._complete2D, 1859 update_chisqr=update_chisqr, source=source) 1866 data=data, 1867 page_id=page_id, 1868 smearer=smearer, 1869 qmin=qmin, 1870 qmax=qmax, 1871 weight=weight, 1872 fid=fid, 1873 toggle_mode_on=toggle_mode_on, 1874 state=state, 1875 completefn=self._complete2D, 1876 update_chisqr=update_chisqr, 1877 exception_handler=self._calc_exception, 1878 source=source) 1860 1879 self.calc_2D.queue() 1861 1880 except: … … 1912 1931 #updatefn = self._update1D, 1913 1932 update_chisqr=update_chisqr, 1933 exception_handler=self._calc_exception, 1914 1934 source=source) 1915 1935 self.calc_1D.queue() -
src/sas/sasgui/perspectives/fitting/model_thread.py
rd85c194 r934ce649 25 25 source='model', 26 26 yieldtime=0.04, 27 worktime=0.04 27 worktime=0.04, 28 exception_handler=None, 28 29 ): 29 CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 30 CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime, 31 exception_handler=exception_handler) 30 32 self.qmin = qmin 31 33 self.qmax = qmax … … 133 135 updatefn=None, 134 136 yieldtime=0.01, 135 worktime=0.01 137 worktime=0.01, 138 exception_handler=None, 136 139 ): 137 140 """ 138 141 """ 139 CalcThread.__init__(self, completefn, 140 updatefn, 141 yieldtime, 142 worktime) 142 CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime, 143 exception_handler=exception_handler) 143 144 self.fid = fid 144 145 self.data = data -
src/sas/sasgui/perspectives/invariant/media/invariant_help.rst
r7805458 r70305bd2 19 19 .. image:: image001.gif 20 20 21 where *g = Q* for pinhole geometry (SAS) and *g = Qv*(the slit height) for21 where *g = q* for pinhole geometry (SAS) and *g = q*\ :sub:`v` (the slit height) for 22 22 slit geometry (USAS). 23 23 -
src/sas/sasgui/plottools/plottables.py
rd7bb526 rcd54205 704 704 else: 705 705 self.dy = None 706 tempx = []707 tempy = []708 706 if not has_err_x: 709 707 dx = numpy.zeros(len(x)) … … 724 722 if has_err_y: 725 723 self.dy.append(tempdy) 726 except: 727 tempx = x[i] 728 tempy = y[i] 729 tempdy = dy[i] 724 except Exception: 725 pass 730 726 # Sanity check 731 727 if not len(self.x) == len(self.y): … … 733 729 msg += "and y are not of the same length" 734 730 raise ValueError, msg 735 if has_err_x and not (len(self.x) andlen(self.dx)):731 if has_err_x and not (len(self.x) == len(self.dx)): 736 732 msg = "Plottable.View: transformed x and dx" 737 733 msg += " are not of the same length" 738 734 raise ValueError, msg 739 if has_err_y and not (len(self.y) andlen(self.dy)):735 if has_err_y and not (len(self.y) == len(self.dy)): 740 736 msg = "Plottable.View: transformed y" 741 737 msg += " and dy are not of the same length" -
src/sas/sasgui/perspectives/fitting/models.py
rcb4ef58 r6afc14b 147 147 try: 148 148 import compileall 149 compileall.compile_dir(dir=dir, ddir=dir, force= 1,149 compileall.compile_dir(dir=dir, ddir=dir, force=0, 150 150 quiet=report_problem) 151 151 except:
Note: See TracChangeset
for help on using the changeset viewer.