Changeset 2981


Ignore:
Timestamp:
May 25, 2006, 6:16:16 PM (19 years ago)
Author:
sexton
Message:

updates to sww2timeseries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/util.py

    r2965 r2981  
    717717
    718718    return generate_figures(plot_quantity, file_loc, report,
    719                             f, gauges, locations,
     719                            f, gauges, locations, 
    720720                            time_min, time_max, title_on, label_id, verbose)
    721721                         
    722722
    723723def get_gauges_from_file(filename):
     724    from os import sep, getcwd, access, F_OK, mkdir
    724725    fid = open(filename)
    725726    lines = fid.readlines()
     
    740741        loc = fields[name_index]
    741742        gaugelocation.append(loc.strip('\n'))
    742    
     743
    743744    return gauges, gaugelocation
    744745
     
    778779
    779780    from math import sqrt, atan, degrees
    780     from Numeric import ones, allclose
     781    from Numeric import ones, allclose, zeros, Float
    781782    from os import sep, altsep, getcwd, mkdir, access, F_OK, environ
    782     from pylab import ion, hold, plot, axis, figure, legend, savefig, xlabel, ylabel, title, close
     783    from pylab import ion, hold, plot, axis, figure, legend, savefig, \
     784         xlabel, ylabel, title, close, subplot
    783785
    784786    filename = file_loc.split(sep)
    785        
     787
    786788    if report == True:
    787789        label_id1 = label_id.replace(sep,'')
     
    794796        texfilename = texfile + '.tex'
    795797        if verbose: print '\n Latex output printed to %s \n' %texfilename
    796 
    797798        fid = open(texfilename, 'w')
    798         s = '\\begin{center} \n \\begin{tabular}{|l|l|l|}\hline \n \\bf{Gauge Name} & \\bf{Easting} & \\bf{Northing} \\\\ \hline \n'
    799         fid.write(s)
    800         gauges1 = gauges
    801         for name, gauges1 in zip(locations, gauges1):
    802             east = gauges1[0]
    803             north = gauges1[1]
    804             s = '%s & %.2f & %.2f \\\\ \hline \n' %(name.replace('_',' '), east, north)
    805             fid.write(s)
    806 
    807         s = '\\end{tabular} \n \\end{center} \n \n'
    808         fid.write(s)
    809799    else:
    810800        texfile = ''
    811801
     802    n = len(f.get_time())
     803    m = len(locations)
     804    model_time = zeros((n,m), Float) # this is actually T, but need to think about
     805                                     # how to change this for tmin to tmax range
     806    stages = zeros((n,m), Float)
     807    elevations = zeros((n,m), Float) # same as model_time
     808    momenta = zeros((n,m), Float)
     809    xmom = zeros((n,m), Float)
     810    ymom = zeros((n,m), Float)
     811    velocity = zeros((n,m), Float)
     812    bearings = zeros((n,m), Float)
     813    depths = zeros((n,m), Float)
     814    min_stages = []
     815    max_stages = []
     816    max_momentums = []
     817    max_velocitys = []
    812818    c = 0
    813819    ##### loop over each gauge #####
    814820    for k, g in enumerate(gauges):
    815821        if verbose: print 'Gauge %d of %d' %(k, len(gauges))
    816         model_time = []
    817         stages = []
    818         elevations = []
    819         momenta = []
    820         xmom = []
    821         ymom = []
    822         velocity = []
    823         bearings = []
    824         depths = []
    825         max_depth = 0
     822        min_stage = 10
     823        max_stage = 0
    826824        max_momentum = 0
    827         max_velocity = 0     
    828        
     825        max_velocity = 0   
     826        gaugeloc = locations[k]
     827        thisfile = file_loc+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
     828        fid_out = open(thisfile, 'w')
     829        s = 'Time, Stage, Momentum, Velocity \n'
     830        fid_out.write(s)
    829831        #### generate quantities #######
     832       
    830833        for i, t in enumerate(f.get_time()):
    831 
    832834            if time_min <= t <= time_max:
    833 
    834835                w = f(t, point_id = k)[0]
    835836                z = f(t, point_id = k)[1]
    836837                uh = f(t, point_id = k)[2]
    837                 vh = f(t, point_id = k)[3]
    838                 gaugeloc = locations[k]
    839                 depth = w-z
    840                
     838                vh = f(t, point_id = k)[3]     
     839                depth = w-z     
    841840                m = sqrt(uh*uh + vh*vh)   
    842841                if m < 0.001:
     
    845844                    vel = m / (depth + 1.e-30)
    846845                bearing = calc_bearing(uh, vh)
    847 
    848                 model_time.append(t)       
    849                 stages.append(w)
    850                 elevations.append(z)
    851                 xmom.append(uh)
    852                 ymom.append(vh)
    853                 momenta.append(m)
    854                 velocity.append(vel)
    855                 bearings.append(bearing)
    856                 depths.append(depth)
    857 
    858                 if depth > max_depth: max_depth = w-z
     846                model_time[i,k] = t         
     847                stages[i,k] = w
     848                elevations[i,k] = z
     849                xmom[i,k] = uh
     850                ymom[i,k] = vh
     851                momenta[i,k] = m
     852                velocity[i,k] = vel
     853                bearings[i,k] = bearing
     854                depths[i,k] = depth
     855                s = '%.2f, %.2f, %.2f, %.2f\n' %(t, w, m, vel)
     856                fid_out.write(s)
     857                if w > max_stage: max_stage = w
     858                if w < min_stage: min_stage = w
    859859                if m > max_momentum: max_momentum = m
    860860                if vel > max_velocity: max_velocity = vel
    861861
     862        max_stages.append(max_stage)
     863        min_stages.append(min_stage)
     864        max_momentums.append(max_momentum)
     865        max_velocitys.append(max_velocity)       
     866       
    862867        #### finished generating quantities #####
    863                
     868
     869    stage_axis = axis([time_min, time_max, min(min_stages), max(max_stages)*1.1])
     870    vel_axis = axis([time_min, time_max, min(max_velocitys), max(max_velocitys)*1.1])
     871    mom_axis = axis([time_min, time_max, min(max_momentums), max(max_momentums)*1.1])
     872   
     873    nn = len(plot_quantity)
     874    no_cols = 2
     875    for k, g in enumerate(gauges):               
    864876        #### generate figures ###
    865877        ion()
    866878        hold(False)
    867 
    868         for i in range(len(plot_quantity)):
    869             which_quantity = plot_quantity[i]
    870             figure(i+1, frameon = False)
     879        count = 0
     880        where = 0
     881        word_quantity = ''
     882        if report == True:
     883            s = '\\begin{figure}[hbt] \n \\centering \n \\begin{tabular}{cc} \n'
     884            fid.write(s)
     885           
     886        for which_quantity in plot_quantity:
     887            count += 1
     888            where += 1
     889            figure(count, frameon = False)
    871890            if which_quantity == 'depth':
    872                 plot(model_time, depths, '-')
     891                plot(model_time[:,k], depths[:,k], '-')
    873892                units = 'm'
    874893            if which_quantity == 'stage':
    875                 if elevations[0] < -10:
    876                     plot(model_time, stages, '-')
    877                 else:
    878                     plot(model_time, stages, '-', model_time, elevations, '-')
     894                plot(model_time[:,k], stages[:,k], '-')
     895                axis(stage_axis)
    879896                units = 'm'
    880897            if which_quantity == 'momentum':
    881                 plot(model_time, momenta, '-')
     898                plot(model_time[:,k], momenta[:,k], '-')
     899                axis(mom_axis)
    882900                units = 'm^2 / sec'
    883901            if which_quantity == 'xmomentum':
    884                 plot(model_time, xmom, '-')
     902                plot(model_time[:,k], xmom[:,k], '-')
     903                axis(mom_axis)
    885904                units = 'm^2 / sec'
    886905            if which_quantity == 'ymomentum':
    887                 plot(model_time, ymom, '-')
     906                plot(model_time[:,k], ymom[:,k], '-')
     907                axis(mom_axis)
    888908                units = 'm^2 / sec'
    889909            if which_quantity == 'velocity':
    890                 plot(model_time, velocity, '-')
     910                plot(model_time[:,k], velocity[:,k], '-')
     911                axis(vel_axis)
    891912                units = 'm / sec'
    892913            if which_quantity == 'bearing':
     
    903924
    904925            gaugeloc1 = gaugeloc.replace(' ','')
    905             gaugeloc2 = gaugeloc1.replace('_','')
     926            #gaugeloc2 = gaugeloc1.replace('_','')
     927            gaugeloc2 = locations[k].replace(' ','')
    906928            graphname = '%sgauge%s_%s' %(file_loc, gaugeloc2, which_quantity)
    907929
     
    915937                # storing files in production directory
    916938                graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2)
     939
    917940                # giving location in latex output file
    918941                graphname_report = '%sgauge%s%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity, label_id2)
    919                        
    920                 label = '%s%sgauge%s' %(label_id2, which_quantity, gaugeloc2)
    921                 caption = 'Time series for %s at %s gauge location' %(which_quantity, gaugeloc.replace('_',' '))
    922                 s = '\\begin{figure}[hbt] \n \\centerline{\includegraphics[width=100mm, height=75mm]{%s%s}} \n' %(graphname_report, '.png')
     942               
     943                s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report, '.png')
    923944                fid.write(s)
    924                 s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
     945                if where % 2 == 0:
     946                    s = '\\\\ \n'
     947                    where = 0
     948                else:
     949                    s = '& \n'
    925950                fid.write(s)
    926                 c += 1
    927                 if c % 10 == 0: fid.write('\\clearpage \n')
     951               
     952                #label = '%s%sgauge%s' %(label_id2, which_quantity, gaugeloc2)
     953                #caption = 'Time series for %s at %s gauge location' %(which_quantity, gaugeloc.replace('_',' '))
     954                #s = '\\begin{figure}[hbt] \n \\centerline{\includegraphics[width=100mm, height=75mm]{%s%s}} \n' %(graphname_report, '.png')
     955                #fid.write(s)
     956                #s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
     957                #fid.write(s)
     958                #c += 1
     959                #if c % 10 == 0: fid.write('\\clearpage \n')
    928960                savefig(graphname_latex) # save figures in production directory for report generation
    929961           
     
    933965            savefig(graphname) # save figures with sww file
    934966
    935    
    936         thisfile = file_loc+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
    937         fid_out = open(thisfile, 'w')
    938         s = 'Time, Depth, Momentum, Velocity \n'
    939         fid_out.write(s)
    940         for i_t, i_d, i_m, i_vel in zip(model_time, depths, momenta, velocity):
    941             s = '%.2f, %.2f, %.2f, %.2f\n' %(i_t, i_d, i_m, i_vel)
    942             fid_out.write(s)
     967        if report == True:
     968            for i in range(nn-1):
     969                if nn > 2:
     970                    word_quantity += plot_quantity[i] + ', '
     971                else:
     972                    word_quantity += plot_quantity[i]
     973               
     974            word_quantity += ' and ' + plot_quantity[nn-1]               
     975            caption = 'Time series for %s at %s gauge location' %(word_quantity, locations[k]) #gaugeloc.replace('_',' '))
     976            label = '%sgauge%s' %(label_id2, gaugeloc2)
     977            s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
     978            fid.write(s)
     979            c += 1
     980            if c % 10 == 0: fid.write('\\clearpage \n')
     981
    943982           
    944983        #### finished generating figures ###
Note: See TracChangeset for help on using the changeset viewer.