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

brad at geodynamics.org brad at geodynamics.org
Fri Dec 1 11:25:08 PST 2006


Author: brad
Date: 2006-12-01 11:25:07 -0800 (Fri, 01 Dec 2006)
New Revision: 5404

Modified:
   cs/spatialdata-0.1/trunk/modulesrc/utils/simplearray.pyxe
   cs/spatialdata-0.1/trunk/tests/pytests/geocoords/TestConverter.py
   cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py
   cs/spatialdata-0.1/trunk/tests/pytests/utils/TestChangeCoordSys.py
   cs/spatialdata-0.1/trunk/tests/pytests/utils/TestConvertApp.py
   cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py
   cs/spatialdata-0.1/trunk/tests/pytests/utils/TestSimpleArray.py
Log:
Updated array interface stuff in utils module to accommodate changes to array interface in numpy (version < 1.0 to version 1.0).

Modified: cs/spatialdata-0.1/trunk/modulesrc/utils/simplearray.pyxe
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/utils/simplearray.pyxe	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/modulesrc/utils/simplearray.pyxe	2006-12-01 19:25:07 UTC (rev 5404)
@@ -310,7 +310,22 @@
     """Constuctor."""
     SimpleArray.__init__(self)
 
-    shape = pyarray.__array_shape__
+
+    # Array interface version 2 (numpy < 1.0?)
+    #shape = pyarray.__array_shape__ # Array interface version 2
+    #typestring = pyarray.__array_typestr__
+    #strides = pyarray.__array_strides__
+    #address = int(pyarray.__array_data__[0], 16)
+    #readonly = pyarray.__array_data__[1]
+
+    # Array interface version ? (numpy >= 1.0)
+    pyarrayInfo = pyarray.__array_interface__
+    shape = pyarrayInfo['shape']
+    typestring = pyarrayInfo['typestr']
+    strides = pyarrayInfo['strides']
+    address = int(pyarrayInfo['data'][0])
+    readonly = pyarrayInfo['data'][1]
+
     nd = len(shape)
     self.nd = nd
 
@@ -318,10 +333,8 @@
     for i in range(nd):
       self.shape[i] = shape[i]
 
-    typestring = pyarray.__array_typestr__
     self._typeinfo = self._sizeandtype(typestring[1:])
 
-    strides = pyarray.__array_strides__
     if strides:
       self.strides = [0]*nd
       for i from 0 <= i < nd:
@@ -330,10 +343,8 @@
       self._calcStrides()
 
     cdef void* data
-    address = int(pyarray.__array_data__[0], 16)
     data = <void*> PyInt_AsLong(address)
 
-    readonly = pyarray.__array_data__[1]
     flags = 0
     if '|' == typestring[0]:
       flags = flags | NOTSWAPPED

Modified: cs/spatialdata-0.1/trunk/tests/pytests/geocoords/TestConverter.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/geocoords/TestConverter.py	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/tests/pytests/geocoords/TestConverter.py	2006-12-01 19:25:07 UTC (rev 5404)
@@ -12,24 +12,24 @@
 
 import unittest
 
-import numpy as numeric
+import numpy
 
-lonlatNAD27ElevVals = numeric.array([
+lonlatNAD27ElevVals = numpy.array([
   [ -1.150000000000e+02,  3.900000000000e+01,  1.200000000000e+01],
   [ -1.203425320000e+02,  4.323423000000e+01,  1.010000000000e+01],
   [ -1.213425320000e+02,  4.523423000000e+01,  3.600000000000e+00],
   [ -1.153425320000e+02,  3.623423000000e+01,  7.200000000000e+00],
   [ -1.103425320000e+02,  3.923423000000e+01,  1.233000000000e+02],
   [ -1.073425320000e+02,  3.323423000000e+01,  3.460000000000e+01] ],
-                                    numeric.Float64)
-xyzLocalVals = numeric.array([
+                                    numpy.float64)
+xyzLocalVals = numpy.array([
   [ -1.284640403035e+06,  1.064304545254e+05, -1.314223692642e+05],
   [ -1.617989794934e+06,  6.524818198322e+05, -2.429529282853e+05],
   [ -1.637488936891e+06,  8.852730256818e+05, -2.774331803783e+05],
   [ -1.362847273202e+06, -1.913287267443e+05, -1.500646063011e+05],
   [ -8.881745585536e+05,  7.658679833419e+04, -6.239199171253e+04],
   [ -6.825105927499e+05, -6.111332573069e+05, -6.615476872030e+04] ],
-                             numeric.Float64)
+                             numpy.float64)
 
 class TestConverter(unittest.TestCase):
 
@@ -56,11 +56,11 @@
     from spatialdata.geocoords.Converter import convert
     coordsXYZ = lonlatNAD27ElevVals
     convert(coordsXYZ, csLocal, csNAD27)
-    xyzLocalValsT = numeric.array(coordsXYZ)
+    xyzLocalValsT = numpy.array(coordsXYZ)
 
     self.assertEqual(len(xyzLocalVals.shape), len(xyzLocalValsT.shape))
-    for (xyz, xyzT) in zip(numeric.reshape(xyzLocalVals,-1),
-                           numeric.reshape(xyzLocalValsT, -1)):
+    for (xyz, xyzT) in zip(numpy.reshape(xyzLocalVals,-1),
+                           numpy.reshape(xyzLocalValsT, -1)):
       self.assertAlmostEqual(1.0, xyz/xyzT, 6)
         
     return

Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSpatialDB.py	2006-12-01 19:25:07 UTC (rev 5404)
@@ -38,11 +38,11 @@
 
     locs = numpy.array( [[1.0, 2.0, 3.0],
                          [5.6, 4.2, 8.6]],
-                        numpy.Float64)
+                        numpy.float64)
     cs = CSCart()
     cs.toMeters = 1.0
     
-    valsE = numpy.array( [[4.7, 6.3]]*2, numpy.Float64)
+    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))
     for dE, d in zip(valsE.shape, vals.shape):

Modified: cs/spatialdata-0.1/trunk/tests/pytests/utils/TestChangeCoordSys.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/utils/TestChangeCoordSys.py	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/tests/pytests/utils/TestChangeCoordSys.py	2006-12-01 19:25:07 UTC (rev 5404)
@@ -21,7 +21,7 @@
   [ -1.153425320000e+02,  3.623423000000e+01,  7.200000000000e+00],
   [ -1.103425320000e+02,  3.923423000000e+01,  1.233000000000e+02],
   [ -1.073425320000e+02,  3.323423000000e+01,  3.460000000000e+01] ],
-                                  numpy.Float64)
+                                  numpy.float64)
 xyzLocalVals = numpy.array([
   [ -1.284640403035e+06,  1.064304545254e+05, -1.314223692642e+05],
   [ -1.617989794934e+06,  6.524818198322e+05, -2.429529282853e+05],
@@ -29,7 +29,7 @@
   [ -1.362847273202e+06, -1.913287267443e+05, -1.500646063011e+05],
   [ -8.881745585536e+05,  7.658679833419e+04, -6.239199171253e+04],
   [ -6.825105927499e+05, -6.111332573069e+05, -6.615476872030e+04] ],
-                           numpy.Float64)
+                           numpy.float64)
 
 
 class TestChangeCoordSys(unittest.TestCase):

Modified: cs/spatialdata-0.1/trunk/tests/pytests/utils/TestConvertApp.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/utils/TestConvertApp.py	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/tests/pytests/utils/TestConvertApp.py	2006-12-01 19:25:07 UTC (rev 5404)
@@ -21,7 +21,7 @@
   [ -1.153425320000e+02,  3.623423000000e+01,  7.200000000000e+00],
   [ -1.103425320000e+02,  3.923423000000e+01,  1.233000000000e+02],
   [ -1.073425320000e+02,  3.323423000000e+01,  3.460000000000e+01] ],
-                                  numpy.Float64)
+                                  numpy.float64)
 xyzLocalVals = numpy.array([
   [ -1.284640403035e+06,  1.064304545254e+05, -1.314223692642e+05],
   [ -1.617989794934e+06,  6.524818198322e+05, -2.429529282853e+05],
@@ -29,7 +29,7 @@
   [ -1.362847273202e+06, -1.913287267443e+05, -1.500646063011e+05],
   [ -8.881745585536e+05,  7.658679833419e+04, -6.239199171253e+04],
   [ -6.825105927499e+05, -6.111332573069e+05, -6.615476872030e+04] ],
-                           numpy.Float64)
+                           numpy.float64)
 
 class TestConvertApp(unittest.TestCase):
 

Modified: cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py	2006-12-01 19:25:07 UTC (rev 5404)
@@ -54,7 +54,7 @@
     pointsE = numpy.array([ [1.0, 2.0, 3.0],
                             [1.1, 2.1, 3.1],
                             [1.2, 2.2, 3.2] ],
-                          numpy.Float64)
+                          numpy.float64)
     filename = "tmp.txt"
     s = PointsStream()
     s.filename = filename

Modified: cs/spatialdata-0.1/trunk/tests/pytests/utils/TestSimpleArray.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/utils/TestSimpleArray.py	2006-12-01 04:40:37 UTC (rev 5403)
+++ cs/spatialdata-0.1/trunk/tests/pytests/utils/TestSimpleArray.py	2006-12-01 19:25:07 UTC (rev 5404)
@@ -20,7 +20,7 @@
 
   def test_frompy(self):
     vals = [1.1, 2.1, 3.1, 1.2, 2.2, 3.2]
-    x = numpy.array(vals, numpy.Float64)
+    x = numpy.array(vals, numpy.float64)
     y = simplearray.SimplePyArray(x)
     self.assertEqual(len(x.shape), y.nd)
     self.assertEqual(len(x.shape), len(y.shape))
@@ -32,7 +32,7 @@
 
     vals = [ [1, 2, 3],
              [4, 5, 6] ]
-    x = numpy.array(vals, numpy.Int32)
+    x = numpy.array(vals, numpy.int32)
     y = simplearray.SimplePyArray(x)
     self.assertEqual(len(x.shape), y.nd)
     self.assertEqual(len(x.shape), len(y.shape))
@@ -44,7 +44,7 @@
 
     vals = [ [ [1.1, 2.1, 3.1] ],
              [ [2.1, 2.2, 3.2] ] ]
-    x = numpy.array(vals, numpy.Float32)
+    x = numpy.array(vals, numpy.float32)
     y = simplearray.SimplePyArray(x)
     self.assertEqual(len(x.shape), y.nd)
     self.assertEqual(len(x.shape), len(y.shape))
@@ -59,7 +59,7 @@
   def test_fromcpp(self):
     vals = [ [1.1, 2.1, 3.1],
              [1.2, 2.2, 3.2] ]
-    x = numpy.array(vals, numpy.Float64)
+    x = numpy.array(vals, numpy.float64)
     import spatialdata.utils.testcpp as testcpp
     y = testcpp.cpparray()
     self.assertEqual(len(x.shape), y.nd)
@@ -76,7 +76,7 @@
     vals = [ [1.1, 2.1],
              [1.2, 2.2],
              [1.3, 2.3] ]
-    x = numpy.array(vals, numpy.Float64)
+    x = numpy.array(vals, numpy.float64)
     import spatialdata.utils.testcpp as testcpp
     try:
       testcpp.test(simplearray.SimplePyArray(x))



More information about the cig-commits mailing list