def test_simple_case(self): """`VoxelizePoints`: simple case""" x = np.array([0.0, 1.0, 0.0]) y = np.array([0.0, 0.0, 1.0]) z = np.array([0.0, 0.0, 0.0]) x = np.reshape(x, (len(x), -1)) y = np.reshape(y, (len(y), -1)) z = np.reshape(z, (len(z), -1)) pts = np.concatenate((x, y, z), axis=1) vtkpoints = interface.points_to_poly_data(pts) # Use filter v = VoxelizePoints() v.SetInputDataObject(vtkpoints) v.set_safe_size(5.0) v.Update() grid = v.GetOutput() # Checkout output: self.assertEqual(grid.GetNumberOfCells(), 3, msg='Number of CELLS is incorrect') self.assertEqual(grid.GetNumberOfPoints(), 16, msg='Number of POINTS is incorrect') bounds = grid.GetBounds() self.assertEqual( bounds, (-0.5, 1.5, -0.5, 1.5, -2.5, 2.5), msg='Grid bounds are incorrect.') # Z bounds from SAFE return
def makeSimpleInput(self): x = np.array([0.0, 1.0, 0.0]) y = np.array([0.0, 0.0, 1.0]) z = np.array([0.0, 0.0, 0.0]) x = np.reshape(x, (len(x), -1)) y = np.reshape(y, (len(y), -1)) z = np.reshape(z, (len(z), -1)) self.pts = np.concatenate((x, y, z), axis=1) self.vtkpoints = interface.points_to_poly_data(self.pts)
def setUp(self): TestBase.setUp(self) # create a volumetric data set self.grid = PVGeo.model_build.CreateTensorMesh().apply() # create an unudulating surface in the grid domain # make XY random in the grid bounds # make Z ranome within a very small domain inside the grid bnds = self.grid.GetBounds() x = np.random.uniform(bnds[0], bnds[1], 5000) y = np.random.uniform(bnds[2], bnds[3], 5000) z = np.random.uniform(-200, -100, 5000) self.points = interface.points_to_poly_data(np.c_[x,y,z])
def setUp(self): TestBase.setUp(self) self.RTOL = 0.00001 # As higi as rotation precision can get x = np.array([0.0, 1.0, 0.0]) y = np.array([0.0, 0.0, 1.0]) z = np.array([0.0, 0.0, 0.0]) x = np.reshape(x, (len(x), -1)) y = np.reshape(y, (len(y), -1)) z = np.reshape(z, (len(z), -1)) self.pts = np.concatenate((x, y, z), axis=1) self.vtkpoints = interface.points_to_poly_data(self.pts) return
def test_conversion(self): """`LonLatToUTM`: CONVERSION""" self.filename = os.path.join(os.path.dirname(__file__), 'data/das-coords.csv') # read in data that has Lat/Lon and pre converted points in zone 11 data = pd.read_csv(self.filename) points = interface.points_to_poly_data( data[['longitude', 'latitude', 'altitude']]) converted = LonLatToUTM(zone=11).apply(points) converted.GetPoints() wpdi = dsa.WrapDataObject(converted) points = np.array(wpdi.Points) self.assertTrue( np.allclose(points, data[['x_utm', 'y_utm', 'altitude']])) return True
def test_mesh_grid_uniform(self): """`VoxelizePoints`: uniform mesh grid with given spacings""" # make the mesh grid dd = 5 x = y = z = np.arange(0, 100, dd, dtype=float) g = np.meshgrid(x, y, z) # Convert to XYZ points points = np.vstack(map(np.ravel, g)).T rand = np.random.random(len(points)) vtkpoints = interface.points_to_poly_data(points) vtkpoints.GetPointData().AddArray( interface.convert_array(rand, 'Random')) # Use filter v = VoxelizePoints() v.SetInputDataObject(vtkpoints) v.set_estimate_grid(False) # Cell size is explicitly set v.set_delta_x(10) v.set_delta_y(10) v.set_delta_z(10) v.Update() grid = v.GetOutput() wgrd = dsa.WrapDataObject(grid) celldata = wgrd.CellData['Random'] # Checkout output: self.assertEqual(grid.GetNumberOfCells(), 8 * 10**3, msg='Number of CELLS is incorrect') numPts = (len(x) + 2)**3 self.assertEqual(grid.GetNumberOfPoints(), numPts, msg='Number of POINTS is incorrect') self.assertTrue(np.allclose(celldata, rand)) # Now check that we can set the spacing for every cell spac = np.full((len(points)), 10.0) v.set_deltas(spac, spac, spac) v.Update() grid = v.GetOutput() wgrd = dsa.WrapDataObject(grid) celldata = wgrd.CellData['Random'] self.assertEqual(grid.GetNumberOfCells(), 8 * 10**3, msg='Number of CELLS is incorrect') self.assertEqual(grid.GetNumberOfPoints(), numPts, msg='Number of POINTS is incorrect') self.assertTrue(np.allclose(celldata, rand)) return
def RequestData(self, request, inInfo, outInfo): """Used by pipeline to get data for current timestep and populate the output data object. This assumes that ``self._get_raw_data()`` will return a dataset ready for PVGeo's ``interface.points_to_poly_data()``. """ # Get output: output = self.GetOutputData(outInfo, 0) # Get requested time index i = _helpers.get_requested_time(self, outInfo) if self.need_to_read(): self._read_up_front() # Get the data which has already been loaded data = self._get_raw_data(idx=i) # these should just be XYZ+attribute # in either a numpy array or a pandas dataframe where first three # columns are the XYZ arrays output.DeepCopy(interface.points_to_poly_data(data)) return 1 # NOTE: ALWAYS return 1 on pipeline methods
def test(self): """`ArraysToRGBA`: make sure no errors arise""" # create an input with three arrays that can be RGB r = np.random.randint(0, 255, 300) g = np.random.randint(0, 255, 300) b = np.random.randint(0, 255, 300) a = np.random.uniform(0, 1, 300) # now make it an arbirtray dataset df = pd.DataFrame(data=np.c_[r, g, b, r, g, b, a], columns=['x', 'y', 'z', 'R', 'G', 'B', 'A']) data = interface.points_to_poly_data(df) # Set up the algorithm colored = ArraysToRGBA().apply(data, 'R', 'G', 'B', 'A') # Make sure there is a new 'Colors' Array arr = colored.GetPointData().GetArray('Colors') self.assertTrue(isinstance(arr, vtk.vtkUnsignedCharArray)) return True
def setUp(self): TestBase.setUp(self) # create a volumetric data set self.grid = PVGeo.model_build.CreateTensorMesh().apply() # create a spline throught the data set def path1(y): """Equation: x = a(y-h)^2 + k""" a = -0.0001 x = a * y**2 + 1000 idxs = np.argwhere(x > 0) return x[idxs][:, 0], y[idxs][:, 0] x, y = path1(np.arange(-500.0, 1500.0, 25.0)) zo = np.linspace(9.0, 11.0, num=len(y)) coords = np.vstack((x, y, zo)).T self.points = interface.points_to_poly_data(coords)
def test_simple_run(self): """`ExtractTopography`: Test extraction on simple data""" # Produce some input data data = vtk.vtkImageData() data.SetOrigin(0.0, 0.0, 0.0) data.SetSpacing(5.0, 5.0, 5.0) data.SetDimensions(20, 20, 20) x = y = np.linspace(0, 100, num=50, dtype=float) g = np.meshgrid(x, y) # Convert to XYZ points points = np.vstack(map(np.ravel, g)).T z = np.reshape(np.full(len(points), 55.0), (len(points), -1)) #z = np.reshape(np.random.uniform(low=55.0, high=65.0, size=(len(points),)), (len(points), -1)) points = np.concatenate((points, z), axis=1) topo = interface.points_to_poly_data(points) # # apply filter f = ExtractTopography() grd = f.apply(data, topo) # Test the output self.assertIsNotNone(grd) self.assertEqual(grd.GetDimensions(), data.GetDimensions()) self.assertEqual(grd.GetSpacing(), data.GetSpacing()) self.assertEqual(grd.GetOrigin(), data.GetOrigin()) # Now check the active topo cell data? # TODO: implement active = dsa.WrapDataObject(grd).CellData['Extracted'] for i in range(grd.GetNumberOfCells()): cell = grd.GetCell(i) bounds = cell.GetBounds() z = bounds[5]#(bounds[4]+bounds[5])/2.0 if z <= 55.0: self.assertTrue(active[i]) elif z > 55.0: self.assertFalse(active[i]) else: self.fail(msg='Non-testable cell encountered') return
def test_simple_rotated_case(self): """`VoxelizePoints`: simple rotated case""" pts = ROTATED_POINTS vtkpoints = interface.points_to_poly_data(ROTATED_POINTS) # Use filter v = VoxelizePoints() v.SetInputDataObject(vtkpoints) v.set_safe_size(5.0) v.Update() grid = v.GetOutput() # Checkout output: #- Assumes this same data's rotation was checked by `TestRotationTool` self.assertEqual(grid.GetNumberOfCells(), len(pts), msg='Number of CELLS is incorrect') numPts = (len(pts) * 8) - ( (len(pts) - 1) * 4) # Works because points make a line self.assertEqual(grid.GetNumberOfPoints(), numPts, msg='Number of POINTS is incorrect') return
def makeComplicatedInput(self, shuffle=True): def path1(y): # Equation: x = a(y-h)^2 + k k = 110.0 h = 0.0 a = -k / 160.0**2 x = a * (y - h)**2 + k idxs = np.argwhere(x > 0) return x[idxs][:, 0], y[idxs][:, 0] y = np.linspace(0.0, 200.0, num=100) x, y = path1(y) zo = np.linspace(9.0, 11.0, num=len(y)) coords = np.zeros((len(y), 3)) coords[:, 0] = x coords[:, 1] = y coords[:, 2] = zo np.random.shuffle(coords) self.pts = coords self.vtkpoints = interface.points_to_poly_data(self.pts)