""" Generate report for production run Inputs: report_title: title to be included in tex file production dirs: dictionary of production directories with a association to that simulation run, eg high tide, low tide and MSL. Outputs: * Report generated to scenario_report.tex where the scenario relates the name of the production directory this script is being run from. * figures used for report stored in the report_figure directory NOTE, this directory will need to be committed, as well as the latex files. The report structure is * Introduction * Data sources * Tsunami scenario * Inundation modelling results * Damage modelling * Summary * References * Appendix: Metadata Other files included in document which require manual intervention: * an abstract must be written in abstract.tex * an introduction must be written in introduction.tex; a basic outline and some of the core inputs are already in place * the tsunami-genic event should be discussed in tsunami_scenario.tex * a computational_setup.tex file needs to be written for the particular scenario * the interpretation of the results needs to be written to interpretation.tex * maximum inundation maps need to be included in HAT_map and LAT_map etc. * damage modelling maps need to be included in HAT_damage and LAT_damage etc. * a summary must be written into summary.tex * metadata for the scenario data to be included in metadata.tex May 2006 """ from os import getcwd, sep, altsep, mkdir, access, F_OK import project from pyvolution.util import sww2timeseries, get_gauges_from_file # Derive scenario name p = getcwd().split(sep) scenario = p[-1] # Last element of absolute CWD path scenario_name = scenario.split('_2006')[0] # Strip any text past `_2006` test = scenario_name.split('_') if len(test) <> 1: scenario_name = '%s %s' %(test[0], test[1]) # Create report directory reportdir = getcwd()+sep+'report'+sep if access(reportdir,F_OK) == 0: mkdir (reportdir) # User defined inputs report_title = 'Tsunami impact modelling for the North West shelf: %s' %scenario_name.title() production_dirs = {'20060426_004129': 'Highest Astronomical Tide', '20060426_004237': 'Lowest Astronomical Tide'} max_maps = {'Highest Astronomical Tide': 'HAT_map', 'Lowest Astronomical Tide': 'LAT_map'} damage_maps = {'Highest Astronomical Tide': 'HAT_damage', 'Lowest Astronomical Tide': 'LAT_damage'} # Create sections and graphs for each designated production directory latex_output = [] for label_id in production_dirs.keys(): file_loc = project.outputdir + label_id + sep swwfile = file_loc + project.basename + '.sww' texname = sww2timeseries(swwfile, project.gauge_filename, label_id, report = True, plot_quantity = ['stage', 'velocity'], time_min = None, time_max = None, title_on = False, verbose = True) latex_output.append(texname) # Start report generation report_name = reportdir + scenario + '_report.tex' fid = open(report_name, 'w') s = """ % This is based on an automatically generated file (by make_report.py). % % Manual parts are: % * an abstract must be written in abstract.tex % * an introduction must be written in introduction.tex; a basic outline and % some of the core inputs are already in place % * the tsunami-genic event should be discussed in tsunami_scenario.tex % * an computational_setup.tex file needs to be written for the particular scenario % * the interpretation of the results needs to be written to interpretation.tex % * maximum inundation maps need to be included in HAT_map.tex and LAT_map.tex etc. % * damage modelling maps need to be included in HAT_damage and LAT_damage etc. % * a summary must be written into summary.tex % * metadata for the scenario data to be included in metadata.tex \documentclass{article} \usepackage{ae} % or {zefonts} \usepackage[T1]{fontenc} \usepackage[ansinew]{inputenc} \usepackage{amsmath} \usepackage{amssymb} \usepackage{graphicx} \usepackage{color} \usepackage[colorlinks]{hyperref} \usepackage{lscape} %landcape pages support \usepackage{setspace} \setstretch{1.25} \\topmargin 0pt \oddsidemargin 0pt \evensidemargin 0pt \marginparwidth 0.5pt \\textwidth \paperwidth \\advance\\textwidth -2in """ fid.write(s) s = '\\title{%s} \n' %report_title fid.write(s) s = """ \date{\\today} \\author{Geoscience Australia} \\begin{document} \maketitle \\begin{abstract} \input{abstract} \end{abstract} \\tableofcontents \section{Introduction} \label{sec:intro} \input{introduction} \section{Data sources} \label{sec:data} \input{data} \section{Tsunami scenarios} \label{sec:tsunami_scenarios} \input{tsunami_scenario} \section{Inundation modelling results} \label{sec:results} \input{computational_setup} """ fid.write(s) # Generate latex output for gauges s = '\\begin{table} \label{table:gaugelocations} \n' fid.write(s) s = '\caption{Defined gauge locations for %s study area.}' %scenario_name.title() fid.write(s) s = """ \\begin{center} \\begin{tabular}{|l|l|l|l|}\hline \\bf{Gauge Name} & \\bf{Easting} & \\bf{Northing} & \\bf{Elevation}\\\\ \hline """ fid.write(s) gauges, locations = get_gauges_from_file(project.gauge_filename) for name, gauges in zip(locations, gauges): east = gauges[0] north = gauges[1] elev = 0.0 #elev = gauges[2] s = '%s & %.2f & %.2f & %.2f \\\\ \hline \n' %(name.replace('_',' '), east, north, elev) fid.write(s) s = '\\end{tabular} \n \end{center} \n \end{table} \n \n' fid.write(s) s = '\input{interpretation} \n' fid.write(s) # Assign titles to each production section # Must specify one name per section for i, name in enumerate(production_dirs.keys()): s = '\subsection{%s} \n \n' %production_dirs[name] fid.write(s) s = '\input{%s} \n \clearpage \n \n' %max_maps[production_dirs[name]] fid.write(s) s = '\input{%s} \n \clearpage \n \n' %latex_output[i] fid.write(s) # Closing s = """ \section{Damage modelling} \input{damage} """ fid.write(s) for i, name in enumerate(production_dirs.keys()): s = '\subsection{%s} \n \n' %production_dirs[name] fid.write(s) s = '\input{%s} \n \clearpage \n \n' %damage_maps[production_dirs[name]] fid.write(s) s = """ \section{Summary} \input{summary} \section{References} \input{references} \section{Metadata} \label{sec:metadata} \input{metadata} \end{document} """ fid.write(s)