def scale_monitors(self, slice_factor): monitor_workspace = self.getProperty("InputWorkspaceMonitor").value if slice_factor < 1.0: monitor_workspace = get_scaled_workspace(monitor_workspace, slice_factor) append_to_sans_file_tag(monitor_workspace, "_sliced") self.setProperty("OutputWorkspaceMonitor", monitor_workspace)
def PyExec(self): workspace = get_input_workspace_as_copy_if_not_same_as_output_workspace( self) progress = Progress(self, start=0.0, end=1.0, nreports=3) # Convert the units into wavelength progress.report("Converting workspace to wavelength units.") workspace = self._convert_units_to_wavelength(workspace) # Get the rebin option rebin_type = RebinType.from_string(self.getProperty("RebinMode").value) rebin_string = self._get_rebin_string(workspace) if rebin_type is RebinType.Rebin: rebin_options = { "InputWorkspace": workspace, "PreserveEvents": True, "Params": rebin_string } else: rebin_options = { "InputWorkspace": workspace, "Params": rebin_string } # Perform the rebin progress.report("Performing rebin.") workspace = self._perform_rebin(rebin_type, rebin_options, workspace) append_to_sans_file_tag(workspace, "_toWavelength") self.setProperty("OutputWorkspace", workspace) progress.report("Finished converting to wavelength.")
def PyExec(self): workspace = get_input_workspace_as_copy_if_not_same_as_output_workspace( self) wavelength_pairs: List[Tuple[float, float]] = json.loads( self.getProperty(self.WAV_PAIRS).value) progress = Progress(self, start=0.0, end=1.0, nreports=1 + len(wavelength_pairs)) # 1 - convert units # Convert the units into wavelength progress.report("Converting workspace to wavelength units.") workspace = self._convert_units_to_wavelength(workspace) # Get the rebin option output_group = WorkspaceGroup() for pair in wavelength_pairs: rebin_string = self._get_rebin_string(workspace, *pair) progress.report(f"Converting wavelength range: {rebin_string}") # Perform the rebin rebin_options = self._get_rebin_params(rebin_string, workspace) out_ws = self._perform_rebin(rebin_options) append_to_sans_file_tag(out_ws, "_toWavelength") output_group.addWorkspace(out_ws) self.setProperty("OutputWorkspace", output_group)
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) progress = Progress(self, start=0.0, end=1.0, nreports=3) input_workspace = self.getProperty("InputWorkspace").value data_type_as_string = self.getProperty("DataType").value data_type = DataType.from_string(data_type_as_string) slicer = SliceEventFactory.create_slicer(state, input_workspace, data_type) slice_info = state.slice # Perform the slicing progress.report("Starting to slice the workspace.") sliced_workspace, slice_factor = slicer.create_slice(input_workspace, slice_info) # Scale the monitor accordingly progress.report("Scaling the monitors.") self.scale_monitors(slice_factor) # Set the outputs append_to_sans_file_tag(sliced_workspace, "_sliced") self.setProperty("OutputWorkspace", sliced_workspace) self.setProperty("SliceEventFactor", slice_factor) progress.report("Finished slicing.")
def PyExec(self): # State state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager( state_property_manager) wavelength_state = state.wavelength # Input workspace workspace = get_input_workspace_as_copy_if_not_same_as_output_workspace( self) wavelength_name = "SANSConvertToWavelengthAndRebin" wavelength_options = { "InputWorkspace": workspace, "WavelengthLow": wavelength_state.wavelength_low, "WavelengthHigh": wavelength_state.wavelength_high, "WavelengthStep": wavelength_state.wavelength_step, "WavelengthStepType": RangeStepType.to_string(wavelength_state.wavelength_step_type), "RebinMode": RebinType.to_string(wavelength_state.rebin_type) } wavelength_alg = create_unmanaged_algorithm(wavelength_name, **wavelength_options) wavelength_alg.setPropertyValue("OutputWorkspace", EMPTY_NAME) wavelength_alg.setProperty("OutputWorkspace", workspace) wavelength_alg.execute() converted_workspace = wavelength_alg.getProperty( "OutputWorkspace").value append_to_sans_file_tag(converted_workspace, "_wavelength") self.setProperty("OutputWorkspace", converted_workspace)
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) progress = Progress(self, start=0.0, end=1.0, nreports=3) input_workspace = self.getProperty("InputWorkspace").value data_type_as_string = self.getProperty("DataType").value data_type = DataType.from_string(data_type_as_string) slicer = SliceEventFactory.create_slicer(state, input_workspace, data_type) slice_info = state.slice # Perform the slicing progress.report("Starting to slice the workspace.") sliced_workspace, slice_factor = slicer.create_slice(input_workspace, slice_info) # Scale the monitor accordingly progress.report("Scaling the monitors.") self.scale_monitors(slice_factor) # Set the outputs append_to_sans_file_tag(sliced_workspace, "_sliced") self.setProperty("OutputWorkspace", sliced_workspace) self.setProperty("SliceEventFactor", slice_factor) progress.report("Finished slicing.")
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager( state_property_manager) component = self._get_component() # Get the correct SANS masking strategy from create_masker workspace = self.getProperty("Workspace").value masker = create_masker(state, component) # Perform the masking number_of_masking_options = 7 progress = Progress(self, start=0.0, end=1.0, nreports=number_of_masking_options) mask_info = state.mask workspace = masker.mask_workspace(mask_info, workspace, component, progress) append_to_sans_file_tag(workspace, "_masked") self.setProperty("Workspace", workspace) progress.report("Completed masking the workspace")
def PyExec(self): # Get the correct SANS move strategy from the SANSMaskFactory workspace = self.getProperty("InputWorkspace").value # Component to crop component = self._get_component(workspace) progress = Progress(self, start=0.0, end=1.0, nreports=2) progress.report("Starting to crop component {0}".format(component)) # Crop to the component crop_name = "CropToComponent" crop_options = { "InputWorkspace": workspace, "OutputWorkspace": EMPTY_NAME, "ComponentNames": component } crop_alg = create_unmanaged_algorithm(crop_name, **crop_options) crop_alg.execute() output_workspace = crop_alg.getProperty("OutputWorkspace").value # Change the file tag and set the output append_to_sans_file_tag(output_workspace, "_cropped") self.setProperty("OutputWorkspace", output_workspace) progress.report("Finished cropping")
def PyExec(self): workspace = get_input_workspace_as_copy_if_not_same_as_output_workspace(self) progress = Progress(self, start=0.0, end=1.0, nreports=3) # Convert the units into wavelength progress.report("Converting workspace to wavelength units.") workspace = self._convert_units_to_wavelength(workspace) # Get the rebin option rebin_type = RebinType.from_string(self.getProperty("RebinMode").value) rebin_string = self._get_rebin_string(workspace) if rebin_type is RebinType.Rebin: rebin_options = {"InputWorkspace": workspace, "PreserveEvents": True, "Params": rebin_string} else: rebin_options = {"InputWorkspace": workspace, "Params": rebin_string} # Perform the rebin progress.report("Performing rebin.") workspace = self._perform_rebin(rebin_type, rebin_options, workspace) append_to_sans_file_tag(workspace, "_toWavelength") self.setProperty("OutputWorkspace", workspace) progress.report("Finished converting to wavelength.")
def mask_workspace(state, component_as_string, workspace): assert (state is not dict) component = DetectorType(component_as_string) # Get the correct SANS masking strategy from create_masker masker = create_masker(state, component) # Perform the masking mask_info = state.mask workspace = masker.mask_workspace(mask_info, workspace, component) append_to_sans_file_tag(workspace, "_masked") return workspace
def _convert_to_histogram(self, workspace): if isinstance(workspace, IEventWorkspace): convert_name = "RebinToWorkspace" convert_options = {"WorkspaceToRebin": workspace, "WorkspaceToMatch": workspace, "OutputWorkspace": "OutputWorkspace", "PreserveEvents": False} convert_alg = create_child_algorithm(self, convert_name, **convert_options) convert_alg.execute() workspace = convert_alg.getProperty("OutputWorkspace").value append_to_sans_file_tag(workspace, "_histogram") return workspace
def _convert_to_histogram(self, workspace): if isinstance(workspace, IEventWorkspace): convert_name = "RebinToWorkspace" convert_options = {"WorkspaceToRebin": workspace, "WorkspaceToMatch": workspace, "OutputWorkspace": "OutputWorkspace", "PreserveEvents": False} convert_alg = create_child_algorithm(self, convert_name, **convert_options) convert_alg.execute() workspace = convert_alg.getProperty("OutputWorkspace").value append_to_sans_file_tag(workspace, "_histogram") return workspace
def slice_sans_event(state_slice, input_ws, input_ws_monitor, data_type_str="Sample"): """ Takes an event slice from an event workspace :param state_slice: The state.slice object :param input_ws: The input workspace. If it is an event workspace, then the slice is taken. In case of a Workspace2D the original workspace is returned :param input_ws_monitor: The monitor workspace associated with the main input workspace. :param data_type_str: The component of the instrument which is to be reduced. Allowed values: ['Sample', 'Can'] :return: A dict with the following: 'SliceEventFactor': The factor of the event slicing. This corresponds to the proportion of the the total proton charge, which the slice corresponds to. 'OutputWorkspace' : The slice workspace 'OutputWorkspaceMonitor' : The output monitor workspace which has the correct slice factor applied to it. """ data_type = DataType(data_type_str) # This should be removed in the future when cycle 19/1 data is unlikely to be processed by users # This prevents time slicing falling over, since we wrap around and get -0 _clean_logs(ws=input_ws, estimate_logs=True) if isinstance(input_ws, Workspace2D): sliced_workspace = input_ws slice_factor = 1.0 else: sliced_workspace, slice_factor = _create_slice(workspace=input_ws, slice_info=state_slice, data_type=data_type) # Scale the monitor accordingly slice_monitor = _scale_monitors(slice_factor=slice_factor, input_monitor_ws=input_ws_monitor) # Set the outputs append_to_sans_file_tag(sliced_workspace, "_sliced") to_return = { "OutputWorkspace": sliced_workspace, "SliceEventFactor": slice_factor, "OutputWorkspaceMonitor": slice_monitor } return to_return
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) # Perform either a 1D reduction or a 2D reduction convert_to_q = state.convert_to_q reduction_dimensionality = convert_to_q.reduction_dimensionality if reduction_dimensionality is ReductionDimensionality.OneDim: output_workspace, sum_of_counts_workspace, sum_of_norms_workspace = self._run_q_1d(state) else: output_workspace, sum_of_counts_workspace, sum_of_norms_workspace = self._run_q_2d(state) # Set the output append_to_sans_file_tag(output_workspace, "_convertq") self.setProperty("OutputWorkspace", output_workspace) if sum_of_counts_workspace and sum_of_norms_workspace: self._set_partial_workspaces(sum_of_counts_workspace, sum_of_norms_workspace)
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) # Perform either a 1D reduction or a 2D reduction convert_to_q = state.convert_to_q reduction_dimensionality = convert_to_q.reduction_dimensionality if reduction_dimensionality is ReductionDimensionality.OneDim: output_workspace, sum_of_counts_workspace, sum_of_norms_workspace = self._run_q_1d(state) else: output_workspace, sum_of_counts_workspace, sum_of_norms_workspace = self._run_q_2d(state) # Set the output append_to_sans_file_tag(output_workspace, "_convertq") self.setProperty("OutputWorkspace", output_workspace) output_parts = self.getProperty("OutputParts").value if output_parts: self._set_partial_workspaces(sum_of_counts_workspace, sum_of_norms_workspace)
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) component = self._get_component() # Get the correct SANS masking strategy from create_masker workspace = self.getProperty("Workspace").value masker = create_masker(state, component) # Perform the masking number_of_masking_options = 7 progress = Progress(self, start=0.0, end=1.0, nreports=number_of_masking_options) mask_info = state.mask workspace = masker.mask_workspace(mask_info, workspace, component, progress) append_to_sans_file_tag(workspace, "_masked") self.setProperty("Workspace", workspace) progress.report("Completed masking the workspace")
def convert_workspace(workspace, state_convert_to_q, output_summed_parts=False, wavelength_adj_workspace=None, pixel_adj_workspace=None, wavelength_and_pixel_adj_workspace=None): """ Converts workspace from wavelengths to momentum Transfer :param workspace: Workspace in wavelength :param state_convert_to_q The convert_to_q field of the SANSState object :param wavelength_adj_workspace: (Optional) The Wavelength adjustment workspace :param pixel_adj_workspace: (Optional) The pixel adjustment workspace :param wavelength_and_pixel_adj_workspace (Optional) The wavelength and pixel adjustment workspace :param output_summed_parts: (Optional) If set to true the partial sum of counts and normalisation is returned :return: The output workspace in q if output_summed_parts is False. Otherwise a dict containing 'output', 'counts_summed' and 'norm_summed' with respective workspaces """ # Perform either a 1D reduction or a 2D reduction reduction_dimensionality = state_convert_to_q.reduction_dimensionality if reduction_dimensionality is ReductionDimensionality.ONE_DIM: output_workspace, sum_of_counts_workspace, sum_of_norms_workspace = \ _run_q_1d(workspace, output_summed_parts, conv_to_q_state=state_convert_to_q, pixel_adj_ws=pixel_adj_workspace, wavelength_adj_ws=wavelength_adj_workspace, wavelength_and_pixel_adj_ws=wavelength_and_pixel_adj_workspace) else: output_workspace, sum_of_counts_workspace, sum_of_norms_workspace = \ _run_q_2d(workspace, output_summed_parts, state_convert_to_q=state_convert_to_q, wavelength_adj_ws=wavelength_adj_workspace, pixel_adj_ws=pixel_adj_workspace) # Set the output append_to_sans_file_tag(output_workspace, "_convertq") if output_summed_parts: to_return = { 'output': output_workspace, 'counts_summed': sum_of_counts_workspace, 'norm_summed': sum_of_norms_workspace } return to_return else: return output_workspace
def PyExec(self): state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) # Get the correct SANS move strategy from the SANSMaskFactory workspace = self.getProperty("InputWorkspace").value progress = Progress(self, start=0.0, end=1.0, nreports=3) # Multiply by the absolute scale progress.report("Applying absolute scale.") workspace = self._multiply_by_absolute_scale(workspace, state) # Divide by the sample volume progress.report("Dividing by the sample volume.") workspace = self._divide_by_volume(workspace, state) append_to_sans_file_tag(workspace, "_scale") self.setProperty("OutputWorkspace", workspace) progress.report("Finished applying absolute scale")
def PyExec(self): state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager( state_property_manager) # Get the correct SANS move strategy from the SANSMaskFactory workspace = self.getProperty("InputWorkspace").value progress = Progress(self, start=0.0, end=1.0, nreports=3) # Multiply by the absolute scale progress.report("Applying absolute scale.") workspace = self._multiply_by_absolute_scale(workspace, state) # Divide by the sample volume progress.report("Dividing by the sample volume.") workspace = self._divide_by_volume(workspace, state) append_to_sans_file_tag(workspace, "_scale") self.setProperty("OutputWorkspace", workspace) progress.report("Finished applying absolute scale")
def PyExec(self): # Get the correct SANS move strategy from the SANSMaskFactory workspace = self.getProperty("InputWorkspace").value # Component to crop component = self._get_component(workspace) progress = Progress(self, start=0.0, end=1.0, nreports=2) progress.report("Starting to crop component {0}".format(component)) # Crop to the component crop_name = "CropToComponent" crop_options = {"InputWorkspace": workspace, "OutputWorkspace": EMPTY_NAME, "ComponentNames": component} crop_alg = create_unmanaged_algorithm(crop_name, **crop_options) crop_alg.execute() output_workspace = crop_alg.getProperty("OutputWorkspace").value # Change the file tag and set the output append_to_sans_file_tag(output_workspace, "_cropped") self.setProperty("OutputWorkspace", output_workspace) progress.report("Finished cropping")
def PyExec(self): # State state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) wavelength_state = state.wavelength # Input workspace workspace = get_input_workspace_as_copy_if_not_same_as_output_workspace(self) wavelength_name = "SANSConvertToWavelengthAndRebin" wavelength_options = {"InputWorkspace": workspace, "WavelengthLow": wavelength_state.wavelength_low[0], "WavelengthHigh": wavelength_state.wavelength_high[0], "WavelengthStep": wavelength_state.wavelength_step, "WavelengthStepType": RangeStepType.to_string( wavelength_state.wavelength_step_type), "RebinMode": RebinType.to_string(wavelength_state.rebin_type)} wavelength_alg = create_unmanaged_algorithm(wavelength_name, **wavelength_options) wavelength_alg.setPropertyValue("OutputWorkspace", EMPTY_NAME) wavelength_alg.setProperty("OutputWorkspace", workspace) wavelength_alg.execute() converted_workspace = wavelength_alg.getProperty("OutputWorkspace").value append_to_sans_file_tag(converted_workspace, "_wavelength") self.setProperty("OutputWorkspace", converted_workspace)
def _scale_monitors(slice_factor, input_monitor_ws): if slice_factor < 1.0: input_monitor_ws = _get_scaled_workspace(input_monitor_ws, slice_factor) append_to_sans_file_tag(input_monitor_ws, "_sliced") return input_monitor_ws
def scale_monitors(self, slice_factor): monitor_workspace = self.getProperty("InputWorkspaceMonitor").value if slice_factor < 1.0: monitor_workspace = get_scaled_workspace(monitor_workspace, slice_factor) append_to_sans_file_tag(monitor_workspace, "_sliced") self.setProperty("OutputWorkspaceMonitor", monitor_workspace)
def scale_workspace(workspace, instrument, state_scale): workspace = _multiply_by_abs_scale(instrument, state_scale, workspace) workspace = _divide_by_sample_volume(workspace, scale_info=state_scale) append_to_sans_file_tag(workspace, "_scale") return workspace