1 | """Read in timeseries from N simulations and plot spread for each timestep at specified locations (ch 5,7,9) |
---|
2 | """ |
---|
3 | |
---|
4 | import sys, os |
---|
5 | from caching import cache |
---|
6 | import project |
---|
7 | |
---|
8 | gauge_name = project.gauge_names[0] |
---|
9 | from Numeric import zeros, Float, allclose |
---|
10 | |
---|
11 | |
---|
12 | number_of_realisations = project.number_of_realisations |
---|
13 | |
---|
14 | time = zeros(project.number_of_timesteps, Float) |
---|
15 | data = zeros((project.number_of_timesteps, number_of_realisations), Float) |
---|
16 | |
---|
17 | j = 0 # Count realisations |
---|
18 | for filename in os.listdir('.'): |
---|
19 | if filename.startswith(project.basename) and filename.endswith('%s.txt' %gauge_name): |
---|
20 | if j < data.shape[1]: |
---|
21 | print 'Reading filename %s (column %d)' %(filename, j) |
---|
22 | fid = open(filename) |
---|
23 | for i, line in enumerate(fid.readlines()): |
---|
24 | if i < data.shape[0]: |
---|
25 | fields = line.strip().split() |
---|
26 | time[i] = float(fields[0]) |
---|
27 | data[i,j] = float(fields[1]) |
---|
28 | else: |
---|
29 | print 'Ignored %s (column %d)' %(filename, j) |
---|
30 | |
---|
31 | fid.close() |
---|
32 | j += 1 |
---|
33 | |
---|
34 | |
---|
35 | # Plot |
---|
36 | from pylab import ion, hold, plot, title, xlabel, ylabel, legend, savefig, show |
---|
37 | |
---|
38 | ion() |
---|
39 | hold(True) |
---|
40 | hold(False) |
---|
41 | |
---|
42 | #for i in range(project.number_of_timesteps): |
---|
43 | # print i, data[i,:] |
---|
44 | # plot(data[i,:], 'k.') |
---|
45 | # raw_input('Next') |
---|
46 | |
---|
47 | for j in range(number_of_realisations): |
---|
48 | print j, data[:,j] |
---|
49 | plot(data[:,j], 'k-') |
---|
50 | |
---|
51 | raw_input('Next') |
---|
52 | #title('Gauge %s' %name) |
---|
53 | #xlabel('time(s)') |
---|
54 | #ylabel('stage (m)') |
---|
55 | #legend(('Observed', 'Modelled'), shadow=True, loc='upper left') |
---|
56 | #savefig(name, dpi = 300) |
---|
57 | |
---|
58 | |
---|
59 | show() |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | #from pylab import * |
---|
64 | #plot(time, stage) |
---|
65 | #show() |
---|