def testArrays(rtData, rtData2, grad, grad2, total_npts): " Test various parallel algorithms." if rank == 0: print "-----------------------" PRINT("SUM ones:", algs.sum(rtData / rtData) - total_npts) PRINT( "SUM sin:", (algs.sum(algs.sin(rtData) + 1) - numpy.sum(numpy.sin(rtData2) + 1)) / numpy.sum(numpy.sin(rtData2) + 1), ) PRINT("rtData min:", algs.min(rtData) - numpy.min(rtData2)) PRINT("rtData max:", algs.max(rtData) - numpy.max(rtData2)) PRINT("rtData sum:", (algs.sum(rtData) - numpy.sum(rtData2)) / (2 * numpy.sum(rtData2))) PRINT("rtData mean:", (algs.mean(rtData) - numpy.mean(rtData2)) / (2 * numpy.mean(rtData2))) PRINT("rtData var:", (algs.var(rtData) - numpy.var(rtData2)) / numpy.var(rtData2)) PRINT("rtData std:", (algs.std(rtData) - numpy.std(rtData2)) / numpy.std(rtData2)) PRINT("grad min:", algs.min(grad) - numpy.min(grad2)) PRINT("grad max:", algs.max(grad) - numpy.max(grad2)) PRINT("grad min 0:", algs.min(grad, 0) - numpy.min(grad2, 0)) PRINT("grad max 0:", algs.max(grad, 0) - numpy.max(grad2, 0)) PRINT("grad min 1:", algs.sum(algs.min(grad, 1)) - numpy.sum(numpy.min(grad2, 1))) PRINT("grad max 1:", algs.sum(algs.max(grad, 1)) - numpy.sum(numpy.max(grad2, 1))) PRINT("grad sum 1:", algs.sum(algs.sum(grad, 1)) - numpy.sum(numpy.sum(grad2, 1))) PRINT("grad var:", (algs.var(grad) - numpy.var(grad2)) / numpy.var(grad2)) PRINT("grad var 0:", (algs.var(grad, 0) - numpy.var(grad2, 0)) / numpy.var(grad2, 0))
def testArrays(rtData, rtData2, grad, grad2, total_npts): " Test various parallel algorithms." if rank == 0: print('-----------------------') PRINT("SUM ones:", algs.sum(rtData / rtData) - total_npts) PRINT( "SUM sin:", (algs.sum(algs.sin(rtData) + 1) - numpy.sum(numpy.sin(rtData2) + 1)) / numpy.sum(numpy.sin(rtData2) + 1)) PRINT("rtData min:", algs.min(rtData) - numpy.min(rtData2)) PRINT("rtData max:", algs.max(rtData) - numpy.max(rtData2)) PRINT("rtData sum:", (algs.sum(rtData) - numpy.sum(rtData2)) / (2 * numpy.sum(rtData2))) PRINT("rtData mean:", (algs.mean(rtData) - numpy.mean(rtData2)) / (2 * numpy.mean(rtData2))) PRINT("rtData var:", (algs.var(rtData) - numpy.var(rtData2)) / numpy.var(rtData2)) PRINT("rtData std:", (algs.std(rtData) - numpy.std(rtData2)) / numpy.std(rtData2)) PRINT("grad min:", algs.min(grad) - numpy.min(grad2)) PRINT("grad max:", algs.max(grad) - numpy.max(grad2)) PRINT("grad min 0:", algs.min(grad, 0) - numpy.min(grad2, 0)) PRINT("grad max 0:", algs.max(grad, 0) - numpy.max(grad2, 0)) PRINT("grad min 1:", algs.sum(algs.min(grad, 1)) - numpy.sum(numpy.min(grad2, 1))) PRINT("grad max 1:", algs.sum(algs.max(grad, 1)) - numpy.sum(numpy.max(grad2, 1))) PRINT("grad sum 1:", algs.sum(algs.sum(grad, 1)) - numpy.sum(numpy.sum(grad2, 1))) PRINT("grad var:", (algs.var(grad) - numpy.var(grad2)) / numpy.var(grad2)) PRINT("grad var 0:", (algs.var(grad, 0) - numpy.var(grad2, 0)) / numpy.var(grad2, 0))
def get_range(self, attr='scalars', mode='point'): assert mode in ('point', 'cell') assert attr in ('scalars', 'vectors') dataset = self.dataset da = dataset.PointData if mode == 'point' else dataset.CellData x = self._get_attr(da, attr, mode) if x is None: return None, [0.0, 1.0] name, x = x if self._composite: # Don't bother with Nans for composite data for now. if isinstance(x, dsa.VTKNoneArray): res = [0.0, 1.0] elif attr == 'scalars': res = [algs.min(x), algs.max(x)] else: max_norm = np.sqrt(algs.max(algs.sum(x * x, axis=1))) res = [0.0, max_norm] else: has_nan = np.isnan(x).any() if attr == 'scalars': if has_nan: res = [float(np.nanmin(x)), float(np.nanmax(x))] else: res = list(x.GetRange()) else: if has_nan: d_mag = np.sqrt((x * x).sum(axis=1)) res = [float(np.nanmin(d_mag)), float(np.nanmax(d_mag))] else: res = [0.0, x.GetMaxNorm()] return name, res
def get_range(self, attr='scalars', mode='point'): assert mode in ('point', 'cell') assert attr in ('scalars', 'vectors') dataset = self.dataset da = dataset.PointData if mode == 'point' else dataset.CellData x = self._get_attr(da, attr, mode) if x is None: return None, [0.0, 1.0] name, x = x if self._composite: # Don't bother with Nans for composite data for now. if isinstance(x, dsa.VTKNoneArray): res = [0.0, 1.0] elif attr == 'scalars': res = [algs.min(x), algs.max(x)] else: max_norm = np.sqrt(algs.max(algs.sum(x*x, axis=1))) res = [0.0, max_norm] else: has_nan = np.isnan(x).any() if attr == 'scalars': if has_nan: res = [float(np.nanmin(x)), float(np.nanmax(x))] else: res = list(x.GetRange()) else: if has_nan: d_mag = np.sqrt((x*x).sum(axis=1)) res = [float(np.nanmin(d_mag)), float(np.nanmax(d_mag))] else: res = [0.0, x.GetMaxNorm()] return name, res
def get_bounds(self): """Return the bounds of the data. """ if self._composite: c1 = algs.min(self.dataset.Points, axis=0) c2 = algs.max(self.dataset.Points, axis=0) result = np.zeros(6) result[::2] = c1 result[1::2] = c2 return result else: return self.dataset.GetBounds()
cdata = dsa.WrapDataObject(c) rtdata = cdata.PointData['RTData'] rtdata = algs.abs(rtdata) g = algs.gradient(rtdata) g2 = algs.gradient(g) res = True dummy = vtk.vtkDummyController() for axis in [None, 0]: for array in [rtdata, g, g2]: if rank == 0: array2 = array / 2 min = algs.min_per_block(array2, axis=axis) res &= numpy.all(min.Arrays[NUM_BLOCKS - 1] == numpy.min(array, axis=axis)) all_min = algs.min(min, controller=dummy) all_min_true = numpy.min([ algs.min(array, controller=dummy), algs.min(array2, controller=dummy) ]) res &= all_min == all_min_true max = algs.max_per_block(array2, axis=axis) res &= numpy.all(max.Arrays[NUM_BLOCKS - 1] == numpy.max(array, axis=axis)) all_max = algs.max(max, controller=dummy) all_max_true = numpy.max([ algs.max(array, controller=dummy), algs.max(array2, controller=dummy) ]) res &= all_max == all_max_true sum = algs.sum_per_block(array2, axis=axis)
dbgRt.SetValue(3, 19.47) dbgRt.SetValue(4, 3.350) dbgRt.SetValue(5, 0.212) dbgRt.SetValue(6, 1023.) dbg.GetPointData().AddArray(dbgRt) test_dataset(dbg) print("Success!") print("Testing homogeneous image data...") source = vtk.vtkRTAnalyticSource() source.Update() imgData = source.GetOutput() test_dataset(imgData) print("Success!") d = dsa.WrapDataObject(imgData) rtData = d.PointData['RTData'] rtMin = algs.min(rtData) rtMax = algs.max(rtData) clipScalar = 0.5 * (rtMin + rtMax) print("Testing non-homogenous unstructured grid...") clip = vtk.vtkClipDataSet() clip.SetInputData(imgData) clip.SetValue(clipScalar) clip.Update() ugrid = clip.GetOutput() test_dataset(ugrid) print("Success!")
cdata = dsa.WrapDataObject(c) rtdata = cdata.PointData['RTData'] rtdata = algs.abs(rtdata) g = algs.gradient(rtdata) g2 = algs.gradient(g) res = True dummy = vtk.vtkDummyController() for axis in [None, 0]: for array in [rtdata, g, g2]: if rank == 0: array2 = array/2 min = algs.min_per_block(array2, axis=axis) res &= numpy.all(min.Arrays[NUM_BLOCKS - 1] == numpy.min(array, axis=axis)) all_min = algs.min(min, controller=dummy) all_min_true = numpy.min([algs.min(array, controller=dummy), algs.min(array2, controller=dummy)]) res &= all_min == all_min_true max = algs.max_per_block(array2, axis=axis) res &= numpy.all(max.Arrays[NUM_BLOCKS - 1] == numpy.max(array, axis=axis)) all_max = algs.max(max, controller=dummy) all_max_true = numpy.max([algs.max(array, controller=dummy), algs.max(array2, controller=dummy)]) res &= all_max == all_max_true sum = algs.sum_per_block(array2, axis=axis) sum_true = numpy.sum(array2.Arrays[0]) * (NUM_BLOCKS-1) sum_true += numpy.sum(array.Arrays[0]) * 3 res &= numpy.sum(algs.sum(sum, controller=dummy) - algs.sum(sum_true, controller=dummy)) == 0 mean = algs.mean_per_block(array2, axis=axis) res &= numpy.sum(mean.Arrays[0] - numpy.mean(array2.Arrays[0], axis=axis)) < 1E-6 if len(array.Arrays[0].shape) == 1: stk = numpy.hstack