def test_chile_example(self): """`TensorMeshReader`: Test Chile mesh example""" meshfile = os.path.join(os.path.dirname(__file__), 'data/Craig-Chile/craig_chile.msh') modfile = os.path.join(os.path.dirname(__file__), 'data/Craig-Chile/Lpout.mod') reader = TensorMeshReader() reader.set_mesh_filename(meshfile) # Get and test output: reader.Update() # Read only mesh upfront reader.add_model_file_name(modfile) reader.set_data_name('Lpout') mesh = reader.apply() self.assertTrue(mesh.n_cells > 0) self.assertTrue(mesh.n_arrays > 0)
def test_writer(self): """`WriteRectilinearGridToUBC`: Test data integretiy across I/O""" # Write known data back out using the writer: writer = WriteRectilinearGridToUBC() filename = os.path.join(self.test_dir, 'test-writer.msh') writer.SetFileName(filename) writer.Write(self.GRID) # Now read in the data again and compare! reader = TensorMeshReader() reader.set_mesh_filename(filename) modname = os.path.join(self.test_dir, '%s.mod' % self.data_name) reader.add_model_file_name(modname) reader.set_data_name(self.data_name) reader.Update() test = reader.GetOutput() # Compare the data self._check_shape(test) self._check_spatial_reference(test) self._check_data(test, self.data) self.assertEqual(test.GetCellData().GetArrayName(0), self.data_name) return
def get_time_step_values(self): """This is critical for registering the timesteps""" return TensorMeshReader.get_time_step_values(self)
def set_time_delta(self, dt): TensorMeshReader.set_time_delta(self, dt)
def add_model_file_name(self, filename): """Use to set the file names for the reader. Handles singlt string or list of strings.""" TensorMeshReader.add_model_file_name(self, filename)
def set_mesh_filename(self, filename): TensorMeshReader.set_mesh_filename(self, filename)
def __init__(self): TensorMeshReader.__init__(self)
def set_data_name(self, name): TensorMeshReader.set_data_name(self, name)
def set_use_filename(self, flag): TensorMeshReader.set_use_filename(self, flag)
def setUp(self): TestBase.setUp(self) # Create a temporary directory self.test_dir = tempfile.mkdtemp() self.origin = (-350, -400, 0) self.xCells = '200 100 50 20*50.0 50 100 200' self.yCells = '200 100 50 21*50.0 50 100 200' self.zCells = '20*25.0 50 100 200' self.shape = (26, 27, 23) self.n = self.shape[0]*self.shape[1]*self.shape[2] self.extent = (0, self.shape[0], 0, self.shape[1], 0, self.shape[2]) self.data_name = 'foo' ##### Now generate output for testing #### # Produce data and write out files: self.meshname = self._write_mesh() self.modname, self.data = self._write_model() self.modname_multi, self.data_multi = self._write_model_multi() # Set up the reader: reader = TensorMeshReader() reader.set_mesh_filename(self.meshname) # Get and test output: reader.Update() # Read only mesh upfront reader.add_model_file_name(self.modname) reader.set_data_name(self.data_name) reader.Update() # Read models upfront self.GRID = reader.GetOutput() #### Now read mesh with multi component data # Set up the reader: reader = TensorMeshReader() reader.set_mesh_filename(self.meshname) # Get and test output: reader.Update() # Read only mesh upfront reader.add_model_file_name(self.modname_multi) reader.set_data_name(self.data_name) reader.Update() # Read models upfront self.GRID_MULTI = reader.GetOutput()
def setUp(self): TestBase.setUp(self) # Create a temporary directory self.test_dir = tempfile.mkdtemp() self.mesh = """9 -300.0 -180.0 1 -130.0 1 -110.0 1 -100.0 1 100.0 40 110.0 1 130.0 1 180.0 1 300.0 1 14 -10.0 10.0 5 22.0 4 42.0 5 57.0 3 63.0 1 71.0 1 81.0 1 95.0 1 115.0 1 140.0 1 170.0 1 205.0 1 245.0 1 300.0 1 """ self.origin = (-300, 0, 10) self.nx = 48 self.nz = 27 self.shape = (self.nx, 1, self.nz) self.extent = (0, self.shape[0], 0, self.shape[1], 0, self.shape[2]) self.data_name = 'foo' ##### Now generate output for testing #### # Produce data and write out files: meshname = self._write_mesh() modname, self.data = self._write_model() # Set up the reader: reader = TensorMeshReader() reader.set_mesh_filename(meshname) # Get and test output: reader.Update() # Test the read up front for the mesh reader.add_model_file_name(modname) reader.set_data_name(self.data_name) reader.Update() # Now read the models upfront self.GRID = reader.GetOutput() return