source: anuga_validation/automated_validation_tests/patong_beach_validation/compare_model_timeseries.py @ 7641

Last change on this file since 7641 was 7641, checked in by ole, 13 years ago

Repaired patong validate reading output dir. I still think this is hacky.

File size: 2.1 KB
Line 
1"""Compare selected timeseries from model outputs
2
3Usage:
4python compare_model_timeseries.py swwfile1 swwfile2
5
6Return 0 if timeseries are 'close enough', otherwise return non zero error code
7
8Typically swwfile1 would be model output from unit test and swwfile2 would
9be a reference model.
10"""
11
12import numpy as num
13import sys
14
15# Model specific data
16gauges = {'g10a': [422233.4, 874380.2],
17          'g10b': [422107.9, 873556.8],
18          'g10c': [421966.8, 872890.3],
19          'g10d': [421606.1, 872106.2],
20          'g11a': [422628.2, 873933.2],
21          'g11b': [422716.2, 873420.6],
22          'g11c': [422689.1, 872859.8],
23          'g11d': [422408.7, 871940.3],
24          'g11e': [421751.7, 871097.8],
25          'north': [422572.4, 873992.6],
26          'south': [422004.4, 872014.4]}
27
28
29#---------------------------------------
30
31def usage():
32    print 'Usage:'
33    print 'python compare_model_timeseries.py swwfile1 swwfile2'
34
35
36
37def get_timeseries(sww_filename, gauges):
38    """Generate time series for sww file based on gauges
39    """
40
41    gauge_locations = gauges.values()
42    gauge_names = gauges.keys()
43   
44    f = file_function(sww_filename,
45                      quantities='stage',
46                      interpolation_points=gauge_locations,
47                      use_cache=True,
48                      verbose=True)
49
50    timevector = f.get_time()
51
52    timeseries = {}
53    for k, name in enumerate(gauge_names):
54        model = timeseries[name] = []
55       
56        for t in timevector:
57            model.append(f(t, point_id=k)[0])
58
59
60    return timevector, timeseries
61
62
63
64def compare_timeseries(swwfile1, swwfile2):
65   
66    timevector1, timeseries1 = get_timeseries(swwfile1, gauges)
67    timevector2, timeseries2 = get_timeseries(swwfile2, gauges)   
68
69    msg = 'Time vectors were different in models %s and %s' %\
70          (swwfile1, swwfile2)
71    assert num.allclose(timevector1, timevector2), msg
72
73   
74
75
76if __name__ == '__main__':
77
78    if len(sys.argv) != 3:
79        usage()
80        import sys; sys.exit(-1) 
81   
82    try:
83        res = compare_timeseries(sys.argv[1], sys.argv[2])
84    except:
85        sys.exit(-1)
86    else:
87        sys.exit(0) 
Note: See TracBrowser for help on using the repository browser.