Changeset 7520


Ignore:
Timestamp:
Sep 21, 2009, 7:19:55 PM (15 years ago)
Author:
steve
Message:

Improved the fix to sww2dem. Using numpy.savetxt instead of num.array2string

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

Legend:

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

    r7519 r7520  
    24872487        # change printoptions so that a long string of zeros in not
    24882488        # summarized as [0.0, 0.0, 0.0, ... 0.0, 0.0, 0.0]
    2489         printoptions = num.get_printoptions()
    2490         num.set_printoptions(threshold=sys.maxint)
    2491 
     2489        #printoptions = num.get_printoptions()
     2490        #num.set_printoptions(threshold=sys.maxint)
     2491
     2492        format = '%.'+'%g' % number_of_decimal_places +'e'
    24922493        for i in range(nrows):
    24932494            if verbose and i % ((nrows+10)/10) == 0:
     
    24972498
    24982499            slice = grid_values[base_index:base_index+ncols]
    2499             #s = array2string(slice, max_line_width=sys.maxint)
    2500 
    2501             s = num.array2string(slice, max_line_width=sys.maxint,
    2502                                  precision=number_of_decimal_places)
    2503             ascid.write(s[1:-1] + '\n')
    2504 
    2505         num.set_printoptions(threshold=printoptions['threshold'])
     2500
     2501            num.savetxt(ascid, slice.reshape(1,ncols), format, ' ' )
     2502           
    25062503       
    25072504        #Close
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r7519 r7520  
    21062106    def test_sww2dem_larger_zero(self):
    21072107        """Test that sww information can be converted correctly to asc/prj
    2108         format readable by e.g. ArcView. Here:
    2109 
    2110         ncols         11
    2111         nrows         11
     2108        format readable by e.g. Arcview. This example has rows with a
     2109        large number of zeros
     2110
     2111        ncols         2001
     2112        nrows         2
    21122113        xllcorner     308500
    21132114        yllcorner     6189000
    2114         cellsize      10.000000
     2115        cellsize      1.000000
    21152116        NODATA_value  -9999
    2116         -100 -110 -120 -130 -140 -150 -160 -170 -180 -190 -200
    2117          -90 -100 -110 -120 -130 -140 -150 -160 -170 -180 -190
    2118          -80  -90 -100 -110 -120 -130 -140 -150 -160 -170 -180
    2119          -70  -80  -90 -100 -110 -120 -130 -140 -150 -160 -170
    2120          -60  -70  -80  -90 -100 -110 -120 -130 -140 -150 -160
    2121          -50  -60  -70  -80  -90 -100 -110 -120 -130 -140 -150
    2122          -40  -50  -60  -70  -80  -90 -100 -110 -120 -130 -140
    2123          -30  -40  -50  -60  -70  -80  -90 -100 -110 -120 -130
    2124          -20  -30  -40  -50  -60  -70  -80  -90 -100 -110 -120
    2125          -10  -20  -30  -40  -50  -60  -70  -80  -90 -100 -110
    2126            0  -10  -20  -30  -40  -50  -60  -70  -80  -90 -100
    2127 
     2117        0.0 ....
    21282118        """
    21292119
     
    21332123        #Setup
    21342124
    2135         from mesh_factory import rectangular
     2125        from mesh_factory import rectangular_cross
    21362126
    21372127        #Create basic mesh (100m x 100m)
    2138         points, vertices, boundary = rectangular(2, 2, 100, 100)
     2128        points, vertices, boundary = rectangular_cross(2000, 1, 2000.0, 1.0)
    21392129
    21402130        #Create shallow water domain
     
    21702160        sww.store_timestep()
    21712161
    2172         # Set theshold for printoptions to somrthing small
    2173         # to pickup Rudy's error caused a long sequence of zeros printing
    2174         # as [ 0.0, 0.0, 0.0, ... 0.0, 0.0, 0.0] by num.array2string
    2175         printoptions = num.get_printoptions()
    2176         num.set_printoptions(threshold=9)
    2177        
    2178         cellsize = 10  #10m grid
     2162        cellsize = 1.0  #0.1 grid
    21792163
    21802164
     
    22072191        prjid.close()
    22082192
     2193
    22092194        L = lines[0].strip().split()
    22102195        assert L[0].strip().lower() == 'projection'
     
    22482233        ascid.close()
    22492234
     2235
     2236
    22502237        L = lines[0].strip().split()
    22512238        assert L[0].strip().lower() == 'ncols'
    2252         assert L[1].strip().lower() == '11'
     2239        assert L[1].strip().lower() == '2001'
    22532240
    22542241        L = lines[1].strip().split()
    22552242        assert L[0].strip().lower() == 'nrows'
    2256         assert L[1].strip().lower() == '11'
     2243        assert L[1].strip().lower() == '2'
    22572244
    22582245        L = lines[2].strip().split()
     
    22862273
    22872274
    2288         num.set_printoptions(threshold=printoptions['threshold'])
    22892275        #Cleanup
    22902276        os.remove(prjfile)
Note: See TracChangeset for help on using the changeset viewer.