def PyExec(self): # Progress reporter for algorithm initialization prog_reporter = Progress(self, start=0.0, end=0.1, nreports=4) raw_xvals, raw_yvals, raw_error, error_ws = self.load_data( prog_reporter) # Convert the data to point data prog_reporter.report('Converting to point data') raw_data_ws = ConvertToPointData(error_ws, StoreInADS=False) raw_xvals = raw_data_ws.readX(0).copy() raw_yvals = raw_data_ws.readY(0).copy() raw_xvals, raw_yvals, raw_error = self.crop_data( raw_xvals, raw_yvals, raw_error, prog_reporter) # Find the best peaks (peakids, peak_table, refit_peak_table), baseline = self.process( raw_xvals, raw_yvals, raw_error, acceptance=self._acceptance, average_window=self._smooth_window, bad_peak_to_consider=self._bad_peak_to_consider, use_poisson=self._use_poisson_cost, peak_width_estimate=self._estimate_peak_sigma, fit_to_baseline=self._fit_to_baseline, prog_reporter=prog_reporter) if self._plot_peaks: self.plot_peaks(raw_xvals, raw_yvals, baseline, peakids) self.set_output_properties(peak_table, refit_peak_table)
def create_merged_workspace(self, workspace_list): if workspace_list: # get max number of bins and max X range max_num_bins = 0 for ws_name in workspace_list: if ws_name: ws = AnalysisDataService.retrieve(ws_name) max_num_bins = max(ws.blocksize(), max_num_bins) # create single ws for the merged data, use original ws as a template template_ws = next(ws for ws in workspace_list if ws is not None) merged_ws = WorkspaceFactory.create( AnalysisDataService.retrieve(template_ws), NVectors=NUM_FILES_PER_DETECTOR, XLength=max_num_bins, YLength=max_num_bins) # create a merged workspace based on every entry from workspace list for i in range(0, NUM_FILES_PER_DETECTOR): # load in ws - first check workspace exists if workspace_list[i]: ws = AnalysisDataService.retrieve(workspace_list[i]) # check if histogram data, and convert if necessary if ws.isHistogramData(): ws = ConvertToPointData(InputWorkspace=ws.name(), OutputWorkspace=ws.name()) # find max x val max_x = np.max(ws.readX(0)) # get current number of bins num_bins = ws.blocksize() # pad bins X_padded = np.empty(max_num_bins) X_padded.fill(max_x) X_padded[:num_bins] = ws.readX(0) Y_padded = np.zeros(max_num_bins) Y_padded[:num_bins] = ws.readY(0) E_padded = np.zeros(max_num_bins) E_padded[:num_bins] = ws.readE(0) # set row of merged workspace merged_ws.setX(i, X_padded) merged_ws.setY(i, Y_padded) merged_ws.setE(i, E_padded) # set y axis labels self.set_y_axis_labels(merged_ws, SPECTRUM_INDEX) # remove workspace from ADS DeleteWorkspace(ws) return merged_ws