def test_read(self): size = (2, 4) loader = NPYReader(self.fn, communicator=MPI.COMM_SELF) topo = loader.topography(physical_sizes=size) np.testing.assert_array_almost_equal(topo.heights(), self.data) # self.assertEqual(topo.info, loader.info) self.assertEqual(topo.physical_sizes, size)
def test_save_and_load_np(comm_self, file_format_examples): # sometimes the surface isn't transposed the same way when topography = open_topography(os.path.join(file_format_examples, 'di4.di'), format="di").topography() with tempfile.TemporaryDirectory() as d: npyfile = os.path.join(d, 'test_save_and_load_np.npy') np.save(npyfile, topography.heights()) loaded_topography = NPYReader( npyfile, communicator=comm_self).topography(physical_sizes=(1., 1.)) np.testing.assert_allclose(loaded_topography.heights(), topography.heights())
def test_load_binary(comm_self, file_format_examples): with open(os.path.join(file_format_examples, 'example-2d.npy'), mode="rb") as f: loaded_topography = NPYReader(f, communicator=comm_self).topography( # nb_subdomain_grid_pts=topography.nb_grid_pts, # subdomain_locations=(0,0), physical_sizes=(1., 1.)) loaded_topography
def test_save_and_load(comm_self, file_format_examples): # sometimes the surface isn't transposed the same way when topography = open_topography( os.path.join(file_format_examples, 'di4.di'), format="di").topography() npyfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_save_and_load.npy") save_npy(npyfile, topography) loaded_topography = NPYReader(npyfile, communicator=comm_self).topography( # nb_subdomain_grid_pts=topography.nb_grid_pts, # subdomain_locations=(0,0), physical_sizes=(1., 1.)) np.testing.assert_allclose(loaded_topography.heights(), topography.heights()) os.remove(npyfile)