def __addSens(self, varName, vec, isEnergyIntegrated): dest = (self.energyIntegratedSens if isEnergyIntegrated else self.sensitivities) newShape = [2, self.nPert, self.nZai, self.nMat] if not isEnergyIntegrated: newShape.insert(1, self.nEne) try: newName = convertVariableName(varName) dest[newName] = reshapePermuteSensMat(vec, newShape) except Exception as ee: critical("The following error was raised attempting to " "reshape matrix {}".format(varName)) raise ee
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 test_depSamplerValidCalcs(self): """ Run through all variables and materials and check error propagation and averaging. """ errMsg = "{varN} {qty} for material {matN}" for name, material in self.sampler.iterMaterials(): for varName, varData in iteritems(material.data): r0 = self.reader0.materials[name].data[varName] r1 = self.reader1.materials[name].data[varName] samplerUnc = material.uncertainties[varName] expectedMean, expectedStd = computeMeansErrors(r0, r1) for qty, actual, expected in zip(('mean', 'uncertainty'), (varData, samplerUnc), (expectedMean, expectedStd)): msg = errMsg.format(qty=qty, varN=varName, matN=material) try: assert_allclose(actual, expected, err_msg=msg, rtol=1E-5) except AssertionError as ae: critical("\nMaterial {} - value {}".format( name, varName)) for aRow, eRow in zip(actual, expected): critical('Actual: {}'.format(aRow)) critical('Expected: {}'.format(eRow)) den = aRow.copy() if isinstance(den, ndarray): den[where(den == 0)] = 1 else: den = den or 1 rDiff = (fabs(aRow - eRow) / den) critical('Relative: {}'.format(rDiff)) raise ae