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) 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) calculate_transmission_state = state.adjustment.calculate_transmission # The calculation of the transmission has the following steps: # 1. Get all spectrum numbers which take part in the transmission calculation # 2. Clean up the transmission and direct workspaces, ie peak prompt correction, flat background calculation, # wavelength conversion and rebinning of the data. # 3. Run the CalculateTransmission algorithm transmission_workspace = self.getProperty( "TransmissionWorkspace").value direct_workspace = self.getProperty("DirectWorkspace").value incident_monitor_spectrum_number = calculate_transmission_state.incident_monitor if incident_monitor_spectrum_number is None: incident_monitor_spectrum_number = calculate_transmission_state.default_incident_monitor # 1. Get relevant spectra detector_id_incident_monitor = get_detector_id_for_spectrum_number( transmission_workspace, incident_monitor_spectrum_number) detector_ids_roi, detector_id_transmission_monitor, detector_id_default_transmission_monitor = \ self._get_detector_ids_for_transmission_calculation(transmission_workspace, calculate_transmission_state) all_detector_ids = [detector_id_incident_monitor] if len(detector_ids_roi) > 0: all_detector_ids.extend(detector_ids_roi) elif detector_id_transmission_monitor is not None: all_detector_ids.append(detector_id_transmission_monitor) elif detector_id_default_transmission_monitor is not None: all_detector_ids.append(detector_id_default_transmission_monitor) else: raise RuntimeError( "SANSCalculateTransmission: No region of interest or transmission monitor selected." ) # 2. Clean transmission data data_type_string = self.getProperty("DataType").value data_type = DataType.from_string(data_type_string) transmission_workspace = self._get_corrected_wavelength_workspace( transmission_workspace, all_detector_ids, calculate_transmission_state) direct_workspace = self._get_corrected_wavelength_workspace( direct_workspace, all_detector_ids, calculate_transmission_state) # 3. Fit output_workspace, unfitted_transmission_workspace = \ self._perform_fit(transmission_workspace, direct_workspace, detector_ids_roi, detector_id_transmission_monitor, detector_id_default_transmission_monitor, detector_id_incident_monitor, calculate_transmission_state, data_type) self.setProperty("OutputWorkspace", output_workspace) if unfitted_transmission_workspace: self.setProperty("UnfittedData", unfitted_transmission_workspace)
def validateInputs(self): errors = dict() # Check that the input can be converted into the right state object state_property_manager = self.getProperty("SANSState").value try: state = create_deserialized_sans_state_from_property_manager( state_property_manager) state.property_manager = state_property_manager state.validate() except ValueError as err: errors.update({"SANSCalculateTransmission": str(err)}) state = None if state is not None: transmission_workspace = self.getProperty( "TransmissionWorkspace").value calculate_transmission_state = state.adjustment.calculate_transmission try: incident_monitor = calculate_transmission_state.incident_monitor if incident_monitor is None: incident_monitor = calculate_transmission_state.default_incident_monitor transmission_workspace.getIndexFromSpectrumNumber( incident_monitor) except RuntimeError: errors.update({ "IncidentMonitorSpectrumNumber": "The spectrum number for the incident monitor spectrum " "does not seem to exist for the transmission" " workspace." }) if state is not None: calculate_transmission_state = state.adjustment.calculate_transmission fit = calculate_transmission_state.fit data_type_string = self.getProperty("DataType").value data_type = DataType.from_string(data_type_string) sample = fit[DataType.to_string(DataType.Sample)] can = fit[DataType.to_string(DataType.Can)] if data_type is DataType.Sample and sample.fit_type is None: errors.update({ "DataType": "There does not seem to be a fit type set for the selected data type" }) if data_type is DataType.Can and can.fit_type is None: errors.update({ "DataType": "There does not seem to be a fit type set for the selected data type" }) return errors
def PyExec(self): # Read the state state_property_manager = self.getProperty("SANSState").value state = create_deserialized_sans_state_from_property_manager(state_property_manager) calculate_transmission_state = state.adjustment.calculate_transmission # The calculation of the transmission has the following steps: # 1. Get all spectrum numbers which take part in the transmission calculation # 2. Clean up the transmission and direct workspaces, ie peak prompt correction, flat background calculation, # wavelength conversion and rebinning of the data. # 3. Run the CalculateTransmission algorithm transmission_workspace = self.getProperty("TransmissionWorkspace").value direct_workspace = self.getProperty("DirectWorkspace").value incident_monitor_spectrum_number = calculate_transmission_state.incident_monitor if incident_monitor_spectrum_number is None: incident_monitor_spectrum_number = calculate_transmission_state.default_incident_monitor # 1. Get relevant spectra detector_id_incident_monitor = get_detector_id_for_spectrum_number(transmission_workspace, incident_monitor_spectrum_number) detector_ids_roi, detector_id_transmission_monitor, detector_id_default_transmission_monitor = \ self._get_detector_ids_for_transmission_calculation(transmission_workspace, calculate_transmission_state) all_detector_ids = [detector_id_incident_monitor] if len(detector_ids_roi) > 0: all_detector_ids.extend(detector_ids_roi) elif detector_id_transmission_monitor is not None: all_detector_ids.append(detector_id_transmission_monitor) elif detector_id_default_transmission_monitor is not None: all_detector_ids.append(detector_id_default_transmission_monitor) else: raise RuntimeError("SANSCalculateTransmission: No region of interest or transmission monitor selected.") # 2. Clean transmission data data_type_string = self.getProperty("DataType").value data_type = DataType.from_string(data_type_string) transmission_workspace = self._get_corrected_wavelength_workspace(transmission_workspace, all_detector_ids, calculate_transmission_state) direct_workspace = self._get_corrected_wavelength_workspace(direct_workspace, all_detector_ids, calculate_transmission_state) # 3. Fit output_workspace, unfitted_transmission_workspace = \ self._perform_fit(transmission_workspace, direct_workspace, detector_ids_roi, detector_id_transmission_monitor, detector_id_default_transmission_monitor, detector_id_incident_monitor, calculate_transmission_state, data_type) self.setProperty("OutputWorkspace", output_workspace) if unfitted_transmission_workspace: self.setProperty("UnfittedData", unfitted_transmission_workspace)
def validateInputs(self): errors = dict() # Check that the input can be converted into the right state object state_property_manager = self.getProperty("SANSState").value try: state = create_deserialized_sans_state_from_property_manager(state_property_manager) state.property_manager = state_property_manager state.validate() except ValueError as err: errors.update({"SANSCalculateTransmission": str(err)}) state = None if state is not None: transmission_workspace = self.getProperty("TransmissionWorkspace").value calculate_transmission_state = state.adjustment.calculate_transmission try: incident_monitor = calculate_transmission_state.incident_monitor if incident_monitor is None: incident_monitor = calculate_transmission_state.default_incident_monitor transmission_workspace.getIndexFromSpectrumNumber(incident_monitor) except RuntimeError: errors.update({"IncidentMonitorSpectrumNumber": "The spectrum number for the incident monitor spectrum " "does not seem to exist for the transmission" " workspace."}) if state is not None: calculate_transmission_state = state.adjustment.calculate_transmission fit = calculate_transmission_state.fit data_type_string = self.getProperty("DataType").value data_type = DataType.from_string(data_type_string) sample = fit[DataType.to_string(DataType.Sample)] can = fit[DataType.to_string(DataType.Can)] if data_type is DataType.Sample and sample.fit_type is None: errors.update({"DataType": "There does not seem to be a fit type set for the selected data type"}) if data_type is DataType.Can and can.fit_type is None: errors.update({"DataType": "There does not seem to be a fit type set for the selected data type"}) return errors