Changeset 11a7e11 in sasview for sansview/perspectives/fitting/pagestate.py
- Timestamp:
- May 24, 2010 4:12:21 PM (14 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:
- 6c2d1a1
- Parents:
- 4d5fa8c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/pagestate.py
r5cc7001 r11a7e11 1 import time, os, sys 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 10 import time 11 import os 12 import sys 13 import copy 2 14 import logging 3 import DataLoader 15 4 16 from xml.dom.minidom import parse 5 17 from lxml import etree 6 18 7 8 import copy 9 19 import DataLoader 10 20 from DataLoader.readers.cansas_reader import Reader as CansasReader 11 21 from DataLoader.readers.cansas_reader import get_content 12 22 23 #Information to read/write state as xml 13 24 FITTING_NODE_NAME = 'fitting_plug_in' 14 25 CANSAS_NS = "cansas1d/1.0" … … 45 56 ["dq_r","dq_r", "string"]] 46 57 58 list_of_model_attributes = [["values", "values"], 59 ["weights", "weights"]] 60 47 61 list_of_state_parameters = [["parameters", "parameters"] , 48 62 ["orientation_parameters", "orientation_params"], … … 53 67 class PageState(object): 54 68 """ 55 Contains information to reconstruct a page of the fitpanel 69 Contains information to reconstruct a page of the fitpanel. 56 70 """ 57 71 def __init__(self, parent=None, model=None, data=None): … … 59 73 """ 60 74 Initialize the current state 75 @param model: a selected model within a page 76 @param data: 61 77 """ 62 78 self.file = None 79 #Time of state creation 80 self.timestamp = time.time() 63 81 ## Data member to store the dispersion object created 64 82 self._disp_obj_dict = {} … … 155 173 self.enable_disp = False 156 174 self.disable_disp = True 157 ## plot 2D data 158 self.enable2D = False 175 159 176 ## state of selected all check button 160 177 self.cb1 = False … … 234 251 def _repr_helper(self, list, rep): 235 252 """ 253 Helper method to print a state 236 254 """ 237 255 for item in list: … … 249 267 250 268 def __repr__(self): 251 """ output string for printing""" 252 rep = "\n\nState name: %s\n"%self.name 253 rep += "\n\nState form factor combobox selection: %s\n"%self.formfactorcombobox 254 rep += "\n\nState structure factor combobox selection: %s\n"%self.structurecombobox 255 rep += "\n\n is data : %s\n"%self.is_data 256 rep += "\n\n data's name : %s\n"%self.data_name 257 rep += "\n\n data's id : %s\n"%self.data_id 258 rep += "\n\n model type (form factor) selected: %s\n"%self.shape_rbutton 259 rep += "\n\n model type (shape independent) selected: %s\n "%self.shape_indep_rbutton 260 rep += "\n\n model type (structure factor) selected: %s\n"%self.struct_rbutton 261 rep += "\n\n model type (plug-in ) selected: %s\n"%self.plugin_rbutton 262 #rep +="data : %s\n"% str(self.data) 263 #rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin), 264 # str(self.qmax),str(self.npts)) 265 #rep +="model : %s\n\n"% str(self.model) 266 #rep +="number parameters(self.parameters): %s\n"%len(self.parameters) 267 #rep += self._repr_helper( list=self.parameters, rep=rep) 268 #rep +="number orientation parameters" 269 #rep +="(self.orientation_params): %s\n"%len(self.orientation_params) 270 #rep += self._repr_helper( list=self.orientation_params, rep=rep) 271 #rep +="number dispersity parameters" 272 #rep +="(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp) 273 #rep += self._repr_helper( list=self.orientation_params_disp, rep=rep) 274 269 """ 270 output string for printing 271 """ 272 rep = "\nState name: %s\n"%self.file 273 t = time.localtime(self.timestamp) 274 time_str = time.strftime("%b %d %H:%M", t) 275 rep += "State created on : %s\n"%time_str 276 rep += "State form factor combobox selection: %s\n"%self.formfactorcombobox 277 rep += "State structure factor combobox selection: %s\n"%self.structurecombobox 278 rep += "is data : %s\n"%self.is_data 279 rep += "data's name : %s\n"%self.data_name 280 rep += "data's id : %s\n"%self.data_id 281 rep += "model type (form factor) selected: %s\n"%self.shape_rbutton 282 rep += "model type (shape independent) selected: %s\n"%self.shape_indep_rbutton 283 rep += "model type (structure factor) selected: %s\n"%self.struct_rbutton 284 rep += "model type (plug-in ) selected: %s\n"%self.plugin_rbutton 285 rep += "data : %s\n"% str(self.data) 286 rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin), 287 str(self.qmax),str(self.npts)) 288 """ 289 rep += "model : %s\n\n"% str(self.model) 290 rep += "number parameters(self.parameters): %s\n"%len(self.parameters) 291 rep += self._repr_helper( list=self.parameters, rep=rep) 292 rep += "number orientation parameters" 293 rep += "(self.orientation_params): %s\n"%len(self.orientation_params) 294 rep += self._repr_helper( list=self.orientation_params, rep=rep) 295 rep += "number dispersity parameters" 296 rep += "(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp) 297 rep += self._repr_helper( list=self.orientation_params_disp, rep=rep) 298 """ 275 299 return rep 276 300 277 301 def _toXML_helper(self, list, element, newdoc): 278 302 """ 303 Helper method to create xml file for saving state 279 304 """ 280 305 for item in list: … … 292 317 element.appendChild(sub_element) 293 318 294 295 319 def toXML(self, file="fitting_state.fitv", doc=None, entry_node=None): 296 320 """ … … 333 357 element.appendChild(newdoc.createTextNode(str(file))) 334 358 top_element.appendChild(element) 335 359 360 element = newdoc.createElement("timestamp") 361 element.appendChild(newdoc.createTextNode(time.ctime(self.timestamp))) 362 attr = newdoc.createAttribute("epoch") 363 attr.nodeValue = str(self.timestamp) 364 element.setAttributeNode(attr) 365 top_element.appendChild(element) 336 366 # Inputs 337 367 inputs = newdoc.createElement("Attributes") … … 356 386 exec "element.setAttribute(item[0], str(self.%s))"%(item[1]) 357 387 inputs.appendChild(element) 358 388 389 for item in list_of_model_attributes: 390 element = newdoc.createElement(item[0]) 391 exec "list = self.%s"%item[1] 392 for item in list: 393 exec "element.appendChild(newdoc.createTextNode(str(%s)))" % item 394 inputs.appendChild(element) 395 359 396 for item in list_of_state_parameters: 360 397 element = newdoc.createElement(item[0]) … … 373 410 def _fromXML_helper(self, node, list): 374 411 """ 412 Helper function to write state to xml 375 413 """ 376 414 for item in node: … … 397 435 398 436 if file is not None: 399 raise RuntimeError, "PageState no longer supports non-CanSAS format for fitting files" 400 401 if node.get('version')\ 402 and node.get('version') == '1.0': 437 msg = "PageState no longer supports non-CanSAS" 438 msg += " format for fitting files" 439 raise RuntimeError, msg 440 441 if node.get('version')and node.get('version') == '1.0': 403 442 404 443 # Get file name … … 406 445 if entry is not None: 407 446 self.file = entry.text.strip() 408 447 448 # Get time stamp 449 entry = get_content('ns:timestamp', node) 450 if entry is not None and entry.get('epoch'): 451 try: 452 self.timestamp = float(entry.get('epoch')) 453 except: 454 msg = "PageState.fromXML: Could not" 455 msg += " read timestamp\n %s" % sys.exc_value 456 logging.error(msg) 457 409 458 # Parse fitting attributes 410 459 entry = get_content('ns:Attributes', node) … … 425 474 except: 426 475 exec "self.%s = None"%item[1] 427 476 for item in list_of_model_attributes: 477 node = get_content("ns:%s"%item[0], entry) 478 list = [] 479 for value in node: 480 try: 481 list.append(float(value)) 482 except: 483 list.append(None) 484 485 exec "self.%s = list"%item[1] 486 428 487 for item in list_of_state_parameters: 429 field= get_content("ns:%s"%item[0], entry)430 self._fromXML_helper(node= field, list=self.parameters)488 node = get_content("ns:%s"%item[0], entry) 489 self._fromXML_helper(node=node, list=self.parameters) 431 490 432 491 … … 725 784 # Call back to post the new state 726 785 state = output[0].meta_data['fitstate'] 786 t = time.localtime(state.timestamp) 787 time_str = time.strftime("%b %d %H:%M", t) 788 # Check that no time stamp is already appended 789 max_char = state.file.find("[") 790 if max_char < 0: 791 max_char = len(state.file) 792 state.file = state.file[0:max_char] +' [' + time_str + ']' 793 794 727 795 if state is not None and state.is_data is not None: 728 796 exec 'output[0].is_data = state.is_data' 729 797 730 output[0].filename = state.data_name 798 output[0].filename = state.file 799 #output[0].filename = state.data_name 731 800 state.data = output[0] 732 801 state.data.name = state.data_name 733 802 state.data.id = state.data_id 734 state.data.group_id = state.data_group_id 803 #state.data.group_id = state.data_group_id 804 state.data.group_id = output[0].filename 805 735 806 self.call_back(state=state, datainfo=output[0]) 736 807 return output[0] … … 773 844 state = PageState(parent=None) 774 845 state.toXML() 775 846 print "state", state
Note: See TracChangeset
for help on using the changeset viewer.