source: anuga_work/production/onslow_2006/make_report.py @ 4347

Last change on this file since 4347 was 4248, checked in by sexton, 18 years ago

updates

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