Beispiel #1
0
    def PyExec(self):
        import TransmissionUtils
        sample_file = self.getPropertyValue("SampleDataFilename")
        empty_file = self.getPropertyValue("EmptyDataFilename")

        property_manager_name = self.getProperty("ReductionProperties").value
        property_manager = PropertyManagerDataService[property_manager_name]

        # Build the name we are going to give the transmission workspace
        sample_basename = os.path.basename(sample_file)
        empty_basename = os.path.basename(empty_file)
        entry_name = "Transmission%s%s" % (sample_basename, empty_basename)
        trans_ws_name = "__transmission_fit_%s" % sample_basename
        trans_ws = None

        if property_manager.existsProperty(entry_name):
            trans_ws_name = property_manager.getProperty(entry_name)
            if AnalysisDataService.doesExist(trans_ws_name):
                trans_ws = AnalysisDataService.retrieve(trans_ws_name)

        if trans_ws is None:
            # Load data files
            sample_mon_ws, empty_mon_ws, first_det, output_str, monitor_det_ID = TransmissionUtils.load_monitors(
                self, property_manager)
            trans_ws, raw_ws = TransmissionUtils.calculate_transmission(
                self, sample_mon_ws, empty_mon_ws, first_det, trans_ws_name,
                monitor_det_ID)

        # 2- Apply correction (Note: Apply2DTransCorr)
        if trans_ws is not None:
            input_ws = self.getProperty("InputWorkspace").value

            output_ws = TransmissionUtils.apply_transmission(
                self, input_ws, trans_ws)

            trans = trans_ws.dataY(0)[0]
            error = trans_ws.dataE(0)[0]

            if len(trans_ws.dataY(0)) == 1:
                self.setProperty("MeasuredTransmission", trans)
                self.setProperty("MeasuredError", error)
                output_str = "%s   T = %6.2g += %6.2g\n" % (output_str, trans,
                                                            error)

            self.setProperty("OutputWorkspace", output_ws)
            input_tr_name = self.getPropertyValue("TransmissionWorkspace")
            if len(input_tr_name.strip()) == 0:
                self.setPropertyValue("TransmissionWorkspace", trans_ws_name)
            self.setProperty("TransmissionWorkspace", trans_ws)

            if raw_ws is not None:
                raw_ws_name = "__transmission_raw_%s" % sample_basename
                self.setPropertyValue("RawTransmissionWorkspace", raw_ws_name)
                self.setProperty("RawTransmissionWorkspace", raw_ws)
            output_msg = "Transmission correction applied [%s]\n%s\n" % (
                trans_ws_name, output_str)
        else:
            output_msg = "Transmission correction had errors\n%s\n" % output_str

        self.setPropertyValue("OutputMessage", output_msg)
    def PyExec(self):
        import TransmissionUtils

        sample_file = self.getPropertyValue("SampleDataFilename")
        empty_file = self.getPropertyValue("EmptyDataFilename")

        property_manager_name = self.getProperty("ReductionProperties").value
        property_manager = PropertyManagerDataService.retrieve(property_manager_name)

        # Build the name we are going to give the transmission workspace
        sample_basename = os.path.basename(sample_file)
        empty_basename = os.path.basename(empty_file)
        entry_name = "Transmission%s%s" % (sample_basename, empty_basename)
        trans_ws_name = "__transmission_fit_%s" % sample_basename
        trans_ws = None

        if property_manager.existsProperty(entry_name):
            trans_ws_name = property_manager.getProperty(entry_name)
            if AnalysisDataService.doesExist(trans_ws_name):
                trans_ws = AnalysisDataService.retrieve(trans_ws_name)

        if trans_ws is None:
            # Load data files
            sample_mon_ws, empty_mon_ws, first_det, output_str, monitor_det_ID = TransmissionUtils.load_monitors(
                self, property_manager
            )
            trans_ws, raw_ws = TransmissionUtils.calculate_transmission(
                self, sample_mon_ws, empty_mon_ws, first_det, trans_ws_name, monitor_det_ID
            )

        # 2- Apply correction (Note: Apply2DTransCorr)
        if trans_ws is not None:
            input_ws = self.getProperty("InputWorkspace").value

            output_ws = TransmissionUtils.apply_transmission(self, input_ws, trans_ws)

            trans = trans_ws.dataY(0)[0]
            error = trans_ws.dataE(0)[0]

            if len(trans_ws.dataY(0)) == 1:
                self.setProperty("MeasuredTransmission", trans)
                self.setProperty("MeasuredError", error)
                output_str = "%s   T = %6.2g += %6.2g\n" % (output_str, trans, error)

            self.setProperty("OutputWorkspace", output_ws)
            input_tr_name = self.getPropertyValue("TransmissionWorkspace")
            if len(input_tr_name.strip()) == 0:
                self.setPropertyValue("TransmissionWorkspace", trans_ws_name)
            self.setProperty("TransmissionWorkspace", trans_ws)

            if raw_ws is not None:
                raw_ws_name = "__transmission_raw_%s" % sample_basename
                self.setPropertyValue("RawTransmissionWorkspace", raw_ws_name)
                self.setProperty("RawTransmissionWorkspace", raw_ws)
            output_msg = "Transmission correction applied [%s]\n%s\n" % (trans_ws_name, output_str)
        else:
            output_msg = "Transmission correction had errors\n%s\n" % output_str

        self.setPropertyValue("OutputMessage", output_msg)
            def _crop_and_compute(wl_min_prop, wl_max_prop, suffix):
                # Get the wavelength band from the run properties
                if workspace.getRun().hasProperty(wl_min_prop):
                    wl_min = workspace.getRun().getProperty(wl_min_prop).value
                else:
                    raise RuntimeError(
                        "DirectBeamTransmission could not retrieve the %s property"
                        % wl_min_prop)

                if workspace.getRun().hasProperty(wl_max_prop):
                    wl_max = workspace.getRun().getProperty(wl_max_prop).value
                else:
                    raise RuntimeError(
                        "DirectBeamTransmission could not retrieve the %s property"
                        % wl_max_prop)

                rebin_params = "%4.1f,%4.1f,%4.1f" % (wl_min, 0.1, wl_max)
                alg = TransmissionUtils.simple_algorithm(
                    "Rebin", {
                        "InputWorkspace": sample_mon_ws,
                        "OutputWorkspace": "__sample_mon_" + suffix,
                        "Params": rebin_params,
                        "PreserveEvents": False
                    })
                sample_ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm(
                    "Rebin", {
                        "InputWorkspace": empty_mon_ws,
                        "OutputWorkspace": "__empty_mon_" + suffix,
                        "Params": rebin_params,
                        "PreserveEvents": False
                    })
                empty_ws = alg.getProperty("OutputWorkspace").value
                trans_ws, raw_ws = TransmissionUtils.calculate_transmission(
                    self, sample_ws, empty_ws, first_det,
                    "__transmission_" + suffix)
                alg = TransmissionUtils.simple_algorithm(
                    "RebinToWorkspace", {
                        "WorkspaceToRebin": trans_ws,
                        "WorkspaceToMatch": workspace,
                        "OutputWorkspace": "__transmission_" + suffix,
                        "PreserveEvents": False
                    })
                trans_ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm(
                    "RebinToWorkspace", {
                        "WorkspaceToRebin": raw_ws,
                        "WorkspaceToMatch": workspace,
                        "OutputWorkspace": "__transmission_unfitted_" + suffix,
                        "PreserveEvents": False
                    })
                raw_ws = alg.getProperty("OutputWorkspace").value

                return trans_ws, raw_ws
            def _crop_and_compute(wl_min_prop, wl_max_prop, suffix):
                # Get the wavelength band from the run properties
                if workspace.getRun().hasProperty(wl_min_prop):
                    wl_min = workspace.getRun().getProperty(wl_min_prop).value
                else:
                    raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_min_prop
                
                if workspace.getRun().hasProperty(wl_max_prop):
                    wl_max = workspace.getRun().getProperty(wl_max_prop).value
                else:
                    raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_max_prop
                
                rebin_params = "%4.1f,%4.1f,%4.1f" % (wl_min, 0.1, wl_max)
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                         {"InputWorkspace": workspace,
                                                          "OutputWorkspace": input_ws_name+suffix,
                                                          "Params": rebin_params,
                                                          "PreserveEvents": False
                                                          })
                ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                   {"InputWorkspace": sample_mon_ws,
                                                    "OutputWorkspace": "__sample_mon_"+suffix,
                                                    "Params": rebin_params,
                                                    "PreserveEvents": False
                                                    })
                sample_ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                   {"InputWorkspace": empty_mon_ws,
                                                    "OutputWorkspace": "__empty_mon_"+suffix,
                                                    "Params": rebin_params,
                                                    "PreserveEvents": False
                                                    })
                empty_ws = alg.getProperty("OutputWorkspace").value
                trans_ws = TransmissionUtils.calculate_transmission(self, 
                                                                    sample_ws, 
                                                                    empty_ws, 
                                                                    first_det, 
                                                                    "__transmission_"+suffix)
                alg = TransmissionUtils.simple_algorithm("RebinToWorkspace",
                                                   {"WorkspaceToRebin": trans_ws,
                                                    "WorkspaceToMatch": workspace,
                                                    "OutputWorkspace": "__transmission_"+suffix,
                                                    "PreserveEvents": False
                                                    })
                trans_ws = alg.getProperty("OutputWorkspace").value 

                return trans_ws
    def _with_frame_skipping(self, workspace):
        """
            Perform transmission correction assuming frame-skipping
        """
        import TransmissionUtils
        input_ws_name = self.getPropertyValue('InputWorkspace')
        sample_file = self.getPropertyValue("SampleDataFilename")
        empty_file = self.getPropertyValue("EmptyDataFilename")
        
        property_manager_name = self.getProperty("ReductionProperties").value
        property_manager = PropertyManagerDataService.retrieve(property_manager_name)
        
        # Build the name we are going to give the transmission workspace
        sample_basename = os.path.basename(sample_file)
        empty_basename = os.path.basename(empty_file)
        entry_name = "Transmission%s%s" % (sample_basename, empty_basename)
        trans_ws_name = "__transmission_fit_%s" % sample_basename
        trans_ws = None
        
        if property_manager.existsProperty(entry_name):
            trans_ws_name = property_manager.getProperty(entry_name)
            if AnalysisDataService.doesExist(trans_ws_name):
                trans_ws = AnalysisDataService.retrieve(trans_ws_name)

        output_str = ""
        if trans_ws is None:
            trans_ws_name = "transmission_fit_"+input_ws_name
            # Load data files
            sample_mon_ws, empty_mon_ws, first_det, output_str, monitor_det_ID = TransmissionUtils.load_monitors(self, property_manager)
            
            def _crop_and_compute(wl_min_prop, wl_max_prop, suffix):
                # Get the wavelength band from the run properties
                if workspace.getRun().hasProperty(wl_min_prop):
                    wl_min = workspace.getRun().getProperty(wl_min_prop).value
                else:
                    raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_min_prop
                
                if workspace.getRun().hasProperty(wl_max_prop):
                    wl_max = workspace.getRun().getProperty(wl_max_prop).value
                else:
                    raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_max_prop
                
                rebin_params = "%4.1f,%4.1f,%4.1f" % (wl_min, 0.1, wl_max)
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                         {"InputWorkspace": workspace,
                                                          "OutputWorkspace": input_ws_name+suffix,
                                                          "Params": rebin_params,
                                                          "PreserveEvents": False
                                                          })
                ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                   {"InputWorkspace": sample_mon_ws,
                                                    "OutputWorkspace": "__sample_mon_"+suffix,
                                                    "Params": rebin_params,
                                                    "PreserveEvents": False
                                                    })
                sample_ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                   {"InputWorkspace": empty_mon_ws,
                                                    "OutputWorkspace": "__empty_mon_"+suffix,
                                                    "Params": rebin_params,
                                                    "PreserveEvents": False
                                                    })
                empty_ws = alg.getProperty("OutputWorkspace").value
                trans_ws = TransmissionUtils.calculate_transmission(self, 
                                                                    sample_ws, 
                                                                    empty_ws, 
                                                                    first_det, 
                                                                    "__transmission_"+suffix)
                alg = TransmissionUtils.simple_algorithm("RebinToWorkspace",
                                                   {"WorkspaceToRebin": trans_ws,
                                                    "WorkspaceToMatch": workspace,
                                                    "OutputWorkspace": "__transmission_"+suffix,
                                                    "PreserveEvents": False
                                                    })
                trans_ws = alg.getProperty("OutputWorkspace").value 

                return trans_ws
                
            # First frame
            trans_frame_1 = _crop_and_compute("wavelength_min", "wavelength_max", "_frame1")
            
            # Second frame
            trans_frame_2 = _crop_and_compute("wavelength_min_frame2", "wavelength_max_frame2", "_frame2")
            
            alg = TransmissionUtils.simple_algorithm("Plus",
                                               {"LHSWorkspace": trans_frame_1,
                                                "RHSWorkspace": trans_frame_2,
                                                "OutputWorkspace": "__transmission",
                                                })
            trans_ws = alg.getProperty("OutputWorkspace").value
            
        # 2- Apply correction (Note: Apply2DTransCorr)
        #Apply angle-dependent transmission correction using the zero-angle transmission
        TransmissionUtils.apply_transmission(self, workspace, trans_ws)
Beispiel #6
0
    def _with_frame_skipping(self, workspace):
        """
            Perform transmission correction assuming frame-skipping
        """
        import TransmissionUtils
        input_ws_name = self.getPropertyValue('InputWorkspace')
        sample_file = self.getPropertyValue("SampleDataFilename")
        empty_file = self.getPropertyValue("EmptyDataFilename")

        property_manager_name = self.getProperty("ReductionProperties").value
        property_manager = PropertyManagerDataService.retrieve(property_manager_name)

        # Build the name we are going to give the transmission workspace
        sample_basename = os.path.basename(sample_file)
        empty_basename = os.path.basename(empty_file)
        entry_name = "Transmission%s%s" % (sample_basename, empty_basename)
        trans_ws_name = "__transmission_fit_%s" % sample_basename
        trans_ws = None

        if property_manager.existsProperty(entry_name):
            trans_ws_name = property_manager.getProperty(entry_name)
            if AnalysisDataService.doesExist(trans_ws_name):
                trans_ws = AnalysisDataService.retrieve(trans_ws_name)

        if trans_ws is None:
            trans_ws_name = "__transmission_fit_"+input_ws_name
            # Load data files
            sample_mon_ws, empty_mon_ws, first_det, output_str, monitor_det_ID = TransmissionUtils.load_monitors(self, property_manager)

            def _crop_and_compute(wl_min_prop, wl_max_prop, suffix):
                # Get the wavelength band from the run properties
                if workspace.getRun().hasProperty(wl_min_prop):
                    wl_min = workspace.getRun().getProperty(wl_min_prop).value
                else:
                    raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_min_prop

                if workspace.getRun().hasProperty(wl_max_prop):
                    wl_max = workspace.getRun().getProperty(wl_max_prop).value
                else:
                    raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_max_prop

                rebin_params = "%4.1f,%4.1f,%4.1f" % (wl_min, 0.1, wl_max)
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                   {"InputWorkspace": sample_mon_ws,
                                                    "OutputWorkspace": "__sample_mon_"+suffix,
                                                    "Params": rebin_params,
                                                    "PreserveEvents": False
                                                    })
                sample_ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm("Rebin",
                                                   {"InputWorkspace": empty_mon_ws,
                                                    "OutputWorkspace": "__empty_mon_"+suffix,
                                                    "Params": rebin_params,
                                                    "PreserveEvents": False
                                                    })
                empty_ws = alg.getProperty("OutputWorkspace").value
                trans_ws, raw_ws = TransmissionUtils.calculate_transmission(self,
                                                                            sample_ws,
                                                                            empty_ws,
                                                                            first_det,
                                                                            "__transmission_"+suffix)
                alg = TransmissionUtils.simple_algorithm("RebinToWorkspace",
                                                   {"WorkspaceToRebin": trans_ws,
                                                    "WorkspaceToMatch": workspace,
                                                    "OutputWorkspace": "__transmission_"+suffix,
                                                    "PreserveEvents": False
                                                    })
                trans_ws = alg.getProperty("OutputWorkspace").value
                alg = TransmissionUtils.simple_algorithm("RebinToWorkspace",
                                                   {"WorkspaceToRebin": raw_ws,
                                                    "WorkspaceToMatch": workspace,
                                                    "OutputWorkspace": "__transmission_unfitted_"+suffix,
                                                    "PreserveEvents": False
                                                    })
                raw_ws = alg.getProperty("OutputWorkspace").value

                return trans_ws, raw_ws

            # First frame
            trans_frame_1, raw_frame_1 = _crop_and_compute("wavelength_min", "wavelength_max", "_frame1")

            # Second frame
            trans_frame_2, raw_frame_2 = _crop_and_compute("wavelength_min_frame2", "wavelength_max_frame2", "_frame2")

            alg = TransmissionUtils.simple_algorithm("Plus",
                                               {"LHSWorkspace": trans_frame_1,
                                                "RHSWorkspace": trans_frame_2,
                                                "OutputWorkspace": "__transmission",
                                                })
            trans_ws = alg.getProperty("OutputWorkspace").value
            self.setPropertyValue("TransmissionWorkspace", trans_ws_name)
            self.setProperty("TransmissionWorkspace", trans_ws)

            alg = TransmissionUtils.simple_algorithm("Plus",
                                               {"LHSWorkspace": raw_frame_1,
                                                "RHSWorkspace": raw_frame_2,
                                                "OutputWorkspace": "__transmission_unfitted",
                                                })
            raw_ws = alg.getProperty("OutputWorkspace").value
            raw_ws_name = "__transmission_raw_%s" % input_ws_name
            self.setPropertyValue("RawTransmissionWorkspace", raw_ws_name)
            self.setProperty("RawTransmissionWorkspace", raw_ws)

            # Save the transmission to disk
            self._save_transmission(trans_ws, raw_ws)

        # 2- Apply correction (Note: Apply2DTransCorr)
        #Apply angle-dependent transmission correction using the zero-angle transmission
        return TransmissionUtils.apply_transmission(self, workspace, trans_ws)