[cig-commits] r8307 - in cs/spatialdata-0.1/trunk: modulesrc/spatialdb spatialdata spatialdata/spatialdb tests/pytests/spatialdb

brad at geodynamics.org brad at geodynamics.org
Mon Nov 19 19:41:54 PST 2007


Author: brad
Date: 2007-11-19 19:41:53 -0800 (Mon, 19 Nov 2007)
New Revision: 8307

Added:
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SCECCVMH.py
   cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py
   cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/test_sceccvmh.py
Modified:
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
   cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py
   cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
Log:
Added Python bindings and Python implementation for SCECCVMH. Added Python unit test. Need to setup setting data dir in Python unit test from configure.

Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src	2007-11-20 03:41:53 UTC (rev 8307)
@@ -18,6 +18,7 @@
 #include "spatialdata/spatialdb/SimpleDBTypes.hh"
 #include "spatialdata/spatialdb/GravityField.hh"
 #include "spatialdata/spatialdb/UniformDB.hh"
+#include "spatialdata/spatialdb/SCECCVMH.hh"
 
 #include "spatialdata/geocoords/CoordSys.hh"
 
@@ -586,4 +587,36 @@
     return
 
 
+# ----------------------------------------------------------------------
+cdef class SCECCVMH(SpatialDB):
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    # create shim for constructor
+    #embed{ void* SCECCVMH_constructor()
+      return (void*)(new spatialdata::spatialdb::SCECCVMH);
+    #}embed
+
+    SpatialDB.__init__(self)
+    self.thisptr = SCECCVMH_constructor()
+    self.handle = self._createHandle()
+    return
+
+
+  def dataDir(self, dir):
+    """
+    Set the data directory for SCEC CVM-H data files..
+    """
+    # create shim for method 'dataDir'
+    #embed{ void SCECCVMH_dataDir(void* pObj, char* dir)
+    assert(0 != pObj);
+    ((spatialdata::spatialdb::SCECCVMH*) pObj)->dataDir(dir);
+    #}embed
+
+    SCECCVMH_dataDir(self.thisptr, dir)
+    return
+
+
 # End of file 

Modified: cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/Makefile.am	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/spatialdata/Makefile.am	2007-11-20 03:41:53 UTC (rev 8307)
@@ -21,6 +21,7 @@
 	geocoords/Projector.py \
 	geocoords/__init__.py \
 	spatialdb/GravityField.py \
+	spatialdb/SCECCVMH.py \
 	spatialdb/SimpleDB.py \
 	spatialdb/SimpleIOAscii.py \
 	spatialdb/SimpleIO.py \

Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SCECCVMH.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SCECCVMH.py	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SCECCVMH.py	2007-11-20 03:41:53 UTC (rev 8307)
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/SCECCVMH.py
+##
+## @brief Python manager for spatial database interface to the SCEC
+## CVM-H.
+##
+## Factory: spatial_database
+
+from SpatialDB import SpatialDB
+
+# SCECCVMH class
+class SCECCVMH(SpatialDB):
+  """
+  Python manager for spatial database to the SCEC CVM-H.
+
+  Factory: spatial_database
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(SpatialDB.Inventory):
+    """
+    Python object for managing SCECCVMH facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing SCECCVMH facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b dataDir Directory containing SCEC CVM-H data files.
+    ##
+    ## \b Facilities
+    ## @li none
+
+    import pyre.inventory
+
+    dataDir = pyre.inventory.list("dataDir", default=".")
+    dataDir.meta['tip'] = "Directory containing SCEC CVM-H data files."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="sceccvmh"):
+    """
+    Constructor.
+    """
+    SpatialDB.__init__(self, name)
+    import spatialdb as bindings
+    self.cppHandle = bindings.SCECCVMH()
+    return
+
+
+  def initialize(self):
+    """
+    Initialize database.
+    """
+    SpatialDB.initialize(self)
+    self.cppHandle.dataDir(self.dataDir)
+    return
+  
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based on inventory.
+    """
+    SpatialDB._configure(self)
+    self.dataDir = self.inventory.dataDir
+    return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def spatial_database():
+  """
+  Factory associated with SCECCVMH.
+  """
+  return SCECCVMH()
+
+
+# End of file 

Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py	2007-11-20 03:41:53 UTC (rev 8307)
@@ -14,7 +14,8 @@
 ##
 ## @brief Python spatialdata spatialdb module initialization.
 
-__all__ = ['SimpleDB',
+__all__ = ['SCECCVMH',
+           'SimpleDB',
            'SimpleIOAscii',
            'SimpleIO',
            'SpatialDB',

Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am	2007-11-20 03:41:53 UTC (rev 8307)
@@ -14,12 +14,19 @@
 
 TESTS = testspatial.py
 
+check_SCRIPTS = testspatial.py
+
+if ENABLE_SCEC_CVM_H
+  TESTS += test_sceccvmh.py
+  check_SCRIPTS += test_sceccvmh.py
+endif
+
 noinst_PYTHON = \
 	TestGenSimpleDBApp.py \
+	TestSCECCVMH.py \
 	TestSimpleIOAscii.py \
 	TestSpatialDB.py \
-	TestUniformDB.py \
-	testspatial.py
+	TestUniformDB.py
 
 
 data_DATA = \

Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py	2007-11-20 03:41:53 UTC (rev 8307)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+
+class TestSCECCVMH(unittest.TestCase):
+
+  def setUp(self):
+    from spatialdata.spatialdb.SCECCVMH import SCECCVMH
+    db = SCECCVMH()
+    db._configure()
+    db.dataDir = "/Users/brad/data/sceccvm-h/vx52/bin"
+    db.initialize()
+    self._db = db
+    return
+
+
+  def test_query(self):
+    locs = numpy.array( [[-118.520000,  34.120000,  -1400.00],
+                         [-116.400000,  32.340000,  -1000.00]],
+                        numpy.float64)
+    from spatialdata.geocoords.CSGeo import CSGeo
+    cs = CSGeo()
+    cs._configure()
+    cs.datumHoriz = "NAD27"
+    cs.datumVert = "mean sea level"
+    cs.ellipsoid = "clrk66"
+    cs.initialize()
+    queryVals = ["topo-elev", "moho-depth", "density"]
+    dataE = numpy.array([[489.975189, -31178.105469,   2660.851074],
+                         [801.209961, -34526.414062,   3022.192708]],
+                        numpy.float64)
+    errE = numpy.array( [0]*2, numpy.int32)
+    
+    self._db.open()
+    self._db.queryVals(queryVals)
+    (data, err) = self._db.query(locs, cs, 3)
+    data = numpy.array(data)
+    err = numpy.array(err)
+
+    self.assertEqual(len(errE.shape), len(err.shape))
+    for dE, d in zip(errE.shape, err.shape):
+      self.assertEqual(dE, d)
+    for vE, v in zip(numpy.reshape(errE, -1), numpy.reshape(err, -1)):
+      self.assertEqual(vE, v)
+
+    self.assertEqual(len(dataE.shape), len(data.shape))
+    for dE, d in zip(dataE.shape, data.shape):
+      self.assertEqual(dE, d)
+    for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
+      self.assertAlmostEqual(vE, v, 6)
+
+    self._db.close()    
+    return
+
+
+# End of file 

Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/test_sceccvmh.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/test_sceccvmh.py	2007-11-20 01:50:31 UTC (rev 8306)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/test_sceccvmh.py	2007-11-20 03:41:53 UTC (rev 8307)
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+def suite():
+
+  suite = unittest.TestSuite()
+
+  from TestSCECCVMH import TestSCECCVMH
+  suite.addTest(unittest.makeSuite(TestSCECCVMH))
+
+  return suite
+
+def main():
+  unittest.TextTestRunner(verbosity=2).run(suite())
+  return
+
+if __name__ == '__main__':
+  main()
+  
+
+# End of file 


Property changes on: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/test_sceccvmh.py
___________________________________________________________________
Name: svn:executable
   + *



More information about the cig-commits mailing list