Changeset 11114

Show
Ignore:
Timestamp:
03/31/07 22:45:55 (2 years ago)
Author:
warmerdam
Message:

Merged support for NG bindings for unified test script.
Added additional tests for complex data, and using AsArray? methods on
band and dataset.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/gcore/numpy_rw.py

    r11065 r11114  
    4444    gdaltest.numpy_drv = None 
    4545    try: 
    46         import Numeric 
    4746        import gdalnumeric 
    4847    except: 
    4948        return 'skip' 
    5049 
    51     import _gdal 
    52     gdal.AllRegister() 
    53     _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 
    5456 
    5557    gdaltest.numpy_drv = gdal.GetDriverByName( 'NUMPY' ) 
     
    7779    ds = gdalnumeric.OpenArray( array ) 
    7880    if ds is None: 
    79       gdaltest.post_reason( 'Failed to open memory array as dataset.' ) 
     81      gdaltest.post_reason( 'Failed to open memory array as dataset.' ) 
    8082        return 'fail' 
    8183 
     
    8890    return 'success' 
    8991 
     92############################################################################### 
     93# Test loading complex data. 
     94 
     95def 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] != 116-16j: 
     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 
     113def 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 multi-band file. 
     130 
     131def 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' 
    90156 
    91157def numpy_rw_cleanup(): 
     
    97163    numpy_rw_1, 
    98164    numpy_rw_2, 
     165    numpy_rw_3, 
     166    numpy_rw_4, 
     167    numpy_rw_5, 
    99168    numpy_rw_cleanup ] 
    100169