Changeset 0b12abb5 in sasview for sansview/perspectives
- Timestamp:
- Jun 18, 2010 12:36:11 PM (15 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 97dea6c
- Parents:
- df7ed14
- Location:
- sansview/perspectives/fitting
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
r1b43306 r0b12abb5 41 41 """ 42 42 """ 43 wx.ScrolledWindow.__init__(self, parent, 44 style= wx.FULL_REPAINT_ON_RESIZE ) 43 wx.ScrolledWindow.__init__(self, parent,style=wx.FULL_REPAINT_ON_RESIZE) 45 44 #Set window's font size 46 45 self.SetWindowVariant(variant=FONT_VARIANT) 47 ##window_name48 49 46 ## parent of the page 50 47 self.parent = parent … … 58 55 self.data = None 59 56 self.mask = None 60 self.theory = None 57 ## Q range 58 self.qmax_x = None 59 self.qmin_x = None 60 self.num_points= _NPTS_DEFAULT 61 ## total number of point: float 62 self.npts = None 63 ## default fitengine type 64 self.engine_type = None 65 ## smear default 66 self.smearer = None 67 self.current_smearer = None 68 ## 2D smear accuracy default 69 self.smear2d_accuracy = 'Low' 70 ## slit smear: 71 self.dxl = None 72 self.dxw = None 73 ## pinhole smear 74 self.dx_min = None 75 self.dx_max = None 76 77 self.disp_cb_dict = {} 78 61 79 self.state = PageState(parent=parent) 62 80 ## dictionary containing list of models … … 96 114 self.fitrange= True 97 115 98 ## Q range 99 self.qmin_x= _QMIN_DEFAULT 100 self.qmax_x= _QMAX_DEFAULT 101 self.num_points= _NPTS_DEFAULT 116 117 102 118 103 119 ## Create memento to save the current state … … 193 209 194 210 """ 195 196 211 event.Skip() 197 212 self.full_selection = True … … 296 311 self.sizer4.SetMinSize((PANEL_WIDTH,-1)) 297 312 self.sizer5.SetMinSize((PANEL_WIDTH,-1)) 298 #self.sizer6.SetMinSize((PANEL_WIDTH,-1))313 self.sizer6.SetMinSize((PANEL_WIDTH,-1)) 299 314 300 315 self.vbox.Add(self.sizer0) … … 304 319 self.vbox.Add(self.sizer4) 305 320 self.vbox.Add(self.sizer5) 306 #self.vbox.Add(self.sizer6)321 self.vbox.Add(self.sizer6) 307 322 308 323 def set_layout(self): … … 578 593 self.manager.save_fit_state(filepath=path, fitstate=new_state) 579 594 return new_state 580 595 581 596 def on_bookmark(self, event): 597 """ 598 save history of the data and model 599 """ 600 if self.model==None: 601 msg="Can not bookmark; Please select Data and Model first..." 602 wx.MessageBox(msg, 'Info') 603 return 604 self.save_current_state() 605 new_state = self.state.clone() 606 ##Add model state on context menu 607 self.number_saved_state += 1 608 #name= self.model.name+"[%g]"%self.number_saved_state 609 name= self.model.__class__.__name__+"[%g]"%self.number_saved_state 610 self.saved_states[name]= new_state 611 612 ## Add item in the context menu 613 614 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() 615 my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " 616 date= str( month)+"|"+str(day)+"|"+str(year) 617 msg= "Model saved at %s on %s"%(my_time, date) 618 ## post help message for the selected model 619 msg +=" Saved! right click on this page to retrieve this model" 620 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 621 622 id = wx.NewId() 623 self.popUpMenu.Append(id,name,str(msg)) 624 wx.EVT_MENU(self, id, self.onResetModel) 625 626 def old_on_bookmark(self, event): 582 627 """ 583 628 save history of the data and model … … 676 721 Store current state 677 722 """ 723 if hasattr(self, "engine_type"): 724 self.state.engine_type = copy.deepcopy(self.engine_type) 678 725 ## save model option 679 726 if self.model!= None: … … 681 728 self.state.disp_list= copy.deepcopy(self.disp_list) 682 729 self.state.model = self.model.clone() 683 730 #save radiobutton state for model selection 731 self.state.shape_rbutton = self.shape_rbutton.GetValue() 732 self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() 733 self.state.struct_rbutton = self.struct_rbutton.GetValue() 734 self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 735 #model combobox 736 self.state.structurebox = self.structurebox.GetSelection() 737 self.state.formfactorbox = self.formfactorbox.GetSelection() 738 684 739 self.state.enable2D = copy.deepcopy(self.enable2D) 685 740 self.state.values= copy.deepcopy(self.values) … … 687 742 ## save data 688 743 self.state.data= copy.deepcopy(self.data) 744 self.state.qmax_x = self.qmax_x 745 self.state.qmin_x = self.qmin_x 689 746 try: 690 747 n = self.disp_box.GetCurrentSelection() … … 697 754 except: 698 755 pass 699 756 700 757 if hasattr(self,"enable_disp"): 701 758 self.state.enable_disp= self.enable_disp.GetValue() … … 711 768 712 769 if hasattr(self,"disp_box"): 713 self.state.disp_box = self.disp_box.Get CurrentSelection()770 self.state.disp_box = self.disp_box.GetSelection() 714 771 715 772 if len(self.disp_cb_dict)>0: … … 842 899 return True 843 900 901 844 902 def reset_page_helper(self, state): 845 903 """ … … 854 912 #self._undo.Enable(False) 855 913 return 856 857 self.model= state.model 858 self.data = state.data 859 if self.data !=None: 860 from DataLoader.qsmearing import smear_selection 861 self.smearer= smear_selection(self.data) 914 915 self.set_data(state.data) 862 916 self.enable2D= state.enable2D 863 917 self.engine_type = state.engine_type … … 871 925 self.struct_rbutton.SetValue(state.struct_rbutton ) 872 926 self.plugin_rbutton.SetValue(state.plugin_rbutton) 873 ##draw sizer containing model parameters value for the current model 874 self._set_model_sizer_selection( self.model ) 875 self.set_model_param_sizer(self.model) 876 877 ## reset value of combox box 927 928 ## fill model combobox 929 self._show_combox_helper() 930 #select the current model 878 931 self.structurebox.SetSelection(state.structurecombobox ) 879 932 self.formfactorbox.SetSelection(state.formfactorcombobox) 880 881 882 ## enable the view 2d button if this is a modelpage type 883 if hasattr(self,"model_view"): 884 if self.enable2D: 885 self.model_view.Disable() 886 else: 887 self.model_view.Enable() 933 #reset the fitting engine type 934 self.engine_type = state.engine_type 935 #draw the pnael according to the new model parameter 936 self._on_select_model(event=None) 937 938 if self.manager !=None: 939 self.manager._on_change_engine(engine=self.engine_type) 888 940 ## set the select all check box to the a given state 889 if hasattr(self, "cb1"): 890 self.cb1.SetValue(state.cb1) 941 self.cb1.SetValue(state.cb1) 891 942 892 943 ## reset state of checkbox,textcrtl and regular parameters value 893 894 944 self._reset_parameters_state(self.orientation_params_disp, 895 945 state.orientation_params_disp) … … 944 994 ##plotting range restore 945 995 self._reset_plotting_range(state) 996 ## smearing info restore 997 if hasattr(self, "enable_smearer"): 998 ## set smearing value whether or not the data contain the smearing info 999 self.enable_smearer.SetValue(state.enable_smearer) 1000 self.disable_smearer.SetValue(state.disable_smearer) 1001 self.onSmear(event=None) 1002 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1003 self.slit_smearer.SetValue(state.slit_smearer) 1004 ## we have two more options for smearing 1005 if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None) 1006 elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None) 1007 1008 ## reset state of checkbox,textcrtl and dispersity parameters value 1009 self._reset_parameters_state(self.fittable_param,state.fittable_param) 1010 self._reset_parameters_state(self.fixed_param,state.fixed_param) 1011 1012 ## draw the model with previous parameters value 1013 self._onparamEnter_helper() 1014 ## reset context menu items 1015 self._reset_context_menu() 1016 ## set the value of the current state to the state given as parameter 1017 self.state = state.clone() 1018 1019 1020 def old_reset_page_helper(self, state): 1021 """ 1022 Use page_state and change the state of existing page 1023 1024 :precondition: the page is already drawn or created 1025 1026 :postcondition: the state of the underlying data change as well as the 1027 state of the graphic interface 1028 """ 1029 if state ==None: 1030 #self._undo.Enable(False) 1031 return 1032 1033 self.model= state.model 1034 self.data = state.data 1035 if self.data !=None: 1036 from DataLoader.qsmearing import smear_selection 1037 self.smearer= smear_selection(self.data) 1038 self.enable2D= state.enable2D 1039 self.engine_type = state.engine_type 1040 1041 self.disp_cb_dict = state.disp_cb_dict 1042 self.disp_list = state.disp_list 1043 1044 ## set the state of the radio box 1045 self.shape_rbutton.SetValue(state.shape_rbutton ) 1046 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 1047 self.struct_rbutton.SetValue(state.struct_rbutton ) 1048 self.plugin_rbutton.SetValue(state.plugin_rbutton) 1049 ##draw sizer containing model parameters value for the current model 1050 self._set_model_sizer_selection( self.model ) 1051 self.set_model_param_sizer(self.model) 1052 1053 ## reset value of combox box 1054 self.structurebox.SetSelection(state.structurecombobox ) 1055 self.formfactorbox.SetSelection(state.formfactorcombobox) 1056 1057 1058 ## enable the view 2d button if this is a modelpage type 1059 if hasattr(self,"model_view"): 1060 if self.enable2D: 1061 self.model_view.Disable() 1062 else: 1063 self.model_view.Enable() 1064 ## set the select all check box to the a given state 1065 if hasattr(self, "cb1"): 1066 self.cb1.SetValue(state.cb1) 1067 1068 ## reset state of checkbox,textcrtl and regular parameters value 1069 1070 self._reset_parameters_state(self.orientation_params_disp, 1071 state.orientation_params_disp) 1072 self._reset_parameters_state(self.orientation_params, 1073 state.orientation_params) 1074 self._reset_parameters_state(self.parameters,state.parameters) 1075 ## display dispersion info layer 1076 self.enable_disp.SetValue(state.enable_disp) 1077 self.disable_disp.SetValue(state.disable_disp) 1078 1079 if hasattr(self, "disp_box"): 1080 1081 self.disp_box.SetSelection(state.disp_box) 1082 n= self.disp_box.GetCurrentSelection() 1083 dispersity= self.disp_box.GetClientData(n) 1084 name= dispersity.__name__ 1085 1086 self._set_dipers_Param(event=None) 1087 1088 if name=="ArrayDispersion": 1089 1090 for item in self.disp_cb_dict.keys(): 1091 1092 if hasattr(self.disp_cb_dict[item],"SetValue") : 1093 self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item]) 1094 # Create the dispersion objects 1095 from sans.models.dispersion_models import ArrayDispersion 1096 disp_model = ArrayDispersion() 1097 if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: 1098 if len(state.values)>0: 1099 self.values=state.values 1100 self.weights=state.weights 1101 disp_model.set_weights(self.values, state.weights) 1102 else: 1103 self._reset_dispersity() 1104 1105 self._disp_obj_dict[item] = disp_model 1106 # Set the new model as the dispersion object for the selected parameter 1107 self.model.set_dispersion(item, disp_model) 1108 1109 self.model._persistency_dict[item] = [state.values, state.weights] 1110 1111 else: 1112 keys = self.model.getParamList() 1113 for item in keys: 1114 if item in self.disp_list and not self.model.details.has_key(item): 1115 self.model.details[item]=["",None,None] 1116 for k,v in self.state.disp_cb_dict.iteritems(): 1117 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1118 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1119 1120 ##plotting range restore 1121 self._reset_plotting_range(state) 946 1122 947 1123 ## smearing info restore … … 1003 1179 self.qmin.SetValue(str(state.qmin)) 1004 1180 self.qmax.SetValue(str(state.qmax)) 1005 if self.state.npts!=None: 1006 self.npts.SetValue(str(state.npts)) 1007 1181 1008 1182 def _save_typeOfmodel(self): 1009 1183 """ … … 1182 1356 item_page_info = statelist[j] 1183 1357 ##change the state of the check box for simple parameters 1184 if item_page[0]!=None: 1358 if item_page[0]!=None: 1185 1359 item_page[0].SetValue(item_page_info[0]) 1186 1187 1360 if item_page[2]!=None: 1188 1361 item_page[2].SetValue(item_page_info[2]) 1189 1190 1362 if item_page[3]!=None: 1191 1363 ## show or hide text +/- … … 1477 1649 self.SetScrollbars(20,20,25,65) 1478 1650 1479 def _show_combox(self, event): 1480 """ 1481 Show combox box associate with type of model selected 1482 """ 1483 if self.check_invalid_panel(): 1484 self.shape_rbutton.SetValue(True) 1485 return 1486 1487 ## Don't want to populate combo box again if the event comes from check box 1488 if self.shape_rbutton.GetValue()and\ 1489 event.GetEventObject()==self.shape_rbutton: 1651 def _show_combox_helper(self): 1652 """ 1653 Fill panel's combo box according to the type of model selected 1654 """ 1655 if self.shape_rbutton.GetValue(): 1490 1656 ##fill the combobox with form factor list 1491 1657 self.structurebox.SetSelection(0) … … 1493 1659 self.formfactorbox.Clear() 1494 1660 self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) 1495 1496 if self.shape_indep_rbutton.GetValue()and\ 1497 event.GetEventObject()==self.shape_indep_rbutton: 1661 if self.shape_indep_rbutton.GetValue(): 1498 1662 ##fill the combobox with shape independent factor list 1499 1663 self.structurebox.SetSelection(0) … … 1502 1666 self._populate_box( self.formfactorbox, 1503 1667 self.model_list_box["Shape-Independent"]) 1504 1505 if self.struct_rbutton.GetValue() and\ 1506 event.GetEventObject()==self.struct_rbutton: 1668 if self.struct_rbutton.GetValue(): 1507 1669 ##fill the combobox with structure factor list 1508 1670 self.structurebox.SetSelection(0) … … 1511 1673 self._populate_box( self.formfactorbox, 1512 1674 self.model_list_box["Structure Factors"]) 1513 1514 if self.plugin_rbutton.GetValue()and\ 1515 event.GetEventObject()==self.plugin_rbutton: 1516 1675 if self.plugin_rbutton.GetValue(): 1517 1676 ##fill the combobox with form factor list 1518 1677 self.structurebox.Disable() … … 1521 1680 self.model_list_box["Customized Models"]) 1522 1681 1682 def _show_combox(self, event=None): 1683 """ 1684 Show combox box associate with type of model selected 1685 """ 1686 if self.check_invalid_panel(): 1687 self.shape_rbutton.SetValue(True) 1688 return 1689 1690 self._show_combox_helper() 1523 1691 self._on_select_model(event=None) 1524 1692 self._save_typeOfmodel() … … 1574 1742 msg= "Model Error:wrong value entered : %s"% sys.exc_value 1575 1743 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1576 return 1577 1744 return 1578 1745 except: 1579 1746 tcrtl.SetBackgroundColour("pink") … … 1591 1758 msg= "Cannot Plot :No npts in that Qrange!!! " 1592 1759 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1593 1594 1760 else: 1595 1761 tcrtl.SetBackgroundColour("pink") 1596 1762 msg= "Model Error:wrong value entered!!!" 1597 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1598 1763 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1599 1764 #self._undo.Enable(True) 1600 1765 self.save_current_state() … … 1617 1782 form_factor = None 1618 1783 if f_id >= 0: 1619 form_factor = self.formfactorbox.GetClientData( f_id)1784 form_factor = self.formfactorbox.GetClientData(f_id) 1620 1785 1621 1786 if not form_factor in self.model_list_box["multiplication"]: … … 2119 2284 self.sizer5.Layout() 2120 2285 2121 2122 2286 def _fill_save_sizer(self): 2123 2287 """ 2124 2288 Draw the layout for saving option 2125 2289 """ 2126 return2127 2290 self.sizer6.Clear(True) 2128 2291 box_description= wx.StaticBox(self, -1,"Save Model") -
sansview/perspectives/fitting/fitpage.py
r5062bbf r0b12abb5 12 12 from sans.guicomm.events import StatusEvent 13 13 from sans.guiframe.utils import format_number,check_float 14 #from sans.guiframe.local_perspectives.plotting.Masking import ModelPanel2D as panel2D 15 16 ## event to post model to fit to fitting plugins 17 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 14 15 18 16 19 17 ## event to know the selected fit engine … … 45 43 """ 46 44 BasicPage.__init__(self, parent, page_info) 47 ## total number of point: float 48 self.npts=None 49 ## thread for compute Chisqr 50 self.calc_Chisqr=None 51 ## default fitengine type 52 self.engine_type = None 53 ## smear default 54 self.smearer = None 55 self.current_smearer = None 56 ## 2D smear accuracy default 57 self.smear2d_accuracy = 'Low' 58 ## slit smear: 59 self.dxl = None 60 self.dxw = None 61 ## pinhole smear 62 self.dx_min = None 63 self.dx_max = None 64 65 ## model data (theory) calculated on drawing. 66 self.theory_data = None 67 45 68 46 ## draw sizer 69 47 self._fill_datainfo_sizer() 70 71 48 # get smear info from data 72 49 self._get_smear_info() 73 74 50 self._fill_model_sizer( self.sizer1) 75 76 51 self._get_defult_custom_smear() 77 78 52 self._fill_range_sizer() 79 53 … … 82 56 self.structurebox.Disable() 83 57 else: 84 self.smearer = smear_selection( self.data)58 self.smearer = smear_selection(self.data) 85 59 if self.smearer ==None: 86 60 self.enable_smearer.Disable() 87 #if self.data.__class__.__name__ =="Data2D":88 #if self.model != None:89 #self.smear_description_2d.Show(True)90 91 self.disp_cb_dict = {}92 61 ## to update the panel according to the fit engine type selected 93 62 self.Bind(EVT_FITTER_TYPE,self._on_engine_change) … … 124 93 """ 125 94 self.engine_type = event.type 95 self.state.engine_type = self.engine_type 126 96 if len(self.parameters)==0: 127 97 self.Layout() … … 828 798 829 799 830 def _on_select_model(self, event ):800 def _on_select_model(self, event=None): 831 801 """ 832 802 call back for model selection … … 859 829 ## error occured on chisqr computation 860 830 pass 831 ## event to post model to fit to fitting plugins 832 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 861 833 if self.data is not None and self.data.__class__.__name__ !="Data2D": 862 834 ## set smearing value whether or not the data contain the smearing info … … 867 839 else: 868 840 evt = ModelEventbox(model=self.model) 869 wx.PostEvent(self.event_owner, evt) 870 841 842 self.manager._on_model_panel(evt=evt) 843 self.state.model = self.model.clone() 844 self.state.model.name = self.model.name 845 if event is not None: 846 self._draw_model() 871 847 if event !=None: 872 848 #self._undo.Enable(True) … … 874 850 event = PageInfoEvent(page = self) 875 851 wx.PostEvent(self.parent, event) 852 876 853 877 854 def _onparamEnter(self,event): … … 1335 1312 """ 1336 1313 self.reset_page_helper(state) 1337 import sans.guiframe.gui_manager1338 evt = ModelEventbox(model=state.model)1339 wx.PostEvent(self.event_owner, evt)1314 #import sans.guiframe.gui_manager 1315 #evt = ModelEventbox(model=state.model) 1316 #wx.PostEvent(self.event_owner, evt) 1340 1317 1341 1318 if self.engine_type != None: … … 1813 1790 of the values entered for slit smear 1814 1791 """ 1792 if self.data.__class__.__name__ == "Data2D": 1793 return 1815 1794 temp_smearer = None 1816 1795 # make sure once more if it is smearer -
sansview/perspectives/fitting/fitpanel.py
r5062bbf r0b12abb5 211 211 if name == page_info.window_name: 212 212 # the page is still opened 213 panel.set_manager(self.manager) 214 panel.set_owner(self.event_owner) 215 if panel.model_list_box is None or len(panel.model_list_box) == 0: 216 page_info.model_list_box = self.model_list_box.get_list() 217 panel.populate_box(dict=page_info.model_list_box) 218 panel.initialize_combox() 219 panel.set_page_info(page_info=page_info) 220 self.opened_pages[page_info.type] = [page_info.window_name, panel] 221 if panel is not None: 222 self.manager.store_page(page=panel, data=state.data) 213 223 panel.reset_page(state=state) 214 224 page_is_opened = True 225 215 226 if not page_is_opened: 216 227 panel = self.add_fit_page(data=state.data) … … 303 314 name = "Fit Page" 304 315 type = 'empty' 305 if data is not None :316 if data is not None and hasattr(data, "is_data"): 306 317 if data.is_data: 307 318 name = data.name -
sansview/perspectives/fitting/fitting.py
r1759c8e r0b12abb5 161 161 self.fit_panel.set_owner(owner) 162 162 self.fit_panel.set_model_list(self.menu_mng.get_model_list()) 163 owner.Bind(fitpage.EVT_MODEL_BOX,self._on_model_panel) 164 163 165 164 #create menubar items 166 165 return [(id, self.menu1, "Fitting")] … … 299 298 300 299 """ 300 #print "state", state 301 #return 301 302 #working on reading state 302 return303 303 try: 304 304 # Load fitting state … … 1003 1003 ## example trying to call set_panel on self.sim_page 1004 1004 if self.current_pg != self.sim_page : 1005 if self.page_finder[self.current_pg].get_model()== None 1005 if self.page_finder[self.current_pg].get_model()== None: 1006 1006 1007 1007 model.name = "M"+str(self.index_model) … … 1016 1016 qmin, qmax= self.current_pg.get_range() 1017 1017 self.page_finder[self.current_pg].set_range(qmin=qmin, qmax=qmax) 1018 smearer= self.page_finder[self.current_pg].get_smearer() 1019 # save model name 1020 self.set_smearer(smearer=smearer, qmin=qmin, qmax=qmax) 1021 1018 1022 1019 if self.sim_page!=None: 1023 1020 self.sim_page.draw_page() -
sansview/perspectives/fitting/pagestate.py
rdf7ed14 r0b12abb5 44 44 ["plugin_rbutton", "plugin_rbutton","bool"], 45 45 ["struct_rbutton", "struct_rbutton", "bool"], 46 ["formfactorcombobox", "formfactorcombobox", " bool"],47 ["structurecombobox", "structurecombobox", " bool"],48 ["disp_box", "disp_box" ],46 ["formfactorcombobox", "formfactorcombobox", "float"], 47 ["structurecombobox", "structurecombobox", "float"], 48 ["disp_box", "disp_box", "float"], 49 49 ["enable_smearer","enable_smearer","bool"], 50 50 ["disable_smearer","disable_smearer","bool"], … … 89 89 ["mask","mask","bool"]] 90 90 91 def parse_entry_helper( node, item): 92 """ 93 Create a numpy list from value extrated from the node 94 95 :param node: node from each the value is stored 96 :param item: list name of three strings.the two first are name of data 97 attribute and the third one is the type of the value of that 98 attribute. type can be string, float, bool, etc. 99 100 : return: numpy array 101 """ 102 if node is not None: 103 if item[2] == "string": 104 return str(node.get(item[0]).strip()) 105 elif item[2] == "bool": 106 try: 107 exec "value = bool(node.get(item[0]).strip())" 108 return value 109 except: 110 return None 111 else: 112 try: 113 return float(node.get(item[0])) 114 except: 115 return None 116 117 91 118 class PageState(object): 92 119 """ … … 122 149 if self.data is not None and hasattr(self.data, "group_id"): 123 150 self.data_group_id = self.data.group_id 124 #-------------------------151 125 152 ## reset True change the state of exsiting button 126 153 self.reset = False … … 189 216 self.qmin = 0.001 190 217 self.qmax = 0.1 218 #reset data range 219 self.qmax_x = None 220 self.qmin_x = None 221 191 222 self.npts = None 192 223 self.name = "" … … 312 343 rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin), 313 344 str(self.qmax),str(self.npts)) 314 """ 345 rep += "Dispersion selection : %s\n"%str(self.disp_box) 346 rep += "Smearing enable : %s\n"%str(self.enable_smearer) 347 rep += "Smearing disable : %s\n"%str(self.disable_smearer) 348 rep += "Pinhole smearer enable : %s\n"%str(self.pinhole_smearer) 349 rep += "Slit smearer enable : %s\n"%str(self.slit_smearer) 350 rep += "Dispersity enable : %s\n"%str(self.enable_disp) 351 rep += "Dispersity disable : %s\n"%str(self.disable_disp) 352 rep += "Slit smearer enable: %s\n"%str(self.slit_smearer) 353 rep += "2D enable : %s\n"%str(self.enable2D) 354 rep += "All parameters checkbox selected: %s\n"%(self.cb1) 355 rep += "Value of Chisqr : %s\n"%str(self.tcChi) 356 rep += "Smear object : %s\n"%str(self.smearer) 357 rep += "Smear type : %s\n"%(self.smear_type) 358 rep += "dq_l : %s\n"%self.dq_l 359 rep += "dq_r : %s\n"%self.dq_r 360 315 361 rep += "model : %s\n\n"% str(self.model) 316 362 rep += "number parameters(self.parameters): %s\n"%len(self.parameters) … … 322 368 rep += "(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp) 323 369 rep += self._repr_helper( list=self.orientation_params_disp, rep=rep) 324 """370 325 371 return rep 326 372 … … 395 441 top_element.appendChild(inputs) 396 442 397 element = newdoc.createElement('data_attributes') 443 398 444 if self.data is not None and hasattr(self.data, "group_id"): 399 445 self.data_group_id = self.data.group_id … … 406 452 407 453 for item in list_of_data_attributes: 454 element = newdoc.createElement(item[0]) 408 455 exec "element.setAttribute(item[0], str(self.%s))"%(item[1]) 409 inputs.appendChild(element)456 inputs.appendChild(element) 410 457 411 458 for item in list_of_state_attributes: … … 418 465 exec "list = self.%s"%item[1] 419 466 for value in list: 420 exec "element.appendChild(newdoc.createTextNode(str(%s)))" %value467 exec "element.appendChild(newdoc.createTextNode(str(%s)))"%value 421 468 inputs.appendChild(element) 422 469 … … 440 487 """ 441 488 for item in node: 442 name = item.get('name') 443 value = item.get('value') 444 selected_to_fit = item.get('selected_to_fit') 445 error_displayed = item.get('error_displayed') 446 error_value = item.get('error_value') 447 minimum_displayed = item.get('minimum_displayed') 448 minimum_value = item.get('minimum_value') 449 maximum_displayed = item.get('maximum_displayed') 450 maximum_value = item.get('maximum_value') 451 unit = item.get('unit') 489 try: 490 name = item.get('name') 491 except: 492 name = None 493 try: 494 value = item.get('value') 495 except: 496 value = None 497 try: 498 selected_to_fit = bool(item.get('selected_to_fit')) 499 except: 500 selected_to_fit = None 501 try: 502 error_displayed = item.get('error_displayed') 503 except: 504 error_displayed = None 505 try: 506 error_value = item.get('error_value') 507 except: 508 error_value = None 509 try: 510 minimum_displayed = bool(item.get('minimum_displayed')) 511 except: 512 minimum_displayed = None 513 try: 514 minimum_value = item.get('minimum_value') 515 except: 516 minimum_value = None 517 try: 518 maximum_displayed = bool(item.get('maximum_displayed')) 519 except: 520 maximum_displayed = None 521 try: 522 maximum_value = item.get('maximum_value') 523 except: 524 maximum_value = None 525 try: 526 unit = item.get('unit') 527 except: 528 unit = None 452 529 list.append([selected_to_fit, name, value, "+/-",[error_displayed, error_value], 453 530 [minimum_displayed,minimum_value],[maximum_displayed,maximum_value], unit]) … … 461 538 462 539 """ 463 464 540 if file is not None: 465 541 msg = "PageState no longer supports non-CanSAS" … … 486 562 # Parse fitting attributes 487 563 entry = get_content('ns:Attributes', node) 564 for item in list_of_data_attributes: 565 node = get_content('ns:%s'%item[0], entry) 566 try: 567 exec "self.%s = parse_entry_helper(node, item)"%item[0] 568 569 except: 570 raise 571 488 572 if entry is not None: 573 489 574 for item in list_of_state_attributes: 490 field = get_content('ns:%s'%item[0], entry) 491 if field is not None: 492 if item[2] == "string": 493 exec "self.%s= str(field.text)"%item[1] 494 elif item[2] == "bool": 495 try: 496 exec "self.%s= field.get(%s)"%(item[1], item[0]) 497 except: 498 exec "self.%s = None"%item[1] 499 else: 500 try: 501 exec "self.%s = float(field.get(%s))"%(item[1], item[0]) 502 except: 503 exec "self.%s = None"%item[1] 575 node = get_content('ns:%s'%item[0], entry) 576 try: 577 exec "self.%s = parse_entry_helper(node, item)"%str(item[0]) 578 except: 579 raise 580 504 581 for item in list_of_model_attributes: 505 582 node = get_content("ns:%s"%item[0], entry) … … 510 587 except: 511 588 list.append(None) 512 513 589 exec "self.%s = list"%item[1] 514 590 515 591 for item in list_of_state_parameters: 516 592 node = get_content("ns:%s"%item[0], entry) 517 self._fromXML_helper(node=node, list=self.parameters)518 593 exec "self._fromXML_helper(node=node, list=self.%s)"%item[1] 594 519 595 520 596 class Reader(CansasReader): … … 761 837 try: 762 838 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, namespaces={'ns': CANSAS_NS}) 763 #if entry is not None:764 # self.file = entry.text.strip()765 839 state.fromXML(node=nodes[0]) 766 840 except: … … 769 843 return state 770 844 771 def _parse_entry_2d_helper(self, node, item): 772 """ 773 Create a numpy list from value extrated from the node 774 775 :param node: node from each the value is stored 776 :param item: list name of three strings.the two first are name of data 777 attribute and the third one is the type of the value of that 778 attribute. type can be string, float, bool, etc. 779 780 : return: numpy array 781 """ 782 if node is not None: 783 if item[2] == "string": 784 return node.get(item[0]).strip() 785 elif item[2] == "bool": 786 try: 787 return node.get(item[0]).strip() 788 except: 789 return None 790 else: 791 try: 792 return float(node.get(item[0])) 793 except: 794 return None 845 795 846 796 847 def _parse_entry(self, dom): … … 1014 1065 #get node 1015 1066 node = get_content('ns:%s'%item[0], entry) 1016 exec "data_info.%s = self._parse_entry_2d_helper(node, item)"%(item[1])1067 exec "data_info.%s = parse_entry_helper(node, item)"%(item[1]) 1017 1068 1018 1069 for item in list_of_data2d_values: … … 1020 1071 list = [] 1021 1072 if field is not None: 1022 list = [ self._parse_entry_2d_helper(node, item) for node in field]1073 list = [parse_entry_helper(node, item) for node in field] 1023 1074 exec "data_info.%s = numpy.array(list)"%item[0] 1024 1075 … … 1085 1136 1086 1137 output[0].filename = state.file 1087 #output[0].filename = state.data_name1088 1138 state.data = output[0] 1089 1139 state.data.name = state.data_name … … 1092 1142 if state.is_data is not None: 1093 1143 state.data.is_data = state.is_data 1094 #state.data.group_id = state.data_group_id1095 1144 state.data.group_id = output[0].filename 1096 1145
Note: See TracChangeset
for help on using the changeset viewer.