Changeset 4226


Ignore:
Timestamp:
Feb 6, 2007, 4:01:28 PM (17 years ago)
Author:
sexton
Message:

update sww2timeseries to allow quantity information to be generated without having to generate the plots (easier for working on cyclone etc)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4221 r4226  
    657657                   reportname = None,
    658658                   plot_quantity = None,
     659                   generate_fig = False,
    659660                   surface = None,
    660661                   time_min = None,
     
    706707                    - default will be ['stage', 'speed', 'bearing']
    707708
     709    generate_fig     - if True, generate figures as well as csv files of quantities
     710                     - if False, csv files created only
     711                     
    708712    surface          - if True, then generate solution surface with 3d plot
    709713                       and save to current working directory
     
    745749                        reportname,
    746750                        plot_quantity,
     751                        generate_fig,
    747752                        surface,
    748753                        time_min,
     
    759764                    reportname = None,
    760765                    plot_quantity = None,
     766                    generate_fig = False,
    761767                    surface = None,
    762768                    time_min = None,
     
    867873        texfile, elev_output = generate_figures(plot_quantity, file_loc, report, reportname, surface,
    868874                                                leg_label, f_list, gauges, locations, elev, gauge_index,
    869                                                 production_dirs, time_min, time_max, title_on, label_id, verbose)
     875                                                production_dirs, time_min, time_max, title_on, label_id,
     876                                                generate_fig, verbose)
    870877    else:
    871878        texfile = ''
     
    962969                     leg_label, f_list, gauges, locations, elev, gauge_index,
    963970                     production_dirs, time_min, time_max, title_on, label_id,
    964                      verbose):
     971                     generate_fig, verbose):
    965972    """ Generate figures based on required quantities and gauges for each sww file
    966973    """
     
    968975    from Numeric import ones, allclose, zeros, Float, ravel
    969976    from os import sep, altsep, getcwd, mkdir, access, F_OK, environ
    970     from pylab import ion, hold, plot, axis, figure, legend, savefig, \
    971          xlabel, ylabel, title, close, subplot
    972 
    973     import pylab as p1
    974     if surface is True:
    975         import mpl3d.mplot3d as p3
     977
     978    if generate_fig is True:
     979        from pylab import ion, hold, plot, axis, figure, legend, savefig, \
     980             xlabel, ylabel, title, close, subplot
     981   
     982        if surface is True:
     983            import pylab as p1
     984            import mpl3d.mplot3d as p3
    976985       
    977986    if report == True:   
     
    11251134    vel_axis = axis([time_min/60.0, time_max/60.0, min(max_speeds), max(max_speeds)*1.1])
    11261135    mom_axis = axis([time_min/60.0, time_max/60.0, min(max_momentums), max(max_momentums)*1.1]) 
    1127    
    1128     cstr = ['g', 'r', 'b', 'c', 'm', 'y', 'k']
    1129     nn = len(plot_quantity)
    1130     no_cols = 2
    1131     elev_output = []
    1132     if len(label_id) > 1: graphname_report = []
    1133     pp = 1
    1134     div = 11.
    1135     cc = 0
    1136     for k in gauge_index:
    1137         g = gauges[k]
    1138         count1 = 0
    1139         if report == True and len(label_id) > 1:
    1140             s = '\\begin{figure}[ht] \n \\centering \n \\begin{tabular}{cc} \n'
    1141             fid.write(s)
     1136
     1137    if generate_fig is True:
     1138        cstr = ['g', 'r', 'b', 'c', 'm', 'y', 'k']
     1139        nn = len(plot_quantity)
     1140        no_cols = 2
     1141        elev_output = []
    11421142        if len(label_id) > 1: graphname_report = []
    1143         #### generate figures for each gauge ####
    1144         for j, f in enumerate(f_list):
    1145             ion()
    1146             hold(True)
    1147             count = 0
    1148             where1 = 0
    1149             where2 = 0
    1150             word_quantity = ''
    1151             if report == True and len(label_id) == 1:
    1152                 s = '\\begin{figure}[hbt] \n \\centering \n \\begin{tabular}{cc} \n'
     1143        pp = 1
     1144        div = 11.
     1145        cc = 0
     1146        for k in gauge_index:
     1147            g = gauges[k]
     1148            count1 = 0
     1149            if report == True and len(label_id) > 1:
     1150                s = '\\begin{figure}[ht] \n \\centering \n \\begin{tabular}{cc} \n'
    11531151                fid.write(s)
    1154                
    1155             for which_quantity in plot_quantity:
    1156                 count += 1
    1157                 where1 += 1
    1158                 figure(count, frameon = False)
    1159                 if which_quantity == 'depth':
    1160                     plot(model_time[0:n[j]-1,k,j], depths[0:n[j]-1,k,j], '-', c = cstr[j])
    1161                     units = 'm'
    1162                     axis(depth_axis)
    1163                 if which_quantity == 'stage':
    1164                     if elevations[0,k,j] < 0:
    1165                         plot(model_time[0:n[j]-1,k,j], stages[0:n[j]-1,k,j], '-', c = cstr[j])
    1166                         axis(stage_axis)
     1152            if len(label_id) > 1: graphname_report = []
     1153            #### generate figures for each gauge ####
     1154            for j, f in enumerate(f_list):
     1155                ion()
     1156                hold(True)
     1157                count = 0
     1158                where1 = 0
     1159                where2 = 0
     1160                word_quantity = ''
     1161                if report == True and len(label_id) == 1:
     1162                    s = '\\begin{figure}[hbt] \n \\centering \n \\begin{tabular}{cc} \n'
     1163                    fid.write(s)
     1164                   
     1165                for which_quantity in plot_quantity:
     1166                    count += 1
     1167                    where1 += 1
     1168                    figure(count, frameon = False)
     1169                    if which_quantity == 'depth':
     1170                        plot(model_time[0:n[j]-1,k,j], depths[0:n[j]-1,k,j], '-', c = cstr[j])
     1171                        units = 'm'
     1172                        axis(depth_axis)
     1173                    if which_quantity == 'stage':
     1174                        if elevations[0,k,j] < 0:
     1175                            plot(model_time[0:n[j]-1,k,j], stages[0:n[j]-1,k,j], '-', c = cstr[j])
     1176                            axis(stage_axis)
     1177                        else:
     1178                            plot(model_time[0:n[j]-1,k,j], depths[0:n[j]-1,k,j], '-', c = cstr[j])
     1179                            axis(depth_axis)                 
     1180                        units = 'm'
     1181                    if which_quantity == 'momentum':
     1182                        plot(model_time[0:n[j]-1,k,j], momenta[0:n[j]-1,k,j], '-', c = cstr[j])
     1183                        axis(mom_axis)
     1184                        units = 'm^2 / sec'
     1185                    if which_quantity == 'xmomentum':
     1186                        plot(model_time[0:n[j]-1,k,j], xmom[0:n[j]-1,k,j], '-', c = cstr[j])
     1187                        axis(mom_axis)
     1188                        units = 'm^2 / sec'
     1189                    if which_quantity == 'ymomentum':
     1190                        plot(model_time[0:n[j]-1,k,j], ymom[0:n[j]-1,k,j], '-', c = cstr[j])
     1191                        axis(mom_axis)
     1192                        units = 'm^2 / sec'
     1193                    if which_quantity == 'speed':
     1194                        plot(model_time[0:n[j]-1,k,j], speed[0:n[j]-1,k,j], '-', c = cstr[j])
     1195                        axis(vel_axis)
     1196                        units = 'm / sec'
     1197                    if which_quantity == 'bearing':
     1198                        due_east = 90.0*ones(shape(model_time[0:n[j]-1,k,j],Float))
     1199                        due_west = 270.0*ones(shape(model_time[0:n[j]-1,k,j],Float))
     1200                        plot(model_time[0:n[j]-1,k,j], bearings, '-',
     1201                             model_time[0:n[j]-1,k,j], due_west, '-.',
     1202                             model_time[0:n[j]-1,k,j], due_east, '-.')
     1203                        units = 'degrees from North'
     1204                        ax = axis([time_min, time_max, 0.0, 360.0])
     1205                        legend(('Bearing','West','East'))
     1206
     1207                    xlabel('time (mins)')
     1208                    if which_quantity == 'stage' and elevations[0:n[j]-1,k,j] > 0:
     1209                        ylabel('%s (%s)' %('depth', units))
    11671210                    else:
    1168                         plot(model_time[0:n[j]-1,k,j], depths[0:n[j]-1,k,j], '-', c = cstr[j])
    1169                         axis(depth_axis)                 
    1170                     units = 'm'
    1171                 if which_quantity == 'momentum':
    1172                     plot(model_time[0:n[j]-1,k,j], momenta[0:n[j]-1,k,j], '-', c = cstr[j])
    1173                     axis(mom_axis)
    1174                     units = 'm^2 / sec'
    1175                 if which_quantity == 'xmomentum':
    1176                     plot(model_time[0:n[j]-1,k,j], xmom[0:n[j]-1,k,j], '-', c = cstr[j])
    1177                     axis(mom_axis)
    1178                     units = 'm^2 / sec'
    1179                 if which_quantity == 'ymomentum':
    1180                     plot(model_time[0:n[j]-1,k,j], ymom[0:n[j]-1,k,j], '-', c = cstr[j])
    1181                     axis(mom_axis)
    1182                     units = 'm^2 / sec'
    1183                 if which_quantity == 'speed':
    1184                     plot(model_time[0:n[j]-1,k,j], speed[0:n[j]-1,k,j], '-', c = cstr[j])
    1185                     axis(vel_axis)
    1186                     units = 'm / sec'
    1187                 if which_quantity == 'bearing':
    1188                     due_east = 90.0*ones(shape(model_time[0:n[j]-1,k,j],Float))
    1189                     due_west = 270.0*ones(shape(model_time[0:n[j]-1,k,j],Float))
    1190                     plot(model_time[0:n[j]-1,k,j], bearings, '-',
    1191                          model_time[0:n[j]-1,k,j], due_west, '-.',
    1192                          model_time[0:n[j]-1,k,j], due_east, '-.')
    1193                     units = 'degrees from North'
    1194                     ax = axis([time_min, time_max, 0.0, 360.0])
    1195                     legend(('Bearing','West','East'))
    1196 
    1197                 xlabel('time (mins)')
    1198                 if which_quantity == 'stage' and elevations[0:n[j]-1,k,j] > 0:
    1199                     ylabel('%s (%s)' %('depth', units))
    1200                 else:
    1201                     ylabel('%s (%s)' %(which_quantity, units))
    1202                 if len(label_id) > 1: legend((leg_label),loc='upper right')
    1203 
    1204                 gaugeloc1 = gaugeloc.replace(' ','')
    1205                 #gaugeloc2 = gaugeloc1.replace('_','')
    1206                 gaugeloc2 = locations[k].replace(' ','')
    1207                 graphname = '%sgauge%s_%s' %(file_loc[j], gaugeloc2, which_quantity)
    1208 
    1209                 if report == True and len(label_id) > 1:
    1210                     figdir = getcwd()+sep+'report_figures'+sep
    1211                     if access(figdir,F_OK) == 0 :
    1212                         mkdir (figdir)
    1213                     latex_file_loc = figdir.replace(sep,altsep)
    1214                     graphname_latex = '%sgauge%s%s' %(latex_file_loc, gaugeloc2, which_quantity) # storing files in production directory   
    1215                     graphname_report_input = '%sgauge%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity) # giving location in latex output file
    1216                     graphname_report.append(graphname_report_input)
     1211                        ylabel('%s (%s)' %(which_quantity, units))
     1212                    if len(label_id) > 1: legend((leg_label),loc='upper right')
     1213
     1214                    gaugeloc1 = gaugeloc.replace(' ','')
     1215                    #gaugeloc2 = gaugeloc1.replace('_','')
     1216                    gaugeloc2 = locations[k].replace(' ','')
     1217                    graphname = '%sgauge%s_%s' %(file_loc[j], gaugeloc2, which_quantity)
     1218
     1219                    if report == True and len(label_id) > 1:
     1220                        figdir = getcwd()+sep+'report_figures'+sep
     1221                        if access(figdir,F_OK) == 0 :
     1222                            mkdir (figdir)
     1223                        latex_file_loc = figdir.replace(sep,altsep)
     1224                        graphname_latex = '%sgauge%s%s' %(latex_file_loc, gaugeloc2, which_quantity) # storing files in production directory   
     1225                        graphname_report_input = '%sgauge%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity) # giving location in latex output file
     1226                        graphname_report.append(graphname_report_input)
     1227                       
     1228                        savefig(graphname_latex) # save figures in production directory for report generation
     1229
     1230                    if report == True:
     1231
     1232                        figdir = getcwd()+sep+'report_figures'+sep
     1233                        if access(figdir,F_OK) == 0 :
     1234                            mkdir (figdir)
     1235                        latex_file_loc = figdir.replace(sep,altsep)   
     1236
     1237                        if len(label_id) == 1:
     1238                            graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2) # storing files in production directory 
     1239                            graphname_report = '%sgauge%s%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity, label_id2) # giving location in latex output file
     1240                            s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report, '.png')
     1241                            fid.write(s)
     1242                            if where1 % 2 == 0:
     1243                                s = '\\\\ \n'
     1244                                where1 = 0
     1245                            else:
     1246                                s = '& \n'
     1247                            fid.write(s)
     1248                            savefig(graphname_latex)
    12171249                   
    1218                     savefig(graphname_latex) # save figures in production directory for report generation
    1219 
    1220                 if report == True:
    1221 
    1222                     figdir = getcwd()+sep+'report_figures'+sep
    1223                     if access(figdir,F_OK) == 0 :
    1224                         mkdir (figdir)
    1225                     latex_file_loc = figdir.replace(sep,altsep)   
    1226 
    1227                     if len(label_id) == 1:
    1228                         graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2) # storing files in production directory 
    1229                         graphname_report = '%sgauge%s%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity, label_id2) # giving location in latex output file
    1230                         s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report, '.png')
     1250                    if title_on == True:
     1251                        title('%s scenario: %s at %s gauge' %(label_id, which_quantity, gaugeloc2))
     1252
     1253                    savefig(graphname) # save figures with sww file
     1254
     1255                if report == True and len(label_id) == 1:
     1256                    for i in range(nn-1):
     1257                        if nn > 2:
     1258                            if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
     1259                                word_quantity += 'depth' + ', '
     1260                            else:
     1261                                word_quantity += plot_quantity[i] + ', '
     1262                        else:
     1263                            if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
     1264                                word_quantity += 'depth' + ', '
     1265                            else:
     1266                                word_quantity += plot_quantity[i]
     1267                       
     1268                    if plot_quantity[nn-1] == 'stage' and elevations[0,k,j] > 0:
     1269                        word_quantity += ' and ' + 'depth'
     1270                    else:
     1271                        word_quantity += ' and ' + plot_quantity[nn-1]
     1272                    caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elev[k]) #gaugeloc.replace('_',' '))
     1273                    if elev[k] == 0.0:
     1274                        caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elevations[0,k,j])
     1275                        east = gauges[0]
     1276                        north = gauges[1]
     1277                        elev_output.append([locations[k],east,north,elevations[0,k,j]])
     1278                    label = '%sgauge%s' %(label_id2, gaugeloc2)
     1279                    s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
     1280                    fid.write(s)
     1281                    cc += 1
     1282                    if cc % 6 == 0: fid.write('\\clearpage \n')
     1283                    savefig(graphname_latex)               
     1284                   
     1285            if report == True and len(label_id) > 1:
     1286                for i in range(nn-1):
     1287                    if nn > 2:
     1288                        if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
     1289                            word_quantity += 'depth' + ','
     1290                        else:
     1291                            word_quantity += plot_quantity[i] + ', '
     1292                    else:
     1293                        if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
     1294                            word_quantity += 'depth'
     1295                        else:
     1296                            word_quantity += plot_quantity[i]
     1297                    where1 = 0
     1298                    count1 += 1
     1299                    index = j*len(plot_quantity)
     1300                    for which_quantity in plot_quantity:
     1301                        where1 += 1
     1302                        s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report[index], '.png')
     1303                        index += 1
    12311304                        fid.write(s)
    12321305                        if where1 % 2 == 0:
     
    12361309                            s = '& \n'
    12371310                        fid.write(s)
    1238                         savefig(graphname_latex)
    1239                
    1240                 if title_on == True:
    1241                     title('%s scenario: %s at %s gauge' %(label_id, which_quantity, gaugeloc2))
    1242 
    1243                 savefig(graphname) # save figures with sww file
    1244 
    1245             if report == True and len(label_id) == 1:
    1246                 for i in range(nn-1):
    1247                     if nn > 2:
    1248                         if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
    1249                             word_quantity += 'depth' + ', '
    1250                         else:
    1251                             word_quantity += plot_quantity[i] + ', '
    1252                     else:
    1253                         if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
    1254                             word_quantity += 'depth' + ', '
    1255                         else:
    1256                             word_quantity += plot_quantity[i]
    1257                    
    1258                 if plot_quantity[nn-1] == 'stage' and elevations[0,k,j] > 0:
    1259                     word_quantity += ' and ' + 'depth'
    1260                 else:
    1261                     word_quantity += ' and ' + plot_quantity[nn-1]
    1262                 caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elev[k]) #gaugeloc.replace('_',' '))
     1311                word_quantity += ' and ' + plot_quantity[nn-1]           
     1312                label = 'gauge%s' %(gaugeloc2)
     1313                caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elev[k])
    12631314                if elev[k] == 0.0:
    1264                     caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elevations[0,k,j])
    1265                     east = gauges[0]
    1266                     north = gauges[1]
    1267                     elev_output.append([locations[k],east,north,elevations[0,k,j]])
    1268                 label = '%sgauge%s' %(label_id2, gaugeloc2)
     1315                        caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elevations[0,k,j])
     1316                        thisgauge = gauges[k]
     1317                        east = thisgauge[0]
     1318                        north = thisgauge[1]
     1319                        elev_output.append([locations[k],east,north,elevations[0,k,j]])
     1320                       
    12691321                s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
    12701322                fid.write(s)
    1271                 cc += 1
    1272                 if cc % 6 == 0: fid.write('\\clearpage \n')
    1273                 savefig(graphname_latex)               
     1323                if float((k+1)/div - pp) == 0.:
     1324                    fid.write('\\clearpage \n')
     1325                    pp += 1
    12741326               
    1275         if report == True and len(label_id) > 1:
    1276             for i in range(nn-1):
    1277                 if nn > 2:
    1278                     if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
    1279                         word_quantity += 'depth' + ','
    1280                     else:
    1281                         word_quantity += plot_quantity[i] + ', '
    1282                 else:
    1283                     if plot_quantity[i] == 'stage' and elevations[0,k,j] > 0:
    1284                         word_quantity += 'depth'
    1285                     else:
    1286                         word_quantity += plot_quantity[i]
    1287                 where1 = 0
    1288                 count1 += 1
    1289                 index = j*len(plot_quantity)
    1290                 for which_quantity in plot_quantity:
    1291                     where1 += 1
    1292                     s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report[index], '.png')
    1293                     index += 1
    1294                     fid.write(s)
    1295                     if where1 % 2 == 0:
    1296                         s = '\\\\ \n'
    1297                         where1 = 0
    1298                     else:
    1299                         s = '& \n'
    1300                     fid.write(s)
    1301             word_quantity += ' and ' + plot_quantity[nn-1]           
    1302             label = 'gauge%s' %(gaugeloc2)
    1303             caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elev[k])
    1304             if elev[k] == 0.0:
    1305                     caption = 'Time series for %s at %s location (elevation %.2fm)' %(word_quantity, locations[k], elevations[0,k,j])
    1306                     thisgauge = gauges[k]
    1307                     east = thisgauge[0]
    1308                     north = thisgauge[1]
    1309                     elev_output.append([locations[k],east,north,elevations[0,k,j]])
    1310                    
    1311             s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
    1312             fid.write(s)
    1313             if float((k+1)/div - pp) == 0.:
    1314                 fid.write('\\clearpage \n')
    1315                 pp += 1
    1316            
    1317             #### finished generating figures ###
    1318 
    1319         close('all')
    1320    
     1327                #### finished generating figures ###
     1328
     1329            close('all')
     1330       
    13211331    return texfile2, elev_output
    13221332
Note: See TracChangeset for help on using the changeset viewer.