Esempio n. 1
0
    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
Esempio n. 2
0
 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()
Esempio n. 3
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