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 set_data_name(self, data_name): SurferGridReader.set_data_name(self, data_name)