Esempio n. 1
0
    def compare(self, other, selfContainer, otherContainer, tolerance=0.0):
        """
        Compare the metadata for two libraries.

        Parameters
        ----------
        other: Similar Metadata class as self
            Metadata to be compared against
        selfContainer: class
        otherContainer: class
            Objects that hold the two metadata instances
        tolerance: float
            Acceptable difference between two metadata values

        Returns
        -------
        equal: bool
            If the metadata are equal or not.
        """
        equal = True
        for propName in set(list(self.keys()) + list(other.keys())):
            selfVal = self[propName]
            otherVal = other[propName]
            if not properties.areEqual(selfVal, otherVal, tolerance):
                runLog.important(
                    "{} and {} {} have different {}:\n{}\n{}".format(
                        selfContainer,
                        otherContainer,
                        self.__class__.__name__,
                        propName,
                        selfVal,
                        otherVal,
                    ))
                equal = False
        return equal
Esempio n. 2
0
def compareXSLibraryAttribute(lib1, lib2, attributeName, tolerance=0.0):
    """Compare the values of an attribute in two libraries."""
    val1 = getattr(lib1, "_" + attributeName, None)
    val2 = getattr(lib2, "_" + attributeName, None)
    if not properties.areEqual(val1, val2, tolerance):
        runLog.important(
            "{} and {} have different `{}` attributes:\n{}\n{}".format(
                lib1, lib2, attributeName, val1, val2))
        return False
    return True
Esempio n. 3
0
    def compare(self, other, flux, relativeTolerance=0, verbose=False):
        """Compare the cross sections between two XSCollections objects."""
        equal = True
        for xsName in ALL_COLLECTION_DATA:

            myXsData = self.__dict__[xsName]
            theirXsData = other.__dict__[xsName]

            if xsName == HIGHORDER_SCATTER:
                for actualList, expectedList in zip(myXsData, theirXsData):
                    if actualList != expectedList:
                        equal = False
                        runLog.important(
                            "  {} {:<30} cross section is different.".format(
                                self.source, xsName
                            )
                        )

            elif sparse.issparse(myXsData) and sparse.issparse(theirXsData):
                if not numpy.allclose(
                    myXsData.todense(),
                    theirXsData.todense(),
                    rtol=relativeTolerance,
                    atol=0.0,
                ):
                    verboseData = (
                        ""
                        if not verbose
                        else "\n{},\n\n{}".format(myXsData, theirXsData)
                    )
                    runLog.important(
                        "  {} {:<30} cross section is different.{}".format(
                            self.source, xsName, verboseData
                        )
                    )
                    equal = False
            elif isinstance(myXsData, dict) and myXsData != theirXsData:
                # there are no dicts currently so code is untested
                raise NotImplementedError("there are no dicts")
            elif not properties.areEqual(myXsData, theirXsData, relativeTolerance):
                verboseData = (
                    "" if not verbose else "\n{},\n\n{}".format(myXsData, theirXsData)
                )
                runLog.important(
                    "  {} {:<30} cross section is different.{}".format(
                        self.source, xsName, verboseData
                    )
                )
                equal = False
        return equal