def _read(self): curKey = None scratch = ScratchStorage() cycles = None indx = 0 with open(self.filePath) as out: for lineNo, line in enumerate(out): if not line.strip(): continue if '=' in line: serpentN = line.split()[0].replace('HIS_', '') curKey = convertVariableName(serpentN) continue if 'active' in line: if self.numInactive is None: self.numInactive = indx continue if line[0] == ']': data = asfortranarray(scratch.data) self.arrays[curKey] = data cycles = data.shape[0] indx = 0 continue values = line.split()[1:] # skip indexing term indx += 1 values = [float(xx) for xx in values] if cycles and indx == 1: scratch.allocate((cycles, len(values))) scratch[indx - 1] = values
def addData(self, variable, rawData): """ Add data straight from the file onto a variable. Parameters ---------- variable: str Name of the variable directly from ``SERPENT`` rawData: list List of strings corresponding to the raw data from the file """ newName = convertVariableName(variable) debug('Adding {} data to {}'.format(newName, self.name)) if isinstance(rawData, str): scratch = [float(item) for item in rawData.split()] else: scratch = [] for line in rawData: if line: scratch.append([float(item) for item in line.split()]) self.data[newName] = numpy.array(scratch)
def addData(self, variableName, variableValue, uncertainty=False): """ sets the value of the variable and, optionally, the associate s.d. .. warning:: This method will overwrite data for variables that already exist Parameters ---------- variableName: str Variable Name variableValue: Variable Value uncertainty: bool Set to ``True`` in order to retrieve the uncertainty associated to the expected values Raises ------ TypeError If the uncertainty flag is not boolean """ # 1. Check the input type variableName = convertVariableName(variableName) if not isinstance(uncertainty, bool): raise TypeError('The variable uncertainty has type {}, ' 'should be boolean.'.format(type(uncertainty))) # 2. Pointer to the proper dictionary setter = self._lookup(variableName, uncertainty) # 3. Check if variable is already present. Then set the variable. if variableName in setter: warning("The variable {} will be overwritten".format(variableName)) setter[variableName] = variableValue
def varsToBullets(incomingVars): lines = "\n" for item in sorted(incomingVars): lines += VAR_FMTR.format(original=item, converted=convertVariableName(item)) return lines + '\n'