[cig-commits] r16608 - short/3D/PyLith/trunk/applications/utilities

brad at geodynamics.org brad at geodynamics.org
Sun May 2 20:54:21 PDT 2010


Author: brad
Date: 2010-05-02 20:54:21 -0700 (Sun, 02 May 2010)
New Revision: 16608

Added:
   short/3D/PyLith/trunk/applications/utilities/pylith_vtktohdf5
Log:
Started work on VTK to HDF5 utility.

Added: short/3D/PyLith/trunk/applications/utilities/pylith_vtktohdf5
===================================================================
--- short/3D/PyLith/trunk/applications/utilities/pylith_vtktohdf5	                        (rev 0)
+++ short/3D/PyLith/trunk/applications/utilities/pylith_vtktohdf5	2010-05-03 03:54:21 UTC (rev 16608)
@@ -0,0 +1,142 @@
+#!/usr/bin/env nemesis
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+# This script combines VTK files written by PyLith into a single HDF5
+# file. The filenames must be of the pattern [name]_t[number].vtk and
+# follow the usual VTK conventions for files with time slices.  Usage:
+# pylith_vtktohdf5 [--verbose] [--filename=FILE]
+
+__requires__ = "PyLith"
+
+
+# ======================================================================
+class ConvertApp(object):
+  """
+  Application for combining VTK files into a single HDF5 file.
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="pylith_vtktohdf5"):
+    """
+    Constructor.
+    """
+    self.verbose = False
+    self.filename = ""
+    return
+
+
+  def main(self, *args, **kwds):
+    """
+    Main entry point for application.
+    """
+
+    reader = VTKDataReader()
+    filenames = self._getFilenames()
+    self.h5 = ()
+
+    nsteps = len(filenames)
+    assert(nsteps > 0)
+
+    # Initial time step
+    if self.verbose:
+      print "Reading data from VTK file '%s'." % filenames[0]
+    data = reader.read(filenames[0])
+    self._writeVertices(data['vertices'])
+    self._writeCells(data['cells'])
+    self._setupGroups(nsteps, data['vertex_fields'], data['cell_fields'])
+    self._writeVertexFields(data['vertex_fields'])
+    self._writeVellFields(data['cell_fields'])
+
+    # Time steps
+    for istep in xrange(nsteps):
+      if self.verbose:
+        print "Reading data from VTK file '%s'." % filenames[0]
+      data = reader.read(filenames[istep])
+      self._writeVertexFields(data['vertex_fields'])
+      self._writeCellFields(data['cell_fields'])
+      
+    h5.close()
+   
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _getFilenames(self):
+    """
+    Get filenames with same pattern as provided filename but different time stamps.
+    """
+    filenames = []
+    return filenames
+
+
+  def _setupGroups(self, data):
+    """
+    Setup groups in HDF5 file.
+    """
+    return
+
+
+  def _writeVertices(self, data):
+    """
+    Write vertices to HDF5 file.
+    """
+    return
+
+
+  def _writeCells(self, data):
+    """
+    Write cells to HDF5 file.
+    """
+    return
+
+
+  def _writeVertexFields(self, data):
+    """
+    Add vertex fields at current time slice to HDF5 file.
+    """
+    return
+
+
+  def _writeCellFields(self, data):
+    """
+    Add cell fields at current time slice to HDF5 file.
+    """
+    return
+
+
+# ----------------------------------------------------------------------
+if __name__ == "__main__":
+
+  usage = "%prog [--verbose] [--file=FILE]"
+  from optparse import OptionParser
+  parser = OptionParser(usage=usage)
+  parser.add_option("-v", "--verbose", dest="verbose",
+                    action="store_true", default=False,
+                    help="Print verbose output.")
+  parser.add_option("-o", "--file", dest="filename",
+                    type="string", metavar="FILE",
+                    help="Read data file files matching FILE.",
+                    default="")
+  (options, args) = parser.parse_args()
+  if options.filename == "":
+    raise IOError("No input provided. Specify a file using the --file command "
+                  "line argument.")
+
+  app = ConvertApp()
+  app.verbose = options.verbose
+  app.filename = options.filename
+  app.main()
+
+
+# End of file 


Property changes on: short/3D/PyLith/trunk/applications/utilities/pylith_vtktohdf5
___________________________________________________________________
Name: svn:executable
   + *



More information about the CIG-COMMITS mailing list