source: anuga_validation/okushiri_2005/extract_timeseries.py @ 3883

Last change on this file since 3883 was 3883, checked in by ole, 17 years ago

More cleanup of okushiri prior to release

File size: 6.1 KB
Line 
1"""Verify that simulation produced by ANUGA compares to published
2validation timeseries ch5, ch7 and ch9 as well as the boundary timeseries.
3
4RMS norm is printed and plots are produced.
5"""
6
7from Numeric import allclose
8from Scientific.IO.NetCDF import NetCDFFile
9
10from anuga.abstract_2d_finite_volumes.util import file_function
11from anuga.utilities.numerical_tools import\
12     ensure_numeric, cov, get_machine_precision
13
14import project
15
16try:
17    from pylab import ion, hold, plot, title, legend, xlabel, ylabel, savefig
18except:
19    plotting = False
20else:
21    plotting = True
22
23#plotting = False
24
25#-------------------------
26# Basic data
27#-------------------------
28
29finaltime = 22.5
30timestep = 0.05
31
32gauge_locations = [[0.000, 1.696]] # Boundary gauge
33gauge_locations += [[4.521, 1.196],  [4.521, 1.696],  [4.521, 2.196]] #Ch 5-7-9
34gauge_names = ['Boundary', 'ch5', 'ch7', 'ch9']
35
36validation_data = {}
37for key in gauge_names:
38    validation_data[key] = []
39
40   
41#expected_covariances = {'Boundary': 5.288392008865989e-05,
42#                        'ch5': 1.166748190444681e-04,
43#                        'ch7': 1.121816242516758e-04,
44#                        'ch9': 1.249543278366778e-04}
45
46# old limiters
47#expected_covariances = {'Boundary': 5.288601162783020386e-05,
48#                        'ch5': 1.167001054284431472e-04,
49#                        'ch7': 1.121474766904651861e-04,
50#                        'ch9': 1.249244820847215335e-04}
51#
52#expected_differences = {'Boundary': 8.361144081847830638e-04,
53#                        'ch5': 3.423673831653336816e-03,
54#                        'ch7': 2.799962153549145211e-03,
55#                        'ch9': 3.198560464876740433e-03}
56
57
58#expected_covariances = {'Boundary': 5.288392008865989237e-05,
59#                        'ch5': 1.166748190444680592e-04,
60#                        'ch7': 1.121816242516757850e-04,
61#                        'ch9': 1.249543278366777640e-04}
62#
63#expected_differences = {'Boundary':  8.373150808730501615e-04,
64#                        'ch5': 3.425914311580337875e-03,
65#                        'ch7': 2.802327594773105189e-03,
66#                        'ch9': 3.198733498646373370e-03}
67
68
69expected_covariances = {'Boundary': 5.278365381306500051e-05, 
70                        'ch5': 1.168250251701857399e-04,
71                        'ch7': 1.125146958894896555e-04,
72                        'ch9': 1.248634476898675049e-04}
73
74expected_differences = {'Boundary': 8.502104901511024380e-04, 
75                        'ch5': 3.442302747303998579e-03,
76                        'ch7': 2.802987591027187534e-03,
77                        'ch9': 3.191368834008508938e-03}
78
79
80
81
82
83#-------------------------
84# Read validation dataa
85#-------------------------
86
87print 'Reading', project.boundary_filename
88fid = NetCDFFile(project.boundary_filename, 'r')
89input_time = fid.variables['time'][:]
90validation_data['Boundary'] = fid.variables['stage'][:]
91
92reference_time = []
93fid = open(project.validation_filename)
94lines = fid.readlines()
95fid.close()
96
97for i, line in enumerate(lines[1:]):
98    if i == len(input_time): break
99   
100    fields = line.split()
101
102    reference_time.append(float(fields[0]))    # Record reference time
103    for j, key in enumerate(gauge_names[1:]):  # Omit boundary gauge
104        value = float(fields[1:][j])           # Omit time
105        validation_data[key].append(value/100) # Convert cm2m
106
107
108# Checks
109assert reference_time[0] == 0.0
110assert reference_time[-1] == finaltime
111assert allclose(reference_time, input_time)
112
113for key in gauge_names:
114    validation_data[key] = ensure_numeric(validation_data[key])
115
116
117#--------------------------------------------------
118# Read and interpolate model output
119#--------------------------------------------------
120
121import sys
122if len(sys.argv) > 1:
123    sww_filename = sys.argv[1]
124else:   
125    sww_filename = project.output_filename
126   
127#f = file_function('okushiri_new_limiters.sww',   #The best so far
128#f = file_function('okushiri_as2005_with_mxspd=0.1.sww',
129f = file_function(sww_filename,
130                  quantities='stage',
131                  interpolation_points=gauge_locations,
132                  use_cache=True,
133                  verbose=True)
134
135
136#--------------------------------------------------
137# Compare model output to validation data
138#--------------------------------------------------
139
140eps = get_machine_precision()
141for k, name in enumerate(gauge_names):
142    sqsum = 0
143    denom = 0
144    model = []
145    print 
146    print 'Validating ' + name
147    observed_timeseries = validation_data[name]
148    for i, t in enumerate(reference_time):
149        model.append(f(t, point_id=k)[0])
150
151    # Covariance measures   
152    res = cov(observed_timeseries, model)     
153    print 'Covariance = %.18e' %res
154
155    if res < expected_covariances[name]-eps:
156        print 'Result is better than expected by: %.18e'\
157              %(res-expected_covariances[name])
158        print 'Expect = %.18e' %expected_covariances[name]   
159    elif res > expected_covariances[name]+eps:
160        print 'FAIL: Result is worse than expected by: %.18e'\
161                                %(res-expected_covariances[name])
162        print 'Expect = %.18e' %expected_covariances[name]
163    else:
164        pass
165
166    # Difference measures   
167    res = sum(abs(observed_timeseries-model))/len(model)     
168    print 'Accumulated difference = %.18e' %res
169
170    if res < expected_differences[name]-eps:
171        print 'Result is better than expected by: %.18e'\
172              %(res-expected_differences[name])
173        print 'Expect = %.18e' %expected_differences[name]   
174    elif res > expected_differences[name]+eps:
175        print 'FAIL: Result is worse than expected by: %.18e'\
176                                %(res-expected_differences[name])
177        print 'Expect = %.18e' %expected_differences[name]
178    else:
179        pass
180
181
182
183
184    if plotting is True:
185        ion()
186        hold(False)
187   
188        plot(reference_time, validation_data[name], 'r.-',
189             reference_time, model, 'k-')
190        title('Gauge %s' %name)
191        xlabel('time(s)')
192        ylabel('stage (m)')   
193        legend(('Observed', 'Modelled'), shadow=True, loc='upper left')
194        savefig(name, dpi = 300)       
195
196        raw_input('Next')
197
198
199
Note: See TracBrowser for help on using the repository browser.