def _compareMaterials(self, other, lower, upper, sigma): """Private method for going directly into the comparison.""" commonMats = getKeyMatchingShapes(self.materials, other.materials, 'materials') similar = (len(self) == len(other) == len(commonMats)) for matName in sorted(commonMats): myMat = self[matName] otherMat = other[matName] similar &= myMat.compare(otherMat, lower, upper, sigma) return similar
def compareResults(self, other, lower=DEF_COMP_LOWER, upper=DEF_COMP_UPPER, sigma=DEF_COMP_SIGMA, header=False): """ Compare the contents of the results dictionary Parameters ---------- other: :class:`ResultsReader` Class against which to compare {compLimits} {sigma} {header} Returns ------- bool: If the results data agree to given tolerances Raises ------ {compTypeErr} """ self._checkCompareObj(other) if header: self._compareLogPreMsg(other, lower, upper, sigma, 'results') myRes = self.resdata otherR = other.resdata commonTypeKeys = getKeyMatchingShapes(myRes, otherR, 'results') similar = len(commonTypeKeys) == len(myRes) == len(otherR) for key in sorted(commonTypeKeys): mine = myRes[key] theirs = otherR[key] if key in RES_DATA_NO_UNCS: similar &= logDirectCompare(mine, theirs, lower, upper, key) continue myVals, myUncs = splitValsUncs(mine) theirVals, theirUncs = splitValsUncs(theirs) similar &= getLogOverlaps(key, myVals, theirVals, myUncs, theirUncs, sigma, relative=True) return similar
def _helpCompareGCDict(self, other, attrBase, sigma): """ Method that actually compare group constant dictionaries. ``attrBase`` is used to find dictionaries by appending ``'Exp'`` and ``'Unc'`` to ``attrBase`` """ self._checkCompareObj(other) valName = (attrBase + 'Exp') if attrBase != 'gc' else 'gc' uncName = attrBase + 'Unc' try: myVals = getattr(self, valName) myUncs = getattr(self, uncName) otherVals = getattr(other, valName) otherUncs = getattr(other, uncName) except Exception as ee: critical("The following error was raised extracting {} and " "{} from universes {} and {}:\n\t{}".format( valName, uncName, self, other, ee)) return False keys = getKeyMatchingShapes(myVals, otherVals, valName) similar = len(keys) == len(myVals) == len(otherVals) for key in keys: if key not in myUncs or key not in otherUncs: loc = self if key in otherUncs else other error("Uncertainty data for {} missing from {}".format( key, loc)) similar = False continue myVal = myVals[key] myUnc = myUncs[key] otherVal = otherVals[key] otherUnc = otherUncs[key] similar &= getLogOverlaps(key, myVal, otherVal, myUnc, otherUnc, sigma, relative=True) return similar
def compareAttributes(self, other, lower=DEF_COMP_LOWER, upper=DEF_COMP_UPPER, sigma=DEF_COMP_SIGMA): """ Compare attributes like group structure and burnup. Return the result Parameters ---------- other: :class:`HomogUniv` Universe against which to compare {compLimits} {sigma} Returns ------- bools: ``True`` if the attributes agree within specifications Raises ------ {compTypeErr} """ self._checkCompareObj(other) myMeta = {} otherMeta = {} for key in {'bu', 'step', 'groups', 'microGroups', 'reshaped'}: for meta, obj in zip((myMeta, otherMeta), (self, other)): try: meta[key] = getattr(obj, key) except AttributeError: meta[key] = None matchingKeys = getKeyMatchingShapes(myMeta, otherMeta, 'metadata') similar = len(matchingKeys) == len(myMeta) for key in sorted(matchingKeys): similar &= logDirectCompare(myMeta[key], otherMeta[key], lower, upper, key) return similar
def compareUniverses(self, other, lower=DEF_COMP_LOWER, upper=DEF_COMP_UPPER, sigma=DEF_COMP_SIGMA): """ Compare the contents of the ``universes`` dictionary Parameters ---------- other: :class:`ResultsReader` Reader by which to compare {compLimits} {sigma} Returns ------- bool: If the contents of the universes agree to given tolerances Raises ------ {compTypeErr} """ self._checkCompareObj(other) myUniverses = self.universes otherUniverses = other.universes keyGoodTypes = getKeyMatchingShapes(myUniverses, otherUniverses, 'universes') similar = len(keyGoodTypes) == len(myUniverses) == len(otherUniverses) for univKey in keyGoodTypes: myUniv = myUniverses[univKey] otherUniv = otherUniverses[univKey] similar &= myUniv.compare(otherUniv, lower, upper, sigma) return similar