[cig-commits] [commit] baagaard/feature-output-station-names: Add station name to list of points for output. (f33c75b)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Nov 5 15:48:00 PST 2014
Repository : https://github.com/geodynamics/pylith
On branch : baagaard/feature-output-station-names
Link : https://github.com/geodynamics/pylith/compare/f33c75b19fd60eedb2a3405db76a1fee333bb1d7...5b6d812b1612809fea3bd331c4e5af98c25a536a
>---------------------------------------------------------------
commit f33c75b19fd60eedb2a3405db76a1fee333bb1d7
Author: Brad Aagaard <baagaard at usgs.gov>
Date: Tue Nov 4 17:44:13 2014 -0800
Add station name to list of points for output.
>---------------------------------------------------------------
f33c75b19fd60eedb2a3405db76a1fee333bb1d7
examples/3d/hex8/output_points.txt | 10 +++---
pylith/meshio/PointsList.py | 56 ++++++++++++++++++++++++--------
unittests/pytests/meshio/data/point.txt | 2 +-
unittests/pytests/meshio/data/points.txt | 6 ++--
4 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/examples/3d/hex8/output_points.txt b/examples/3d/hex8/output_points.txt
index 424b453..7fae03c 100644
--- a/examples/3d/hex8/output_points.txt
+++ b/examples/3d/hex8/output_points.txt
@@ -7,7 +7,9 @@
# coordsys component of the OutputSolnPoints object. The points will
# be transformed into the coordinate system of the mesh before
# interpolation.
-0.0 0.0 -500.0
-0.0 0.0 -1500.0
-0.0 0.0 -2500.0
-0.0 0.0 -3500.0
+#
+# The first column is network.station_code.
+ZZ.AAA 0.0 0.0 -500.0
+ZZ.BBB 0.0 0.0 -1500.0
+ZZ.CCC 0.0 0.0 -2500.0
+ZZ.DDD 0.0 0.0 -3500.0
diff --git a/pylith/meshio/PointsList.py b/pylith/meshio/PointsList.py
index 7d90934..5197ea9 100644
--- a/pylith/meshio/PointsList.py
+++ b/pylith/meshio/PointsList.py
@@ -57,14 +57,13 @@ class PointsList(Component):
import pyre.inventory
- filename = pyre.inventory.str("filename", default="",
- validator=validateFilename)
+ filename = pyre.inventory.str("filename", default="", validator=validateFilename)
filename.meta['tip'] = "Filename for list of points."
commentDelimiter = pyre.inventory.str("comment_delimiter", default="#")
commentDelimiter.meta['tip'] = "Delimiter for comments."
- valueDelimiter = pyre.inventory.str("value_delimiter", default="")
+ valueDelimiter = pyre.inventory.str("value_delimiter", default=None)
valueDelimiter.meta['tip'] = "Delimiter used to separate values."
@@ -83,17 +82,46 @@ class PointsList(Component):
Read points from file.
"""
import numpy
- if len(self.valueDelimiter) == 0:
- points = numpy.loadtxt(self.filename, comments=self.commentDelimiter)
- else:
- points = numpy.loadtxt(self.filename,
- comments=self.commentDelimiter,
- delimiter=self.valueDelimiter)
- ndims = len(points.shape)
- if ndims == 1:
- spaceDim = points.shape[0]
- points = points.reshape((1,spaceDim))
- return points
+
+ fin = open(self.filename, "r")
+ lines = fin.readlines()
+ fin.close()
+
+ npoints = 0
+ ndims = None
+ for line in lines:
+ if line.startswith(self.commentDelimiter):
+ continue
+
+ if not self.valueDelimiter:
+ fields = line.split()
+ else:
+ fields = line.split(self.valueDelimiter)
+ if ndims:
+ if len(fields) != 1+ndims:
+ raise IOError("Error occurred while reading line '%s' in points file '%s'.\n"
+ "Expected format: station x y [z] with %d fields. Found %d fields." % \
+ (line, self.filename, 1+ndims, len(fields)))
+ else:
+ ndims = len(fields)-1
+ npoints += 1
+
+
+ points = numpy.zeros((npoints, ndims), dtype=numpy.float64)
+ stations = numpy.zeros((npoints,), dtype='S16')
+ ipoint = 0
+ for line in lines:
+ if line.startswith(self.commentDelimiter):
+ continue
+
+ fields = line.split(self.valueDelimiter)
+
+ stations[ipoint] = fields[0].strip()
+ points[ipoint,:] = map(float, fields[1:])
+
+ ipoint += 1
+
+ return stations,points
# PRIVATE METHODS ////////////////////////////////////////////////////
diff --git a/unittests/pytests/meshio/data/point.txt b/unittests/pytests/meshio/data/point.txt
index c7881cf..a0932e1 100644
--- a/unittests/pytests/meshio/data/point.txt
+++ b/unittests/pytests/meshio/data/point.txt
@@ -1,2 +1,2 @@
# Here is a point within the volume of the hex8 mesh.
- 0.5 0.2 0.0
+ZZ.AAA 0.5 0.2 0.0
diff --git a/unittests/pytests/meshio/data/points.txt b/unittests/pytests/meshio/data/points.txt
index 9dfb59f..cbfd167 100644
--- a/unittests/pytests/meshio/data/points.txt
+++ b/unittests/pytests/meshio/data/points.txt
@@ -1,4 +1,4 @@
# Here are some points within the volume of the hex8 mesh.
- 0.5 0.2 0.0
--0.5 0.2 0.0
- 0.5 -0.2 0.0
+ZZ.A 0.5 0.2 0.0
+ZZ.B -0.5 0.2 0.0
+ZZ.C 0.5 -0.2 0.0
More information about the CIG-COMMITS
mailing list