Changeset 2839


Ignore:
Timestamp:
May 9, 2006, 11:52:30 AM (18 years ago)
Author:
sexton
Message:

updates and setting up scripts for timeseries and report generation for Pt Hedland

Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/util.py

    r2836 r2839  
    507507def sww2timeseries(swwfile,
    508508                   gauge_filename,
    509                    file_loc,
    510509                   label_id,
     510                   report = None,
    511511                   plot_quantity = None,
    512512                   time_min = None,
     
    530530                          such as a geospatial data object
    531531                         
    532     file_loc        - file location of sww file
    533                     - gauge graphs and data written to this directory
     532    label_id        - used in generating latex output. It will be part of
     533                      the directory name of file_loc (typically the timestamp).
     534                      Helps to differentiate latex files for different simulations
     535                      for a particular scenario.
     536                     
     537    report          - if True, then write figures to report_figures directory in
     538                      relevant production directory
     539                    - if False, figures are already stored with sww file
     540                    - default to False
    534541   
    535542    plot_quantity   - list containing quantities to plot, they must
     
    555562                        - default will be last available time found in swwfile
    556563                       
    557     title_on        - if True, export standard graphics
    558                     - if False, export graphics as eps and generate
    559                       latex output (how about png which is much smaller
    560                       and can still latex using pdflatex?)
    561                     - latex output to be written to same directory as
    562                       where this function is being used from and named
    563                       according to scenario name
    564                      
    565     label_id        - used in generating latex output. It will generally
    566                       be part of the directory name of file_loc (the
    567                       time stamp, if using that). Helps to differentiate
    568                       between runs within a particular scenario.
     564    title_on        - if True, export standard graphics with title
     565                    - if False, export standard graphics without title
    569566                     
    570567    Output:
     
    572569    - time series data stored in .csv for later use if required.
    573570      Name = gauges_timeseries followed by gauge name
    574     - if title_on = False then output latex file will be generated
    575       in same directory as where script is run (usually production
    576       scenario direcotry. Name = latexoutpulabel_id.tex
     571    - latex file will be generated in same directory as where script is
     572      run (usually production scenario direcotry.
     573      Name = latexoutputlabel_id.tex
    577574
    578575    Other important information:
     
    588585    k = _sww2timeseries(swwfile,
    589586                        gauge_filename,
    590                         file_loc,
    591587                        label_id,
     588                        report,
    592589                        plot_quantity,
    593590                        time_min,
     
    600597def _sww2timeseries(swwfile,
    601598                    gauge_filename,
    602                     file_loc,
    603599                    label_id,
     600                    report = None,
    604601                    plot_quantity = None,
    605602                    time_min = None,
     
    618615        raise msg
    619616
     617    index = swwfile.rfind(sep)
     618    file_loc = swwfile[:index+1]
     619       
    620620    assert type(gauge_filename) == type(''),\
    621621               'Gauge filename must be a string'
     
    627627                  %(gauge_filename, e)
    628628        raise msg
     629
     630    if report is None:
     631        report = False
    629632       
    630633    assert type(plot_quantity) == list,\
     
    644647    if verbose: print '\n Gauges obtained from: %s \n' %gauge_filename
    645648    gauges, locations = get_gauges_from_file(gauge_filename)
    646 
    647     #from pyvolution.util import file_function
    648649
    649650    sww_quantity = ['stage', 'elevation', 'xmomentum', 'ymomentum']
     
    674675
    675676    if verbose: print 'Inputs OK - going to generate figures'
    676 
    677     # could try different approach for file_loc:
    678     # index = swwfile.find(basename.sww)
    679     # file_loc = swwfile[:index-1]
    680    
    681     return generate_figures(plot_quantity, file_loc, f, gauges, locations,
     677   
     678    return generate_figures(plot_quantity, file_loc, report,
     679                            f, gauges, locations,
    682680                            time_min, time_max, title_on, label_id, verbose)
    683681                         
     
    736734    return bearing
    737735
    738 def generate_figures(plot_quantity, file_loc, f, gauges,
     736def generate_figures(plot_quantity, file_loc, report, f, gauges,
    739737                     locations, time_min, time_max, title_on, label_id, verbose):
    740738
     
    742740    from Numeric import ones
    743741    from os import sep, altsep, getcwd, mkdir, access, F_OK, environ
    744     from os.path import expanduser
    745742    from pylab import ion, hold, plot, axis, figure, legend, savefig, xlabel, ylabel, title, close
    746743
    747744    filename = file_loc.split(sep)
    748745       
    749     if title_on == False:
    750         #ext = '.eps'
    751         ext = ''
     746    if report == True:
    752747        label_id1 = label_id.replace(sep,'')
    753748        label_id2 = label_id1.replace('_','')
     
    755750        texfilename = texfile + '.tex'
    756751        if verbose: print '\n Latex output printed to %s \n' %texfilename
     752
    757753        fid = open(texfilename, 'w')
    758754        s = '\\begin{center} \n \\begin{tabular}{|l|l|l|}\hline \n \\bf{Gauge Name} & \\bf{Easting} & \\bf{Northing} \\\\ \hline \n'
     
    768764        fid.write(s)
    769765    else:
    770         texfilename = ''
    771         ext = ''
     766        texfile = ''
    772767   
    773768    ##### loop over each gauge #####
     
    857852
    858853            gaugeloc1 = gaugeloc.replace(' ','')
    859             graphname = '%sgauge%s_%s%s' %(file_loc, gaugeloc1, which_quantity, ext)
    860             figdir = getcwd()+sep+'report_figures'+sep
    861             if access(figdir,F_OK) == 0 :
    862                 mkdir (figdir)
    863             latex_file_loc = figdir.replace(sep,altsep)
    864            
    865             graphname_latex = '%sgauge%s%s%s%s' %(latex_file_loc, gaugeloc1, which_quantity, label_id2, ext)
    866 
    867             p = getcwd().split(sep)   
    868             scenario = p[len(p)-1]
    869             home = expanduser('~')
    870             report_fig_loc = '~'+altsep+'anuga'+altsep+'production'+altsep+scenario+altsep+'report_figures'+altsep
    871             graphname_report = '%sgauge%s%s%s%s' %('report_figures'+altsep, gaugeloc1, which_quantity, label_id2, ext)
    872            
    873             if title_on == True:
    874                 title('%s scenario: %s at %s gauge'
    875                       %(label_id, which_quantity, gaugeloc))
    876                 savefig(graphname)
    877             else:
     854            graphname = '%sgauge%s_%s' %(file_loc, gaugeloc1, which_quantity)
     855
     856            if report == True:
     857
     858                figdir = getcwd()+sep+'report_figures'+sep
     859                if access(figdir,F_OK) == 0 :
     860                    mkdir (figdir)
     861                latex_file_loc = figdir.replace(sep,altsep)
     862
     863                # storing files in production directory
     864                graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc1, which_quantity, label_id2)
     865                # giving location in latex output file
     866                graphname_report = '%sgauge%s%s%s' %('report_figures'+altsep, gaugeloc1, which_quantity, label_id2)
     867                       
    878868                label = '%s%sgauge%s' %(label_id2, which_quantity, gaugeloc1)
    879869                caption = 'Time series for %s at %s gauge location' %(which_quantity, gaugeloc)
     
    882872                s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
    883873                fid.write(s)
    884                 savefig(graphname_latex)
     874                savefig(graphname_latex) # save figures in production directory for report generation
    885875           
     876            if title_on == True:
     877                title('%s scenario: %s at %s gauge' %(label_id, which_quantity, gaugeloc))
     878
     879            savefig(graphname) # save figures with sww file
     880
     881   
    886882        thisfile = file_loc+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
    887883        fid_out = open(thisfile, 'w')
  • production/onslow_2006/make_report.py

    r2837 r2839  
    44Inputs:
    55
    6 Report title:  title to be included in tex file
    7 latex_output:  list of latex_outputs which are
    8                generated for the desired output, eg high tide,
    9                low tide and MSL.
     6report_title:    title to be included in tex file
     7production dirs: dictionary of production directories with a
     8                 association to that simulation run, eg high tide,
     9                 low tide and MSL.
    1010                   
    1111
     
    2828* Appendix: Metadata
    2929
    30 Other files included in document:
     30Other files included in document which require manual intervention:
    3131
    3232* an abstract must be written in abstract.tex
     
    5050p = getcwd().split(sep)
    5151scenario = p[-1] # Last element of absolute CWD path
    52 scenario_name = scenario.split('_')[0] # Strip any text past `_`
     52scenario_name = scenario.split('_2006')[0] # Strip any text past `_2006`
     53test = scenario_name.split('_')
     54if len(test) <> 1:
     55    scenario_name = '%s %s' %(test[0], test[1])
    5356
    5457# User defined inputs
    5558report_title = 'Tsunami impact modelling for the North West shelf: %s' %scenario_name.title()
    5659
    57 production_dirs = ['20060424_020426_duplictate_time_steps',
    58                    '20060426_004129']
    59 
     60production_dirs = {'20060424_020426_duplictate_time_steps': 'Highest Astronomical Tide',
     61                   '20060426_004129': 'Lowest Astronomical Tide'}
    6062
    6163# Create sections and graphs for each designated production directory
    6264latex_output = []
    63 for label_id in production_dirs:
     65for label_id in production_dirs.keys():
    6466   
    6567    file_loc = project.outputdir + label_id + sep
     
    6870    texname = sww2timeseries(swwfile,
    6971                             project.gauge_filename,
    70                              file_loc,
    7172                             label_id,
     73                             report = True,
    7274                             plot_quantity = ['stage', 'velocity', 'bearing'],
    7375                             time_min = None,
     
    115117\\textwidth \paperwidth
    116118\\advance\\textwidth -2in
     119
    117120"""
    118121fid.write(s)
     
    121124fid.write(s)
    122125
    123 s =
    124 """
    125 \date{\today}
     126s = """
     127\date{\\today}
    126128\\begin{document}
    127129  \maketitle
     
    149151     \input{results}
    150152     \input{interpretation}
     153     
    151154"""
    152155fid.write(s)
    153156
    154 
    155 
    156157# Assign titles to each production section
    157158# Must specify one name per section
    158 for i, s in enumerate(['\subsection{Highest Astronomical Tide} \n',
    159                        '\subsection{Lowest Astronomical Tide} \n',
    160                        '\subsection{} \n']):
    161          
     159for i, name in enumerate(production_dirs.keys()):
     160
     161    s = '\subsection{%s} \n \n' %production_dirs[name]     
    162162    fid.write(s)
    163163   
    164     s = '\input{%s} \n \clearpage \n' %latex_output[i]
     164    s = '\input{%s} \n \clearpage \n \n' %latex_output[i]
    165165    fid.write(s)
    166166
    167167
    168168# Closing   
    169 s =
    170 """\section{Summary}
     169s = """\section{Summary}
    171170     \input{summary}
    172171     
    173172   \section{References}
     173
    174174   \section{Metadata}
    175175     \label{sec:metadata}
    176176     \input{metadata}
     177
    177178\end{document}
    178179"""
  • production/onslow_2006/onslow_2006_report.tex

    r2831 r2839  
    1 \documentclass{article}
    2  \usepackage{ae} % or {zefonts}
    3  \usepackage[T1]{fontenc}
    4  \usepackage[ansinew]{inputenc}
    5  \usepackage{amsmath}
    6  \usepackage{amssymb}
    7  \usepackage{graphicx}
    8  \usepackage{color}
    9  \usepackage[colorlinks]{hyperref}
    10  \usepackage{lscape} %landcape pages support
    11  \topmargin 0pt
    12  \oddsidemargin 0pt
    13  \evensidemargin 0pt
    14  \marginparwidth 0.5pt
    15  \textwidth \paperwidth
    16  \advance\textwidth -2in
     1
     2% This is based on an automatically generated file (by make_report.py).
     3%
     4% Manual parts are:
     5% * an abstract must be written in abstract.tex
     6% * an introduction must be written in introduction.tex; a basic outline and
     7%   some of the core inputs are already in place
     8% * an interpretation.tex file needs to be written for the particular scenario
     9% * any data issues must be included in data_issues.tex (data.tex should
     10%   be revised for future reports)
     11% * the tsunami-genic event should be discussed in tsunami_scenario.tex
     12% * a summary must be written into summary.tex
     13% * metadata for the scenario data to be included in metadata.tex
     14
     15\documentclass{article}
     16
     17\usepackage{ae} % or {zefonts}
     18\usepackage[T1]{fontenc}
     19\usepackage[ansinew]{inputenc}
     20\usepackage{amsmath}
     21\usepackage{amssymb}
     22\usepackage{graphicx}
     23\usepackage{color}
     24\usepackage[colorlinks]{hyperref}
     25\usepackage{lscape} %landcape pages support
     26
     27\topmargin 0pt
     28\oddsidemargin 0pt
     29\evensidemargin 0pt
     30\marginparwidth 0.5pt
     31\textwidth \paperwidth
     32\advance\textwidth -2in
     33
    1734\title{Tsunami impact modelling for the North West shelf: Onslow}
    18  \date{}
    19  \begin{document}
    20  \maketitle
    21  \begin{abstract}
    22  \input{abstract}
    23  \end{abstract}
    24  \tableofcontents
    25  \section{Introduction}
    26  \label{sec:intro}
    27  \input{introduction}
    28  \section{Data sources}
    29  \label{sec:data}
    30  \input{data}
    31  \section{Tsunami scenarios}
    32  \label{sec:tsunami_scenarios}
    33  \input{tsunami_scenario}
    34  \section{Inundation modelling results}
    35  \label{sec:results}
    36  \input{results}
    37  \input{interpretation}
    38  \subsection{Highest Astronomical Tide}
     35
     36\date{\today}
     37\begin{document}
     38  \maketitle
     39 
     40  \begin{abstract}
     41    \input{abstract}
     42  \end{abstract}
     43 
     44  \tableofcontents
     45 
     46  \section{Introduction}
     47    \label{sec:intro}
     48  \input{introduction}
     49 
     50  \section{Data sources}
     51    \label{sec:data}
     52    \input{data}
     53   
     54  \section{Tsunami scenarios}
     55    \label{sec:tsunami_scenarios}
     56    \input{tsunami_scenario}
     57   
     58  \section{Inundation modelling results}
     59     \label{sec:results}
     60     \input{results}
     61     \input{interpretation}
     62     
     63\subsection{Highest Astronomical Tide}
     64 
    3965\input{latexoutput20060424020426duplictatetimesteps}
    4066 \clearpage
     67 
    4168\subsection{Lowest Astronomical Tide}
     69 
    4270\input{latexoutput20060426004129}
    4371 \clearpage
    44 \section{Summary}
    45  \input{summary}
    46  \section{References}
    47  \section{Metadata}
    48  \label{sec:metadata}
    49  \input{metadata}
    50  \end{document}
     72 
     73\section{Summary}
     74     \input{summary}
     75     
     76   \section{References}
     77
     78   \section{Metadata}
     79     \label{sec:metadata}
     80     \input{metadata}
     81
     82\end{document}
  • production/onslow_2006/run_timeseries.py

    r2815 r2839  
    44import project
    55from os import sep
    6 from shutil import copy
    76
    87# define directory location of sww and gauge data
     
    109file_loc = project.outputdir + timestampdir + sep #project.outputtimedir
    1110swwfile = file_loc + project.basename + '.sww'
    12 gauge_filename = project.gauge_filename
    1311label_id = timestampdir
    14 
    15 # False to generate latex output, True otherwise
    16 title_on = True
    1712
    1813# generate figures - see sww2timeseries for documentation
    1914texname = sww2timeseries(swwfile,
    20                          gauge_filename,
    21                          file_loc,
     15                         project.gauge_filename,
    2216                         label_id,
     17                         report = False,
    2318                         plot_quantity = ['stage', 'velocity', 'bearing'],
    2419                         time_min = None,
    2520                         time_max = None,
    26                          title_on = title_on,   
     21                         title_on = True,   
    2722                         verbose = True)
    2823
Note: See TracChangeset for help on using the changeset viewer.