Example #1
0
 def readAndParseFile(_strFileName):
     """
     Reads a file and parses potential existing environment variables such as:
      - EDNA_TESTS_DATA_HOME
     Returns the content of this file as a string
     """
     return EDUtilsFile.readFileAndParseVariables(_strFileName, EDUtilsPath.getDictOfPaths())
Example #2
0
 def getDictReplace(self):
     dictReplace = EDUtilsPath.getDictOfPaths()
     dictReplace["${EDNA_PLUGIN_TESTS_DATA_HOME}"] = self._strPluginTestsDataHome
     if self._edPlugin is not None:
         workDir = self._edPlugin.getWorkingDirectory()
         if workDir is not None:
             dictReplace["${EDNA_WORKING_DIR}"] = workDir
     return dictReplace
Example #3
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()
Example #4
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)
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

        ################################################################################
        # Compare XSDataResults
        ################################################################################

        strExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        #        strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile)
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsAzimutIntv1_0.parseString(
            strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(),
                                xsDataResultObtained.marshal(),
                                "XSDataResult output are the same",
                                _strExcluded="bioSaxs")

        ################################################################################
        # Compare spectrum ascii Files
        ################################################################################

        outputData = open(
            xsDataResultObtained.getIntegratedCurve().getPath().value,
            "rb").read().split(os.linesep)
        referenceData = EDUtilsFile.readFileAndParseVariables(
            os.path.join(self.getTestsDataImagesHome(),
                         "bioSaxsIntegratedv1_3.dat"),
            EDUtilsPath.getDictOfPaths()).split(os.linesep)
        outputData = os.linesep.join(
            [i for i in outputData if not i.startswith("# History")])
        referenceData = os.linesep.join(
            [i for i in referenceData if not i.startswith("# History")])
        EDAssert.strAlmostEqual(
            referenceData,
            outputData,
            _strComment="3column ascii spectra files are the same",
            _fRelError=0.1,
            _fAbsError=0.1,
            _strExcluded="bioSaxs")
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

################################################################################
# Compare XSDataResults
################################################################################

        strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile())
#        strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile)
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsAzimutIntv1_0.parseString(strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "XSDataResult output are the same", _strExcluded="bioSaxs")

################################################################################
# Compare spectrum ascii Files
################################################################################

        outputData = open(xsDataResultObtained.getIntegratedCurve().getPath().value, "rb").read().split(os.linesep)
        referenceData = EDUtilsFile.readFileAndParseVariables(os.path.join(self.getTestsDataImagesHome(), "bioSaxsIntegratedv1_2.dat"), EDUtilsPath.getDictOfPaths()).split(os.linesep)
        outputData = os.linesep.join([i for i in outputData if not i.startswith("# History")])
        referenceData = os.linesep.join([i for i in referenceData if not i.startswith("# History")])
        EDAssert.strAlmostEqual(referenceData, outputData, _strComment="3column ascii spectra files are the same", _fRelError=0.1, _fAbsError=0.1, _strExcluded="bioSaxs")

################################################################################
# Compare images 
################################################################################
#        edfObt = EdfFile.EdfFile(xsDataResultObtained.getCorrectedImage().getPath().value)
#        edfRef = EdfFile.EdfFile(os.path.join(self.getTestsDataImagesHome(), "bioSaxsCorrected.edf"))
#        outputData = edfObt.GetData(0)
#        referenceData = edfRef.GetData(0)
#        EDAssert.arraySimilar(outputData, referenceData , _fAbsMaxDelta=0.1, _fScaledMaxDelta=0.05, _strComment="Corrected images are the same")

#        headerRef = edfRef.GetHeader(0)
#        headerObt = edfObt.GetHeader(0)
#        keysRef = headerRef.keys()
#        keysObt = headerObt.keys()
#        keysRef.sort()
#        keysObt.sort()
#        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dictionary for Corrected Images")
#        for key in keysRef:
#            EDAssert.strAlmostEqual(headerRef[key], headerObt[key], _strComment="header value in Corrected %s are the same" % key, _strExcluded="bioSaxs")

        edfObt = EdfFile.EdfFile(os.path.join(self.getTestsDataImagesHome(), "bioSaxsIntegrated.edf"))
        edfRef = EdfFile.EdfFile(xsDataResultObtained.getIntegratedImage().getPath().value)
        outputData = edfObt.GetData(0)
        referenceData = edfRef.GetData(0)
        EDAssert.arraySimilar(outputData, referenceData , _fScaledMaxDelta=0.05, _strComment="Integrated images are the same")

        headerRef = edfRef.GetHeader(0)
        headerObt = edfObt.GetHeader(0)
        keysRef = headerRef.keys()
        keysObt = headerObt.keys()
        keysRef.sort()
        keysObt.sort()
        for key in ["HeaderID", "Image", 'EDF_BinarySize', "EDF_DataBlockID", "EDF_HeaderSize", "filename", "RasterOrientation", "History-1", "History-1~1"]:
            if key in keysObt: keysObt.remove(key)
            if key in keysRef: keysRef.remove(key)
        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dictionary for Integrated Images")
        for key in keysRef:
            EDAssert.strAlmostEqual(headerRef[key], headerObt[key], _strComment="header value in Integrated %s are the same" % key, _strExcluded="bioSaxs")
Example #7
0
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

        ################################################################################
        # Compare XSDataResults
        ################################################################################

        strExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsProcessOneFilev1_0.parseString(
            strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(),
                                xsDataResultObtained.marshal(),
                                "XSDataResult output are the same",
                                _strExcluded="bioSaxs")

        ################################################################################
        # Compare dictionary
        ################################################################################
        obtFile = xsDataResultObtained.integratedImage.path.value
        refFile = os.path.join(self.getTestsDataImagesHome(),
                               "bioSaxsProcessIntegrated.edf")
        EDVerbose.DEBUG("fileRef=%s fileObt=%s" % (refFile, obtFile))
        edfRef = openimage(refFile)
        edfObt = openimage(obtFile)
        headerRef = edfRef.header
        headerObt = edfObt.header

        keysRef = headerRef.keys()
        keysObt = headerObt.keys()
        keysRef.sort()
        keysObt.sort()
        #        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dict")
        for key in keysRef:
            if not (key.startswith("History") or key in [
                    "Compression", "DDummy", "Dummy", "EDF_HeaderSize",
                    "HeaderID", "Image", "filename", "RasterOrientation"
            ]):
                EDAssert.strAlmostEqual(
                    headerRef[key],
                    headerObt[key],
                    _strComment="header value %s are the same" % key,
                    _strExcluded="bioSaxs")


################################################################################
# Compare images
################################################################################

        outputData = edfRef.data
        referenceData = edfObt.data
        EDAssert.arraySimilar(numpy.maximum(outputData, 0),
                              numpy.maximum(referenceData, 0),
                              _fScaledMaxDelta=0.05,
                              _strComment="Images-data are the same")

        outputData = edfRef.next().data
        referenceData = edfObt.next().data
        EDAssert.arraySimilar(numpy.maximum(outputData, 0),
                              numpy.maximum(referenceData, 0),
                              _fScaledMaxDelta=0.05,
                              _strComment="Images-ESD are the same")

        ################################################################################
        # Compare Ascii files
        ################################################################################
        asciiObt = os.linesep.join([
            i.strip()
            for i in open(xsDataResultObtained.integratedCurve.path.value)
            if "RasterOrientation" not in i
        ])
        asciiRef = os.linesep.join([
            i.strip() for i in EDUtilsFile.readFileAndParseVariables(
                os.path.join(self.getTestsDataImagesHome(),
                             "bioSaxsProcessIntegrated.dat"),
                EDUtilsPath.getDictOfPaths()).split(os.linesep)
            if "RasterOrientation" not in i
        ])
        EDAssert.strAlmostEqual(
            asciiRef,
            asciiObt,
            _strComment="3 column ascii files are the same",
            _fRelError=0.1,
            _strExcluded=os.environ["USER"])
 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)
 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 testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

        ################################################################################
        # Compare XSDataResults
        ################################################################################

        strExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        #        strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile)
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsAzimutIntv1_0.parseString(
            strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(),
                                xsDataResultObtained.marshal(),
                                "XSDataResult output are the same",
                                _strExcluded="bioSaxs")

        ################################################################################
        # Compare spectrum ascii Files
        ################################################################################

        outputData = open(
            xsDataResultObtained.getIntegratedCurve().getPath().value,
            "rb").read().split(os.linesep)
        referenceData = EDUtilsFile.readFileAndParseVariables(
            os.path.join(self.getTestsDataImagesHome(),
                         "bioSaxsIntegratedv1_1.dat"),
            EDUtilsPath.getDictOfPaths()).split(os.linesep)
        outputData = os.linesep.join([
            i for i in outputData
            if not (i.startswith("# History") or i.startswith("# Raster"))
        ])
        referenceData = os.linesep.join([
            i for i in referenceData
            if not (i.startswith("# History") or i.startswith("# Raster"))
        ])

        EDAssert.strAlmostEqual(
            referenceData,
            outputData,
            _strComment="3column ascii spectra files are the same",
            _fRelError=0.1,
            _fAbsError=0.1,
            _strExcluded="bioSaxs")

        ################################################################################
        # Compare images
        ################################################################################
        #        edfObt = EdfFile.EdfFile(xsDataResultObtained.getCorrectedImage().getPath().value)
        #        edfRef = EdfFile.EdfFile(os.path.join(self.getTestsDataImagesHome(), "bioSaxsCorrected.edf"))
        #        outputData = edfObt.GetData(0)
        #        referenceData = edfRef.GetData(0)
        #        EDAssert.arraySimilar(outputData, referenceData , _fAbsMaxDelta=0.1, _fScaledMaxDelta=0.05, _strComment="Corrected images are the same")

        #        headerRef = edfRef.GetHeader(0)
        #        headerObt = edfObt.GetHeader(0)
        #        keysRef = headerRef.keys()
        #        keysObt = headerObt.keys()
        #        keysRef.sort()
        #        keysObt.sort()
        #        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dictionary for Corrected Images")
        #        for key in keysRef:
        #            EDAssert.strAlmostEqual(headerRef[key], headerObt[key], _strComment="header value in Corrected %s are the same" % key, _strExcluded="bioSaxs")

        edfObt = EdfFile.EdfFile(
            os.path.join(self.getTestsDataImagesHome(),
                         "bioSaxsIntegrated.edf"))
        edfRef = EdfFile.EdfFile(
            xsDataResultObtained.getIntegratedImage().getPath().value)
        outputData = edfObt.GetData(0)
        referenceData = edfRef.GetData(0)
        EDAssert.arraySimilar(outputData,
                              referenceData,
                              _fScaledMaxDelta=0.05,
                              _strComment="Integrated images are the same")

        headerRef = edfRef.GetHeader(0)
        headerObt = edfObt.GetHeader(0)
        keysRef = headerRef.keys()
        keysObt = headerObt.keys()
        keysRef.sort()
        keysObt.sort()
        for key in [
                "HeaderID", "Image", 'EDF_BinarySize', "EDF_DataBlockID",
                "EDF_HeaderSize", "filename", "RasterOrientation", "History-1",
                "History-1~1", "History-2"
        ]:
            if key in keysObt: keysObt.remove(key)
            if key in keysRef: keysRef.remove(key)
        EDAssert.equal(
            keysRef,
            keysObt,
            _strComment=
            "Same keys in the header dictionary for Integrated Images")
        for key in keysRef:
            EDAssert.strAlmostEqual(
                headerRef[key],
                headerObt[key],
                _strComment="header value in Integrated %s are the same" % key,
                _strExcluded="bioSaxs")
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

################################################################################
# Compare XSDataResults
################################################################################

        strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile())
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsProcessOneFilev1_0.parseString(strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "XSDataResult output are the same", _strExcluded="bioSaxs")


################################################################################
# Compare dictionary
################################################################################
        obtFile = xsDataResultObtained.integratedImage.path.value
        refFile = os.path.join(self.getTestsDataImagesHome(), "bioSaxsProcessIntegrated.edf")
        EDVerbose.DEBUG("fileRef=%s fileObt=%s" % (refFile, obtFile))
        edfRef = openimage(refFile)
        edfObt = openimage(obtFile)
        headerRef = edfRef.header
        headerObt = edfObt.header

        keysRef = headerRef.keys()
        keysObt = headerObt.keys()
        keysRef.sort()
        keysObt.sort()
#        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dict")
        for key in keysRef:
            if not (key.startswith("History") or key in [ "Compression", "DDummy", "Dummy", "EDF_HeaderSize", "HeaderID", "Image", "filename", "RasterOrientation"]):
                EDAssert.strAlmostEqual(headerRef[key], headerObt[key], _strComment="header value %s are the same" % key, _strExcluded="bioSaxs")

################################################################################
# Compare images 
################################################################################

        outputData = edfRef.data
        referenceData = edfObt.data
        EDAssert.arraySimilar(numpy.maximum(outputData, 0), numpy.maximum(referenceData, 0) , _fScaledMaxDelta=0.05, _strComment="Images-data are the same")

        outputData = edfRef.next().data
        referenceData = edfObt.next().data
        EDAssert.arraySimilar(numpy.maximum(outputData, 0), numpy.maximum(referenceData, 0) , _fScaledMaxDelta=0.05, _strComment="Images-ESD are the same")

################################################################################
# Compare Ascii files
################################################################################
        asciiObt = os.linesep.join([i.strip() for i in  open(xsDataResultObtained.integratedCurve.path.value) if "RasterOrientation" not in i])
        asciiRef = os.linesep.join([i.strip() for i in  EDUtilsFile.readFileAndParseVariables(os.path.join(self.getTestsDataImagesHome(), "bioSaxsProcessIntegrated.dat"), EDUtilsPath.getDictOfPaths()).split(os.linesep) if "RasterOrientation" not in i])
        EDAssert.strAlmostEqual(asciiRef, asciiObt, _strComment="3 column ascii files are the same", _fRelError=0.1, _strExcluded=os.environ["USER"])
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

################################################################################
# Compare XSDataResults
################################################################################

        strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile())
#        strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile)
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsAzimutIntv1_0.parseString(strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "XSDataResult output are the same", _strExcluded="bioSaxs")

################################################################################
# Compare spectrum ascii Files
################################################################################

        outputData = open(xsDataResultObtained.getIntegratedCurve().getPath().value, "rb").read().split(os.linesep)
        referenceData = EDUtilsFile.readFileAndParseVariables(os.path.join(self.getTestsDataImagesHome(), "bioSaxsIntegratedv1_3.dat"), EDUtilsPath.getDictOfPaths()).split(os.linesep)
        outputData = os.linesep.join([i for i in outputData if not i.startswith("# History")])
        referenceData = os.linesep.join([i for i in referenceData if not i.startswith("# History")])
        EDAssert.strAlmostEqual(referenceData, outputData, _strComment="3column ascii spectra files are the same", _fRelError=0.1, _fAbsError=0.1, _strExcluded="bioSaxs")