Changeset 2972


Ignore:
Timestamp:
May 25, 2006, 3:42:31 PM (18 years ago)
Author:
ole
Message:

Added create_bins and refactored pyvolution/mesh.py

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • development/stochastic_study/plot_spread.py

    r2967 r2972  
    22"""
    33
     4# Standard modules
    45import sys, os
     6
     7# Related major packages
     8from Numeric import zeros, Float, allclose, arange
    59from caching import cache
     10
     11# Application specific imports
     12from utilities.numerical_tools import histogram, create_bins
    613import project
    714
     15# Initialise
    816gauge_name = project.gauge_names[0]
    9 from Numeric import zeros, Float, allclose
    10 
    11 
    1217number_of_realisations = project.number_of_realisations
    1318
    1419time = zeros(project.number_of_timesteps, Float)
    1520data = zeros((project.number_of_timesteps, number_of_realisations), Float)
     21
     22
     23# Read in all realisations-timeseries
    1624
    1725j = 0 # Count realisations
     
    3745
    3846ion()
    39 hold(True)
     47#hold(True)
    4048hold(False)
    4149
    42 #for i in range(project.number_of_timesteps):
    43 #    print i, data[i,:]
    44 #    plot(data[i,:], 'k.')
    45 #    raw_input('Next')   
    46 
     50# Simple plot of timeseries for different realisations
    4751for j in range(number_of_realisations):
    48     print j, data[:,j]
     52    #print j, data[:,j]
    4953    plot(data[:,j], 'k-')
    5054   
    5155    raw_input('Next')
     56    xlabel('time(s)')
     57    ylabel('stage (m)')
     58    title('Realisation %d of %d' %(j, number_of_realisations))   
     59   
     60
     61
     62# Plot histogram of stage values for each timestep
     63for i in range(project.number_of_timesteps):
     64    # Plot histogram
     65
     66    w = data[i,:]
     67     
     68    bins = create_bins(w, project.number_of_bins)
     69    print 'bins', bins
     70    hist = histogram(w, bins)
     71    print 'hist', hist
     72   
     73    #plot(w, 'k.')
     74    plot(hist, 'k.')
     75    xlabel('stage (m)')
     76    ylabel('count')
     77    title('Timestep %d of %d (t=%.2f)'\
     78          %(i, project.number_of_timesteps, time[i]))       
     79    raw_input('Next')
     80
     81
    5282#title('Gauge %s' %name)
    5383#xlabel('time(s)')
     
    5585#legend(('Observed', 'Modelled'), shadow=True, loc='upper left')
    5686#savefig(name, dpi = 300)
     87
     88
     89
     90
    5791
    5892
  • development/stochastic_study/project.py

    r2966 r2972  
    1919
    2020# Stats (Suresh ?)
    21 number_of_realisations = 4
     21number_of_realisations = 1
    2222#std_dev = 0.0026  #Range is 26.035 cm
    2323std_dev = 0.0013  #Range is 26.035 cm
     
    2525blocksize = 100 #How many realisations to fit at a time
    2626
    27 
     27number_of_bins = 10
    2828
    2929
  • inundation/pyvolution/mesh.py

    r2866 r2972  
    689689
    690690        from Numeric import arange
    691         from utilities.numerical_tools import histogram
     691        from utilities.numerical_tools import histogram, create_bins
    692692
    693693        vertex_coordinates = self.vertex_coordinates
     
    698698
    699699        #Setup 10 bins for area histogram
    700         m = max(areas)
    701         bins = arange(0., m, m/10)
     700        bins = create_bins(areas, 10)
     701        #m = max(areas)
     702        #bins = arange(0., m, m/10)
    702703        hist = histogram(areas, bins)
    703704
  • inundation/utilities/numerical_tools.py

    r2778 r2972  
    88#(this should move to somewhere central)
    99try:
    10     from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float   
     10    from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float, arange   
    1111except:
    1212    #print 'Could not find scipy - using Numeric'
    13     from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float   
     13    from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float, arange   
    1414
    1515# Getting an infinite number to use when using Numeric
     
    212212    return n[1:]-n[:-1]
    213213
     214def create_bins(data, number_of_bins = None):
     215    """Safely create bins for use with histogram
     216    If data contains only one point or is constant, one bin will be created.
     217    If number_of_bins in omitted 10 bins will be created
     218    """
     219
     220    mx = max(data)
     221    mn = min(data)
     222
     223    if mx == mn:
     224        bins = array([mn])
     225    else:
     226        if number_of_bins is None:
     227            number_of_bins = 10
     228           
     229        bins = arange(mn, mx, (mx-mn)/number_of_bins)
     230
     231    return bins
     232
    214233
    215234
Note: See TracChangeset for help on using the changeset viewer.