def test_data_fidelity(self): """`MadagascarReader`: Check data fidelity""" # Create a temporary directory self.test_dir = tempfile.mkdtemp() self.n = 100 # Make data and write out dtype = np.dtype('f') self.data = np.array(np.random.random(self.n), dtype=dtype) filename = os.path.join(self.test_dir, 'test.rsf') # Write ascii header lines = ['hello\n'] * 10 with open(filename, 'w') as f: f.writelines(lines) # Write data with open(filename, 'ab') as f: f.write(b'\014\014\004') # The control sequence self.data.tofile(f) # Set up reader reader = MadagascarReader() reader.AddFileName(filename) reader.set_data_type('f') reader.set_data_name('Test Data') self.assertEqual(reader.get_data_name(), 'Test Data') # Perfrom Read reader.Update() table = reader.GetOutput() arr = nps.vtk_to_numpy(table.GetColumn(0)) self.assertTrue(np.allclose(self.data, arr)) #, rtol=0.0001)) self.assertEqual(table.GetColumnName(0), 'Test Data') return
def AddFileName(self, fname): MadagascarReader.AddFileName(self, fname)