[cig-commits] r6117 - in cs/spatialdata-0.1/trunk: . applications
modulesrc modulesrc/spatialdb spatialdata
spatialdata/spatialdb spatialdata/spatialdb/generator
tests/pytests/spatialdb tests/pytests/spatialdb/data
brad at geodynamics.org
brad at geodynamics.org
Mon Feb 26 14:00:31 PST 2007
Author: brad
Date: 2007-02-26 14:00:30 -0800 (Mon, 26 Feb 2007)
New Revision: 6117
Added:
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestGenSimpleDBApp.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleIOAscii.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_add.spatialdb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_bg.spatialdb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_multiply.spatialdb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_bg.spatialdb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_divide.spatialdb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_subtract.spatialdb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/gensimpledb.cfg
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d.odb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_one.odb
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_two.odb
Removed:
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py
Modified:
cs/spatialdata-0.1/trunk/CHANGES
cs/spatialdata-0.1/trunk/TODO
cs/spatialdata-0.1/trunk/applications/gensimpledb.py
cs/spatialdata-0.1/trunk/applications/pyconvert.py
cs/spatialdata-0.1/trunk/configure.ac
cs/spatialdata-0.1/trunk/modulesrc/Makefile.am
cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am
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/SimpleIOAscii.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filter.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filters.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/GenSimpleDBApp.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Geometry.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Value.py
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Values.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
Log:
Switched to using numpy arrays as arguments in Python SimpleIOAscii::write(). Simplified generator app so it is all Python. Added unit tests for Python SimpleIOAscii and GenSimpleDBApp.
Modified: cs/spatialdata-0.1/trunk/CHANGES
===================================================================
--- cs/spatialdata-0.1/trunk/CHANGES 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/CHANGES 2007-02-26 22:00:30 UTC (rev 6117)
@@ -1,3 +1,9 @@
+2007/02/26
+
+ Switched to using numpy arrays as arguments in Python
+ SimpleIOAscii::write(). This greatly simplifies creating a database
+ from Python. Simplified GenSimpleDBApp so that it is all Python.
+
2007/01/01
Changed interface so that it no longer uses pointers to pointers
Modified: cs/spatialdata-0.1/trunk/TODO
===================================================================
--- cs/spatialdata-0.1/trunk/TODO 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/TODO 2007-02-26 22:00:30 UTC (rev 6117)
@@ -1,6 +1,3 @@
-Update generator code to allow generating 0-D, 1-D, and 2-D spatial
-distributions in addition to 3-D.
-
UTILS
Ignore comment lines in PointsStream.
@@ -11,9 +8,6 @@
SPATIALDB
- Testing
- Test generator code.
-
Get units by parsing header with Python
Cleanup SimpleDB::DataStruct, SimpleDBTypes
Modified: cs/spatialdata-0.1/trunk/applications/gensimpledb.py
===================================================================
--- cs/spatialdata-0.1/trunk/applications/gensimpledb.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/applications/gensimpledb.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,6 +11,7 @@
#
## @file spatialdata/applications/gensimpledb.py
+
## @brief Generic use of GenSimpleDBApp.
# ----------------------------------------------------------------------
Modified: cs/spatialdata-0.1/trunk/applications/pyconvert.py
===================================================================
--- cs/spatialdata-0.1/trunk/applications/pyconvert.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/applications/pyconvert.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,6 +11,7 @@
#
## @file spatialdata/applications/pyconvert.py
+
## @brief Generic use of ConvertApp.
# ----------------------------------------------------------------------
Modified: cs/spatialdata-0.1/trunk/configure.ac
===================================================================
--- cs/spatialdata-0.1/trunk/configure.ac 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/configure.ac 2007-02-26 22:00:30 UTC (rev 6117)
@@ -127,13 +127,8 @@
modulesrc/Makefile
modulesrc/geocoords/Makefile
modulesrc/spatialdb/Makefile
- modulesrc/spatialdb/generator/Makefile
modulesrc/utils/Makefile
spatialdata/Makefile
- spatialdata/geocoords/Makefile
- spatialdata/spatialdb/Makefile
- spatialdata/spatialdb/generator/Makefile
- spatialdata/utils/Makefile
tests/Makefile
tests/libtests/Makefile
tests/libtests/geocoords/Makefile
Modified: cs/spatialdata-0.1/trunk/modulesrc/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/Makefile.am 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/modulesrc/Makefile.am 2007-02-26 22:00:30 UTC (rev 6117)
@@ -15,7 +15,5 @@
spatialdb \
utils
-# version
-# $Id$
# End of file
Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am 2007-02-26 22:00:30 UTC (rev 6117)
@@ -13,8 +13,6 @@
subpackage = spatialdb
include $(top_srcdir)/subpackage.am
-SUBDIRS = generator
-
subpkgpyexec_LTLIBRARIES = spatialdbmodule.la
spatialdbmodule_la_LDFLAGS = -module
Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src 2007-02-26 22:00:30 UTC (rev 6117)
@@ -15,6 +15,7 @@
#include "spatialdata/spatialdb/SimpleDB.hh"
#include "spatialdata/spatialdb/SimpleIO.hh"
#include "spatialdata/spatialdb/SimpleIOAscii.hh"
+#include "spatialdata/spatialdb/SimpleDBTypes.hh"
#include "spatialdata/geocoords/CoordSys.hh"
#}header
@@ -116,8 +117,10 @@
#}embed
cdef char** pNames
+ pNames = NULL
numVals = len(names)
- pNames = <char**> malloc(numVals*sizeof(char*))
+ if numVals > 0:
+ pNames = <char**> malloc(numVals*sizeof(char*))
for i from 0 <= i < numVals:
strsize = len(names[i])
pNames[i] = <char*> malloc(1+strsize*sizeof(char))
@@ -139,12 +142,12 @@
Query db to get values at locations.
"""
# create shim for method 'query'
- #embed{ void SpatialDB_query(void* pObj, double* vals, int nvals, double* coords, int spaceDim, void* csObj)
+ #embed{ int SpatialDB_query(void* pObj, double* vals, int nvals, double* coords, int spaceDim, void* csObj)
spatialdata::geocoords::CoordSys* pCS =
(spatialdata::geocoords::CoordSys*) csObj;
- ((spatialdata::spatialdb::SpatialDB*) pObj)->query(vals, nvals,
- coords, spaceDim,
- pCS);
+ return ((spatialdata::spatialdb::SpatialDB*) pObj)->query(vals, nvals,
+ coords, spaceDim,
+ pCS);
#}embed
import spatialdata.utils.simplearray
@@ -171,13 +174,16 @@
cdef double* pVals
pVals = <double*> malloc(nlocs*nvals*sizeof(double))
+ cdef int* pErr
+ pErr = <int*> malloc(nlocs*sizeof(int))
+
cdef double* valbuffer
valbuffer = <double*> malloc(nvals*sizeof(double))
for iloc from 0 <= iloc < nlocs:
- SpatialDB_query(self.thisptr, valbuffer, nvals,
- &pLocs[spaceDim*iloc], spaceDim,
- ptrFromHandle(cs))
+ pErr[iloc] = SpatialDB_query(self.thisptr, valbuffer, nvals,
+ &pLocs[spaceDim*iloc], spaceDim,
+ ptrFromHandle(cs))
for ival from 0 <= ival < nvals:
pVals[nvals*iloc+ival] = valbuffer[ival]
free(<void*> valbuffer)
@@ -185,8 +191,9 @@
dims = [nlocs, nvals]
import spatialdata.utils.simplearray
pValsObj = PyCObject_FromVoidPtr(pVals, NULL);
- return spatialdata.utils.simplearray.SimpleCppArray(pValsObj,
- dims, "double")
+ pErrObj = PyCObject_FromVoidPtr(pErr, NULL);
+ return (spatialdata.utils.simplearray.SimpleCppArray(pValsObj, dims, "double"),
+ spatialdata.utils.simplearray.SimpleCppArray(pErrObj, [nlocs], "int"))
def _createHandle(self):
@@ -324,23 +331,84 @@
return
- def write(self, data, cs):
+ def write(self, names, units, dataObj, spaceDim, dataDim, cs):
"""
Write database to file.
"""
# create shim for method 'write'
- #embed{ void SimpleIOAscii_write(void* pObj, void* pDataObj, void* pCSObj)
+ #embed{ void SimpleIOAscii_write(void* pObj, char** names, char** units, double* data, int numLocs, int spaceDim, int numValues, int dataDim, void* pCSObj)
spatialdata::spatialdb::SimpleDB::DataStruct* pData =
- (spatialdata::spatialdb::SimpleDB::DataStruct*) pDataObj;
+ new spatialdata::spatialdb::SimpleDB::DataStruct;
+ pData->data = data;
+
+ pData->valNames = new std::string[numValues];
+ pData->valUnits = new std::string[numValues];
+ for (int iValue=0; iValue < numValues; ++iValue) {
+ pData->valNames[iValue] = names[iValue];
+ pData->valUnits[iValue] = units[iValue];
+ } // for
+ pData->numLocs = numLocs;
+ pData->numVals = numValues;
+ pData->dataDim = dataDim;
+ pData->spaceDim = spaceDim;
+
spatialdata::geocoords::CoordSys* pCS =
(spatialdata::geocoords::CoordSys*) pCSObj;
((spatialdata::spatialdb::SimpleIOAscii*) pObj)->write(*pData, pCS);
+ delete pData; pData = 0;
#}embed
- cdef void* pDataObj
- pDataObj = PyCObject_AsVoidPtr(data)
+
+ import spatialdata.utils.simplearray
+ data = spatialdata.utils.simplearray.objAsSimpleArray(dataObj)
+ if not data.isCompatible(nd=2,
+ simpletype="double",
+ contiguous=True,
+ notswapped=True):
+ raise TypeError, \
+ "Argument 'dataObj' must be a contiguous, 2-D array of type double."
+ numValues = len(names)
+ if not (numValues == len(units)):
+ raise ValueError, \
+ "Arguments 'names' and 'values' must have the same length."
+ (numLocs, totalDim) = data.shape
+ if totalDim != numValues + spaceDim:
+ raise ValueError, \
+ "'dataObj' not compatible with number of values and spaceDim."
+ if not cs.name == "spatialdata_geocoords_CoordSys":
+ raise TypeError, \
+ "Argument 'cs' must be extension module type 'CoordSys'."
- SimpleIOAscii_write(self.thisptr, pDataObj, ptrFromHandle(cs))
+ cdef double* dataArray
+ dataArray = <double*> PyCObject_AsVoidPtr(data.data)
+
+ cdef char** namesArray
+ cdef char** unitsArray
+ namesArray = NULL
+ unitsArray = NULL
+ if numValues > 0:
+ 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))
+ tmp = names[i] # KLUDGE??
+ strcpy(namesArray[i], tmp)
+
+ strsize = len(units[i])
+ unitsArray[i] = <char*> malloc(1+strsize*sizeof(char))
+ tmp = units[i] # KLUDGE??
+ strcpy(unitsArray[i], tmp)
+
+ SimpleIOAscii_write(self.thisptr,
+ namesArray, unitsArray, dataArray,
+ numLocs, spaceDim, numValues, dataDim,
+ ptrFromHandle(cs))
+ for i from 0 <= i < numValues:
+ free(<void*> namesArray[i])
+ free(<void*> unitsArray[i])
+ free(<void*> namesArray)
+ free(<void*> unitsArray)
return
Modified: cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2007-02-26 22:00:30 UTC (rev 6117)
@@ -10,18 +10,33 @@
# ----------------------------------------------------------------------
#
-subpackage = geocoords
-include $(top_srcdir)/subpackage.am
+nobase_pkgpyexec_PYTHON = \
+ __init__.py \
+ geocoords/Converter.py \
+ geocoords/CoordSys.py \
+ geocoords/CSCart.py \
+ geocoords/CSGeoLocalCart.py \
+ geocoords/CSGeoProj.py \
+ geocoords/CSGeo.py \
+ geocoords/Projector.py \
+ geocoords/__init__.py \
+ spatialdb/SimpleDB.py \
+ spatialdb/SimpleIOAscii.py \
+ spatialdb/SimpleIO.py \
+ spatialdb/SpatialDB.py \
+ spatialdb/__init__.py \
+ spatialdb/generator/Filter.py \
+ spatialdb/generator/Filters.py \
+ spatialdb/generator/GenSimpleDBApp.py \
+ spatialdb/generator/Geometry.py \
+ spatialdb/generator/Value.py \
+ spatialdb/generator/Values.py \
+ spatialdb/generator/__init__.py \
+ utils/ChangeCoordSys.py \
+ utils/ConvertApp.py \
+ utils/CppData.py \
+ utils/PointsStream.py \
+ utils/__init__.py
-SUBDIRS = \
- geocoords \
- spatialdb \
- utils
-pkgpyexec_PYTHON = \
- __init__.py
-
-# version
-# $Id$
-
# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,10 +11,13 @@
#
## @file spatialdata/spatialdb/SimpleIOAscii.py
+
## @brief Python ascii I/O manager for simple spatial database (SimpleDB).
from SimpleIO import SimpleIO
+import numpy
+
# SimpleIOAscii class
class SimpleIOAscii(SimpleIO):
"""
@@ -23,20 +26,44 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
- def write(self, cppDB, cs):
+ def __init__(self, name="simpleioascii"):
"""
- Write database data to file.
+ Constructor.
"""
- self.cppHandle.write(cppDB, cs.cppHandle)
- return
-
-
- def __init__(self, name="simpleioascii"):
- """Constructor."""
SimpleIO.__init__(self, name)
import spatialdb as bindings
self.cppHandle = bindings.SimpleIOAscii()
return
+ def write(self, data):
+ """
+ Write database to file.
+
+ @param data Dictionary of the following form:
+ data = {'locs': 2-D array (numLocs, spaceDim),
+ 'coordsys': Coordinate system associated with locations,
+ 'data_dim': Dimension of spatial distribution,
+ 'values': [{'name': Name of value,
+ 'units': Units of value,
+ 'data': Data for value (numLocs)}]}
+ """
+ names = []
+ units = []
+ (numLocs, spaceDim) = data['locs'].shape
+ dataDim = data['data_dim']
+ numValues = len(data['values'])
+ dbData = numpy.zeros( (numLocs, spaceDim+numValues), dtype=numpy.float64)
+ dbData[:,0:spaceDim] = data['locs'][:]
+ i = spaceDim
+ for value in data['values']:
+ names.append(value['name'])
+ units.append(value['units'])
+ dbData[:,i] = value['data'][:]
+ i += 1
+ cs = data['coordsys']
+ self.cppHandle.write(names, units, dbData, spaceDim, dataDim, cs.cppHandle)
+ return
+
+
# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -19,12 +19,16 @@
# SpatialDB class
class SpatialDB(Component):
- """Python abstract base class for spatial database."""
+ """
+ Python abstract base class for spatial database.
+ """
# INVENTORY //////////////////////////////////////////////////////////
class Inventory(Component.Inventory):
- """Python object for managing SpatialDB facilities and properties."""
+ """
+ Python object for managing SpatialDB facilities and properties.
+ """
## @class Inventory
## Python object for managing SpatialDB facilities and properties.
@@ -43,46 +47,60 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
+ def __init__(self, name="spatialdb"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="spatialdb")
+ self.cppHandle = None
+ return
+
+
def initialize(self):
- """Initialize database."""
+ """
+ Initialize database.
+ """
self.cppHandle.label = self.label
return
def open(self):
- """Open database and prepare for querying."""
+ """
+ Open database and prepare for querying.
+ """
self.cppHandle.open()
return
def close(self):
- """Close database."""
+ """
+ Close database.
+ """
self.cppHandle.close()
return
def queryVals(self, names):
- """Set values to return in queries."""
+ """
+ Set values to return in queries.
+ """
self.cppHandle.queryVals(names)
return
def query(self, locs, cs, numvals):
- """Perform query of db to get values at locations."""
+ """
+ Perform query of db to get values at locations.
+ """
return self.cppHandle.query(locs, cs.cppHandle, numvals)
- def __init__(self, name="spatialdb"):
- """Constructor."""
- Component.__init__(self, name, facility="spatialdb")
- self.cppHandle = None
- return
-
-
# PRIVATE METHODS ////////////////////////////////////////////////////
def _configure(self):
- """Set attributes based on inventory."""
+ """
+ Set attributes based on inventory.
+ """
self.label = self.inventory.label
return
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filter.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filter.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filter.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,26 +11,33 @@
#
## @file spatialdata/spatialdb/generator/Filter.py
+
## @brief Python manager for shaping spatial distribution of data
-## while generating database.
+## while generating database.
from pyre.components.Component import Component
+import numpy
+
# Filter class
class Filter(Component):
- """Python manager for shaping spatial distribution of data while
- generating database."""
+ """
+ Python manager for shaping spatial distribution of data while
+ generating database.
+ """
# INVENTORY //////////////////////////////////////////////////////////
class Inventory(Component.Inventory):
- """Python object for managing Filter facilities and properties."""
+ """
+ Python object for managing Filter facilities and properties.
+ """
## @class Inventory
## Python object for managing Filter facilities and properties.
##
## \b Properties
- ## @li \b db_value Name of value in supplied in filter spatial database
+ ## @li \b db_value Name of value in supplied spatial database filter
## @li \b operand Operand to use in applying filter
##
## \b Facilities
@@ -56,35 +63,64 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
+ def __init__(self, name="filter"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="filter")
+ return
+
+
def initialize(self):
- """Initialize filter."""
+ """
+ Initialize filter.
+ """
self.db.initialize()
self.db.open()
return
- def cleanup(self):
- """Cleanup."""
+ def finalize(self):
+ """
+ Cleanup.
+ """
self.db.close()
return
- def apply(self, cppVals, valueCount, locs, locCount, cs):
- """Apply filter to data."""
- import spatialdata.spatialdb.generator.generator as bindings
+ def apply(self, value, locs, cs):
+ """
+ Apply filter to data.
+ """
self.db.queryVals([self.dbValue])
- bindings.applyFilter(cppVals, valueCount, locs, locCount,
- cs.cppHandle, self.db.cppHandle,
- self.operand, self.defaultValue)
- return
+ (vals, err) = self.db.query(locs, cs, numvals=1)
+ vals = numpy.reshape(numpy.array(vals), -1)
+ err = numpy.array(err)
+ default = self.defaultValue*numpy.ones( vals.shape, dtype=numpy.float64)
+ mask = numpy.zeros( vals.shape, dtype=numpy.float64)
+ mask[err[:] != 0] = 1.0
+ vals[:] += default[:]*mask[:]
- def __init__(self, name="filter"):
- """Constructor."""
- Component.__init__(self, name, facility="filter")
+ if self.operand == "add":
+ value[:] += vals[:]
+ elif self.operand == "subtract":
+ value[:] -= vals[:]
+ elif self.operand == "multiply":
+ value[:] *= vals[:]
+ elif self.operand == "divide":
+ value[:] /= vals[:]
+ else:
+ raise ValueError, \
+ "Unknown operand setting '%s'." % self.operand
return
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
def _configure(self):
+ """
+ Setup members using inventory.
+ """
Component._configure(self)
if self.inventory.dbValue == "":
raise ValueError, \
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filters.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filters.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Filters.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,18 +11,23 @@
#
## @file spatialdata/spatialdb/generator/Filters.py
+
## @brief Python manager for filters controlling spatial distribution.
from pyre.components.Component import Component
# Filters class
class Filters(Component):
- """Python manager for filters controlling spatial distribution."""
+ """
+ Python manager for filters controlling spatial distribution.
+ """
# PUBLIC METHODS /////////////////////////////////////////////////////
def __init__(self, name="filters"):
- """Constructor."""
+ """
+ Constructor.
+ """
Component.__init__(self, name, facility="filters")
self.filters = []
return
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/GenSimpleDBApp.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/GenSimpleDBApp.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/GenSimpleDBApp.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,18 +11,24 @@
#
## @file spatialdata/spatialdb/generator/GenSimpleDBApp.py
-## @brief Python application to generate simple spatial database.
+## @brief Python application to generate simple spatial database from
+## other simple spatial databases.
+
from pyre.applications.Script import Script
# GenSimpleDBApp class
class GenSimpleDBApp(Script):
- """Python object to generate simple spatial database."""
+ """
+ Python object to generate simple spatial database.
+ """
# INVENTORY //////////////////////////////////////////////////////////
class Inventory(Script.Inventory):
- """Python object for managing GenSimpleDBApp facilities and properties."""
+ """
+ Python object for managing GenSimpleDBApp facilities and properties.
+ """
## @class Inventory
## Python object for managing GenSimpleDBApp facilities and properties.
@@ -52,41 +58,43 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
+ def __init__(self, name='gensimpledb'):
+ """
+ Constructor.
+ """
+ Script.__init__(self, name)
+ return
+
+
def main(self, *args, **kwds):
- self.geometry.load()
- vertices = self.geometry.vertices
+ """
+ Application driver.
+ """
+ self._info.log("Reading geometry.")
+ self.geometry.read()
+ locs = self.geometry.vertices
coordsys = self.geometry.coordsys
+ data = {'locs': locs,
+ 'coordsys': coordsys,
+ 'data_dim': self.geometry.dataDim,
+ 'values': []}
for value in self.values.values:
- value.applyFilters(vertices.handle(), vertices.vertexCount, vertices.dim,
- coordsys)
- cppDB = self._assembleDB()
+ self._info.log("Creating value '%s'" % value.name)
+ data['values'].append({'name': value.name,
+ 'units': value.units,
+ 'data': value.calculate(locs, coordsys)})
+ self._info.log("Writing database.")
self.iohandler.initialize()
- self.iohandler.write(cppDB, coordsys)
+ self.iohandler.write(data)
return
- def __init__(self, name='gensimpledb'):
- Script.__init__(self, name)
- return
-
-
# PRIVATE METHODS ////////////////////////////////////////////////////
- def _assembleDB(self):
- import spatialdata.spatialdb.generator.generator as bindings
- vertices = self.geometry.vertices
- coordsys = self.geometry.coordsys
- numValues = len(self.values.values)
- cppDB = bindings.create(vertices.handle(),
- vertices.vertexCount, vertices.dim,
- numValues, coordsys.spaceDim,
- self.geometry.dataDim)
- for i in range(numValues):
- self.values.values[i].setDB(cppDB, i)
- return cppDB
-
-
def _configure(self):
+ """
+ Setup members based on inventory.
+ """
Script._configure(self)
self.geometry = self.inventory.geometry
self.values = self.inventory.values
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Geometry.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Geometry.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Geometry.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,6 +11,7 @@
#
## @file spatialdata/spatialdb/generator/Geometry.py
+
## @brief Python manager for geometry used in generating database.
from pyre.components.Component import Component
@@ -24,12 +25,16 @@
# Geometry class
class Geometry(Component):
- """Python manager for geometry used in generating database."""
+ """
+ Python manager for geometry used in generating database.
+ """
# INVENTORY //////////////////////////////////////////////////////////
class Inventory(Component.Inventory):
- """Python object for managing Geometry facilities and properties."""
+ """
+ Python object for managing Geometry facilities and properties.
+ """
## @class Inventory
## Python object for managing Geometry facilities and properties.
@@ -38,43 +43,53 @@
## @li \b data_dim Spatial dimension of database locations.
##
## \b Facilities
- ## @li \b unpickler Object to unpickle geometry
+ ## @li \b reader Object to read geometry
## @li \b coordsys Coordinate system of geometry
import pyre.inventory
- dataDim = pyre.inventory.str("data_dim", default=2)
+ dataDim = pyre.inventory.int("data_dim", default=2)
dataDim.validator = pyre.inventory.choice([0, 1, 2, 3])
dataDim.meta['tip'] = "Spatial dimension of database locations."
- unpickler = pyre.inventory.facility("unpickler", factory=Dummy)
- unpickler.meta['tip'] = "Object to unpickle geometry."
+ reader = pyre.inventory.facility("reader", factory=Dummy)
+ reader.meta['tip'] = "Object to read geometry."
- from spatialdata.geocoords.CoordSys import CoordSys
- coordsys = pyre.inventory.facility("coordsys", factory=CoordSys)
+ from spatialdata.geocoords.CSCart import CSCart
+ coordsys = pyre.inventory.facility("coordsys", factory=CSCart)
coordsys.meta['tip'] = "Coordinate system for database."
# PUBLIC METHODS /////////////////////////////////////////////////////
- def load(self):
- mesh = self.unpickler.load()
- self.vertices = mesh.vertices()
- self.coordsys.initialize()
- return
-
-
def __init__(self, name="geometry"):
- """Constructor."""
+ """
+ Constructor.
+ """
Component.__init__(self, name, facility="geometry")
self.vertices = None
return
+ def read(self):
+ """
+ Read geometry.
+ """
+ mesh = self.reader.unpickle()
+ self.vertices = mesh.vertices
+ self.coordsys.initialize()
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
def _configure(self):
+ """
+ Setup members using inventory.
+ """
Component._configure(self)
self.dataDim = self.inventory.dataDim
- self.unpickler = self.inventory.unpickler
+ self.reader = self.inventory.reader
self.coordsys = self.inventory.coordsys
return
Deleted: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -1,70 +0,0 @@
-#!/usr/bin/env python
-#
-# ----------------------------------------------------------------------
-#
-# Brad T. Aagaard
-# U.S. Geological Survey
-#
-# <LicenseText>
-#
-# ----------------------------------------------------------------------
-#
-
-## @file spatialdata/spatialdb/generator/SimpleDBCreator.py
-
-## @brief Python object for creating a SimpleDB file.
-
-# SimpleDBCreator class
-class SimpleDBCreator(object):
- """
- Python object for creating a SimpleDB file.
- """
-
- # PUBLIC METHODS /////////////////////////////////////////////////////
-
- def create(self, filename, values, units, coords, data, dataDim, cs):
- """
- Create database file.
- """
- self._validate(values, units, coords, data)
- (numLocs, spaceDim) = coords.shape
- numValues = len(values)
-
- import spatialdb.spatialdb.generator.generator as bindings
- cppData = bindings.createData(values, units, coords, data, dataDim)
-
- # Create SimpleIOAscii object
- # Write database file
- return
-
-
- def __init__(self):
- """
- Constructor.
- """
- return
-
-
- # PRIVATE METHODS ////////////////////////////////////////////////////
-
- def _validate(values, units, coords, data):
- """
- Check consistency of dimensions.
- """
- msg = ""
- numValues = len(values)
- if numValues != len(units):
- msg += "Number of values given in 'values' and 'units' do not match."
- (numLocs, spaceDim) = coords.shape
- (dataLocs, dataValues) = data.shape
- if numLocs != dataLocs:
- msg += "Number of locations in 'coords' and 'data' do not match."
- if numValues != dataValues:
- msg += "Number of values in 'values' and 'data' do not match."
- if msg != "":
- raise ValueError(msg)
- return
-
-
-
-# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Value.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Value.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Value.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,18 +11,25 @@
#
## @file spatialdata/spatialdb/generator/Value.py
+
## @brief Python manager for generating value in database.
from pyre.components.Component import Component
+import numpy
+
# Value class
class Value(Component):
- """Python manager for generating value in database."""
+ """
+ Python manager for generating value in database.
+ """
# INVENTORY //////////////////////////////////////////////////////////
class Inventory(Component.Inventory):
- """Python object for managing Value facilities and properties."""
+ """
+ Python object for managing Value facilities and properties.
+ """
## @class Inventory
## Python object for managing Value facilities and properties.
@@ -49,37 +56,33 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
- def handle(self):
- return self._cppVal
+ def __init__(self, name="value"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="value")
+ return
- def applyFilters(self, locs, locCount, locDim, cs):
- self.locCount = locCount
- self.locDim = locDim
- import spatialdata.spatialdb.generator.generator as bindings
- self._cppVal = bindings.createValue(locCount)
+
+ def calculate(self, locs, cs):
+ """
+ Calculate spatial distribution for value using filters.
+ """
+ (numLocs, spaceDim) = locs.shape
+ value = numpy.zeros( (numLocs,), dtype=numpy.float64)
for filter in self.filters.filters:
filter.initialize()
- filter.apply(self._cppVal, locCount, locs, locCount, cs)
- filter.cleanup()
- return
+ filter.apply(value, locs, cs)
+ filter.finalize()
+ return value
- def setDB(self, cppDB, index):
- import spatialdata.spatialdb.generator.generator as bindings
- bindings.setValue(cppDB, index,
- self._cppVal, self.locCount,
- self.name, self.units)
- return
+ # PRIVATE METHODS ////////////////////////////////////////////////////
-
- def __init__(self, name="value"):
- """Constructor."""
- Component.__init__(self, name, facility="value")
- self._cppVal = None
- return
-
-
def _configure(self):
+ """
+ Setup members using inventory.
+ """
Component._configure(self)
self.name = self.inventory.name
self.units = self.inventory.units
@@ -87,7 +90,4 @@
return
-# version
-__id__ = "$Id$"
-
# End of file
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Values.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Values.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Values.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,24 +11,26 @@
#
## @file spatialdata/spatialdb/generator/Values.py
+
## @brief Python manager for values in database.
from pyre.components.Component import Component
# Values class
class Values(Component):
- """Python manager for values in database."""
+ """
+ Python manager for values in database.
+ """
# PUBLIC METHODS /////////////////////////////////////////////////////
def __init__(self, name="values"):
- """Constructor."""
+ """
+ Constructor.
+ """
Component.__init__(self, name, facility="values")
self.values = []
return
-# version
-__id__ = "$Id$"
-
# 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-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am 2007-02-26 22:00:30 UTC (rev 6117)
@@ -15,11 +15,26 @@
TESTS = testspatial.py
noinst_PYTHON = \
+ TestGenSimpleDBApp.py \
+ TestSimpleIOAscii.py \
TestSpatialDB.py \
testspatial.py
-# version
-# $Id$
+data_DATA = \
+ testgen1din2d.odb \
+ testgen1din2d_one.odb \
+ testgen1din2d_two.odb \
+ gensimpledb.cfg
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/tests/pytests/spatialdb
+export-data: $(data_DATA)
+ for f in $(data_DATA); do $(install_sh_DATA) $(srcdir)/$$f $(export_datadir); done
+
+BUILT_SOURCES = export-data
+
+CLEANFILES = \
+ $(export_datadir)/$(data_DATA)
+
# End of file
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestGenSimpleDBApp.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestGenSimpleDBApp.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestGenSimpleDBApp.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+
+# ----------------------------------------------------------------------
+class TestGenSimpleDBApp(unittest.TestCase):
+
+ def test(self):
+ """
+ Test GenSimpleDBApp with 1-D data in 2-D space.
+ """
+ from spatialdata.spatialdb.generator.GenSimpleDBApp import GenSimpleDBApp
+ from spatialdata.spatialdb.generator.Value import Value
+ from spatialdata.spatialdb.generator.Filter import Filter
+ from spatialdata.geocoords.CSCart import CSCart
+ from spatialdata.spatialdb.SimpleDB import SimpleDB
+ from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+
+ app = GenSimpleDBApp()
+ app.run()
+
+ # Test write using query
+ from spatialdata.spatialdb.SimpleDB import SimpleDB
+ iohandler = SimpleIOAscii()
+ iohandler.filename = "data/gen1Din2D.spatialdb"
+ db = SimpleDB()
+ db.label = "test"
+ db.queryType = "nearest"
+ db.iohandler = iohandler
+ db.initialize()
+
+ db.open()
+ db.queryVals(["two", "one"])
+
+ qlocs = numpy.array( [[-2.0, 2.0],
+ [ 3.0, -4.0],
+ [ 0.0, 0.7]],
+ numpy.float64)
+
+ valsE = numpy.array( [[-0.15, 3.45],
+ [2.4, 6.4],
+ [-0.6, 3.45]], numpy.float64)
+
+ from spatialdata.geocoords.CSCart import CSCart
+ cs = CSCart()
+ cs.spaceDim = 2
+ cs.initialize()
+
+ (vals, err) = db.query(qlocs, cs, 2)
+ vals = numpy.array(vals)
+
+ self.assertEqual(len(valsE.shape), len(vals.shape))
+ for dE, d in zip(valsE.shape, vals.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(valsE, -1), numpy.reshape(vals, -1)):
+ self.assertAlmostEqual(vE, v, 6)
+
+ db.close()
+ return
+
+
+# End of file
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleIOAscii.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleIOAscii.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleIOAscii.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+import spatialdata.utils.simplearray as simplearray
+from spatialdata.geocoords.CSCart import CSCart
+
+class TestSimpleIOAscii(unittest.TestCase):
+
+ def test_write(self):
+ """
+ Test write().
+ """
+ # Database info
+ filename = "data/test.spatialdb"
+ cs = CSCart()
+ data = {'locs': numpy.array( [ [1.0, 2.0, 3.0],
+ [0.5, 3.0, -3.0]], numpy.float64),
+ 'coordsys': cs,
+ 'data_dim': 1,
+ 'values': [{'name': "One",
+ 'units': "m",
+ 'data': numpy.array( [2.0, 8.0], numpy.float64)},
+ {'name': "Two",
+ 'units': "m",
+ 'data': numpy.array( [-2.0, 3.0], numpy.float64)}]}
+
+ dataDim = 1
+
+
+ # Write database
+ from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+ writer = SimpleIOAscii()
+ writer.filename = filename
+ writer.initialize()
+ writer.write(data)
+
+ # Test write using query
+ from spatialdata.spatialdb.SimpleDB import SimpleDB
+ iohandler = SimpleIOAscii()
+ iohandler.filename = filename
+ db = SimpleDB()
+ db.label = "test"
+ db.queryType = "Linear"
+ db.iohandler = iohandler
+ db.initialize()
+
+ db.open()
+ db.queryVals(["two", "one"])
+
+ qlocs = numpy.array( [[0.875, 2.25, 1.5],
+ [0.6, 2.8, -1.8],
+ [1.0, 2.0, 3.0]],
+ numpy.float64)
+
+ valsE = numpy.array( [[-0.75, 3.5],
+ [2.0, 6.8],
+ [-2.0, 2.0]], numpy.float64)
+
+ (vals, err) = db.query(qlocs, cs, 2)
+ vals = numpy.array(vals)
+
+ self.assertEqual(len(valsE.shape), len(vals.shape))
+ for dE, d in zip(valsE.shape, vals.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(valsE, -1), numpy.reshape(vals, -1)):
+ self.assertAlmostEqual(vE, v, 6)
+
+ db.close()
+ return
+
+
+# End of file
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -43,8 +43,19 @@
cs.toMeters = 1.0
valsE = numpy.array( [[4.7, 6.3]]*2, numpy.float64)
- vals = numpy.array(self._db.query(locs, cs, 2))
- self.assertEqual(2, len(vals.shape))
+ errE = numpy.array( [0]*2, numpy.int32)
+
+ (vals, err) = self._db.query(locs, cs, 2)
+ vals = numpy.array(vals)
+ 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(valsE.shape), len(vals.shape))
for dE, d in zip(valsE.shape, vals.shape):
self.assertEqual(dE, d)
for vE, v in zip(numpy.reshape(valsE, -1), numpy.reshape(vals, -1)):
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/Makefile.am 2007-02-26 22:00:30 UTC (rev 6117)
@@ -11,8 +11,18 @@
#
data_DATA = \
- spatialdb.dat
+ spatialdb.dat \
+ gen1Din2D_one_bg.spatialdb \
+ gen1Din2D_one_add.spatialdb \
+ gen1Din2D_one_multiply.spatialdb \
+ gen1Din2D_two_bg.spatialdb \
+ gen1Din2D_two_subtract.spatialdb \
+ gen1Din2D_two_divide.spatialdb
+data_CLEAN = \
+ test.spatialdb \
+ gen1Din2D.spatialdb
+
noinst_HEADERS = \
$(data_DATA)
@@ -24,9 +34,8 @@
BUILT_SOURCES = export-data
CLEANFILES = \
- $(export_datadir)/$(data_DATA)
+ $(export_datadir)/$(data_DATA) \
+ $(export_datadir)/$(data_CLEAN)
-# version
-# $Id$
# End of file
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_add.spatialdb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_add.spatialdb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_add.spatialdb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 1
+ value-names = One
+ value-units = none
+ num-locs = 2
+ data-dim = 1
+ space-dim = 2
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 2
+ }
+}
+-10.0 0.0 0.1
+ 0.5 0.0 0.1
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_bg.spatialdb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_bg.spatialdb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_bg.spatialdb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,14 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 1
+ value-names = One
+ value-units = none
+ num-locs = 1
+ data-dim = 0
+ space-dim = 2
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 2
+ }
+}
+0.0 0.0 2.2
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_multiply.spatialdb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_multiply.spatialdb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_one_multiply.spatialdb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,17 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 1
+ value-names = One
+ value-units = none
+ num-locs = 4
+ data-dim = 1
+ space-dim = 2
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 2
+ }
+}
+0.0 10.0 1.5
+0.0 0.11 1.5
+0.0 0.10 2.0
+0.0 -10.0 2.0
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_bg.spatialdb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_bg.spatialdb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_bg.spatialdb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,14 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 1
+ value-names = Two
+ value-units = none
+ num-locs = 1
+ data-dim = 0
+ space-dim = 2
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 2
+ }
+}
+0.0 0.0 -0.3
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_divide.spatialdb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_divide.spatialdb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_divide.spatialdb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,17 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 1
+ value-names = Two
+ value-units = none
+ num-locs = 4
+ data-dim = 1
+ space-dim = 2
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 2
+ }
+}
+-10.0 0.0 2.0
+ -0.11 0.0 2.0
+ -0.10 0.0 0.5
+ 10.0 0.0 0.5
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_subtract.spatialdb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_subtract.spatialdb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/data/gen1Din2D_two_subtract.spatialdb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 1
+ value-names = Two
+ value-units = none
+ num-locs = 2
+ data-dim = 1
+ space-dim = 2
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 2
+ }
+}
+0.0 0.2 -1.5
+0.0 -10.0 -1.5
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/gensimpledb.cfg
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/gensimpledb.cfg 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/gensimpledb.cfg 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,61 @@
+[gensimpledb]
+
+# ----------------------------------------------------------------------
+# Journal
+# ----------------------------------------------------------------------
+#journal.info.gensimpledb = 1
+
+# ----------------------------------------------------------------------
+# Geometry
+# ----------------------------------------------------------------------
+geometry.reader = testgen1din2d
+geometry.data_dim = 2
+geometry.coordsys.space_dim = 2
+
+# ----------------------------------------------------------------------
+# Values
+# ----------------------------------------------------------------------
+values = testgen1din2d
+values.one.name = One
+values.one.units = kg
+values.one.filters = testgen1din2d_one
+values.two.name = Two
+values.two.units = m
+values.two.filters = testgen1din2d_two
+
+values.one.filters.bg.default = 0.0
+values.one.filters.bg.operand = add
+values.one.filters.bg.db_value = One
+values.one.filters.bg.db.query_type = linear
+values.one.filters.bg.db.iohandler.filename = data/gen1Din2D_one_bg.spatialdb
+values.one.filters.add.default = 1.0
+values.one.filters.add.operand = add
+values.one.filters.add.db_value = One
+values.one.filters.add.db.query_type = linear
+values.one.filters.add.db.iohandler.filename = data/gen1Din2D_one_add.spatialdb
+values.one.filters.multiply.default = 0.0
+values.one.filters.multiply.operand = multiply
+values.one.filters.multiply.db_value = One
+values.one.filters.multiply.db.query_type = linear
+values.one.filters.multiply.db.iohandler.filename = data/gen1Din2D_one_multiply.spatialdb
+
+values.two.filters.bg.default = -1.0
+values.two.filters.bg.db_value = Two
+values.two.filters.bg.operand = add
+values.two.filters.bg.db.query_type = linear
+values.two.filters.bg.db.iohandler.filename = data/gen1Din2D_two_bg.spatialdb
+values.two.filters.subtract.default = 0.0
+values.two.filters.subtract.operand = subtract
+values.two.filters.subtract.db_value = Two
+values.two.filters.subtract.db.query_type = linear
+values.two.filters.subtract.db.iohandler.filename = data/gen1Din2D_two_subtract.spatialdb
+values.two.filters.divide.default = 1.0
+values.two.filters.divide.operand = divide
+values.two.filters.divide.db_value = Two
+values.two.filters.divide.db.query_type = linear
+values.two.filters.divide.db.iohandler.filename = data/gen1Din2D_two_divide.spatialdb
+
+# ----------------------------------------------------------------------
+# IO
+# ----------------------------------------------------------------------
+iohandler.filename = data/gen1Din2D.spatialdb
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d.odb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d.odb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d.odb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,136 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+from pyre.components.Component import Component
+
+import numpy
+
+# ----------------------------------------------------------------------
+# GeometryTestGen class
+class GeometryTestGen(Component):
+ """
+ Python object acting as Geometry component in testing GenSimpleDBApp.
+ """
+
+ class Topology(object):
+ """
+ Topology object to hold geometry.
+ """
+ def __init__(self):
+ """
+ Constructor.
+ """
+ self.vertices = None
+ self.simplices = None
+ return
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name="geometrytestgen", facility="reader")
+ self.topology = self.Topology()
+ self.topology.vertices = numpy.array([ [-2.0, 3.0],
+ [ 0.0, 1.0],
+ [ 1.0, 0.0],
+ [ 2.0, -4.0] ],
+ dtype=numpy.float64)
+ return
+
+
+ def unpickle(self):
+ """
+ Read geometry.
+ """
+ return self.topology
+
+
+# ----------------------------------------------------------------------
+# TwoValues class
+from spatialdata.spatialdb.generator.Values import Values
+class TwoValues(Values):
+ """
+ Python object acting as Values component in testing GenSimpleDBApp.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing Filter facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing Filter facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li \b one Value 'one' in database
+ ## @li \b two Value 'two' in database
+
+ import pyre.inventory
+
+ from spatialdata.spatialdb.generator.Value import Value
+
+ one = pyre.inventory.facility("one", factory=Value)
+ one.meta['tip'] = "Value 'one' in database."
+
+ two = pyre.inventory.facility("two", factory=Value)
+ two.meta['tip'] = "Value 'two' in database."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self):
+ """
+ Constructor.
+ """
+ Values.__init__(self, name="twovalues")
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Setup members based on inventory.
+ """
+ Values._configure(self)
+ self.values = [self.inventory.one, self.inventory.two]
+ return
+
+
+# ======================================================================
+# Factories
+
+def reader():
+ """
+ Factory for geometry reader.
+ """
+ return GeometryTestGen()
+
+
+def values():
+ """
+ Factory for geometry reader.
+ """
+ return TwoValues()
+
+
+
+
+# End of file
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_one.odb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_one.odb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_one.odb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+from pyre.components.Component import Component
+
+# ----------------------------------------------------------------------
+# OneFilters class
+from spatialdata.spatialdb.generator.Filters import Filters
+class OneFilters(Filters):
+ """
+ Python object acting as Filters component for value 'one' in testing
+ GenSimpleDBApp.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing Filters facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing Filter facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li \b bg Background filter
+ ## @li \b add Addition filter
+ ## @li \b multiply Multiplication filter
+
+ import pyre.inventory
+
+ from spatialdata.spatialdb.generator.Filter import Filter
+
+ bg = pyre.inventory.facility("bg", factory=Filter)
+ bg.meta['tip'] = "Background filter."
+
+ add = pyre.inventory.facility("add", factory=Filter)
+ add.meta['tip'] = "Addition filter."
+
+ multiply = pyre.inventory.facility("multiply", factory=Filter)
+ multiply.meta['tip'] = "Addition filter."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self):
+ """
+ Constructor.
+ """
+ Filters.__init__(self, name="onefilters")
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Setup members based on inventory.
+ """
+ Filters._configure(self)
+ self.filters = [self.inventory.bg,
+ self.inventory.add,
+ self.inventory.multiply]
+ return
+
+
+# ======================================================================
+# Factories
+
+def filters():
+ """
+ Factory for filters.
+ """
+ return OneFilters()
+
+
+# End of file
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_two.odb
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_two.odb 2007-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testgen1din2d_two.odb 2007-02-26 22:00:30 UTC (rev 6117)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+from pyre.components.Component import Component
+
+# ----------------------------------------------------------------------
+# TwoFilters class
+from spatialdata.spatialdb.generator.Filters import Filters
+class TwoFilters(Filters):
+ """
+ Python object acting as Filters component for value 'one' in testing
+ GenSimpleDBApp.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing Filters facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing Filter facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li \b bg Background filter
+ ## @li \b subtract Subtraction filter
+ ## @li \b divide Division filter
+
+ import pyre.inventory
+
+ from spatialdata.spatialdb.generator.Filter import Filter
+
+ bg = pyre.inventory.facility("bg", factory=Filter)
+ bg.meta['tip'] = "Background filter."
+
+ subtract = pyre.inventory.facility("subtract", factory=Filter)
+ subtract.meta['tip'] = "Subtraction filter."
+
+ divide = pyre.inventory.facility("divide", factory=Filter)
+ divide.meta['tip'] = "Division filter."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self):
+ """
+ Constructor.
+ """
+ Filters.__init__(self, name="onefilters")
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Setup members based on inventory.
+ """
+ Filters._configure(self)
+ self.filters = [self.inventory.bg,
+ self.inventory.subtract,
+ self.inventory.divide]
+ return
+
+
+# ======================================================================
+# Factories
+
+def filters():
+ """
+ Factory for filters.
+ """
+ return TwoFilters()
+
+
+# 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-02-26 18:30:58 UTC (rev 6116)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2007-02-26 22:00:30 UTC (rev 6117)
@@ -19,6 +19,12 @@
from TestSpatialDB import TestSpatialDB
suite.addTest(unittest.makeSuite(TestSpatialDB))
+ from TestSimpleIOAscii import TestSimpleIOAscii
+ suite.addTest(unittest.makeSuite(TestSimpleIOAscii))
+
+ from TestGenSimpleDBApp import TestGenSimpleDBApp
+ suite.addTest(unittest.makeSuite(TestGenSimpleDBApp))
+
return suite
def main():
@@ -28,7 +34,5 @@
if __name__ == '__main__':
main()
-# version
-__id__ = "$Id: testspatial.py,v 1.1 2005/05/25 18:43:08 baagaard Exp $"
# End of file
More information about the cig-commits
mailing list