def MissingValue(self, name): """ Return the value denoting "missing value" for the supplied field """ variable = self.Variable(name) if hasattr(variable, "missing_value"): assert (len(variable.missing_value) == 1) return float(variable.missing_value) else: return calc.Nan()
def JoinStat(*args): """ Joins a series of stat files together. Useful for combining checkpoint .stat files. Selects data in later stat files over earlier stat files. Assumes data in stat files are sorted by ElapsedTime. """ nStat = len(args) assert (nStat > 0) times = [stat["ElapsedTime"] for stat in args] startT = [t[0] for t in times] permutation = utils.KeyedSort(startT, range(nStat)) stats = [args[index] for index in permutation] startT = [startT[index] for index in permutation] times = [times[index] for index in permutation] endIndices = numpy.array([len(time) for time in times], dtype=int) for i, t in enumerate(times[:-1]): for j, time in enumerate(t): if calc.AlmostEquals(startT[i + 1], time, tolerance=1.0e-6): endIndices[i] = max(j - 1, 0) break elif startT[i + 1] < time: endIndices[i] = j break debug.dprint("Time ranges:") if len(times) > 0: for i in range(nStat): debug.dprint((startT[i], times[i][endIndices[i] - 1])) else: debug.dprint("No data") dataIndices = numpy.empty(len(args) + 1, dtype=int) dataIndices[0] = 0 for i, index in enumerate(endIndices): dataIndices[i + 1] = dataIndices[i] + index stat = stats[0] data = {} for key in stat.keys(): arr = stat[key] shape = list(arr.shape) shape[0] = dataIndices[-1] data[key] = numpy.empty(shape, dtype=arr.dtype) data[key][:dataIndices[1]] = arr[:endIndices[0]] data[key][dataIndices[1]:] = calc.Nan() delimiter = stat.GetDelimiter() for i in range(1, nStat): stat = stats[i] for key in stat.keys(): arr = stat[key] if not key in data: shape = list(arr.shape) shape[0] = dataIndices[-1] data[key] = numpy.empty(shape, dtype=arr.dtype) data[key][:dataIndices[i]] = calc.Nan() data[key][dataIndices[i + 1]:] = calc.Nan() data[key][dataIndices[i]:dataIndices[i + 1]] = arr[:endIndices[i]] output = Stat(delimiter=delimiter) for key in data.keys(): output[key] = numpy.array(data[key]) return output