Changeset 7949dcf7 in sasview for src/sas/sasgui
- Timestamp:
- Oct 14, 2016 8:28:47 AM (8 years ago)
- Parents:
- 9087214 (diff), 8b645cc (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. - git-author:
- jhbakker <j.h.bakker@…> (10/14/16 08:28:47)
- git-committer:
- GitHub <noreply@…> (10/14/16 08:28:47)
- Location:
- src/sas/sasgui
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/calculator/model_editor.py
rec72ceb rad1ac45 28 28 import math 29 29 import re 30 import logging 30 31 from wx.py.editwindow import EditWindow 31 32 from sas.sasgui.guiframe.documentation_window import DocumentationWindow … … 388 389 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 389 390 info=info)) 390 else:391 raise392 391 393 392 def on_help(self, event): … … 633 632 self.reader = None 634 633 self.name = 'untitled' 635 self.overwrite_name = False634 self.overwrite_name = True 636 635 self.is_2d = False 637 636 self.fname = None … … 684 683 #title name [string] 685 684 name_txt = wx.StaticText(self, -1, 'Function Name : ') 686 overwrite_cb = wx.CheckBox(self, -1, "Overwrite ?", (10, 10))687 overwrite_cb.SetValue( False)685 overwrite_cb = wx.CheckBox(self, -1, "Overwrite existing plugin model of this name?", (10, 10)) 686 overwrite_cb.SetValue(True) 688 687 overwrite_cb.SetToolTipString("Overwrite it if already exists?") 689 688 wx.EVT_CHECKBOX(self, overwrite_cb.GetId(), self.on_over_cb) … … 947 946 # Sort out the errors if occur 948 947 # First check for valid python name then if the name already exists 949 if not re.match('^[A-Za-z0-9_]*$', name): 950 msg = "not a valid python name. Name must include only alpha \n" 951 msg += "numeric or underline characters and no spaces" 948 if not name or not bool(re.match('^[A-Za-z0-9_]*$', name)): 949 msg = "is not a valid python name. Name must not be empty and \n" 950 msg += "may include only alpha numeric or underline characters \n" 951 msg += "and no spaces" 952 952 elif self.check_name(): 953 953 description = self.desc_tcl.GetValue() … … 966 966 result, msg = None, "error building model" 967 967 check_err = "\n"+traceback.format_exc(limit=2) 968 969 # Modified compiling test, as it will fail for sasmodels.sasview_model class970 # Should add a test to check that the class is correctly built971 # by sasview_model.make_class_from_file?972 # try:973 # tr_msg = _compile_file(self.fname)974 # msg = str(tr_msg.__str__())975 # # Compile error976 # if msg:977 # msg.replace(" ", "\n")978 # msg += "\nCompiling Failed"979 # try:980 # # try to remove pyc file if exists981 # _delete_file(self.fname)982 # _delete_file(self.fname + "c")983 # except:984 # pass985 # except:986 # pass987 968 else: 988 969 msg = "Error: The func(x) must 'return' a value at least.\n" … … 1002 983 exec "from %s import Model" % name 1003 984 except: 1004 pass 1005 # except: 1006 # msg = 'new model fails to import in python' 1007 # try: 1008 # # try to remove pyc file if exists 1009 # _delete_file(self.fname + "c") 1010 # except: 1011 # pass 1012 # 1013 # And also need to test if model runs 1014 # if self.base != None and not msg: 1015 # try: 1016 # Model().run(0.01) 1017 # except: 1018 # msg = "new model fails on run method:" 1019 # _, value, _ = sys.exc_info() 1020 # msg += "in %s:\n%s\n" % (name, value) 1021 # try: 1022 # # try to remove pyc file if exists 1023 # _delete_file(self.fname + "c") 1024 # except: 1025 # pass 985 logging.error(sys.exc_value) 986 1026 987 # Prepare the messagebox 1027 988 if msg: … … 1191 1152 1192 1153 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" 1193 _PageAnchor = "# custom-model-editor"1154 _PageAnchor = "#New_Plugin_Model" 1194 1155 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, _PageAnchor, 1195 " CustomModel Editor Help")1156 "Plugin Model Editor Help") 1196 1157 1197 1158 def on_close(self, event): … … 1230 1191 1231 1192 ## Templates for custom models 1232 #CUSTOM_TEMPLATE = """1233 #from sas.models.pluginmodel import Model1DPlugin1234 #from math import *1235 #import os1236 #import sys1237 #import numpy1238 ##import scipy?1239 #class Model(Model1DPlugin):1240 # name = basename without extension of __file__1241 # def __init__(self):1242 # Model1DPlugin.__init__(self, name=self.name)1243 # #set name same as file name1244 # #self.params here1245 # self.description = "%s"1246 # self.set_details()1247 # def function(self, x=0.0%s):1248 # #local params here1249 # #function here1250 #"""1251 1193 1252 1194 CUSTOM_TEMPLATE = """ … … 1419 1361 1420 1362 def _clone(self, obj): 1363 import copy 1421 1364 obj.params = copy.deepcopy(self.params) 1422 1365 obj.description = copy.deepcopy(self.description) -
src/sas/sasgui/perspectives/fitting/basepage.py
r9087214 r7949dcf7 2057 2057 2058 2058 if struct_factor != None: 2059 from sas .sascalc.fit.MultiplicationModel import MultiplicationModel2059 from sasmodels.sasview_model import MultiplicationModel 2060 2060 self.model = MultiplicationModel(form_factor(self.multi_factor), 2061 2061 struct_factor()) … … 3344 3344 item[0].SetValue(is_true) 3345 3345 3346 self.select_param(event=None) 3347 self.Refresh() 3348 3346 3349 def _paste_poly_help(self, item, value): 3347 3350 """ -
src/sas/sasgui/perspectives/fitting/media/fitting_help.rst
r3e1c9e5 r26c8be3 163 163 ^^^^^^^^^^^^^^^^ 164 164 165 Relatively straightforward models can be programmed directly from the SasView GUI 166 using the *New Plugin Model Function*. 167 165 168 .. image:: new_model.bmp 166 169 167 A model template generated by this option can be viewed and further modified using 170 When using this feature, be aware that even if your code has errors, including 171 syntax errors, a model file is still generated. When you then correct the errors 172 and click 'Apply' again to re-compile you will get an error informing you that 173 the model already exists if the 'Overwrite' box is not checked. In this case you 174 will need to supply a new model function name. By default the 'Overwrite' box is 175 *checked*\ . 176 177 Also note that the 'Fit Parameters' have been split into two sections: those which 178 can be polydisperse (shape and orientation parameters) and those which are not 179 (eg, scattering length densities). 180 181 A model file generated by this option can be viewed and further modified using 168 182 the :ref:`Advanced_Plugin_Editor` . 169 170 *NB: "Fit Parameters" has been split into two sections, those which can be171 polydisperse (shape and orientation parameters) and those which are not172 (scattering length densities, for example).*173 183 174 184 Sum|Multi(p1,p2) -
src/sas/sasgui/perspectives/fitting/models.py
r5de7f69 r313c5c9 356 356 """ 357 357 if int(evt.GetId()) in self.form_factor_dict.keys(): 358 from sas .sascalc.fit.MultiplicationModel import MultiplicationModel358 from sasmodels.sasview_model import MultiplicationModel 359 359 self.model_dictionary[MultiplicationModel.__name__] = MultiplicationModel 360 360 model1, model2 = self.form_factor_dict[int(evt.GetId())] -
src/sas/sasgui/perspectives/pr/pr.py
rc10d9d6c ra69a967 1276 1276 wx.PostEvent(self.parent, StatusEvent(status=msg, info='error')) 1277 1277 return 1278 msg += "Prview does not allow multiple data!\n"1278 msg = "Prview does not allow multiple data!\n" 1279 1279 msg += "Please select one.\n" 1280 1280 if len(data_list) > 1: -
src/sas/sasgui/guiframe/dataFitting.py
r9b6d62d r1fac6c0 17 17 """ 18 18 """ 19 def __init__(self, x=None, y=None, dx=None, dy=None ):19 def __init__(self, x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=False): 20 20 """ 21 21 """ … … 24 24 if y is None: 25 25 y = [] 26 PlotData1D.__init__(self, x, y, dx, dy) 27 LoadData1D.__init__(self, x, y, dx, dy) 26 self.isSesans = isSesans 27 PlotData1D.__init__(self, x, y, dx, dy, lam, dlam) 28 LoadData1D.__init__(self, x, y, dx, dy, lam, dlam, isSesans) 28 29 self.id = None 29 30 self.list_group_id = [] … … 68 69 # First, check the data compatibility 69 70 dy, dy_other = self._validity_check(other) 70 result = Data1D(x=[], y=[], dx=None, dy=None)71 result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=None) 71 72 result.clone_without_data(length=len(self.x), clone=self) 72 73 result.copy_from_datainfo(data1d=self) … … 115 116 # First, check the data compatibility 116 117 self._validity_check_union(other) 117 result = Data1D(x=[], y=[], dx=None, dy=None)118 result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=None) 118 119 tot_length = len(self.x) + len(other.x) 119 120 result = self.clone_without_data(length=tot_length, clone=result) 121 if self.dlam == None or other.dlam is None: 122 result.dlam = None 123 else: 124 result.dlam = numpy.zeros(tot_length) 120 125 if self.dy == None or other.dy is None: 121 126 result.dy = None … … 141 146 result.y = numpy.append(self.y, other.y) 142 147 result.y = result.y[ind] 148 result.lam = numpy.append(self.lam, other.lam) 149 result.lam = result.lam[ind] 150 if result.dlam != None: 151 result.dlam = numpy.append(self.dlam, other.dlam) 152 result.dlam = result.dlam[ind] 143 153 if result.dy != None: 144 154 result.dy = numpy.append(self.dy, other.dy) … … 260 270 # First, check the data compatibility 261 271 self._validity_check_union(other) 262 result = Data1D(x=[], y=[], dx=None, dy=None)272 result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=[]) 263 273 tot_length = len(self.x)+len(other.x) 264 274 result.clone_without_data(length=tot_length, clone=self) 275 if self.dlam == None or other.dlam is None: 276 result.dlam = None 277 else: 278 result.dlam = numpy.zeros(tot_length) 265 279 if self.dy == None or other.dy is None: 266 280 result.dy = None … … 285 299 result.y = numpy.append(self.y, other.y) 286 300 result.y = result.y[ind] 301 result.lam = numpy.append(self.lam, other.lam) 302 result.lam = result.lam[ind] 287 303 if result.dy != None: 288 304 result.dy = numpy.append(self.dy, other.dy) -
src/sas/sasgui/guiframe/data_manager.py
rd85c194 r1fac6c0 62 62 if issubclass(Data2D, data.__class__): 63 63 new_plot = Data2D(image=None, err_image=None) 64 else: 65 new_plot = Data1D(x=[], y=[], dx=None, dy=None) 64 elif data.meta_data['loader'] == 'SESANS': 65 new_plot = Data1D(x=[], y=[], dx=None, dy=None, lam=None, dlam=None, isSesans=True) 66 else: 67 new_plot = Data1D(x=[], y=[], dx=None, dy=None, lam=None, dlam=None) #SESANS check??? 66 68 67 69 new_plot.copy_from_datainfo(data) -
src/sas/sasgui/perspectives/fitting/fitpage.py
r3bec50a r9087214 55 55 self.weightbt_string = None 56 56 self.m_name = None 57 # transform implementation 58 self._fill_Trafo_sizer() 59 # self.Trafobt_string() 57 60 # get smear info from data 58 61 self._get_smear_info() … … 92 95 self.parent.on_set_focus(event) 93 96 self.on_tap_focus() 97 98 def onTrafo(self, event): 99 """ 100 On Trafo radio button event, sets the Trafobt_string 101 """ 102 self.Trafobt_string = event.GetEventObject().GetLabelText() 103 self._set_Trafo() 104 105 def _fill_Trafo_sizer(self): 106 107 title = "Transform" 108 box_description_trafo = wx.StaticBox(self, wx.ID_ANY, str(title)) 109 box_description_trafo.SetForegroundColour(wx.BLUE) 110 #boxsizer_trafo = wx.StaticBoxSizer(box_description_trafo, wx.VERTICAL) 111 boxsizer_trafo = wx.StaticBoxSizer(box_description_trafo, wx.HORIZONTAL) 112 #sizer_trafo = wx.StaticBoxSizer(box_description_trafo, wx.HORIZONTAL) 113 #weighting_set_box = wx.StaticBox(self, wx.ID_ANY, 114 # 'Select the type of SESANS analysis') 115 116 #sizer_weighting = wx.BoxSizer(wx.HORIZONTAL) 117 # weighting_box.SetMinSize((_DATA_BOX_WIDTH, 60)) 118 119 #For every radio button (each statement x3): 120 self.no_transform = wx.RadioButton(self, wx.ID_ANY, 121 'None', style=wx.RB_GROUP) 122 123 #self.Bind(wx.EVT_RADIOBUTTON, self.onTrafo, 124 # id=self.no_transform.GetId()) 125 self.hankel = wx.RadioButton(self, wx.ID_ANY, 126 'Hankel') 127 #self.Bind(wx.EVT_RADIOBUTTON, self.onTrafo, 128 # id=self.hankel.GetId()) 129 self.cosine = wx.RadioButton(self, wx.ID_ANY, 130 'Cosine') 131 #self.Bind(wx.EVT_RADIOBUTTON, self.onTrafo, 132 # id=self.cosine.GetId()) 133 134 #Not sure about this (only once though) 135 self.no_transform.SetValue(True) 136 137 #For every radio button (each statement x3): 138 boxsizer_trafo.Add(self.no_transform, 0, wx.LEFT, 10) 139 boxsizer_trafo.Add((14, 10)) 140 boxsizer_trafo.Add(self.hankel) 141 boxsizer_trafo.Add((14, 10)) 142 boxsizer_trafo.Add(self.cosine) 143 boxsizer_trafo.Add((14, 10)) 144 #Default for weighting is False, but these need to be on by default! 145 self.no_transform.Enable(True) 146 147 #Not sure about this (only once though) 148 #weighting_box.Add(sizer_trafo) 149 150 self.sizerTrafo.Clear(True) 151 self.sizerTrafo.Add(boxsizer_trafo, 0, wx.EXPAND | wx.ALL, 10) 152 #self.sizerTrafo.Add(sizer_trafo, 0, wx.EXPAND | wx.ALL, 10) 153 self.sizerTrafo.Layout() 94 154 95 155 def _fill_data_sizer(self): … … 624 684 ## fill a sizer with the combobox to select dispersion type 625 685 model_disp = wx.StaticText(self, wx.ID_ANY, 'Function') 626 CHECK_STATE = False686 CHECK_STATE = self.cb1.GetValue() 627 687 628 688 ix = 0 … … 969 1029 self.state.model = self.model.clone() 970 1030 ## save state into 1031 self.state.cb1 = self.cb1.GetValue() 971 1032 self._copy_parameters_state(self.parameters, self.state.parameters) 972 1033 self._copy_parameters_state(self.orientation_params_disp, … … 979 1040 StatusEvent(status=" Selected Distribution: Gaussian")) 980 1041 #Fill the list of fittable parameters 1042 #self.select_all_param(event=None) 981 1043 self.get_all_checked_params() 982 1044 self.Layout() … … 2693 2755 self._manager.set_param2fit(self.uid, param2fit) 2694 2756 2757 def select_all_param(self, event): 2758 """ 2759 set to true or false all checkBox given the main checkbox value cb1 2760 """ 2761 self.param_toFit = [] 2762 if self.parameters != []: 2763 if self.cb1.GetValue(): 2764 for item in self.parameters: 2765 if item[0].IsShown(): 2766 ## for data2D select all to fit 2767 if self.data.__class__.__name__ == "Data2D" or \ 2768 self.enable2D: 2769 item[0].SetValue(True) 2770 self.param_toFit.append(item) 2771 else: 2772 ## for 1D all parameters except orientation 2773 if not item in self.orientation_params: 2774 item[0].SetValue(True) 2775 self.param_toFit.append(item) 2776 else: 2777 item[0].SetValue(False) 2778 #if len(self.fittable_param)>0: 2779 for item in self.fittable_param: 2780 if item[0].IsShown(): 2781 if self.data.__class__.__name__ == "Data2D" or \ 2782 self.enable2D: 2783 item[0].SetValue(True) 2784 self.param_toFit.append(item) 2785 try: 2786 if len(self.values[item[1]]) > 0: 2787 item[0].SetValue(False) 2788 except: 2789 pass 2790 2791 else: 2792 ## for 1D all parameters except orientation 2793 if not item in self.orientation_params_disp: 2794 item[0].SetValue(True) 2795 self.param_toFit.append(item) 2796 try: 2797 if len(self.values[item[1]]) > 0: 2798 item[0].SetValue(False) 2799 except: 2800 pass 2801 else: 2802 item[0].SetValue(False) 2803 2804 else: 2805 for item in self.parameters: 2806 item[0].SetValue(False) 2807 for item in self.fittable_param: 2808 item[0].SetValue(False) 2809 self.param_toFit = [] 2810 2811 self.save_current_state_fit() 2812 2813 if event != None: 2814 #self._undo.Enable(True) 2815 ## post state to fit panel 2816 event = PageInfoEvent(page=self) 2817 wx.PostEvent(self.parent, event) 2818 param2fit = [] 2819 for item in self.param_toFit: 2820 if item[0] and item[0].IsShown(): 2821 param2fit.append(item[1]) 2822 self.parent._manager.set_param2fit(self.uid, param2fit) 2823 2695 2824 def select_param(self, event): 2696 2825 """ … … 2739 2868 if len(self.fittable_param) > 0: 2740 2869 len_orient_para *= 2 2870 #Set the value of checkbox that selected every checkbox or not 2871 if len(self.parameters) + len(self.fittable_param) - len_orient_para \ 2872 == len(self.param_toFit): 2873 self.cb1.SetValue(True) 2874 else: 2875 self.cb1.SetValue(False) 2741 2876 2742 2877 self.save_current_state_fit() … … 2840 2975 iy = 0 2841 2976 ix = 0 2842 sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Parameter'), 2843 (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2977 select_text = "Select All" 2978 self.cb1 = wx.CheckBox(self, wx.ID_ANY, str(select_text), (10, 10)) 2979 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) 2980 self.cb1.SetToolTipString("To check/uncheck all the boxes below.") 2981 self.cb1.SetValue(True) 2982 2983 sizer.Add(self.cb1, (iy, ix), (1, 1), \ 2984 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 2844 2985 ix += 1 2845 2986 self.text2_2 = wx.StaticText(self, wx.ID_ANY, 'Value') … … 2868 3009 self.text2_4.Hide() 2869 3010 2870 CHECK_STATE = False3011 CHECK_STATE = self.cb1.GetValue() 2871 3012 for item in keys: 2872 3013 -
src/sas/sasgui/plottools/plottables.py
r8abd96d r1fac6c0 1022 1022 """ 1023 1023 1024 def __init__(self, x, y, dx=None, dy=None ):1024 def __init__(self, x, y, dx=None, dy=None, lam=None, dlam=None): 1025 1025 """ 1026 1026 Draw points specified by x[i],y[i] in the current color/symbol. … … 1036 1036 self.x = x 1037 1037 self.y = y 1038 self.lam = lam 1038 1039 self.dx = dx 1039 1040 self.dy = dy 1041 self.dlam = dlam 1040 1042 self.source = None 1041 1043 self.detector = None
Note: See TracChangeset
for help on using the changeset viewer.