- Timestamp:
- Jan 13, 2017 10:52:21 AM (8 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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- eb2dc13
- Parents:
- 1905128 (diff), 12361fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/local_perspectives/plotting/plotting.py
r6ffa0dd rca224b1 134 134 """ 135 135 for group_id in self.plot_panels.keys(): 136 panel = self.plot_panels[group_id] 137 panel.graph.reset() 138 self.hide_panel(group_id) 136 self.clear_panel_by_id(group_id) 139 137 self.plot_panels = {} 140 138 -
src/sas/sasgui/perspectives/fitting/basepage.py
r505706a ra6fccd7 1105 1105 """ 1106 1106 for key, value in self.master_category_dict.iteritems(): 1107 formfactor = state.formfactorcombobox.split(":") 1108 if isinstance(formfactor, list): 1109 formfactor = formfactor[0] 1107 1110 for list_item in value: 1108 if state.formfactorcomboboxin list_item:1111 if formfactor in list_item: 1109 1112 return self.categorybox.Items.index(key) 1110 1113 return 0 … … 1152 1155 self._show_combox_helper() 1153 1156 # select the current model 1154 try: 1155 # to support older version 1156 category_pos = int(state.categorycombobox) 1157 except: 1158 state.formfactorcombobox = state.formfactorcombobox.lower() 1159 state.formfactorcombobox = \ 1160 state.formfactorcombobox.replace('model', '') 1161 state.formfactorcombobox = unicode(state.formfactorcombobox) 1162 state.categorycombobox = unicode(state.categorycombobox) 1163 if state.categorycombobox in self.categorybox.Items: 1164 category_pos = self.categorybox.Items.index( 1165 state.categorycombobox) 1166 else: 1167 # Look in master list for model name (model.lower) 1168 category_pos = self.get_cat_combo_box_pos(state) 1157 state._convert_to_sasmodels() 1158 state.categorycombobox = unicode(state.categorycombobox) 1159 if state.categorycombobox in self.categorybox.Items: 1160 category_pos = self.categorybox.Items.index( 1161 state.categorycombobox) 1162 else: 1163 # Look in master list for model name (model.lower) 1164 category_pos = self.get_cat_combo_box_pos(state) 1169 1165 1170 1166 self.categorybox.Select(category_pos) 1171 1167 self._show_combox(None) 1172 try: 1173 # to support older version 1174 formfactor_pos = int(state.formfactorcombobox) 1175 except: 1176 formfactor_pos = 0 1177 for ind_form in range(self.formfactorbox.GetCount()): 1178 if self.formfactorbox.GetString(ind_form) == \ 1179 (state.formfactorcombobox): 1180 formfactor_pos = int(ind_form) 1168 from models import PLUGIN_NAME_BASE 1169 if self.categorybox.GetValue() == 'Customized Models' \ 1170 and PLUGIN_NAME_BASE not in state.formfactorcombobox: 1171 state.formfactorcombobox = \ 1172 PLUGIN_NAME_BASE + state.formfactorcombobox 1173 formfactor_pos = 0 1174 for ind_form in range(self.formfactorbox.GetCount()): 1175 if self.formfactorbox.GetString(ind_form) == \ 1176 (state.formfactorcombobox): 1177 formfactor_pos = int(ind_form) 1178 break 1179 1180 self.formfactorbox.Select(formfactor_pos) 1181 1182 structfactor_pos = 0 1183 if state.structurecombobox is not None: 1184 state.structurecombobox = unicode(state.structurecombobox) 1185 for ind_struct in range(self.structurebox.GetCount()): 1186 if self.structurebox.GetString(ind_struct) == \ 1187 (state.structurecombobox): 1188 structfactor_pos = int(ind_struct) 1181 1189 break 1182 1183 self.formfactorbox.Select(formfactor_pos)1184 1185 structfactor_pos = 01186 try:1187 # to support older version1188 structfactor_pos = int(state.structurecombobox)1189 except:1190 if state.structurecombobox is not None:1191 state.structurecombobox = unicode(state.structurecombobox)1192 for ind_struct in range(self.structurebox.GetCount()):1193 if self.structurebox.GetString(ind_struct) == \1194 (state.structurecombobox):1195 structfactor_pos = int(ind_struct)1196 break1197 1190 1198 1191 self.structurebox.SetSelection(structfactor_pos) … … 1384 1377 # self.state.struct_rbutton = self.struct_rbutton.GetValue() 1385 1378 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 1386 self.state.structurecombobox = self.structurebox.Get Label()1387 self.state.formfactorcombobox = self.formfactorbox.Get Label()1388 self.state.categorycombobox = self.categorybox.Get Label()1379 self.state.structurecombobox = self.structurebox.GetValue() 1380 self.state.formfactorcombobox = self.formfactorbox.GetValue() 1381 self.state.categorycombobox = self.categorybox.GetValue() 1389 1382 1390 1383 # post state to fit panel … … 1587 1580 if len(statelist) == 0 or len(listtorestore) == 0: 1588 1581 return 1589 if len(statelist) != len(listtorestore):1590 return1591 1582 1592 1583 for j in range(len(listtorestore)): 1593 item_page = listtorestore[j] 1594 item_page_info = statelist[j] 1595 # change the state of the check box for simple parameters 1596 if item_page[0] is not None: 1597 item_page[0].SetValue(item_page_info[0]) 1598 if item_page[2] is not None: 1599 item_page[2].SetValue(item_page_info[2]) 1600 if item_page[2].__class__.__name__ == "ComboBox": 1601 if item_page_info[2] in self.model.fun_list: 1602 fun_val = self.model.fun_list[item_page_info[2]] 1603 self.model.setParam(item_page_info[1], fun_val) 1604 if item_page[3] is not None: 1605 # show or hide text +/- 1606 if item_page_info[2]: 1607 item_page[3].Show(True) 1608 else: 1609 item_page[3].Hide() 1610 if item_page[4] is not None: 1611 # show of hide the text crtl for fitting error 1612 if item_page_info[4][0]: 1613 item_page[4].Show(True) 1614 item_page[4].SetValue(item_page_info[4][1]) 1615 else: 1616 item_page[3].Hide() 1617 if item_page[5] is not None: 1618 # show of hide the text crtl for fitting error 1619 item_page[5].Show(item_page_info[5][0]) 1620 item_page[5].SetValue(item_page_info[5][1]) 1621 1622 if item_page[6] is not None: 1623 # show of hide the text crtl for fitting error 1624 item_page[6].Show(item_page_info[6][0]) 1625 item_page[6].SetValue(item_page_info[6][1]) 1584 for param in statelist: 1585 if param[1] == listtorestore[j][1]: 1586 item_page = listtorestore[j] 1587 item_page_info = param 1588 if (item_page_info[1] == "theta" or item_page_info[1] == 1589 "phi") and not self._is_2D(): 1590 break 1591 # change the state of the check box for simple parameters 1592 if item_page[0] is not None: 1593 item_page[0].SetValue(item_page_info[0]) 1594 if item_page[2] is not None: 1595 item_page[2].SetValue(item_page_info[2]) 1596 if item_page[2].__class__.__name__ == "ComboBox": 1597 if item_page_info[2] in self.model.fun_list: 1598 fun_val = self.model.fun_list[item_page_info[2]] 1599 self.model.setParam(item_page_info[1], fun_val) 1600 if item_page[3] is not None: 1601 # show or hide text +/- 1602 if item_page_info[2]: 1603 item_page[3].Show(True) 1604 else: 1605 item_page[3].Hide() 1606 if item_page[4] is not None: 1607 # show of hide the text crtl for fitting error 1608 if item_page_info[4][0]: 1609 item_page[4].Show(True) 1610 item_page[4].SetValue(str(item_page_info[4][1])) 1611 else: 1612 item_page[3].Hide() 1613 if item_page[5] is not None: 1614 # show of hide the text crtl for fitting error 1615 item_page[5].Show(True) 1616 item_page[5].SetValue(str(item_page_info[5][1])) 1617 if item_page[6] is not None: 1618 # show of hide the text crtl for fitting error 1619 item_page[6].Show(True) 1620 item_page[6].SetValue(str(item_page_info[6][1])) 1621 break 1626 1622 1627 1623 def _reset_strparam_state(self, listtorestore, statelist): -
src/sas/sasgui/perspectives/fitting/fitpage.py
r24fd27a ra6fccd7 1190 1190 self.state.slit_smearer = self.slit_smearer.GetValue() 1191 1191 1192 self.state.structurecombobox = self.structurebox.GetLabel() 1193 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1192 self.state.structurecombobox = self.structurebox.GetValue() 1193 self.state.formfactorcombobox = self.formfactorbox.GetValue() 1194 self.state.categorycombobox = self.categorybox.GetValue() 1194 1195 self.enable_fit_button() 1195 1196 if self.model is not None: -
src/sas/sasgui/perspectives/fitting/models.py
r313c5c9 r0de74af 23 23 PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR, 24 24 "plugins.log") 25 PLUGIN_NAME_BASE = '[plug-in] ' 25 26 26 27 def get_model_python_path(): … … 181 182 try: 182 183 model = load_custom_model(path) 183 model.name = "[plug-in] "+model.name184 model.name = PLUGIN_NAME_BASE + model.name 184 185 plugins[model.name] = model 185 186 except Exception: -
src/sas/sasgui/perspectives/fitting/pagestate.py
raf08e55 r18b7ca96 25 25 from lxml import etree 26 26 27 from sasmodels import convert 27 28 import sasmodels.weights 28 29 … … 271 272 # store value of chisqr 272 273 self.tcChi = None 274 self.version = (1,0,0) 273 275 274 276 def clone(self): … … 349 351 obj.cb1 = copy.deepcopy(self.cb1) 350 352 obj.smearer = copy.deepcopy(self.smearer) 353 obj.version = copy.deepcopy(self.version) 351 354 352 355 for name, state in self.saved_states.iteritems(): … … 355 358 obj.saved_states[copy_name] = copy_state 356 359 return obj 360 361 def _old_first_model(self): 362 """ 363 Handle save states from 4.0.1 and before where the first item in the 364 selection boxes of category, formfactor and structurefactor were not 365 saved. 366 :return: None 367 """ 368 if self.formfactorcombobox == '': 369 if self.categorycombobox == '' and len(self.parameters) == 3: 370 self.categorycombobox = "Shape-Independent" 371 self.formfactorcombobox = 'PowerLawAbsModel' 372 elif self.categorycombobox == '' and len(self.parameters) == 9: 373 self.categorycombobox = 'Cylinder' 374 self.formfactorcombobox = 'barbell' 375 elif self.categorycombobox == 'Shapes': 376 self.formfactorcombobox = 'BCCrystalModel' 377 elif self.categorycombobox == 'Uncategorized': 378 self.formfactorcombobox = 'LineModel' 379 elif self.categorycombobox == 'StructureFactor': 380 self.structurecombobox = 'HardsphereStructure' 381 elif self.categorycombobox == 'Customized Models': 382 self.formfactorcombobox = 'MySumFunction' 383 elif self.categorycombobox == 'Ellipsoid': 384 self.formfactorcombobox = 'core_shell_ellipsoid' 385 elif self.categorycombobox == 'Lamellae': 386 self.formfactorcombobox = 'lamellar' 387 elif self.categorycombobox == 'Paracrystal': 388 self.formfactorcombobox = 'bcc_paracrystal' 389 elif self.categorycombobox == 'Parallelepiped': 390 self.formfactorcombobox = 'core_shell_parallelepiped' 391 elif self.categorycombobox == 'Shape Independent': 392 self.formfactorcombobox = 'be_polyelectrolyte' 393 elif self.categorycombobox == 'Sphere': 394 self.formfactorcombobox = 'adsorbed_layer' 395 elif self.categorycombobox == 'Structure Factor': 396 self.formfactorcombobox = 'hardsphere' 397 398 @staticmethod 399 def param_remap_to_sasmodels_convert(params, is_string=False): 400 """ 401 Remaps the parameters for sasmodels conversion 402 403 :param params: list of parameters (likely self.parameters) 404 :return: remapped dictionary of parameters 405 """ 406 p = dict() 407 for fittable, name, value, _, uncert, lower, upper, units in params: 408 if not value: 409 value = numpy.nan 410 if not uncert or uncert[1] == '' or uncert[1] == 'None': 411 uncert[0] = False 412 uncert[1] = numpy.nan 413 if not upper or upper[1] == '' or upper[1] == 'None': 414 upper[0] = False 415 upper[1] = numpy.nan 416 if not lower or lower[1] == '' or lower[1] == 'None': 417 lower[0] = False 418 lower[1] = numpy.nan 419 if is_string: 420 p[name] = str(value) 421 else: 422 p[name] = float(value) 423 p[name + ".fittable"] = bool(fittable) 424 p[name + ".std"] = float(uncert[1]) 425 p[name + ".upper"] = float(upper[1]) 426 p[name + ".lower"] = float(lower[1]) 427 p[name + ".units"] = units 428 return p 429 430 @staticmethod 431 def param_remap_from_sasmodels_convert(params): 432 """ 433 Converts {name : value} map back to [] param list 434 :param params: parameter map returned from sasmodels 435 :return: None 436 """ 437 p_map = [] 438 for name, info in params.iteritems(): 439 if ".fittable" in name or ".std" in name or ".upper" in name or \ 440 ".lower" in name or ".units" in name: 441 pass 442 else: 443 fittable = params.get(name + ".fittable", True) 444 std = params.get(name + ".std", '0.0') 445 upper = params.get(name + ".upper", 'inf') 446 lower = params.get(name + ".lower", '-inf') 447 units = params.get(name + ".units") 448 if std is not None and std is not numpy.nan: 449 std = [True, str(std)] 450 else: 451 std = [False, ''] 452 if lower is not None and lower is not numpy.nan: 453 lower = [True, str(lower)] 454 else: 455 lower = [True, '-inf'] 456 if upper is not None and upper is not numpy.nan: 457 upper = [True, str(upper)] 458 else: 459 upper = [True, 'inf'] 460 param_list = [bool(fittable), str(name), str(info), 461 "+/-", std, lower, upper, str(units)] 462 p_map.append(param_list) 463 return p_map 464 465 def _convert_to_sasmodels(self): 466 """ 467 Convert parameters to a form usable by sasmodels converter 468 469 :return: None 470 """ 471 # Create conversion dictionary to send to sasmodels 472 self._old_first_model() 473 p = self.param_remap_to_sasmodels_convert(self.parameters) 474 structurefactor, params = convert.convert_model(self.structurecombobox, 475 p, False, self.version) 476 formfactor, params = convert.convert_model(self.formfactorcombobox, 477 params, False, self.version) 478 if len(self.str_parameters) > 0: 479 str_pars = self.param_remap_to_sasmodels_convert( 480 self.str_parameters, True) 481 formfactor, str_params = convert.convert_model( 482 self.formfactorcombobox, str_pars, False, self.version) 483 for key, value in str_params.iteritems(): 484 params[key] = value 485 486 if self.formfactorcombobox == 'SphericalSLDModel': 487 self.multi_factor += 1 488 self.formfactorcombobox = formfactor 489 self.structurecombobox = structurefactor 490 self.parameters = [] 491 self.parameters = self.param_remap_from_sasmodels_convert(params) 357 492 358 493 def _repr_helper(self, list, rep): … … 682 817 683 818 attr = newdoc.createAttribute("version") 684 attr.nodeValue = '1.0' 819 import sasview 820 attr.nodeValue = sasview.__version__ 821 # attr.nodeValue = '1.0' 685 822 top_element.setAttributeNode(attr) 686 823 … … 875 1012 raise RuntimeError, msg 876 1013 877 if node.get('version') and node.get('version') == '1.0': 1014 if node.get('version'): 1015 # Get the version for model conversion purposes 1016 self.version = tuple(int(e) for e in 1017 str.split(node.get('version'), ".")) 1018 # The tuple must be at least 3 items long 1019 while len(self.version) < 3: 1020 ver_list = list(self.version) 1021 ver_list.append(0) 1022 self.version = tuple(ver_list) 878 1023 879 1024 # Get file name … … 1191 1336 name = original_fname 1192 1337 state.data.group_id = name 1338 state.version = fitstate.version 1193 1339 # store state in fitting 1194 1340 self.call_back(state=state, -
src/sas/sasgui/perspectives/invariant/invariant_state.py
rcb93b40 rdb5294e 423 423 for item in DEFAULT_STATE: 424 424 input_field = get_content('ns:%s' % item, entry) 425 val = str(input_field.text.strip()) 425 if input_field.text is not None: 426 val = str(input_field.text.strip()) 427 else: 428 val = '' 426 429 if input_field is not None: 427 430 temp_state[item] = val … … 433 436 for item in DEFAULT_STATE: 434 437 input_field = get_content('ns:%s' % item, entry) 435 val = str(input_field.text.strip()) 438 if input_field.text is not None: 439 val = str(input_field.text.strip()) 440 else: 441 val = '' 436 442 if input_field is not None: 437 443 self.set_saved_state(name=item, value=val) -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r0639476 r1905128 20 20 import inspect 21 21 # For saving individual sections of data 22 from sas.sascalc.dataloader.data_info import Data1D, DataInfo, plottable_1D 23 from sas.sascalc.dataloader.data_info import Collimation, TransmissionSpectrum, Detector, Process, Aperture 24 from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable as combine_data 22 from sas.sascalc.dataloader.data_info import Data1D, Data2D, DataInfo, \ 23 plottable_1D, plottable_2D 24 from sas.sascalc.dataloader.data_info import Collimation, TransmissionSpectrum, \ 25 Detector, Process, Aperture 26 from sas.sascalc.dataloader.data_info import \ 27 combine_data_info_with_plottable as combine_data 25 28 import sas.sascalc.dataloader.readers.xml_reader as xml_reader 26 29 from sas.sascalc.dataloader.readers.xml_reader import XMLreader … … 56 59 The CanSAS reader requires PyXML 0.8.4 or later. 57 60 """ 58 # #CanSAS version - defaults to version 1.061 # CanSAS version - defaults to version 1.0 59 62 cansas_version = "1.0" 60 63 base_ns = "{cansas1d/1.0}" … … 63 66 invalid = True 64 67 frm = "" 65 # #Log messages and errors68 # Log messages and errors 66 69 logging = None 67 70 errors = set() 68 # #Namespace hierarchy for current xml_file object71 # Namespace hierarchy for current xml_file object 69 72 names = None 70 73 ns_list = None 71 # #Temporary storage location for loading multiple data sets in a single file74 # Temporary storage location for loading multiple data sets in a single file 72 75 current_datainfo = None 73 76 current_dataset = None 74 77 current_data1d = None 75 78 data = None 76 # #List of data1D objects to be sent back to SasView79 # List of data1D objects to be sent back to SasView 77 80 output = None 78 # #Wildcards81 # Wildcards 79 82 type = ["XML files (*.xml)|*.xml", "SasView Save Files (*.svs)|*.svs"] 80 # #List of allowed extensions83 # List of allowed extensions 81 84 ext = ['.xml', '.XML', '.svs', '.SVS'] 82 # #Flag to bypass extension check85 # Flag to bypass extension check 83 86 allow_all = True 84 87 … … 220 223 self.parent_class = tagname_original 221 224 if tagname == 'SASdata': 222 self._initialize_new_data_set() 223 ## Recursion step to access data within the group 225 self._initialize_new_data_set(node) 226 if isinstance(self.current_dataset, plottable_2D): 227 x_bins = attr.get("x_bins", "") 228 y_bins = attr.get("y_bins", "") 229 if x_bins is not "" and y_bins is not "": 230 self.current_dataset.shape = (x_bins, y_bins) 231 else: 232 self.current_dataset.shape = () 233 # Recursion step to access data within the group 224 234 self._parse_entry(node, True) 225 235 if tagname == "SASsample": … … 234 244 self.add_intermediate() 235 245 else: 236 data_point, unit = self._get_node_value(node, tagname) 237 238 ## If this is a dataset, store the data appropriately 246 if isinstance(self.current_dataset, plottable_2D): 247 data_point = node.text 248 unit = attr.get('unit', '') 249 else: 250 data_point, unit = self._get_node_value(node, tagname) 251 252 # If this is a dataset, store the data appropriately 239 253 if tagname == 'Run': 240 254 self.current_datainfo.run_name[data_point] = name … … 245 259 self.current_datainfo.notes.append(data_point) 246 260 247 # # I and Q Data248 elif tagname == 'I' :261 # I and Q - 1D data 262 elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 249 263 self.current_dataset.yaxis("Intensity", unit) 250 264 self.current_dataset.y = np.append(self.current_dataset.y, data_point) 251 elif tagname == 'Idev' :265 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 252 266 self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 253 267 elif tagname == 'Q': … … 265 279 pass 266 280 267 ## Sample Information 281 # I and Qx, Qy - 2D data 282 elif tagname == 'I' and isinstance(self.current_dataset, plottable_2D): 283 self.current_dataset.yaxis("Intensity", unit) 284 self.current_dataset.data = np.fromstring(data_point, dtype=float, sep=",") 285 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_2D): 286 self.current_dataset.err_data = np.fromstring(data_point, dtype=float, sep=",") 287 elif tagname == 'Qx': 288 self.current_dataset.xaxis("Qx", unit) 289 self.current_dataset.qx_data = np.fromstring(data_point, dtype=float, sep=",") 290 elif tagname == 'Qy': 291 self.current_dataset.yaxis("Qy", unit) 292 self.current_dataset.qy_data = np.fromstring(data_point, dtype=float, sep=",") 293 elif tagname == 'Qxdev': 294 self.current_dataset.xaxis("Qxdev", unit) 295 self.current_dataset.dqx_data = np.fromstring(data_point, dtype=float, sep=",") 296 elif tagname == 'Qydev': 297 self.current_dataset.yaxis("Qydev", unit) 298 self.current_dataset.dqy_data = np.fromstring(data_point, dtype=float, sep=",") 299 elif tagname == 'Mask': 300 inter = data_point.split(",") 301 self.current_dataset.mask = np.asarray(inter, dtype=bool) 302 303 # Sample Information 268 304 elif tagname == 'ID' and self.parent_class == 'SASsample': 269 305 self.current_datainfo.sample.ID = data_point … … 299 335 self.current_datainfo.sample.orientation_unit = unit 300 336 301 # #Instrumental Information337 # Instrumental Information 302 338 elif tagname == 'name' and self.parent_class == 'SASinstrument': 303 339 self.current_datainfo.instrument = data_point 304 # #Detector Information340 # Detector Information 305 341 elif tagname == 'name' and self.parent_class == 'SASdetector': 306 342 self.detector.name = data_point … … 347 383 self.detector.orientation.z = data_point 348 384 self.detector.orientation_unit = unit 349 # #Collimation and Aperture385 # Collimation and Aperture 350 386 elif tagname == 'length' and self.parent_class == 'SAScollimation': 351 387 self.collimation.length = data_point … … 366 402 self.collimation.size_unit = unit 367 403 368 # #Process Information404 # Process Information 369 405 elif tagname == 'name' and self.parent_class == 'SASprocess': 370 406 self.process.name = data_point … … 386 422 self.process.term.append(dic) 387 423 388 # #Transmission Spectrum424 # Transmission Spectrum 389 425 elif tagname == 'T' and self.parent_class == 'Tdata': 390 426 self.transspectrum.transmission = np.append(self.transspectrum.transmission, data_point) … … 397 433 self.transspectrum.wavelength_unit = unit 398 434 399 # #Source Information435 # Source Information 400 436 elif tagname == 'wavelength' and (self.parent_class == 'SASsource' or self.parent_class == 'SASData'): 401 437 self.current_datainfo.source.wavelength = data_point … … 424 460 self.current_datainfo.source.beam_shape = data_point 425 461 426 # #Everything else goes in meta_data462 # Everything else goes in meta_data 427 463 else: 428 464 new_key = self._create_unique_key(self.current_datainfo.meta_data, tagname) … … 438 474 self.add_data_set() 439 475 empty = None 440 if self.output[0].dx is not None:441 self.output[0].dxl = np.empty(0)442 self.output[0].dxw = np.empty(0)443 else:444 self.output[0].dx = np.empty(0)445 476 return self.output[0], empty 446 477 … … 514 545 self.current_datainfo = DataInfo() 515 546 516 def _initialize_new_data_set(self, parent_list=None):547 def _initialize_new_data_set(self, node=None): 517 548 """ 518 549 A private class method to generate a new 1D data object. 519 550 Outside methods should call add_data_set() to be sure any existing data is stored properly. 520 551 521 :param parent_list: List of names of parent elements 522 """ 523 524 if parent_list is None: 525 parent_list = [] 552 :param node: XML node to determine if 1D or 2D data 553 """ 526 554 x = np.array(0) 527 555 y = np.array(0) 556 for child in node: 557 if child.tag.replace(self.base_ns, "") == "Idata": 558 for i_child in child: 559 if i_child.tag.replace(self.base_ns, "") == "Qx": 560 self.current_dataset = plottable_2D() 561 return 528 562 self.current_dataset = plottable_1D(x, y) 529 563 … … 560 594 """ 561 595 562 # #Append errors to dataset and reset class errors596 # Append errors to dataset and reset class errors 563 597 self.current_datainfo.errors = set() 564 598 for error in self.errors: … … 566 600 self.errors.clear() 567 601 568 # #Combine all plottables with datainfo and append each to output569 # #Type cast data arrays to float64 and find min/max as appropriate602 # Combine all plottables with datainfo and append each to output 603 # Type cast data arrays to float64 and find min/max as appropriate 570 604 for dataset in self.data: 571 if dataset.x is not None: 572 dataset.x = np.delete(dataset.x, [0]) 573 dataset.x = dataset.x.astype(np.float64) 574 dataset.xmin = np.min(dataset.x) 575 dataset.xmax = np.max(dataset.x) 576 if dataset.y is not None: 577 dataset.y = np.delete(dataset.y, [0]) 578 dataset.y = dataset.y.astype(np.float64) 579 dataset.ymin = np.min(dataset.y) 580 dataset.ymax = np.max(dataset.y) 581 if dataset.dx is not None: 582 dataset.dx = np.delete(dataset.dx, [0]) 583 dataset.dx = dataset.dx.astype(np.float64) 584 if dataset.dxl is not None: 585 dataset.dxl = np.delete(dataset.dxl, [0]) 586 dataset.dxl = dataset.dxl.astype(np.float64) 587 if dataset.dxw is not None: 588 dataset.dxw = np.delete(dataset.dxw, [0]) 589 dataset.dxw = dataset.dxw.astype(np.float64) 590 if dataset.dy is not None: 591 dataset.dy = np.delete(dataset.dy, [0]) 592 dataset.dy = dataset.dy.astype(np.float64) 593 np.trim_zeros(dataset.x) 594 np.trim_zeros(dataset.y) 595 np.trim_zeros(dataset.dy) 605 if isinstance(dataset, plottable_1D): 606 if dataset.x is not None: 607 dataset.x = np.delete(dataset.x, [0]) 608 dataset.x = dataset.x.astype(np.float64) 609 dataset.xmin = np.min(dataset.x) 610 dataset.xmax = np.max(dataset.x) 611 if dataset.y is not None: 612 dataset.y = np.delete(dataset.y, [0]) 613 dataset.y = dataset.y.astype(np.float64) 614 dataset.ymin = np.min(dataset.y) 615 dataset.ymax = np.max(dataset.y) 616 if dataset.dx is not None: 617 dataset.dx = np.delete(dataset.dx, [0]) 618 dataset.dx = dataset.dx.astype(np.float64) 619 if dataset.dxl is not None: 620 dataset.dxl = np.delete(dataset.dxl, [0]) 621 dataset.dxl = dataset.dxl.astype(np.float64) 622 if dataset.dxw is not None: 623 dataset.dxw = np.delete(dataset.dxw, [0]) 624 dataset.dxw = dataset.dxw.astype(np.float64) 625 if dataset.dy is not None: 626 dataset.dy = np.delete(dataset.dy, [0]) 627 dataset.dy = dataset.dy.astype(np.float64) 628 np.trim_zeros(dataset.x) 629 np.trim_zeros(dataset.y) 630 np.trim_zeros(dataset.dy) 631 elif isinstance(dataset, plottable_2D): 632 dataset.data = dataset.data.astype(np.float64) 633 dataset.qx_data = dataset.qx_data.astype(np.float64) 634 dataset.xmin = np.min(dataset.qx_data) 635 dataset.xmax = np.max(dataset.qx_data) 636 dataset.qy_data = dataset.qy_data.astype(np.float64) 637 dataset.ymin = np.min(dataset.qy_data) 638 dataset.ymax = np.max(dataset.qy_data) 639 dataset.q_data = np.sqrt(dataset.qx_data * dataset.qx_data 640 + dataset.qy_data * dataset.qy_data) 641 if dataset.err_data is not None: 642 dataset.err_data = dataset.err_data.astype(np.float64) 643 if dataset.dqx_data is not None: 644 dataset.dqx_data = dataset.dqx_data.astype(np.float64) 645 if dataset.dqy_data is not None: 646 dataset.dqy_data = dataset.dqy_data.astype(np.float64) 647 if dataset.mask is not None: 648 dataset.mask = dataset.mask.astype(dtype=bool) 649 650 if len(dataset.shape) == 2: 651 n_rows, n_cols = dataset.shape 652 dataset.y_bins = dataset.qy_data[0::int(n_cols)] 653 dataset.x_bins = dataset.qx_data[:int(n_cols)] 654 dataset.data = dataset.data.flatten() 655 else: 656 dataset.y_bins = [] 657 dataset.x_bins = [] 658 dataset.data = dataset.data.flatten() 659 596 660 final_dataset = combine_data(dataset, self.current_datainfo) 597 661 self.output.append(final_dataset) … … 693 757 and local_unit.lower() != "none": 694 758 if HAS_CONVERTER == True: 695 # #Check local units - bad units raise KeyError759 # Check local units - bad units raise KeyError 696 760 data_conv_q = Converter(local_unit) 697 761 value_unit = default_unit … … 740 804 A method to check all resolution data sets are the same size as I and Q 741 805 """ 742 dql_exists = False 743 dqw_exists = False 744 dq_exists = False 745 di_exists = False 746 if self.current_dataset.dxl is not None: 747 dql_exists = True 748 if self.current_dataset.dxw is not None: 749 dqw_exists = True 750 if self.current_dataset.dx is not None: 751 dq_exists = True 752 if self.current_dataset.dy is not None: 753 di_exists = True 754 if dqw_exists and not dql_exists: 755 array_size = self.current_dataset.dxw.size - 1 756 self.current_dataset.dxl = np.append(self.current_dataset.dxl, np.zeros([array_size])) 757 elif dql_exists and not dqw_exists: 758 array_size = self.current_dataset.dxl.size - 1 759 self.current_dataset.dxw = np.append(self.current_dataset.dxw, np.zeros([array_size])) 760 elif not dql_exists and not dqw_exists and not dq_exists: 761 array_size = self.current_dataset.x.size - 1 762 self.current_dataset.dx = np.append(self.current_dataset.dx, np.zeros([array_size])) 763 if not di_exists: 764 array_size = self.current_dataset.y.size - 1 765 self.current_dataset.dy = np.append(self.current_dataset.dy, np.zeros([array_size])) 766 806 if isinstance(self.current_dataset, plottable_1D): 807 dql_exists = False 808 dqw_exists = False 809 dq_exists = False 810 di_exists = False 811 if self.current_dataset.dxl is not None: 812 dql_exists = True 813 if self.current_dataset.dxw is not None: 814 dqw_exists = True 815 if self.current_dataset.dx is not None: 816 dq_exists = True 817 if self.current_dataset.dy is not None: 818 di_exists = True 819 if dqw_exists and not dql_exists: 820 array_size = self.current_dataset.dxw.size - 1 821 self.current_dataset.dxl = np.append(self.current_dataset.dxl, 822 np.zeros([array_size])) 823 elif dql_exists and not dqw_exists: 824 array_size = self.current_dataset.dxl.size - 1 825 self.current_dataset.dxw = np.append(self.current_dataset.dxw, 826 np.zeros([array_size])) 827 elif not dql_exists and not dqw_exists and not dq_exists: 828 array_size = self.current_dataset.x.size - 1 829 self.current_dataset.dx = np.append(self.current_dataset.dx, 830 np.zeros([array_size])) 831 if not di_exists: 832 array_size = self.current_dataset.y.size - 1 833 self.current_dataset.dy = np.append(self.current_dataset.dy, 834 np.zeros([array_size])) 835 elif isinstance(self.current_dataset, plottable_2D): 836 dqx_exists = False 837 dqy_exists = False 838 di_exists = False 839 mask_exists = False 840 if self.current_dataset.dqx_data is not None: 841 dqx_exists = True 842 if self.current_dataset.dqy_data is not None: 843 dqy_exists = True 844 if self.current_dataset.err_data is not None: 845 di_exists = True 846 if self.current_dataset.mask is not None: 847 mask_exists = True 848 if not dqy_exists: 849 array_size = self.current_dataset.qy_data.size - 1 850 self.current_dataset.dqy_data = np.append( 851 self.current_dataset.dqy_data, np.zeros([array_size])) 852 if not dqx_exists: 853 array_size = self.current_dataset.qx_data.size - 1 854 self.current_dataset.dqx_data = np.append( 855 self.current_dataset.dqx_data, np.zeros([array_size])) 856 if not di_exists: 857 array_size = self.current_dataset.data.size - 1 858 self.current_dataset.err_data = np.append( 859 self.current_dataset.err_data, np.zeros([array_size])) 860 if not mask_exists: 861 array_size = self.current_dataset.data.size - 1 862 self.current_dataset.mask = np.append( 863 self.current_dataset.mask, 864 np.ones([array_size] ,dtype=bool)) 767 865 768 866 ####### All methods below are for writing CanSAS XML files ####### 769 770 867 771 868 def write(self, filename, datainfo): … … 792 889 :param datainfo: Data1D object 793 890 """ 794 if not issubclass(datainfo.__class__, Data1D): 795 raise RuntimeError, "The cansas writer expects a Data1D instance" 891 is_2d = False 892 if issubclass(datainfo.__class__, Data2D): 893 is_2d = True 796 894 797 895 # Get PIs and create root element … … 813 911 self._write_run_names(datainfo, entry_node) 814 912 # Add Data info to SASEntry 815 self._write_data(datainfo, entry_node) 913 if is_2d: 914 self._write_data_2d(datainfo, entry_node) 915 else: 916 self._write_data(datainfo, entry_node) 816 917 # Transmission Spectrum Info 817 918 self._write_trans_spectrum(datainfo, entry_node) … … 907 1008 def _write_data(self, datainfo, entry_node): 908 1009 """ 909 Writes theI and Q data to the XML file1010 Writes 1D I and Q data to the XML file 910 1011 911 1012 :param datainfo: The Data1D object the information is coming from … … 935 1036 self.write_node(point, "dQl", datainfo.dxl[i], 936 1037 {'unit': datainfo.x_unit}) 1038 1039 def _write_data_2d(self, datainfo, entry_node): 1040 """ 1041 Writes 2D data to the XML file 1042 1043 :param datainfo: The Data2D object the information is coming from 1044 :param entry_node: lxml node ElementTree object to be appended to 1045 """ 1046 attr = {} 1047 if datainfo.data.shape: 1048 attr["x_bins"] = str(len(datainfo.x_bins)) 1049 attr["y_bins"] = str(len(datainfo.y_bins)) 1050 node = self.create_element("SASdata", attr) 1051 self.append(node, entry_node) 1052 1053 point = self.create_element("Idata") 1054 node.append(point) 1055 qx = ','.join([str(datainfo.qx_data[i]) for i in xrange(len(datainfo.qx_data))]) 1056 qy = ','.join([str(datainfo.qy_data[i]) for i in xrange(len(datainfo.qy_data))]) 1057 intensity = ','.join([str(datainfo.data[i]) for i in xrange(len(datainfo.data))]) 1058 err = ','.join([str(datainfo.err_data[i]) for i in xrange(len(datainfo.err_data))]) 1059 dqy = ','.join([str(datainfo.dqy_data[i]) for i in xrange(len(datainfo.dqy_data))]) 1060 dqx = ','.join([str(datainfo.dqx_data[i]) for i in xrange(len(datainfo.dqx_data))]) 1061 mask = ','.join([str(datainfo.mask[i]) for i in xrange(len(datainfo.mask))]) 1062 1063 self.write_node(point, "Qx", qx, 1064 {'unit': datainfo._xunit}) 1065 self.write_node(point, "Qy", qy, 1066 {'unit': datainfo._yunit}) 1067 self.write_node(point, "I", intensity, 1068 {'unit': datainfo._zunit}) 1069 if datainfo.err_data is not None: 1070 self.write_node(point, "Idev", err, 1071 {'unit': datainfo._zunit}) 1072 if datainfo.dqy_data is not None: 1073 self.write_node(point, "Qydev", dqy, 1074 {'unit': datainfo._yunit}) 1075 if datainfo.dqx_data is not None: 1076 self.write_node(point, "Qxdev", dqx, 1077 {'unit': datainfo._xunit}) 1078 if datainfo.mask is not None: 1079 self.write_node(point, "Mask", mask) 937 1080 938 1081 def _write_trans_spectrum(self, datainfo, entry_node): -
src/sas/sascalc/dataloader/readers/schema/cansas1d_invalid_v1_0.xsd
r250fec92 raf08e55 24 24 25 25 <complexType name="IdataType"> 26 <xsd:choice> 26 27 <sequence> 27 28 <element name="Q" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> … … 40 41 <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax" namespace="##other" /> 41 42 </sequence> 43 <sequence> 44 <element name="Qx" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> 45 <element name="Qy" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> 46 <element name="I" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> 47 <element name="Idev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 48 <element name="Qydev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 49 <element name="Qxdev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 50 <element name="Mask" minOccurs="0" maxOccurs="1" type="string" default="0" /> 51 </sequence> 52 </xsd:choice> 42 53 </complexType> 43 54 … … 51 62 <attribute name="name" type="string" use="optional" default="" /> 52 63 <attribute name="timestamp" type="dateTime" use="optional" /> 64 <attribute name="x_bins" type="string" use="optional" /> 65 <attribute name="y_bins" type="string" use="optional" /> 53 66 </complexType> 54 67 -
src/sas/sascalc/dataloader/readers/schema/cansas1d_invalid_v1_1.xsd
r250fec92 raf08e55 24 24 25 25 <complexType name="IdataType"> 26 <xsd:choice> 26 27 <sequence> 27 28 <element name="Q" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> … … 40 41 <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax" namespace="##other" /> 41 42 </sequence> 43 <sequence> 44 <element name="Qx" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> 45 <element name="Qy" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> 46 <element name="I" minOccurs="1" maxOccurs="1" type="tns:floatUnitType" /> 47 <element name="Idev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 48 <element name="Qydev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 49 <element name="Qxdev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 50 <element name="Mask" minOccurs="0" maxOccurs="1" type="string" default="0" /> 51 </sequence> 52 </xsd:choice> 42 53 </complexType> 43 54 … … 51 62 <attribute name="name" type="string" use="optional" default="" /> 52 63 <attribute name="timestamp" type="dateTime" use="optional" /> 64 <attribute name="x_bins" type="string" use="optional" /> 65 <attribute name="y_bins" type="string" use="optional" /> 53 66 </complexType> 54 67 -
src/sas/sasgui/perspectives/fitting/model_thread.py
rd3911e3 rc1681ea 197 197 output[index] = self.model.evalDistribution(self.data.x[index]) 198 198 199 sq_model = None 200 pq_model = None 199 sq_values = None 200 pq_values = None 201 s_model = None 202 p_model = None 201 203 if isinstance(self.model, MultiplicationModel): 202 sq_model = numpy.zeros((len(self.data.x))) 203 pq_model = numpy.zeros((len(self.data.x))) 204 sq_model[index] = self.model.s_model.evalDistribution(self.data.x[index]) 205 pq_model[index] = self.model.p_model.evalDistribution(self.data.x[index]) 204 s_model = self.model.s_model 205 p_model = self.model.p_model 206 elif hasattr(self.model, "get_composition_models"): 207 p_model, s_model = self.model.get_composition_models() 208 209 if p_model is not None and s_model is not None: 210 sq_values = numpy.zeros((len(self.data.x))) 211 pq_values = numpy.zeros((len(self.data.x))) 212 sq_values[index] = s_model.evalDistribution(self.data.x[index]) 213 pq_values[index] = p_model.evalDistribution(self.data.x[index]) 206 214 207 215 elapsed = time.time() - self.starttime … … 220 228 unsmeared_data=unsmeared_data, 221 229 unsmeared_error=unsmeared_error, 222 pq_model=pq_ model,223 sq_model=sq_ model)230 pq_model=pq_values, 231 sq_model=sq_values) 224 232 225 233 def results(self):
Note: See TracChangeset
for help on using the changeset viewer.