def _update_high_q(self, ws=None): """ Update High-Q data set """ self._high_q_data = self.update_data(self._content.high_q_combo, None, None, self._content.high_scale_edit) self._high_q_modified = False file = str(self._content.high_q_combo.lineEdit().text()) if len(file.strip()) == 0: self._high_q_data = None elif os.path.isfile(file) or AnalysisDataService.doesExist(file): self._high_q_data = DataSet(file) try: self._high_q_data.load(True) except: self._high_q_data = None util.set_valid(self._content.high_q_combo.lineEdit(), False) QtGui.QMessageBox.warning( self, "Error loading file", "Could not load %s.\nMake sure you pick the XML output from the reduction." % file) return self._content.high_scale_edit.setText("1.0") npts = self._high_q_data.get_number_of_points() util.set_valid(self._content.high_q_combo.lineEdit(), True) else: self._high_q_data = None util.set_valid(self._content.high_q_combo.lineEdit(), False)
def _update_high_q(self, _ws=None): """ Update High-Q data set """ self._high_q_data = self.update_data(self._content.high_q_combo, None, None, self._content.high_scale_edit) self._high_q_modified = False file_in = str(self._content.high_q_combo.lineEdit().text()) if len(file_in.strip()) == 0: self._high_q_data = None elif os.path.isfile(file_in) or AnalysisDataService.doesExist(file_in): self._high_q_data = DataSet(file_in) try: self._high_q_data.load(True) except (AttributeError, ImportError, NameError, TypeError, ValueError, Warning): self._high_q_data = None util.set_valid(self._content.high_q_combo.lineEdit(), False) QtGui.QMessageBox.warning( self, "Error loading file", "Could not load %s.\nMake sure you pick the XML output from the reduction." % file_in) return self._content.high_scale_edit.setText("1.0") util.set_valid(self._content.high_q_combo.lineEdit(), True) else: self._high_q_data = None util.set_valid(self._content.high_q_combo.lineEdit(), False)
def _load_workspace(self, workspace): ws_data = DataSet(workspace) try: ws_data.load(True, True) except: ws_data = None QtGui.QMessageBox.warning(self, "Error loading file", "Could not load %s." % file) return
def set_user_data(self, data): self._data[ReflData.OFF_OFF] = data if self.name.find("Off_Off")>0: ws_name = self.name.replace("Off_Off", "On_Off") if AnalysisDataService.doesExist(ws_name): self._data[ReflData.ON_OFF] = DataSet(ws_name) self._data[ReflData.ON_OFF].load(True, True) ws_name = self.name.replace("Off_Off", "Off_On") if AnalysisDataService.doesExist(ws_name): self._data[ReflData.OFF_ON] = DataSet(ws_name) self._data[ReflData.OFF_ON].load(True, True) ws_name = self.name.replace("Off_Off", "On_On") if AnalysisDataService.doesExist(ws_name): self._data[ReflData.ON_ON] = DataSet(ws_name) self._data[ReflData.ON_ON].load(True, True)
def update_data(self, dataset_control, min_control, max_control, scale_control): """ Update a data set @param dataset_control: combo box with the file path or workspace name @param min_control: text widget containing the minimum Q of the overlap region @param max_control: text widget containing the maximum Q of the overlap region @param scale_control: text widget containing the scale (can be input or output) """ data_object = None file_in = str(dataset_control.lineEdit().text()) if len(file_in.strip()) == 0: data_object = None elif os.path.isfile(file_in) or AnalysisDataService.doesExist(file_in): data_object = DataSet(file_in) try: data_object.load(True) except (AttributeError, ImportError, NameError, TypeError, ValueError, Warning): data_object = None util.set_valid(dataset_control.lineEdit(), False) QtGui.QMessageBox.warning( self, "Error loading file", "Could not load %s.\nMake sure you pick the XML output from the reduction." % file_in) return if min_control is not None and max_control is not None \ and (len(min_control.text()) == 0 or len(max_control.text()) == 0): minx, maxx = data_object.get_range() min_control.setText("%-6.3g" % minx) max_control.setText("%-6.3g" % maxx) # Set the reference scale, unless we just loaded the data if len(scale_control.text()) == 0: scale_control.setText("1.0") else: scale = util._check_and_get_float_line_edit(scale_control) data_object.set_scale(scale) util.set_valid(dataset_control.lineEdit(), True) else: data_object = None util.set_valid(dataset_control.lineEdit(), False) self._plotted = False return data_object
def stitch_data(self, input_file, output_dir, q_min, q_step): from LargeScaleStructures.data_stitching import DataSet, Stitcher #, RangeSelector # Identify the data sets to stitch and order them workspace_list = [] _list_name = [] _list_ts = [] ws_list = AnalysisDataService.getObjectNames() for item in ws_list: if item.endswith('ts'): (_name, _ts) = item.split('_#') _list_name.append(item) _list_ts.append(_ts) _name_ts = zip(_list_ts, _list_name) _name_ts.sort() _ts_sorted, workspace_list = zip(*_name_ts) # Stitch the data s = Stitcher() q_max = 0 for item in workspace_list: data = DataSet(item) data.load(True, True) dummy_x_min, x_max = data.get_range() if x_max > q_max: q_max = x_max s.append(data) s.set_reference(0) s.compute() # Apply the scaling factors for data in s._data_sets: Scale(InputWorkspace=str(data), OutputWorkspace=data._ws_scaled, Operation="Multiply", Factor=data.get_scale()) SaveAscii(InputWorkspace=str(data), Filename=os.path.join(output_dir, '%s.txt' % str(data))) output_file = input_file.replace('.xml', '_reprocessed.txt') Logger("REFLReprocess").notice("Saving to %s" % output_file) output_ws = _average_y_of_same_x_(q_min, q_step, q_max) SaveAscii(InputWorkspace=output_ws, Filename=output_file)
def _scale_data_sets(self): """ Perform auto-scaling """ scale_to_unity = self._content.scale_to_one_chk.isChecked() min_q_unity = float(self._content.min_q_unity_edit.text()) max_q_unity = float(self._content.max_q_unity_edit.text()) s = Stitcher() refID = 0 # Get reference cross-section ref_pol = ReflData.OFF_OFF if self._content.off_on_radio.isChecked(): ref_pol = ReflData.OFF_ON elif self._content.on_off_radio.isChecked(): ref_pol = ReflData.ON_OFF elif self._content.on_on_radio.isChecked(): ref_pol = ReflData.ON_ON for i in range(len(self._workspace_list)): item = self._workspace_list[i] data = DataSet(item.name) data.load(True, True) item.set_user_data(data) # Set skipped points for all cross-section xmin, xmax = item.update_skipped() if item.is_selected(): data.set_scale(item.get_scale()) refID = i if scale_to_unity: scale = data.scale_to_unity(max(xmin,min_q_unity), min(xmax,max_q_unity)) data.set_scale(scale) item.set_scale(scale) ref_data = item.get_user_data(ref_pol) if ref_data is None: QtGui.QMessageBox.warning(self,\ "Invalid choice of reference cross-section",\ "The selected cross-section is empty, please select another one") return s.append(ref_data) if s.size()==0: Logger("Stitcher").notice("No data to scale") return s.set_reference(refID) s.compute() for item in self._workspace_list: data = item.get_user_data(ref_pol) xmin, xmax = item.get_common_range() data.apply_scale(xmin=xmin, xmax=xmax) scale = data.get_scale() item.set_scale(scale) self._stitcher = s self.plot_result()