source: development/stochastic_study/plot_spread.py @ 2984

Last change on this file since 2984 was 2979, checked in by ole, 19 years ago

Arbitrary working dir

File size: 2.4 KB
RevLine 
[2967]1"""Read in timeseries from N simulations and plot spread for each timestep at specified locations (ch 5,7,9)
2"""
3
[2972]4# Standard modules
[2967]5import sys, os
[2972]6
7# Related major packages
8from Numeric import zeros, Float, allclose, arange
[2967]9from caching import cache
[2972]10
11# Application specific imports
12from utilities.numerical_tools import histogram, create_bins
[2967]13import project
14
[2972]15# Initialise
[2975]16gauge = '%s.txt' %project.gauge_names[0]
[2967]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
[2972]22
23# Read in all realisations-timeseries
24
[2967]25j = 0 # Count realisations
[2979]26for filename in os.listdir(project.working_dir):
[2975]27    if filename.startswith(project.basename) and filename.endswith(gauge):
[2967]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()
[2972]47#hold(True)
[2967]48hold(False)
49
[2972]50# Simple plot of timeseries for different realisations
[2967]51for j in range(number_of_realisations):
[2972]52    #print j, data[:,j]
[2975]53    plot(time, data[:,j], 'k-')
[2967]54   
[2972]55    xlabel('time(s)')
56    ylabel('stage (m)')
[2975]57    title('Realisation %d of %d' %(j, number_of_realisations-1))   
[2972]58
[2975]59    raw_input('Next')
[2972]60
[2975]61
62
[2972]63# Plot histogram of stage values for each timestep
64for 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
[2975]71    hist = histogram(w, bins, relative=True)
72    #print 'hist', hist
[2972]73   
74    #plot(w, 'k.')
[2975]75    plot(bins, hist, 'k.')
[2972]76    xlabel('stage (m)')
[2975]77    ylabel('frequency')
[2972]78    title('Timestep %d of %d (t=%.2f)'\
[2975]79          %(i, project.number_of_timesteps-1, time[i]))       
[2972]80    raw_input('Next')
81
82
[2967]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
[2972]90
91
92
93
[2967]94show()
95
96
97
98#from pylab import *
99#plot(time, stage)
100#show()
Note: See TracBrowser for help on using the repository browser.