source: development/stochastic_study/plot_spread.py @ 2986

Last change on this file since 2986 was 2986, checked in by ole, 18 years ago

More stochastic plotting

File size: 2.7 KB
Line 
1"""Read in timeseries from N simulations and plot spread for each timestep at specified locations (ch 5,7,9)
2"""
3
4# Standard modules
5import sys, os
6
7# Related major packages
8from Numeric import zeros, Float, allclose, arange
9from caching import cache
10
11# Application specific imports
12from utilities.numerical_tools import histogram, create_bins
13import project
14
15# Initialise
16gauge = '%s.txt' %project.gauge_names[0]
17number_of_realisations = project.number_of_realisations
18
19time = zeros(project.number_of_timesteps, Float)
20data = zeros((project.number_of_timesteps, number_of_realisations), Float)
21
22
23# Read in all realisations-timeseries
24
25j = 0 # Count realisations
26for filename in os.listdir(project.working_dir):
27    if filename.startswith(project.basename) and filename.endswith(gauge):
28        if j < data.shape[1]:       
29            print 'Reading filename %s (column %d)' %(filename, j)
30            fid = open(filename)
31            for i, line in enumerate(fid.readlines()):
32                if i < data.shape[0]:
33                    fields = line.strip().split()
34                    time[i] = float(fields[0])
35                    data[i,j] = float(fields[1])
36        else:
37            print 'Ignored %s (column %d)' %(filename, j)
38
39        fid.close()
40        j += 1   
41
42
43# Plot
44from pylab import ion, hold, plot, title, xlabel, ylabel, legend, savefig, show
45
46ion()
47#hold(True)
48hold(False)
49
50# Simple plot of timeseries for different realisations
51for j in range(number_of_realisations):
52    print j, data[:,j]
53    plot(time, data[:,j], 'k-')
54   
55    xlabel('time(s)')
56    ylabel('stage (m)')
57    title('Realisation %d of %d' %(j, number_of_realisations-1))    #
58#raw_input('Next')
59
60
61hold(False)
62# Plot spread of stage values for each timestep
63for i in range(200,project.number_of_timesteps):
64    # Plot histogram
65
66    w = data[i,:]
67    plot(w, 'k.')
68    xlabel('realisations')
69    ylabel('stage (m)')
70    title('Timestep %d of %d (t=%.2f)'\
71          %(i, project.number_of_timesteps-1, time[i]))       
72    raw_input('Next')
73
74
75hold(False)
76# Plot histogram of stage values for each timestep
77for i in range(200,project.number_of_timesteps):
78    # Plot histogram
79
80    w = data[i,:]
81     
82    bins = create_bins(w, project.number_of_bins)
83    print 'bins', bins
84    hist = histogram(w, bins, relative=True)
85    #print 'hist', hist
86   
87    #plot(w, 'k.')
88    plot(bins, hist, 'k.')
89    xlabel('stage (m)')
90    ylabel('frequency')
91    title('Timestep %d of %d (t=%.2f)'\
92          %(i, project.number_of_timesteps-1, time[i]))       
93    #raw_input('Next')
94
95
96#title('Gauge %s' %name)
97#xlabel('time(s)')
98#ylabel('stage (m)')   
99#legend(('Observed', 'Modelled'), shadow=True, loc='upper left')
100#savefig(name, dpi = 300)
101
102
103
104
105
106
107show()
108
109
110
111#from pylab import *
112#plot(time, stage)
113#show()
Note: See TracBrowser for help on using the repository browser.