def _shift_workspace(self, workspace, shift_factor): return s_api.ScaleX(InputWorkspace=workspace, Factor=shift_factor, OutputWorkspace="__shifted", Operation="Add", StoreInADS=False)
def PyExec(self): self._setup() if not self._use_corrections: logger.information('Not using corrections') if not self._use_can: logger.information('Not using container') prog_container = Progress(self, start=0.0, end=0.2, nreports=4) prog_container.report('Starting algorithm') # Units should be wavelength sample_unit = s_api.mtd[self._sample_ws_name].getAxis( 0).getUnit().unitID() self._convert_units_wavelength(sample_unit, self._sample_ws_name, self._sample_ws_wavelength, "Wavelength") if self._use_can: # Appy container shift if needed if self._shift_can: # Use temp workspace so we don't modify data prog_container.report('Shifting can') s_api.ScaleX(InputWorkspace=self._can_ws_name, OutputWorkspace=self._shifted_container, Factor=self._can_shift_factor, Operation='Add') logger.information('Container data shifted by %f' % self._can_shift_factor) else: prog_container.report('Cloning Workspace') s_api.CloneWorkspace(InputWorkspace=self._can_ws_name, OutputWorkspace=self._shifted_container) # Apply container scale factor if needed if self._scale_can: # Use temp workspace so we don't modify original data prog_container.report('Scaling can') s_api.Scale(InputWorkspace=self._shifted_container, OutputWorkspace=self._scaled_container, Factor=self._can_scale_factor, Operation='Multiply') logger.information('Container scaled by %f' % self._can_scale_factor) else: prog_container.report('Cloning Workspace') s_api.CloneWorkspace(InputWorkspace=self._shifted_container, OutputWorkspace=self._scaled_container) # Units should be wavelength can_unit = s_api.mtd[self._scaled_container].getAxis( 0).getUnit().unitID() self._convert_units_wavelength(can_unit, self._scaled_container, self._scaled_container_wavelength, "Wavelength") prog_corr = Progress(self, start=0.2, end=0.6, nreports=2) if self._use_corrections: prog_corr.report('Preprocessing corrections') self._pre_process_corrections() if self._use_can: # Use container factors prog_corr.report('Correcting sample and can') self._correct_sample_can() correction_type = 'sample_and_can_corrections' else: # Use sample factor only self._correct_sample() correction_type = 'sample_corrections_only' # Add corrections filename to log values prog_corr.report('Correcting sample') s_api.AddSampleLog(Workspace=self._output_ws_name, LogName='corrections_filename', LogType='String', LogText=self._corrections_ws_name) else: # Do simple subtraction self._subtract() correction_type = 'can_subtraction' # Add container filename to log values can_cut = self._can_ws_name.index('_') can_base = self._can_ws_name[:can_cut] prog_corr.report('Adding container filename') s_api.AddSampleLog(Workspace=self._output_ws_name, LogName='container_filename', LogType='String', LogText=can_base) prog_wrkflow = Progress(self, 0.6, 1.0, nreports=5) # Record the container scale factor if self._use_can and self._scale_can: prog_wrkflow.report('Adding container scaling') s_api.AddSampleLog(Workspace=self._output_ws_name, LogName='container_scale', LogType='Number', LogText=str(self._can_scale_factor)) # Record the container shift amount if self._use_can and self._shift_can: prog_wrkflow.report('Adding container shift') s_api.AddSampleLog(Workspace=self._output_ws_name, LogName='container_shift', LogType='Number', LogText=str(self._can_shift_factor)) # Record the type of corrections applied prog_wrkflow.report('Adding correction type') s_api.AddSampleLog(Workspace=self._output_ws_name, LogName='corrections_type', LogType='String', LogText=correction_type) # Add original sample as log entry sam_cut = self._sample_ws_name.index('_') sam_base = self._sample_ws_name[:sam_cut] prog_wrkflow.report('Adding sample filename') s_api.AddSampleLog(Workspace=self._output_ws_name, LogName='sample_filename', LogType='String', LogText=sam_base) # Convert Units back to original self._convert_units_wavelength(sample_unit, self._output_ws_name, self._output_ws_name, sample_unit) self.setPropertyValue('OutputWorkspace', self._output_ws_name) # Remove temporary workspaces prog_wrkflow.report('Deleting Workspaces') if self._corrections in s_api.mtd: s_api.DeleteWorkspace(self._corrections) if self._scaled_container in s_api.mtd: s_api.DeleteWorkspace(self._scaled_container) if self._shifted_container in s_api.mtd: s_api.DeleteWorkspace(self._shifted_container) if self._scaled_container_wavelength in s_api.mtd: s_api.DeleteWorkspace(self._scaled_container_wavelength) if self._sample_ws_wavelength in s_api.mtd: s_api.DeleteWorkspace(self._sample_ws_wavelength) prog_wrkflow.report('Algorithm Complete')