Changeset 2533


Ignore:
Timestamp:
Mar 13, 2006, 2:18:40 PM (19 years ago)
Author:
ole
Message:

Work on area histogram

Location:
inundation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/examples/beach.py

    r1977 r2533  
    1010######################
    1111# Module imports
    12 #
    1312
    1413import sys
     
    1615#sys.path.append('..'+sep+'pyvolution')
    1716
    18 from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
     17from pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
    1918     Transmissive_boundary, Time_boundary, Wind_stress
    2019
    21 from pmesh2domain import pmesh_to_domain_instance
    22 from util import read_polygon, Polygon_function
     20from pyvolution.pmesh2domain import pmesh_to_domain_instance
     21from utilities.polygon import read_polygon, Polygon_function
    2322from math import pi
    2423from Numeric import choose, greater, ones, sin, exp
  • inundation/pyvolution/mesh.py

    r2532 r2533  
    620620        """
    621621
     622        from Numeric import arange
     623        from utilities.numerical_tools import histogram
     624
    622625        vertex_coordinates = self.vertex_coordinates
    623626        areas = self.areas
    624627        x = vertex_coordinates[:,0]
    625         y = vertex_coordinates[:,1]               
     628        y = vertex_coordinates[:,1]
     629
     630
     631        #Setup 10 bins for area histogram
     632        m = max(areas)
     633        bins = arange(0, m/10, m)
     634        hist = histogram(areas, bins)
    626635
    627636        str =  '------------------------------------------------\n'
     
    633642        str += '  Areas:\n'
    634643        str += '    A in [%f, %f]\n' %(min(areas), max(areas))
     644        str += '    Histogram:\n'
     645        for i, count in enumerate(hist):
     646            str += '      >=%f: %d\n' %(bins[i], count)
     647                     
    635648        str += 'Boundary:\n'
    636649        str += '  Number of boundary segments == %d\n' %(len(self.boundary))
  • inundation/pyvolution/test_pmesh2domain.py

    r2056 r2533  
    169169
    170170         domain = pmesh_instance_to_domain_instance(mesh_instance, Domain)
     171
    171172         os.remove(fileName)
    172173         #print "domain.tagged_elements", domain.tagged_elements
  • inundation/utilities/numerical_tools.py

    r2531 r2533  
    88#(this should move to somewhere central)
    99try:
    10     from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt   
     10    from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate   
    1111except:
    1212    print 'Could not find scipy - using Numeric'
    13     from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt
     13    from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate   
    1414   
    1515
     
    190190
    191191
     192
     193def histogram(a, bins):
     194    """Standard histogram straight from the Numeric manual
     195    """
     196
     197    n = searchsorted(sort(a), bins)
     198    n = concatenate( [n, [len(a)]] )
     199    return n[1:]-n[:-1]
     200
     201
     202
    192203####################################################################
    193204#Python versions of function that are also implemented in numerical_tools_ext.c
  • inundation/utilities/test_numerical_tools.py

    r2526 r2533  
    141141
    142142
     143    def test_histogram(self):
     144        """Test histogram with different bin boundaries
     145        """
     146       
     147        a = [1,1,1,1,1,2,1,3,2,3,1,2,3,4,1]
     148
     149
     150        #There are four elements greater than or equal to 3
     151        bins = [3]
     152        assert allclose(histogram(a, bins), [4])
     153
     154
     155        bins = [ min(a) ]
     156        assert allclose(histogram(a, bins), [len(a)])
     157
     158
     159        bins = [ max(a)+0.00001 ]
     160        assert allclose(histogram(a, bins), [0])       
     161
     162       
     163        bins = [1,2,3,4]
     164        assert allclose(histogram(a, bins), [8,3,3,1])
     165
     166
     167        bins = [0.5,1.5,2,3]
     168        assert allclose(histogram(a, bins), [8,0,3,4])
     169
     170
     171       
     172
    143173    def test_that_C_extension_compiles(self):
    144174        FN = 'util_ext.c'
Note: See TracChangeset for help on using the changeset viewer.