Ejemplo n.º 1
0
    def preProcess(self, _edObject=None):
        """
        
        """
        EDPluginExec.preProcess(self)
        EDVerbose.DEBUG("*** EDPluginDCTWriteSinogramv1_0.preProcess")
        pyStrPathToInputCIFFile = self.getDataInput().getIntegratedIntensities().getPath().getValue()
        EDVerbose.DEBUG("This is the file which will be analyzed: %s" % pyStrPathToInputCIFFile)
        self.pystrPathToSinogramsDir = self.getDataInput().getSinogramDirectory().getPath().getValue()
        if not PyOs.path.isdir(self.pystrPathToSinogramsDir):
            PyOs.makedirs(self.pystrPathToSinogramsDir)
        self.pystrSinogramPrefix = self.getDataInput().getSinogramFileNamePrefix().getValue()
        EDVerbose.DEBUG(
            "Now generation of the SinoGrams, Path:  %s, Prefix= %s"
            % (self.pystrPathToSinogramsDir, self.pystrSinogramPrefix)
        )
        if not EDUtilsPath.existPath(pyStrPathToInputCIFFile):
            pyStrErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % (
                self.getPluginName() + ".preProcess",
                pyStrPathToInputFile,
            )
            EDVerbose.error(pyStrErrorMessage)
            self.addErrorMessage(pyStrErrorMessage)
            raise RuntimeError, pyStrErrorMessage
        # File exists, try to read it with the CIF library
        try:
            self.m_cifPowderData = CIF()
            self.m_cifPowderData.loadCIF(pyStrPathToInputCIFFile)
            EDVerbose.DEBUG("Parsing of the CIF file %s successful" % pyStrPathToInputCIFFile)
        except Exception:
            pyStrErrorMessage = EDMessage.ERROR_UNEXPECTED_01 % (
                "EDPluginDCTWriteSinogramv1_0.preProcess: Error when trying to read CIF file : %s"
                % pyStrPathToInputCIFFile
            )
            EDVerbose.error(pyStrErrorMessage)
            self.addErrorMessage(pyStrErrorMessage)
            # Just raise the exception in order to not loose the error stack trace
            raise
        if not self.m_cifPowderData.exists("_tomo_scan_type"):
            EDVerbose.DEBUG(
                "How do you want to generate a Sinogram if you are lacking essential things like the scan type !!!!"
            )
            raise
        self.pydMetaDataEDF = self.m_cifPowderData.copy()  # This is a simple python dictionary
        if self.pydMetaDataEDF.has_key("loop_"):
            self.pydMetaDataEDF.pop("loop_")
        if self.pydMetaDataEDF.has_key("_synchrotron_photon-flux"):
            self.pydMetaDataEDF.pop("_synchrotron_photon-flux")
        if self.pydMetaDataEDF.has_key("_synchrotron_ring-intensity"):
            self.pydMetaDataEDF.pop("_synchrotron_ring-intensity")
        if self.pydMetaDataEDF.has_key("_tomo_spec_displ_rotation"):
            self.pydMetaDataEDF.pop("_tomo_spec_displ_rotation")
        if self.pydMetaDataEDF.has_key("_tomo_spec_displ_x"):
            self.pydMetaDataEDF.pop("_tomo_spec_displ_x")
        if self.pydMetaDataEDF.has_key("_tomo_spec_displ_z"):
            self.pydMetaDataEDF.pop("_tomo_spec_displ_z")

        self.powderIntegrator = PowderIntegrator(self.m_cifPowderData)
        self.pyintXpos, self.pyintYpos = self.powderIntegrator.getSinogramPosition()
        (Xmax, Ymax) = self.powderIntegrator.getSinogramSize()
        self.pydProcessSinograms = {}
        for pystrSinogramSuffix in ["PhotonFlux", "IntegratedRaw", "IntegratedCor"]:
            pystrSinogramFullPath = PyOs.path.join(
                self.pystrPathToSinogramsDir, self.pystrSinogramPrefix + "Sinogram" + pystrSinogramSuffix
            )
            self.pydProcessSinograms[pystrSinogramFullPath] = pystrSinogramSuffix

        if self.m_cifPowderData.exists("_pd_sum_2theta_range_min"):
            for basename in ["Raw", "Cor"]:
                startregion = float(self.m_cifPowderData["_pd_sum_2theta_range_min"])
                stopregion = float(self.m_cifPowderData["_pd_sum_2theta_range_max"])
                pystrSinogramFilename = "%sSinogramROI%i-%i%s" % (
                    self.pystrSinogramPrefix,
                    int(round(startregion)),
                    int(round(stopregion)),
                    basename,
                )
                pystrSinogramFullPath = PyOs.path.join(self.pystrPathToSinogramsDir, pystrSinogramFilename)
                self.pydProcessSinograms[pystrSinogramFullPath] = [startregion, stopregion]
        else:
            for oneloop in self.m_cifPowderData["loop_"]:
                if "_pd_sum_2theta_range_min" in oneloop[0]:
                    for i in oneloop[1]:
                        startregion = float(i["_pd_sum_2theta_range_min"])
                        stopregion = float(i["_pd_sum_2theta_range_max"])
                        for basename in ["Raw", "Cor"]:
                            pystrSinogramFilename = "%sSinogramROI%i-%i%s" % (
                                self.pystrSinogramPrefix,
                                int(round(startregion)),
                                int(round(stopregion)),
                                basename,
                            )
                            pystrSinogramFullPath = PyOs.path.join(self.pystrPathToSinogramsDir, pystrSinogramFilename)
                            self.pydProcessSinograms[pystrSinogramFullPath] = [startregion, stopregion]
Ejemplo n.º 2
0
    def preProcess(self, _edObject=None):
        """
        
        """
        EDPluginExec.preProcess(self)
        EDVerbose.DEBUG("*** EDPluginDCTWriteSinogramv1_0.preProcess")
        pyStrPathToInputCIFFile = self.getDataInput().getIntegratedIntensities(
        ).getPath().getValue()
        EDVerbose.DEBUG("This is the file which will be analyzed: %s" %
                        pyStrPathToInputCIFFile)
        self.pystrPathToSinogramsDir = self.getDataInput(
        ).getSinogramDirectory().getPath().getValue()
        if not PyOs.path.isdir(self.pystrPathToSinogramsDir):
            PyOs.makedirs(self.pystrPathToSinogramsDir)
        self.pystrSinogramPrefix = self.getDataInput(
        ).getSinogramFileNamePrefix().getValue()
        EDVerbose.DEBUG(
            "Now generation of the SinoGrams, Path:  %s, Prefix= %s" %
            (self.pystrPathToSinogramsDir, self.pystrSinogramPrefix))
        if (not EDUtilsPath.existPath(pyStrPathToInputCIFFile)):
            pyStrErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % (
                self.getPluginName() + ".preProcess", pyStrPathToInputFile)
            EDVerbose.error(pyStrErrorMessage)
            self.addErrorMessage(pyStrErrorMessage)
            raise RuntimeError, pyStrErrorMessage
        # File exists, try to read it with the CIF library
        try:
            self.m_cifPowderData = CIF()
            self.m_cifPowderData.loadCIF(pyStrPathToInputCIFFile)
            EDVerbose.DEBUG("Parsing of the CIF file %s successful" %
                            pyStrPathToInputCIFFile)
        except Exception:
            pyStrErrorMessage = EDMessage.ERROR_UNEXPECTED_01 % (
                "EDPluginDCTWriteSinogramv1_0.preProcess: Error when trying to read CIF file : %s"
                % pyStrPathToInputCIFFile)
            EDVerbose.error(pyStrErrorMessage)
            self.addErrorMessage(pyStrErrorMessage)
            # Just raise the exception in order to not loose the error stack trace
            raise
        if not self.m_cifPowderData.exists("_tomo_scan_type"):
            EDVerbose.DEBUG(
                "How do you want to generate a Sinogram if you are lacking essential things like the scan type !!!!"
            )
            raise
        self.pydMetaDataEDF = self.m_cifPowderData.copy(
        )  #This is a simple python dictionary
        if self.pydMetaDataEDF.has_key("loop_"):
            self.pydMetaDataEDF.pop("loop_")
        if self.pydMetaDataEDF.has_key("_synchrotron_photon-flux"):
            self.pydMetaDataEDF.pop("_synchrotron_photon-flux")
        if self.pydMetaDataEDF.has_key("_synchrotron_ring-intensity"):
            self.pydMetaDataEDF.pop("_synchrotron_ring-intensity")
        if self.pydMetaDataEDF.has_key("_tomo_spec_displ_rotation"):
            self.pydMetaDataEDF.pop("_tomo_spec_displ_rotation")
        if self.pydMetaDataEDF.has_key("_tomo_spec_displ_x"):
            self.pydMetaDataEDF.pop("_tomo_spec_displ_x")
        if self.pydMetaDataEDF.has_key("_tomo_spec_displ_z"):
            self.pydMetaDataEDF.pop("_tomo_spec_displ_z")

        self.powderIntegrator = PowderIntegrator(self.m_cifPowderData)
        self.pyintXpos, self.pyintYpos = self.powderIntegrator.getSinogramPosition(
        )
        (Xmax, Ymax) = self.powderIntegrator.getSinogramSize()
        self.pydProcessSinograms = {}
        for pystrSinogramSuffix in [
                "PhotonFlux", "IntegratedRaw", "IntegratedCor"
        ]:
            pystrSinogramFullPath = PyOs.path.join(
                self.pystrPathToSinogramsDir,
                self.pystrSinogramPrefix + "Sinogram" + pystrSinogramSuffix)
            self.pydProcessSinograms[
                pystrSinogramFullPath] = pystrSinogramSuffix

        if self.m_cifPowderData.exists("_pd_sum_2theta_range_min"):
            for basename in ["Raw", "Cor"]:
                startregion = float(
                    self.m_cifPowderData["_pd_sum_2theta_range_min"])
                stopregion = float(
                    self.m_cifPowderData["_pd_sum_2theta_range_max"])
                pystrSinogramFilename = "%sSinogramROI%i-%i%s" % (
                    self.pystrSinogramPrefix, int(
                        round(startregion)), int(round(stopregion)), basename)
                pystrSinogramFullPath = PyOs.path.join(
                    self.pystrPathToSinogramsDir, pystrSinogramFilename)
                self.pydProcessSinograms[pystrSinogramFullPath] = [
                    startregion, stopregion
                ]
        else:
            for oneloop in self.m_cifPowderData["loop_"]:
                if "_pd_sum_2theta_range_min" in oneloop[0]:
                    for i in oneloop[1]:
                        startregion = float(i["_pd_sum_2theta_range_min"])
                        stopregion = float(i["_pd_sum_2theta_range_max"])
                        for basename in ["Raw", "Cor"]:
                            pystrSinogramFilename = "%sSinogramROI%i-%i%s" % (
                                self.pystrSinogramPrefix,
                                int(round(startregion)), int(
                                    round(stopregion)), basename)
                            pystrSinogramFullPath = PyOs.path.join(
                                self.pystrPathToSinogramsDir,
                                pystrSinogramFilename)
                            self.pydProcessSinograms[pystrSinogramFullPath] = [
                                startregion, stopregion
                            ]