[cig-commits] r15118 - in cs/spatialdata-0.1/trunk: modulesrc/spatialdb spatialdata spatialdata/spatialdb tests/libtests/spatialdb tests/pytests/spatialdb tests/pytests/spatialdb/data
brad at geodynamics.org
brad at geodynamics.org
Thu Jun 4 09:20:14 PDT 2009
Author: brad
Date: 2009-06-04 09:20:13 -0700 (Thu, 04 Jun 2009)
New Revision: 15118
Added:
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistory.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistoryIO.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistory.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistoryIO.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/test_okay.timedb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/timehistory.timedb
Modified:
cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i
cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py
cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestTimeHistory.cc
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
Log:
Added Python stuff for TimeHistory with associated unit tests.
Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i 2009-06-04 12:54:14 UTC (rev 15117)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i 2009-06-04 16:20:13 UTC (rev 15118)
@@ -75,8 +75,10 @@
*
* @returns 0 on success, 1 on failure (i.e., could not interpolate)
*/
+ %apply double* OUTPUT { double* value };
int query(double* value,
const double t);
+ %clear (double* value);
}; // class TimeHistory
Modified: cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2009-06-04 12:54:14 UTC (rev 15117)
+++ cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2009-06-04 16:20:13 UTC (rev 15118)
@@ -27,6 +27,8 @@
spatialdb/SimpleIOAscii.py \
spatialdb/SimpleIO.py \
spatialdb/SpatialDBObj.py \
+ spatialdb/TimeHistory.py \
+ spatialdb/TimeHistoryIO.py \
spatialdb/UniformDB.py \
spatialdb/__init__.py \
spatialdb/generator/Shaper.py \
Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistory.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistory.py (rev 0)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistory.py 2009-06-04 16:20:13 UTC (rev 15118)
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/TimeHistory.py
+##
+## @brief Python object for time history dependence with spatial databases.
+##
+## Factory: temporal_database
+
+from pyre.components.Component import Component
+from spatialdb import TimeHistory as ModuleTimeHistory
+
+# TimeHistory class
+class TimeHistory(Component, ModuleTimeHistory):
+ """
+ Python object for time history dependence with spatial databases.
+
+ \b Properties
+ @li \b label Label for time history.
+ @li \b filename Name of file for time history.
+
+ \b Facilities
+ @li None
+
+ Factory: temporal_database
+ """
+
+ import pyre.inventory
+
+ label = pyre.inventory.str("label", default="temporal database")
+ label.meta['tip'] = "Label for time history."
+
+ filename = pyre.inventory.str("filename", default="timehistory.timedb")
+ filename.meta['tip'] = "Name of file for time history."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="timehistory"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="temporal_database")
+ self._createModuleObj()
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set attributes based on inventory.
+ """
+ Component._configure(self)
+ ModuleTimeHistory.label(self, self.inventory.label)
+ ModuleTimeHistory.filename(self, self.inventory.filename)
+ return
+
+
+ def _createModuleObj(self):
+ """
+ Create Python module object.
+ """
+ ModuleTimeHistory.__init__(self)
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def temporal_database():
+ """
+ Factory associated with TimeHistory.
+ """
+ return TimeHistory()
+
+
+# End of file
Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistoryIO.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistoryIO.py (rev 0)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/TimeHistoryIO.py 2009-06-04 16:20:13 UTC (rev 15118)
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/TimeHistoryIO.py
+##
+## @brief Python function to write time history file.
+
+def write(time, amplitude, units, filename):
+ """
+ Write time history file.
+ """
+ import spatialdb
+ spatialdb.TimeHistoryIO.write(time, amplitude, units, filename)
+ return
+
+
+# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py 2009-06-04 12:54:14 UTC (rev 15117)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py 2009-06-04 16:20:13 UTC (rev 15118)
@@ -19,6 +19,8 @@
'SimpleIOAscii',
'SimpleIO',
'SpatialDBObj',
+ 'TimeHistory',
+ 'TimeHistoryIO',
'UniformDB',
'generator']
Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestTimeHistory.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestTimeHistory.cc 2009-06-04 12:54:14 UTC (rev 15117)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestTimeHistory.cc 2009-06-04 16:20:13 UTC (rev 15118)
@@ -94,7 +94,7 @@
{ 0.5, 0.0, 0.6, 2.0, 5.0, 20.0, 8.0 };
const double amplitudeE[nqueries] =
{ 1.0, 0.0, 1.2, 4.0, 2.5, 0.0, 1.0 };
- const int errQ[nqueries] =
+ const int errE[nqueries] =
{ 0, 0, 0, 0, 0, 1, 0 };
TimeHistory th;
@@ -106,8 +106,8 @@
double amplitude = 0.0;
for (int i=0; i < nqueries; ++i) {
int err = th.query(&litude, timeQ[i]);
- CPPUNIT_ASSERT_EQUAL(errQ[i], err);
- if (0 == errQ[i])
+ CPPUNIT_ASSERT_EQUAL(errE[i], err);
+ if (0 == errE[i])
CPPUNIT_ASSERT_DOUBLES_EQUAL(amplitudeE[i], amplitude, tolerance);
} // for
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistory.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistory.py (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistory.py 2009-06-04 16:20:13 UTC (rev 15118)
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+
+class TestTimeHistory(unittest.TestCase):
+
+ def test_timehistory(self):
+ timeQ = numpy.array( [0.5, 0.0, 0.6, 2.0, 5.0, 20.0, 8.0 ], dtype=numpy.float64)
+ amplitudeE = numpy.array( [1.0, 0.0, 1.2, 4.0, 2.5, 0.0, 1.0 ],
+ dtype=numpy.float64)
+ errE = numpy.array( [ 0, 0, 0, 0, 0, 1, 0 ], dtype=numpy.float64)
+
+
+ from spatialdata.spatialdb.TimeHistory import TimeHistory
+ th = TimeHistory()
+ th.inventory.label = "test"
+ th.inventory.filename = "data/timehistory.timedb"
+ th._configure()
+
+ th.open()
+ nlocs = timeQ.shape[0]
+ amplitude = numpy.zeros( (nlocs,), dtype=numpy.float64)
+ err = numpy.zeros( (nlocs,), dtype=numpy.int32)
+
+ for i in xrange(nlocs):
+ (e, amplitude[i]) = th.query(timeQ[i])
+ err[i] = e
+ th.close()
+
+ self.assertEqual(len(errE), len(err))
+ for vE, v in zip(errE, err):
+ self.assertEqual(vE, v)
+
+ self.assertEqual(len(amplitudeE.shape), len(amplitude.shape))
+ for dE, d in zip(amplitudeE.shape, amplitude.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(amplitudeE, -1), numpy.reshape(amplitude, -1)):
+ self.assertAlmostEqual(vE, v, 6)
+
+ return
+
+
+# End of file
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistoryIO.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistoryIO.py (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestTimeHistoryIO.py 2009-06-04 16:20:13 UTC (rev 15118)
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+
+class TestTimeHistoryIO(unittest.TestCase):
+
+ def test_write(self):
+ """
+ Test write().
+ """
+ filename = "data/test.timedb"
+ time = numpy.array( [0.0, 2.0, 6.0, 7.0, 10.0], dtype=numpy.float64)
+ amplitude = numpy.array( [0.0, 0.2, 0.1, -0.1, 2.0], dtype=numpy.float64)
+ units = "year"
+
+ # Write database
+ from spatialdata.spatialdb.TimeHistoryIO import write
+ write(time, amplitude, units, filename)
+
+ # Test write
+ filenameE = "data/test_okay.timedb"
+
+ fin = open(filenameE, "r")
+ linesE = fin.readlines()
+ fin.close()
+
+ fin = open(filename, "r")
+ lines = fin.readlines()
+ fin.close()
+
+ self.assertEqual(len(linesE), len(lines))
+ iline = 0
+ for (lineE, line) in zip(linesE, lines):
+ if lineE != line:
+ print "Error found in line %d in file '%s' is incorrect." % (iline, filename)
+ self.failIf(True)
+ iline += 1
+
+ return
+
+
+# End of file
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am 2009-06-04 12:54:14 UTC (rev 15117)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am 2009-06-04 16:20:13 UTC (rev 15118)
@@ -12,6 +12,8 @@
data_DATA = \
spatialdb.dat \
+ test_okay.timedb \
+ timehistory.timedb \
gen1Din2D_one_bg.spatialdb \
gen1Din2D_one_add.spatialdb \
gen1Din2D_one_multiply.spatialdb \
@@ -21,6 +23,7 @@
data_CLEAN = \
test.spatialdb \
+ test.timedb \
gen1Din2D.spatialdb
noinst_HEADERS = \
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/test_okay.timedb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/test_okay.timedb (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/test_okay.timedb 2009-06-04 16:20:13 UTC (rev 15118)
@@ -0,0 +1,10 @@
+#TIME HISTORY ascii
+TimeHistory {
+ num-points = 5
+ time-units = year
+}
+ 0.000000e+00 0.000000e+00
+ 2.000000e+00 2.000000e-01
+ 6.000000e+00 1.000000e-01
+ 7.000000e+00 -1.000000e-01
+ 1.000000e+01 2.000000e+00
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/timehistory.timedb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/timehistory.timedb (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/timehistory.timedb 2009-06-04 16:20:13 UTC (rev 15118)
@@ -0,0 +1,11 @@
+#TIME HISTORY ascii
+TimeHistory {
+ num-points = 6
+ time-units = second
+}
+ 0.000000e+00 0.000000e+00
+ 2.000000e-01 4.000000e-01
+ 8.000000e-01 1.600000e+00
+ 1.000000e+00 2.000000e+00
+ 2.000000e+00 4.000000e+00
+ 1.000000e+01 0.000000e+00
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2009-06-04 12:54:14 UTC (rev 15117)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2009-06-04 16:20:13 UTC (rev 15118)
@@ -31,6 +31,12 @@
from TestGravityField import TestGravityField
suite.addTest(unittest.makeSuite(TestGravityField))
+ from TestTimeHistoryIO import TestTimeHistoryIO
+ suite.addTest(unittest.makeSuite(TestTimeHistoryIO))
+
+ from TestTimeHistory import TestTimeHistory
+ suite.addTest(unittest.makeSuite(TestTimeHistory))
+
from TestGenSimpleDBApp import TestGenSimpleDBApp
suite.addTest(unittest.makeSuite(TestGenSimpleDBApp))
More information about the CIG-COMMITS
mailing list