1 | """ |
---|
2 | Generate report for production run |
---|
3 | |
---|
4 | Inputs: |
---|
5 | |
---|
6 | report_title: title to be included in tex file |
---|
7 | production dirs: dictionary of production directories with a |
---|
8 | association to that simulation run, eg high tide, |
---|
9 | low tide and MSL. |
---|
10 | |
---|
11 | |
---|
12 | Outputs: |
---|
13 | |
---|
14 | * Report generated to scenario_report.tex where the scenario relates |
---|
15 | the name of the production directory this script is being run from. |
---|
16 | * figures used for report stored in the report_figure directory |
---|
17 | NOTE, this directory will need to be committed, as well as |
---|
18 | the latex files. |
---|
19 | |
---|
20 | The report structure is |
---|
21 | |
---|
22 | * Introduction |
---|
23 | * Data sources |
---|
24 | * Tsunami scenario |
---|
25 | * Inundation modelling results |
---|
26 | * Damage modelling |
---|
27 | * Summary |
---|
28 | * References |
---|
29 | * Appendix: Metadata |
---|
30 | |
---|
31 | Other files included in document which require manual intervention: |
---|
32 | |
---|
33 | * an abstract must be written in abstract.tex |
---|
34 | * an introduction must be written in introduction.tex; a basic outline and |
---|
35 | some of the core inputs are already in place |
---|
36 | * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
37 | * a computational_setup.tex file needs to be written for the particular scenario |
---|
38 | * the interpretation of the results needs to be written to interpretation.tex |
---|
39 | * maximum inundation maps need to be included in HAT_map and LAT_map etc. |
---|
40 | * damage modelling maps need to be included in HAT_damage and LAT_damage etc. |
---|
41 | * a summary must be written into summary.tex |
---|
42 | * metadata for the scenario data to be included in metadata.tex |
---|
43 | |
---|
44 | May 2006 |
---|
45 | """ |
---|
46 | |
---|
47 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
48 | import project |
---|
49 | from pyvolution.util import sww2timeseries, get_gauges_from_file |
---|
50 | |
---|
51 | # Derive scenario name |
---|
52 | p = getcwd().split(sep) |
---|
53 | scenario = p[-1] # Last element of absolute CWD path |
---|
54 | scenario_name = scenario.split('_2006')[0] # Strip any text past `_2006` |
---|
55 | test = scenario_name.split('_') |
---|
56 | if len(test) <> 1: |
---|
57 | scenario_name = '%s %s' %(test[0], test[1]) |
---|
58 | |
---|
59 | # Create report directory |
---|
60 | reportdir = getcwd()+sep+'report'+sep |
---|
61 | if access(reportdir,F_OK) == 0: |
---|
62 | mkdir (reportdir) |
---|
63 | |
---|
64 | # User defined inputs |
---|
65 | report_title = 'Tsunami impact modelling for the North West shelf: %s' %scenario_name.title() |
---|
66 | |
---|
67 | production_dirs = {'20060426_004129': 'Highest Astronomical Tide', |
---|
68 | '20060426_004237': 'Lowest Astronomical Tide'} |
---|
69 | |
---|
70 | max_maps = {'Highest Astronomical Tide': 'HAT_map', |
---|
71 | 'Lowest Astronomical Tide': 'LAT_map'} |
---|
72 | |
---|
73 | damage_maps = {'Highest Astronomical Tide': 'HAT_damage', |
---|
74 | 'Lowest Astronomical Tide': 'LAT_damage'} |
---|
75 | |
---|
76 | # Create sections and graphs for each designated production directory |
---|
77 | latex_output = [] |
---|
78 | for label_id in production_dirs.keys(): |
---|
79 | |
---|
80 | file_loc = project.outputdir + label_id + sep |
---|
81 | swwfile = file_loc + project.basename + '.sww' |
---|
82 | |
---|
83 | texname = sww2timeseries(swwfile, |
---|
84 | project.gauge_filename, |
---|
85 | label_id, |
---|
86 | report = True, |
---|
87 | plot_quantity = ['stage', 'velocity'], |
---|
88 | time_min = None, |
---|
89 | time_max = None, |
---|
90 | title_on = False, |
---|
91 | verbose = True) |
---|
92 | |
---|
93 | latex_output.append(texname) |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | # Start report generation |
---|
98 | report_name = reportdir + scenario + '_report.tex' |
---|
99 | fid = open(report_name, 'w') |
---|
100 | |
---|
101 | s = """ |
---|
102 | % This is based on an automatically generated file (by make_report.py). |
---|
103 | % |
---|
104 | % Manual parts are: |
---|
105 | % * an abstract must be written in abstract.tex |
---|
106 | % * an introduction must be written in introduction.tex; a basic outline and |
---|
107 | % some of the core inputs are already in place |
---|
108 | % * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
109 | % * an computational_setup.tex file needs to be written for the particular scenario |
---|
110 | % * the interpretation of the results needs to be written to interpretation.tex |
---|
111 | % * maximum inundation maps need to be included in HAT_map.tex and LAT_map.tex etc. |
---|
112 | % * damage modelling maps need to be included in HAT_damage and LAT_damage etc. |
---|
113 | % * a summary must be written into summary.tex |
---|
114 | % * metadata for the scenario data to be included in metadata.tex |
---|
115 | |
---|
116 | \documentclass{article} |
---|
117 | |
---|
118 | \usepackage{ae} % or {zefonts} |
---|
119 | \usepackage[T1]{fontenc} |
---|
120 | \usepackage[ansinew]{inputenc} |
---|
121 | \usepackage{amsmath} |
---|
122 | \usepackage{amssymb} |
---|
123 | \usepackage{graphicx} |
---|
124 | \usepackage{color} |
---|
125 | \usepackage[colorlinks]{hyperref} |
---|
126 | \usepackage{lscape} %landcape pages support |
---|
127 | \usepackage{setspace} |
---|
128 | \setstretch{1.25} |
---|
129 | \\topmargin 0pt |
---|
130 | \oddsidemargin 0pt |
---|
131 | \evensidemargin 0pt |
---|
132 | \marginparwidth 0.5pt |
---|
133 | \\textwidth \paperwidth |
---|
134 | \\advance\\textwidth -2in |
---|
135 | |
---|
136 | """ |
---|
137 | fid.write(s) |
---|
138 | |
---|
139 | s = '\\title{%s} \n' %report_title |
---|
140 | fid.write(s) |
---|
141 | |
---|
142 | s = """ |
---|
143 | \date{\\today} |
---|
144 | \\author{Geoscience Australia} |
---|
145 | \\begin{document} |
---|
146 | \maketitle |
---|
147 | |
---|
148 | \\begin{abstract} |
---|
149 | \input{abstract} |
---|
150 | \end{abstract} |
---|
151 | |
---|
152 | \\tableofcontents |
---|
153 | |
---|
154 | \section{Introduction} |
---|
155 | \label{sec:intro} |
---|
156 | \input{introduction} |
---|
157 | |
---|
158 | \section{Data sources} |
---|
159 | \label{sec:data} |
---|
160 | \input{data} |
---|
161 | |
---|
162 | \section{Tsunami scenarios} |
---|
163 | \label{sec:tsunami_scenarios} |
---|
164 | \input{tsunami_scenario} |
---|
165 | |
---|
166 | \section{Inundation modelling results} |
---|
167 | \label{sec:results} |
---|
168 | \input{computational_setup} |
---|
169 | |
---|
170 | """ |
---|
171 | fid.write(s) |
---|
172 | |
---|
173 | # Generate latex output for gauges |
---|
174 | s = '\\begin{table} \label{table:gaugelocations} \n' |
---|
175 | fid.write(s) |
---|
176 | s = '\caption{Defined gauge locations for %s study area.}' %scenario_name.title() |
---|
177 | fid.write(s) |
---|
178 | s = """ |
---|
179 | \\begin{center} |
---|
180 | \\begin{tabular}{|l|l|l|l|}\hline |
---|
181 | \\bf{Gauge Name} & \\bf{Easting} & \\bf{Northing} & \\bf{Elevation}\\\\ \hline |
---|
182 | """ |
---|
183 | fid.write(s) |
---|
184 | |
---|
185 | gauges, locations = get_gauges_from_file(project.gauge_filename) |
---|
186 | |
---|
187 | for name, gauges in zip(locations, gauges): |
---|
188 | east = gauges[0] |
---|
189 | north = gauges[1] |
---|
190 | elev = 0.0 |
---|
191 | #elev = gauges[2] |
---|
192 | s = '%s & %.2f & %.2f & %.2f \\\\ \hline \n' %(name.replace('_',' '), east, north, elev) |
---|
193 | fid.write(s) |
---|
194 | |
---|
195 | s = '\\end{tabular} \n \end{center} \n \end{table} \n \n' |
---|
196 | fid.write(s) |
---|
197 | |
---|
198 | s = '\input{interpretation} \n' |
---|
199 | fid.write(s) |
---|
200 | |
---|
201 | # Assign titles to each production section |
---|
202 | # Must specify one name per section |
---|
203 | for i, name in enumerate(production_dirs.keys()): |
---|
204 | |
---|
205 | s = '\subsection{%s} \n \n' %production_dirs[name] |
---|
206 | fid.write(s) |
---|
207 | |
---|
208 | s = '\input{%s} \n \clearpage \n \n' %max_maps[production_dirs[name]] |
---|
209 | fid.write(s) |
---|
210 | |
---|
211 | s = '\input{%s} \n \clearpage \n \n' %latex_output[i] |
---|
212 | fid.write(s) |
---|
213 | |
---|
214 | # Closing |
---|
215 | |
---|
216 | s = """ |
---|
217 | \section{Damage modelling} |
---|
218 | \input{damage} |
---|
219 | """ |
---|
220 | fid.write(s) |
---|
221 | |
---|
222 | for i, name in enumerate(production_dirs.keys()): |
---|
223 | |
---|
224 | s = '\subsection{%s} \n \n' %production_dirs[name] |
---|
225 | fid.write(s) |
---|
226 | |
---|
227 | s = '\input{%s} \n \clearpage \n \n' %damage_maps[production_dirs[name]] |
---|
228 | fid.write(s) |
---|
229 | |
---|
230 | |
---|
231 | s = """ |
---|
232 | \section{Summary} |
---|
233 | \input{summary} |
---|
234 | |
---|
235 | \section{References} |
---|
236 | \input{references} |
---|
237 | |
---|
238 | \section{Metadata} |
---|
239 | \label{sec:metadata} |
---|
240 | \input{metadata} |
---|
241 | |
---|
242 | \end{document} |
---|
243 | """ |
---|
244 | fid.write(s) |
---|