Changeset 5ce7f17 in sasview
- Timestamp:
- Mar 27, 2015 11:05:11 AM (10 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:
- cce0ad3
- Parents:
- a862cea0
- Location:
- src/sas
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/dataloader/readers/cansas_reader.py
r682c432 r5ce7f17 322 322 value_unit = local_unit 323 323 except: 324 print sys.exc_info()325 324 err_msg = "CanSAS reader: unknown error converting " 326 325 err_msg += "\"{0}\" unit [{1}]" … … 990 989 self.append(node, entry_node) 991 990 992 def _check_origin(self, entry_node, doc ):991 def _check_origin(self, entry_node, doc, frm): 993 992 """ 994 993 Return the document, and the SASentry node associated with … … 1000 999 :param doc: entire xml tree 1001 1000 """ 1002 frm = inspect.stack()[1] 1001 if not frm: 1002 frm = inspect.stack()[1] 1003 1003 mod_name = frm[1].replace("\\", "/").replace(".pyc", "") 1004 1004 mod_name = mod_name.replace(".py", "") … … 1011 1011 node_list = doc.getElementsByTagName(node_name) 1012 1012 entry_node = node_list.item(0) 1013 return entry_node1013 return doc, entry_node 1014 1014 1015 1015 def _to_xml_doc(self, datainfo): … … 1061 1061 # If the calling function was not the cansas reader, return a minidom 1062 1062 # object rather than an lxml object. 1063 entry_node = self._check_origin(entry_node, doc) 1063 frm = inspect.stack()[1] 1064 doc, entry_node = self._check_origin(entry_node, doc, frm) 1064 1065 return doc, entry_node 1065 1066 -
src/sas/dataloader/readers/xml_reader.py
r79492222 r5ce7f17 1 1 """ 2 2 Generic XML read and write utility 3 3 4 4 Usage: Either extend xml_reader or add as a class variable. 5 5 """ … … 7 7 #This software was developed by the University of Tennessee as part of the 8 8 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 9 #project funded by the US National Science Foundation. 10 #If you use DANSE applications to do scientific research that leads to 11 #publication, we ask that you acknowledge the use of the software with the 9 #project funded by the US National Science Foundation. 10 #If you use DANSE applications to do scientific research that leads to 11 #publication, we ask that you acknowledge the use of the software with the 12 12 #following sentence: 13 #This work benefited from DANSE software developed under NSF award DMR-0520547. 13 #This work benefited from DANSE software developed under NSF award DMR-0520547. 14 14 #copyright 2008,2009 University of Tennessee 15 15 ############################################################################# … … 25 25 Generic XML read and write class. Mostly helper functions. 26 26 Makes reading/writing XML a bit easier than calling lxml libraries directly. 27 27 28 28 :Dependencies: 29 29 This class requires lxml 2.3 or higher. 30 30 """ 31 31 32 32 xml = None 33 33 xmldoc = None … … 37 37 encoding = None 38 38 processing_instructions = None 39 40 def __init__(self, xml = None, schema =None):39 40 def __init__(self, xml=None, schema=None): 41 41 self.xml = xml 42 42 self.schema = schema … … 51 51 else: 52 52 self.schemadoc = None 53 53 54 54 def reader(self): 55 55 """ … … 57 57 """ 58 58 if self.validate_xml(): 59 self.xmldoc = etree.parse(self.xml, parser =PARSER)59 self.xmldoc = etree.parse(self.xml, parser=PARSER) 60 60 else: 61 61 raise etree.XMLSchemaValidateError(self, self.find_invalid_xml()) 62 62 return self.xmldoc 63 63 64 64 def set_xml_file(self, xml): 65 65 """ … … 68 68 try: 69 69 self.xml = xml 70 self.xmldoc = etree.parse(self.xml, parser =PARSER)70 self.xmldoc = etree.parse(self.xml, parser=PARSER) 71 71 self.xmlroot = self.xmldoc.getroot() 72 72 except etree.XMLSyntaxError as xml_error: … … 76 76 self.xmldoc = None 77 77 self.xmlroot = None 78 78 79 79 def set_schema(self, schema): 80 80 """ … … 83 83 try: 84 84 self.schema = schema 85 self.schemadoc = etree.parse(self.schema, parser =PARSER)85 self.schemadoc = etree.parse(self.schema, parser=PARSER) 86 86 except etree.XMLSyntaxError as xml_error: 87 87 logging.info(xml_error) … … 89 89 self.schema = None 90 90 self.schemadoc = None 91 91 92 92 def validate_xml(self): 93 93 """ … … 100 100 valid = schema_check.validate(self.xmldoc) 101 101 return valid 102 102 103 103 def find_invalid_xml(self): 104 104 """ … … 113 113 first_error = str(err) 114 114 return first_error 115 115 116 116 def parse_schema_and_doc(self): 117 117 """ … … 120 120 self.set_xml_file(self.xml) 121 121 self.set_schema(self.schema) 122 122 123 123 def to_string(self, elem, pretty_print=False, encoding=None): 124 124 """ 125 125 Converts an etree element into a string 126 126 """ 127 return etree.tostring(elem, pretty_print =pretty_print, \128 encoding =encoding)129 127 return etree.tostring(elem, pretty_print=pretty_print, \ 128 encoding=encoding) 129 130 130 def break_processing_instructions(self, string, dic): 131 131 """ 132 132 Method to break a processing instruction string apart and add to a dict 133 133 134 134 :param string: A processing instruction as a string 135 135 :param dic: The dictionary to save the PIs to … … 142 142 dic[new_pi_name] = attr 143 143 return dic 144 144 145 145 def set_processing_instructions(self): 146 146 """ … … 164 164 del dic['xml'] 165 165 self.processing_instructions = dic 166 166 167 167 def set_encoding(self, attr_str): 168 168 """ 169 169 Find the encoding in the xml declaration and save it as a string 170 170 171 171 :param attr_str: All attributes as a string 172 172 e.g. "foo1="bar1" foo2="bar2" foo3="bar3" ... foo_n="bar_n"" 173 173 """ 174 174 attr_str = attr_str.replace(" = ", "=") 175 attr_list = attr_str.split( 175 attr_list = attr_str.split() 176 176 for item in attr_list: 177 177 name_value = item.split("\"=") … … 182 182 return 183 183 self.encoding = None 184 185 def _create_unique_key(self, dictionary, name, numb =0):184 185 def _create_unique_key(self, dictionary, name, numb=0): 186 186 """ 187 187 Create a unique key value for any dictionary to prevent overwriting … … 198 198 name = self._create_unique_key(dictionary, name, numb) 199 199 return name 200 200 201 201 def create_tree(self, root): 202 202 """ 203 203 Create an element tree for processing from an etree element 204 204 205 205 :param root: etree Element(s) 206 206 """ 207 207 return etree.ElementTree(root) 208 208 209 209 def create_element_from_string(self, xml_string): 210 210 """ 211 211 Create an element from an XML string 212 212 213 213 :param xml_string: A string of xml 214 214 """ 215 215 return etree.fromstring(xml_string) 216 216 217 217 def create_element(self, name, attrib=None, nsmap=None): 218 218 """ 219 219 Create an XML element for writing to file 220 220 221 221 :param name: The name of the element to be created 222 222 """ … … 224 224 attrib = {} 225 225 return etree.Element(name, attrib, nsmap) 226 226 227 227 def write_text(self, elem, text): 228 228 """ 229 229 Write text to an etree Element 230 230 231 231 :param elem: etree.Element object 232 232 :param text: text to write to the element … … 234 234 elem.text = text 235 235 return elem 236 236 237 237 def write_attribute(self, elem, attr_name, attr_value): 238 238 """ 239 239 Write attributes to an Element 240 240 241 241 :param elem: etree.Element object 242 242 :param attr_name: attribute name to write … … 245 245 attr = elem.attrib 246 246 attr[attr_name] = attr_value 247 247 248 248 def return_processing_instructions(self): 249 249 """ 250 250 Get all processing instructions saved when loading the document 251 251 252 252 :param tree: etree.ElementTree object to write PIs to 253 253 """ … … 259 259 pi_list.append(pi_item) 260 260 return pi_list 261 261 262 262 def append(self, element, tree): 263 263 """ 264 264 Append an etree Element to an ElementTree. 265 265 266 266 :param element: etree Element to append 267 267 :param tree: ElementTree object to append to … … 269 269 tree = tree.append(element) 270 270 return tree 271 271 272 272 def ebuilder(self, parent, elementname, text=None, attrib=None): 273 273 """ 274 274 Use lxml E builder class with arbitrary inputs. 275 275 276 276 :param parnet: The parent element to append a child to 277 277 :param elementname: The name of the child in string form … … 285 285 parent = parent.append(elem) 286 286 return parent 287 -
src/sas/perspectives/fitting/basepage.py
r7cd87c2 r5ce7f17 175 175 self.orientation_params = [] 176 176 self.orientation_params_disp = [] 177 # Self.model should ALWAYS be None here. It was set to none above in 177 # Self.model should ALWAYS be None here. It was set to none above in 178 178 # this long init setting. no obvious function call in between setting 179 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 179 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 180 180 # it is pointless. 181 181 # if self.model != None: … … 417 417 _on_set_focus_callback = None 418 418 419 def __init__(self, parent, id= 419 def __init__(self, parent, id=-1, 420 420 value=wx.EmptyString, 421 421 pos=wx.DefaultPosition, … … 430 430 431 431 wx.TextCtrl.__init__(self, parent, id, value, pos, 432 432 size, style, validator, name) 433 433 434 434 # Bind appropriate events … … 488 488 set some page important information at once 489 489 """ 490 # THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED. Started up program 490 # THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED. Started up program 491 491 # and started new fit window and PR and Invariant and a fit in fitting 492 492 # but never entered this routine which should be an initialization 493 # routine. Leave for a while but probably something to clean up at 493 # routine. Leave for a while but probably something to clean up at 494 494 # some point? 495 495 # … … 589 589 def get_state(self): 590 590 """ 591 return the current page state 591 592 """ 592 593 return self.state … … 645 646 ## These are called for first time by formfactor_combo_init 646 647 ## itself called from fitpanel only. If we find that I'm wrong and 647 ## we DO need to initialize somehow here - do it by a call to 648 ## formfactor_combo_init 648 ## we DO need to initialize somehow here - do it by a call to 649 ## formfactor_combo_init 649 650 ## self.formfator_combo_init() 650 ## BUT NOT HERE -- make it last line of this 651 ## BUT NOT HERE -- make it last line of this 651 652 ## method so that structure box is populated before _show_comboox_helper 652 653 ## is called. Otherwise wx will complain mightily:-) … … 660 661 # self.model_list_box["Shapes"]) 661 662 self._populate_box(self.structurebox, 662 663 self.model_list_box["Structure Factors"]) 663 664 self.structurebox.Insert("None", 0, None) 664 665 self.structurebox.SetSelection(0) … … 686 687 #---------------------------------------------------- 687 688 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 688 689 style=wx.RB_GROUP) 689 690 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 690 691 # best size for MAC and PC … … 696 697 style=wx.BU_EXACTFIT, 697 698 size=size_q) 698 self.disp_help_bt.Bind(wx.EVT_BUTTON, 699 self.on_pd_help_clicked,id=self.disp_help_bt.GetId())699 self.disp_help_bt.Bind(wx.EVT_BUTTON, self.on_pd_help_clicked, 700 id=self.disp_help_bt.GetId()) 700 701 self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 701 702 702 703 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 703 704 id=self.disable_disp.GetId()) 704 705 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 705 706 id=self.enable_disp.GetId()) 706 707 #MAC needs SetValue 707 708 self.disable_disp.SetValue(True) … … 718 719 ## fill a sizer for dispersion 719 720 boxsizer1.Add(sizer_dispersion, 0, 720 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND |wx.ADJUST_MINSIZE,721 border=5)721 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 722 border=5) 722 723 self.sizer4_4 = wx.GridBagSizer(6, 5) 723 724 … … 778 779 self._manager.parent._default_save_location 779 780 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, 780 781 self.window_caption, "*.fitv", wx.SAVE) 781 782 782 783 if dlg.ShowModal() == wx.ID_OK: … … 784 785 self._default_save_location = os.path.dirname(path) 785 786 self._manager.parent._default_save_location = \ 786 787 self._default_save_location 787 788 else: 788 789 return None … … 843 844 # inform msg to wx 844 845 wx.PostEvent(self._manager.parent, 845 StatusEvent(status=msg, info=infor))846 StatusEvent(status=msg, info=infor)) 846 847 847 848 def _get_time_stamp(self): … … 912 913 try: 913 914 if path == None: 915 status = " Selected Distribution was not loaded: %s" % path 914 916 wx.PostEvent(self._manager.parent, 915 StatusEvent(status=\ 916 " Selected Distribution was not loaded: %s" % path)) 917 StatusEvent(status=status)) 917 918 return None, None 918 919 input_f = open(path, 'r') … … 931 932 except: 932 933 # Skip non-data lines 933 logging.error(sys.exc_ value)934 logging.error(sys.exc_info()[1]) 934 935 return numpy.array(angles), numpy.array(weights) 935 936 except: … … 1095 1096 ## save checkbutton state and txtcrtl values 1096 1097 self._copy_parameters_state(self.orientation_params, 1097 1098 self.state.orientation_params) 1098 1099 self._copy_parameters_state(self.orientation_params_disp, 1099 1100 self.state.orientation_params_disp) 1100 1101 self._copy_parameters_state(self.parameters, self.state.parameters) 1101 1102 self._copy_parameters_state(self.fittable_param, 1102 1103 self.state.fittable_param) 1103 1104 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1104 1105 … … 1136 1137 category_pos = 0 1137 1138 for ind_cat in range(self.categorybox.GetCount()): 1138 if self.categorycombobox.GetString(ind_ form) == \1139 if self.categorycombobox.GetString(ind_cat) == \ 1139 1140 state.categorycombobox: 1140 1141 category_pos = int(ind_cat) … … 1365 1366 else: 1366 1367 self.model_view.SetLabel("1D Mode") 1367 # else: 1368 1369 if self._manager != None and self.engine_type != None: 1370 self._manager._on_change_engine(engine=self.engine_type) 1368 1371 1369 ## set the select all check box to the a given state 1372 1370 self.cb1.SetValue(state.cb1) … … 1480 1478 [state.values, state.weights] 1481 1479 except: 1482 logging.error(sys.exc_ value)1480 logging.error(sys.exc_info()[1]) 1483 1481 selection = self._find_polyfunc_selection(disp_model) 1484 1482 for list in self.fittable_param: … … 1497 1495 list[6].Disable() 1498 1496 except: 1499 logging.error(sys.exc_ value)1497 logging.error(sys.exc_info()[1]) 1500 1498 # For array, disable all fixed params 1501 1499 if selection == 1: … … 1506 1504 item[2].Disable() 1507 1505 except: 1508 logging.error(sys.exc_ value)1506 logging.error(sys.exc_info()[1]) 1509 1507 1510 1508 # Make sure the check box updated when all checked … … 1520 1518 self._manager.parent.get_save_location() 1521 1519 dlg = wx.FileDialog(self, "Choose a weight file", 1522 1523 1520 self._default_save_location, "", 1521 "*.*", wx.OPEN) 1524 1522 path = None 1525 1523 if dlg.ShowModal() == wx.ID_OK: … … 1587 1585 try: 1588 1586 is_modified = self._check_value_enter(self.fittable_param, 1589 is_modified)1587 is_modified) 1590 1588 is_modified = self._check_value_enter(self.fixed_param, 1591 1589 is_modified) … … 1593 1591 is_modified) 1594 1592 except: 1595 logging.error(sys.exc_ value)1593 logging.error(sys.exc_info()[1]) 1596 1594 1597 1595 # Here we should check whether the boundaries have been modified. … … 1659 1657 self._check_value_enter(self.parameters, is_modified) 1660 1658 1661 # If qmin and qmax have been modified, update qmin and qmax and 1659 # If qmin and qmax have been modified, update qmin and qmax and 1662 1660 # Here we should check whether the boundaries have been modified. 1663 # If qmin and qmax have been modified, update qmin and qmax and 1661 # If qmin and qmax have been modified, update qmin and qmax and 1664 1662 # set the is_modified flag to True 1665 1663 self.fitrange = self._validate_qrange(self.qmin, self.qmax) … … 1681 1679 flag = self.update_pinhole_smear() 1682 1680 else: 1681 enable_smearer = not self.disable_smearer.GetValue() 1683 1682 self._manager.set_smearer(smearer=temp_smearer, 1684 1683 uid=self.uid, … … 1686 1685 qmin=float(self.qmin_x), 1687 1686 qmax=float(self.qmax_x), 1688 enable_smearer=not self.disable_smearer.GetValue(),1689 1687 enable_smearer=enable_smearer, 1688 draw=False) 1690 1689 elif not self._is_2D(): 1691 1690 self._manager.set_smearer(smearer=temp_smearer, … … 1735 1734 self.save_current_state() 1736 1735 except: 1737 logging.error(sys.exc_ value)1736 logging.error(sys.exc_info()[1]) 1738 1737 1739 1738 return flag … … 1990 1989 # StatusEvent(status=msg, info="error")) 1991 1990 except: 1992 msg = "%s\n" % (sys.exc_ value)1991 msg = "%s\n" % (sys.exc_info()[1]) 1993 1992 wx.PostEvent(self._manager.parent, 1994 1993 StatusEvent(status=msg, info="error")) … … 1996 1995 1997 1996 def _on_modify_cat(self, event=None): 1997 """ 1998 Called when category manager is opened 1999 """ 1998 2000 self._manager.parent.on_category_panel(event) 1999 2001 … … 2059 2061 else: 2060 2062 tcrtl.SetBackgroundColour("pink") 2061 msg = "Model Error: wrong value entered: %s" % sys.exc_value 2063 msg = "Model Error: wrong value entered: %s" % \ 2064 sys.exc_info()[1] 2062 2065 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2063 2066 return 2064 2067 except: 2065 2068 tcrtl.SetBackgroundColour("pink") 2066 msg = "Model Error: wrong value entered: %s" % sys.exc_ value2069 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1] 2067 2070 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2068 2071 return … … 2116 2119 else: 2117 2120 tcrtl.SetBackgroundColour("pink") 2118 msg = "Model Error: wrong value entered: %s" % sys.exc_value 2121 msg = "Model Error: wrong value entered: %s" % \ 2122 sys.exc_info()[1] 2119 2123 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2120 2124 return 2121 2125 except: 2122 2126 tcrtl.SetBackgroundColour("pink") 2123 msg = "Model Error: wrong value entered: %s" % sys.exc_ value2127 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1] 2124 2128 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2125 2129 return … … 2551 2555 self.model.set_dispersion(p, disp_model) 2552 2556 except: 2553 logging.error(sys.exc_ value)2557 logging.error(sys.exc_info()[1]) 2554 2558 2555 2559 ## save state into … … 2764 2768 del self.state.model._persistency_dict[name.split('.')[0]] 2765 2769 except: 2766 logging.error(sys.exc_ value)2770 logging.error(sys.exc_info()[1]) 2767 2771 2768 2772 def _lay_out(self): … … 2910 2914 except: 2911 2915 # Not for control panels 2912 logging.error(sys.exc_ value)2916 logging.error(sys.exc_info()[1]) 2913 2917 # Make sure the resduals plot goes to the last 2914 2918 if res_item != None: … … 3226 3230 disfunc = str(item[7].GetValue()) 3227 3231 except: 3228 logging.error(sys.exc_ value)3232 logging.error(sys.exc_info()[1]) 3229 3233 3230 3234 # 2D … … 3261 3265 disfunc += ' ' + str(weight) 3262 3266 except: 3263 logging.error(sys.exc_ value)3267 logging.error(sys.exc_info()[1]) 3264 3268 content += name + ',' + str(check) + ',' + value + disfunc + ':' 3265 3269 … … 3462 3466 is_array = True 3463 3467 except: 3464 logging.error(sys.exc_ value)3468 logging.error(sys.exc_info()[1]) 3465 3469 if not is_array: 3466 3470 self._disp_obj_dict[name] = disp_model … … 3477 3481 3478 3482 except: 3479 logging.error(sys.exc_value) 3480 print "Error in BasePage._paste_poly_help: %s" % sys.exc_value 3483 logging.error(sys.exc_info()[1]) 3484 print "Error in BasePage._paste_poly_help: %s" % \ 3485 sys.exc_info()[1] 3481 3486 3482 3487 def _set_disp_array_cb(self, item): … … 3502 3507 return 3503 3508 3504 3505 3506 3507 3509 def _read_category_info(self): 3508 3510 """ 3509 3511 Reads the categories in from file 3510 3512 """ 3511 3512 3513 # # ILL mod starts here - July 2012 kieranrcampbell@gmail.com 3513 3514 self.master_category_dict = defaultdict(list) … … 3523 3524 self._regenerate_model_dict() 3524 3525 cat_file.close() 3525 3526 3526 except IOError: 3527 3527 raise … … 3536 3536 along with the enabled mapping 3537 3537 """ 3538 3539 3538 self.by_model_dict = defaultdict(list) 3540 3539 for category in self.master_category_dict: … … 3564 3563 self.categorybox.SetSelection(\ 3565 3564 self.categorybox.GetSelection()) 3566 3567 3565 #self._on_change_cat(None) 3568 3569 3566 3570 3567 def _on_change_cat(self, event): … … 3588 3585 if(enabled): 3589 3586 self.model_box.Append(model) 3590 3591 3592 3593 3587 3594 3588 def _fill_model_sizer(self, sizer): … … 3654 3648 3655 3649 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3656 3657 3658 3650 #sizer_radiobutton.Add(self.shape_rbutton) 3659 3651 #sizer_radiobutton.Add(self.shape_indep_rbutton)
Note: See TracChangeset
for help on using the changeset viewer.