def test_create_from_data(self): data = np.random.random_sample((50, 49, 31)) test = PFData(data) self.assertEqual(31, test.getNX()) self.assertEqual(49, test.getNY()) self.assertEqual(50, test.getNZ()) self.assertEqual(1, test.getP()) self.assertEqual(1, test.getQ()) self.assertEqual(1, test.getR()) self.assertEqual(0, test.getX()) self.assertEqual(0, test.getY()) self.assertEqual(0, test.getZ()) test.writeFile(('test_write_raw.pfb')) test_read = PFData(('test_write_raw.pfb')) test_read.loadHeader() test_read.loadData() self.assertEqual(0, test_read.getX()) self.assertEqual(0, test_read.getY()) self.assertEqual(0, test_read.getZ()) self.assertEqual(31, test_read.getNX()) self.assertEqual(49, test_read.getNY()) self.assertEqual(50, test_read.getNZ()) self.assertEqual(1, test_read.getP()) self.assertEqual(1, test_read.getQ()) self.assertEqual(1, test_read.getR()) test_data = test_read.getDataAsArray() self.assertIsNone( np.testing.assert_array_equal(data, test_data), 'Data written to array should exist in ' 'written PFB file.') del data test.close() test_read.close() os.remove(('test_write_raw.pfb'))
def test_compare(self): test1 = PFData(('press.init.pfb')) test1.loadHeader() test1.loadData() test2 = PFData(('press.init.pfb')) test2.loadHeader() test2.loadData() self.assertEqual(PFData.differenceType_none, test1.compare(test2)[0], "test1 and test2 are the same") test1.setX(test1.getX() + 1.0) self.assertEqual(PFData.differenceType_x, test1.compare(test2)[0], "The x values differ") test1.setX(test1.getX() - 1.0) arr = test1.getDataAsArray() arr[1][2][3] += 1.0 ret, zyx = test1.compare(test2) self.assertEqual(PFData.differenceType_data, ret, "The data values differ") self.assertEqual((1, 2, 3), zyx, "The differing data's coordinates are correct") arr[1][2][3] -= 1.0 test1.close() test2.close()
def test_good_filename(self): test = PFData(('press.init.pfb')) retval = test.loadHeader() self.assertEqual(0, retval, 'should load header of file that exists') self.assertEqual(41, test.getNX(), 'sample file should have 41 columns') self.assertEqual(41, test.getNY(), 'sample file should have 41 rows') self.assertEqual(50, test.getNZ(), 'sample file should have 50 z-layers') self.assertEqual(0, test.getX(), 'sample file starts at X=0') self.assertEqual(0, test.getY(), 'sample file starts at Y=0') self.assertEqual(0, test.getZ(), 'sample file starts at Z=0') self.assertEqual(16, test.getNumSubgrids(), 'sample file should have 16 subgrids') test.close()