def preProcess(self):
        """
        """
        EDTestCasePluginExecute.preProcess(self)
        self.loadTestImage([ "diff6105.edf", "flats0001.edf", "darks0001.edf", "frelon_spline_file_to_correct_SPD.spline" ])
        strPathToCifHeaders = (os.path.abspath(os.path.join(self.getPluginTestsDataHome(), "default_headers.cif")))
        cifDictDefaultHeaders = CIF()
        cifDictDefaultHeaders.loadCIF(strPathToCifHeaders)
        strImageDir = self.getTestsDataImagesHome()
        strPathToInputImage = os.path.abspath(os.path.join(strImageDir, "diff6105.edf"))
        strPathToDarkImage = os.path.abspath(os.path.join(strImageDir, "darks0001.edf"))
        strPathToFlatImage = os.path.abspath(os.path.join(strImageDir, "flats0001.edf"))
        strPathToSplineFile = os.path.abspath(os.path.join(strImageDir, "frelon_spline_file_to_correct_SPD.spline"))
        cifDictDefaultHeaders[ "_file_correction_image_dark-current" ] = strPathToDarkImage
        cifDictDefaultHeaders[ "_file_correction_image_flat-field" ] = strPathToFlatImage
        cifDictDefaultHeaders[ "_file_correction_spline_spatial-distortion" ] = strPathToSplineFile

        strPathToTestImage = os.path.abspath(os.path.join(strImageDir, "test.edf"))
        strPathToTestCif = os.path.abspath(os.path.join(strImageDir, "test.cif"))
        if os.path.isfile(strPathToTestImage):
            os.remove(strPathToTestImage)
        EDFfileCompleter.edf_keywords_completion(strPathToInputImage, cifDictDefaultHeaders, strPathToTestImage)
        cifDictDefaultHeaders.saveCIF(strPathToTestCif)
예제 #2
0
            for oneLoop in loops:
                oneLoopIdx = 0  #this is a index of the loop
                for oneLoopdict in oneLoop[1]:
                    oneLoopIdx += 1
                    for loopKey in oneLoop[0]:
                        headers["%s[%i]" %
                                (loopKey, oneLoopIdx)] = oneLoopdict[loopKey]
        else:
            headers[key] = keywords[key]
    outfile = EDF.EdfFile(edfout)
    outfile.WriteImage(headers, data)


if __name__ == '__main__':
    EDF_to_process = []
    cif = CIF()
    if len(sys.argv) == 0:
        raise "Please enter the name of a EDF file to be completed"
    for i in sys.argv[1:]:
        if os.path.isfile(i):
            if os.path.splitext(i)[1].lower() == ".edf":
                EDF_to_process.append(i)
            elif os.path.splitext(i)[1].lower() == ".cif":
                print "I agree with you: it would be nice to be allowed to give a CIF input file to feed the system"
                cif.loadCIF(i)
            else:
                print "Sorry I don't know what to do with this %s file" % i
        else:
            print "Sorry %s is not a readable file" % i

    if len(cif) == 0:
예제 #3
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
                            ]