Changeset 7308


Ignore:
Timestamp:
Jul 12, 2009, 10:53:38 PM (15 years ago)
Author:
ole
Message:

Tested ANUGA/numpy for Python2.6 on Ubuntu 9.04 and fixed up remaining errors.
In short, they had to do with hasattr, which now can raise a proper exception and the rest
was situations where numpy.int32 had to be converted to a proper int.

Location:
anuga_core/source/anuga
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r7276 r7308  
    30833083    else:
    30843084        jmin = num.searchsorted(times, mint)
     3085       
     3086        # numpy.int32 didn't work in slicing of amplitude below
     3087        jmin = int(jmin)
    30853088
    30863089    if maxt is None:
     
    30893092    else:
    30903093        jmax = num.searchsorted(times, maxt)
     3094       
     3095        # numpy.int32 didn't work in slicing of amplitude below
     3096        jmax = int(jmax)       
    30913097
    30923098    kmin, kmax, lmin, lmax = _get_min_max_indexes(latitudes[:],
     
    31233129    #        'print hmmm'
    31243130
    3125     #Get missing values
     3131    # Get missing values
    31263132    nan_ha = file_h.variables['HA'].missing_value[0]
    31273133    nan_ua = file_u.variables['UA'].missing_value[0]
     
    31323138        nan_e = None
    31333139
    3134     #Cleanup
     3140    # Cleanup
    31353141    missing = (amplitudes == nan_ha)
    31363142    if num.sometrue (missing):
     
    38283834    if verbose: print 'Reading DEM from %s' % inname
    38293835
    3830     #Read metadata
    3831     ncols = infile.ncols[0]
    3832     nrows = infile.nrows[0]
     3836    # Read metadata (convert from numpy.int32 to int where appropriate)
     3837    ncols = int(infile.ncols[0])
     3838    nrows = int(infile.nrows[0])
    38333839    xllcorner = infile.xllcorner[0]
    38343840    yllcorner = infile.yllcorner[0]
    3835     cellsize = infile.cellsize[0]
    3836     NODATA_value = infile.NODATA_value[0]
    3837     zone = infile.zone[0]
     3841    cellsize = int(infile.cellsize[0])
     3842    NODATA_value = int(infile.NODATA_value[0])
     3843    zone = int(infile.zone[0])
    38383844    false_easting = infile.false_easting[0]
    38393845    false_northing = infile.false_northing[0]
     
    38603866    nrows_new = 1 + (nrows - nrows_stencil) / cellsize_ratio
    38613867
     3868    #print type(ncols_new), ncols_new
     3869   
    38623870    #Open netcdf file for output
    38633871    outfile = NetCDFFile(outname, netcdf_mode_w)
     
    38853893
    38863894    # dimension definition
     3895    #print nrows_new, ncols_new, nrows_new*ncols_new
     3896    #print type(nrows_new), type(ncols_new), type(nrows_new*ncols_new)
    38873897    outfile.createDimension('number_of_points', nrows_new*ncols_new)
    38883898
     
    61026112        Maybe make this general, but the viewer assumes these quantities,
    61036113        so maybe we don't want it general - unless the viewer is general
    6104 
    6105         precon
    6106         triangulation and
    6107         header have been called.
     6114       
     6115        The argument sww_precision allows for storing as either
     6116        * single precision (default): num.float32
     6117        * double precision: num.float64 or num.float
     6118
     6119        Precondition:
     6120            triangulation and
     6121            header have been called.
    61086122        """
    61096123
     
    61126126            slice_index = len(file_time)
    61136127            file_time[slice_index] = time
     6128        else:
     6129            slice_index = int(slice_index) # In case it was numpy.int   
    61146130
    61156131        # Write the conserved quantities from Domain.
     
    61246140            else:
    61256141                q_values = quant[q]
    6126                 outfile.variables[q][slice_index] = \
    6127                                 q_values.astype(sww_precision)
     6142               
     6143                x = q_values.astype(sww_precision)
     6144                outfile.variables[q][slice_index] = x
     6145                   
    61286146       
    61296147                # This updates the _range values
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r7276 r7308  
    59605960        tide = 1
    59615961        base_name, files = self.create_mux()
     5962       
    59625963        urs2sww(base_name,
    59635964                mint=0.25,
     
    59655966                mean_stage=tide,
    59665967                remove_nc_files=True,
    5967                       verbose=self.verbose
    5968                 )
     5968                verbose=self.verbose)
    59695969        sww_file = base_name + '.sww'
    59705970       
     
    1167811678
    1167911679if __name__ == "__main__":
    11680     suite = unittest.makeSuite(Test_Data_Manager,'test')
     11680    suite = unittest.makeSuite(Test_Data_Manager, 'test')
    1168111681   
     11682   
     11683    # FIXME(Ole): When Ross has implemented logging, we can
     11684    # probably get rid of all this:
    1168211685    if len(sys.argv) > 1 and sys.argv[1][0].upper() == 'V':
    1168311686        Test_Data_Manager.verbose=True
  • anuga_core/source/anuga/utilities/test_polygon.py

    r7276 r7308  
    304304        points = [[0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]]
    305305        res = inside_polygon( points, polygon, verbose=False )
    306         assert num.allclose( res, [0,1,2] )
     306        assert num.allclose(res, [0,1,2])
    307307
    308308    def test_outside_polygon(self):
     
    585585        points = [(1., 0.25),(1., 0.75)]
    586586        inside, outside = in_and_outside_polygon(points, polygon, closed=True)
    587         assert (inside, [0,1])
     587        assert num.alltrue(inside == [0,1])
    588588        assert len(outside) == 0
    589589
    590590        inside, outside = in_and_outside_polygon(points, polygon, closed=False)
    591591        assert len(inside) == 0
    592         assert (outside, [0,1])
     592        assert num.alltrue(outside == [0,1])
    593593
    594594        points = [(100., 0.25), (0.5, 0.5) ]
    595595        inside, outside = in_and_outside_polygon(points, polygon)
    596         assert (inside, [1])
     596        assert num.alltrue(inside == [1])
    597597        assert outside[0] == 0
    598598
    599599        points = [(100., 0.25),(0.5, 0.5), (39,20), (0.6,0.7),(56,43),(67,90)]
    600600        inside, outside = in_and_outside_polygon(points, polygon)
    601         assert (inside, [1, 3])
    602         assert (outside, [0, 2, 4, 5])
     601        assert num.alltrue(inside == [1, 3])
     602        assert num.alltrue(outside == [0, 2, 4, 5])
    603603
    604604    def test_intersection1(self):
  • anuga_core/source/anuga/utilities/treenode.py

    r3566 r7308  
    2424        self.parent = None
    2525
    26         # subclasses can implement these attributes as functions, called
     26        # Subclasses can implement these attributes as functions, called
    2727        # when a node (either leaf or internal) is deleted
    28         if not hasattr(self,'ClearLeafNode'):
    29             self.ClearLeafNode = None
    30         if not hasattr(self,'ClearInternalNode'):
    31             self.ClearInternalNode = None
     28       
     29        # FIXME (Ole): The hasattr statements below were commented out on 12 July 2009 by Ole Nielsen due to
     30        # errors appearing when using Python2.6. Tests pass, so I think this was just superfluous anyway.
     31        #
     32        # Excerpt from What's New in Python 2.6
     33        #
     34        #The hasattr() function was catching and ignoring all errors,
     35        #under the assumption that they meant a __getattr__() method
     36        #was failing somehow and the return value of hasattr() would
     37        #therefore be False. This logic shouldn't be applied to
     38        #KeyboardInterrupt and SystemExit, however; Python 2.6 will no
     39        #longer discard such exceptions when hasattr() encounters
     40        #them. (Fixed by Benjamin Peterson; issue 2196.)
     41       
     42        #if not hasattr(self,'ClearLeafNode'):
     43        #    self.ClearLeafNode = None
     44        #if not hasattr(self,'ClearInternalNode'):
     45        #    self.ClearInternalNode = None
     46       
     47        # # When not already set by derived class, set unique instance name       
     48        #if not hasattr(self,'name'):
     49        #    if name:
     50        #        self.name = name
     51        #    else:
     52        #        self.name = id(self)       
    3253
    33         # when not already set by derived class, set unique instance name
    34         if not hasattr(self,"name"):
    35             if name:
    36                 self.name = name
    37             else:
    38                 self.name = id(self)
     54        # When not already set by derived class, set unique instance name
     55        if name:
     56            self.name = name
     57        else:
     58            self.name = id(self)       
     59       
    3960
    4061
    41     #Make treenode elements appear as sequences such thta on
    42     #can iterate over them             
     62
     63    # Make treenode elements appear as sequences such that one
     64    # can iterate over them             
    4365    def __iter__(self):
    4466        self.index = -1   # incremented on first call to next()
Note: See TracChangeset for help on using the changeset viewer.