[cig-commits] r7519 - in cs/cigma/branches/cigma-0.9: contrib sandbox/python/cigma

luis at geodynamics.org luis at geodynamics.org
Tue Jun 26 10:16:56 PDT 2007


Author: luis
Date: 2007-06-26 10:16:56 -0700 (Tue, 26 Jun 2007)
New Revision: 7519

Modified:
   cs/cigma/branches/cigma-0.9/contrib/bmssnog_hex8.py
   cs/cigma/branches/cigma-0.9/contrib/bmssnog_tet4.py
   cs/cigma/branches/cigma-0.9/sandbox/python/cigma/utils.py
Log:
darcs patches:
  * Updated bmssnog_tet4.py to use cigma.utils.readfrom
  * Absolute path to the bmssnog_1000m_pylith_linhex benchmark data
  * Fixed erroneous factor when importing mesh coordinates into bmssnog_hex8.h5
  * Updated docstring for cigma.utils functions



Modified: cs/cigma/branches/cigma-0.9/contrib/bmssnog_hex8.py
===================================================================
--- cs/cigma/branches/cigma-0.9/contrib/bmssnog_hex8.py	2007-06-26 17:15:54 UTC (rev 7518)
+++ cs/cigma/branches/cigma-0.9/contrib/bmssnog_hex8.py	2007-06-26 17:16:56 UTC (rev 7519)
@@ -11,15 +11,16 @@
     from cigma.utils import readfrom
 
     filename = 'bmssnog_hex8.h5'
-    coordinates_file = 'bmssnog_1000m_1.0.coord'
-    connectivity_file = 'bmssnog_1000m_1.0.connect'
+    topdir = '/home/luis/benchmark/bmssnog/1000m-pylith-linhex/'
+    coordinates_file = topdir + 'bmssnog_1000m_1.0.coord'
+    connectivity_file = topdir + 'bmssnog_1000m_1.0.connect'
     (nno, nel) = (15625, 13824)
 
     coordinates = numpy.zeros((nno,3), numpy.float32)
     connectivity = numpy.zeros((nel,8), numpy.int32)
 
     readfrom(coordinates_file, coordinates,
-             skip=6, factor=1.0, dtype=float, range=slice(1,4))
+             skip=6, factor=1000.0, dtype=float, range=slice(1,4))
 
     readfrom(connectivity_file, connectivity,
              skip=3, offset=1, dtype=int, range=slice(4,12))

Modified: cs/cigma/branches/cigma-0.9/contrib/bmssnog_tet4.py
===================================================================
--- cs/cigma/branches/cigma-0.9/contrib/bmssnog_tet4.py	2007-06-26 17:15:54 UTC (rev 7518)
+++ cs/cigma/branches/cigma-0.9/contrib/bmssnog_tet4.py	2007-06-26 17:16:56 UTC (rev 7519)
@@ -4,40 +4,12 @@
 # http://geodynamics.org/cig/workinggroups/short/workarea/benchmarks/benchmark-strikeslip/pylith-0.8-input
 #
 
-import numpy
-import tables
-
-def readfromfile(fp, x, **kw):
-    (n,d) = x.shape
-    skip = kw.get('skip', 0)
-    factor = kw.get('factor', 1.0)
-    range = kw.get('range', slice(1,4))
-    dtype = kw.get('dtype', float)
-    offset = kw.get('offset', 1)
-    # skip the specified number of lines
-    for i in xrange(skip):
-        fp.readline()
-    # read n lines into array
-    for i in xrange(n):
-        line = fp.readline()
-        cols = line.split()
-        k = int(cols[0]) - offset
-        x[k] = map(dtype, cols[range])
-    # finally, apply the conversion factor
-    x *= factor
-    return
-
-def readfrom(filename, x, **kw):
-    print "Reading file", filename
-    fp = open(filename, 'r')
-    readfromfile(fp, x, **kw)
-    fp.close()
-    return
-
-###############################################################################
-
 if __name__ == '__main__':
 
+    import numpy
+    import tables
+    from cigma.utils import readfrom
+
     filename = 'bmssnog_tet4.h5'
     topdir = 'bmssnog_tet4_%s/'
     coordinates_file = topdir + 'tet4_%s.coord'
@@ -55,10 +27,9 @@
         coordinates = numpy.zeros((nno,3), numpy.float32)
         connectivity = numpy.zeros((nel,4), numpy.int32)
         readfrom(coordinates_file % (res,res), coordinates,
-                 skip=1, factor=1000.0)
+                 skip=1, factor=1000.0, dtype=float, range=slice(1,4))
         readfrom(connectivity_file % (res,res), connectivity,
-                 skip=0, range=slice(4,8), dtype=int)
-        connectivity -= 1
+                 skip=0, offset=1, dtype=int, range=slice(4,8))
         resgroup = h5.createGroup('/', 'mesh_'+res)
         h5.createArray(resgroup, 'coordinates', coordinates)
         h5.createArray(resgroup, 'connectivity', connectivity)

Modified: cs/cigma/branches/cigma-0.9/sandbox/python/cigma/utils.py
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/python/cigma/utils.py	2007-06-26 17:15:54 UTC (rev 7518)
+++ cs/cigma/branches/cigma-0.9/sandbox/python/cigma/utils.py	2007-06-26 17:16:56 UTC (rev 7519)
@@ -4,15 +4,17 @@
     Given a file object to an ascii file with data in a column-based
     format. Note that x is assumed to be a numpy array with rank 2.
     As many rows will be read from the file as can fit along the extent
-    of the first dimension of x.
+    of the first dimension of x.  Additionally, the first column is assumed
+    to be an integer.
 
     The following keyword arguments may be specified
 
-      skip - skip this many lines at beginning
+      skip   - skip this many lines at beginning
       factor - conversion factor to apply to each value
-      range - slice representing range of columns to copy into array row
-      dtype - datatype factory for the column data (float or int)
+      range  - slice representing range of columns to copy into array row
+      dtype  - datatype factory for the column data (float or int)
       offset - whether to apply an index offset (0 or 1)
+
     """
     (n,d) = x.shape
     skip = kw.get('skip', 0)



More information about the cig-commits mailing list