Index: anuga_work/production/newcastle_2006/make_report.py
===================================================================
--- anuga_work/production/newcastle_2006/make_report.py	(revision 4580)
+++ anuga_work/production/newcastle_2006/make_report.py	(revision 4580)
@@ -0,0 +1,343 @@
+"""
+Generate report for production run
+
+NOTE - this will only work on Windows system (as pylab not installed on unix).
+
+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
+
+* Executive Summary
+* Introduction
+* Modelling Methodology
+* Tsunami scenario
+* Data sources
+* Inundation model
+* Inundation modelling results
+* Impact modelling
+* Summary
+* Acknowledgements
+* References
+* Appendix: Metadata
+* Appendix: Time series outputs
+
+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 discussion of the ANUGA model is required in anuga.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 map names need to be included in HAT_map and LAT_map etc.
+* damage modelling map names 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, June 2006                    
+"""
+
+from os import getcwd, sep, altsep, mkdir, access, F_OK
+import project_slide
+from anuga.abstract_2d_finite_volumes.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 inundation modelling for the NSW coastline: Generation by Submarine Mass Failures' 
+
+# WA DLI data
+production_dirs = {#'20061211_071516': 'Area B - Bulli'}
+                   #'20061212_012705': 'Area B - Shovel',
+                   #'20061212_064807': 'Area B - Yacaaba',
+                   #'20061211_060105': 'Area A - Bulli'}
+                   #'20061212_012715': 'Area A - Shovel',
+                   #'20061212_064735': 'Area A - Yacaaba',
+                   '20061211_073709': 'Area C - Bulli'}
+                   #'20061212_012802': 'Area C - Shovel',
+                   #'20061212_064757': 'Area C - Yacaaba'}
+
+do_timeseries = True
+
+is_parallel = False
+if is_parallel == True:
+    nodes = 8
+
+max_maps = {'Area A - Bulli': 'bulli_A_map',
+            'Area A - Shovel': 'bulli_B_map',
+            'Area A - Yacaaba': 'bulli_C_map',
+            'Area B - Bulli': 'shovel_A_map',
+            'Area B - Shovel': 'shovel_B_map',
+            'Area B - Yacaaba': 'shovel_C_map',
+            'Area C - Bulli': 'yacaaba_A_map',
+            'Area C - Shovel': 'yacaaba_B_map',
+            'Area C - Yacaaba': 'yacaaba_C_map'}
+
+##gauge_mapA = ''
+##gauge_mapB = ''
+##gauge_mapC = ''
+
+# Create sections and graphs for each designated production directory
+latex_output = []
+report_name = 'latexoutput'
+
+if do_timeseries == True:
+    
+    if is_parallel == True:
+
+        for i in range(nodes):
+            print 'Sending node %d of %d' %(i,nodes)
+            swwfiles = {}
+            reportname = report_name + '_%s' %(i)
+            for label_id in production_dirs.keys():
+                file_loc = project_slide.outputdir + label_id + sep
+                sww_extra = '_P%s_%s' %(i,nodes)
+                swwfile = file_loc + project.scenario_name + sww_extra + '.sww'
+                swwfiles[swwfile] = label_id
+
+                texname, elev_output = sww2timeseries(swwfiles,
+                                                      project.gauge_filename,
+                                                      production_dirs,
+                                                      report = True,
+                                                      reportname = reportname,
+                                                      plot_quantity = ['stage', 'momentum'],
+                                                      generate_fig = True,
+                                                      surface = False,
+                                                      time_min = None,
+                                                      time_max = None,
+                                                      title_on = False,
+                                                      verbose = True)
+                
+                latex_output.append(texname)
+        
+    else:
+        swwfiles = {}
+        for label_id in production_dirs.keys():
+
+            file_loc = project_slide.outputdir + label_id + sep
+            if production_dirs[label_id] == 'Area A - Bulli':
+                scenario_dir_name = 'wollongong_tsunami_scenario_2006'
+                file_loc = project_slide.home+sep+project_slide.state+sep+scenario_dir_name+sep+'anuga'+sep+'outputs'+sep+label_id+sep
+            if production_dirs[label_id] == 'Area C - Bulli':
+                scenario_dir_name = 'newcastle_tsunami_scenario_2006'
+                file_loc = project_slide.home+sep+project_slide.state+sep+scenario_dir_name+sep+'anuga'+sep+'outputs'+sep+label_id+sep
+            swwfile = file_loc + project_slide.basename + '.sww'
+            swwfiles[swwfile] = label_id
+            
+        texname, elev_output = sww2timeseries(swwfiles,
+                                              'arrivaltime.csv',#project.gauge_filename,
+                                              production_dirs,
+                                              report = True,
+                                              reportname = report_name,
+                                              plot_quantity = ['stage', 'momentum'],
+                                              generate_fig = True,
+                                              surface = False,
+                                              time_min = None,
+                                              time_max = None,
+                                              title_on = False,
+                                              verbose = True)
+
+# Start report generation
+# Future: generate_report(reportdir, scenario, report_title, 
+# project.gauge_filename, max_maps, damage_maps, production_dirs, latex_output)
+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
+% * outline of the modelling methodology provided in modelling_methodology.tex
+% * 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}
+\usepackage{rotating}
+\usepackage{pdfpages}
+\include{appendix}
+\setstretch{1.25}
+\\topmargin 0pt
+\oddsidemargin 0pt
+\evensidemargin 0pt
+\marginparwidth 0.5pt
+\\textwidth \paperwidth
+\\advance\\textwidth -2in
+\\newcommand{\degree}{\ensuremath{^\circ}}
+\\newcommand{\sech}{\operatorname{sech}}
+
+"""
+fid.write(s)
+
+s = """
+\date{\\today}
+%\\author{Geoscience Australia}
+
+\\begin{document}
+\\title{
+\\begin{figure}[hbt]
+  \centerline{ \includegraphics[scale=0.4]{../report_figures/GAlogo.jpg}}
+\end{figure}
+"""
+fid.write(s)
+s = '%s} '%report_title
+fid.write(s)
+s = """
+  \maketitle
+
+    \section{Executive Summary}
+    \label{sec:execsum}
+  \input{execsum}
+
+\pagebreak
+
+  \\tableofcontents
+  
+   \section{Modelling methodology}
+    \label{sec:methodology}
+    \input{modelling_methodology}
+
+  \section{Data sources}
+    \label{sec:data}
+    \input{data}
+        
+  \section{Inundation modelling results}
+     \label{sec:results}
+         
+"""
+fid.write(s)
+
+# Generate latex output for location points
+##s = '\\begin{table} \\begin{center} \n'
+##fid.write(s)
+##s = '\caption{Defined point locations for %s study area.}' %scenario_name
+##fid.write(s)
+##s = """
+##\label{table:locations}
+##\\begin{tabular}{|l|l|l|l|}\hline
+##\\bf{Point Name} & \\bf{Easting} & \\bf{Northing} & \\bf{Elevation}\\\\ \hline
+##"""
+##fid.write(s)
+##
+##gauges, locations, elevation = get_gauges_from_file(project.gauge_filename)
+##
+##for name, gauges, elev in zip(locations, gauges, elevation):
+##    east = gauges[0]
+##    north = gauges[1]
+##    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 = '\\begin{figure}[hbt] \centerline{\includegraphics[scale = 0.5]{../report_figures/%s}}' %gauge_map2
+##fid.write(s)
+##s  = """
+##\caption{Point locations used for Dampier study; surrounding the facility.
+##See Appendix \\ref{sec:timeseries} for stage and momentum results.
+##}  
+##\label{fig:points2}
+##\end{figure}
+##"""
+##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 = '\input{%s} \n \clearpage \n \n' %max_maps[production_dirs[name]]
+    fid.write(s)
+
+# Closing
+
+
+s = """
+
+     \section{Summary}
+     \label{sec:summary}
+     \input{summary}
+
+     %\section{Acknowledgements}
+     %\input{acknowledgements}
+     
+    \input{references}
+
+    \\appendix
+    
+ %  \section{Metadata}
+  %   \label{sec:metadata}
+   %  \input{metadata}
+     
+\section{ANUGA modelling parameters}
+\label{sec:anugasetup}
+\input{anuga_setup}
+
+\section{Submarine Mass Failure Model}
+\label{sec:smfmodel}
+\input{smfmodel}
+
+\clearpage
+
+   \section{Time series}
+     \label{sec:timeseries}
+"""
+fid.write(s)
+
+##for i in range(len(latex_output)):
+##    if latex_output[i] <> '':
+##        s = '\input{%s} \n \clearpage \n \n' %latex_output[i]   
+##        fid.write(s)
+s = '\input{%s} \n \clearpage \n \n' %texname  
+fid.write(s)
+s="""
+\end{document}
+"""
+fid.write(s)
