[3005] | 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 |
---|
[3082] | 23 | * Tsunami scenario |
---|
| 24 | * Inundation model |
---|
[3005] | 25 | * Data sources |
---|
[3082] | 26 | * Modelling results |
---|
| 27 | * Impact modelling |
---|
[3005] | 28 | * Summary |
---|
| 29 | * References |
---|
| 30 | * Appendix: Metadata |
---|
[3082] | 31 | * Appendix: Time series outputs |
---|
[3005] | 32 | |
---|
| 33 | Other files included in document which require manual intervention: |
---|
| 34 | |
---|
| 35 | * an abstract must be written in abstract.tex |
---|
| 36 | * an introduction must be written in introduction.tex; a basic outline and |
---|
| 37 | some of the core inputs are already in place |
---|
[3082] | 38 | * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
| 39 | * a discussion of the ANUGA model is required in anuga.tex |
---|
[3005] | 40 | * a computational_setup.tex file needs to be written for the particular scenario |
---|
| 41 | * the interpretation of the results needs to be written to interpretation.tex |
---|
[3082] | 42 | * maximum inundation map names need to be included in HAT_map and LAT_map etc. |
---|
| 43 | * damage modelling map names need to be included in HAT_damage and LAT_damage etc. |
---|
[3005] | 44 | * a summary must be written into summary.tex |
---|
| 45 | * metadata for the scenario data to be included in metadata.tex |
---|
| 46 | |
---|
[3082] | 47 | May, June 2006 |
---|
[3005] | 48 | """ |
---|
| 49 | |
---|
| 50 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
| 51 | import project |
---|
| 52 | from pyvolution.util import sww2timeseries, get_gauges_from_file |
---|
| 53 | |
---|
| 54 | # Derive scenario name |
---|
| 55 | p = getcwd().split(sep) |
---|
| 56 | scenario = p[-1] # Last element of absolute CWD path |
---|
| 57 | scenario_name = scenario.split('_2006')[0] # Strip any text past `_2006` |
---|
| 58 | test = scenario_name.split('_') |
---|
| 59 | if len(test) <> 1: |
---|
| 60 | scenario_name = '%s %s' %(test[0], test[1]) |
---|
| 61 | |
---|
| 62 | # Create report directory |
---|
| 63 | reportdir = getcwd()+sep+'report'+sep |
---|
| 64 | if access(reportdir,F_OK) == 0: |
---|
| 65 | mkdir (reportdir) |
---|
| 66 | |
---|
| 67 | # User defined inputs |
---|
| 68 | report_title = 'Tsunami impact modelling for the North West shelf: %s' %scenario_name.title() |
---|
| 69 | |
---|
[3082] | 70 | production_dirs = {'20060426_004129': '1.5 AHD', |
---|
| 71 | '20060426_004237': '-1.5 AHD', |
---|
| 72 | '20060515_001733': '0 AHD'} |
---|
[3005] | 73 | |
---|
[3082] | 74 | max_maps = {'1.5 AHD': 'HAT_map', |
---|
| 75 | '-1.5 AHD': 'LAT_map', |
---|
| 76 | '0 AHD': 'MSL_map'} |
---|
[3005] | 77 | |
---|
[3136] | 78 | #damage_maps = {'1.5 AHD': 'HAT_damage', |
---|
| 79 | # '-1.5 AHD': 'LAT_damage', |
---|
| 80 | # '0 AHD': 'MSL_damage'} |
---|
[3082] | 81 | |
---|
| 82 | gauge_map = 'onslow_gauge_map.jpg' |
---|
| 83 | |
---|
[3005] | 84 | # Create sections and graphs for each designated production directory |
---|
| 85 | latex_output = [] |
---|
[3082] | 86 | swwfiles = {} |
---|
[3005] | 87 | for label_id in production_dirs.keys(): |
---|
| 88 | |
---|
| 89 | file_loc = project.outputdir + label_id + sep |
---|
| 90 | swwfile = file_loc + project.basename + '.sww' |
---|
[3082] | 91 | swwfiles[swwfile] = label_id |
---|
[3005] | 92 | |
---|
[3082] | 93 | texname = sww2timeseries(swwfiles, |
---|
| 94 | project.gauge_filename, |
---|
| 95 | production_dirs, |
---|
| 96 | report = True, |
---|
| 97 | plot_quantity = ['stage', 'speed'], |
---|
| 98 | time_min = None, |
---|
| 99 | time_max = None, |
---|
| 100 | title_on = False, |
---|
| 101 | verbose = True) |
---|
[3005] | 102 | |
---|
[3082] | 103 | latex_output.append(texname) |
---|
[3005] | 104 | |
---|
| 105 | # Start report generation |
---|
[3082] | 106 | # Future: generate_report(reportdir, scenario, report_title, |
---|
| 107 | # project.gauge_filename, max_maps, damage_maps, production_dirs, latex_output) |
---|
[3005] | 108 | report_name = reportdir + scenario + '_report.tex' |
---|
| 109 | fid = open(report_name, 'w') |
---|
| 110 | |
---|
| 111 | s = """ |
---|
| 112 | % This is based on an automatically generated file (by make_report.py). |
---|
| 113 | % |
---|
| 114 | % Manual parts are: |
---|
| 115 | % * an abstract must be written in abstract.tex |
---|
| 116 | % * an introduction must be written in introduction.tex; a basic outline and |
---|
| 117 | % some of the core inputs are already in place |
---|
| 118 | % * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
| 119 | % * an computational_setup.tex file needs to be written for the particular scenario |
---|
| 120 | % * the interpretation of the results needs to be written to interpretation.tex |
---|
| 121 | % * maximum inundation maps need to be included in HAT_map.tex and LAT_map.tex etc. |
---|
| 122 | % * damage modelling maps need to be included in HAT_damage and LAT_damage etc. |
---|
| 123 | % * a summary must be written into summary.tex |
---|
| 124 | % * metadata for the scenario data to be included in metadata.tex |
---|
| 125 | |
---|
| 126 | \documentclass{article} |
---|
| 127 | |
---|
| 128 | \usepackage{ae} % or {zefonts} |
---|
| 129 | \usepackage[T1]{fontenc} |
---|
| 130 | \usepackage[ansinew]{inputenc} |
---|
| 131 | \usepackage{amsmath} |
---|
| 132 | \usepackage{amssymb} |
---|
| 133 | \usepackage{graphicx} |
---|
| 134 | \usepackage{color} |
---|
| 135 | \usepackage[colorlinks]{hyperref} |
---|
| 136 | \usepackage{lscape} %landcape pages support |
---|
| 137 | \usepackage{setspace} |
---|
| 138 | \setstretch{1.25} |
---|
| 139 | \\topmargin 0pt |
---|
| 140 | \oddsidemargin 0pt |
---|
| 141 | \evensidemargin 0pt |
---|
| 142 | \marginparwidth 0.5pt |
---|
| 143 | \\textwidth \paperwidth |
---|
| 144 | \\advance\\textwidth -2in |
---|
| 145 | |
---|
| 146 | """ |
---|
| 147 | fid.write(s) |
---|
| 148 | |
---|
| 149 | s = '\\title{%s} \n' %report_title |
---|
| 150 | fid.write(s) |
---|
| 151 | |
---|
| 152 | s = """ |
---|
| 153 | \date{\\today} |
---|
| 154 | \\author{Geoscience Australia} |
---|
| 155 | \\begin{document} |
---|
| 156 | \maketitle |
---|
| 157 | |
---|
| 158 | \\begin{abstract} |
---|
| 159 | \input{abstract} |
---|
| 160 | \end{abstract} |
---|
| 161 | |
---|
| 162 | \\tableofcontents |
---|
| 163 | |
---|
| 164 | \section{Introduction} |
---|
| 165 | \label{sec:intro} |
---|
| 166 | \input{introduction} |
---|
[3082] | 167 | |
---|
| 168 | \section{Tsunami scenarios} |
---|
[3094] | 169 | \label{sec:tsunamiscenario} |
---|
[3082] | 170 | \input{tsunami_scenario} |
---|
| 171 | |
---|
[3136] | 172 | \section{Inundation model} |
---|
[3082] | 173 | \label{sec:anuga} |
---|
| 174 | \input{anuga} |
---|
| 175 | \input{computational_setup} |
---|
| 176 | |
---|
[3005] | 177 | \section{Data sources} |
---|
| 178 | \label{sec:data} |
---|
| 179 | \input{data} |
---|
| 180 | |
---|
[3082] | 181 | \section{Modelling results} |
---|
[3005] | 182 | \label{sec:results} |
---|
[3082] | 183 | |
---|
[3005] | 184 | """ |
---|
| 185 | fid.write(s) |
---|
| 186 | |
---|
[3082] | 187 | # Generate latex output for location points |
---|
| 188 | s = '\\begin{table} \label{table:locations} \n' |
---|
[3005] | 189 | fid.write(s) |
---|
[3082] | 190 | s = '\caption{Defined point locations for %s study area.}' %report_title |
---|
[3005] | 191 | fid.write(s) |
---|
| 192 | s = """ |
---|
[3007] | 193 | \\begin{center} |
---|
[3005] | 194 | \\begin{tabular}{|l|l|l|l|}\hline |
---|
[3082] | 195 | \\bf{Point Name} & \\bf{Easting} & \\bf{Northing} & \\bf{Elevation}\\\\ \hline |
---|
[3005] | 196 | """ |
---|
| 197 | fid.write(s) |
---|
| 198 | |
---|
[3082] | 199 | gauges, locations, elevation = get_gauges_from_file(project.gauge_filename) |
---|
[3005] | 200 | |
---|
[3082] | 201 | for name, gauges, elev in zip(locations, gauges, elevation): |
---|
[3005] | 202 | east = gauges[0] |
---|
| 203 | north = gauges[1] |
---|
| 204 | s = '%s & %.2f & %.2f & %.2f \\\\ \hline \n' %(name.replace('_',' '), east, north, elev) |
---|
| 205 | fid.write(s) |
---|
| 206 | |
---|
| 207 | s = '\\end{tabular} \n \end{center} \n \end{table} \n \n' |
---|
| 208 | fid.write(s) |
---|
| 209 | |
---|
[3082] | 210 | s = '\\begin{figure}[hbt] \n \centerline{ \includegraphics[width=150mm, height=100mm]{../report_figures/%s}}' %gauge_map |
---|
| 211 | fid.write(s) |
---|
| 212 | |
---|
| 213 | s = """ |
---|
| 214 | \caption{Point locations used for Onslow study.} |
---|
| 215 | \label{fig:points} |
---|
| 216 | \end{figure} |
---|
| 217 | """ |
---|
| 218 | fid.write(s) |
---|
| 219 | |
---|
[3005] | 220 | s = '\input{interpretation} \n' |
---|
| 221 | fid.write(s) |
---|
| 222 | |
---|
[3082] | 223 | # Assign titles to each production section |
---|
[3005] | 224 | # Must specify one name per section |
---|
| 225 | for i, name in enumerate(production_dirs.keys()): |
---|
[3082] | 226 | # |
---|
| 227 | # s = '\subsection{%s} \n \n' %production_dirs[name] |
---|
| 228 | # fid.write(s) |
---|
[3005] | 229 | |
---|
| 230 | s = '\input{%s} \n \clearpage \n \n' %max_maps[production_dirs[name]] |
---|
| 231 | fid.write(s) |
---|
| 232 | |
---|
| 233 | # Closing |
---|
| 234 | |
---|
| 235 | s = """ |
---|
[3136] | 236 | \section{Impact modelling} |
---|
| 237 | \label{sec:impact} |
---|
[3005] | 238 | \input{damage} |
---|
| 239 | """ |
---|
| 240 | fid.write(s) |
---|
| 241 | |
---|
[3136] | 242 | #for i, name in enumerate(production_dirs.keys()): |
---|
[3005] | 243 | |
---|
[3136] | 244 | # s = '\input{%s} \n \clearpage \n \n' %damage_maps[production_dirs[name]] |
---|
| 245 | # fid.write(s) |
---|
[3005] | 246 | |
---|
| 247 | s = """ |
---|
| 248 | \section{Summary} |
---|
| 249 | \input{summary} |
---|
| 250 | |
---|
| 251 | \section{References} |
---|
[3015] | 252 | \input{references} |
---|
| 253 | |
---|
[3005] | 254 | \section{Metadata} |
---|
| 255 | \label{sec:metadata} |
---|
| 256 | \input{metadata} |
---|
| 257 | |
---|
[3082] | 258 | \section{Time series} |
---|
| 259 | \label{sec:timeseries} |
---|
[3005] | 260 | """ |
---|
| 261 | fid.write(s) |
---|
[3082] | 262 | |
---|
| 263 | s = '\input{%s} \n \clearpage \n \n' %latex_output[0] |
---|
| 264 | fid.write(s) |
---|
| 265 | |
---|
| 266 | s = '\end{document}' |
---|
| 267 | fid.write(s) |
---|