def _perform_rebin(self, rebin_options): rebin_type = RebinType(self.getProperty("RebinMode").value) rebin_name = "Rebin" if rebin_type is RebinType.REBIN else "InterpolatingRebin" rebin_alg = create_unmanaged_algorithm(rebin_name, **rebin_options) rebin_alg.setPropertyValue("OutputWorkspace", EMPTY_NAME) rebin_alg.execute() return rebin_alg.getProperty("OutputWorkspace").value
def validateInputs(self): errors = dict() # Check the wavelength wavelength_json = self.getProperty(self.WAV_PAIRS).value try: wavelengths: List[Tuple[float, float]] = json.loads(wavelength_json) except JSONDecodeError as e: errors.update( {self.WAV_PAIRS: f"Failed to decode JSON. Exception was: {e}"}) return errors if not all( isinstance(internal_item, list) for internal_item in wavelengths): errors.update({ self.WAV_PAIRS: "A list of pairs (i.e. list of lists) is required." " A single pair must be container within an outer list too." }) return errors # The below checks aren't really possible as we don't have a clue what we have now def _check_individual_pair(wavelength_low, wavelength_high): if wavelength_low is not None and wavelength_high is not None and wavelength_low > wavelength_high: errors.update({ self.WAV_PAIRS: "The lower wavelength setting needs to be smaller " "than the higher wavelength setting." }) if wavelength_low is not None and wavelength_low < 0: errors.update({ self.WAV_PAIRS: "The wavelength cannot be smaller than 0." }) if wavelength_high is not None and wavelength_high < 0: errors.update({ self.WAV_PAIRS: "The wavelength cannot be smaller than 0." }) for pair in wavelengths: _check_individual_pair(*pair) wavelength_step = self.getProperty("WavelengthStep").value if wavelength_step is not None and wavelength_step < 0: errors.update({ "WavelengthStep": "The wavelength step cannot be smaller than 0." }) # Check the workspace workspace = self.getProperty("InputWorkspace").value rebin_type = RebinType(self.getProperty("RebinMode").value) if rebin_type is RebinType.INTERPOLATING_REBIN and isinstance( workspace, EventWorkspace): errors.update({ "RebinMode": "An interpolating rebin cannot be applied to an EventWorkspace." }) return errors
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(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 validateInputs(self): errors = dict() # Check the wavelength wavelength_low = self.getProperty("WavelengthLow").value wavelength_high = self.getProperty("WavelengthHigh").value if wavelength_low is not None and wavelength_high is not None and wavelength_low > wavelength_high: errors.update({"WavelengthLow": "The lower wavelength setting needs to be smaller " "than the higher wavelength setting."}) if wavelength_low is not None and wavelength_low < 0: errors.update({"WavelengthLow": "The wavelength cannot be smaller than 0."}) if wavelength_high is not None and wavelength_high < 0: errors.update({"WavelengthHigh": "The wavelength cannot be smaller than 0."}) wavelength_step = self.getProperty("WavelengthStep").value if wavelength_step is not None and wavelength_step < 0: errors.update({"WavelengthStep": "The wavelength step cannot be smaller than 0."}) # Check the workspace workspace = self.getProperty("InputWorkspace").value rebin_type = RebinType(self.getProperty("RebinMode").value) if rebin_type is RebinType.INTERPOLATING_REBIN and isinstance(workspace, EventWorkspace): errors.update({"RebinMode": "An interpolating rebin cannot be applied to an EventWorkspace."}) return errors
def _get_rebin_params(self, rebin_string, workspace): rebin_type = RebinType(self.getProperty("RebinMode").value) if rebin_type is RebinType.REBIN: rebin_options = { "InputWorkspace": workspace, "PreserveEvents": True, "Params": rebin_string } else: rebin_options = { "InputWorkspace": workspace, "Params": rebin_string } return rebin_options