Changeset f32d144 in sasview for fittingview/src/sans/perspectives/fitting/pagestate.py
- Timestamp:
- Apr 27, 2012 2:20:33 PM (13 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:
- f992a06
- Parents:
- 9e07bc4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/pagestate.py
r14d2daa rf32d144 1 2 1 """ 2 Class that holds a fit page state 3 """ 3 4 ################################################################################ 4 5 #This software was developed by the University of Tennessee as part of the 5 6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 #project funded by the US National Science Foundation. 7 8 # 8 9 #See the license text in license.txt … … 10 11 #copyright 2009, University of Tennessee 11 12 ################################################################################ 12 13 13 import time 14 14 import os … … 43 43 ["shape_rbutton", "shape_rbutton", "bool"], 44 44 ["shape_indep_rbutton", "shape_indep_rbutton", "bool"], 45 ["plugin_rbutton", "plugin_rbutton", "bool"],45 ["plugin_rbutton", "plugin_rbutton", "bool"], 46 46 ["struct_rbutton", "struct_rbutton", "bool"], 47 47 ["formfactorcombobox", "formfactorcombobox", "string"], … … 69 69 ["weights", "weights"]] 70 70 71 list_of_obj_dic = 72 73 list_of_state_parameters = [["parameters", "parameters"] ,74 ["str_parameters", "str_parameters"] ,71 list_of_obj_dic = [["disp_obj_dict", "_disp_obj_dict", "string"]] 72 73 list_of_state_parameters = [["parameters", "parameters"], 74 ["str_parameters", "str_parameters"], 75 75 ["orientation_parameters", "orientation_params"], 76 76 ["dispersity_parameters", "orientation_params_disp"], 77 ["fixed_param", "fixed_param"], 78 ["fittable_param", "fittable_param"]]79 list_of_data_2d_attr = [["xmin", "xmin", "float"],80 ["xmax", "xmax","float"],81 ["ymin", "ymin","float"],82 ["ymax", "ymax","float"],83 ["_xaxis", "_xaxis", "string"],77 ["fixed_param", "fixed_param"], 78 ["fittable_param", "fittable_param"]] 79 list_of_data_2d_attr = [["xmin", "xmin", "float"], 80 ["xmax", "xmax", "float"], 81 ["ymin", "ymin", "float"], 82 ["ymax", "ymax", "float"], 83 ["_xaxis", "_xaxis", "string"], 84 84 ["_xunit", "_xunit", "string"], 85 ["_yaxis","_yaxis","string"], 86 ["_yunit","_yunit","string"], 87 ["_zaxis","_zaxis","string"], 88 ["_zunit","_zunit","string"]] 89 list_of_data2d_values = [["qx_data","qx_data","float"], 90 ["qy_data","qy_data","float"], 91 ["dqx_data","dqx_data","float"], 92 ["dqy_data","dqy_data","float"], 93 ["data","data","float"], 94 ["q_data","q_data","float"], 95 ["err_data","err_data","float"], 96 ["mask","mask","bool"]] 97 98 def parse_entry_helper( node, item): 85 ["_yaxis", "_yaxis", "string"], 86 ["_yunit", "_yunit", "string"], 87 ["_zaxis", "_zaxis", "string"], 88 ["_zunit", "_zunit", "string"]] 89 list_of_data2d_values = [["qx_data", "qx_data", "float"], 90 ["qy_data", "qy_data", "float"], 91 ["dqx_data", "dqx_data", "float"], 92 ["dqy_data", "dqy_data", "float"], 93 ["data", "data", "float"], 94 ["q_data", "q_data", "float"], 95 ["err_data", "err_data", "float"], 96 ["mask", "mask", "bool"]] 97 98 99 def parse_entry_helper(node, item): 99 100 """ 100 101 Create a numpy list from value extrated from the node … … 102 103 :param node: node from each the value is stored 103 104 :param item: list name of three strings.the two first are name of data 104 attribute and the third one is the type of the value of that 105 attribute and the third one is the type of the value of that 105 106 attribute. type can be string, float, bool, etc. 106 107 … … 128 129 """ 129 130 def __init__(self, parent=None, model=None, data=None): 130 131 """ 131 """ 132 132 Initialize the current state 133 133 134 134 :param model: a selected model within a page 135 :param data: 135 :param data: 136 136 137 137 """ … … 142 142 self._disp_obj_dict = {} 143 143 #------------------------ 144 #Data used for fitting 144 #Data used for fitting 145 145 self.data = data 146 146 # model data … … 175 175 #list of process done to model 176 176 self.process = [] 177 #fit page manager 177 #fit page manager 178 178 self.manager = None 179 179 #Store the parent of this panel parent 180 180 # For this application fitpanel is the parent 181 self.parent 181 self.parent = parent 182 182 # Event_owner is the owner of model event 183 183 self.event_owner = None … … 188 188 # String parameter list that can not be fitted 189 189 self.str_parameters = [] 190 # Contains list of parameters that cannot be fitted and reference to 191 #panel objects 190 # Contains list of parameters that cannot be fitted and reference to 191 #panel objects 192 192 self.fixed_param = [] 193 # Contains list of parameters with dispersity and reference to 194 #panel objects 193 # Contains list of parameters with dispersity and reference to 194 #panel objects 195 195 self.fittable_param = [] 196 196 ## orientation parameters … … 205 205 206 206 #list of dispersion paramaters 207 self.disp_list = []207 self.disp_list = [] 208 208 if self.model is not None: 209 209 self.disp_list = self.model.getDispParamList() … … 213 213 self.weights = {} 214 214 215 #contains link between a model and selected parameters to fit 215 #contains link between a model and selected parameters to fit 216 216 self.param_toFit = [] 217 217 ##dictionary of model type and model class … … 221 221 ## save selection of combobox 222 222 self.formfactorcombobox = None 223 self.structurecombobox 223 self.structurecombobox = None 224 224 225 225 ## radio box to select type of model … … 245 245 self.disable_smearer = True 246 246 self.pinhole_smearer = False 247 self.slit_smearer 247 self.slit_smearer = False 248 248 # weighting options 249 249 self.dI_noweight = False 250 250 self.dI_didata = True 251 251 self.dI_sqrdata = False 252 self.dI_idata 252 self.dI_idata = False 253 253 ## disperity selection 254 254 self.enable_disp = False … … 279 279 280 280 obj.formfactorcombobox = self.formfactorcombobox 281 obj.structurecombobox = self.structurecombobox282 283 obj.shape_rbutton = self.shape_rbutton 281 obj.structurecombobox = self.structurecombobox 282 283 obj.shape_rbutton = self.shape_rbutton 284 284 obj.shape_indep_rbutton = self.shape_indep_rbutton 285 285 obj.struct_rbutton = self.struct_rbutton … … 295 295 obj.fixed_param = copy.deepcopy(self.fixed_param) 296 296 obj.fittable_param = copy.deepcopy(self.fittable_param) 297 obj.orientation_params = 298 obj.orientation_params_disp = 297 obj.orientation_params = copy.deepcopy(self.orientation_params) 298 obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) 299 299 obj.enable_disp = copy.deepcopy(self.enable_disp) 300 300 obj.disable_disp = copy.deepcopy(self.disable_disp) 301 301 obj.tcChi = self.tcChi 302 302 303 if len(self._disp_obj_dict) >0:304 for k 305 obj._disp_obj_dict[k] = v306 if len(self.disp_cb_dict) >0:307 for k 308 obj.disp_cb_dict[k] = v309 if len(self.values) >0:310 for k , v in self.values.iteritems():303 if len(self._disp_obj_dict) > 0: 304 for k, v in self._disp_obj_dict.iteritems(): 305 obj._disp_obj_dict[k] = v 306 if len(self.disp_cb_dict) > 0: 307 for k, v in self.disp_cb_dict.iteritems(): 308 obj.disp_cb_dict[k] = v 309 if len(self.values) > 0: 310 for k, v in self.values.iteritems(): 311 311 obj.values[k] = v 312 if len(self.weights) >0:313 for k , v in self.weights.iteritems():312 if len(self.weights) > 0: 313 for k, v in self.weights.iteritems(): 314 314 obj.weights[k] = v 315 315 obj.enable_smearer = copy.deepcopy(self.enable_smearer) … … 329 329 obj.qmax = copy.deepcopy(self.qmax) 330 330 obj.multi_factor = self.multi_factor 331 obj.npts = copy.deepcopy(self.npts 331 obj.npts = copy.deepcopy(self.npts) 332 332 obj.cb1 = copy.deepcopy(self.cb1) 333 333 obj.smearer = copy.deepcopy(self.smearer) … … 336 336 copy_name = copy.deepcopy(name) 337 337 copy_state = state.clone() 338 obj.saved_states[copy_name] = copy_state338 obj.saved_states[copy_name] = copy_state 339 339 return obj 340 340 … … 344 344 """ 345 345 for item in list: 346 rep += "parameter name: %s \n" %str(item[1])347 rep += "value: %s\n" %str(item[2])348 rep += "selected: %s\n" %str(item[0])349 rep += "error displayed : %s \n" %str(item[4][0])350 rep += "error value:%s \n" %str(item[4][1])351 rep += "minimum displayed : %s \n" %str(item[5][0])352 rep += "minimum value : %s \n" %str(item[5][1])353 rep += "maximum displayed : %s \n" %str(item[6][0])354 rep += "maximum value : %s \n" %str(item[6][1])355 rep += "parameter unit: %s\n\n" %str(item[7])346 rep += "parameter name: %s \n" % str(item[1]) 347 rep += "value: %s\n" % str(item[2]) 348 rep += "selected: %s\n" % str(item[0]) 349 rep += "error displayed : %s \n" % str(item[4][0]) 350 rep += "error value:%s \n" % str(item[4][1]) 351 rep += "minimum displayed : %s \n" % str(item[5][0]) 352 rep += "minimum value : %s \n" % str(item[5][1]) 353 rep += "maximum displayed : %s \n" % str(item[6][0]) 354 rep += "maximum value : %s \n" % str(item[6][1]) 355 rep += "parameter unit: %s\n\n" % str(item[7]) 356 356 return rep 357 357 358 358 def __repr__(self): 359 """ 359 """ 360 360 output string for printing 361 361 """ 362 rep = "\nState name: %s\n" %self.file362 rep = "\nState name: %s\n" % self.file 363 363 t = time.localtime(self.timestamp) 364 364 time_str = time.strftime("%b %d %Y %H;%M;%S ", t) 365 365 366 rep += "State created: %s\n" %time_str367 rep += "State form factor combobox selection: %s\n" %self.formfactorcombobox368 rep += "State structure factor combobox selection: %s\n" %self.structurecombobox369 rep += "is data : %s\n" %self.is_data370 rep += "data's name : %s\n" %self.data_name371 rep += "data's id : %s\n" %self.data_id366 rep += "State created: %s\n" % time_str 367 rep += "State form factor combobox selection: %s\n" % self.formfactorcombobox 368 rep += "State structure factor combobox selection: %s\n" % self.structurecombobox 369 rep += "is data : %s\n" % self.is_data 370 rep += "data's name : %s\n" % self.data_name 371 rep += "data's id : %s\n" % self.data_id 372 372 if self.model != None: 373 373 m_name = self.model.__class__.__name__ 374 374 if m_name == 'Model': 375 375 m_name = self.m_name 376 rep += "model name : %s\n" % m_name376 rep += "model name : %s\n" % m_name 377 377 else: 378 378 rep += "model name : None\n" 379 rep += "model type (form factor) selected: %s\n"%self.shape_rbutton 380 rep += "multi_factor : %s\n"% str(self.multi_factor) 381 rep += "model type (shape independent) selected: %s\n"%self.shape_indep_rbutton 382 rep += "model type (structure factor) selected: %s\n"%self.struct_rbutton 383 rep += "model type (plug-in ) selected: %s\n"%self.plugin_rbutton 384 rep += "data : %s\n"% str(self.data) 385 rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin), 386 str(self.qmax),str(self.npts)) 387 rep += "Dispersion selection : %s\n"%str(self.disp_box) 388 rep += "Smearing enable : %s\n"%str(self.enable_smearer) 389 rep += "Smearing disable : %s\n"%str(self.disable_smearer) 390 rep += "Pinhole smearer enable : %s\n"%str(self.pinhole_smearer) 391 rep += "Slit smearer enable : %s\n"%str(self.slit_smearer) 392 rep += "Dispersity enable : %s\n"%str(self.enable_disp) 393 rep += "Dispersity disable : %s\n"%str(self.disable_disp) 394 rep += "Slit smearer enable: %s\n"%str(self.slit_smearer) 395 396 rep += "dI_noweight : %s\n"%str(self.dI_noweight) 397 rep += "dI_didata : %s\n"%str(self.dI_didata) 398 rep += "dI_sqrdata : %s\n"%str(self.dI_sqrdata) 399 rep += "dI_idata : %s\n"%str(self.dI_idata) 400 401 402 rep += "2D enable : %s\n"%str(self.enable2D) 403 rep += "All parameters checkbox selected: %s\n"%(self.cb1) 404 rep += "Value of Chisqr : %s\n"%str(self.tcChi) 405 rep += "Smear object : %s\n"%str(self.smearer) 406 rep += "Smear type : %s\n"%(self.smear_type) 407 rep += "dq_l : %s\n"%self.dq_l 408 rep += "dq_r : %s\n"%self.dq_r 409 410 rep += "model : %s\n\n"% str(self.model) 379 rep += "model type (form factor) selected: %s\n" % self.shape_rbutton 380 rep += "multi_factor : %s\n" % str(self.multi_factor) 381 rep += "model type (shape independent) selected: %s\n" % self.shape_indep_rbutton 382 rep += "model type (structure factor) selected: %s\n" % self.struct_rbutton 383 rep += "model type (plug-in ) selected: %s\n" % self.plugin_rbutton 384 rep += "data : %s\n" % str(self.data) 385 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % (str(self.qmin), 386 str(self.qmax), str(self.npts)) 387 rep += "Dispersion selection : %s\n" % str(self.disp_box) 388 rep += "Smearing enable : %s\n" % str(self.enable_smearer) 389 rep += "Smearing disable : %s\n" % str(self.disable_smearer) 390 rep += "Pinhole smearer enable : %s\n" % str(self.pinhole_smearer) 391 rep += "Slit smearer enable : %s\n" % str(self.slit_smearer) 392 rep += "Dispersity enable : %s\n" % str(self.enable_disp) 393 rep += "Dispersity disable : %s\n" % str(self.disable_disp) 394 rep += "Slit smearer enable: %s\n" % str(self.slit_smearer) 395 396 rep += "dI_noweight : %s\n" % str(self.dI_noweight) 397 rep += "dI_didata : %s\n" % str(self.dI_didata) 398 rep += "dI_sqrdata : %s\n" % str(self.dI_sqrdata) 399 rep += "dI_idata : %s\n" % str(self.dI_idata) 400 401 rep += "2D enable : %s\n" % str(self.enable2D) 402 rep += "All parameters checkbox selected: %s\n" % (self.cb1) 403 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 404 rep += "Smear object : %s\n" % str(self.smearer) 405 rep += "Smear type : %s\n" % (self.smear_type) 406 rep += "dq_l : %s\n" % self.dq_l 407 rep += "dq_r : %s\n" % self.dq_r 408 409 rep += "model : %s\n\n" % str(self.model) 411 410 temp_parameters = [] 412 411 temp_fittable_param = [] … … 427 426 temp_fittable_param = self.fittable_param 428 427 429 rep += "number parameters(self.parameters): %s\n" %len(temp_parameters)430 rep = self._repr_helper( 431 rep += "number str_parameters(self.str_parameters): %s\n" %len(self.str_parameters)432 rep = self._repr_helper( list=self.str_parameters, rep=rep)433 rep += "number fittable_param(self.fittable_param): %s\n" %len(temp_fittable_param)434 rep = self._repr_helper( list=temp_fittable_param, rep=rep)435 """ 428 rep += "number parameters(self.parameters): %s\n" % len(temp_parameters) 429 rep = self._repr_helper(list=temp_parameters, rep=rep) 430 rep += "number str_parameters(self.str_parameters): %s\n" % len(self.str_parameters) 431 rep = self._repr_helper(list=self.str_parameters, rep=rep) 432 rep += "number fittable_param(self.fittable_param): %s\n" % len(temp_fittable_param) 433 rep = self._repr_helper(list=temp_fittable_param, rep=rep) 434 """ 436 435 if is_2D: 437 436 rep += "number orientation parameters" … … 446 445 def set_report_string(self): 447 446 """ 448 Get the values (strings) from __str__ for report 447 Get the values (strings) from __str__ for report 449 448 """ 450 449 # Dictionary of teh report strings … … 487 486 param_string += value + ',' 488 487 if name == "parameter unit": 489 param_string += value + ':' 488 param_string += value + ':' 490 489 if name == "Value of Chisqr ": 491 490 chi2 = ("Chi2/Npts = " + value) … … 513 512 except: 514 513 modelname = "Model name:" + " NAN" 515 model_name = CENTRE % 514 model_name = CENTRE % modelname 516 515 517 516 if name == "Plotting Range": … … 524 523 pass 525 524 paramval = "" 526 for lines in param_string.split(":"): 525 for lines in param_string.split(":"): 527 526 line = lines.split(",") 528 if len(lines) > 0: 529 param = line[0] 527 if len(lines) > 0: 528 param = line[0] 530 529 param += " = " + line[1] 531 530 if len(line[2].split()) > 0 and not line[2].count("None"): … … 534 533 param += " " + line[3] 535 534 if not paramval.count(param): 536 paramval += 535 paramval += param + "\n" 537 536 paramval_string += CENTRE % param + "\n" 538 537 539 538 text_string = "\n\n\n" + title + "\n\n" + file + \ 540 541 542 "\n\n" + paramval539 "\n" + q_name + \ 540 "\n" + chi2 + \ 541 "\n\n" + paramval 543 542 544 543 title_name = self._check_html_format(title_name) … … 547 546 548 547 html_string = title_name + "\n" + file_name + \ 549 "\n" + model_name + \548 "\n" + model_name + \ 550 549 "\n" + q_range + \ 551 550 "\n" + chi2_string + \ … … 554 553 "\n" + ELINE + \ 555 554 "\n" + FEET_1 % title + \ 556 "\n" + FEET_2 555 "\n" + FEET_2 557 556 558 557 return html_string, text_string, title … … 566 565 567 566 return name 568 569 567 570 568 def report(self, figs=None, canvases=None): … … 579 577 # Allow 2 figures to append 580 578 if len(figs) == 1: 581 add_str = FEET_3 579 add_str = FEET_3 582 580 elif len(figs) == 2: 583 add_str = ELINE 584 add_str += FEET_2 % ("%s") 585 add_str += ELINE 586 add_str += FEET_3 581 add_str = ELINE 582 add_str += FEET_2 % ("%s") 583 add_str += ELINE 584 add_str += FEET_3 587 585 elif len(figs) > 2: 588 add_str = ELINE 589 add_str += FEET_2 % ("%s") 590 add_str += ELINE 591 add_str += FEET_2 % ("%s") 592 add_str += ELINE 593 add_str += FEET_3 586 add_str = ELINE 587 add_str += FEET_2 % ("%s") 588 add_str += ELINE 589 add_str += FEET_2 % ("%s") 590 add_str += ELINE 591 add_str += FEET_3 594 592 else: 595 593 add_str = "" … … 600 598 # make plot image 601 599 images = self.set_plot_state(figs, canvases) 602 report_list = [report_str, text_str, images 600 report_list = [report_str, text_str, images] 603 601 dialog = ReportDialog(report_list, None, -1, "") 604 602 dialog.ShowModal() 605 603 606 607 604 def _toXML_helper(self, list, element, newdoc): 608 605 """ … … 641 638 if doc is None: 642 639 impl = getDOMImplementation() 643 doc_type = impl.createDocumentType(FITTING_NODE_NAME, "1.0", "1.0") 640 doc_type = impl.createDocumentType(FITTING_NODE_NAME, "1.0", "1.0") 644 641 newdoc = impl.createDocument(None, FITTING_NODE_NAME, doc_type) 645 642 top_element = newdoc.documentElement … … 675 672 top_element.appendChild(inputs) 676 673 677 678 674 if self.data is not None and hasattr(self.data, "group_id"): 679 675 self.data_group_id = self.data.group_id … … 688 684 element = newdoc.createElement(item[0]) 689 685 exec "element.setAttribute(item[0], str(self.%s))" % (item[1]) 690 inputs.appendChild(element) 686 inputs.appendChild(element) 691 687 692 688 for item in list_of_state_attributes: … … 695 691 inputs.appendChild(element) 696 692 697 # For self.values ={ disp_param_name: [vals,...],...} 698 # and for self.weights ={ disp_param_name: [weights,...],...} 693 # For self.values ={ disp_param_name: [vals,...],...} 694 # and for self.weights ={ disp_param_name: [weights,...],...} 699 695 for item in list_of_model_attributes: 700 696 element = newdoc.createElement(item[0]) … … 708 704 exec com % val 709 705 710 element.appendChild(sub_element) 706 element.appendChild(sub_element) 711 707 inputs.appendChild(element) 712 708 713 709 # Create doc for the dictionary of self._disp_obj_dic 714 710 for item in list_of_obj_dic: 715 716 717 718 719 720 721 722 element.appendChild(sub_element)723 inputs.appendChild(element)711 element = newdoc.createElement(item[0]) 712 exec "list = self.%s" % item[1] 713 for key, val in list.iteritems(): 714 value = repr(val) 715 sub_element = newdoc.createElement(key) 716 sub_element.setAttribute('name', str(key)) 717 sub_element.setAttribute('value', str(value)) 718 element.appendChild(sub_element) 719 inputs.appendChild(element) 724 720 725 721 for item in list_of_state_parameters: … … 727 723 com = "self._toXML_helper(list=self.%s," 728 724 com += " element=element, newdoc=newdoc)" 729 exec com % item[1] 725 exec com % item[1] 730 726 inputs.appendChild(element) 731 727 … … 760 756 except: 761 757 error_displayed = None 762 try: 758 try: 763 759 error_value = item.get('error_value') 764 760 except: 765 761 error_value = None 766 762 try: 767 minimum_displayed = (item.get('minimum_displayed') == "True")763 minimum_displayed = (item.get('minimum_displayed') == "True") 768 764 except: 769 765 minimum_displayed = None … … 786 782 list.append([selected_to_fit, name, value, "+/-", 787 783 [error_displayed, error_value], 788 [minimum_displayed, minimum_value],789 [maximum_displayed, maximum_value], unit])784 [minimum_displayed, minimum_value], 785 [maximum_displayed, maximum_value], unit]) 790 786 791 787 def fromXML(self, file=None, node=None): … … 822 818 entry = get_content('ns:Attributes', node) 823 819 for item in list_of_data_attributes: 824 node = get_content('ns:%s' %item[0], entry)820 node = get_content('ns:%s' % item[0], entry) 825 821 try: 826 822 exec "self.%s = parse_entry_helper(node, item)" % item[0] … … 844 840 item[1] 845 841 846 # Recover _disp_obj_dict from xml file 847 self._disp_obj_dict = {} 842 # Recover _disp_obj_dict from xml file 843 self._disp_obj_dict = {} 848 844 for item in list_of_obj_dic: 849 845 # Get node … … 851 847 for attr in node: 852 848 name = attr.get('name') 853 val 849 val = attr.get('value') 854 850 value = val.split(" instance")[0] 855 851 disp_name = value.split("<")[1] 856 852 try: 857 853 # Try to recover disp_model object from strings 858 com 854 com = "from sans.models.dispersion_models " 859 855 com += "import %s as disp" 860 856 com_name = disp_name.split(".")[3] … … 865 861 pass 866 862 867 # get self.values and self.weights dic. if exists 863 # get self.values and self.weights dic. if exists 868 864 for item in list_of_model_attributes: 869 865 node = get_content("ns:%s" % item[0], entry) … … 876 872 for line in values: 877 873 try: 878 val = float(line)879 list.append(val) 874 val = float(line) 875 list.append(val) 880 876 except: 881 877 # pass if line is empty (it happens) … … 902 898 figs = [None] 903 899 904 # Loop over the list of figures 900 # Loop over the list of figures 905 901 # use wx.MemoryFSHandler 906 self.imgRAM = wx.MemoryFSHandler() 902 self.imgRAM = wx.MemoryFSHandler() 907 903 for fig in figs: 908 904 if figs != None: 909 #fig.set_facecolor('w')910 905 ind = figs.index(fig) 911 906 canvas = canvases[ind] 912 907 913 #bmp = wx.BitmapDataObject()914 #bmp.SetBitmap(canvas.bitmap)915 908 #store the image in wx.FileSystem Object 916 909 wx.FileSystem.AddHandler(wx.MemoryFSHandler()) … … 920 913 921 914 #AddFile, image can be retrieved with 'memory:filename' 922 self.imgRAM.AddFile('img_fit%s.png' % ind ,915 self.imgRAM.AddFile('img_fit%s.png' % ind, 923 916 canvas.bitmap, wx.BITMAP_TYPE_PNG) 924 917 … … 927 920 928 921 return images 922 929 923 930 924 class Reader(CansasReader): … … 939 933 "SANSView file (*.svs)|*.svs"] 940 934 ## List of allowed extensions 941 ext =['.fitv', '.FITV', '.svs', 'SVS']935 ext = ['.fitv', '.FITV', '.svs', 'SVS'] 942 936 943 937 def __init__(self, call_back=None, cansas=True): … … 957 951 self.cansas = cansas 958 952 self.state = None 953 959 954 def get_state(self): 960 955 return self.state 961 956 962 957 def read(self, path): 963 """ 958 """ 964 959 Load a new P(r) inversion state from file 965 960 … … 1005 1000 for item in list_of_data_2d_attr: 1006 1001 element = doc.createElement(item[0]) 1007 exec "element.setAttribute(item[0], str(datainfo.%s))" %(item[1])1002 exec "element.setAttribute(item[0], str(datainfo.%s))" % (item[1]) 1008 1003 new_node.appendChild(element) 1009 1004 … … 1012 1007 new_node.appendChild(root_node) 1013 1008 1014 exec "temp_list = datainfo.%s" %item[1]1009 exec "temp_list = datainfo.%s" % item[1] 1015 1010 1016 1011 if temp_list is None or len(temp_list)== 0: 1017 1012 element = doc.createElement(item[0]) 1018 exec "element.appendChild(doc.createTextNode(str(%s)))" %temp_list1013 exec "element.appendChild(doc.createTextNode(str(%s)))" % temp_list 1019 1014 root_node.appendChild(element) 1020 1015 else: 1021 1016 for value in temp_list: 1022 1017 element = doc.createElement(item[0]) 1023 exec "element.setAttribute(item[0], str(%s))" %value1018 exec "element.setAttribute(item[0], str(%s))" % value 1024 1019 root_node.appendChild(element) 1025 1020 … … 1030 1025 entry_node.appendChild(sample) 1031 1026 write_node(doc, sample, "ID", str(datainfo.sample.ID)) 1032 write_node(doc, sample, "thickness", datainfo.sample.thickness, {"unit":datainfo.sample.thickness_unit}) 1027 write_node(doc, sample, "thickness", datainfo.sample.thickness, 1028 {"unit": datainfo.sample.thickness_unit}) 1033 1029 write_node(doc, sample, "transmission", datainfo.sample.transmission) 1034 write_node(doc, sample, "temperature", datainfo.sample.temperature, {"unit":datainfo.sample.temperature_unit}) 1030 write_node(doc, sample, "temperature", datainfo.sample.temperature, 1031 {"unit": datainfo.sample.temperature_unit}) 1035 1032 1036 1033 for item in datainfo.sample.details: … … 1038 1035 1039 1036 pos = doc.createElement("position") 1040 written = write_node(doc, pos, "x", datainfo.sample.position.x, {"unit":datainfo.sample.position_unit}) 1041 written = written | write_node(doc, pos, "y", datainfo.sample.position.y, {"unit":datainfo.sample.position_unit}) 1042 written = written | write_node(doc, pos, "z", datainfo.sample.position.z, {"unit":datainfo.sample.position_unit}) 1037 written = write_node(doc, pos, "x", datainfo.sample.position.x, 1038 {"unit": datainfo.sample.position_unit}) 1039 written = written | write_node(doc, pos, "y", 1040 datainfo.sample.position.y, 1041 {"unit": datainfo.sample.position_unit}) 1042 written = written | write_node(doc, pos, "z", 1043 datainfo.sample.position.z, 1044 {"unit": datainfo.sample.position_unit}) 1043 1045 if written == True: 1044 1046 sample.appendChild(pos) 1045 1047 1046 1048 ori = doc.createElement("orientation") 1047 written = write_node(doc, ori, "roll", datainfo.sample.orientation.x, {"unit":datainfo.sample.orientation_unit}) 1048 written = written | write_node(doc, ori, "pitch", datainfo.sample.orientation.y, {"unit":datainfo.sample.orientation_unit}) 1049 written = written | write_node(doc, ori, "yaw", datainfo.sample.orientation.z, {"unit":datainfo.sample.orientation_unit}) 1049 written = write_node(doc, ori, "roll", datainfo.sample.orientation.x, 1050 {"unit": datainfo.sample.orientation_unit}) 1051 written = written | write_node(doc, ori, "pitch", 1052 datainfo.sample.orientation.y, 1053 {"unit": datainfo.sample.orientation_unit}) 1054 written = written | write_node(doc, ori, "yaw", 1055 datainfo.sample.orientation.z, 1056 {"unit": datainfo.sample.orientation_unit}) 1050 1057 if written == True: 1051 1058 sample.appendChild(ori) … … 1068 1075 if datainfo.source.beam_size_name is not None: 1069 1076 size.setAttribute("name", str(datainfo.source.beam_size_name)) 1070 written = write_node(doc, size, "x", datainfo.source.beam_size.x, {"unit":datainfo.source.beam_size_unit}) 1071 written = written | write_node(doc, size, "y", datainfo.source.beam_size.y, {"unit":datainfo.source.beam_size_unit}) 1072 written = written | write_node(doc, size, "z", datainfo.source.beam_size.z, {"unit":datainfo.source.beam_size_unit}) 1077 written = write_node(doc, size, "x", datainfo.source.beam_size.x, 1078 {"unit": datainfo.source.beam_size_unit}) 1079 written = written | write_node(doc, size, "y", 1080 datainfo.source.beam_size.y, 1081 {"unit": datainfo.source.beam_size_unit}) 1082 written = written | write_node(doc, size, "z", 1083 datainfo.source.beam_size.z, 1084 {"unit": datainfo.source.beam_size_unit}) 1073 1085 if written == True: 1074 1086 source.appendChild(size) 1075 1087 1076 write_node(doc, source, "wavelength", datainfo.source.wavelength, {"unit":datainfo.source.wavelength_unit}) 1077 write_node(doc, source, "wavelength_min", datainfo.source.wavelength_min, {"unit":datainfo.source.wavelength_min_unit}) 1078 write_node(doc, source, "wavelength_max", datainfo.source.wavelength_max, {"unit":datainfo.source.wavelength_max_unit}) 1079 write_node(doc, source, "wavelength_spread", datainfo.source.wavelength_spread, {"unit":datainfo.source.wavelength_spread_unit}) 1088 write_node(doc, source, "wavelength", datainfo.source.wavelength, 1089 {"unit": datainfo.source.wavelength_unit}) 1090 write_node(doc, source, "wavelength_min", 1091 datainfo.source.wavelength_min, 1092 {"unit": datainfo.source.wavelength_min_unit}) 1093 write_node(doc, source, "wavelength_max", 1094 datainfo.source.wavelength_max, 1095 {"unit": datainfo.source.wavelength_max_unit}) 1096 write_node(doc, source, "wavelength_spread", 1097 datainfo.source.wavelength_spread, 1098 {"unit": datainfo.source.wavelength_spread_unit}) 1080 1099 1081 1100 # Collimation … … 1086 1105 instr.appendChild(coll) 1087 1106 1088 write_node(doc, coll, "length", item.length, {"unit":item.length_unit}) 1107 write_node(doc, coll, "length", item.length, 1108 {"unit": item.length_unit}) 1089 1109 1090 1110 for apert in item.aperture: … … 1096 1116 coll.appendChild(ap) 1097 1117 1098 write_node(doc, ap, "distance", apert.distance, {"unit":apert.distance_unit}) 1118 write_node(doc, ap, "distance", apert.distance, 1119 {"unit": apert.distance_unit}) 1099 1120 1100 1121 size = doc.createElement("size") 1101 1122 if apert.size_name is not None: 1102 1123 size.setAttribute("name", str(apert.size_name)) 1103 written = write_node(doc, size, "x", apert.size.x, {"unit":apert.size_unit}) 1104 written = written | write_node(doc, size, "y", apert.size.y, {"unit":apert.size_unit}) 1105 written = written | write_node(doc, size, "z", apert.size.z, {"unit":apert.size_unit}) 1124 written = write_node(doc, size, "x", apert.size.x, 1125 {"unit": apert.size_unit}) 1126 written = written | write_node(doc, size, "y", apert.size.y, 1127 {"unit": apert.size_unit}) 1128 written = written | write_node(doc, size, "z", apert.size.z, 1129 {"unit": apert.size_unit}) 1106 1130 if written == True: 1107 1131 ap.appendChild(size) … … 1111 1135 det = doc.createElement("SASdetector") 1112 1136 written = write_node(doc, det, "name", item.name) 1113 written = written | write_node(doc, det, "SDD", item.distance, {"unit":item.distance_unit}) 1114 written = written | write_node(doc, det, "slit_length", item.slit_length, {"unit":item.slit_length_unit}) 1137 written = written | write_node(doc, det, "SDD", item.distance, 1138 {"unit": item.distance_unit}) 1139 written = written | write_node(doc, det, "slit_length", 1140 item.slit_length, 1141 {"unit": item.slit_length_unit}) 1115 1142 if written == True: 1116 1143 instr.appendChild(det) 1117 1144 1118 1145 off = doc.createElement("offset") 1119 written = write_node(doc, off, "x", item.offset.x, {"unit":item.offset_unit}) 1120 written = written | write_node(doc, off, "y", item.offset.y, {"unit":item.offset_unit}) 1121 written = written | write_node(doc, off, "z", item.offset.z, {"unit":item.offset_unit}) 1146 written = write_node(doc, off, "x", item.offset.x, 1147 {"unit": item.offset_unit}) 1148 written = written | write_node(doc, off, "y", item.offset.y, 1149 {"unit": item.offset_unit}) 1150 written = written | write_node(doc, off, "z", item.offset.z, 1151 {"unit": item.offset_unit}) 1122 1152 if written == True: 1123 1153 det.appendChild(off) 1124 1154 1125 1155 center = doc.createElement("beam_center") 1126 written = write_node(doc, center, "x", item.beam_center.x, {"unit":item.beam_center_unit}) 1127 written = written | write_node(doc, center, "y", item.beam_center.y, {"unit":item.beam_center_unit}) 1128 written = written | write_node(doc, center, "z", item.beam_center.z, {"unit":item.beam_center_unit}) 1156 written = write_node(doc, center, "x", item.beam_center.x, 1157 {"unit": item.beam_center_unit}) 1158 written = written | write_node(doc, center, "y", 1159 item.beam_center.y, 1160 {"unit": item.beam_center_unit}) 1161 written = written | write_node(doc, center, "z", 1162 item.beam_center.z, 1163 {"unit": item.beam_center_unit}) 1129 1164 if written == True: 1130 1165 det.appendChild(center) 1131 1166 1132 1167 pix = doc.createElement("pixel_size") 1133 written = write_node(doc, pix, "x", item.pixel_size.x, {"unit":item.pixel_size_unit}) 1134 written = written | write_node(doc, pix, "y", item.pixel_size.y, {"unit":item.pixel_size_unit}) 1135 written = written | write_node(doc, pix, "z", item.pixel_size.z, {"unit":item.pixel_size_unit}) 1168 written = write_node(doc, pix, "x", item.pixel_size.x, 1169 {"unit": item.pixel_size_unit}) 1170 written = written | write_node(doc, pix, "y", item.pixel_size.y, 1171 {"unit": item.pixel_size_unit}) 1172 written = written | write_node(doc, pix, "z", item.pixel_size.z, 1173 {"unit": item.pixel_size_unit}) 1136 1174 if written == True: 1137 1175 det.appendChild(pix) 1138 1176 1139 1177 ori = doc.createElement("orientation") 1140 written = write_node(doc, ori, "roll", item.orientation.x, {"unit":item.orientation_unit}) 1141 written = written | write_node(doc, ori, "pitch", item.orientation.y, {"unit":item.orientation_unit}) 1142 written = written | write_node(doc, ori, "yaw", item.orientation.z, {"unit":item.orientation_unit}) 1178 written = write_node(doc, ori, "roll", item.orientation.x, 1179 {"unit": item.orientation_unit}) 1180 written = written | write_node(doc, ori, "pitch", 1181 item.orientation.y, 1182 {"unit": item.orientation_unit}) 1183 written = written | write_node(doc, ori, "yaw", item.orientation.z, 1184 {"unit": item.orientation_unit}) 1143 1185 if written == True: 1144 1186 det.appendChild(ori) … … 1166 1208 Read a fit result from an XML node 1167 1209 1168 :param entry: XML node to read from 1210 :param entry: XML node to read from 1169 1211 1170 1212 :return: PageState object … … 1174 1216 # Locate the P(r) node 1175 1217 try: 1176 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, namespaces={'ns': CANSAS_NS}) 1177 if nodes !=[]: 1218 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1219 namespaces={'ns': CANSAS_NS}) 1220 if nodes != []: 1178 1221 # Create an empty state 1179 state = 1222 state = PageState() 1180 1223 state.fromXML(node=nodes[0]) 1181 1224 except: … … 1183 1226 1184 1227 return state 1185 1186 1187 1228 1188 1229 def _parse_entry(self, dom): 1189 1230 """ … … 1202 1243 data_info = Data2D() 1203 1244 1204 # Look up title 1245 # Look up title 1205 1246 self._store_content('ns:Title', dom, 'title', data_info) 1206 1247 1207 # Look up run number 1248 # Look up run number 1208 1249 nodes = dom.xpath('ns:Run', namespaces={'ns': CANSAS_NS}) 1209 for item in nodes: 1250 for item in nodes: 1210 1251 if item.text is not None: 1211 1252 value = item.text.strip() … … 1215 1256 data_info.run_name[value] = item.get('name') 1216 1257 1217 # Look up instrument name 1218 self._store_content('ns:SASinstrument/ns:name', dom, 'instrument', data_info) 1258 # Look up instrument name 1259 self._store_content('ns:SASinstrument/ns:name', dom, 1260 'instrument', data_info) 1219 1261 1220 1262 # Notes … … 1236 1278 data_info.sample.name = entry.get('name') 1237 1279 1238 self._store_content('ns:SASsample/ns:ID', 1239 dom, 'ID', data_info.sample) 1240 self._store_float('ns:SASsample/ns:thickness', 1280 self._store_content('ns:SASsample/ns:ID', 1281 dom, 'ID', data_info.sample) 1282 self._store_float('ns:SASsample/ns:thickness', 1241 1283 dom, 'thickness', data_info.sample) 1242 self._store_float('ns:SASsample/ns:transmission', 1284 self._store_float('ns:SASsample/ns:transmission', 1243 1285 dom, 'transmission', data_info.sample) 1244 self._store_float('ns:SASsample/ns:temperature', 1286 self._store_float('ns:SASsample/ns:temperature', 1245 1287 dom, 'temperature', data_info.sample) 1246 1288 1247 nodes = dom.xpath('ns:SASsample/ns:details', namespaces={'ns': CANSAS_NS}) 1289 nodes = dom.xpath('ns:SASsample/ns:details', 1290 namespaces={'ns': CANSAS_NS}) 1248 1291 for item in nodes: 1249 1292 try: … … 1258 1301 1259 1302 # Position (as a vector) 1260 self._store_float('ns:SASsample/ns:position/ns:x', 1261 dom, 'position.x', data_info.sample) 1262 self._store_float('ns:SASsample/ns:position/ns:y', 1263 dom, 'position.y', data_info.sample) 1264 self._store_float('ns:SASsample/ns:position/ns:z', 1265 dom, 'position.z', data_info.sample) 1303 self._store_float('ns:SASsample/ns:position/ns:x', 1304 dom, 'position.x', data_info.sample) 1305 self._store_float('ns:SASsample/ns:position/ns:y', 1306 dom, 'position.y', data_info.sample) 1307 self._store_float('ns:SASsample/ns:position/ns:z', 1308 dom, 'position.z', data_info.sample) 1266 1309 1267 1310 # Orientation (as a vector) 1268 self._store_float('ns:SASsample/ns:orientation/ns:roll', 1269 dom, 'orientation.x', data_info.sample) 1270 self._store_float('ns:SASsample/ns:orientation/ns:pitch', 1271 dom, 'orientation.y', data_info.sample) 1272 self._store_float('ns:SASsample/ns:orientation/ns:yaw', 1273 dom, 'orientation.z', data_info.sample) 1311 self._store_float('ns:SASsample/ns:orientation/ns:roll', 1312 dom, 'orientation.x', data_info.sample) 1313 self._store_float('ns:SASsample/ns:orientation/ns:pitch', 1314 dom, 'orientation.y', data_info.sample) 1315 self._store_float('ns:SASsample/ns:orientation/ns:yaw', 1316 dom, 'orientation.z', data_info.sample) 1274 1317 1275 1318 # Source info ################### … … 1278 1321 data_info.source.name = entry.get('name') 1279 1322 1280 self._store_content('ns:SASinstrument/ns:SASsource/ns:radiation', 1281 dom, 'radiation', data_info.source) 1282 self._store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape', 1283 dom, 'beam_shape', data_info.source) 1284 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength', 1285 dom, 'wavelength', data_info.source) 1286 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min', 1287 dom, 'wavelength_min', data_info.source) 1288 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max', 1289 dom, 'wavelength_max', data_info.source) 1290 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread', 1291 dom, 'wavelength_spread', data_info.source) 1292 1293 # Beam size (as a vector) 1323 self._store_content('ns:SASinstrument/ns:SASsource/ns:radiation', 1324 dom, 'radiation', data_info.source) 1325 self._store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape', 1326 dom, 'beam_shape', data_info.source) 1327 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength', 1328 dom, 'wavelength', data_info.source) 1329 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min', 1330 dom, 'wavelength_min', data_info.source) 1331 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max', 1332 dom, 'wavelength_max', data_info.source) 1333 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread', 1334 dom, 'wavelength_spread', data_info.source) 1335 1336 # Beam size (as a vector) 1294 1337 entry = get_content('ns:SASinstrument/ns:SASsource/ns:beam_size', dom) 1295 1338 if entry is not None: 1296 1339 data_info.source.beam_size_name = entry.get('name') 1297 1340 1298 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x', 1299 dom, 'beam_size.x', data_info.source) 1300 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y', 1301 dom, 'beam_size.y', data_info.source) 1302 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z', 1303 dom, 'beam_size.z', data_info.source) 1341 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x', 1342 dom, 'beam_size.x', data_info.source) 1343 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y', 1344 dom, 'beam_size.y', data_info.source) 1345 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z', 1346 dom, 'beam_size.z', data_info.source) 1304 1347 1305 1348 # Collimation info ################### 1306 nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation', namespaces={'ns': CANSAS_NS}) 1349 nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation', 1350 namespaces={'ns': CANSAS_NS}) 1307 1351 for item in nodes: 1308 1352 collim = Collimation() 1309 1353 if item.get('name') is not None: 1310 1354 collim.name = item.get('name') 1311 self._store_float('ns:length', item, 'length', collim) 1355 self._store_float('ns:length', item, 'length', collim) 1312 1356 1313 1357 # Look for apertures 1314 apert_list = item.xpath('ns:aperture', namespaces={'ns': CANSAS_NS}) 1358 apert_list = item.xpath('ns:aperture', 1359 namespaces={'ns': CANSAS_NS}) 1315 1360 for apert in apert_list: 1316 aperture = 1361 aperture = Aperture() 1317 1362 1318 1363 # Get the name and type of the aperture … … 1320 1365 aperture.type = apert.get('type') 1321 1366 1322 self._store_float('ns:distance', apert, 'distance', aperture) 1367 self._store_float('ns:distance', apert, 'distance', aperture) 1323 1368 1324 1369 entry = get_content('ns:size', apert) … … 1326 1371 aperture.size_name = entry.get('name') 1327 1372 1328 self._store_float('ns:size/ns:x', apert, 'size.x', aperture) 1329 self._store_float('ns:size/ns:y', apert, 'size.y', aperture) 1373 self._store_float('ns:size/ns:x', apert, 'size.x', aperture) 1374 self._store_float('ns:size/ns:y', apert, 'size.y', aperture) 1330 1375 self._store_float('ns:size/ns:z', apert, 'size.z', aperture) 1331 1376 … … 1335 1380 1336 1381 # Detector info ###################### 1337 nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', namespaces={'ns': CANSAS_NS}) 1382 nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', 1383 namespaces={'ns': CANSAS_NS}) 1338 1384 for item in nodes: 1339 1385 … … 1341 1387 1342 1388 self._store_content('ns:name', item, 'name', detector) 1343 self._store_float('ns:SDD', item, 'distance', detector) 1389 self._store_float('ns:SDD', item, 'distance', detector) 1344 1390 1345 1391 # Detector offset (as a vector) 1346 self._store_float('ns:offset/ns:x', item, 'offset.x', detector) 1347 self._store_float('ns:offset/ns:y', item, 'offset.y', detector) 1348 self._store_float('ns:offset/ns:z', item, 'offset.z', detector) 1392 self._store_float('ns:offset/ns:x', item, 'offset.x', detector) 1393 self._store_float('ns:offset/ns:y', item, 'offset.y', detector) 1394 self._store_float('ns:offset/ns:z', item, 'offset.z', detector) 1349 1395 1350 1396 # Detector orientation (as a vector) 1351 self._store_float('ns:orientation/ns:roll', item, 'orientation.x', detector) 1352 self._store_float('ns:orientation/ns:pitch', item, 'orientation.y', detector) 1353 self._store_float('ns:orientation/ns:yaw', item, 'orientation.z', detector) 1397 self._store_float('ns:orientation/ns:roll', item, 1398 'orientation.x', detector) 1399 self._store_float('ns:orientation/ns:pitch', item, 1400 'orientation.y', detector) 1401 self._store_float('ns:orientation/ns:yaw', item, 1402 'orientation.z', detector) 1354 1403 1355 1404 # Beam center (as a vector) 1356 self._store_float('ns:beam_center/ns:x', item, 'beam_center.x', detector) 1357 self._store_float('ns:beam_center/ns:y', item, 'beam_center.y', detector) 1358 self._store_float('ns:beam_center/ns:z', item, 'beam_center.z', detector) 1405 self._store_float('ns:beam_center/ns:x', item, 1406 'beam_center.x', detector) 1407 self._store_float('ns:beam_center/ns:y', item, 1408 'beam_center.y', detector) 1409 self._store_float('ns:beam_center/ns:z', item, 1410 'beam_center.z', detector) 1359 1411 1360 1412 # Pixel size (as a vector) 1361 self._store_float('ns:pixel_size/ns:x', item, 'pixel_size.x', detector) 1362 self._store_float('ns:pixel_size/ns:y', item, 'pixel_size.y', detector) 1363 self._store_float('ns:pixel_size/ns:z', item, 'pixel_size.z', detector) 1413 self._store_float('ns:pixel_size/ns:x', item, 1414 'pixel_size.x', detector) 1415 self._store_float('ns:pixel_size/ns:y', item, 1416 'pixel_size.y', detector) 1417 self._store_float('ns:pixel_size/ns:z', item, 1418 'pixel_size.z', detector) 1364 1419 1365 1420 self._store_float('ns:slit_length', item, 'slit_length', detector) 1366 1421 1367 data_info.detector.append(detector) 1422 data_info.detector.append(detector) 1368 1423 1369 1424 # Processes info ###################### … … 1389 1444 logging.error(err_mess) 1390 1445 1391 note_list = item.xpath('ns:SASprocessnote', namespaces={'ns': CANSAS_NS}) 1446 note_list = item.xpath('ns:SASprocessnote', 1447 namespaces={'ns': CANSAS_NS}) 1392 1448 for note in note_list: 1393 1449 if note.text is not None: … … 1396 1452 data_info.process.append(process) 1397 1453 1398 1399 1454 # Data info ###################### 1400 1455 nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 1401 if len(nodes) >1:1456 if len(nodes) > 1: 1402 1457 raise RuntimeError, "CanSAS reader is not compatible with multiple SASdata entries" 1403 1458 … … 1405 1460 for item in list_of_data_2d_attr: 1406 1461 #get node 1407 node = get_content('ns:%s' %item[0], entry)1408 exec "data_info.%s = parse_entry_helper(node, item)" %(item[1])1462 node = get_content('ns:%s' % item[0], entry) 1463 exec "data_info.%s = parse_entry_helper(node, item)" % item[1] 1409 1464 1410 1465 for item in list_of_data2d_values: 1411 field = get_content('ns:%s' %item[0], entry)1466 field = get_content('ns:%s' % item[0], entry) 1412 1467 list = [] 1413 1468 if field is not None: 1414 1469 list = [parse_entry_helper(node, item) for node in field] 1415 exec "data_info.%s = numpy.array(list)" %item[0]1470 exec "data_info.%s = numpy.array(list)" % item[0] 1416 1471 1417 1472 return data_info 1418 1473 1419 1474 def _read_cansas(self, path): 1420 """ 1475 """ 1421 1476 Load data and P(r) information from a CanSAS XML file. 1422 1477 1423 1478 :param path: file path 1424 1479 1425 :return: Data1D object if a single SASentry was found, 1480 :return: Data1D object if a single SASentry was found, 1426 1481 or a list of Data1D objects if multiple entries were found, 1427 1482 or None of nothing was found … … 1432 1487 """ 1433 1488 output = [] 1434 basename 1489 basename = os.path.basename(path) 1435 1490 root, extension = os.path.splitext(basename) 1436 1491 ext = extension.lower() … … 1445 1500 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 1446 1501 # Check the format version number 1447 # Specifying the namespace will take care of the file format version 1502 # Specifying the namespace will take care of the file format version 1448 1503 root = tree.getroot() 1449 entry_list = root.xpath('ns:SASentry', namespaces={'ns': CANSAS_NS}) 1450 for entry in entry_list: 1504 entry_list = root.xpath('ns:SASentry', 1505 namespaces={'ns': CANSAS_NS}) 1506 for entry in entry_list: 1451 1507 try: 1452 1508 sas_entry = self._parse_entry(entry) … … 1466 1522 1467 1523 # Return output consistent with the loader's api 1468 if len(output) ==0:1469 self.call_back(state=None, datainfo=None, format=ext)1524 if len(output) == 0: 1525 self.call_back(state=None, datainfo=None, format=ext) 1470 1526 return None 1471 1527 else: … … 1480 1536 max_char = len(state.file) 1481 1537 original_fname = state.file[0:max_char] 1482 state.file = original_fname +' [' + time_str + ']' 1483 1484 1538 state.file = original_fname + ' [' + time_str + ']' 1539 1485 1540 if state is not None and state.is_data is not None: 1486 exec 'output[%d].is_data = state.is_data' % ind1541 exec 'output[%d].is_data = state.is_data' % ind 1487 1542 1488 1543 output[ind].filename = state.file 1489 1544 state.data = output[ind] 1490 state.data.name = output[ind].filename #state.data_name1545 state.data.name = output[ind].filename # state.data_name 1491 1546 state.data.id = state.data_id 1492 1547 if state.is_data is not None: 1493 1548 state.data.is_data = state.is_data 1494 if output[ind].run_name is not None and len(output[ind].run_name) != 0 : 1549 if output[ind].run_name is not None\ 1550 and len(output[ind].run_name) != 0: 1495 1551 name = output[ind].run_name 1496 else: 1497 name =original_fname1552 else: 1553 name = original_fname 1498 1554 state.data.group_id = name 1499 1555 #store state in fitting 1500 self.call_back(state=state, datainfo=output[ind],format=ext) 1501 self.state= state 1556 self.call_back(state=state, 1557 datainfo=output[ind], format=ext) 1558 self.state = state 1502 1559 return output 1503 1560 … … 1530 1587 def write_toXML(self, datainfo=None, state=None): 1531 1588 """ 1532 Write toXML, a helper for write() , could be used by guimanager._on_save() 1589 Write toXML, a helper for write(), 1590 could be used by guimanager._on_save() 1533 1591 1534 1592 : return: xml doc … … 1536 1594 1537 1595 if state.data is None: 1538 data = sans.dataloader.data_info.Data1D(x=[], y=[]) 1539 else: 1596 data = sans.dataloader.data_info.Data1D(x=[], y=[]) 1597 else: 1540 1598 #make sure title and data run is filled up. 1541 if state.data.title == None or state.data.title=='': state.data.title = state.data.name 1542 if state.data.run_name == None or state.data.run_name=={}: 1599 if state.data.title == None or state.data.title == '': 1600 state.data.title = state.data.name 1601 if state.data.run_name == None or state.data.run_name == {}: 1543 1602 state.data.run = [str(state.data.name)] 1544 1603 state.data.run_name[0] = state.data.name 1545 1604 1546 if issubclass(state.data.__class__, sans.dataloader.data_info.Data1D):1547 1605 if issubclass(state.data.__class__, 1606 sans.dataloader.data_info.Data1D): 1548 1607 data = state.data 1549 1608 doc, sasentry = self._to_xml_doc(data) … … 1552 1611 doc, sasentry = self._data2d_to_xml_doc(data) 1553 1612 1554 1555 1613 if state is not None: 1556 1614 state.toXML(doc=doc, file=data.name, entry_node=sasentry) 1557 1615 1558 return doc 1616 return doc 1559 1617 1560 # Simple html report templet 1618 # Simple html report templet 1561 1619 HEADER = "<html>\n" 1562 1620 HEADER += "<head>\n" … … 1579 1637 <br> 1580 1638 <p class=MsoNormal><b><span ><center> <font size='4' > Graph 1581 </font></span></center></b></p> 1582 <p class=MsoNormal> </p> 1583 <center> 1639 </font></span></center></b></p> 1640 <p class=MsoNormal> </p> 1641 <center> 1584 1642 <br><font size='4' >Model Computation</font> 1585 <br><font size='4' >Data: "%s"</font><br> 1643 <br><font size='4' >Data: "%s"</font><br> 1586 1644 """ 1587 1645 FEET_2 = \ 1588 1646 """ 1589 <img src="%s" > 1647 <img src="%s" > 1590 1648 </img> 1591 1649 """ 1592 1650 FEET_3 = \ 1593 1651 """ 1594 </center> 1652 </center> 1595 1653 </div> 1596 1654 </body> … … 1618 1676 import bsddb 1619 1677 import pickle 1620 db = bsddb.btopen('file_state.db', 'c')1678 db = bsddb.btopen('file_state.db', 'c') 1621 1679 val = (pickle.dumps(state), "hello", "hi") 1622 db['state1'] = pickle.dumps(val)1680 db['state1'] = pickle.dumps(val) 1623 1681 print pickle.loads(db['state1']) 1624 1682 state.data_name = "hello---->22" 1625 db['state2'] = pickle.dumps(state)1683 db['state2'] = pickle.dumps(state) 1626 1684 state.data_name = "hello---->2" 1627 db['state3'] = pickle.dumps(state)1685 db['state3'] = pickle.dumps(state) 1628 1686 del db['state3'] 1629 1687 state.data_name = "hello---->3" 1630 db['state4'] = pickle.dumps(state)1688 db['state4'] = pickle.dumps(state) 1631 1689 new_state = pickle.loads(db['state1']) 1632 1690 #print db.last() 1633 1691 db.set_location('state2') 1634 1692 state.data_name = "hello---->5" 1635 db['aastate5'] = pickle.dumps(state)1693 db['aastate5'] = pickle.dumps(state) 1636 1694 db.keys().sort() 1637 1695 print pickle.loads(db['state2'])
Note: See TracChangeset
for help on using the changeset viewer.