Changeset 11121
 Timestamp:
 Mar 31, 2007 8:16:34 PM (9 years ago)
 Location:
 branches/1.4/autotest/gcore
 Files:

 2 added
 1 deleted
 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/1.4/autotest/gcore/numpy_rw.py
r10613 r11121 1 1 #!/usr/bin/env python 2 2 ############################################################################### 3 # $Id: numpy_rw.py ,v 1.4 2006/10/27 04:31:51 fwarmerdam Exp$3 # $Id: numpy_rw.py 11114 20070401 02:45:55Z warmerdam $ 4 4 # 5 5 # Project: GDAL/OGR Test Suite … … 28 28 # DEALINGS IN THE SOFTWARE. 29 29 ############################################################################### 30 #31 # $Log: numpy_rw.py,v $32 # Revision 1.4 2006/10/27 04:31:51 fwarmerdam33 # corrected licenses34 #35 # Revision 1.3 2006/04/28 03:40:05 fwarmerdam36 # Just skip if we can't import gdalnumeric.37 #38 # Revision 1.2 2004/11/11 04:21:44 fwarmerdam39 # converted to unix text format, added allregister40 #41 # Revision 1.1 2003/09/26 15:55:18 warmerda42 # New43 #44 #45 30 46 31 import os … … 59 44 gdaltest.numpy_drv = None 60 45 try: 61 import Numeric62 46 import gdalnumeric 63 47 except: 64 48 return 'skip' 65 49 66 import _gdal 67 gdal.AllRegister() 68 _gdal.GDALRegister_NUMPY() 50 try: 51 import _gdal 52 _gdal.GDALRegister_NUMPY() # only needed for old style bindings. 53 gdal.AllRegister() 54 except: 55 pass 69 56 70 57 gdaltest.numpy_drv = gdal.GetDriverByName( 'NUMPY' ) … … 92 79 ds = gdalnumeric.OpenArray( array ) 93 80 if ds is None: 94 gdaltest.post_reason( 'Failed to open memory array as dataset.' )81 gdaltest.post_reason( 'Failed to open memory array as dataset.' ) 95 82 return 'fail' 96 83 … … 103 90 return 'success' 104 91 92 ############################################################################### 93 # Test loading complex data. 94 95 def numpy_rw_3(): 96 97 if gdaltest.numpy_drv is None: 98 return 'skip' 99 100 ds = gdal.Open( 'data/cint_sar.tif' ) 101 array = ds.ReadAsArray() 102 103 if array[2][3] != 11616j: 104 print array[0][2][3] 105 gdaltest.post_reason( 'complex value read improperly.' ) 106 return 'fail' 107 108 return 'success' 109 110 ############################################################################### 111 # Test a band read with downsampling. 112 113 def numpy_rw_4(): 114 115 if gdaltest.numpy_drv is None: 116 return 'skip' 117 118 ds = gdal.Open( 'data/byte.tif' ) 119 array = ds.GetRasterBand(1).ReadAsArray(0,0,20,20,5,5) 120 121 if array[2][3] != 123: 122 print array[2][3] 123 gdaltest.post_reason( 'Read wrong value  perhaps downsampling algorithm has changed subtly?' ) 124 return 'fail' 125 126 return 'success' 127 128 ############################################################################### 129 # Test reading a multiband file. 130 131 def numpy_rw_5(): 132 133 if gdaltest.numpy_drv is None: 134 return 'skip' 135 136 import gdalnumeric 137 138 array = gdalnumeric.LoadFile('data/rgbsmall.tif',35,21,1,1) 139 140 if array[0][0][0] != 78: 141 print array 142 gdaltest.post_reason( 'value read improperly.' ) 143 return 'fail' 144 145 if array[1][0][0] != 117: 146 print array 147 gdaltest.post_reason( 'value read improperly.' ) 148 return 'fail' 149 150 if array[2][0][0] != 24: 151 print array 152 gdaltest.post_reason( 'value read improperly.' ) 153 return 'fail' 154 155 return 'success' 105 156 106 157 def numpy_rw_cleanup(): … … 112 163 numpy_rw_1, 113 164 numpy_rw_2, 165 numpy_rw_3, 166 numpy_rw_4, 167 numpy_rw_5, 114 168 numpy_rw_cleanup ] 115 169
Note: See TracChangeset
for help on using the changeset viewer.