[cig-commits] r15444 - cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator
brad at geodynamics.org
brad at geodynamics.org
Wed Jul 8 14:50:03 PDT 2009
Author: brad
Date: 2009-07-08 14:50:03 -0700 (Wed, 08 Jul 2009)
New Revision: 15444
Modified:
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Shaper.py
Log:
Refactored apply() into initialize(), apply(), and finalize() to allow precomputing values.
Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Shaper.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Shaper.py 2009-07-08 20:24:00 UTC (rev 15443)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/Shaper.py 2009-07-08 21:50:03 UTC (rev 15444)
@@ -76,7 +76,7 @@
return
- def initialize(self):
+ def initialize(self, locs, cs):
"""
Initialize shaper.
"""
@@ -85,23 +85,8 @@
"Name of value in spatial database must be set for shaper '%s'." %\
self.name
self.db.open()
- return
-
- def finalize(self):
- """
- Cleanup shaper.
- """
- self.db.close()
- return
-
-
- def apply(self, value, locs, cs):
- """
- Shape value.
- """
nlocs = locs.shape[0]
-
self.db.queryVals([self.dbValue])
v = numpy.zeros( (1,), dtype=numpy.float64)
vals = numpy.zeros( (nlocs, 1), dtype=numpy.float64)
@@ -113,14 +98,32 @@
mask[err[:] != 0] = 1.0
vals[:] += default[:]*mask[:]
+ self.db.close()
+
+ self.values = vals
+ return
+
+
+ def finalize(self):
+ """
+ Deallocate values.
+ """
+ del self.values
+ return
+
+
+ def apply(self, value):
+ """
+ Shape value.
+ """
if self.operand == "add":
- value[:] += vals[:]
+ value[:] += self.values[:]
elif self.operand == "subtract":
- value[:] -= vals[:]
+ value[:] -= self.values[:]
elif self.operand == "multiply":
- value[:] *= vals[:]
+ value[:] *= self.values[:]
elif self.operand == "divide":
- value[:] /= vals[:]
+ value[:] /= self.values[:]
else:
raise ValueError, \
"Unknown operand setting '%s'." % self.operand
More information about the CIG-COMMITS
mailing list