Ejemplo n.º 1
0
 def test_bad_file(self):
     """`GSLibReader`: check handling of bad input file"""
     filename = os.path.join(self.test_dir, 'test_bad.dat')
     header = ['A header line', 'Bad number of titles']
     for ln in self.titles:
         header.append(ln + '\n')
     header = '\n'.join(header)
     np.savetxt(filename,
                self.data,
                delimiter=' ',
                header=header,
                comments='')
     # Set up the reader
     reader = GSLibReader()
     reader.AddFileName(filename)
     # Perform the read
     reader.Update()
     self.assertTrue(reader.error_occurred())
Ejemplo n.º 2
0
 def setUp(self):
     TestBase.setUp(self)
     # Create a temporary directory
     self.test_dir = tempfile.mkdtemp()
     self.n = 100
     self.titles = ['Array 1', 'Array 2', 'Array 3']
     self.header = 'A header line'
     ##### Now generate output for testing ####
     filename = os.path.join(self.test_dir, 'test.dat')
     self.data = np.random.random((self.n, len(self.titles)))
     header = [self.header, '%d' % len(self.titles)]
     for ln in self.titles:
         header.append(ln + '\n')
     header = '\n'.join(header)
     np.savetxt(filename,
                self.data,
                delimiter=' ',
                header=header,
                comments='')
     # Set up the reader
     reader = GSLibReader()
     reader.AddFileName(filename)
     # Perform the read
     reader.Update()
     self.HEADER = reader.get_file_header()
     self.TABLE = reader.GetOutput()
Ejemplo n.º 3
0
 def test_writer(self):
     """`WriteTableToGSLib`: check data integrity across I/O"""
     writer = WriteTableToGSLib()
     filename = os.path.join(self.test_dir, 'test-writer.dat')
     writer.SetFileName(filename)
     writer.Write(self.TABLE)
     # Now read that data and compare
     reader = GSLibReader()
     read = reader.apply(filename)
     # Compare data
     truedata = self.TABLE.GetRowData()
     testdata = read.GetRowData()
     self.assertEqual(truedata.GetNumberOfArrays(),
                      testdata.GetNumberOfArrays())
     #self.assertEqual(truedata.GetNumberOfRows(), testdata.GetNumberOfRows())
     #self.assertEqual(truedata.GetNumberOfColumns(), testdata.GetNumberOfColumns())
     wtbl = dsa.WrapDataObject(self.TABLE)
     wrd = dsa.WrapDataObject(read)
     for i in range(truedata.GetNumberOfArrays()):
         self.assertIsNotNone(wtbl.RowData[i])
         self.assertIsNotNone(wrd.RowData[i])
         self.assertTrue(np.allclose(wtbl.RowData[i], wrd.RowData[i]))
Ejemplo n.º 4
0
 def print_file_header(self):
     print(GSLibReader.get_file_header(self))
     return 1
Ejemplo n.º 5
0
 def AddFileName(self, filename):
     GSLibReader.AddFileName(self, filename)
Ejemplo n.º 6
0
 def set_time_delta(self, dt):
     GSLibReader.set_time_delta(self, dt)
Ejemplo n.º 7
0
 def get_time_step_values(self):
     """This is critical for registering the timesteps"""
     return GSLibReader.get_time_step_values(self)
Ejemplo n.º 8
0
 def set_skip_rows(self, skip):
     GSLibReader.set_skip_rows(self, skip)
Ejemplo n.º 9
0
 def set_comments(self, identifier):
     GSLibReader.set_comments(self, identifier)
Ejemplo n.º 10
0
 def SetDelimiter(self, deli):
     GSLibReader.SetDelimiter(self, deli)
Ejemplo n.º 11
0
 def set_split_on_white_space(self, flag):
     GSLibReader.set_split_on_white_space(self, flag)
Ejemplo n.º 12
0
 def __init__(self):
     GSLibReader.__init__(self)
Ejemplo n.º 13
0
 def SetUseTab(self, flag):
     GSLibReader.SetUseTab(self, flag)
Ejemplo n.º 14
0
 def PrintFileHeader(self):
     print(GSLibReader.GetFileHeader(self))
     return 1
Ejemplo n.º 15
0
 def GetTimestepValues(self):
     """This is critical for registering the timesteps"""
     return GSLibReader.GetTimestepValues(self)
Ejemplo n.º 16
0
 def SetTimeDelta(self, dt):
     GSLibReader.SetTimeDelta(self, dt)
Ejemplo n.º 17
0
 def SetComments(self, identifier):
     GSLibReader.SetComments(self, identifier)
Ejemplo n.º 18
0
 def SetSkipRows(self, skip):
     GSLibReader.SetSkipRows(self, skip)
Ejemplo n.º 19
0
 def set_delimiter(self, deli):
     GSLibReader.set_delimiter(self, deli)
Ejemplo n.º 20
0
~~~~~~~~~~~~~~~~

Read any GSLib file as a table :class:`pyvist.Table`

"""
import pyvista as pv
from pyvista import examples
from PVGeo.gslib import GSLibReader
from PVGeo.grids import TableToTimeGrid

###############################################################################

# points_url = 'http://www.trainingimages.org/uploads/3/4/7/0/34703305/sundarbans.zip'
filename, _ = examples.downloads._download_file('sundarbans.SGEMS.zip')

reader = GSLibReader()
table = reader.apply(filename)

# Print the file header
print(reader.get_file_header())

###############################################################################
print(table)

###############################################################################
# From inspecting the header, we realize that this dataset os gridded, so let's
# use the :class:`PVGeo.grid.TableToTimeGrid` filter to create a
# :class:`pyvista.UniformGrid` of that dataset.

# 1200 x, 1750 y, 1 z, 1 t
grid = TableToTimeGrid(extent=(1200, 1750, 1, 1)).apply(table)