[cig-commits] r8190 - in cs/spatialdata-0.1/trunk: libsrc/geocoords
libsrc/spatialdb modulesrc/spatialdb spatialdata
spatialdata/spatialdb tests/libtests/spatialdb
tests/pytests/spatialdb
brad at geodynamics.org
brad at geodynamics.org
Sun Oct 28 12:29:59 PDT 2007
Author: brad
Date: 2007-10-28 12:29:58 -0700 (Sun, 28 Oct 2007)
New Revision: 8190
Added:
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/UniformDB.py
cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc
cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.hh
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestUniformDB.py
Modified:
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc
cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc
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/libtests/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
Log:
Finished implementing and testing Python UniformDB object. Fixed bug in reading CSGeoProj coordinate system.
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc 2007-10-28 19:29:58 UTC (rev 8190)
@@ -186,7 +186,7 @@
for (int i=start; i < end; ++i)
if ('=' == rbuffer[i])
start = i+1;
- for (int i=start; i < end; ++i) {
+ for (int i=end-1; i >= start; --i) {
s.putback(rbuffer[i]);
} // for
s.clear();
Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am 2007-10-28 19:29:58 UTC (rev 8190)
@@ -28,7 +28,8 @@
SimpleDBQuery.hh \
SimpleDBTypes.hh \
SimpleDBTypes.icc \
- UniformDB.hh
+ UniformDB.hh \
+ UniformDB.icc
noinst_HEADERS =
Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc 2007-10-28 19:29:58 UTC (rev 8190)
@@ -61,7 +61,7 @@
const double* values,
const int numValues)
{ // setData
- assert( (0 > numValues && 0 != names && 0 != values) ||
+ assert( (0 < numValues && 0 != names && 0 != values) ||
(0 == numValues && 0 == names && 0 == values) );
// clear out old data
Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src 2007-10-28 19:29:58 UTC (rev 8190)
@@ -16,6 +16,7 @@
#include "spatialdata/spatialdb/SimpleIO.hh"
#include "spatialdata/spatialdb/SimpleIOAscii.hh"
#include "spatialdata/spatialdb/SimpleDBTypes.hh"
+#include "spatialdata/spatialdb/UniformDB.hh"
#include "spatialdata/geocoords/CoordSys.hh"
@@ -456,8 +457,8 @@
namesArray = NULL
unitsArray = NULL
if numValues > 0:
- namesArray = <char**> malloc(numValues*sizeof(char))
- unitsArray = <char**> malloc(numValues*sizeof(char))
+ namesArray = <char**> malloc(numValues*sizeof(char*))
+ unitsArray = <char**> malloc(numValues*sizeof(char*))
for i from 0 <= i < numValues:
strsize = len(names[i])
namesArray[i] = <char*> malloc(1+strsize*sizeof(char))
@@ -480,5 +481,58 @@
free(<void*> unitsArray)
return
+# ----------------------------------------------------------------------
+cdef class UniformDB(SpatialDB):
+ def __init__(self):
+ """
+ Constructor.
+ """
+ # create shim for constructor
+ #embed{ void* UniformDB_constructor()
+ return (void*)(new spatialdata::spatialdb::UniformDB);
+ #}embed
+
+ SpatialDB.__init__(self)
+ self.thisptr = UniformDB_constructor()
+ self.handle = self._createHandle()
+ return
+
+
+ def setData(self, names, values):
+ """
+ Set the data in the spatial database.
+ """
+ # create shim for method 'setData'
+ #embed{ void UniformDB_setData(void* pObj, char** names, double* values, int size)
+ ((spatialdata::spatialdb::UniformDB*) pObj)->setData(
+ const_cast<const char**>(names), values, size);
+ #}embed
+
+ cdef char** namesArray
+ cdef double* valuesArray
+ namesArray = NULL
+ valuesArray = NULL
+ numValues = len(names)
+ if numValues > 0:
+ namesArray = <char**> malloc(numValues*sizeof(char*))
+ valuesArray = <double*> malloc(numValues*sizeof(double))
+ for i from 0 <= i < numValues:
+ strsize = len(names[i])
+ namesArray[i] = <char*> malloc(1+strsize*sizeof(char))
+ tmp = names[i] # KLUDGE??
+ strcpy(namesArray[i], tmp)
+
+ valuesArray[i] = values[i]
+
+ UniformDB_setData(self.thisptr, namesArray, valuesArray, numValues)
+
+ for i from 0 <= i < numValues:
+ free(<void*> namesArray[i])
+ free(<void*> namesArray)
+ free(<void*> valuesArray)
+ return
+
+
+
# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2007-10-28 19:29:58 UTC (rev 8190)
@@ -24,6 +24,7 @@
spatialdb/SimpleIOAscii.py \
spatialdb/SimpleIO.py \
spatialdb/SpatialDB.py \
+ spatialdb/UniformDB.py \
spatialdb/__init__.py \
spatialdb/generator/Shaper.py \
spatialdb/generator/Shapers.py \
Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/UniformDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/UniformDB.py 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/UniformDB.py 2007-10-28 19:29:58 UTC (rev 8190)
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/UniformDB.py
+##
+## @brief Python manager for spatial database with uniform values.
+##
+## Factory: spatial_database
+
+from SpatialDB import SpatialDB
+
+# UniformDB class
+class UniformDB(SpatialDB):
+ """
+ Python manager for spatial database with uniform values.
+
+ Factory: spatial_database
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(SpatialDB.Inventory):
+ """
+ Python object for managing UniformDB facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing UniformDB facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b values Names of values in spatial database.
+ ## @li \b data Values in spatial database.
+ ##
+ ## \b Facilities
+ ## @li none
+
+ import pyre.inventory
+
+ values = pyre.inventory.list("values", default=[])
+ values.meta['tip'] = "Names of values in spatial database."
+
+ data = pyre.inventory.list("data", default=[])
+ data.meta['tip'] = "Values in spatial database."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="uniformdb"):
+ """
+ Constructor.
+ """
+ SpatialDB.__init__(self, name)
+ import spatialdb as bindings
+ self.cppHandle = bindings.UniformDB()
+ return
+
+
+ def initialize(self):
+ """
+ Initialize database.
+ """
+ SpatialDB.initialize(self)
+ self.cppHandle.setData(self.values, self.data)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based on inventory.
+ """
+ SpatialDB._configure(self)
+ self._validate(self.inventory)
+ self.values = self.inventory.values
+ self.data = self.inventory.data
+ return
+
+
+ def _validate(self, data):
+ """
+ Validate parameters.
+ """
+ if (len(data.values) != len(data.data)):
+ raise ValueError, \
+ "Incompatible settings for uniform spatial database '%s'.\n"\
+ "'values' and 'data' must be lists of the same size.\n"\
+ "'values' has size of %d but 'data' has size of %d." \
+ % (self.label, len(self.values), len(self.data))
+ try:
+ dataFloat = map(float, data.data)
+ except:
+ raise ValueError, \
+ "'data' list must contain floating point values."
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def spatial_database():
+ """
+ Factory associated with UniformDB.
+ """
+ return UniformDB()
+
+
+# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/__init__.py 2007-10-28 19:29:58 UTC (rev 8190)
@@ -18,6 +18,7 @@
'SimpleIOAscii',
'SimpleIO',
'SpatialDB',
+ 'UniformDB',
'generator']
Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am 2007-10-28 19:29:58 UTC (rev 8190)
@@ -29,6 +29,7 @@
TestSimpleDBVolume3D.cc \
TestSimpleIOAscii.cc \
TestSpatialDB.cc \
+ TestUniformDB.cc \
testcquery.c \
testspatial.cc
@@ -41,6 +42,7 @@
TestSimpleDBArea3D.hh \
TestSimpleDBVolume3D.hh \
TestSimpleIOAscii.hh \
+ TestUniformDB.hh \
testcquery.h \
TestSpatialDB.hh
Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc 2007-10-28 19:29:58 UTC (rev 8190)
@@ -0,0 +1,130 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestUniformDB.hh" // Implementation of class methods
+
+#include "spatialdata/spatialdb/UniformDB.hh" // USES UniformDB
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestUniformDB );
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+spatialdata::spatialdb::TestUniformDB::testConstructorA(void)
+{ // testConstructorA
+ UniformDB db;
+} // testConstructorA
+
+// ----------------------------------------------------------------------
+// Test constructor w/label.
+void
+spatialdata::spatialdb::TestUniformDB::testConstructorB(void)
+{ // testConstructorB
+ const char* label = "database A";
+ UniformDB db(label);
+ CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testConstructorB
+
+// ----------------------------------------------------------------------
+// Test Label().
+void
+spatialdata::spatialdb::TestUniformDB::testLabel(void)
+{ // testLabel
+ UniformDB db;
+ const char* label = "database 2";
+ db.label(label);
+ CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testLabel
+
+// ----------------------------------------------------------------------
+// Test setData().
+void
+spatialdata::spatialdb::TestUniformDB::testSetData(void)
+{ // testSetData
+ UniformDB db;
+
+ const int numValues = 3;
+ const char* names[] = { "one", "two", "three" };
+ const double values[] = { 1.1, 2.2, 3.3 };
+
+ db.setData(names, values, numValues);
+
+ CPPUNIT_ASSERT_EQUAL(numValues, db._numValues);
+ for (int i=0; i < numValues; ++i)
+ CPPUNIT_ASSERT_EQUAL(std::string(names[i]), db._names[i]);
+
+ for (int i=0; i < numValues; ++i)
+ CPPUNIT_ASSERT_EQUAL(values[i], db._values[i]);
+} // testSetData
+
+// ----------------------------------------------------------------------
+// Test setData().
+void
+spatialdata::spatialdb::TestUniformDB::testQueryVals(void)
+{ // testQueryVals
+ UniformDB db;
+
+ const int numValues = 3;
+ const char* names[] = { "one", "two", "three" };
+ const double values[] = { 1.1, 2.2, 3.3 };
+
+ const int querySize = 2;
+ const char* queryNames[] = { "three", "two" };
+ const int queryVals[] = { 2, 1 };
+
+ db.setData(names, values, numValues);
+ db.queryVals(queryNames, querySize);
+
+ CPPUNIT_ASSERT_EQUAL(querySize, db._querySize);
+ for (int i=0; i < querySize; ++i)
+ CPPUNIT_ASSERT_EQUAL(queryVals[i], db._queryVals[i]);
+} // testQueryVals
+
+// ----------------------------------------------------------------------
+// Test query().
+void
+spatialdata::spatialdb::TestUniformDB::testQuery(void)
+{ // testQuery
+ UniformDB db;
+
+ const int numValues = 3;
+ const char* names[] = { "one", "two", "three" };
+ const double values[] = { 1.1, 2.2, 3.3 };
+
+ const int querySize = 2;
+ const char* queryNames[] = { "three", "two" };
+ const int queryVals[] = { 2, 1 };
+
+ db.setData(names, values, numValues);
+ db.queryVals(queryNames, querySize);
+
+ const int spaceDim = 2;
+ spatialdata::geocoords::CSCart cs;
+ cs.setSpaceDim(spaceDim);
+ const double coords[] = { 2.3, 5.6 };
+ double data[querySize];
+
+ db.query(data, querySize, coords, spaceDim, &cs);
+
+ for (int i=0; i < querySize; ++i) {
+ const double valE = values[queryVals[i]];
+ CPPUNIT_ASSERT_EQUAL(valE, data[i]);
+ } // for
+} // testQuery
+
+
+// End of file
Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.hh 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.hh 2007-10-28 19:29:58 UTC (rev 8190)
@@ -0,0 +1,75 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file tests/libtests/spatialdb/TestUniformDB.hh
+ *
+ * @brief C++ TestUniformDB object
+ *
+ * C++ unit testing for UniformDB.
+ */
+
+#if !defined(spatialdata_spatialdb_testuniformdb_hh)
+#define spatialdata_spatialdb_testuniformdb_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for spatial package
+namespace spatialdata {
+ namespace spatialdb {
+ class TestUniformDB;
+ class UniformDB; // USES UniformDB
+ } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for UniformDB
+class spatialdata::spatialdb::TestUniformDB : public CppUnit::TestFixture
+{ // class TestUniformDB
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestUniformDB );
+
+ CPPUNIT_TEST( testConstructorA );
+ CPPUNIT_TEST( testConstructorB );
+ CPPUNIT_TEST( testLabel );
+ CPPUNIT_TEST( testSetData );
+ CPPUNIT_TEST( testQueryVals );
+ CPPUNIT_TEST( testQuery );
+
+ CPPUNIT_TEST_SUITE_END();
+
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /// Test constructor
+ void testConstructorA(void);
+
+ /// Test constructor with label
+ void testConstructorB(void);
+
+ /// Test label()
+ void testLabel(void);
+
+ /// Test setData()
+ void testSetData(void);
+
+ /// Test queryVals()
+ void testQueryVals(void);
+
+ /// Test query()
+ void testQuery(void);
+
+}; // class TestUniformDB
+
+#endif // spatialdata_spatialdb_testuniformdb_hh
+
+
+// End of file
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am 2007-10-28 19:29:58 UTC (rev 8190)
@@ -18,6 +18,7 @@
TestGenSimpleDBApp.py \
TestSimpleIOAscii.py \
TestSpatialDB.py \
+ TestUniformDB.py \
testspatial.py
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestUniformDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestUniformDB.py 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestUniformDB.py 2007-10-28 19:29:58 UTC (rev 8190)
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+
+
+class TestUniformDB(unittest.TestCase):
+
+ def setUp(self):
+ from spatialdata.spatialdb.UniformDB import UniformDB
+ db = UniformDB()
+ db.label = "test db"
+ db.values = ["one", "two", "three"]
+ db.data = [1.1, 2.2, 3.3]
+ db.initialize()
+ self._db = db
+ return
+
+ def test_database(self):
+ locs = numpy.array( [[1.0, 2.0, 3.0],
+ [5.6, 4.2, 8.6]],
+ numpy.float64)
+ from spatialdata.geocoords.CSCart import CSCart
+ cs = CSCart()
+ queryVals = ["three", "one"]
+ dataE = numpy.array([[3.3, 1.1],
+ [3.3, 1.1]], numpy.float64)
+ errE = numpy.array( [0]*2, numpy.int32)
+
+ self._db.open()
+ self._db.queryVals(queryVals)
+ (data, err) = self._db.query(locs, cs, 2)
+ 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
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2007-10-27 19:34:26 UTC (rev 8189)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2007-10-28 19:29:58 UTC (rev 8190)
@@ -22,6 +22,9 @@
from TestSimpleIOAscii import TestSimpleIOAscii
suite.addTest(unittest.makeSuite(TestSimpleIOAscii))
+ from TestUniformDB import TestUniformDB
+ suite.addTest(unittest.makeSuite(TestUniformDB))
+
from TestGenSimpleDBApp import TestGenSimpleDBApp
suite.addTest(unittest.makeSuite(TestGenSimpleDBApp))
More information about the cig-commits
mailing list