Changeset 6153


Ignore:
Timestamp:
Jan 13, 2009, 2:49:15 PM (15 years ago)
Author:
rwilson
Message:

Change Numeric imports to general form - ready to change to NumPy?.

Location:
anuga_core/source/anuga/geospatial_data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r6086 r6153  
    99from warnings import warn
    1010from string import lower
    11 from Numeric import concatenate, array, Float, shape, reshape, ravel, take, \
    12                     size, shape
    1311from RandomArray import randint, seed, get_seed
    1412from copy import deepcopy
    1513from Scientific.IO.NetCDF import NetCDFFile
     14
     15import Numeric as num
     16
    1617from anuga.coordinate_transforms.lat_long_UTM_conversion import UTMtoLL
    1718from anuga.utilities.numerical_tools import ensure_numeric
     
    486487            zone2 = geo_ref2.get_zone()
    487488            geo_ref1.reconcile_zones(geo_ref2)
    488             new_points = concatenate((self.get_data_points(absolute=True),
    489                                       other.get_data_points(absolute=True)),
    490                                      axis = 0)
     489            new_points = num.concatenate((self.get_data_points(absolute=True),
     490                                          other.get_data_points(absolute=True)),
     491                                         axis = 0)
    491492
    492493            # Concatenate attributes if any
     
    504505                        attrib1 = self.attributes[x]
    505506                        attrib2 = other.attributes[x]
    506                         new_attributes[x] = concatenate((attrib1, attrib2))
     507                        new_attributes[x] = num.concatenate((attrib1, attrib2))
    507508                    else:
    508509                        msg = 'Geospatial data must have the same \n'
     
    660661        #FIXME: add the geo_reference to this
    661662        points = self.get_data_points()
    662         sampled_points = take(points, indices)
     663        sampled_points = num.take(points, indices)
    663664
    664665        attributes = self.get_all_attributes()
     
    667668        if attributes is not None:
    668669            for key, att in attributes.items():
    669                 sampled_attributes[key] = take(att, indices)
     670                sampled_attributes[key] = num.take(att, indices)
    670671
    671672        return Geospatial_data(sampled_points, sampled_attributes)
     
    706707        if verbose: print "make unique random number list and get indices"
    707708
    708         total=array(range(self_size))
     709        total=num.array(range(self_size))
    709710        total_list = total.tolist()
    710711
     
    959960            raise ValueError, msg
    960961        lats_longs = ensure_numeric(data_points)
    961         latitudes = ravel(lats_longs[:,0:1])
    962         longitudes = ravel(lats_longs[:,1:])
     962        latitudes = num.ravel(lats_longs[:,0:1])
     963        longitudes = num.ravel(lats_longs[:,1:])
    963964
    964965    if latitudes is None and longitudes is None:
     
    10041005    fid = NetCDFFile(file_name, netcdf_mode_r)
    10051006
    1006     pointlist = array(fid.variables['points'])
     1007    pointlist = num.array(fid.variables['points'])
    10071008    keys = fid.variables.keys()
    10081009
     
    10201021        if verbose: print "reading attribute '%s'" % key
    10211022
    1022         attributes[key] = array(fid.variables[key])
     1023        attributes[key] = num.array(fid.variables[key])
    10231024
    10241025    try:
     
    11381139                      "There might be a problem with the file header."
    11391140                raise SyntaxError, msg
    1140             for i,num in enumerate(numbers):
    1141                 num.strip()
    1142                 if num != '\n' and num != '':
    1143                     #attributes.append(float(num))
    1144                     att_dict.setdefault(header[i],[]).append(float(num))
     1141            for i,n in enumerate(numbers):
     1142                n.strip()
     1143                if n != '\n' and n != '':
     1144                    #attributes.append(float(n))
     1145                    att_dict.setdefault(header[i],[]).append(float(n))
    11451146        except ValueError:
    11461147            raise SyntaxError
     
    11491150        raise StopIteration
    11501151
    1151     pointlist = array(points).astype(Float)
     1152    pointlist = num.array(points).astype(num.Float)
    11521153    for key in att_dict.keys():
    1153         att_dict[key] = array(att_dict[key]).astype(Float)
     1154        att_dict[key] = num.array(att_dict[key]).astype(num.Float)
    11541155
    11551156    # Do stuff here so the info is in lat's and longs
     
    11601161       and (y_header == 'lon' or  y_header == 'lat'):
    11611162        if x_header == 'lon':
    1162             longitudes = ravel(pointlist[:,0:1])
    1163             latitudes = ravel(pointlist[:,1:])
     1163            longitudes = num.ravel(pointlist[:,0:1])
     1164            latitudes = num.ravel(pointlist[:,1:])
    11641165        else:
    1165             latitudes = ravel(pointlist[:,0:1])
    1166             longitudes = ravel(pointlist[:,1:])
     1166            latitudes = num.ravel(pointlist[:,0:1])
     1167            longitudes = num.ravel(pointlist[:,1:])
    11671168
    11681169        pointlist, geo_ref = _set_using_lat_long(latitudes,
     
    12141215    """
    12151216
    1216     pointlist = array(fid.variables['points'][start_row:fin_row])
     1217    pointlist = num.array(fid.variables['points'][start_row:fin_row])
    12171218
    12181219    attributes = {}
    12191220    for key in keys:
    1220         attributes[key] = array(fid.variables[key][start_row:fin_row])
     1221        attributes[key] = num.array(fid.variables[key][start_row:fin_row])
    12211222
    12221223    return pointlist, attributes
     
    12661267
    12671268    # Variable definition
    1268     outfile.createVariable('points', Float, ('number_of_points',
    1269                                              'number_of_dimensions'))
     1269    outfile.createVariable('points', num.Float, ('number_of_points',
     1270                                                 'number_of_dimensions'))
    12701271
    12711272    #create variables
     
    12741275    if write_attributes is not None:
    12751276        for key in write_attributes.keys():
    1276             outfile.createVariable(key, Float, ('number_of_points',))
     1277            outfile.createVariable(key, num.Float, ('number_of_points',))
    12771278            outfile.variables[key][:] = write_attributes[key] #.astype(Float32)
    12781279
     
    13601361# @return ??
    13611362def _point_atts2array(point_atts):
    1362     point_atts['pointlist'] = array(point_atts['pointlist']).astype(Float)
     1363    point_atts['pointlist'] = num.array(point_atts['pointlist']).astype(num.Float)
    13631364
    13641365    for key in point_atts['attributelist'].keys():
    13651366        point_atts['attributelist'][key] = \
    1366                 array(point_atts['attributelist'][key]).astype(Float)
     1367                num.array(point_atts['attributelist'][key]).astype(num.Float)
    13671368
    13681369    return point_atts
     
    14691470        assert geo_reference == None, msg
    14701471    else:
    1471         points = ensure_numeric(points, Float)
     1472        points = ensure_numeric(points, num.Float)
    14721473
    14731474    # Sort of geo_reference and convert points
     
    15131514    else:
    15141515        # List or numeric array of absolute points
    1515         points = ensure_numeric(points, Float)
     1516        points = ensure_numeric(points, num.Float)
    15161517
    15171518    # Sort out geo reference
     
    16091610    from anuga.pmesh.mesh_interface import create_mesh_from_regions
    16101611    from anuga.utilities.numerical_tools import cov
    1611     from Numeric import array, resize,shape,Float,zeros,take,argsort,argmin
    16121612    from anuga.utilities.polygon import is_inside_polygon
    16131613    from anuga.fit_interpolate.benchmark_least_squares import mem_usage
     
    16711671    #4 onwards is the elevation_predicted using the alpha, which will
    16721672    #be compared later against the real removed data
    1673     data = array([], typecode=Float)
    1674 
    1675     data=resize(data, (len(points), 3+len(alphas)))
     1673    data = num.array([], typecode=num.Float)
     1674
     1675    data=num.resize(data, (len(points), 3+len(alphas)))
    16761676
    16771677    #gets relative point from sample
     
    16811681    data[:,2] = elevation_sample
    16821682
    1683     normal_cov=array(zeros([len(alphas), 2]), typecode=Float)
     1683    normal_cov=num.array(num.zeros([len(alphas), 2]), typecode=num.Float)
    16841684
    16851685    if verbose: print 'Setup computational domains with different alphas'
     
    17201720
    17211721    normal_cov0 = normal_cov[:,0]
    1722     normal_cov_new = take(normal_cov, argsort(normal_cov0))
     1722    normal_cov_new = num.take(normal_cov, num.argsort(normal_cov0))
    17231723
    17241724    if plot_name is not None:
     
    17381738                  % (normal_cov[i][0], normal_cov[i][1])
    17391739        print '\n Optimal alpha is: %s ' \
    1740               % normal_cov_new[(argmin(normal_cov_new, axis=0))[1], 0]
     1740              % normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1], 0]
    17411741
    17421742    # covariance and optimal alpha
    17431743    return (min(normal_cov_new[:,1]),
    1744             normal_cov_new[(argmin(normal_cov_new,axis=0))[1],0])
     1744            normal_cov_new[(num.argmin(normal_cov_new,axis=0))[1],0])
    17451745
    17461746
     
    18171817    from anuga.pmesh.mesh_interface import create_mesh_from_regions
    18181818    from anuga.utilities.numerical_tools import cov
    1819     from Numeric import array, resize,shape,Float,zeros,take,argsort,argmin
    18201819    from anuga.utilities.polygon import is_inside_polygon
    18211820    from anuga.fit_interpolate.benchmark_least_squares import mem_usage
     
    19061905    #4 onwards is the elevation_predicted using the alpha, which will
    19071906    #be compared later against the real removed data
    1908     data = array([], typecode=Float)
    1909 
    1910     data = resize(data, (len(points), 3+len(alphas)))
     1907    data = num.array([], typecode=num.Float)
     1908
     1909    data = num.resize(data, (len(points), 3+len(alphas)))
    19111910
    19121911    #gets relative point from sample
     
    19161915    data[:,2] = elevation_sample
    19171916
    1918     normal_cov = array(zeros([len(alphas), 2]), typecode=Float)
     1917    normal_cov = num.array(num.zeros([len(alphas), 2]), typecode=num.Float)
    19191918
    19201919    if verbose:
     
    19401939
    19411940    normal_cov0 = normal_cov[:,0]
    1942     normal_cov_new = take(normal_cov, argsort(normal_cov0))
     1941    normal_cov_new = num.take(normal_cov, num.argsort(normal_cov0))
    19431942
    19441943    if plot_name is not None:
     
    19521951
    19531952    return (min(normal_cov_new[:,1]),
    1954             normal_cov_new[(argmin(normal_cov_new, axis=0))[1],0])
     1953            normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1],0])
    19551954
    19561955
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r6086 r6153  
    44import unittest
    55import os
    6 from Numeric import zeros, array, allclose, concatenate,sort
    76from math import sqrt, pi
    87import tempfile
    98from sets import ImmutableSet
     9
     10import Numeric as num
    1011
    1112from anuga.geospatial_data.geospatial_data import *
     
    3132        G = Geospatial_data(points)
    3233
    33         assert allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]])
     34        assert num.allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]])
    3435
    3536        # Check __repr__
     
    4243
    4344        #Check getter
    44         assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3]])
     45        assert num.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3]])
    4546       
    4647        #Check defaults
     
    5758        G = Geospatial_data(points, attributes)       
    5859        assert G.attributes.keys()[0] == DEFAULT_ATTRIBUTE
    59         assert allclose(G.attributes.values()[0], [2, 4])
     60        assert num.allclose(G.attributes.values()[0], [2, 4])
    6061       
    6162
     
    8182
    8283        P = G.get_data_points(absolute=False)
    83         assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
     84        assert num.allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
    8485
    8586        P = G.get_data_points(absolute=True)
    86         assert allclose(P, [[101.0, 202.1], [103.0, 205.3]])       
     87        assert num.allclose(P, [[101.0, 202.1], [103.0, 205.3]])       
    8788
    8889        V = G.get_attributes() #Simply get them
    89         assert allclose(V, [2, 4])
     90        assert num.allclose(V, [2, 4])
    9091
    9192        V = G.get_attributes(DEFAULT_ATTRIBUTE) #Get by name
    92         assert allclose(V, [2, 4])
     93        assert num.allclose(V, [2, 4])
    9394
    9495    def test_get_attributes_2(self):
     
    105106
    106107        P = G.get_data_points(absolute=False)
    107         assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
     108        assert num.allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
    108109       
    109110        V = G.get_attributes() #Get default attribute
    110         assert allclose(V, [2, 4])
     111        assert num.allclose(V, [2, 4])
    111112
    112113        V = G.get_attributes('a0') #Get by name
    113         assert allclose(V, [0, 0])
     114        assert num.allclose(V, [0, 0])
    114115
    115116        V = G.get_attributes('a1') #Get by name
    116         assert allclose(V, [2, 4])
     117        assert num.allclose(V, [2, 4])
    117118
    118119        V = G.get_attributes('a2') #Get by name
    119         assert allclose(V, [79.4, -7])
     120        assert num.allclose(V, [79.4, -7])
    120121
    121122        try:
     
    137138        results = spatial.get_data_points(absolute=False)
    138139       
    139         assert allclose(results, points_rel)
     140        assert num.allclose(results, points_rel)
    140141       
    141142        x_p = -1770
     
    146147                  ( geo_reference=geo_ref)
    147148       
    148         assert allclose(results, points_rel)
     149        assert num.allclose(results, points_rel)
    149150
    150151 
     
    165166        #print "test_get_data_points_lat_long - results", results
    166167        #print "points_Lat_long",points_Lat_long
    167         assert allclose(results, points_Lat_long)
     168        assert num.allclose(results, points_Lat_long)
    168169     
    169170    def test_get_data_points_lat_longII(self):
     
    179180        #print "seg_lat_long", seg_lat_long [0][0]
    180181        #print "lat_result",lat_result
    181         assert allclose(seg_lat_long[0][0], lat_result)#lat
    182         assert allclose(seg_lat_long[0][1], long_result)#long
     182        assert num.allclose(seg_lat_long[0][0], lat_result)#lat
     183        assert num.allclose(seg_lat_long[0][1], long_result)#long
    183184
    184185
     
    200201        #print "seg_lat_long", seg_lat_long [0]
    201202        #print "lat_result",lat_result
    202         assert allclose(seg_lat_long[0][0], lat_result)#lat
    203         assert allclose(seg_lat_long[0][1], long_result)#long
     203        assert num.allclose(seg_lat_long[0][0], lat_result)#lat
     204        assert num.allclose(seg_lat_long[0][1], long_result)#long
    204205
    205206
     
    220221        # Create without geo_ref properly set
    221222        G = Geospatial_data(points_rel)       
    222         assert not allclose(points_ab, G.get_data_points(absolute=True))
     223        assert not num.allclose(points_ab, G.get_data_points(absolute=True))
    223224       
    224225        # Create the way it should be
    225226        G = Geospatial_data(points_rel, geo_reference=geo_ref)
    226         assert allclose(points_ab, G.get_data_points(absolute=True))
     227        assert num.allclose(points_ab, G.get_data_points(absolute=True))
    227228       
    228229        # Change georeference and check that absolute values are unchanged.
     
    231232        new_geo_ref = Geo_reference(56, x_p, y_p)
    232233        G.set_geo_reference(new_geo_ref)
    233         assert allclose(points_ab, G.get_data_points(absolute=True))
     234        assert num.allclose(points_ab, G.get_data_points(absolute=True))
    234235       
    235236
     
    254255        assert points_dict.has_key('geo_reference')
    255256
    256         assert allclose( points_dict['pointlist'], points )
     257        assert num.allclose( points_dict['pointlist'], points )
    257258
    258259        A = points_dict['attributelist']
     
    261262        assert A.has_key('a2')       
    262263
    263         assert allclose( A['a0'], [0, 0] )
    264         assert allclose( A['a1'], [2, 4] )       
    265         assert allclose( A['a2'], [79.4, -7] )
     264        assert num.allclose( A['a0'], [0, 0] )
     265        assert num.allclose( A['a1'], [2, 4] )       
     266        assert num.allclose( A['a2'], [79.4, -7] )
    266267
    267268
     
    288289
    289290        P = G.get_data_points(absolute=False)
    290         assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
     291        assert num.allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
    291292       
    292293        #V = G.get_attribute_values() #Get default attribute
     
    294295
    295296        V = G.get_attributes('a0') #Get by name
    296         assert allclose(V, [0, 0])
     297        assert num.allclose(V, [0, 0])
    297298
    298299        V = G.get_attributes('a1') #Get by name
    299         assert allclose(V, [2, 4])
     300        assert num.allclose(V, [2, 4])
    300301
    301302        V = G.get_attributes('a2') #Get by name
    302         assert allclose(V, [79.4, -7])
     303        assert num.allclose(V, [79.4, -7])
    303304
    304305    def test_add(self):
     
    319320        assert G.attributes.has_key('depth')
    320321        assert G.attributes.has_key('elevation')
    321         assert allclose(G.attributes['depth'], [2, 4, 2, 4])
    322         assert allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1])
    323         assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],
    324                                               [1.0, 2.1], [3.0, 5.3]])
    325        
     322        assert num.allclose(G.attributes['depth'], [2, 4, 2, 4])
     323        assert num.allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1])
     324        assert num.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],
     325                                                  [1.0, 2.1], [3.0, 5.3]])
     326
    326327    def test_addII(self):
    327328        """ test the addition of two geospatical objects
     
    343344        assert G.attributes.has_key('depth')
    344345        assert G.attributes.keys(), ['depth']
    345         assert allclose(G.attributes['depth'], [2, 4, 200, 400])
    346         assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],
    347                                               [5.0, 2.1], [3.0, 50.3]])
     346        assert num.allclose(G.attributes['depth'], [2, 4, 200, 400])
     347        assert num.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],
     348                                                  [5.0, 2.1], [3.0, 50.3]])
    348349    def test_add_with_geo (self):
    349350        """
     
    367368        #Check that absolute values are as expected
    368369        P1 = G1.get_data_points(absolute=True)
    369         assert allclose(P1, [[2.0, 4.1], [4.0, 7.3]])
     370        assert num.allclose(P1, [[2.0, 4.1], [4.0, 7.3]])
    370371
    371372        P2 = G2.get_data_points(absolute=True)
    372         assert allclose(P2, [[5.1, 9.1], [6.1, 6.3]])       
     373        assert num.allclose(P2, [[5.1, 9.1], [6.1, 6.3]])       
    373374       
    374375        G = G1 + G2
    375376
    376377        # Check absoluteness
    377         assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    378         assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     378        assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     379        assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    379380
    380381        P = G.get_data_points(absolute=True)
     
    384385        #assert allclose(P_relative, P - [0.1, 2.0])
    385386
    386         assert allclose(P, concatenate( (P1,P2) ))
    387         assert allclose(P, [[2.0, 4.1], [4.0, 7.3],
    388                             [5.1, 9.1], [6.1, 6.3]])
     387        assert num.allclose(P, num.concatenate( (P1,P2) ))
     388        assert num.allclose(P, [[2.0, 4.1], [4.0, 7.3],
     389                                [5.1, 9.1], [6.1, 6.3]])
    389390       
    390391
     
    396397        Difference in Geo_reference resolved
    397398        """
    398         points1 = array([[2.0, 4.1], [4.0, 7.3]])
    399         points2 = array([[5.1, 9.1], [6.1, 6.3]])       
     399        points1 = num.array([[2.0, 4.1], [4.0, 7.3]])
     400        points2 = num.array([[5.1, 9.1], [6.1, 6.3]])       
    400401        attributes1 = [2, 4]
    401402        attributes2 = [5, 76]
     
    413414        #Check that absolute values are as expected
    414415        P1 = G1.get_data_points(absolute=True)
    415         assert allclose(P1, points1)
     416        assert num.allclose(P1, points1)
    416417
    417418        P1 = G1.get_data_points(absolute=False)
    418         assert allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()])       
     419        assert num.allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()])       
    419420
    420421        P2 = G2.get_data_points(absolute=True)
    421         assert allclose(P2, points2)
     422        assert num.allclose(P2, points2)
    422423
    423424        P2 = G2.get_data_points(absolute=False)
    424         assert allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()])               
     425        assert num.allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()])               
    425426       
    426427        G = G1 + G2
     
    435436        #assert allclose(P_relative, [[1.0, 2.1], [3.0, 5.3], [4.1, 7.1], [5.1, 4.3]])
    436437
    437         assert allclose(P, concatenate( (points1,points2) ))
     438        assert num.allclose(P, num.concatenate( (points1,points2) ))
    438439
    439440
     
    442443        """
    443444       
    444         points1 = array([[2.0, 4.1], [4.0, 7.3]])
    445         points2 = array([[5.1, 9.1], [6.1, 6.3]])       
     445        points1 = num.array([[2.0, 4.1], [4.0, 7.3]])
     446        points2 = num.array([[5.1, 9.1], [6.1, 6.3]])       
    446447
    447448        geo_ref1= Geo_reference(55, 1.0, 2.0)
     
    459460
    460461        G1 = Geospatial_data(points1, attributes1, geo_ref1)
    461         assert allclose(G1.get_geo_reference().get_xllcorner(), 1.0)
    462         assert allclose(G1.get_geo_reference().get_yllcorner(), 2.0)
     462        assert num.allclose(G1.get_geo_reference().get_xllcorner(), 1.0)
     463        assert num.allclose(G1.get_geo_reference().get_yllcorner(), 2.0)
    463464        assert G1.attributes.has_key('depth')
    464465        assert G1.attributes.has_key('elevation')
    465         assert allclose(G1.attributes['depth'], [2, 4.7])
    466         assert allclose(G1.attributes['elevation'], [6.1, 5])       
     466        assert num.allclose(G1.attributes['depth'], [2, 4.7])
     467        assert num.allclose(G1.attributes['elevation'], [6.1, 5])       
    467468       
    468469        G2 = Geospatial_data(points2, attributes2, geo_ref2)
    469         assert allclose(G2.get_geo_reference().get_xllcorner(), 0.1)
    470         assert allclose(G2.get_geo_reference().get_yllcorner(), 3.0)
     470        assert num.allclose(G2.get_geo_reference().get_xllcorner(), 0.1)
     471        assert num.allclose(G2.get_geo_reference().get_yllcorner(), 3.0)
    471472        assert G2.attributes.has_key('depth')
    472473        assert G2.attributes.has_key('elevation')
    473         assert allclose(G2.attributes['depth'], [-2.3, 4])
    474         assert allclose(G2.attributes['elevation'], [2.5, 1])       
     474        assert num.allclose(G2.attributes['depth'], [-2.3, 4])
     475        assert num.allclose(G2.attributes['elevation'], [2.5, 1])       
    475476
    476477        #Check that absolute values are as expected
    477478        P1 = G1.get_data_points(absolute=True)
    478         assert allclose(P1, [[3.0, 6.1], [5.0, 9.3]])
     479        assert num.allclose(P1, [[3.0, 6.1], [5.0, 9.3]])
    479480
    480481        P2 = G2.get_data_points(absolute=True)
    481         assert allclose(P2, [[5.2, 12.1], [6.2, 9.3]])       
     482        assert num.allclose(P2, [[5.2, 12.1], [6.2, 9.3]])       
    482483
    483484        # Normal add
     
    486487        assert G.attributes.has_key('depth')
    487488        assert G.attributes.has_key('elevation')
    488         assert allclose(G.attributes['depth'], [2, 4.7])
    489         assert allclose(G.attributes['elevation'], [6.1, 5])       
     489        assert num.allclose(G.attributes['depth'], [2, 4.7])
     490        assert num.allclose(G.attributes['elevation'], [6.1, 5])       
    490491
    491492        # Points are now absolute.
    492         assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    493         assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     493        assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     494        assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    494495        P = G.get_data_points(absolute=True)       
    495         assert allclose(P, [[3.0, 6.1], [5.0, 9.3]])
     496        assert num.allclose(P, [[3.0, 6.1], [5.0, 9.3]])
    496497
    497498
     
    499500        assert G.attributes.has_key('depth')
    500501        assert G.attributes.has_key('elevation')
    501         assert allclose(G.attributes['depth'], [-2.3, 4])
    502         assert allclose(G.attributes['elevation'], [2.5, 1])       
    503 
    504         assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    505         assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     502        assert num.allclose(G.attributes['depth'], [-2.3, 4])
     503        assert num.allclose(G.attributes['elevation'], [2.5, 1])       
     504
     505        assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     506        assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    506507        P = G.get_data_points(absolute=True)       
    507         assert allclose(P, [[5.2, 12.1], [6.2, 9.3]])
     508        assert num.allclose(P, [[5.2, 12.1], [6.2, 9.3]])
    508509       
    509510
     
    514515        assert G.attributes.has_key('depth')
    515516        assert G.attributes.has_key('elevation')
    516         assert allclose(G.attributes['depth'], [2, 4.7])
    517         assert allclose(G.attributes['elevation'], [6.1, 5])       
     517        assert num.allclose(G.attributes['depth'], [2, 4.7])
     518        assert num.allclose(G.attributes['elevation'], [6.1, 5])       
    518519
    519520        # Points are now absolute.
    520         assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    521         assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     521        assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     522        assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    522523        P = G.get_data_points(absolute=True)       
    523         assert allclose(P, [[3.0, 6.1], [5.0, 9.3]])       
     524        assert num.allclose(P, [[3.0, 6.1], [5.0, 9.3]])       
    524525
    525526
     
    527528        assert G.attributes.has_key('depth')
    528529        assert G.attributes.has_key('elevation')
    529         assert allclose(G.attributes['depth'], [-2.3, 4])
    530         assert allclose(G.attributes['elevation'], [2.5, 1])       
    531 
    532         assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    533         assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     530        assert num.allclose(G.attributes['depth'], [-2.3, 4])
     531        assert num.allclose(G.attributes['elevation'], [2.5, 1])       
     532
     533        assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     534        assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    534535        P = G.get_data_points(absolute=True)       
    535         assert allclose(P, [[5.2, 12.1], [6.2, 9.3]])
     536        assert num.allclose(P, [[5.2, 12.1], [6.2, 9.3]])
    536537
    537538       
     
    554555        # First try the unit square   
    555556        U = [[0,0], [1,0], [1,1], [0,1]]
    556         assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])
     557        assert num.allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])
    557558
    558559        # Then a more complex polygon
     
    561562        G = Geospatial_data(points)
    562563
    563         assert allclose(G.clip(polygon).get_data_points(),
     564        assert num.allclose(G.clip(polygon).get_data_points(),
    564565                        [[0.5, 0.5], [1, -0.5], [1.5, 0]])
    565566
     
    577578        attributes = [2, -4, 5, 76, -2, 0.1, 3]
    578579        att_dict = {'att1': attributes,
    579                     'att2': array(attributes)+1}
     580                    'att2': num.array(attributes)+1}
    580581       
    581582        G = Geospatial_data(points, att_dict)
     
    583584        # First try the unit square   
    584585        U = [[0,0], [1,0], [1,1], [0,1]]
    585         assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])
    586         assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])
    587         assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])               
     586        assert num.allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])
     587        assert num.allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])
     588        assert num.allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])               
    588589
    589590        # Then a more complex polygon
     
    595596        G = Geospatial_data(points, attributes)
    596597
    597         assert allclose(G.clip(polygon).get_data_points(),
     598        assert num.allclose(G.clip(polygon).get_data_points(),
    598599                        [[0.5, 0.5], [1, -0.5], [1.5, 0]])
    599         assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])
     600        assert num.allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])
    600601       
    601602
     
    613614        attributes = [2, -4, 5, 76, -2, 0.1, 3]
    614615        att_dict = {'att1': attributes,
    615                     'att2': array(attributes)+1}
     616                    'att2': num.array(attributes)+1}
    616617        G = Geospatial_data(points, att_dict)
    617618       
    618619        # First try the unit square   
    619620        U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]])
    620         assert allclose(G.clip(U).get_data_points(),
     621        assert num.allclose(G.clip(U).get_data_points(),
    621622                        [[0.2, 0.5], [0.4, 0.3], [0, 0]])
    622623
    623         assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])
    624         assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])                       
     624        assert num.allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])
     625        assert num.allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])                       
    625626       
    626627        # Then a more complex polygon
     
    631632       
    632633
    633         assert allclose(G.clip(polygon).get_data_points(),
    634                         [[0.5, 0.5], [1, -0.5], [1.5, 0]])
    635         assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])
     634        assert num.allclose(G.clip(polygon).get_data_points(),
     635                            [[0.5, 0.5], [1, -0.5], [1.5, 0]])
     636        assert num.allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])
    636637       
    637638
     
    651652        # First try the unit square   
    652653        U = [[0,0], [1,0], [1,1], [0,1]]
    653         assert allclose(G.clip_outside(U).get_data_points(),
    654                         [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]])
     654        assert num.allclose(G.clip_outside(U).get_data_points(),
     655                            [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]])
    655656        #print G.clip_outside(U).get_attributes()
    656         assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])       
     657        assert num.allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])       
    657658       
    658659
     
    663664        G = Geospatial_data(points, attributes)
    664665
    665         assert allclose(G.clip_outside(polygon).get_data_points(),
    666                         [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]])
    667         assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])               
     666        assert num.allclose(G.clip_outside(polygon).get_data_points(),
     667                            [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]])
     668        assert num.allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])               
    668669
    669670
     
    684685        # First try the unit square   
    685686        U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]])
    686         assert allclose(G.clip_outside(U).get_data_points(),
    687                         [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]])
    688         assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])       
     687        assert num.allclose(G.clip_outside(U).get_data_points(),
     688                            [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]])
     689        assert num.allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])       
    689690
    690691        # Then a more complex polygon
     
    696697       
    697698
    698         assert allclose(G.clip_outside(polygon).get_data_points(),
    699                         [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]])
    700         assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])
     699        assert num.allclose(G.clip_outside(polygon).get_data_points(),
     700                            [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]])
     701        assert num.allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])
    701702       
    702703
     
    719720        U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]])
    720721        G1 = G.clip(U)
    721         assert allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]])
    722         assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])
     722        assert num.allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]])
     723        assert num.allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])
    723724       
    724725        G2 = G.clip_outside(U)
    725         assert allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1],
    726                                               [3.0, 5.3], [2.4, 3.3]])
    727         assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])               
     726        assert num.allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1],
     727                                                  [3.0, 5.3], [2.4, 3.3]])
     728        assert num.allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])               
    728729
    729730       
     
    734735        new_attributes = [-4, 76, 0.1, 2, 5, -2, 3]                 
    735736       
    736         assert allclose((G1+G2).get_data_points(), new_points)
    737         assert allclose((G1+G2).get_attributes(), new_attributes)
     737        assert num.allclose((G1+G2).get_data_points(), new_points)
     738        assert num.allclose((G1+G2).get_attributes(), new_attributes)
    738739
    739740        G = G1+G2
     
    747748
    748749        # Check result
    749         assert allclose(G3.get_data_points(), new_points)       
    750         assert allclose(G3.get_attributes(), new_attributes)       
     750        assert num.allclose(G3.get_data_points(), new_points)       
     751        assert num.allclose(G3.get_attributes(), new_attributes)       
    751752       
    752753        os.remove(FN)
     
    769770        os.remove(fileName)
    770771#        print 'data', results.get_data_points()
    771         assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],
    772                                                     [1.0, 0.0]])
    773         assert allclose(results.get_attributes(attribute_name='elevation'),
    774                         [10.0, 0.0, 10.4])
    775         assert allclose(results.get_attributes(attribute_name='speed'),
    776                         [0.0, 10.0, 40.0])
     772        assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],
     773                                                        [1.0, 0.0]])
     774        assert num.allclose(results.get_attributes(attribute_name='elevation'),
     775                            [10.0, 0.0, 10.4])
     776        assert num.allclose(results.get_attributes(attribute_name='speed'),
     777                            [0.0, 10.0, 40.0])
    777778
    778779
     
    820821
    821822
    822         assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    823         assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
    824         assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
     823        assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     824        assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
     825        assert num.allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
    825826
    826827        # Blocking
     
    829830            geo_list.append(i)
    830831           
    831         assert allclose(geo_list[0].get_data_points(),
    832                         [[1.0, 0.0],[0.0, 1.0]])
    833 
    834         assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),
    835                         [10.0, 0.0])
    836         assert allclose(geo_list[1].get_data_points(),
    837                         [[1.0, 0.0]])       
    838         assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),
    839                         [10.4])
     832        assert num.allclose(geo_list[0].get_data_points(),
     833                            [[1.0, 0.0],[0.0, 1.0]])
     834
     835        assert num.allclose(geo_list[0].get_attributes(attribute_name='elevation'),
     836                            [10.0, 0.0])
     837        assert num.allclose(geo_list[1].get_data_points(),
     838                            [[1.0, 0.0]])       
     839        assert num.allclose(geo_list[1].get_attributes(attribute_name='elevation'),
     840                            [10.4])
    840841           
    841842        os.remove(fileName)         
     
    980981        results = Geospatial_data(pts_file, max_read_lines=2)
    981982
    982         assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],
    983                                                     [1.0, 0.0]])
    984         assert allclose(results.get_attributes(attribute_name='elevation'),
    985                         [10.0, 0.0, 10.4])
    986         assert allclose(results.get_attributes(attribute_name='speed'),
    987                         [0.0, 10.0, 40.0])
     983        assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],
     984                                                        [1.0, 0.0]])
     985        assert num.allclose(results.get_attributes(attribute_name='elevation'),
     986                            [10.0, 0.0, 10.4])
     987        assert num.allclose(results.get_attributes(attribute_name='speed'),
     988                            [0.0, 10.0, 40.0])
    988989
    989990        # Blocking
     
    991992        for i in results:
    992993            geo_list.append(i)
    993         assert allclose(geo_list[0].get_data_points(),
    994                         [[1.0, 0.0],[0.0, 1.0]])
    995         assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),
    996                         [10.0, 0.0])
    997         assert allclose(geo_list[1].get_data_points(),
    998                         [[1.0, 0.0]])       
    999         assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),
    1000                         [10.4])
     994        assert num.allclose(geo_list[0].get_data_points(),
     995                            [[1.0, 0.0],[0.0, 1.0]])
     996        assert num.allclose(geo_list[0].get_attributes(attribute_name='elevation'),
     997                            [10.0, 0.0])
     998        assert num.allclose(geo_list[1].get_data_points(),
     999                            [[1.0, 0.0]])       
     1000        assert num.allclose(geo_list[1].get_attributes(attribute_name='elevation'),
     1001                            [10.4])
    10011002           
    10021003        os.remove(fileName) 
     
    10691070        for i in results:
    10701071            geo_list.append(i)
    1071         assert allclose(geo_list[0].get_data_points(),
    1072                         [[1.0, 0.0],[0.0, 1.0]])
    1073         assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),
    1074                         [10.0, 0.0])
    1075         assert allclose(geo_list[1].get_data_points(),
    1076                         [[1.0, 0.0],[0.0, 1.0] ])       
    1077         assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),
    1078                         [10.0, 0.0])
     1072        assert num.allclose(geo_list[0].get_data_points(),
     1073                            [[1.0, 0.0],[0.0, 1.0]])
     1074        assert num.allclose(geo_list[0].get_attributes(attribute_name='elevation'),
     1075                            [10.0, 0.0])
     1076        assert num.allclose(geo_list[1].get_data_points(),
     1077                            [[1.0, 0.0],[0.0, 1.0] ])       
     1078        assert num.allclose(geo_list[1].get_attributes(attribute_name='elevation'),
     1079                            [10.0, 0.0])
    10791080           
    10801081        os.remove(fileName) 
     
    10851086    def test_new_export_pts_file(self):
    10861087        att_dict = {}
    1087         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1088         att_dict['elevation'] = array([10.1, 0.0, 10.4])
    1089         att_dict['brightness'] = array([10.0, 1.0, 10.4])
     1088        pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1089        att_dict['elevation'] = num.array([10.1, 0.0, 10.4])
     1090        att_dict['brightness'] = num.array([10.0, 1.0, 10.4])
    10901091       
    10911092        fileName = tempfile.mktemp(".pts")
     
    10991100        os.remove(fileName)
    11001101       
    1101         assert allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1102         assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])
     1102        assert num.allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1103        assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])
    11031104        answer = [10.0, 1.0, 10.4]
    1104         assert allclose(results.get_attributes(attribute_name='brightness'), answer)
     1105        assert num.allclose(results.get_attributes(attribute_name='brightness'), answer)
    11051106
    11061107    def test_new_export_absolute_pts_file(self):
    11071108        att_dict = {}
    1108         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1109         att_dict['elevation'] = array([10.1, 0.0, 10.4])
    1110         att_dict['brightness'] = array([10.0, 1.0, 10.4])
     1109        pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1110        att_dict['elevation'] = num.array([10.1, 0.0, 10.4])
     1111        att_dict['brightness'] = num.array([10.0, 1.0, 10.4])
    11111112        geo_ref = Geo_reference(50, 25, 55)
    11121113       
     
    11211122        os.remove(fileName)
    11221123       
    1123         assert allclose(results.get_data_points(), G.get_data_points(True))
    1124         assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])
     1124        assert num.allclose(results.get_data_points(), G.get_data_points(True))
     1125        assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])
    11251126        answer = [10.0, 1.0, 10.4]
    1126         assert allclose(results.get_attributes(attribute_name='brightness'), answer)
     1127        assert num.allclose(results.get_attributes(attribute_name='brightness'), answer)
    11271128
    11281129    def test_loadpts(self):
     
    11391140   
    11401141        # variable definitions
    1141         outfile.createVariable('points', Float, ('number_of_points',
    1142                                                  'number_of_dimensions'))
    1143         outfile.createVariable('elevation', Float, ('number_of_points',))
     1142        outfile.createVariable('points', num.Float, ('number_of_points',
     1143                                                     'number_of_dimensions'))
     1144        outfile.createVariable('elevation', num.Float, ('number_of_points',))
    11441145   
    11451146        # Get handles to the variables
     
    11591160        os.remove(fileName)
    11601161        answer =  [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]
    1161         assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1162         assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
     1162        assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1163        assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
    11631164       
    11641165    def test_writepts(self):
     
    11661167       
    11671168        att_dict = {}
    1168         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1169         att_dict['elevation'] = array([10.0, 0.0, 10.4])
    1170         att_dict['brightness'] = array([10.0, 0.0, 10.4])
     1169        pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1170        att_dict['elevation'] = num.array([10.0, 0.0, 10.4])
     1171        att_dict['brightness'] = num.array([10.0, 0.0, 10.4])
    11711172        geo_reference=Geo_reference(56,1.9,1.9)
    11721173
     
    11781179        os.remove(fileName)
    11791180
    1180         assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1181         assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
     1181        assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1182        assert num.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
    11821183        answer = [10.0, 0.0, 10.4]
    1183         assert allclose(results.get_attributes('brightness'), answer)
     1184        assert num.allclose(results.get_attributes('brightness'), answer)
    11841185        self.failUnless(geo_reference == geo_reference,
    11851186                         'test_writepts failed. Test geo_reference')
     
    11891190       
    11901191        att_dict = {}
    1191         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1192         att_dict['elevation'] = array([10.0, 0.0, 10.4])
    1193         att_dict['brightness'] = array([10.0, 0.0, 10.4])
     1192        pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1193        att_dict['elevation'] = num.array([10.0, 0.0, 10.4])
     1194        att_dict['brightness'] = num.array([10.0, 0.0, 10.4])
    11941195        geo_reference=Geo_reference(56,0,0)
    11951196        # Test txt format
     
    12001201        results = Geospatial_data(file_name=fileName)
    12011202        os.remove(fileName)
    1202         assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1203         assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
     1203        assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1204        assert num.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
    12041205        answer = [10.0, 0.0, 10.4]
    1205         assert allclose(results.get_attributes('brightness'), answer)
     1206        assert num.allclose(results.get_attributes('brightness'), answer)
    12061207       
    12071208 
     
    12101211       
    12111212        att_dict = {}
    1212         pointlist = array([[-21.5,114.5],[-21.6,114.5],[-21.7,114.5]])
    1213         att_dict['elevation'] = array([10.0, 0.0, 10.4])
    1214         att_dict['brightness'] = array([10.0, 0.0, 10.4])
     1213        pointlist = num.array([[-21.5,114.5],[-21.6,114.5],[-21.7,114.5]])
     1214        att_dict['elevation'] = num.array([10.0, 0.0, 10.4])
     1215        att_dict['brightness'] = num.array([10.0, 0.0, 10.4])
    12151216        # Test txt format
    12161217        fileName = tempfile.mktemp(".txt")
     
    12201221        results = Geospatial_data(file_name=fileName)
    12211222        os.remove(fileName)
    1222         assert allclose(results.get_data_points(False, as_lat_long=True),
     1223        assert num.allclose(results.get_data_points(False, as_lat_long=True),
    12231224                        pointlist)
    1224         assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
     1225        assert num.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
    12251226        answer = [10.0, 0.0, 10.4]
    1226         assert allclose(results.get_attributes('brightness'), answer)
     1227        assert num.allclose(results.get_attributes('brightness'), answer)
    12271228       
    12281229    def test_writepts_no_attributes(self):
     
    12311232       
    12321233        att_dict = {}
    1233         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1234        pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    12341235        geo_reference=Geo_reference(56,1.9,1.9)
    12351236
     
    12411242        os.remove(fileName)
    12421243
    1243         assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1244        assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    12441245        self.failUnless(geo_reference == geo_reference,
    12451246                         'test_writepts failed. Test geo_reference')
     
    12501251       
    12511252        att_dict = {}
    1252         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1253        pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    12531254        geo_reference=Geo_reference(56,0,0)
    12541255        # Test format
     
    12581259        results = Geospatial_data(file_name=fileName)
    12591260        os.remove(fileName)
    1260         assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1261        assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    12611262
    12621263         
     
    12961297   
    12971298        # variable definitions
    1298         outfile.createVariable('points', Float, ('number_of_points',
    1299                                                  'number_of_dimensions'))
    1300         outfile.createVariable('elevation', Float, ('number_of_points',))
     1299        outfile.createVariable('points', num.Float, ('number_of_points',
     1300                                                     'number_of_dimensions'))
     1301        outfile.createVariable('elevation', num.Float, ('number_of_points',))
    13011302   
    13021303        # Get handles to the variables
     
    13151316        G = Geospatial_data(file_name = FN)
    13161317
    1317         assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    1318         assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    1319 
    1320         assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1321         assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])
     1318        assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     1319        assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     1320
     1321        assert num.allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1322        assert num.allclose(G.get_attributes(), [10.0, 0.0, 10.4])
    13221323        os.remove(FN)
    13231324
     
    13431344   
    13441345        # variable definitions
    1345         outfile.createVariable('points', Float, ('number_of_points',
    1346                                                  'number_of_dimensions'))
    1347         outfile.createVariable('elevation', Float, ('number_of_points',))
     1346        outfile.createVariable('points', num.Float, ('number_of_points',
     1347                                                     'number_of_dimensions'))
     1348        outfile.createVariable('elevation', num.Float, ('number_of_points',))
    13481349   
    13491350        # Get handles to the variables
     
    13621363        G = Geospatial_data(file_name = FN)
    13631364
    1364         assert allclose(G.get_geo_reference().get_xllcorner(), xll)
    1365         assert allclose(G.get_geo_reference().get_yllcorner(), yll)
    1366 
    1367         assert allclose(G.get_data_points(), [[1.0+xll, 0.0+yll],
    1368                                               [0.0+xll, 1.0+yll],
    1369                                               [1.0+xll, 0.0+yll]])
    1370        
    1371         assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])
     1365        assert num.allclose(G.get_geo_reference().get_xllcorner(), xll)
     1366        assert num.allclose(G.get_geo_reference().get_yllcorner(), yll)
     1367
     1368        assert num.allclose(G.get_data_points(), [[1.0+xll, 0.0+yll],
     1369                                                  [0.0+xll, 1.0+yll],
     1370                                                  [1.0+xll, 0.0+yll]])
     1371       
     1372        assert num.allclose(G.get_attributes(), [10.0, 0.0, 10.4])
    13721373        os.remove(FN)
    13731374
     
    13801381        # create files
    13811382        att_dict1 = {}
    1382         pointlist1 = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1383         att_dict1['elevation'] = array([-10.0, 0.0, 10.4])
    1384         att_dict1['brightness'] = array([10.0, 0.0, 10.4])
     1383        pointlist1 = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1384        att_dict1['elevation'] = num.array([-10.0, 0.0, 10.4])
     1385        att_dict1['brightness'] = num.array([10.0, 0.0, 10.4])
    13851386        geo_reference1 = Geo_reference(56, 2.0, 1.0)
    13861387       
    13871388        att_dict2 = {}
    1388         pointlist2 = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])
    1389         att_dict2['elevation'] = array([1.0, 15.0, 1.4])
    1390         att_dict2['brightness'] = array([14.0, 1.0, -12.4])
     1389        pointlist2 = num.array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])
     1390        att_dict2['elevation'] = num.array([1.0, 15.0, 1.4])
     1391        att_dict2['brightness'] = num.array([14.0, 1.0, -12.4])
    13911392        geo_reference2 = Geo_reference(56, 1.0, 2.0)
    13921393
     
    14121413#        print'res', G.get_data_points()
    14131414#        print'res1', G.get_data_points(False)
    1414         assert allclose(G.get_data_points(),
    1415                         [[ 3.0, 1.0], [ 2.0, 2.0],
    1416                          [ 3.0, 1.0], [ 3.0, 3.0],
    1417                          [ 2.0, 4.0], [ 3.0, 3.0]])
     1415        assert num.allclose(G.get_data_points(),
     1416                            [[ 3.0, 1.0], [ 2.0, 2.0],
     1417                             [ 3.0, 1.0], [ 3.0, 3.0],
     1418                             [ 2.0, 4.0], [ 3.0, 3.0]])
    14181419                         
    1419         assert allclose(G.get_attributes(attribute_name='elevation'),
    1420                         [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4])
     1420        assert num.allclose(G.get_attributes(attribute_name='elevation'),
     1421                            [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4])
    14211422       
    14221423        answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4]
    1423         assert allclose(G.get_attributes(attribute_name='brightness'), answer)
     1424        assert num.allclose(G.get_attributes(attribute_name='brightness'), answer)
    14241425       
    14251426        self.failUnless(G.get_geo_reference() == geo_reference1,
     
    14351436        new_points = ensure_absolute(points)
    14361437       
    1437         assert allclose(new_points, points)
    1438 
    1439         points = array([[2.0, 0.0],[1.0, 1.0],
    1440                          [2.0, 0.0],[2.0, 2.0],
    1441                          [1.0, 3.0],[2.0, 2.0]])
     1438        assert num.allclose(new_points, points)
     1439
     1440        points = num.array([[2.0, 0.0],[1.0, 1.0],
     1441                            [2.0, 0.0],[2.0, 2.0],
     1442                            [1.0, 3.0],[2.0, 2.0]])
    14421443        new_points = ensure_absolute(points)
    14431444       
    1444         assert allclose(new_points, points)
    1445        
    1446         ab_points = array([[2.0, 0.0],[1.0, 1.0],
    1447                          [2.0, 0.0],[2.0, 2.0],
    1448                          [1.0, 3.0],[2.0, 2.0]])
     1445        assert num.allclose(new_points, points)
     1446       
     1447        ab_points = num.array([[2.0, 0.0],[1.0, 1.0],
     1448                               [2.0, 0.0],[2.0, 2.0],
     1449                               [1.0, 3.0],[2.0, 2.0]])
    14491450       
    14501451        mesh_origin = (56, 290000, 618000) #zone, easting, northing
    14511452
    1452         data_points = zeros((ab_points.shape), Float)
     1453        data_points = num.zeros((ab_points.shape), num.Float)
    14531454        #Shift datapoints according to new origins
    14541455        for k in range(len(ab_points)):
     
    14611462        #print "ab_points",ab_points
    14621463           
    1463         assert allclose(new_points, ab_points)
     1464        assert num.allclose(new_points, ab_points)
    14641465
    14651466        geo = Geo_reference(56,67,-56)
     
    14711472        #print "ab_points",ab_points
    14721473           
    1473         assert allclose(new_points, ab_points)
     1474        assert num.allclose(new_points, ab_points)
    14741475
    14751476
     
    14861487        #print "ab_points",ab_points
    14871488           
    1488         assert allclose(new_points, ab_points)
     1489        assert num.allclose(new_points, ab_points)
    14891490
    14901491
     
    14961497        new_points = ensure_geospatial(points)
    14971498       
    1498         assert allclose(new_points.get_data_points(absolute = True), points)
    1499 
    1500         points = array([[2.0, 0.0],[1.0, 1.0],
    1501                          [2.0, 0.0],[2.0, 2.0],
    1502                          [1.0, 3.0],[2.0, 2.0]])
     1499        assert num.allclose(new_points.get_data_points(absolute = True), points)
     1500
     1501        points = num.array([[2.0, 0.0],[1.0, 1.0],
     1502                            [2.0, 0.0],[2.0, 2.0],
     1503                            [1.0, 3.0],[2.0, 2.0]])
    15031504        new_points = ensure_geospatial(points)
    15041505       
    1505         assert allclose(new_points.get_data_points(absolute = True), points)
    1506        
    1507         ab_points = array([[2.0, 0.0],[1.0, 1.0],
    1508                          [2.0, 0.0],[2.0, 2.0],
    1509                          [1.0, 3.0],[2.0, 2.0]])
     1506        assert num.allclose(new_points.get_data_points(absolute = True), points)
     1507       
     1508        ab_points = num.array([[2.0, 0.0],[1.0, 1.0],
     1509                               [2.0, 0.0],[2.0, 2.0],
     1510                               [1.0, 3.0],[2.0, 2.0]])
    15101511       
    15111512        mesh_origin = (56, 290000, 618000) #zone, easting, northing
    15121513
    1513         data_points = zeros((ab_points.shape), Float)
     1514        data_points = num.zeros((ab_points.shape), num.Float)
    15141515        #Shift datapoints according to new origins
    15151516        for k in range(len(ab_points)):
     
    15231524        #print "ab_points",ab_points
    15241525           
    1525         assert allclose(new_points, ab_points)
     1526        assert num.allclose(new_points, ab_points)
    15261527
    15271528        geo = Geo_reference(56,67,-56)
     
    15341535        #print "ab_points",ab_points
    15351536           
    1536         assert allclose(new_points, ab_points)
     1537        assert num.allclose(new_points, ab_points)
    15371538
    15381539
     
    15501551        #print "ab_points",ab_points
    15511552           
    1552         assert allclose(new_points, ab_points)
     1553        assert num.allclose(new_points, ab_points)
    15531554       
    15541555    def test_isinstance(self):
     
    15651566
    15661567        results = Geospatial_data(fileName)
    1567         assert allclose(results.get_data_points(absolute=True), \
    1568                         [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    1569         assert allclose(results.get_attributes(attribute_name='elevation'), \
    1570                         [10.0, 0.0, 10.4])
    1571         assert allclose(results.get_attributes(attribute_name='speed'), \
    1572                         [0.0, 10.0, 40.0])
     1568        assert num.allclose(results.get_data_points(absolute=True),
     1569                            [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     1570        assert num.allclose(results.get_attributes(attribute_name='elevation'),
     1571                            [10.0, 0.0, 10.4])
     1572        assert num.allclose(results.get_attributes(attribute_name='speed'),
     1573                            [0.0, 10.0, 40.0])
    15731574
    15741575        os.remove(fileName)
     
    16021603        points = results.get_data_points()
    16031604       
    1604         assert allclose(points[0][0], 308728.009)
    1605         assert allclose(points[0][1], 6180432.601)
    1606         assert allclose(points[1][0],  222908.705)
    1607         assert allclose(points[1][1], 6233785.284)
     1605        assert num.allclose(points[0][0], 308728.009)
     1606        assert num.allclose(points[0][1], 6180432.601)
     1607        assert num.allclose(points[1][0],  222908.705)
     1608        assert num.allclose(points[1][1], 6233785.284)
    16081609       
    16091610     
     
    16231624        points = results.get_data_points()
    16241625       
    1625         assert allclose(points[0][0], 308728.009)
    1626         assert allclose(points[0][1], 6180432.601)
    1627         assert allclose(points[1][0],  222908.705)
    1628         assert allclose(points[1][1], 6233785.284)
     1626        assert num.allclose(points[0][0], 308728.009)
     1627        assert num.allclose(points[0][1], 6180432.601)
     1628        assert num.allclose(points[1][0],  222908.705)
     1629        assert num.allclose(points[1][1], 6233785.284)
    16291630
    16301631         
     
    16631664        points = gsd.get_data_points(absolute=True)
    16641665       
    1665         assert allclose(points[0][0], 308728.009)
    1666         assert allclose(points[0][1], 6180432.601)
    1667         assert allclose(points[1][0],  222908.705)
    1668         assert allclose(points[1][1], 6233785.284)
     1666        assert num.allclose(points[0][0], 308728.009)
     1667        assert num.allclose(points[0][1], 6180432.601)
     1668        assert num.allclose(points[1][0],  222908.705)
     1669        assert num.allclose(points[1][1], 6233785.284)
    16691670        self.failUnless(gsd.get_geo_reference().get_zone() == 56,
    16701671                        'Bad zone error!')
     
    17161717        points = gsd.get_data_points(absolute=True)
    17171718       
    1718         assert allclose(points[0][0], 308728.009)
    1719         assert allclose(points[0][1], 6180432.601)
    1720         assert allclose(points[1][0],  222908.705)
    1721         assert allclose(points[1][1], 6233785.284)
     1719        assert num.allclose(points[0][0], 308728.009)
     1720        assert num.allclose(points[0][1], 6180432.601)
     1721        assert num.allclose(points[1][0],  222908.705)
     1722        assert num.allclose(points[1][1], 6233785.284)
    17221723        self.failUnless(gsd.get_geo_reference().get_zone() == 56,
    17231724                        'Bad zone error!')
     
    17711772        # and it changes from windows to linux
    17721773        try:
    1773             assert allclose(points[1][0], 308728.009)
    1774             assert allclose(points[1][1], 6180432.601)
    1775             assert allclose(points[0][0],  222908.705)
    1776             assert allclose(points[0][1], 6233785.284)
     1774            assert num.allclose(points[1][0], 308728.009)
     1775            assert num.allclose(points[1][1], 6180432.601)
     1776            assert num.allclose(points[0][0],  222908.705)
     1777            assert num.allclose(points[0][1], 6233785.284)
    17771778        except AssertionError:
    1778             assert allclose(points[0][0], 308728.009)
    1779             assert allclose(points[0][1], 6180432.601)
    1780             assert allclose(points[1][0],  222908.705)
    1781             assert allclose(points[1][1], 6233785.284)
     1779            assert num.allclose(points[0][0], 308728.009)
     1780            assert num.allclose(points[0][1], 6180432.601)
     1781            assert num.allclose(points[1][0],  222908.705)
     1782            assert num.allclose(points[1][1], 6233785.284)
    17821783           
    17831784        self.failUnless(gsd.get_geo_reference().get_zone() == 56,
     
    17861787        #print "test_lat_long_set points", points
    17871788        try:
    1788             assert allclose(points[0][0], -34)
    1789             assert allclose(points[0][1], 150)
     1789            assert num.allclose(points[0][0], -34)
     1790            assert num.allclose(points[0][1], 150)
    17901791        except AssertionError:
    1791             assert allclose(points[1][0], -34)
    1792             assert allclose(points[1][1], 150)
     1792            assert num.allclose(points[1][0], -34)
     1793            assert num.allclose(points[1][1], 150)
    17931794
    17941795    def test_len(self):
     
    18291830            G1, G2  = G.split(factor,100)
    18301831           
    1831             assert allclose(len(G), len(G1)+len(G2))
    1832             assert allclose(round(len(G)*factor), len(G1))
     1832            assert num.allclose(len(G), len(G1)+len(G2))
     1833            assert num.allclose(round(len(G)*factor), len(G1))
    18331834   
    18341835            P = G1.get_data_points(absolute=False)
    1835             assert allclose(P, [[5.0,4.0],[4.0,3.0],[4.0,2.0],[3.0,1.0],[2.0,3.0]])
     1836            assert num.allclose(P, [[5.0,4.0],[4.0,3.0],[4.0,2.0],[3.0,1.0],[2.0,3.0]])
    18361837   
    18371838            A = G1.get_attributes()
    1838             assert allclose(A,[24, 18, 17, 11, 8])
     1839            assert num.allclose(A,[24, 18, 17, 11, 8])
    18391840       
    18401841    def test_split1(self):
     
    18571858           
    18581859    #        print 'G1',G1
    1859             assert allclose(len(G), len(G1)+len(G2))
    1860             assert allclose(round(len(G)*factor), len(G1))
     1860            assert num.allclose(len(G), len(G1)+len(G2))
     1861            assert num.allclose(round(len(G)*factor), len(G1))
    18611862   
    18621863            P = G1.get_data_points(absolute=False)
    1863             assert allclose(P, [[982420.,28233.]])
     1864            assert num.allclose(P, [[982420.,28233.]])
    18641865
    18651866 
Note: See TracChangeset for help on using the changeset viewer.