Changeset 2981
- Timestamp:
- May 25, 2006, 6:16:16 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/util.py
r2965 r2981 717 717 718 718 return generate_figures(plot_quantity, file_loc, report, 719 f, gauges, locations, 719 f, gauges, locations, 720 720 time_min, time_max, title_on, label_id, verbose) 721 721 722 722 723 723 def get_gauges_from_file(filename): 724 from os import sep, getcwd, access, F_OK, mkdir 724 725 fid = open(filename) 725 726 lines = fid.readlines() … … 740 741 loc = fields[name_index] 741 742 gaugelocation.append(loc.strip('\n')) 742 743 743 744 return gauges, gaugelocation 744 745 … … 778 779 779 780 from math import sqrt, atan, degrees 780 from Numeric import ones, allclose 781 from Numeric import ones, allclose, zeros, Float 781 782 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 783 785 784 786 filename = file_loc.split(sep) 785 787 786 788 if report == True: 787 789 label_id1 = label_id.replace(sep,'') … … 794 796 texfilename = texfile + '.tex' 795 797 if verbose: print '\n Latex output printed to %s \n' %texfilename 796 797 798 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 = gauges801 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)809 799 else: 810 800 texfile = '' 811 801 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 = [] 812 818 c = 0 813 819 ##### loop over each gauge ##### 814 820 for k, g in enumerate(gauges): 815 821 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 826 824 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) 829 831 #### generate quantities ####### 832 830 833 for i, t in enumerate(f.get_time()): 831 832 834 if time_min <= t <= time_max: 833 834 835 w = f(t, point_id = k)[0] 835 836 z = f(t, point_id = k)[1] 836 837 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 841 840 m = sqrt(uh*uh + vh*vh) 842 841 if m < 0.001: … … 845 844 vel = m / (depth + 1.e-30) 846 845 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 859 859 if m > max_momentum: max_momentum = m 860 860 if vel > max_velocity: max_velocity = vel 861 861 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 862 867 #### 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): 864 876 #### generate figures ### 865 877 ion() 866 878 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) 871 890 if which_quantity == 'depth': 872 plot(model_time , depths, '-')891 plot(model_time[:,k], depths[:,k], '-') 873 892 units = 'm' 874 893 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) 879 896 units = 'm' 880 897 if which_quantity == 'momentum': 881 plot(model_time, momenta, '-') 898 plot(model_time[:,k], momenta[:,k], '-') 899 axis(mom_axis) 882 900 units = 'm^2 / sec' 883 901 if which_quantity == 'xmomentum': 884 plot(model_time, xmom, '-') 902 plot(model_time[:,k], xmom[:,k], '-') 903 axis(mom_axis) 885 904 units = 'm^2 / sec' 886 905 if which_quantity == 'ymomentum': 887 plot(model_time, ymom, '-') 906 plot(model_time[:,k], ymom[:,k], '-') 907 axis(mom_axis) 888 908 units = 'm^2 / sec' 889 909 if which_quantity == 'velocity': 890 plot(model_time, velocity, '-') 910 plot(model_time[:,k], velocity[:,k], '-') 911 axis(vel_axis) 891 912 units = 'm / sec' 892 913 if which_quantity == 'bearing': … … 903 924 904 925 gaugeloc1 = gaugeloc.replace(' ','') 905 gaugeloc2 = gaugeloc1.replace('_','') 926 #gaugeloc2 = gaugeloc1.replace('_','') 927 gaugeloc2 = locations[k].replace(' ','') 906 928 graphname = '%sgauge%s_%s' %(file_loc, gaugeloc2, which_quantity) 907 929 … … 915 937 # storing files in production directory 916 938 graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2) 939 917 940 # giving location in latex output file 918 941 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') 923 944 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' 925 950 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') 928 960 savefig(graphname_latex) # save figures in production directory for report generation 929 961 … … 933 965 savefig(graphname) # save figures with sww file 934 966 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 943 982 944 983 #### finished generating figures ###
Note: See TracChangeset
for help on using the changeset viewer.