Changeset 3080


Ignore:
Timestamp:
Jun 5, 2006, 2:57:31 PM (18 years ago)
Author:
sexton
Message:

got some pretty colours now for the report as well as getting multiple outputs on one graph

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/util.py

    r3036 r3080  
    4646                 a tuple of values - one for each quantity 
    4747
    48     interpolation_points - list of absolute UTM coordinates for points at
     48    interpolation_points - list of absolute UTM coordinates for points (N x 2) at
    4949    which values are sought
    5050   
     
    198198    if interpolation_points is not None:
    199199        interpolation_points = ensure_numeric(interpolation_points, Float)
    200 
     200        msg = 'Points must by N x 2. I got %d' %interpolation_points.shape[1]
     201        assert interpolation_points.shape[1] == 2, msg
    201202
    202203
     
    541542   
    542543   
    543 def sww2timeseries(swwfile,
     544def sww2timeseries(swwfiles,
    544545                   gauge_filename,
    545                    label_id,
     546                   #label_id,
     547                   production_dirs,
    546548                   report = None,
    547549                   plot_quantity = None,
     
    557559    Input variables:
    558560
    559     swwfile         - name of sww file
     561    swwfiles        - dictionary of sww files with label_ids (used in
     562                      generating latex output. It will be part of
     563                      the directory name of file_loc (typically the timestamp).
     564                      Helps to differentiate latex files for different simulations
     565                      for a particular scenario. 
    560566                    - assume that all conserved quantities have been stored
     567                    - assume each sww file has been simulated with same timestep
    561568                   
    562569    gauge_filename  - name of file containing gauge data
     
    566573                          such as a geospatial data object
    567574                     
    568     label_id        - used in generating latex output. It will be part of
    569                       the directory name of file_loc (typically the timestamp).
    570                       Helps to differentiate latex files for different simulations
    571                       for a particular scenario.
    572                      
    573575    report          - if True, then write figures to report_figures directory in
    574576                      relevant production directory
     
    582584                        - stage; 'stage'
    583585                        - depth; 'depth'
    584                         - velocity; calculated as absolute momentum
    585                          (pointwise) divided by depth; 'velocity'
     586                        - speed; calculated as absolute momentum
     587                         (pointwise) divided by depth; 'speed'
    586588                        - bearing; calculated as the angle of the momentum
    587589                          vector (xmomentum, ymomentum) from the North; 'bearing'
     
    590592                        - x momentum; 'xmomentum'
    591593                        - y momentum; 'ymomentum'
    592                     - default will be ['stage', 'velocity', 'bearing']
     594                    - default will be ['stage', 'speed', 'bearing']
    593595
    594596    time_min         - beginning of user defined time range for plotting purposes
     
    621623
    622624   
    623     k = _sww2timeseries(swwfile,
     625    k = _sww2timeseries(swwfiles,
    624626                        gauge_filename,
    625                         label_id,
     627                        #label_id,
     628                        production_dirs,
    626629                        report,
    627630                        plot_quantity,
     
    633636    return k
    634637
    635 def _sww2timeseries(swwfile,
     638def _sww2timeseries(swwfiles,
    636639                    gauge_filename,
    637                     label_id,
     640                    #label_id,
     641                    production_dirs,
    638642                    report = None,
    639643                    plot_quantity = None,
     
    643647                    verbose = False):   
    644648
    645     assert type(swwfile) == type(''),\
    646                'The sww filename must be a string'
    647 
    648     try:
    649         fid = open(swwfile)
    650     except Exception, e:
    651         msg = 'File "%s" could not be opened: Error="%s"'\
    652                   %(swwfile, e)
    653         raise msg
    654 
    655     index = swwfile.rfind(sep)
    656     file_loc = swwfile[:index+1]
     649    #assert type(swwfile) == type(''),\
     650    #           'The sww filename must be a string'
     651
     652    #try:
     653    #    fid = open(swwfile)
     654    #except Exception, e:
     655    #    msg = 'File "%s" could not be opened: Error="%s"'\
     656    #              %(swwfile, e)
     657    #    raise msg
     658
     659    #index = swwfile.rfind(sep)
     660    #file_loc = swwfile[:index+1]
    657661       
    658662    assert type(gauge_filename) == type(''),\
     
    673677   
    674678    if plot_quantity is None:
    675         plot_quantity = ['depth', 'velocity', 'bearing']
     679        plot_quantity = ['depth', 'speed', 'bearing']
    676680    else:
    677681        check_list(plot_quantity)
     
    680684        title_on = True
    681685     
    682     assert type(label_id) == type(''),\
    683                'label_id to sww2timeseries must be a string'
     686    #assert type(label_id) == type(''),\
     687    #           'label_id to sww2timeseries must be a string'
    684688   
    685689    if verbose: print '\n Gauges obtained from: %s \n' %gauge_filename
    686     gauges, locations = get_gauges_from_file(gauge_filename)
     690    gauges, locations, elev = get_gauges_from_file(gauge_filename)
    687691
    688692    sww_quantity = ['stage', 'elevation', 'xmomentum', 'ymomentum']
    689693
    690     f = file_function(swwfile,
    691                       quantities = sww_quantity,
    692                       interpolation_points = gauges,
    693                       verbose = True,
    694                       use_cache = True)
    695 
     694    file_loc = []
     695    f_list = []
     696    label_id = []
     697   
     698    for swwfile in swwfiles.keys():
     699
     700        try:
     701            fid = open(swwfile)
     702        except Exception, e:
     703            msg = 'File "%s" could not be opened: Error="%s"'\
     704                  %(swwfile, e)
     705            raise msg
     706
     707        f = file_function(swwfile,
     708                          quantities = sww_quantity,
     709                          interpolation_points = gauges,
     710                          verbose = True,
     711                          use_cache = True)
     712       
     713        #if max(f.quantities['xmomentum']) > 1.e10:
     714        #    msg = 'Not all conserved quantities available from sww file. \n sww2timeseries requires all conserved quantities stored in sww file'
     715        #    raise Exception, msg
     716   
     717        index = swwfile.rfind(sep)
     718        file_loc.append(swwfile[:index+1])
     719        label_id.append(swwfiles[swwfile])
     720        f_list.append(f)
     721       
     722    #T.append(f.get_time())
    696723    T = f.get_time()
    697 
    698     if max(f.quantities['xmomentum']) > 1.e10:
    699         msg = 'Not all conserved quantities available from sww file. \n sww2timeseries requires all conserved quantities stored in sww file'
    700         raise Exception, msg
    701724       
    702725    if time_min is None:
     
    717740
    718741    return generate_figures(plot_quantity, file_loc, report,
    719                             f, gauges, locations,
     742                            f_list, gauges, locations, production_dirs,
    720743                            time_min, time_max, title_on, label_id, verbose)
    721744                         
     
    729752    gauges = []
    730753    gaugelocation = []
     754    elev = []
    731755    line1 = lines[0]
    732756    line11 = line1.split(',')
     
    739763    for line in lines[1:]:
    740764        fields = line.split(',')
    741         gauges.append([float(fields[east_index]), float(fields[north_index]), float(fields[elev_index])])
     765        gauges.append([float(fields[east_index]), float(fields[north_index])])
     766        elev.append(float(fields[elev_index]))
    742767        loc = fields[name_index]
    743768        gaugelocation.append(loc.strip('\n'))
    744769
    745     return gauges, gaugelocation
     770    return gauges, gaugelocation, elev
    746771
    747772def check_list(quantity):
    748773
    749774    all_quantity = ['stage', 'depth', 'momentum', 'xmomentum',
    750                     'ymomentum', 'velocity', 'bearing', 'elevation']
     775                    'ymomentum', 'speed', 'bearing', 'elevation']
    751776
    752777    p = list(set(quantity).difference(set(all_quantity)))
     
    776801    return bearing
    777802
    778 def generate_figures(plot_quantity, file_loc, report, f, gauges,
    779                      locations, time_min, time_max, title_on, label_id, verbose):
     803def generate_figures(plot_quantity, file_loc, report, f_list, gauges,
     804                     locations, production_dirs, time_min, time_max,
     805                     title_on, label_id, verbose):
    780806
    781807    from math import sqrt, atan, degrees
     
    785811         xlabel, ylabel, title, close, subplot
    786812
    787     filename = file_loc.split(sep)
    788 
    789     if report == True:
    790         label_id1 = label_id.replace(sep,'')
    791         label_id2 = label_id1.replace('_','')
     813    #filename = file_loc.split(sep)
     814
     815    if report == True:   
    792816        texdir = getcwd()+sep+'report'+sep
    793817        if access(texdir,F_OK) == 0:
    794818            mkdir (texdir)
    795         texfile = texdir+'latexoutput%s' %(label_id2)
    796         texfile2 = 'latexoutput%s' %(label_id2)
    797         texfilename = texfile + '.tex'
    798         if verbose: print '\n Latex output printed to %s \n' %texfilename
    799         fid = open(texfilename, 'w')
     819        if len(label_id) == 1:
     820            label_id1 = label_id[0].replace(sep,'')
     821            label_id2 = label_id1.replace('_','')
     822            texfile = texdir+'latexoutput%s' %(label_id2)
     823            texfile2 = 'latexoutput%s' %(label_id2)
     824            texfilename = texfile + '.tex'
     825            if verbose: print '\n Latex output printed to %s \n' %texfilename
     826            fid = open(texfilename, 'w')
     827        else:
     828            texfile = texdir+'latexoutput'
     829            texfile2 = 'latexoutput'
     830            texfilename = texfile + '.tex'
     831            if verbose: print '\n Latex output printed to %s \n' %texfilename
     832            fid = open(texfilename, 'w')
    800833    else:
    801834        texfile = ''
    802835
    803     n = len(f.get_time())
     836    p = len(f_list)
     837    n = []
     838    n0 = 0
     839    for i in range(len(f_list)):
     840        n.append(len(f_list[i].get_time()))
     841        if n[i] > n0: n0 = n[i] 
     842    n0 = int(n0)
    804843    m = len(locations)
    805     model_time = zeros((n,m), Float) # this is actually T, but need to think about
    806                                      # how to change this for tmin to tmax range
    807     stages = zeros((n,m), Float)
    808     elevations = zeros((n,m), Float) # same as model_time
    809     momenta = zeros((n,m), Float)
    810     xmom = zeros((n,m), Float)
    811     ymom = zeros((n,m), Float)
    812     velocity = zeros((n,m), Float)
    813     bearings = zeros((n,m), Float)
    814     depths = zeros((n,m), Float)
     844    model_time = zeros((n0,m,p), Float)
     845    stages = zeros((n0,m,p), Float)
     846    elevations = zeros((n0,m,p), Float)
     847    momenta = zeros((n0,m,p), Float)
     848    xmom = zeros((n0,m,p), Float)
     849    ymom = zeros((n0,m,p), Float)
     850    speed = zeros((n0,m,p), Float)
     851    bearings = zeros((n0,m,p), Float)
     852    depths = zeros((n0,m,p), Float)
    815853    min_stages = []
    816854    max_stages = []
    817855    max_momentums = []
    818     max_velocitys = []
     856    max_speeds = []
    819857    c = 0
    820     ##### loop over each gauge #####
    821     for k, g in enumerate(gauges):
    822         if verbose: print 'Gauge %d of %d' %(k, len(gauges))
    823         min_stage = 10
    824         max_stage = 0
    825         max_momentum = 0
    826         max_velocity = 0   
    827         gaugeloc = locations[k]
    828         thisfile = file_loc+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
    829         fid_out = open(thisfile, 'w')
    830         s = 'Time, Stage, Momentum, Velocity \n'
    831         fid_out.write(s)
    832         #### generate quantities #######
    833        
    834         for i, t in enumerate(f.get_time()):
    835             if time_min <= t <= time_max:
    836                 w = f(t, point_id = k)[0]
    837                 z = f(t, point_id = k)[1]
    838                 uh = f(t, point_id = k)[2]
    839                 vh = f(t, point_id = k)[3]     
    840                 depth = w-z     
    841                 m = sqrt(uh*uh + vh*vh)   
    842                 if m < 0.001:
    843                     vel = 0.0
    844                 else:
    845                     vel = m / (depth + 1.e-30)
    846                 bearing = calc_bearing(uh, vh)
    847                 model_time[i,k] = t/60.0         
    848                 stages[i,k] = w
    849                 elevations[i,k] = z
    850                 xmom[i,k] = uh
    851                 ymom[i,k] = vh
    852                 momenta[i,k] = m
    853                 velocity[i,k] = vel
    854                 bearings[i,k] = bearing
    855                 depths[i,k] = depth
    856                 s = '%.2f, %.2f, %.2f, %.2f\n' %(t, w, m, vel)
    857                 fid_out.write(s)
    858                 if w > max_stage: max_stage = w
    859                 if w < min_stage: min_stage = w
    860                 if m > max_momentum: max_momentum = m
    861                 if vel > max_velocity: max_velocity = vel
    862 
    863         max_stages.append(max_stage)
    864         min_stages.append(min_stage)
    865         max_momentums.append(max_momentum)
    866         max_velocitys.append(max_velocity)       
    867        
    868         #### finished generating quantities #####
    869 
    870     stage_axis = axis([time_min/60.0, time_max/60.0, min(min_stages),
    871 max(max_stages)*1.1])
    872     vel_axis = axis([time_min/60.0, time_max/60.0, min(max_velocitys),
    873 max(max_velocitys)*1.1])
    874     mom_axis = axis([time_min/60.0, time_max/60.0, min(max_momentums),
    875 max(max_momentums)*1.1])
    876    
     858    ##### loop over each swwfile #####
     859    for j, f in enumerate(f_list):
     860        if verbose: print 'swwfile %d of %d' %(j, len(f_list))
     861        ##### loop over each gauge #####
     862        for k, g in enumerate(gauges):
     863            if verbose: print 'Gauge %d of %d' %(k, len(gauges))
     864            min_stage = 10
     865            max_stage = 0
     866            max_momentum = 0
     867            max_speed = 0   
     868            gaugeloc = locations[k]
     869            thisfile = file_loc[j]+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
     870            fid_out = open(thisfile, 'w')
     871            s = 'Time, Stage, Momentum, Speed \n'
     872            fid_out.write(s)
     873            #### generate quantities #######
     874           
     875            for i, t in enumerate(f.get_time()):
     876                if time_min <= t <= time_max:
     877                    w = f(t, point_id = k)[0]
     878                    z = f(t, point_id = k)[1]
     879                    uh = f(t, point_id = k)[2]
     880                    vh = f(t, point_id = k)[3]     
     881                    depth = w-z     
     882                    m = sqrt(uh*uh + vh*vh)   
     883                    if m < 0.001:
     884                        vel = 0.0
     885                    else:
     886                        vel = m / (depth + 1.e-30)
     887                    bearing = calc_bearing(uh, vh)
     888                    model_time[i,k,j] = t/60.0         
     889                    stages[i,k,j] = w
     890                    elevations[i,k,j] = z
     891                    xmom[i,k,j] = uh
     892                    ymom[i,k,j] = vh
     893                    momenta[i,k,j] = m
     894                    speed[i,k,j] = vel
     895                    bearings[i,k,j] = bearing
     896                    depths[i,k,j] = depth
     897                    s = '%.2f, %.2f, %.2f, %.2f\n' %(t, w, m, vel)
     898                    fid_out.write(s)
     899                    if w > max_stage: max_stage = w
     900                    if w < min_stage: min_stage = w
     901                    if m > max_momentum: max_momentum = m
     902                    if vel > max_speed:
     903                        last_i = i
     904                        last_k = k
     905                        max_speed = vel
     906
     907            max_stages.append(max_stage)
     908            min_stages.append(min_stage)
     909            max_momentums.append(max_momentum)
     910            max_speeds.append(max_speed)       
     911           
     912            #### finished generating quantities for each swwfile #####
     913           
     914    #### finished generating quantities for all swwfiles #####
     915           
     916    stage_axis = axis([time_min/60.0, time_max/60.0, min(min_stages), max(max_stages)*1.1])
     917    vel_axis = axis([time_min/60.0, time_max/60.0, min(max_speeds), max(max_speeds)*1.1])
     918    mom_axis = axis([time_min/60.0, time_max/60.0, min(max_momentums), max(max_momentums)*1.1])
     919
     920    cstr = ['g', 'r', 'b', 'c', 'm', 'y', 'k']
    877921    nn = len(plot_quantity)
    878922    no_cols = 2
    879     for k, g in enumerate(gauges):               
    880         #### generate figures ###
    881         ion()
    882         hold(False)
    883         count = 0
    884         where = 0
    885         word_quantity = ''
    886         if report == True:
     923    if len(label_id) > 1: graphname_report = []
     924    for k, g in enumerate(gauges):
     925        count1 = 0
     926        if report == True and len(label_id) > 1:
    887927            s = '\\begin{figure}[hbt] \n \\centering \n \\begin{tabular}{cc} \n'
    888928            fid.write(s)
    889            
    890         for which_quantity in plot_quantity:
    891             count += 1
    892             where += 1
    893             figure(count, frameon = False)
    894             if which_quantity == 'depth':
    895                 plot(model_time[:,k], depths[:,k], '-')
    896                 units = 'm'
    897             if which_quantity == 'stage':
    898                 plot(model_time[:,k], stages[:,k], '-')
    899                 axis(stage_axis)
    900                 units = 'm'
    901             if which_quantity == 'momentum':
    902                 plot(model_time[:,k], momenta[:,k], '-')
    903                 axis(mom_axis)
    904                 units = 'm^2 / sec'
    905             if which_quantity == 'xmomentum':
    906                 plot(model_time[:,k], xmom[:,k], '-')
    907                 axis(mom_axis)
    908                 units = 'm^2 / sec'
    909             if which_quantity == 'ymomentum':
    910                 plot(model_time[:,k], ymom[:,k], '-')
    911                 axis(mom_axis)
    912                 units = 'm^2 / sec'
    913             if which_quantity == 'velocity':
    914                 plot(model_time[:,k], velocity[:,k], '-')
    915                 axis(vel_axis)
    916                 units = 'm / sec'
    917             if which_quantity == 'bearing':
    918                 due_east = 90.0*ones([len(model_time)])
    919                 due_west = 270.0*ones([len(model_time)])
    920                 plot(model_time, bearings, '-', model_time, due_west, '-.',
    921                      model_time, due_east, '-.')
    922                 units = 'degrees from North'
    923                 ax = axis([time_min, time_max, 0, 360])
    924                 legend(('Bearing','West','East'))
    925 
    926             xlabel('time (secs)')
    927             ylabel('%s (%s)' %(which_quantity, units))
    928 
    929             gaugeloc1 = gaugeloc.replace(' ','')
    930             #gaugeloc2 = gaugeloc1.replace('_','')
    931             gaugeloc2 = locations[k].replace(' ','')
    932             graphname = '%sgauge%s_%s' %(file_loc, gaugeloc2, which_quantity)
    933 
    934             if report == True:
    935 
    936                 figdir = getcwd()+sep+'report_figures'+sep
    937                 if access(figdir,F_OK) == 0 :
    938                     mkdir (figdir)
    939                 latex_file_loc = figdir.replace(sep,altsep)
    940 
    941                 # storing files in production directory
    942                 graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2)
    943 
    944                 # giving location in latex output file
    945                 graphname_report = '%sgauge%s%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity, label_id2)
    946                
    947                 s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report, '.png')
    948                 fid.write(s)
    949                 if where % 2 == 0:
    950                     s = '\\\\ \n'
    951                     where = 0
    952                 else:
    953                     s = '& \n'
     929        if len(label_id) > 1: graphname_report = []
     930        #### generate figures for each gauge ###
     931        for j, f in enumerate(f_list):
     932            ion()
     933            hold(True)
     934            count = 0
     935            where1 = 0
     936            where2 = 0
     937            word_quantity = ''
     938            if report == True and len(label_id) == 1:
     939                s = '\\begin{figure}[hbt] \n \\centering \n \\begin{tabular}{cc} \n'
    954940                fid.write(s)
    955941               
    956                 #label = '%s%sgauge%s' %(label_id2, which_quantity, gaugeloc2)
    957                 #caption = 'Time series for %s at %s gauge location' %(which_quantity, gaugeloc.replace('_',' '))
    958                 #s = '\\begin{figure}[hbt] \n \\centerline{\includegraphics[width=100mm, height=75mm]{%s%s}} \n' %(graphname_report, '.png')
    959                 #fid.write(s)
    960                 #s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
    961                 #fid.write(s)
    962                 #c += 1
    963                 #if c % 10 == 0: fid.write('\\clearpage \n')
    964                 savefig(graphname_latex) # save figures in production directory for report generation
    965            
    966             if title_on == True:
    967                 title('%s scenario: %s at %s gauge' %(label_id, which_quantity, gaugeloc))
    968 
    969             savefig(graphname) # save figures with sww file
    970 
    971         if report == True:
     942            for which_quantity in plot_quantity:
     943                count += 1
     944                where1 += 1
     945                figure(count, frameon = False)
     946                if which_quantity == 'depth':
     947                    plot(model_time[0:n[j]-1,k,j], depths[0:n[j]-1,k,j], '-', c = cstr[j])
     948                    units = 'm'
     949                if which_quantity == 'stage':
     950                    plot(model_time[0:n[j]-1,k,j], stages[0:n[j]-1,k,j], '-', c = cstr[j])
     951                    axis(stage_axis)
     952                    units = 'm'
     953                if which_quantity == 'momentum':
     954                    plot(model_time[0:n[j]-1,k,j], momenta[0:n[j]-1,k,j], '-', c = cstr[j])
     955                    axis(mom_axis)
     956                    units = 'm^2 / sec'
     957                if which_quantity == 'xmomentum':
     958                    plot(model_time[0:n[j]-1,k,j], xmom[0:n[j]-1,k,j], '-', c = cstr[j])
     959                    axis(mom_axis)
     960                    units = 'm^2 / sec'
     961                if which_quantity == 'ymomentum':
     962                    plot(model_time[0:n[j]-1,k,j], ymom[0:n[j]-1,k,j], '-', c = cstr[j])
     963                    axis(mom_axis)
     964                    units = 'm^2 / sec'
     965                if which_quantity == 'speed':
     966                    plot(model_time[0:n[j]-1,k,j], speed[0:n[j]-1,k,j], '-', c = cstr[j])
     967                    axis(vel_axis)
     968                    units = 'm / sec'
     969                if which_quantity == 'bearing':
     970                    due_east = 90.0*ones(shape(model_time[0:n[j]-1,k,j],Float))
     971                    due_west = 270.0*ones(shape(model_time[0:n[j]-1,k,j],Float))
     972                    plot(model_time[0:n[j]-1,k,j], bearings, '-',
     973                         model_time[0:n[j]-1,k,j], due_west, '-.',
     974                         model_time[0:n[j]-1,k,j], due_east, '-.')
     975                    units = 'degrees from North'
     976                    ax = axis([time_min, time_max, 0.0, 360.0])
     977                    legend(('Bearing','West','East'))
     978
     979                xlabel('time (mins)')
     980                ylabel('%s (%s)' %(which_quantity, units))
     981                #legend(production_dirs[label_id[j]],loc='upper right')
     982
     983                gaugeloc1 = gaugeloc.replace(' ','')
     984                #gaugeloc2 = gaugeloc1.replace('_','')
     985                gaugeloc2 = locations[k].replace(' ','')
     986                graphname = '%sgauge%s_%s' %(file_loc[j], gaugeloc2, which_quantity)
     987
     988                if report == True and len(label_id) > 1:
     989                    figdir = getcwd()+sep+'report_figures'+sep
     990                    if access(figdir,F_OK) == 0 :
     991                        mkdir (figdir)
     992                    latex_file_loc = figdir.replace(sep,altsep)
     993                    # storing files in production directory
     994                    graphname_latex = '%sgauge%s%s' %(latex_file_loc, gaugeloc2, which_quantity)     
     995                    # giving location in latex output file
     996                    graphname_report_input = '%sgauge%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity)
     997                    graphname_report.append(graphname_report_input)
     998                   
     999                    savefig(graphname_latex) # save figures in production directory for report generation
     1000
     1001                if report == True:
     1002
     1003                    figdir = getcwd()+sep+'report_figures'+sep
     1004                    if access(figdir,F_OK) == 0 :
     1005                        mkdir (figdir)
     1006                    latex_file_loc = figdir.replace(sep,altsep)   
     1007
     1008                    if len(label_id) == 1:
     1009                        # storing files in production directory
     1010                        graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2)     
     1011                        # giving location in latex output file
     1012                        graphname_report = '%sgauge%s%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity, label_id2)
     1013                        s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report, '.png')
     1014                        fid.write(s)
     1015                        if where1 % 2 == 0:
     1016                            s = '\\\\ \n'
     1017                            where1 = 0
     1018                        else:
     1019                            s = '& \n'
     1020                        fid.write(s)                       
     1021               
     1022                if title_on == True:
     1023                    title('%s scenario: %s at %s gauge' %(label_id, which_quantity, gaugeloc))
     1024
     1025                savefig(graphname) # save figures with sww file
     1026
     1027            if report == True and len(label_id) == 1:
     1028                for i in range(nn-1):
     1029                    if nn > 2:
     1030                        word_quantity += plot_quantity[i] + ', '
     1031                    else:
     1032                        word_quantity += plot_quantity[i]
     1033                   
     1034                word_quantity += ' and ' + plot_quantity[nn-1]               
     1035                caption = 'Time series for %s at %s gauge location' %(word_quantity, locations[k]) #gaugeloc.replace('_',' '))
     1036                label = '%sgauge%s' %(label_id2, gaugeloc2)
     1037                s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
     1038                fid.write(s)
     1039                c += 1
     1040                if c % 25 == 0: fid.write('\\clearpage \n')
     1041                savefig(graphname_latex)               
     1042               
     1043        if report == True and len(label_id) > 1:
    9721044            for i in range(nn-1):
    9731045                if nn > 2:
     
    9751047                else:
    9761048                    word_quantity += plot_quantity[i]
    977                
    978             word_quantity += ' and ' + plot_quantity[nn-1]               
     1049                where1 = 0
     1050                count1 += 1
     1051                index = j*len(plot_quantity)
     1052                for which_quantity in plot_quantity:
     1053                    where1 += 1
     1054                    #index = j*len(plot_quantity)*k
     1055                    s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report[index], '.png')
     1056                    index += 1
     1057                    fid.write(s)
     1058                    if where1 % 2 == 0:
     1059                        s = '\\\\ \n'
     1060                        where1 = 0
     1061                    else:
     1062                        s = '& \n'
     1063                    fid.write(s)
     1064            word_quantity += ' and ' + plot_quantity[nn-1]           
     1065            label = 'gauge%s' %(gaugeloc2)
    9791066            caption = 'Time series for %s at %s gauge location' %(word_quantity, locations[k]) #gaugeloc.replace('_',' '))
    980             label = '%sgauge%s' %(label_id2, gaugeloc2)
     1067           
     1068            #s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
    9811069            s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
    9821070            fid.write(s)
    9831071            c += 1
    9841072            if c % 25 == 0: fid.write('\\clearpage \n')
    985 
     1073               
    9861074           
    987         #### finished generating figures ###
    988 
    989     close('all')
     1075            #### finished generating figures ###
     1076
     1077        close('all')
    9901078   
    9911079    return texfile2
Note: See TracChangeset for help on using the changeset viewer.