def testExecute(self):
        """
        """
        self.run()

        # Checks that there are no error messages

        plugin = self.getPlugin()
        plugin.killAllWorkers()
        if EDVerbose.isVerboseDebug():
             plugin.cleanDispMat(plugin.getWorkingDirectory())
        else:
            plugin.cleanDispMat()


        # Checking obtained results
        xsDataResultSPD = plugin.getDataOutput()
        EDVerbose.DEBUG("outfile = %s" % xsDataResultSPD.getCorrectedFile().getPath().getValue())
        EDVerbose.DEBUG("reffile = %s" % os.path.join(self.getTestsDataImagesHome(), self.refOutput))
        outputData = openimage(xsDataResultSPD.getCorrectedFile().getPath().getValue()).data
        referenceData = openimage(os.path.join(self.getTestsDataImagesHome(), self.refOutput)).data
#        res = 100 * (abs(outputData - referenceData).max() - referenceData.min()) / (referenceData.max() - referenceData.min())
#        EDVerbose.screen("Maximum error = %.2f%%" % res)
#        EDAssert.equal((res < 5), True)
        EDAssert.arraySimilar(outputData, referenceData, "Simple comparison")
        EDAssert.arraySimilar(outputData, referenceData, _fAbsMaxDelta=0.01, _fScaledMaxDelta=0.05, _strComment="Images comparison")
    def testExecute(self):
        """
        """
        self.run()

        # Checks that there are no error messages

        plugin = self.getPlugin()
        plugin.killAllWorkers()
        if EDVerbose.isVerboseDebug():
            plugin.cleanDispMat(plugin.getWorkingDirectory())
        else:
            plugin.cleanDispMat()

# Checking obtained results
        xsDataResultSPD = plugin.getDataOutput()
        outputData = EDF(
            xsDataResultSPD.getCakedFile().getPath().getValue()).GetData(0)
        referenceData = EDF(
            os.path.join(self.getTestsDataImagesHome(),
                         self.refOutput)).GetData(0)
        relError = 100 * (abs(outputData - referenceData).max() -
                          referenceData.min()) / (referenceData.max() -
                                                  referenceData.min())
        absError = abs(outputData - referenceData).max()
        if relError > 5:
            EDAssert.lowerThan(
                relError, 5,
                "Maximum relative error = %.2f%%, Maximum Absolute Error %.2f"
                % (relError, absError))
        else:
            EDAssert.lowerThan(
                absError, 5,
                "Maximum relative error = %.2f%%, Maximum Absolute Error %.2f "
                % (relError, absError))
    def postProcess(self, _edObject=None):
        """
        Calls the parent preProcess method
        Checks that the installed 3rd party software is in the list of compatible versions
        """
        EDPluginExecProcess.postProcess(self)
        EDVerbose.DEBUG("EDPluginExecProcessScript.postProcess")

        # Tests the compatibles executable versions
        listCompatibleVersions = self.getListOfCompatibleVersions()

        if(len(listCompatibleVersions) != 0):

            bFound = False
            for compatibleVersion in listCompatibleVersions:
                bFound = self.findStringInLog(compatibleVersion)
                if(bFound == True):
                    break

            if(bFound == False):
                strErrorMessage = "Plugin not compatible with %s, compatible versions are: %s" % (self.getStringVersion(), self.getCompatibleVersionsStringLine())
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                if (EDVerbose.isVerboseDebug()):
                    raise RuntimeError, strErrorMessage
    def testExecute(self):
        """
        """
        self.run()

        # Checks that there are no error messages

        plugin = self.getPlugin()
        plugin.killAllWorkers()
        if EDVerbose.isVerboseDebug():
             plugin.cleanDispMat(plugin.getWorkingDirectory())
        else:
            plugin.cleanDispMat()


# Checking obtained results
        xsDataResultSPD = plugin.getDataOutput()
        outputData = EDF(xsDataResultSPD.getCakedFile().getPath().getValue()).GetData(0)
        referenceData = EDF(os.path.join(self.getTestsDataImagesHome(), self.refOutput)).GetData(0)
        relError = 100 * (abs(outputData - referenceData).max() - referenceData.min()) / (referenceData.max() - referenceData.min())
        absError = abs(outputData - referenceData).max()
        if relError > 5:
            EDAssert.lowerThan(relError, 5, "Maximum relative error = %.2f%%, Maximum Absolute Error %.2f" % (relError, absError))
        else:
            EDAssert.lowerThan(absError, 5, "Maximum relative error = %.2f%%, Maximum Absolute Error %.2f " % (relError, absError))
    def rewriteAsciiHeader(self):
        if EDVerbose.isVerboseDebug():
            shutil.copy(self.integratedCurve, self.integratedCurve + ".bak")
        lines = open(self.integratedCurve, "rb").readlines()
        headerMarker = None
        headers = []
        firstData = None
        for oneLine in lines:
            stripedLine = oneLine.strip()
            if headerMarker is None and len(stripedLine) > 0:
                headerMarker = stripedLine[0]
            if len(stripedLine) == 0:
                continue
            elif stripedLine.startswith(headerMarker):
                headers.append(stripedLine[1:].strip())
            else:
                firstData = lines.index(oneLine)
                break
        outFile = open(self.integratedCurve, "wb")
        outFile.write("# %s \r\n" % self.comments)
        outFile.write(
            "#Sample c= %s mg/ml \r\n# \r\n# Sample environment:\r\n" %
            self.concentration)

        if self.detector is not None:
            outFile.write("# Detector: %s \r\n" % self.detector)
        if self.detectorDistance is not None:
            outFile.write("# DetectorDistance: %s \r\n" %
                          self.detectorDistance)
        if self.pixelSize_1 is not None:
            outFile.write("# PixelSize_1: %s \r\n" % self.pixelSize_1)
        if self.pixelSize_2 is not None:
            outFile.write("# PixelSize_2: %s \r\n" % self.pixelSize_2)
        if self.beamCenter_1 is not None:
            outFile.write("# BeamCenter_1: %s \r\n" % self.beamCenter_1)
        if self.beamCenter_2 is not None:
            outFile.write("# BeamCenter_2: %s \r\n" % self.beamCenter_2)
        if self.beamStopDiode is not None:
            outFile.write("# BeamStopDiode: %s \r\n" % self.beamStopDiode)
        if self.wavelength is not None:
            outFile.write("# Wavelength: %s \r\n" % self.wavelength)
        if self.maskFile is not None:
            outFile.write("# MaskFile: %s \r\n" % self.maskFile)
        if self.normalizationFactor is not None:
            outFile.write("# NormalizationFactor: %s \r\n" %
                          self.normalizationFactor)
        if self.machineCurrent is not None:
            outFile.write("# MachineCurrent: %s \r\n" % self.machineCurrent)

        outFile.write("#\r\n")
        for oneLine in headers:
            outFile.write("# %s \r\n" % oneLine.strip())
        outFile.write("# \r\n# Sample Information:\r\n")
        outFile.write("# Concentration: %s\r\n" % self.concentration)
        outFile.write("# Code: %s\r\n" % self.code)
        outFile.write("\r\n".join([i.strip() for i in lines[firstData:]]))
        outFile.close()
 def testPopulateXSDataInputSPDCake(self):
     edPluginControlID11 = self.createPlugin()
     xsDataInputSPDCake = edPluginControlID11.populateXSDataInputSPDCake(self.dictID11Reference)
     strDataPath = self.getPluginTestsDataHome()
     strReferenceFile = "XSDataInputSPDCake_fromDict.xml"
     strPath = os.path.join(strDataPath, strReferenceFile)
     xsDataInputSPDCakeReference = XSDataInputSPDCake.parseString(self.readAndParseFile(strPath))
     xsDataInputSPDCakeReference.setDeleteCorImg(XSDataBoolean(not (EDVerbose.isVerboseDebug())))
     EDAssert.equal(xsDataInputSPDCakeReference.marshal(), xsDataInputSPDCake.marshal())
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     if EDVerbose.isVerboseDebug():
          edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())
     else:
         edPluginSPD.cleanDispMat()
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsTest.readAndParseFile(self.strReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     if EDVerbose.isVerboseDebug():
          edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())
     else:
         edPluginSPD.cleanDispMat()
예제 #9
0
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(
         self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     if EDVerbose.isVerboseDebug():
         edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())
     else:
         edPluginSPD.cleanDispMat()
    def rewriteAsciiHeader(self):
        if EDVerbose.isVerboseDebug():
            shutil.copy(self.integratedCurve, self.integratedCurve + ".bak")
        lines = open(self.integratedCurve, "rb").readlines()
        headerMarker = None
        headers = []
        firstData = None
        for oneLine in lines:
            stripedLine = oneLine.strip()
            if headerMarker  is None and len(stripedLine) > 0:
                headerMarker = stripedLine[0]
            if len(stripedLine) == 0:
                continue
            elif stripedLine.startswith(headerMarker) :
                headers.append(stripedLine[1:].strip())
            else:
                firstData = lines.index(oneLine)
                break
        outFile = open(self.integratedCurve, "wb")
        outFile.write("# %s \r\n" % self.comments)
        outFile.write("#Sample c= %s mg/ml \r\n# \r\n# Sample environment:\r\n" % self.concentration)


        if  self.detector is not None:
            outFile.write("# Detector: %s \r\n" % self.detector)
        if self.detectorDistance is not None:
            outFile.write("# DetectorDistance: %s \r\n" % self.detectorDistance)
        if self.pixelSize_1 is not None:
            outFile.write("# PixelSize_1: %s \r\n" % self.pixelSize_1)
        if self.pixelSize_2 is not None:
            outFile.write("# PixelSize_2: %s \r\n" % self.pixelSize_2)
        if self.beamCenter_1 is not None:
            outFile.write("# BeamCenter_1: %s \r\n" % self.beamCenter_1)
        if self.beamCenter_2  is not None:
            outFile.write("# BeamCenter_2: %s \r\n" % self.beamCenter_2)
        if self.beamStopDiode is not None:
            outFile.write("# BeamStopDiode: %s \r\n" % self.beamStopDiode)
        if self.wavelength  is not None:
            outFile.write("# Wavelength: %s \r\n" % self.wavelength)
        if self.maskFile is not  None:
            outFile.write("# MaskFile: %s \r\n" % self.maskFile)
        if self.normalizationFactor is not  None:
            outFile.write("# NormalizationFactor: %s \r\n" % self.normalizationFactor)
        if self.machineCurrent is not  None:
            outFile.write("# MachineCurrent: %s \r\n" % self.machineCurrent)

        outFile.write("#\r\n")
        for oneLine in headers:
            outFile.write("# %s \r\n" % oneLine.strip())
        outFile.write("# \r\n# Sample Information:\r\n")
        outFile.write("# Concentration: %s\r\n" % self.concentration)
        outFile.write("# Code: %s\r\n" % self.code)
        outFile.write("\r\n".join([i.strip() for i in lines[firstData:]]))
        outFile.close()
예제 #11
0
    def generateEdfheaderdelkey2DCommands(self):
        """
        Generate the command line
        """
        EDVerbose.DEBUG("*** EDPluginExecSaxsDelMetadatav1_0.generateEdfheaderdelkeyCommands")
        if EDVerbose.isVerboseDebug():
            strOptions = "0 2 1 1 '%s' '%s'" % (self.strKey, self.strImage)
        else:
            strOptions = "0 0 1 1 '%s' '%s'" % (self.strKey, self.strImage)

        EDVerbose.DEBUG("edfheaderdelkey " + strOptions)
        self.setScriptCommandline(strOptions)
 def testPopulateXSDataInputSPDCake(self):
     edPluginControlID11 = self.createPlugin()
     xsDataInputSPDCake = edPluginControlID11.populateXSDataInputSPDCake(
         self.dictID11Reference)
     strDataPath = self.getPluginTestsDataHome()
     strReferenceFile = "XSDataInputSPDCake_fromDict.xml"
     strPath = os.path.join(strDataPath, strReferenceFile)
     xsDataInputSPDCakeReference = XSDataInputSPDCake.parseString(
         self.readAndParseFile(strPath))
     xsDataInputSPDCakeReference.setDeleteCorImg(
         XSDataBoolean(not (EDVerbose.isVerboseDebug())))
     EDAssert.equal(xsDataInputSPDCakeReference.marshal(),
                    xsDataInputSPDCake.marshal())
 def testGenerateSPDCommand(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.configure()
     edPluginSPD.getInputParameter()
     #edPluginSPD.preProcess()
     edPluginSPD.generateSPDCommand()
     EDVerbose.screen("SPD configuration:\n%s" % edPluginSPD.getSPDConfig())
     if EDVerbose.isVerboseDebug():
         expected = """off_1=0 off_2=0 verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #"do_distortion=2 off_1=0 off_2=0  verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     else:
         expected = """off_1=0 off_2=0 verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #do_distortion=2 off_1=0 off_2=0  verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     EDAssert.equal(edPluginSPD.getSPDConfig(), expected)
예제 #14
0
 def testGenerateSPDCommand(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(
         self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.configure()
     edPluginSPD.getInputParameter()
     #edPluginSPD.preProcess()
     edPluginSPD.generateSPDCommand()
     EDVerbose.screen("SPD configuration:\n%s" % edPluginSPD.getSPDConfig())
     if EDVerbose.isVerboseDebug():
         expected = """off_1=0 off_2=0 verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #"do_distortion=2 off_1=0 off_2=0  verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     else:
         expected = """off_1=0 off_2=0 verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #do_distortion=2 off_1=0 off_2=0  verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     EDAssert.equal(edPluginSPD.getSPDConfig(), expected)
예제 #15
0
    def testGenerateSPDCommand(self):
        edPluginSPD = self.createPlugin()
        edStringXMLInput = EDUtilsTest.readAndParseFile(self.m_edStringReferenceInputFileName)
        xsDataInputSPDCake = XSDataInputSPDCake.parseString(edStringXMLInput)
        edPluginSPD.setDataInput(xsDataInputSPDCake)
        edPluginSPD.configure()
        edPluginSPD.getInputParameter()
        #edPluginSPD.preProcess()
        edPluginSPD.generateSPDCommand()
        EDVerbose.screen("SPD configuration:\n %s" % edPluginSPD.getSPDConfig())
        if EDVerbose.isVerboseDebug():
            expected = """off_1=0 off_2=0 verbose=2 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""
#            """do_distortion=2 off_1=0 off_2=0  verbose=2 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""
        else:
            expected = """off_1=0 off_2=0 verbose=0 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""
#            """do_distortion=2 off_1=0 off_2=0  verbose=0 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""

        EDAssert.equal(edPluginSPD.getSPDConfig(), expected)
예제 #16
0
    else:
        ffx = FullFieldXas()
        if os.path.isfile(".XSDataInputFullFieldXAS.xml"):
            ffx.load(".XSDataInputFullFieldXAS.xml")

        ffx.dontAlign = dontAlign
        if dontAlign:
            print ("*" * 80)
            print ("*" + "Skipping image alignement part".center(78) + "*")
            print ("*" * 80)
        ffx.setup(_listInput=paths, _mode=mode)
    if not isinstance(ffx.reference, int):
        ffx.uploadReferenceFrame(ffx.reference)
    ffx.save(".XSDataInputFullFieldXAS.xml")
    ffx.dump("analysis-%s.json" % time.strftime("%Y%m%d-%Hh%Mm%Ss"))
    edna = EDParallelExecute(
        ffx.pluginName, ffx.makeXML, _functXMLerr=ffx.error, _bVerbose=True, _bDebug=debug, _iNbThreads=iNbCPU
    )
    edna.runEDNA(ffx.listInput, ffx.strMode, ffx.bNewerOnly)
    EDVerbose.WARNING("Back to main !")
    EDJob.synchronizeAll()
    ffx.updateAttrRefImage()
    EDPluginControlAlignStackv1_0.showData()
    if keepShare:
        EDShare.close()
    elif (ffx.getNrErrors() == 0) and (not EDVerbose.isVerboseDebug()):
        EDVerbose.WARNING("All processing finished successfully: Remove EDShare's big HDF5 file")
        EDShare.close(remove=True)
    else:
        EDShare.close()
예제 #17
0
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        EDVerbose.DEBUG("EDPluginExportAsciiPowderv1_0.process")
        if len(self.inputArray.shape) == 2:
            iNbAzimBin, iLength = self.inputArray.shape
            if  iNbAzimBin == 1:
                nplInt = self.inputArray[0, :]
            else:
                nonNull = ((abs(self.inputArray - self.fDummy) > self.fDeltaDummy)).astype("int").sum(axis=0)
                nplInt = self.inputArray.sum(axis=0) / nonNull
        elif len(self.inputArray.shape) == 1:
            nplInt = self.inputArray
            iLength = len(nplInt)
        else:
            EDVerbose.ERROR("EDPluginExportAsciiPowderv1_0.inputArray has a large dimension: %s  " % (self.inputArray.shape))

        nplTth = numpy.degrees(numpy.arctan((numpy.arange(iLength) + 0.5 + self.fRadOffset) * self.fPixelSize / self.fDistance))

        if EDVerbose.isVerboseDebug():
            open("raw.dat", "wb").write("\n".join(["%s\t%s" % (nplTth[i], nplInt[i]) for i in range(len(nplInt))]))
            open("inputArray.xml", "wb").write(EDUtilsArray.arrayToXSData(nplInt, _bIncludeMd5sum=False).marshal())
        XRPD = lambda tth: numpy.interp(tth, nplTth, nplInt, left=0, right=0)

        tthMax = nplTth[-1]
        tthMin = nplTth[0]
        if (self.iNbBins is None):
            self.iNbBins = iLength
        pyfStep = (tthMax - tthMin) / (self.iNbBins - 1)

#        # Create the output data

        if "cif" in self.strFormat:
                cif = CIF()
                cif[ "_audit_creation_method"    ] = 'EDNA'
                cif[ "_pd_meas_2theta_range_inc" ] = str(pyfStep)
                cif[ "_pd_meas_2theta_range_max" ] = str(tthMax)
                cif[ "_pd_meas_2theta_range_min" ] = str(tthMin)
                cif[ "_pd_meas_number_of_points" ] = str(self.iNbBins)
                cif[ "_pd_meas_scan_method"      ] = "fixed"
                if "Title" in self.dHeader:
                    cif[ "_pd_spec_description"] = self.dHeader["Title"]
                if self.fWavelength is not None:
                    cif["_diffrn_radiation_wavelength"] = str(self.fWavelength * 1.0e10) #in Angstrom acording to CIF dict
                cif["_pd_instr_dist_spec/detc"] = str(self.fDistance * 1.0e3) #in mm acording to CIF dict
                oneloop = []
                for i in numpy.linspace(tthMin, tthMax, self.iNbBins):
                    oneloop.append({ "_pd_meas_intensity_total" : str(XRPD(i)) })
                cif["loop_"] = [ [ ["_pd_meas_intensity_total"], oneloop ] ]
                cif.saveCIF(self.outputFilename)

        elif "chi" in self.strFormat :
            f = open(self.outputFilename, "wb")
            if "Title" in self.dHeader:
                f.write(self.dHeader["Title"] + ": ")
            f.write("Angular Profile\nTwo-Theta Angle (degrees)\nIntensity (normalised)\n%i\n" % self.iNbBins)
            for i in numpy.linspace(tthMin, tthMax, self.iNbBins):
                f.write("%f\t%f\n" % (i, XRPD(i)))
            f.close()

        elif "spr" in self.strFormat :
            self.npaTwoTheta = numpy.linspace(tthMin, tthMax, self.iNbBins)
            f = open(self.outputFilename, "wb")
            f.write("# Generated by EDNA, Spread sheet with fortran order for fit2d compatibility" + os.linesep)
            f.write("# dim0 (radial values in degrees): " + "\t".join(["%.2f" % i for i in self.npaTwoTheta]) + os.linesep)
            f.write("# dim1 (azimuthal values in degrees): " + "\t".join(["%.2f" % i for i in numpy.degrees(self.fAzimSize * (numpy.arange(iNbAzimBin) + self.fAzimOffset))]) + os.linesep)
            f.write("%i,%i\tStartPixel=(1,1)" % (self.iNbBins, iNbAzimBin) + os.linesep)
            for i in xrange(iNbAzimBin):
                XRPD = lambda tth: numpy.interp(tth, nplTth, self.inputArray[i, :], left=0, right=0)
                f.write("\t".join(["%8.4f" % i for i in XRPD(self.npaTwoTheta)]) + os.linesep)
            f.close()
        else:
                self.npaTwoTheta = numpy.linspace(tthMin, tthMax, self.iNbBins)
                self.npaIntensities = XRPD(self.npaTwoTheta)
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        self.DEBUG("EDPluginExecStitchOffsetedImagev1_0.process")


        shiftedImage = []
        distanceSq = lambda t2f: (t2f[0] * t2f[0] + t2f[1] * t2f[1])
        ref = self._lOffsets[0]
        refOffset = distanceSq(ref)
        shape = self._lImages[0].shape
        if self._strMask:
            mask = (1 - fabio.open(self._strMask).data).astype("bool")
        else:
            mask = 0
        for img, offset, dummy in zip(self._lImages, self._lOffsets, self._lDummies):
            shImg = scipy.ndimage.shift(img, offset, cval=dummy[0], order=0)
            if dummy[1] == 0:
                if self._strMask:
                    shImgMasked = numpy.ma.MaskedArray(shImg,
                                    (shImg == dummy[0]) + scipy.ndimage.shift(mask, offset, cval=1, order=0))
                else:
                    shImgMasked = numpy.ma.MaskedArray(shImg, (shImg == dummy[0]))
            else:
                if self._strMask:
                    shImgMasked = numpy.ma.MaskedArray(shImg,
                                    (abs(shImg - dummy[0]) <= dummy[1]) + scipy.ndimage.shift(mask, offset, cval=1, order=0))
                else:
                    shImgMasked = numpy.ma.MaskedArray(shImg, (abs(shImg - dummy[0]) <= dummy[1]))
            shiftedImage.append(shImgMasked)
            if (offset != ref) and (distanceSq(offset) < refOffset):
                ref = offset
                refOffset = distanceSq(offset)
        refIdx = self._lOffsets.index(ref)

        if EDVerbose.isVerboseDebug():
            e = edfimage(data=shiftedImage[0].filled(self._fDummy),
                         header={"Dummy":str(self._fDummy), "Offset_1":str(self._lOffsets[0][0]), "Offset_2":str(self._lOffsets[0][1])})
            for img, offset in zip(shiftedImage[1:], self._lOffsets[1:]):
                e.appendFrame(data=img.filled(self._fDummy),
                              header={"Dummy":str(self._fDummy), "Offset_1":str(offset[0]), "Offset_2":str(offset[1])})
            e.write("stack.edf")


        ROI = False
        if self.tCenter is None:
            #the default center is the geometry center of the image ... 
            self.tCenter = [ i // 2 for i in shape ]
        if self.tWidth is not None:
            d0min = max(0, self.tCenter[0] - (self.tWidth[0] // 2))
            d0max = min(shape[0], d0min + self.tWidth[0])
            d1min = max(0, self.tCenter[1] - (self.tWidth[1] // 2))
            d1max = min(shape[1], d1min + self.tWidth[1])
            shape = (d0max - d0min, d1max - d1min)
        else:
            d0min = 0
            d0max = shape[0]
            d1min = 0
            d1max = shape[1]
        refImg = shiftedImage[refIdx]
        stackMaskedImg = numpy.ma.zeros((len(self._lOffsets), refImg.shape[0], refImg.shape[1]))
        self.screen("ROI[%s:%s, %s:%s]\t Autoscale: %s\tBlending method: %s" % (d0min, d0max, d1min, d1max, self._bAutoscale, self._strBlending))
        if self._bAutoscale:
            for idx, img in enumerate(shiftedImage):
                ratio = (refImg[d0min:d0max, d1min:d1max] / img[d0min:d0max, d1min:d1max])
                stackMaskedImg[idx] = ratio.mean() * img
        else:
            for idx, img in enumerate(shiftedImage):
                stackMaskedImg[idx] = img



        if self._strBlending.lower().startswith("naive"):
            npaTempBool = numpy.cumsum((1 - stackMaskedImg.mask), axis=0) * (1 - stackMaskedImg.mask) == 1
            result = numpy.ma.MaskedArray((npaTempBool * stackMaskedImg.data).sum(axis=0), stackMaskedImg.mask.prod(axis=0))

        elif self._strBlending.lower().startswith("max"):
            result = stackMaskedImg.max(axis=0)
        elif self._strBlending.lower().startswith("min"):
            result = stackMaskedImg.min(axis=0)
        else: #self._strBlending.lower() == "mean":
            result = stackMaskedImg.mean(axis=0)

        self._ndaResult = result.filled(self._fDummy)
예제 #19
0
    def postProcess(self, _edObject=None):

        EDPluginExecProcessScript.postProcess(self)
        EDVerbose.DEBUG("EDPluginSPDCakev1_1.postProcess")

        xsDataInputSPDCake = self.getDataInput()
        strOutputFileType = xsDataInputSPDCake.getOutputFileType().getValue()
        # Determine the image file name without path and suffix
        strInputImageFilePath = xsDataInputSPDCake.getInputFile().getPath(
        ).getValue()
        strInputFileNameWithoutSuffix = os.path.splitext(
            EDUtilsFile.getBaseName(strInputImageFilePath))[0]

        self.strOutputFileSuffix = "data"
        if (strOutputFileType == "PowderCIF"):
            self.strOutputFileSuffix = "cif"
        elif (strOutputFileType == "CHIPLOT"):
            self.strOutputFileSuffix = "chi"

        strOutputFileName = strInputFileNameWithoutSuffix + "." + self.strOutputFileSuffix
        if self.outputDir is None:
            self.m_strOutputFilePath = os.path.join(self.getWorkingDirectory(),
                                                    strOutputFileName)
        else:
            self.m_strOutputFilePath = os.path.join(self.outputDir,
                                                    strOutputFileName)
        PyStrCakeFilePrefix = os.path.splitext(
            os.path.split(strInputImageFilePath)[1])[0]

        ################################################################
        ####  Do some manipulation of the  output image  ##############
        ################################################################
        EDFCakeFile = fabio.open(
            os.path.join(self.getWorkingDirectory(),
                         PyStrCakeFilePrefix + ".azim.edf"))
        npaData = EDFCakeFile.data
        pydHeader = EDFCakeFile.header

        pyfPixSize = float(pydHeader["PSize_1"].split()[0])
        pyfDist = float(pydHeader["SampleDistance"].split()[0])
        EDVerbose.DEBUG("Calculation done with PixSize=%s, distance= %s" %
                        (pydHeader["PSize_1"], pydHeader["SampleDistance"]))
        pyiNbAzimBin, pyiLength = npaData.shape
        nplInt = npaData.reshape((pyiLength))
        nplTth = numpy.degrees(
            numpy.arctan(
                numpy.linspace(
                    0.5 * pyfPixSize / pyfDist,
                    (pyiLength - 0.5) * pyfPixSize / pyfDist,
                    pyiLength,
                )))

        #for the description of the +0.5 term, please refer to http://www.esrf.fr/computing/scientific/SAXS/doc/SaxsKeywords/SaxsKeywords.pdf page 23

        ######################################Debugging#######################
        f = open(os.path.join(self.getWorkingDirectory(), "original.dat"), "w")
        for i in range(pyiLength):
            f.write("%f\t%f\n" % (nplTth[i], nplInt[i]))
        f.close()
        ##############################end Debugging############################
        XRPD = lambda tth: numpy.interp(tth, nplTth, nplInt, left=0, right=0)
        pyfTthMin = nplTth[0]
        pyfTthMax = nplTth[-1]
        pyfStep = (pyfTthMax - pyfTthMin) / (pyiLength - 1)
        ########### Remove large files to prevent disk saturation when not in debug mode ###################
        if not EDVerbose.isVerboseDebug():
            os.remove(
                os.path.join(self.getWorkingDirectory(),
                             PyStrCakeFilePrefix + ".cor.edf"))
            os.remove(
                os.path.join(self.getWorkingDirectory(),
                             PyStrCakeFilePrefix + ".azim.edf"))

#        # Create the output data
        xsDataResultSPDCake = XSDataResultSPDCake()
        if (self.m_strOutputFilePath is not None):

            if (strOutputFileType == "PowderCIF"):
                import CIFfile
                cif = CIFfile.CIF()
                cif["_audit_creation_method"] = 'From 2-D detector using SPD and CIFfile'
                cif["_pd_meas_2theta_range_inc"] = str(pyfStep)
                cif["_pd_meas_2theta_range_max"] = str(pyfTthMax)
                cif["_pd_meas_2theta_range_min"] = str(pyfTthMin)
                cif["_pd_meas_number_of_points"] = str(pyiLength)
                cif["_pd_meas_scan_method"] = "fixed"
                cif["_pd_spec_description"] = pydHeader["title"]
                cif["_diffrn_radiation_wavelength"] = str(
                    self.getDataInput().getWavelength().getValue())
                cif["_pd_instr_dist_spec/detc"] = str(self.getDataInput(
                ).getSampleToDetectorDistance().getValue())
                oneloop = []
                #range( pyiLength ):
                for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength):
                    oneloop.append({"_pd_meas_intensity_total": str(XRPD(i))})
                cif["loop_"] = [[["_pd_meas_intensity_total"], oneloop]]
                cif.saveCIF(self.m_strOutputFilePath)

            elif (strOutputFileType == "CHIPLOT"):
                f = open(
                    os.path.join(self.getWorkingDirectory(),
                                 self.m_strOutputFilePath), "w")
                f.write(
                    pydHeader["title"] +
                    ": Angular Profile\nTwo-Theta Angle (degrees)\nIntensity (normalised)\n%i\n"
                    % pyiLength)
                for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength):
                    f.write("%f\t%f\n" % (i, XRPD(i)))
                f.close()

            xsDataFile = XSDataFile()
            xsDataFile.setPath(XSDataString(self.m_strOutputFilePath))
            xsDataResultSPDCake.setCakedFile(xsDataFile)
        self.setDataOutput(xsDataResultSPDCake)
    def process(self, _edObject=None):
        """
        This method starts the execution of the EDNA script using EDActionExecuteSystemCommand
        In case of failure, an error message is added to the list and the plugin fails.
        """
        EDPluginExecProcess.process(self)
        EDVerbose.DEBUG("EDPluginExecProcessScript.process starting")
        self.synchronizeOn()
        if "TIMEOUT" in EDUtilsFile.readFile(self.__strPathToHostNamePidFile):
            EDVerbose.error("Timeout message found in %s" % self.__strPathToHostNamePidFile)
            self.hasTimedOut(True)

        bTimeOut = self.isTimeOut()
        if (bTimeOut == True):
            EDVerbose.DEBUG("EDPluginExecProcessScript.process ========================================= ERROR! ================")
            strErrorMessage = "%s execution timed out ( > %.1f s)!" % (self.__strScriptExecutable, float(self.getTimeOut()))
            EDVerbose.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
            strExecutionStatus = "timeout"
            if (EDVerbose.isVerboseDebug()):
                raise RuntimeError(strErrorMessage)
        else:
            strExecutionStatus = self.getExecutionStatus()
            # Report an error if the result is not "0" and the result is not an empty string
            if (not strExecutionStatus == "0" and not strExecutionStatus == ""):
                EDVerbose.DEBUG("EDPluginExecProcessScript.process ========================================= ERROR! ================")
                # Add any messages in the error log file (.err) to the list of error messages
                strErrorLog = self.readProcessErrorLogFile()
                if (strErrorLog is None):
                    strErrorMessage = "%s execution error - status : %s" % (self.getClassName(), strExecutionStatus)
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    self.setFailure()
                    if (EDVerbose.isVerboseDebug()):
                        raise RuntimeError(strErrorMessage)
                else:
                    strErrorMessage = "%s execution error : %s" % (self.getClassName(), strErrorLog)
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    self.setFailure()
                    if (EDVerbose.isVerboseDebug()):
                        raise RuntimeError(strErrorMessage)
                # Add any messages in the log file (.log) to the list of error messages
                strLog = self.readProcessLogFile()
                if strLog is not None:
                    # Cut down the log file to the last part if it's long
                    listLogLines = strLog.split("\n")
                    if len(listLogLines) > self.__iNumberOfLastLinesFromLogFileIfError:
                        strErrorMessage = "Last part of the %s log file:" % self.getScriptExecutable()
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage(strErrorMessage)
                        listLogLastLines = listLogLines[-self.__iNumberOfLastLinesFromLogFileIfError:]
                        strLogLastLines = ""
                        for strLine in listLogLastLines:
                            strLogLastLines += strLine + "\n"
                        EDVerbose.ERROR(strLogLastLines)
                        self.addErrorMessage(strLogLastLines)
                        strMessage = "Please inspect log file: %s" % os.path.join(self.getWorkingDirectory(), self.getScriptLogFileName())
                        EDVerbose.ERROR(strMessage)
                        self.addErrorMessage(strMessage)
                    else:
                        strMessage = "%s log file: \n%s" % (self.getScriptExecutable(), strLog)
                        EDVerbose.ERROR(strMessage)
                        self.addErrorMessage(strMessage)
        #       Save the return code of the external program in the PID file
        open(self.__strPathToHostNamePidFile, "a").write(strExecutionStatus + os.linesep)

        EDVerbose.DEBUG("EDPluginExecProcessScript.process finished ")
        self.synchronizeOff()
 def configure(self):
     """
     Configures the plugin from the configuration file with the following parameters
      - The shell that will execute the script
      - Script executor
      - Script executable to be invoked
      - Path to CCP4 setup file if required
      - The 3rd party executable installed version
     """
     EDPluginExecProcess.configure(self)
     EDVerbose.DEBUG("EDPluginExecProcessScript.configure")
     xsPluginItem = self.getConfiguration()
     if (xsPluginItem == None):
         EDVerbose.warning("EDPluginExecProcessScript.configure: No plugin item defined.")
         xsPluginItem = XSPluginItem()
     strShell = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_SHELL)
     if(strShell == None):
         EDVerbose.DEBUG("EDPluginExecProcessScript.configure: No configuration parameter found for: " + \
                         EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_SHELL + ", using default value: " + self.getScriptShell())
     else:
         self.setScriptShell(strShell)
     strScriptExecutor = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_EXECUTOR)
     if(strScriptExecutor == None):
         self.setScriptExecutor(self.getScriptShell())
         EDVerbose.DEBUG("EDPluginExecProcessScript.configure: No configuration parameter found for: " + \
                         EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_EXECUTOR + ", using script shell: " + self.getScriptShell())
     else:
         self.setScriptExecutor(strScriptExecutor)
     if (self.getScriptExecutable() is None):
         strScriptExecutable = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_EXECUTABLE)
         if(strScriptExecutable == None):
             strErrorMessage = "Configuration parameter missing: " + EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_EXECUTABLE
             EDVerbose.error(strErrorMessage)
             self.addErrorMessage(strErrorMessage)
             self.setFailure()
             if (EDVerbose.isVerboseDebug()):
                 raise RuntimeError, strErrorMessage
         else:
             # Check that the executable file exists
             if (os.path.exists(strScriptExecutable) == False):
                 strErrorMessage = "Cannot find configured " + EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_EXECUTABLE + " : " + strScriptExecutable
                 EDVerbose.error(strErrorMessage)
                 self.addErrorMessage(strErrorMessage)
                 self.setFailure()
                 if (EDVerbose.isVerboseDebug()):
                     raise RuntimeError, strErrorMessage
             else:
                 self.setScriptExecutable(strScriptExecutable)
     strConfigSetupCCP4 = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_SETUP_CCP4)
     if(strConfigSetupCCP4 == None):
         EDVerbose.DEBUG("EDPluginExecProcessScript.configure: No configuration parameter found for: " + \
                         EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_SETUP_CCP4 + ", NO default value!")
     else:
         self.setSetupCCP4(strConfigSetupCCP4)
     strVersion = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_VERSION_STRING)
     if(strVersion == None):
         EDVerbose.DEBUG("EDPluginExecProcessScript.configure: No configuration parameter found for: " + \
                         EDPluginExecProcessScript.CONF_EXEC_PROCESS_SCRIPT_VERSION_STRING + ", NO default value!")
     else:
         self.setStringVersion(strVersion)
     if (self.__strScriptBaseName == None):
         self.setScriptBaseName(self.getBaseName())
     if (self.__strScriptFileName == None):
         self.setScriptFileName(self.__strScriptBaseName + ".sh")
     if (self.__strScriptLogFileName == None):
         self.setScriptLogFileName(self.__strScriptBaseName + ".log")
     if (self.__strScriptErrorLogFileName == None):
         self.setScriptErrorLogFileName(self.__strScriptBaseName + ".err")
     self.__strPathToHostNamePidFile = os.path.join(self.getWorkingDirectory(), os.path.basename(self.__strScriptExecutable) + "_hostNamePid.txt")
예제 #22
0
    def postProcess(self, _edObject=None):

        EDPluginExecProcessScript.postProcess(self)
        EDVerbose.DEBUG("EDPluginSPDCakev1_1.postProcess")


        xsDataInputSPDCake = self.getDataInput()
        strOutputFileType = xsDataInputSPDCake.getOutputFileType().getValue()
        # Determine the image file name without path and suffix
        strInputImageFilePath = xsDataInputSPDCake.getInputFile().getPath().getValue()
        strInputFileNameWithoutSuffix = os.path.splitext(EDUtilsFile.getBaseName(strInputImageFilePath))[0]

        self.strOutputFileSuffix = "data"
        if (strOutputFileType == "PowderCIF"):
            self.strOutputFileSuffix = "cif"
        elif (strOutputFileType == "CHIPLOT"):
            self.strOutputFileSuffix = "chi"

        strOutputFileName = strInputFileNameWithoutSuffix + "." + self.strOutputFileSuffix
        if self.outputDir is None:
            self.m_strOutputFilePath = os.path.join(self.getWorkingDirectory(), strOutputFileName)
        else:
            self.m_strOutputFilePath = os.path.join(self.outputDir, strOutputFileName)
        PyStrCakeFilePrefix = os.path.splitext(os.path.split(strInputImageFilePath)[1])[0]


        ################################################################
        ####  Do some manipulation of the  output image  ##############
        ################################################################
        EDFCakeFile = fabio.open(os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".azim.edf"))
        npaData = EDFCakeFile.data
        pydHeader = EDFCakeFile.header

        pyfPixSize = float(pydHeader["PSize_1"].split()[0])
        pyfDist = float(pydHeader["SampleDistance"].split()[0])
        EDVerbose.DEBUG("Calculation done with PixSize=%s, distance= %s" % (pydHeader["PSize_1"], pydHeader["SampleDistance"]))
        pyiNbAzimBin, pyiLength = npaData.shape
        nplInt = npaData.reshape((pyiLength))
        nplTth = numpy.degrees(numpy.arctan(numpy.linspace(0.5 * pyfPixSize / pyfDist, (pyiLength - 0.5) * pyfPixSize / pyfDist  , pyiLength,)))

        #for the description of the +0.5 term, please refer to http://www.esrf.fr/computing/scientific/SAXS/doc/SaxsKeywords/SaxsKeywords.pdf page 23

        ######################################Debugging#######################
        f = open(os.path.join(self.getWorkingDirectory(), "original.dat"), "w")
        for i in range(pyiLength):
            f.write("%f\t%f\n" % (nplTth[i], nplInt[i]))
        f.close()
        ##############################end Debugging############################
        XRPD = lambda tth: numpy.interp(tth, nplTth, nplInt, left=0, right=0)
        pyfTthMin = nplTth[0]
        pyfTthMax = nplTth[-1]
        pyfStep = (pyfTthMax - pyfTthMin) / (pyiLength - 1)
                ########### Remove large files to prevent disk saturation when not in debug mode ###################
        if not EDVerbose.isVerboseDebug():
            os.remove(os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".cor.edf"))
            os.remove(os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".azim.edf"))



#        # Create the output data
        xsDataResultSPDCake = XSDataResultSPDCake()
        if (self.m_strOutputFilePath is not None):

            if (strOutputFileType == "PowderCIF"):
                    import CIFfile
                    cif = CIFfile.CIF()
                    cif[ "_audit_creation_method"    ] = 'From 2-D detector using SPD and CIFfile'
                    cif[ "_pd_meas_2theta_range_inc" ] = str(pyfStep)
                    cif[ "_pd_meas_2theta_range_max" ] = str(pyfTthMax)
                    cif[ "_pd_meas_2theta_range_min" ] = str(pyfTthMin)
                    cif[ "_pd_meas_number_of_points" ] = str(pyiLength)
                    cif[ "_pd_meas_scan_method"      ] = "fixed"
                    cif[ "_pd_spec_description"      ] = pydHeader["title"]
                    cif["_diffrn_radiation_wavelength"] = str(self.getDataInput().getWavelength().getValue())
                    cif["_pd_instr_dist_spec/detc"] = str(self.getDataInput().getSampleToDetectorDistance().getValue())
                    oneloop = []
                    #range( pyiLength ):
                    for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength):
                        oneloop.append({ "_pd_meas_intensity_total" : str(XRPD(i)) })
                    cif["loop_"] = [ [ ["_pd_meas_intensity_total"], oneloop ] ]
                    cif.saveCIF(self.m_strOutputFilePath)

            elif (strOutputFileType == "CHIPLOT"):
                f = open(os.path.join(self.getWorkingDirectory(), self.m_strOutputFilePath), "w")
                f.write(pydHeader["title"] + ": Angular Profile\nTwo-Theta Angle (degrees)\nIntensity (normalised)\n%i\n" % pyiLength)
                for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength):
                    f.write("%f\t%f\n" % (i, XRPD(i)))
                f.close()

            xsDataFile = XSDataFile()
            xsDataFile.setPath(XSDataString(self.m_strOutputFilePath))
            xsDataResultSPDCake.setCakedFile(xsDataFile)
        self.setDataOutput(xsDataResultSPDCake)
예제 #23
0
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        EDVerbose.DEBUG("EDPluginExportAsciiPowderv1_0.process")
        if len(self.inputArray.shape) == 2:
            iNbAzimBin, iLength = self.inputArray.shape
            if iNbAzimBin == 1:
                nplInt = self.inputArray[0, :]
            else:
                nonNull = ((abs(self.inputArray - self.fDummy) >
                            self.fDeltaDummy)).astype("int").sum(axis=0)
                nplInt = self.inputArray.sum(axis=0) / nonNull
        elif len(self.inputArray.shape) == 1:
            nplInt = self.inputArray
            iLength = len(nplInt)
        else:
            EDVerbose.ERROR(
                "EDPluginExportAsciiPowderv1_0.inputArray has a large dimension: %s  "
                % (self.inputArray.shape))

        nplTth = numpy.degrees(
            numpy.arctan((numpy.arange(iLength) + 0.5 + self.fRadOffset) *
                         self.fPixelSize / self.fDistance))

        if EDVerbose.isVerboseDebug():
            open("raw.dat", "wb").write("\n".join([
                "%s\t%s" % (nplTth[i], nplInt[i]) for i in range(len(nplInt))
            ]))
            open("inputArray.xml", "wb").write(
                EDUtilsArray.arrayToXSData(nplInt,
                                           _bIncludeMd5sum=False).marshal())
        XRPD = lambda tth: numpy.interp(tth, nplTth, nplInt, left=0, right=0)

        tthMax = nplTth[-1]
        tthMin = nplTth[0]
        if (self.iNbBins is None):
            self.iNbBins = iLength
        pyfStep = (tthMax - tthMin) / (self.iNbBins - 1)

        #        # Create the output data

        if "cif" in self.strFormat:
            cif = CIF()
            cif["_audit_creation_method"] = 'EDNA'
            cif["_pd_meas_2theta_range_inc"] = str(pyfStep)
            cif["_pd_meas_2theta_range_max"] = str(tthMax)
            cif["_pd_meas_2theta_range_min"] = str(tthMin)
            cif["_pd_meas_number_of_points"] = str(self.iNbBins)
            cif["_pd_meas_scan_method"] = "fixed"
            if "Title" in self.dHeader:
                cif["_pd_spec_description"] = self.dHeader["Title"]
            if self.fWavelength is not None:
                cif["_diffrn_radiation_wavelength"] = str(
                    self.fWavelength *
                    1.0e10)  #in Angstrom acording to CIF dict
            cif["_pd_instr_dist_spec/detc"] = str(
                self.fDistance * 1.0e3)  #in mm acording to CIF dict
            oneloop = []
            for i in numpy.linspace(tthMin, tthMax, self.iNbBins):
                oneloop.append({"_pd_meas_intensity_total": str(XRPD(i))})
            cif["loop_"] = [[["_pd_meas_intensity_total"], oneloop]]
            cif.saveCIF(self.outputFilename)

        elif "chi" in self.strFormat:
            f = open(self.outputFilename, "wb")
            if "Title" in self.dHeader:
                f.write(self.dHeader["Title"] + ": ")
            f.write(
                "Angular Profile\nTwo-Theta Angle (degrees)\nIntensity (normalised)\n%i\n"
                % self.iNbBins)
            for i in numpy.linspace(tthMin, tthMax, self.iNbBins):
                f.write("%f\t%f\n" % (i, XRPD(i)))
            f.close()

        elif "spr" in self.strFormat:
            self.npaTwoTheta = numpy.linspace(tthMin, tthMax, self.iNbBins)
            f = open(self.outputFilename, "wb")
            f.write(
                "# Generated by EDNA, Spread sheet with fortran order for fit2d compatibility"
                + os.linesep)
            f.write("# dim0 (radial values in degrees): " +
                    "\t".join(["%.2f" % i
                               for i in self.npaTwoTheta]) + os.linesep)
            f.write("# dim1 (azimuthal values in degrees): " + "\t".join([
                "%.2f" % i for i in numpy.degrees(self.fAzimSize *
                                                  (numpy.arange(iNbAzimBin) +
                                                   self.fAzimOffset))
            ]) + os.linesep)
            f.write("%i,%i\tStartPixel=(1,1)" % (self.iNbBins, iNbAzimBin) +
                    os.linesep)
            for i in xrange(iNbAzimBin):
                XRPD = lambda tth: numpy.interp(
                    tth, nplTth, self.inputArray[i, :], left=0, right=0)
                f.write(
                    "\t".join(["%8.4f" % i
                               for i in XRPD(self.npaTwoTheta)]) + os.linesep)
            f.close()
        else:
            self.npaTwoTheta = numpy.linspace(tthMin, tthMax, self.iNbBins)
            self.npaIntensities = XRPD(self.npaTwoTheta)
예제 #24
0
if ("EDNA_HOME" in os.environ):
    if (os.environ["EDNA_HOME"] != strEdnaHome):
        print("Warning: EDNA_HOME redefined to %s" % strEdnaHome)
        os.environ["EDNA_HOME"] = strEdnaHome
else:
    os.environ["EDNA_HOME"] = strEdnaHome
sys.path.append(os.path.join(os.environ["EDNA_HOME"], "kernel", "src"))
from EDUtilsLibraryInstaller import EDUtilsLibraryInstaller
from EDVerbose import EDVerbose

if __name__ == "__main__":
    installDir = os.path.abspath(sys.argv[0]).split(os.sep)[-2]
    EDVerbose.screen("Building %s" % installDir)
    install = EDUtilsLibraryInstaller(installDir, strArchiveName)
    install.checkPythonVersion()
    install.downloadLibrary()
    install.dependency("numpy", "20090405-Numpy-1.3")
    install.unZipArchive()
    try:
        install.buildSources()
    except Exception:
        EDVerbose.ERROR("Error in the build")
    install.installBuilt()
    if not EDVerbose.isVerboseDebug():
        install.cleanSources()

else:
    EDVerbose.ERROR(
        "This installer program is not made to be imported, please just run it"
    )
예제 #25
0
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        self.DEBUG("EDPluginExecStitchOffsetedImagev1_0.process")

        shiftedImage = []
        distanceSq = lambda t2f: (t2f[0] * t2f[0] + t2f[1] * t2f[1])
        ref = self._lOffsets[0]
        refOffset = distanceSq(ref)
        shape = self._lImages[0].shape
        if self._strMask:
            mask = (1 - fabio.open(self._strMask).data).astype("bool")
        else:
            mask = 0
        for img, offset, dummy in zip(self._lImages, self._lOffsets,
                                      self._lDummies):
            shImg = scipy.ndimage.shift(img, offset, cval=dummy[0], order=0)
            if dummy[1] == 0:
                if self._strMask:
                    shImgMasked = numpy.ma.MaskedArray(
                        shImg, (shImg == dummy[0]) +
                        scipy.ndimage.shift(mask, offset, cval=1, order=0))
                else:
                    shImgMasked = numpy.ma.MaskedArray(shImg,
                                                       (shImg == dummy[0]))
            else:
                if self._strMask:
                    shImgMasked = numpy.ma.MaskedArray(
                        shImg, (abs(shImg - dummy[0]) <= dummy[1]) +
                        scipy.ndimage.shift(mask, offset, cval=1, order=0))
                else:
                    shImgMasked = numpy.ma.MaskedArray(
                        shImg, (abs(shImg - dummy[0]) <= dummy[1]))
            shiftedImage.append(shImgMasked)
            if (offset != ref) and (distanceSq(offset) < refOffset):
                ref = offset
                refOffset = distanceSq(offset)
        refIdx = self._lOffsets.index(ref)

        if EDVerbose.isVerboseDebug():
            e = edfimage(data=shiftedImage[0].filled(self._fDummy),
                         header={
                             "Dummy": str(self._fDummy),
                             "Offset_1": str(self._lOffsets[0][0]),
                             "Offset_2": str(self._lOffsets[0][1])
                         })
            for img, offset in zip(shiftedImage[1:], self._lOffsets[1:]):
                e.appendFrame(data=img.filled(self._fDummy),
                              header={
                                  "Dummy": str(self._fDummy),
                                  "Offset_1": str(offset[0]),
                                  "Offset_2": str(offset[1])
                              })
            e.write("stack.edf")

        ROI = False
        if self.tCenter is None:
            #the default center is the geometry center of the image ...
            self.tCenter = [i // 2 for i in shape]
        if self.tWidth is not None:
            d0min = max(0, self.tCenter[0] - (self.tWidth[0] // 2))
            d0max = min(shape[0], d0min + self.tWidth[0])
            d1min = max(0, self.tCenter[1] - (self.tWidth[1] // 2))
            d1max = min(shape[1], d1min + self.tWidth[1])
            shape = (d0max - d0min, d1max - d1min)
        else:
            d0min = 0
            d0max = shape[0]
            d1min = 0
            d1max = shape[1]
        refImg = shiftedImage[refIdx]
        stackMaskedImg = numpy.ma.zeros(
            (len(self._lOffsets), refImg.shape[0], refImg.shape[1]))
        self.screen(
            "ROI[%s:%s, %s:%s]\t Autoscale: %s\tBlending method: %s" %
            (d0min, d0max, d1min, d1max, self._bAutoscale, self._strBlending))
        if self._bAutoscale:
            for idx, img in enumerate(shiftedImage):
                ratio = (refImg[d0min:d0max, d1min:d1max] /
                         img[d0min:d0max, d1min:d1max])
                stackMaskedImg[idx] = ratio.mean() * img
        else:
            for idx, img in enumerate(shiftedImage):
                stackMaskedImg[idx] = img

        if self._strBlending.lower().startswith("naive"):
            npaTempBool = numpy.cumsum((1 - stackMaskedImg.mask),
                                       axis=0) * (1 - stackMaskedImg.mask) == 1
            result = numpy.ma.MaskedArray(
                (npaTempBool * stackMaskedImg.data).sum(axis=0),
                stackMaskedImg.mask.prod(axis=0))

        elif self._strBlending.lower().startswith("max"):
            result = stackMaskedImg.max(axis=0)
        elif self._strBlending.lower().startswith("min"):
            result = stackMaskedImg.min(axis=0)
        else:  #self._strBlending.lower() == "mean":
            result = stackMaskedImg.mean(axis=0)

        self._ndaResult = result.filled(self._fDummy)
예제 #26
0
    def configure(self):
        """
        Configures the plugin from the configuration file with the following
        parameters
         - The shell that will execute the script
         - Script executor
         - Script executable to be invoked
         - Path to CCP4 setup file if required
         - The 3rd party executable installed version
        """
        EDPluginExec.configure(self)
        EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.configure")
        xsPluginItem = self.getConfiguration()
        if (xsPluginItem == None):
            EDVerbose.warning(
                "EDPluginExecProcessXIA2CORE.configure: No plugin item defined.")
            xsPluginItem = XSPluginItem()

        if (self.getExecutable() is None):
            strExecutable = EDConfiguration.getStringParamValue(
                xsPluginItem,
                EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE)
            if(strExecutable == None):
                strErrorMessage = "Configuration parameter missing: " + \
                                  EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                if (EDVerbose.isVerboseDebug()):
                    raise RuntimeError, strErrorMessage
            else:
                # Check that the executable file exists
                if (os.path.exists(strExecutable) == False):
                    strErrorMessage = "Cannot find configured " + EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE + " : " + strExecutable
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    self.setFailure()
                    if (EDVerbose.isVerboseDebug()):
                        raise RuntimeError, strErrorMessage
                else:
                    self.setExecutable(strExecutable)

        if (self.getConfigXIA2COREType() is None):
            strXIA2COREType = EDConfiguration.getStringParamValue(
                xsPluginItem,
                EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_XIA2CORE_TYPE)
            if(strXIA2COREType == None):
                strErrorMessage = "Configuration parameter not set: " + \
                                  EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_XIA2CORE_TYPE
                EDVerbose.DEBUG(strErrorMessage)
            else:
                # FIXME test that this is a legal name
                self.__strConfigXIA2COREType = strXIA2COREType

        strVersion = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_VERSION_STRING)
        if(strVersion == None):
            EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.configure: No configuration parameter found for: " + \
                            EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_VERSION_STRING + ", NO default value!")
        else:
            self.setStringVersion(strVersion)
        if (self.__strLogFileName == None):
            self.setLogFileName(self.getBaseName() + ".log")
        if (self.__strErrorLogFileName == None):
            self.setErrorLogFileName(self.getBaseName() + ".err")

        if self.__strExecutable is None:
            EDVerbose.ERROR("Executable not defined in configuration file")
            # shall we raise an exception?

        self.__strPathToHostNamePidFile = os.path.join(self.getWorkingDirectory(), os.path.basename(self.__strExecutable) + "_hostNamePid.txt")

        return
예제 #27
0
    if replay:
        ffx = FullFieldXas.replay_from(replay)
    else:
        ffx = FullFieldXas()
        if os.path.isfile(".XSDataInputFullFieldXAS.xml"):
            ffx.load(".XSDataInputFullFieldXAS.xml")

        ffx.dontAlign = dontAlign
        if  dontAlign:
            print("*"*80)
            print("*" + "Skipping image alignement part".center(78) + "*")
            print("*"*80)
        ffx.setup(_listInput=paths, _mode=mode)
    if not isinstance(ffx.reference, int):
        ffx.uploadReferenceFrame(ffx.reference)
    ffx.save(".XSDataInputFullFieldXAS.xml")
    ffx.dump("analysis-%s.json" % time.strftime("%Y%m%d-%Hh%Mm%Ss"))
    edna = EDParallelExecute(ffx.pluginName, ffx.makeXML, _functXMLerr=ffx.error, _bVerbose=True, _bDebug=debug, _iNbThreads=iNbCPU)
    edna.runEDNA(ffx.listInput, ffx.strMode , ffx.bNewerOnly)
    EDVerbose.WARNING("Back to main !")
    EDJob.synchronizeAll()
    ffx.updateAttrRefImage()
    EDPluginControlAlignStackv1_0.showData()
    if keepShare:
        EDShare.close()
    elif (ffx.getNrErrors() == 0) and (not EDVerbose.isVerboseDebug()):
        EDVerbose.WARNING("All processing finished successfully: Remove EDShare's big HDF5 file")
        EDShare.close(remove=True)
    else:
        EDShare.close()
예제 #28
0
if "EDNA_HOME" in os.environ:
    if os.environ["EDNA_HOME"] != strEdnaHome:
        print("Warning: EDNA_HOME redefined to %s" % strEdnaHome)
        os.environ["EDNA_HOME"] = strEdnaHome
else:
    os.environ["EDNA_HOME"] = strEdnaHome
sys.path.append(os.path.join(os.environ["EDNA_HOME"], "kernel", "src"))
from EDUtilsLibraryInstaller import EDUtilsLibraryInstaller
from EDVerbose import EDVerbose


if __name__ == "__main__":
    installDir = os.path.abspath(sys.argv[0]).split(os.sep)[-2]
    EDVerbose.screen("Building %s" % installDir)
    install = EDUtilsLibraryInstaller(installDir, strArchiveName)
    install.checkPythonVersion()
    install.downloadLibrary()
    install.dependency("numpy", "20090405-Numpy-1.3")
    install.unZipArchive()
    try:
        install.buildSources()
    except Exception:
        EDVerbose.ERROR("Error in the build")
    install.installBuilt()
    if not EDVerbose.isVerboseDebug():
        install.cleanSources()

else:
    EDVerbose.ERROR("This installer program is not made to be imported, please just run it")
예제 #29
0
    def configure(self):
        """
        Configures the plugin from the configuration file with the following
        parameters
         - The shell that will execute the script
         - Script executor
         - Script executable to be invoked
         - Path to CCP4 setup file if required
         - The 3rd party executable installed version
        """
        EDPluginExec.configure(self)
        EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.configure")
        xsPluginItem = self.getConfiguration()
        if (xsPluginItem == None):
            EDVerbose.warning(
                "EDPluginExecProcessXIA2CORE.configure: No plugin item defined."
            )
            xsPluginItem = XSPluginItem()

        if (self.getExecutable() is None):
            strExecutable = EDConfiguration.getStringParamValue(
                xsPluginItem,
                EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE)
            if (strExecutable == None):
                strErrorMessage = "Configuration parameter missing: " + \
                                  EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                if (EDVerbose.isVerboseDebug()):
                    raise RuntimeError, strErrorMessage
            else:
                # Check that the executable file exists
                if (os.path.exists(strExecutable) == False):
                    strErrorMessage = "Cannot find configured " + EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE + " : " + strExecutable
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    self.setFailure()
                    if (EDVerbose.isVerboseDebug()):
                        raise RuntimeError, strErrorMessage
                else:
                    self.setExecutable(strExecutable)

        if (self.getConfigXIA2COREType() is None):
            strXIA2COREType = EDConfiguration.getStringParamValue(
                xsPluginItem,
                EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_XIA2CORE_TYPE)
            if (strXIA2COREType == None):
                strErrorMessage = "Configuration parameter not set: " + \
                                  EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_XIA2CORE_TYPE
                EDVerbose.DEBUG(strErrorMessage)
            else:
                # FIXME test that this is a legal name
                self.__strConfigXIA2COREType = strXIA2COREType

        strVersion = EDConfiguration.getStringParamValue(
            xsPluginItem,
            EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_VERSION_STRING)
        if (strVersion == None):
            EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.configure: No configuration parameter found for: " + \
                            EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_VERSION_STRING + ", NO default value!")
        else:
            self.setStringVersion(strVersion)
        if (self.__strLogFileName == None):
            self.setLogFileName(self.getBaseName() + ".log")
        if (self.__strErrorLogFileName == None):
            self.setErrorLogFileName(self.getBaseName() + ".err")

        if self.__strExecutable is None:
            EDVerbose.ERROR("Executable not defined in configuration file")
            # shall we raise an exception?

        self.__strPathToHostNamePidFile = os.path.join(
            self.getWorkingDirectory(),
            os.path.basename(self.__strExecutable) + "_hostNamePid.txt")

        return