1 | """ |
---|
2 | Generate report for production run |
---|
3 | |
---|
4 | NOTE - this will only work on Windows system (as pylab not installed on unix). |
---|
5 | |
---|
6 | Inputs: |
---|
7 | |
---|
8 | report_title: title to be included in tex file |
---|
9 | production dirs: dictionary of production directories with a |
---|
10 | association to that simulation run, eg high tide, |
---|
11 | low tide and MSL. |
---|
12 | |
---|
13 | |
---|
14 | Outputs: |
---|
15 | |
---|
16 | * Report generated to scenario_report.tex where the scenario relates |
---|
17 | the name of the production directory this script is being run from. |
---|
18 | * figures used for report stored in the report_figure directory |
---|
19 | NOTE, this directory will need to be committed, as well as |
---|
20 | the latex files. |
---|
21 | |
---|
22 | The report structure is |
---|
23 | |
---|
24 | * Executive Summary |
---|
25 | * Introduction |
---|
26 | * Modelling Methodology |
---|
27 | * Tsunami scenario |
---|
28 | * Data sources |
---|
29 | * Inundation modelling results |
---|
30 | * Impact modelling |
---|
31 | * Summary |
---|
32 | * Acknowledgements |
---|
33 | * References |
---|
34 | * Appendix: Metadata |
---|
35 | * Appendix: Inundation model metadata |
---|
36 | * Appendix: Time series outputs |
---|
37 | |
---|
38 | Other files included in document which require manual intervention: |
---|
39 | |
---|
40 | * an abstract must be written in abstract.tex |
---|
41 | * an introduction must be written in introduction.tex; a basic outline and |
---|
42 | some of the core inputs are already in place |
---|
43 | * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
44 | * a discussion of the ANUGA model is required in anuga.tex |
---|
45 | * a computational_setup.tex file needs to be written for the particular scenario |
---|
46 | * the interpretation of the results needs to be written to interpretation.tex |
---|
47 | * maximum inundation map names need to be included in HAT_map and LAT_map etc. |
---|
48 | * damage modelling map names need to be included in HAT_damage and LAT_damage etc. |
---|
49 | * a summary must be written into summary.tex |
---|
50 | * metadata for the scenario data to be included in metadata.tex |
---|
51 | |
---|
52 | May, June 2006 |
---|
53 | """ |
---|
54 | |
---|
55 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
56 | import project |
---|
57 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries, get_gauges_from_file |
---|
58 | |
---|
59 | # Derive scenario name |
---|
60 | p = getcwd().split(sep) |
---|
61 | scenario = p[-1] # Last element of absolute CWD path |
---|
62 | scenario_name = scenario.split('_2006')[0] # Strip any text past `_2006` |
---|
63 | test = scenario_name.split('_') |
---|
64 | if len(test) <> 1: |
---|
65 | scenario_name = '%s %s' %(test[0], test[1]) |
---|
66 | |
---|
67 | # Create report directory |
---|
68 | reportdir = getcwd()+sep+'report07'+sep |
---|
69 | if access(reportdir,F_OK) == 0: |
---|
70 | mkdir (reportdir) |
---|
71 | |
---|
72 | # User defined inputs |
---|
73 | report_title = 'Tsunami impact modelling for %s' %scenario_name.title() |
---|
74 | |
---|
75 | is_parallel = True |
---|
76 | if is_parallel == True: |
---|
77 | nodes = 8 |
---|
78 | |
---|
79 | return_periods = [1000, 100000] |
---|
80 | |
---|
81 | # output directories |
---|
82 | production_dirs_1000 = {'20061116_055135_run': 'Mw 9.0'} # RP 1000 years |
---|
83 | production_dirs_100000 = {'20061116_055135': 'Mw 8.0'} # RP 100000 years |
---|
84 | |
---|
85 | all_prod_dirs = [production_dirs_1000, production_dirs_100000] |
---|
86 | |
---|
87 | max_maps_1000 = {'Mw 6.0': 'mw6_map'} |
---|
88 | max_maps_100000 = {'Mw 9.0': 'mw9_map'} |
---|
89 | |
---|
90 | all_maps = [max_maps_1000, max_maps_100000] |
---|
91 | |
---|
92 | # gauge map names |
---|
93 | gauge_map1 = 'dampier_gauges_1.jpg' |
---|
94 | gauge_map2 = 'dampier_gauges_2.jpg' |
---|
95 | |
---|
96 | # Create sections and graphs for each designated production directory |
---|
97 | latex_output = [] |
---|
98 | report_name = 'latexoutput' |
---|
99 | |
---|
100 | if is_parallel == True: |
---|
101 | |
---|
102 | for j, production_dirs in enumerate(all_prod_dirs): |
---|
103 | |
---|
104 | for i in range(nodes): |
---|
105 | print 'Sending node %d of %d' %(i,nodes) |
---|
106 | reportname = report_name + '%s' + 'rp%s' %(i,j) |
---|
107 | swwfiles = {} |
---|
108 | |
---|
109 | for label_id in production_dirs.keys(): |
---|
110 | file_loc = project.output_dir + label_id + sep |
---|
111 | sww_extra = '_P%s_%s' %(i,nodes) |
---|
112 | swwfile = file_loc + project.scenario_name + sww_extra + '.sww' |
---|
113 | swwfiles[swwfile] = label_id |
---|
114 | |
---|
115 | texname, elev_output = sww2timeseries(swwfiles, |
---|
116 | project.gauge_filename, |
---|
117 | production_dirs, |
---|
118 | report = True, |
---|
119 | reportname = reportname, |
---|
120 | plot_quantity = ['stage', 'speed'], |
---|
121 | generate_fig = True, |
---|
122 | surface = False, |
---|
123 | time_min = None, |
---|
124 | time_max = None, |
---|
125 | time_unit = 'hours', |
---|
126 | title_on = False, |
---|
127 | use_cache = True, |
---|
128 | verbose = True) |
---|
129 | |
---|
130 | latex_output.append(texname) |
---|
131 | |
---|
132 | else: |
---|
133 | |
---|
134 | for i, production_dirs in enumerate(all_prod_dirs): |
---|
135 | |
---|
136 | swwfiles = {} |
---|
137 | reportname = report_name + 'rp%s' %(i) |
---|
138 | |
---|
139 | for label_id in production_dirs.keys(): |
---|
140 | |
---|
141 | file_loc = project.output_dir + label_id + sep |
---|
142 | swwfile = file_loc + project.scenario_name + '.sww' |
---|
143 | swwfiles[swwfile] = label_id |
---|
144 | |
---|
145 | texname, elev_output = sww2timeseries(swwfiles, |
---|
146 | project.gauge_filename, |
---|
147 | production_dirs, |
---|
148 | report = True, |
---|
149 | reportname = reportname, |
---|
150 | plot_quantity = ['stage', 'speed'], |
---|
151 | generate_fig = True, |
---|
152 | surface = False, |
---|
153 | time_min = None, |
---|
154 | time_max = None, |
---|
155 | time_unit ='hours', |
---|
156 | title_on = False, |
---|
157 | use_cache = True, |
---|
158 | verbose = True) |
---|
159 | latex_output.append(texname) |
---|
160 | |
---|
161 | # Start report generation |
---|
162 | # Future: generate_report(reportdir, scenario, report_title, |
---|
163 | # project.gauge_filename, max_maps, damage_maps, production_dirs, latex_output) |
---|
164 | report_name = reportdir + scenario + '_report.tex' |
---|
165 | fid = open(report_name, 'w') |
---|
166 | |
---|
167 | s = """ |
---|
168 | % This is based on an automatically generated file (by make_report.py). |
---|
169 | % |
---|
170 | % Manual parts are: |
---|
171 | % * an abstract must be written in abstract.tex |
---|
172 | % * an introduction must be written in introduction.tex; a basic outline and |
---|
173 | % some of the core inputs are already in place |
---|
174 | % * outline of the modelling methodology provided in modelling_methodology.tex |
---|
175 | % * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
176 | % * an computational_setup.tex file needs to be written for the particular scenario |
---|
177 | % * the interpretation of the results needs to be written to interpretation.tex |
---|
178 | % * maximum inundation maps need to be included in HAT_map.tex and LAT_map.tex etc. |
---|
179 | % * damage modelling maps need to be included in HAT_damage and LAT_damage etc. |
---|
180 | % * a summary must be written into summary.tex |
---|
181 | % * metadata for the scenario data to be included in metadata.tex |
---|
182 | |
---|
183 | \documentclass{article} |
---|
184 | |
---|
185 | \usepackage{ae} % or {zefonts} |
---|
186 | \usepackage[T1]{fontenc} |
---|
187 | \usepackage[ansinew]{inputenc} |
---|
188 | \usepackage{amsmath} |
---|
189 | \usepackage{amssymb} |
---|
190 | \usepackage{graphicx} |
---|
191 | \usepackage{color} |
---|
192 | \usepackage[colorlinks]{hyperref} |
---|
193 | \usepackage{lscape} %landcape pages support |
---|
194 | \usepackage{setspace} |
---|
195 | \usepackage{rotating} |
---|
196 | \usepackage{pdfpages} |
---|
197 | \include{appendix} |
---|
198 | \setstretch{1.25} |
---|
199 | \\topmargin 0pt |
---|
200 | \oddsidemargin 0pt |
---|
201 | \evensidemargin 0pt |
---|
202 | \marginparwidth 0.5pt |
---|
203 | \\textwidth \paperwidth |
---|
204 | \\advance\\textwidth -2in |
---|
205 | |
---|
206 | """ |
---|
207 | fid.write(s) |
---|
208 | |
---|
209 | s = """ |
---|
210 | \date{\\today} |
---|
211 | %\\author{Geoscience Australia} |
---|
212 | |
---|
213 | \\begin{document} |
---|
214 | \\title{ |
---|
215 | \\begin{figure}[hbt] |
---|
216 | \centerline{ \includegraphics[scale=0.4]{../report_figures/GAlogo.jpg}} |
---|
217 | \end{figure} |
---|
218 | """ |
---|
219 | fid.write(s) |
---|
220 | s = '%s} '%report_title |
---|
221 | fid.write(s) |
---|
222 | |
---|
223 | s = """ |
---|
224 | \maketitle |
---|
225 | |
---|
226 | \section{Executive Summary} |
---|
227 | \label{sec:execsum} |
---|
228 | \input{execsum} |
---|
229 | |
---|
230 | \clearpage |
---|
231 | |
---|
232 | \\tableofcontents |
---|
233 | |
---|
234 | \section{Introduction} |
---|
235 | \label{sec:intro} |
---|
236 | \input{introduction} |
---|
237 | |
---|
238 | \section{Modelling methodology} |
---|
239 | \label{sec:methodology} |
---|
240 | \input{modelling_methodology} |
---|
241 | |
---|
242 | \section{Tsunami scenarios} |
---|
243 | \label{sec:tsunamiscenario} |
---|
244 | \input{tsunami_scenario} |
---|
245 | |
---|
246 | \section{Data sources} |
---|
247 | \label{sec:data} |
---|
248 | \input{data} |
---|
249 | |
---|
250 | \section{Inundation modelling results} |
---|
251 | \label{sec:results} |
---|
252 | |
---|
253 | """ |
---|
254 | fid.write(s) |
---|
255 | |
---|
256 | s = '\input{interpretation} \n' |
---|
257 | fid.write(s) |
---|
258 | |
---|
259 | # Assign titles to each production section |
---|
260 | # Must specify one name per section |
---|
261 | for i, max_maps in enumerate(all_maps): |
---|
262 | |
---|
263 | s = '\subsection{Return Period: %s years} \n \n' %return_periods[i] |
---|
264 | fid.write(s) |
---|
265 | |
---|
266 | production_dirs = all_prod_dirs[i] |
---|
267 | for name in enumerate(production_dirs.keys()): |
---|
268 | s = '\input{%s} \n \clearpage \n \n' %max_maps[production_dirs[name]] |
---|
269 | fid.write(s) |
---|
270 | |
---|
271 | # Generate latex output for location points |
---|
272 | s = '\\begin{table} \\begin{center} \n' |
---|
273 | fid.write(s) |
---|
274 | s = '\caption{Defined point locations for %s study area.}' %scenario_name.title() |
---|
275 | fid.write(s) |
---|
276 | s = """ |
---|
277 | \label{table:locations} |
---|
278 | \\begin{tabular}{|l|l|l|l|}\hline |
---|
279 | \\bf{Point Name} & \\bf{Easting} & \\bf{Northing} & \\bf{Elevation (m)}\\\\ \hline |
---|
280 | """ |
---|
281 | fid.write(s) |
---|
282 | |
---|
283 | gauges, locations, elevation = get_gauges_from_file(project.gauge_filename) |
---|
284 | |
---|
285 | for name, gauges, elev in zip(locations, gauges, elevation): |
---|
286 | east = gauges[0] |
---|
287 | north = gauges[1] |
---|
288 | s = '%s & %.2f & %.2f & %.2f \\\\ \hline \n' %(name.replace('_',' '), east, north, elev) |
---|
289 | fid.write(s) |
---|
290 | |
---|
291 | s = '\\end{tabular} \n \end{center} \n \end{table} \n \n' |
---|
292 | fid.write(s) |
---|
293 | |
---|
294 | #s = '\\begin{figure}[h] \n \centerline{ \includegraphics[width=\paperwidth]{../report_figures/%s}}' %gauge_map |
---|
295 | s = '\\begin{figure}[h] \n \centerline{ \includegraphics[scale=0.7]{../report_figures/%s}}' %gauge_map |
---|
296 | fid.write(s) |
---|
297 | |
---|
298 | s = """ |
---|
299 | \caption{Point locations used for Dampier study.} |
---|
300 | \label{fig:points} |
---|
301 | \end{figure} |
---|
302 | |
---|
303 | \clearpage |
---|
304 | """ |
---|
305 | fid.write(s) |
---|
306 | |
---|
307 | # Closing |
---|
308 | |
---|
309 | s = """ |
---|
310 | \section{Impact modelling} |
---|
311 | \label{sec:impact} |
---|
312 | \input{damage} |
---|
313 | """ |
---|
314 | fid.write(s) |
---|
315 | |
---|
316 | s = """ |
---|
317 | \section{Summary} |
---|
318 | \label{sec:summary} |
---|
319 | \input{summary} |
---|
320 | |
---|
321 | \section{Acknowledgements} |
---|
322 | \input{acknowledgements} |
---|
323 | |
---|
324 | \input{references} |
---|
325 | |
---|
326 | \clearpage |
---|
327 | |
---|
328 | \\appendix |
---|
329 | |
---|
330 | \section{ANUGA modelling parameters} |
---|
331 | \label{sec:anugasetup} |
---|
332 | \input{anuga_setup} |
---|
333 | |
---|
334 | \clearpage |
---|
335 | |
---|
336 | \section{Metadata} |
---|
337 | \label{sec:metadata} |
---|
338 | \input{metadata} |
---|
339 | |
---|
340 | \clearpage |
---|
341 | |
---|
342 | \section{Time series} |
---|
343 | \label{sec:timeseries} |
---|
344 | \input{timeseriesdiscussion} |
---|
345 | \clearpage |
---|
346 | """ |
---|
347 | fid.write(s) |
---|
348 | |
---|
349 | for i in range(len(latex_output)): |
---|
350 | if latex_output[i] <> '': |
---|
351 | s = '\subsection{Return Period: %s years} \n' %return_periods[i] |
---|
352 | fid.write(s) |
---|
353 | s = '\input{%s} \n \clearpage \n \n' %latex_output[i] |
---|
354 | fid.write(s) |
---|
355 | |
---|
356 | s=""" |
---|
357 | \section{Damage modelling inputs} |
---|
358 | \label{sec:damageinputs} |
---|
359 | \input{damage_inputs} |
---|
360 | |
---|
361 | \end{document} |
---|
362 | """ |
---|
363 | fid.write(s) |
---|