Changeset 6149


Ignore:
Timestamp:
Jan 13, 2009, 1:17:54 PM (10 years ago)
Author:
rwilson
Message:

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

Location:
anuga_core/source/anuga/coordinate_transforms
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/coordinate_transforms/geo_reference.py

    r5736 r6149  
    88
    99import types, sys
    10 from Numeric import array, Float, ArrayType, reshape, allclose
    1110from anuga.utilities.numerical_tools import ensure_numeric
    1211from anuga.utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError, \
    1312     ShapeError
     13
     14import Numeric as num
    1415
    1516
     
    9899       
    99100        # Fix some assertion failures
    100         if type(self.zone) == ArrayType and self.zone.shape == ():
     101        if type(self.zone) == num.ArrayType and self.zone.shape == ():
    101102            self.zone = self.zone[0]
    102         if type(self.xllcorner) == ArrayType and self.xllcorner.shape == ():
     103        if type(self.xllcorner) == num.ArrayType and self.xllcorner.shape == ():
    103104            self.xllcorner = self.xllcorner[0]
    104         if type(self.yllcorner) == ArrayType and self.yllcorner.shape == ():
     105        if type(self.yllcorner) == num.ArrayType and self.yllcorner.shape == ():
    105106            self.yllcorner = self.yllcorner[0]
    106107
     
    172173           
    173174        # Fix some assertion failures
    174         if(type(self.zone) == ArrayType and self.zone.shape == ()):
     175        if(type(self.zone) == num.ArrayType and self.zone.shape == ()):
    175176            self.zone = self.zone[0]
    176         if type(self.xllcorner) == ArrayType and self.xllcorner.shape == ():
     177        if type(self.xllcorner) == num.ArrayType and self.xllcorner.shape == ():
    177178            self.xllcorner = self.xllcorner[0]
    178         if type(self.yllcorner) == ArrayType and self.yllcorner.shape == ():
     179        if type(self.yllcorner) == num.ArrayType and self.yllcorner.shape == ():
    179180            self.yllcorner = self.yllcorner[0]
    180181   
     
    196197            is_list = True
    197198
    198         points = ensure_numeric(points, Float)
     199        points = ensure_numeric(points, num.Float)
    199200       
    200201        if len(points.shape) == 1:
     
    202203            msg = 'Single point must have two elements'
    203204            assert len(points) == 2, msg
    204             points = reshape(points, (1,2))
     205            points = num.reshape(points, (1,2))
    205206
    206207        msg = 'Points array must be two dimensional.\n'
     
    239240        """
    240241
    241         return allclose([self.xllcorner, self.yllcorner], 0)
     242        return num.allclose([self.xllcorner, self.yllcorner], 0)
    242243
    243244       
     
    255256            is_list = True
    256257
    257         points = ensure_numeric(points, Float)
     258        points = ensure_numeric(points, num.Float)
    258259        if len(points.shape) == 1:
    259260            #One point has been passed
     
    295296            is_list = True
    296297
    297         points = ensure_numeric(points, Float)
     298        points = ensure_numeric(points, num.Float)
    298299        if len(points.shape) == 1:
    299300            #One point has been passed
  • anuga_core/source/anuga/coordinate_transforms/redfearn.py

    r5662 r6149  
    88"""
    99from anuga.coordinate_transforms.geo_reference import Geo_reference, DEFAULT_ZONE
    10 from Numeric import array
     10
    1111
    1212def degminsec2decimal_degrees(dd,mm,ss):
  • anuga_core/source/anuga/coordinate_transforms/test_geo_reference.py

    r6086 r6149  
    77
    88from geo_reference import *
    9 from Numeric import allclose,array
    109from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a
     10
     11import Numeric as num
    1112
    1213
     
    165166        y = 443.0
    166167        g = Geo_reference(56,x,y)
    167         lofl = array([[3.0,323.0], [6.0,645.0]])
     168        lofl = num.array([[3.0,323.0], [6.0,645.0]])
    168169        new_lofl = g.change_points_geo_ref(lofl)
    169170        #print "4 lofl",lofl
    170171        #print "4 new_lofl",new_lofl
    171172
    172         self.failUnless(type(new_lofl) == ArrayType, ' failed')
     173        self.failUnless(type(new_lofl) == num.ArrayType, ' failed')
    173174        self.failUnless(type(new_lofl) == type(lofl), ' failed')
    174175        lofl[:,0] -= x
    175176        lofl[:,1] -= y
    176         assert allclose(lofl,new_lofl)
     177        assert num.allclose(lofl,new_lofl)
    177178       
    178179    def test_change_points_geo_ref5(self):
     
    180181        y = 3.0
    181182        g = Geo_reference(56,x,y)
    182         lofl = array([[3.0,323.0]])
     183        lofl = num.array([[3.0,323.0]])
    183184
    184185       
     
    188189        #print "5 new_lofl",new_lofl
    189190
    190         self.failUnless(type(new_lofl) == ArrayType, ' failed')
     191        self.failUnless(type(new_lofl) == num.ArrayType, ' failed')
    191192        self.failUnless(type(new_lofl) == type(lofl), ' failed')
    192193
     
    200201        y = 3.0
    201202        g = Geo_reference(56,x,y)
    202         lofl = array([355.0,3.0])
     203        lofl = num.array([355.0,3.0])
    203204        new_lofl = g.change_points_geo_ref(lofl.copy())       
    204205        #print "lofl",lofl
    205206        #print "new_lofl",new_lofl
    206207
    207         self.failUnless(type(new_lofl) == ArrayType, ' failed')
     208        self.failUnless(type(new_lofl) == num.ArrayType, ' failed')
    208209        self.failUnless(type(new_lofl) == type(lofl), ' failed')
    209210        for point,new_point in map(None,[lofl],new_lofl):
  • anuga_core/source/anuga/coordinate_transforms/test_lat_long_UTM_conversion.py

    r4197 r6149  
    77
    88import unittest
    9 from Numeric import allclose
    109
    1110from lat_long_UTM_conversion import *
    1211from redfearn import degminsec2decimal_degrees, decimal_degrees2degminsec
    1312from anuga.utilities.anuga_exceptions import ANUGAError
     13
     14import Numeric as num
     15
    1416
    1517#-------------------------------------------------------------
     
    2830        lat = degminsec2decimal_degrees(-37,39,10.15610)
    2931        lon = degminsec2decimal_degrees(143,55,35.38390)
    30         assert allclose(lat, -37.65282114)
    31         assert allclose(lon, 143.9264955)
     32        assert num.allclose(lat, -37.65282114)
     33        assert num.allclose(lon, 143.9264955)
    3234
    3335
     
    3537
    3638        assert zone == 54
    37         assert allclose(easting, 758173.797)
    38         assert allclose(northing, 5828674.340)
     39        assert num.allclose(easting, 758173.797)
     40        assert num.allclose(northing, 5828674.340)
    3941
    4042        lat_calced, long_calced = UTMtoLL(northing, easting, zone)
    41         assert allclose(lat,  lat_calced)
    42         assert allclose(lon, long_calced)
     43        assert num.allclose(lat,  lat_calced)
     44        assert num.allclose(lon, long_calced)
    4345
    4446
     
    6163       
    6264        assert zone == 55
    63         assert allclose(easting, 273741.297)
    64         assert allclose(northing, 5796489.777)
     65        assert num.allclose(easting, 273741.297)
     66        assert num.allclose(northing, 5796489.777)
    6567
    6668        lat_calced, long_calced = UTMtoLL(northing, easting, zone)
    67         assert allclose(lat,  lat_calced)
    68         assert allclose(lon, long_calced)
     69        assert num.allclose(lat,  lat_calced)
     70        assert num.allclose(lon, long_calced)
    6971       
    7072       
     
    7880
    7981        assert zone == 52
    80         assert allclose(easting, 555776.267)
    81         assert allclose(northing, 3348167.264)
     82        assert num.allclose(easting, 555776.267)
     83        assert num.allclose(northing, 3348167.264)
    8284
    8385        Lat, Long = UTMtoLL(northing, easting, zone)
     
    9496       
    9597        assert zone == 33
    96         assert allclose(easting, 348157.631)
    97         assert allclose(northing, 6175612.993)
     98        assert num.allclose(easting, 348157.631)
     99        assert num.allclose(northing, 6175612.993)
    98100
    99101        lat_calced, long_calced = UTMtoLL(northing, easting, zone,
    100102                                          isSouthernHemisphere=False)
    101         assert allclose(lat,  lat_calced)
    102         assert allclose(lon, long_calced)
     103        assert num.allclose(lat,  lat_calced)
     104        assert num.allclose(lon, long_calced)
    103105
    104106    def test_UTM_5(self):
     
    113115
    114116        assert zone == 56
    115         assert allclose(easting, 308728.009)
    116         assert allclose(northing, 6180432.601)
     117        assert num.allclose(easting, 308728.009)
     118        assert num.allclose(northing, 6180432.601)
    117119
    118120        lat_calced, long_calced = UTMtoLL(northing, easting, zone)
    119         assert allclose(lat,  lat_calced)
    120         assert allclose(lon, long_calced)
     121        assert num.allclose(lat,  lat_calced)
     122        assert num.allclose(lon, long_calced)
    121123#-------------------------------------------------------------
    122124if __name__ == "__main__":
  • anuga_core/source/anuga/coordinate_transforms/test_redfearn.py

    r5663 r6149  
    77
    88import unittest
    9 from Numeric import allclose
    109
    1110from redfearn import *
    1211from anuga.utilities.anuga_exceptions import ANUGAError
     12
     13import Numeric as num
     14
    1315
    1416#-------------------------------------------------------------
     
    1921        lat = degminsec2decimal_degrees(-37,39,10.15610)
    2022        lon = degminsec2decimal_degrees(143,55,35.38390)
    21         assert allclose(lat, -37.65282114)
    22         assert allclose(lon, 143.9264955)
     23        assert num.allclose(lat, -37.65282114)
     24        assert num.allclose(lon, 143.9264955)
    2325
    2426        dd,mm,ss = decimal_degrees2degminsec(-37.65282114)
    2527        assert dd==-37
    2628        assert mm==39
    27         assert allclose(ss, 10.15610)
     29        assert num.allclose(ss, 10.15610)
    2830
    2931        dd,mm,ss = decimal_degrees2degminsec(143.9264955)
    3032        assert dd==143
    3133        assert mm==55
    32         assert allclose(ss, 35.38390)
     34        assert num.allclose(ss, 35.38390)
    3335
    3436
     
    4446        lat = degminsec2decimal_degrees(-37,39,10.15610)
    4547        lon = degminsec2decimal_degrees(143,55,35.38390)
    46         assert allclose(lat, -37.65282114)
    47         assert allclose(lon, 143.9264955)
     48        assert num.allclose(lat, -37.65282114)
     49        assert num.allclose(lon, 143.9264955)
    4850
    4951
     
    5153
    5254        assert zone == 54
    53         assert allclose(easting, 758173.797)
    54         assert allclose(northing, 5828674.340)
     55        assert num.allclose(easting, 758173.797)
     56        assert num.allclose(northing, 5828674.340)
    5557
    5658
     
    7274
    7375        assert zone == 55
    74         assert allclose(easting, 273741.297)
    75         assert allclose(northing, 5796489.777)
     76        assert num.allclose(easting, 273741.297)
     77        assert num.allclose(northing, 5796489.777)
    7678
    7779       
     
    8587
    8688        assert zone == 52
    87         assert allclose(easting, 555776.267)
    88         assert allclose(northing, 3348167.264)
     89        assert num.allclose(easting, 555776.267)
     90        assert num.allclose(northing, 3348167.264)
    8991
    9092
     
    101103
    102104        assert zone == 33
    103         assert allclose(easting, 348157.631)
    104         assert allclose(northing, 6175612.993)
     105        assert num.allclose(easting, 348157.631)
     106        assert num.allclose(northing, 6175612.993)
    105107
    106108
     
    116118
    117119        assert zone == 56
    118         assert allclose(easting, 308728.009)
    119         assert allclose(northing, 6180432.601)
     120        assert num.allclose(easting, 308728.009)
     121        assert num.allclose(northing, 6180432.601)
    120122
    121123    def test_UTM_6_nonstandard_projection(self):
     
    126128
    127129        assert zone == 50
    128         assert allclose(easting, 213251.040253)
    129         assert allclose(northing, 6762559.15978)
     130        assert num.allclose(easting, 213251.040253)
     131        assert num.allclose(northing, 6762559.15978)
    130132
    131133        #Testing using the native zone
     
    133135
    134136        assert zone == 50
    135         assert allclose(easting, 213251.040253)
    136         assert allclose(northing, 6762559.15978)
     137        assert num.allclose(easting, 213251.040253)
     138        assert num.allclose(northing, 6762559.15978)
    137139
    138140        #Then project to zone 49
     
    140142
    141143        assert zone == 49
    142         assert allclose(easting, 796474.020057)
    143         assert allclose(northing, 6762310.25162)
     144        assert num.allclose(easting, 796474.020057)
     145        assert num.allclose(northing, 6762310.25162)
    144146
    145147       
     
    151153
    152154        assert zone == 49
    153         assert allclose(easting, 788653.192779)
    154         assert allclose(northing, 6773605.46384)
     155        assert num.allclose(easting, 788653.192779)
     156        assert num.allclose(northing, 6773605.46384)
    155157
    156158        #Then project to zone 50
     
    158160
    159161        assert zone == 50
    160         assert allclose(easting, 204863.606467)
    161         assert allclose(northing, 6773440.04726)
     162        assert num.allclose(easting, 204863.606467)
     163        assert num.allclose(northing, 6773440.04726)
    162164
    163165        #Testing point on zone boundary
     
    166168
    167169        assert zone == 50
    168         assert allclose(easting, 208199.768268)
    169         assert allclose(northing, 6769820.01453)
     170        assert num.allclose(easting, 208199.768268)
     171        assert num.allclose(northing, 6769820.01453)
    170172
    171173        #Then project to zone 49
     
    173175
    174176        assert zone == 49
    175         assert allclose(easting, 791800.231817)
    176         assert allclose(northing, 6769820.01453)
     177        assert num.allclose(easting, 791800.231817)
     178        assert num.allclose(northing, 6769820.01453)
    177179
    178180        #Testing furthest point in Geraldton scenario)
     
    181183
    182184        assert zone == 49
    183         assert allclose(easting, 737178.16131)
    184         assert allclose(northing, 6876426.38578)
     185        assert num.allclose(easting, 737178.16131)
     186        assert num.allclose(northing, 6876426.38578)
    185187
    186188        #Then project to zone 50
     
    188190
    189191        assert zone == 50
    190         assert allclose(easting, 148260.567427)
    191         assert allclose(northing, 6873587.50926)
     192        assert num.allclose(easting, 148260.567427)
     193        assert num.allclose(northing, 6873587.50926)
    192194
    193195        #Testing outside GDA zone (New Zeland)
     
    196198
    197199        assert zone == 60
    198         assert allclose(easting, 580174.259843)
    199         assert allclose(northing, 5127641.114461)
     200        assert num.allclose(easting, 580174.259843)
     201        assert num.allclose(northing, 5127641.114461)
    200202
    201203        #Then project to zone 59
     
    203205
    204206        assert zone == 59
    205         assert allclose(easting, 1061266.922118)
    206         assert allclose(northing, 5104249.395469)
     207        assert num.allclose(easting, 1061266.922118)
     208        assert num.allclose(northing, 5104249.395469)
    207209
    208210        #Then skip three zones 57 (native 60)
     
    210212
    211213        assert zone == 57
    212         assert allclose(easting, 2023865.527497)
    213         assert allclose(northing, 4949253.934967)
     214        assert num.allclose(easting, 2023865.527497)
     215        assert num.allclose(northing, 4949253.934967)
    214216
    215217        # Note Projecting into the Northern Hemisphere Does not coincide
     
    227229        # Google Earth interpretation
    228230        assert zone == 57
    229         assert allclose(easting, 259473.69)
    230         assert allclose(northing, 4876249.13)
     231        assert num.allclose(easting, 259473.69)
     232        assert num.allclose(northing, 4876249.13)
    231233
    232234        # ArcMap's interpretation
    233235        #assert zone == 57       
    234         #assert allclose(easting, 259473.678944)
    235         #assert allclose(northing, 14876249.1268)
     236        #assert num.allclose(easting, 259473.678944)
     237        #assert num.allclose(northing, 14876249.1268)
    236238       
    237239        #Then project to zone 56
     
    239241
    240242        assert zone == 56
    241         assert allclose(easting, 740526.321055)
    242         assert allclose(northing, 4876249.13)
     243        assert num.allclose(easting, 740526.321055)
     244        assert num.allclose(northing, 4876249.13)
    243245
    244246       
     
    283285        points, zone = convert_from_latlon_to_utm(latitudes=lats, longitudes=longs)
    284286
    285         assert allclose(points[0][0], 308728.009)
    286         assert allclose(points[0][1], 6180432.601)
    287         assert allclose(points[1][0],  222908.705)
    288         assert allclose(points[1][1], 6233785.284)
     287        assert num.allclose(points[0][0], 308728.009)
     288        assert num.allclose(points[0][1], 6180432.601)
     289        assert num.allclose(points[1][0],  222908.705)
     290        assert num.allclose(points[1][1], 6233785.284)
    289291        self.failUnless(zone == 56,
    290292                        'Bad zone error!')
     
    355357        points, zone = convert_from_latlon_to_utm(points=points)
    356358        #print "points",points
    357         assert allclose(points[0][0], 308728.009)
    358         assert allclose(points[0][1], 6180432.601)
    359         assert allclose(points[1][0],  222908.705)
    360         assert allclose(points[1][1], 6233785.284)
     359        assert num.allclose(points[0][0], 308728.009)
     360        assert num.allclose(points[0][1], 6180432.601)
     361        assert num.allclose(points[1][0],  222908.705)
     362        assert num.allclose(points[1][1], 6233785.284)
    361363        self.failUnless(zone == 56,
    362364                        'Bad zone error!')
Note: See TracChangeset for help on using the changeset viewer.