def loadFromContainer(self, container): """ Copy data from a similar container. Parameters ---------- container: Incoming container from which to take data. Raises ------ serpentTools.messages.MismatchedContainersError If the incoming container is not the expected type declared at construction serpentTools.messages.SamplerError If more containers have been loaded than specified at construction """ if not isinstance(container, self.__expectedClass): raise MismatchedContainersError( 'Sampled container expects {} type containers, not ' '{}'.format(self.__expectedClass, type(container))) if self._index == self.N: name = self.name if hasattr(self, 'name') else '' otherName = container.__class__.__name__ msg = ("{} {} has already loaded {} {} objects and cannot exceed " "this bound ".format(self.__class__.__name__, name, self.N, otherName)) raise SamplerError(msg) self._loadFromContainer(container) self._index += 1
def _raiseErrorMsgFromDict(misMatches, header, objName): msg = 'Files do not contain a consistent set of {}'.format(objName) critMsgs = [msg, header + ": Parser files"] for key, values in iteritems(misMatches): critMsgs.append('{}: {}'.format(key, ', '.join(values))) error('\n'.join(str(item) for item in critMsgs)) raise MismatchedContainersError(msg)
def _loadFromContainer(self, detector): """ Load data from a detector Parameters ---------- detector Returns ------- """ if detector.name != self.name: warning("Attempting to read from detector with dissimilar names: " "Base: {}, incoming: {}".format(self.name, detector.name)) if not self._index: self.__shape = tuple([self.N] + list(detector.tallies.shape)) self.__allocate(detector.scores is not None) if self.__shape[1:] != detector.tallies.shape: raise MismatchedContainersError( "Incoming detector {} tally data shape does not match " "sampled shape. Base: {}, incoming: {}".format( detector.name, self.__shape[1:], detector.tallies.shape)) self.__load(detector.tallies, detector.errors, detector.scores, detector.name) if self.indexes is None: self.indexes = detector.indexes if not self.grids: self.grids = detector.grids
def __load(self, tallies, errors, scores, oName): index = self._index otherHasScores = scores is not None selfHasScores = self.allScores is not None if otherHasScores and selfHasScores: self.allScores[index, ...] = scores elif otherHasScores and not selfHasScores: warning("Incoming detector {} has score data, while base does " "not. Skipping score data".format(oName)) elif not otherHasScores and selfHasScores: raise MismatchedContainersError( "Incoming detector {} does not have score data, while base " "does.".format(oName)) self.allTallies[index] = tallies self.allErrors[index] = tallies * errors