""" Read Surfer Grid File ~~~~~~~~~~~~~~~~~~~~~ Read an Surfer ASCII grid file """ import pyvista from PVGeo.grids import SurferGridReader from pyvista import examples ############################################################################### # Download a sample Surfer grid file fname = 'surfer-grid.grd' url = 'https://github.com/OpenGeoVis/PVGeo/raw/master/tests/data/{}'.format( fname) filename, _ = examples.downloads._retrieve_file(url, fname) dem = SurferGridReader().apply(filename) ############################################################################### # Apply a filter to the DEM to have realistic topography warped = dem.warp_by_scalar(scale_factor=300.) warped.plot(cmap='terrain')
def test(self): """`SurferGridReader` and `WriteImageDataToSurfer`: Test reader and writer for Surfer format""" reader = SurferGridReader() reader.AddFileName(self.filename) reader.set_data_name('foo') reader.Update() img = reader.GetOutput() self.assertIsNotNone(img) # Check shapes of the surfer grid nx, ny, nz = img.GetDimensions() self.assertEqual(nx, 222) self.assertEqual(ny, 182) self.assertEqual(nz, 1) # Now test writer writer = WriteImageDataToSurfer() filename = os.path.join(self.test_dir, 'test-writer.grd') writer.SetFileName(filename) writer.Write(img, 'foo') # Read again and compare reader = SurferGridReader() reader.AddFileName(filename) reader.set_data_name('foo2') reader.Update() read = reader.GetOutput() self.assertIsNotNone(read) nx, ny, nz = read.GetDimensions() self.assertEqual(nx, 222) self.assertEqual(ny, 182) self.assertEqual(nz, 1) self.assertEqual(img.GetBounds(), read.GetBounds()) # Check the data arrays imgArr = dsa.WrapDataObject(img).PointData['foo'] readArr = dsa.WrapDataObject(read).PointData['foo2'] self.assertTrue(np.allclose(imgArr, readArr)) return
def get_time_step_values(self): """This is critical for registering the timesteps""" return SurferGridReader.get_time_step_values(self)
def set_time_delta(self, dt): SurferGridReader.set_time_delta(self, dt)
def set_data_name(self, data_name): SurferGridReader.set_data_name(self, data_name)
def AddFileName(self, filename): SurferGridReader.AddFileName(self, filename)
def __init__(self): SurferGridReader.__init__(self)