[3965] | 1 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
| 2 | import project |
---|
| 3 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries, get_gauges_from_file |
---|
| 4 | |
---|
[3972] | 5 | def print_elev(elevfiles,production_dirs,figname): |
---|
| 6 | from pylab import plot, xlabel, ylabel, hold, ion, legend, savefig, close |
---|
| 7 | ion() |
---|
| 8 | hold(True) |
---|
| 9 | cstr = ['g', 'r', 'b', 'c', 'm', 'y', 'k'] |
---|
| 10 | j = -1 |
---|
| 11 | leg_label = [] |
---|
| 12 | for elevfile in elevfiles.keys(): |
---|
| 13 | x, elev = read_file(elevfile) |
---|
| 14 | leg_label.append(production_dirs[elevfiles[elevfile]]) |
---|
| 15 | j += 1 |
---|
| 16 | plot(x, elev, '-', c = cstr[j]) |
---|
| 17 | xlabel('Easting') |
---|
| 18 | ylabel('Water Depth') |
---|
| 19 | legend((leg_label),loc='upper right') |
---|
| 20 | savefig(figname) |
---|
| 21 | close('all') |
---|
| 22 | return |
---|
| 23 | |
---|
| 24 | def read_file(filename): |
---|
| 25 | fid = open(filename) |
---|
| 26 | lines = fid.readlines() |
---|
| 27 | fid.close() |
---|
| 28 | x = [] |
---|
| 29 | elev = [] |
---|
| 30 | i = -1 |
---|
| 31 | for line in lines[:]: |
---|
| 32 | i += 1 |
---|
| 33 | fields = line.split(',') |
---|
| 34 | x.append(float(fields[3].strip(' '))) |
---|
| 35 | elev.append(float(fields[2].strip(' '))) |
---|
| 36 | return x, elev |
---|
| 37 | |
---|
[3965] | 38 | # Derive scenario name |
---|
| 39 | p = getcwd().split(sep) |
---|
| 40 | scenario = p[-1] # Last element of absolute CWD path |
---|
| 41 | scenario_name = scenario.split('_2006')[0] # Strip any text past `_2006` |
---|
| 42 | test = scenario_name.split('_') |
---|
| 43 | if len(test) <> 1: |
---|
| 44 | scenario_name = '%s %s' %(test[0], test[1]) |
---|
| 45 | |
---|
| 46 | # Create report directory |
---|
| 47 | reportdir = getcwd()+sep+'report'+sep |
---|
| 48 | if access(reportdir,F_OK) == 0: |
---|
| 49 | mkdir (reportdir) |
---|
| 50 | |
---|
| 51 | # |
---|
[3972] | 52 | production_dirs = {'20061022_224422': 'Mw 8-7', # refined around paleo sites |
---|
[3965] | 53 | 'MOST': 'MOST'} # MOST input for Mw 8-7 |
---|
| 54 | |
---|
[3972] | 55 | gauge_map = 'gauges_map_bom.jpg' |
---|
[3965] | 56 | |
---|
| 57 | # Create sections and graphs for each designated production directory |
---|
| 58 | latex_output = [] |
---|
| 59 | swwfiles = {} |
---|
| 60 | for label_id in production_dirs.keys(): |
---|
| 61 | |
---|
| 62 | file_loc = project.outputdir + label_id + sep |
---|
| 63 | swwfile = file_loc + project.basename + '.sww' |
---|
| 64 | if label_id == 'MOST': |
---|
| 65 | swwfile = project.boundarydir + project.boundary_basename + '.sww' |
---|
| 66 | swwfiles[swwfile] = label_id |
---|
| 67 | |
---|
| 68 | texname, elev_output = sww2timeseries(swwfiles, |
---|
| 69 | project.gauge_filename_bom, |
---|
| 70 | production_dirs, |
---|
| 71 | report = True, |
---|
| 72 | reportname = 'latexoutput_boundary', |
---|
| 73 | plot_quantity = ['stage', 'speed'], |
---|
| 74 | surface = False, |
---|
| 75 | time_min = None, |
---|
| 76 | time_max = None, |
---|
| 77 | title_on = False, |
---|
| 78 | verbose = True) |
---|
| 79 | |
---|
| 80 | latex_output.append(texname) |
---|
| 81 | |
---|
[3972] | 82 | elevfiles = {} |
---|
| 83 | for label_id in production_dirs.keys(): |
---|
| 84 | |
---|
| 85 | file_loc = project.outputdir + label_id + sep |
---|
| 86 | elevfile = file_loc + 'gauges_maxmins' + '.csv' |
---|
| 87 | if label_id == 'MOST': |
---|
| 88 | elevfile = project.boundarydir + 'gauges_maxmins' + '.csv' |
---|
| 89 | elevfiles[elevfile] = label_id |
---|
| 90 | |
---|
| 91 | figname = 'compare_elev.png' |
---|
| 92 | print_elev(elevfiles,production_dirs,report_dir+figname) |
---|
| 93 | |
---|
[3965] | 94 | # Start report generation |
---|
| 95 | report_name = reportdir + 'boundary_report.tex' |
---|
| 96 | fid = open(report_name, 'w') |
---|
| 97 | |
---|
| 98 | s = """ |
---|
| 99 | % This is based on an automatically generated file (by make_report.py). |
---|
| 100 | % |
---|
| 101 | % Manual parts are: |
---|
| 102 | % * an abstract must be written in abstract.tex |
---|
| 103 | % * an introduction must be written in introduction.tex; a basic outline and |
---|
| 104 | % some of the core inputs are already in place |
---|
| 105 | % * outline of the modelling methodology provided in modelling_methodology.tex |
---|
| 106 | % * the tsunami-genic event should be discussed in tsunami_scenario.tex |
---|
| 107 | % * an computational_setup.tex file needs to be written for the particular scenario |
---|
| 108 | % * the interpretation of the results needs to be written to interpretation.tex |
---|
| 109 | % * maximum inundation maps need to be included in HAT_map.tex and LAT_map.tex etc. |
---|
| 110 | % * damage modelling maps need to be included in HAT_damage and LAT_damage etc. |
---|
| 111 | % * a summary must be written into summary.tex |
---|
| 112 | % * metadata for the scenario data to be included in metadata.tex |
---|
| 113 | |
---|
| 114 | \documentclass{article} |
---|
| 115 | |
---|
| 116 | \usepackage{ae} % or {zefonts} |
---|
| 117 | \usepackage[T1]{fontenc} |
---|
| 118 | \usepackage[ansinew]{inputenc} |
---|
| 119 | \usepackage{amsmath} |
---|
| 120 | \usepackage{amssymb} |
---|
| 121 | \usepackage{graphicx} |
---|
| 122 | \usepackage{color} |
---|
| 123 | \usepackage[colorlinks]{hyperref} |
---|
| 124 | \usepackage{lscape} %landcape pages support |
---|
| 125 | \usepackage{setspace} |
---|
| 126 | \usepackage{rotating} |
---|
| 127 | \include{appendix} |
---|
| 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 = """ |
---|
| 140 | \date{\\today} |
---|
| 141 | %\\author{Geoscience Australia} |
---|
| 142 | |
---|
| 143 | \\begin{document} |
---|
[3972] | 144 | \\title{Comparison between ANUGA and MOST - Hobart} |
---|
[3965] | 145 | \maketitle |
---|
| 146 | """ |
---|
| 147 | fid.write(s) |
---|
| 148 | |
---|
[3972] | 149 | s = '\\begin{figure}[hbt] \n \centerline{ \includegraphics[scale=0.6]{../report_figures/%s}}' %gauge_map |
---|
[3965] | 150 | fid.write(s) |
---|
| 151 | |
---|
| 152 | s = """ |
---|
| 153 | \caption{Point locations used for boundary investigation.} |
---|
| 154 | \label{fig:points} |
---|
| 155 | \end{figure} |
---|
| 156 | """ |
---|
| 157 | fid.write(s) |
---|
[3972] | 158 | |
---|
| 159 | s = '\\begin{figure}[hbt] \n \centerline{ \includegraphics[width=\paperwidth]{%s}}' %figname |
---|
| 160 | fid.write(s) |
---|
| 161 | |
---|
| 162 | s = """ |
---|
| 163 | \caption{Elevation data for ANUGA and MOST.} |
---|
| 164 | \label{fig:elevation} |
---|
| 165 | \end{figure} |
---|
| 166 | """ |
---|
| 167 | fid.write(s) |
---|
| 168 | |
---|
[3965] | 169 | s = '\input{%s} \n \clearpage \n \n' %latex_output[0] |
---|
| 170 | fid.write(s) |
---|
| 171 | |
---|
| 172 | s=""" |
---|
| 173 | \end{document} |
---|
| 174 | """ |
---|
| 175 | fid.write(s) |
---|