Changeset 11121


Ignore:
Timestamp:
Mar 31, 2007 8:16:34 PM (10 years ago)
Author:
warmerdam
Message:

updated numpy testing

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  
    11#!/usr/bin/env python
    22###############################################################################
    3 # $Id: numpy_rw.py,v 1.4 2006/10/27 04:31:51 fwarmerdam Exp $
     3# $Id: numpy_rw.py 11114 2007-04-01 02:45:55Z warmerdam $
    44#
    55# Project:  GDAL/OGR Test Suite
     
    2828# DEALINGS IN THE SOFTWARE.
    2929###############################################################################
    30 #
    31 #  $Log: numpy_rw.py,v $
    32 #  Revision 1.4  2006/10/27 04:31:51  fwarmerdam
    33 #  corrected licenses
    34 #
    35 #  Revision 1.3  2006/04/28 03:40:05  fwarmerdam
    36 #  Just skip if we can't import gdalnumeric.
    37 #
    38 #  Revision 1.2  2004/11/11 04:21:44  fwarmerdam
    39 #  converted to unix text format, added allregister
    40 #
    41 #  Revision 1.1  2003/09/26 15:55:18  warmerda
    42 #  New
    43 #
    44 #
    4530
    4631import os
     
    5944    gdaltest.numpy_drv = None
    6045    try:
    61         import Numeric
    6246        import gdalnumeric
    6347    except:
    6448        return 'skip'
    6549
    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
    6956
    7057    gdaltest.numpy_drv = gdal.GetDriverByName( 'NUMPY' )
     
    9279    ds = gdalnumeric.OpenArray( array )
    9380    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.' )
    9582        return 'fail'
    9683
     
    10390    return 'success'
    10491
     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'
    105156
    106157def numpy_rw_cleanup():
     
    112163    numpy_rw_1,
    113164    numpy_rw_2,
     165    numpy_rw_3,
     166    numpy_rw_4,
     167    numpy_rw_5,
    114168    numpy_rw_cleanup ]
    115169
Note: See TracChangeset for help on using the changeset viewer.