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 |
---|
5 | import sys, os |
---|
6 | |
---|
7 | # Related major packages |
---|
8 | from Numeric import zeros, Float, allclose, arange |
---|
9 | from caching import cache |
---|
10 | |
---|
11 | # Application specific imports |
---|
12 | from utilities.numerical_tools import histogram, create_bins |
---|
13 | import project |
---|
14 | |
---|
15 | # Initialise |
---|
16 | gauge = '%s.txt' %project.gauge_names[0] |
---|
17 | number_of_realisations = project.number_of_realisations |
---|
18 | |
---|
19 | time = zeros(project.number_of_timesteps, Float) |
---|
20 | data = zeros((project.number_of_timesteps, number_of_realisations), Float) |
---|
21 | |
---|
22 | |
---|
23 | # Read in all realisations-timeseries |
---|
24 | |
---|
25 | j = 0 # Count realisations |
---|
26 | for 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 |
---|
44 | from pylab import ion, hold, plot, title, xlabel, ylabel, legend, savefig, show |
---|
45 | |
---|
46 | ion() |
---|
47 | #hold(True) |
---|
48 | hold(False) |
---|
49 | |
---|
50 | # Simple plot of timeseries for different realisations |
---|
51 | for 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 | |
---|
59 | raw_input('Next') |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | # Plot histogram of stage values for each timestep |
---|
64 | for i in range(project.number_of_timesteps): |
---|
65 | # Plot histogram |
---|
66 | |
---|
67 | w = data[i,:] |
---|
68 | |
---|
69 | bins = create_bins(w, project.number_of_bins) |
---|
70 | print 'bins', bins |
---|
71 | hist = histogram(w, bins, relative=True) |
---|
72 | #print 'hist', hist |
---|
73 | |
---|
74 | #plot(w, 'k.') |
---|
75 | plot(bins, hist, 'k.') |
---|
76 | xlabel('stage (m)') |
---|
77 | ylabel('frequency') |
---|
78 | title('Timestep %d of %d (t=%.2f)'\ |
---|
79 | %(i, project.number_of_timesteps-1, time[i])) |
---|
80 | raw_input('Next') |
---|
81 | |
---|
82 | |
---|
83 | #title('Gauge %s' %name) |
---|
84 | #xlabel('time(s)') |
---|
85 | #ylabel('stage (m)') |
---|
86 | #legend(('Observed', 'Modelled'), shadow=True, loc='upper left') |
---|
87 | #savefig(name, dpi = 300) |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | show() |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | #from pylab import * |
---|
99 | #plot(time, stage) |
---|
100 | #show() |
---|