1 | """ |
---|
2 | Generate images of "gauges" for production run |
---|
3 | |
---|
4 | Inputs: |
---|
5 | |
---|
6 | production dirs: dictionary of production directories with a |
---|
7 | association to that simulation run, eg high tide, |
---|
8 | low tide and MSL. |
---|
9 | |
---|
10 | Outputs: |
---|
11 | |
---|
12 | * figures used for report stored in the report_figure directory |
---|
13 | |
---|
14 | """ |
---|
15 | |
---|
16 | from os import sep, getcwd, access, F_OK, mkdir, getenv |
---|
17 | #from anuga.abstract_2d_finite_volumes.util import get_data_from_file |
---|
18 | import os |
---|
19 | from Numeric import zeros, array, allclose |
---|
20 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
21 | import project |
---|
22 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, sww2timeseries, get_data_from_file |
---|
23 | |
---|
24 | #makes the csv files from the evolved model |
---|
25 | |
---|
26 | |
---|
27 | home = getenv('INUNDATIONHOME') #Sandpit's parent dir |
---|
28 | #user = get_user_name() |
---|
29 | data = 'data' |
---|
30 | state = 'western_australia' |
---|
31 | scenario_name = 'dampier.sww' |
---|
32 | scenario = 'dampier_tsunami_scenario_2006' |
---|
33 | #scenario = 'test_dampier' |
---|
34 | an = 'anuga' |
---|
35 | bo = 'boundaries' |
---|
36 | |
---|
37 | run_time = '20070312_030201_run' |
---|
38 | production_dirs = {#run_time: 'URS evolved data'#, |
---|
39 | 'boundaries': 'URS boundary condition' |
---|
40 | } |
---|
41 | |
---|
42 | topo = 'topographies' |
---|
43 | out = 'outputs' |
---|
44 | urs = 'urs' |
---|
45 | gridded = '1_10000' |
---|
46 | |
---|
47 | #gauge_filename = os.path.join(home,data,state,scenario,an,out,scenario_name,'.sww') |
---|
48 | #sww_filename ={} |
---|
49 | #swwfiles = {} |
---|
50 | |
---|
51 | #sww_filename[os.path.join(home,data,state,scenario,an,out,run_time,scenario_name)] = run_time |
---|
52 | |
---|
53 | gauge_boundary_filename = 'gauges_time_series_near_top.csv' |
---|
54 | gauge_evolved_filename = 'gauges_time_series_near_top.csv' |
---|
55 | #gauge_boundary_filename = 'gauges_time_series_middle.csv' |
---|
56 | #gauge_evolved_filename = 'gauges_time_series_middle.csv' |
---|
57 | |
---|
58 | #gauge_boundary_filename = 'gauges_time_series_first.csv' |
---|
59 | #gauge_evolved_filename = 'gauges_time_series_first.csv' |
---|
60 | |
---|
61 | boundary_dir_filename = os.path.join(home,data,state,scenario,an,bo,gauge_boundary_filename) |
---|
62 | print'boundary_dir_filename',boundary_dir_filename |
---|
63 | out_dir=os.path.join(home,data,state,scenario,an,out,run_time) |
---|
64 | out_dir_name= out_dir+sep |
---|
65 | |
---|
66 | evolved_dir_filename= os.path.join(home,data,state,scenario,an,out,run_time,gauge_evolved_filename) |
---|
67 | |
---|
68 | #start_screen_catcher(out_dir_name, print_to_screen=True) |
---|
69 | start_screen_catcher(out_dir_name, extra_info='get_time', print_to_screen=True) |
---|
70 | print'boundary_dir_filename',boundary_dir_filename |
---|
71 | print'evolved_dir_filename',evolved_dir_filename |
---|
72 | |
---|
73 | #file_loc = project.output_dir + label_id + sep |
---|
74 | #swwfile = file_loc + project.scenario_name + '.sww' |
---|
75 | #swwfiles[swwfile] = label_id |
---|
76 | print "hella what the!" |
---|
77 | ''' |
---|
78 | #get the timeseries for the evolved sww file |
---|
79 | texname, elev_output = sww2timeseries(sww_filename, |
---|
80 | project.gauges_dir_name_simple, |
---|
81 | production_dirs, |
---|
82 | report = False, |
---|
83 | #reportname = report_name, |
---|
84 | plot_quantity = ['stage', 'momentum'], |
---|
85 | surface = False, |
---|
86 | time_min = None, |
---|
87 | time_max = None, |
---|
88 | title_on = False, |
---|
89 | verbose = True) |
---|
90 | |
---|
91 | ''' |
---|
92 | swwfiles = {} |
---|
93 | |
---|
94 | for label_id in production_dirs.keys(): |
---|
95 | |
---|
96 | if label_id == 'boundaries': |
---|
97 | print 'boundaries' |
---|
98 | # file_loc = project.boundaries_in_dir |
---|
99 | # swwfile = project.boundaries_dir_name3 + '.sww' |
---|
100 | swwfile = project.boundaries_dir_name6+'.sww' |
---|
101 | else: |
---|
102 | # file_loc = project.output_dir + label_id + sep |
---|
103 | file_loc = out_dir_name |
---|
104 | swwfile = file_loc + project.scenario_name + '.sww' |
---|
105 | swwfiles[swwfile] = label_id |
---|
106 | print"swwfiles",swwfiles |
---|
107 | |
---|
108 | texname, elev_output = sww2timeseries(swwfiles, |
---|
109 | project.gauges_dir_name_simple, |
---|
110 | production_dirs, |
---|
111 | report = False, |
---|
112 | #reportname = report_name, |
---|
113 | plot_quantity = ['stage', 'xmomentum', 'ymomentum'], |
---|
114 | # plot_quantity = ['stage', 'momentum'], |
---|
115 | surface = False, |
---|
116 | time_min = None, |
---|
117 | time_max = None, |
---|
118 | title_on = False, |
---|
119 | # use_cache = True, |
---|
120 | verbose = True) |
---|
121 | |
---|
122 | #makes the csv files from the evolved model |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | e_time, e_stage, e_momentum, e_speed, e_elevation = get_data_from_file(evolved_dir_filename) |
---|
127 | |
---|
128 | print'boundary_dir_filename',boundary_dir_filename |
---|
129 | b_time, b_stage, b_momentum, b_speed, b_elevation = get_data_from_file(boundary_dir_filename) |
---|
130 | |
---|
131 | # compares the 2 models |
---|
132 | j=0 |
---|
133 | k=2 |
---|
134 | b_sample = [] |
---|
135 | e_sample = [] |
---|
136 | for i in range(len(b_time)): |
---|
137 | # if j<(len(e_time)) and b_time[i] == e_time[j]: |
---|
138 | if j<(len(e_time)) and k<(len(e_time)) and b_time[i] == e_time[j]: |
---|
139 | b_sample.append(float(b_stage[i])) |
---|
140 | e_sample.append(float(e_stage[k])) |
---|
141 | if k <len(e_time): print 'time e equal b:', b_time[i], b_stage[i],i, j, b_sample[j],e_stage[j], e_stage[k],(len(e_time)-1) |
---|
142 | j = j +1 |
---|
143 | k = k +1 |
---|
144 | |
---|
145 | |
---|
146 | e_stage.pop() |
---|
147 | e_stage.pop() |
---|
148 | |
---|
149 | print len(b_sample), len(e_stage) |
---|
150 | #assert allclose (b_sample, e_sample, 0.5, 0.5) |
---|
151 | |
---|
152 | assert allclose (b_sample, e_stage, 0.5, 0.5) |
---|
153 | print "test successful" |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|