[cig-commits] r20440 - in cs/spatialdata/trunk: libsrc/spatialdb tests/pytests/spatialdb tests/pytests/spatialdb/data

brad at geodynamics.org brad at geodynamics.org
Fri Jun 29 10:02:32 PDT 2012


Author: brad
Date: 2012-06-29 10:02:32 -0700 (Fri, 29 Jun 2012)
New Revision: 20440

Modified:
   cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc
   cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py
   cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb
Log:
Fixed some bugs in reading SimpleGridData. Finished Python unit tests for 3-D SimpleGridDB.

Modified: cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc	2012-06-29 15:41:40 UTC (rev 20439)
+++ cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc	2012-06-29 17:02:32 UTC (rev 20440)
@@ -45,16 +45,18 @@
   _x(0),
   _y(0),
   _z(0),
-  _filename(""),
-  _cs(new geocoords::CSGeoProj),
   _queryVals(0),
   _querySize(0),
   _numX(0),
   _numY(0),
   _numZ(0),
+  _dataDim(0),
+  _spaceDim(0),
   _numValues(0),
   _names(0),
   _units(0),
+  _filename(""),
+  _cs(new geocoords::CSGeoProj),
   _queryType(NEAREST)
 { // constructor
 } // constructor
@@ -430,10 +432,23 @@
   if (!ok)
     throw std::runtime_error(msg.str());
 
+  // Set data dimension based on dimensions of data.
+  _dataDim = 0;
+  if (_numX > 1) {
+    _dataDim += 1;
+  } // if
+  if (_numY > 1) {
+    _dataDim += 1;
+  } // if
+  if (_numZ > 1) {
+    _dataDim += 1;
+  } // if
+
   assert(_cs);
   _cs->initialize();
 } // _readHeader
 
+#include <iostream>
 // ----------------------------------------------------------------------
 // Read data values.
 void
@@ -462,12 +477,14 @@
     buffer.str(parser.next());
     buffer.clear();
     for (int i=0; i < numX; ++i) {
-      filein >> _x[i];
+      buffer >> _x[i];
     } // for
     std::vector<double> xVec(numX);
     for (int i=0; i < numX; ++i)
       xVec[i] = _x[i];
     std::sort(xVec.begin(), xVec.end());
+    for (int i=0; i < numX; ++i)
+      _x[i] = xVec[i];
   } // if
 
   if (numY > 1) {
@@ -476,12 +493,14 @@
     buffer.str(parser.next());
     buffer.clear();
     for (int i=0; i < numY; ++i) {
-      filein >> _y[i];
+      buffer >> _y[i];
     } // for
     std::vector<double> yVec(numY);
     for (int i=0; i < numY; ++i)
       yVec[i] = _y[i];
     std::sort(yVec.begin(), yVec.end());
+    for (int i=0; i < numY; ++i)
+      _y[i] = yVec[i];
   } // if
 
   if (numZ > 1) {
@@ -490,12 +509,14 @@
     buffer.str(parser.next());
     buffer.clear();
     for (int i=0; i < numZ; ++i) {
-      filein >> _z[i];
+      buffer >> _z[i];
     } // for
     std::vector<double> zVec(numZ);
     for (int i=0; i < numZ; ++i)
       zVec[i] = _z[i];
     std::sort(zVec.begin(), zVec.end());
+    for (int i=0; i < numZ; ++i)
+      _z[i] = zVec[i];
   } // if
 
   assert(numLocs > 0);
@@ -506,8 +527,9 @@
   for (int iLoc=0; iLoc < numLocs; ++iLoc) {
     buffer.str(parser.next());
     buffer.clear();
-    for (int iDim=0; iDim < spaceDim; ++iDim)
+    for (int iDim=0; iDim < spaceDim; ++iDim) {
       buffer >> coords[iDim];
+    } // for
     
     int indexX = 0;
     int indexY = 0;
@@ -525,8 +547,9 @@
     } // if
     
     const int indexData = _dataIndex(indexX, indexY, indexZ);
-    for (int iVal=0; iVal < _numValues; ++iVal)
+    for (int iVal=0; iVal < _numValues; ++iVal) {
       buffer >> _data[indexData+iVal];
+    } // for
     if (buffer.bad()) {
       throw std::runtime_error("Error reading points.");
     } // if

Modified: cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py	2012-06-29 15:41:40 UTC (rev 20439)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py	2012-06-29 17:02:32 UTC (rev 20440)
@@ -33,13 +33,14 @@
 
 
   def test_database(self):
-    locs = numpy.array( [[1.0, 2.0, 3.0],
-                         [5.6, 4.2, 8.6]],
+    locs = numpy.array( [[3.5, 0.1, 0.8],
+                         [8.0, -0.4, 1.8]],
                         numpy.float64)
     cs = CSCart()
     cs._configure()
     queryVals = ["two", "one"]
-    dataE = numpy.array( [[4.7, 6.3]]*2, numpy.float64)
+    dataE = numpy.array( [[2.20, 1.04],
+                          [2.22, 1.02]], numpy.float64)
     errE = [0, 0]
 
     db = self._db
@@ -67,13 +68,14 @@
 
 
   def test_databasemulti(self):
-    locs = numpy.array( [[1.0, 2.0, 3.0],
-                         [5.6, 4.2, 8.6]],
+    locs = numpy.array( [[2.3, -0.1, 1.8],
+                         [2.0,  0.4, -2.0]],
                         numpy.float64)
     cs = CSCart()
     cs._configure()
     queryVals = ["two", "one"]
-    dataE = numpy.array( [[4.7, 6.3]]*2, numpy.float64)
+    dataE = numpy.array( [[2.07, 1.17],
+                          [2.09, 1.15]], numpy.float64)
     errE = numpy.array([0, 0], numpy.int32)
 
     db = self._db

Modified: cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb	2012-06-29 15:41:40 UTC (rev 20439)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb	2012-06-29 17:02:32 UTC (rev 20440)
@@ -13,8 +13,10 @@
 }
 // x
 2.0  4.0
+
 // y
 4.0  -0.5  1.0  0.0
+
 // z
 1.0  -3.0  2.0
 



More information about the CIG-COMMITS mailing list