Ejemplo n.º 1
0
 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'))
Ejemplo n.º 2
0
 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()