Changeset 4935
- Timestamp:
- Jan 15, 2008, 9:08:44 AM (17 years ago)
- Location:
- anuga_core/source/anuga/abstract_2d_finite_volumes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r4918 r4935 1315 1315 1316 1316 list=[-8,-9,-6,-1,-4] 1317 min1, max1 = get_min_max_values(list ,10,-10)1317 min1, max1 = get_min_max_values(list) 1318 1318 1319 1319 # print 'min1,max1',min1,max1 … … 1321 1321 assert max1==-1 1322 1322 1323 def test_get_min_max_values2(self):1324 '''1325 The min and max supplied are greater than the ones in the1326 list and therefore are the ones returned1327 '''1328 list=[-8,-9,-6,-1,-4]1329 min1, max1 = get_min_max_values(list,-10,10)1330 1331 # print 'min1,max1',min1,max11332 assert min1==-101333 assert max1==101323 # def test_get_min_max_values2(self): 1324 # ''' 1325 # The min and max supplied are greater than the ones in the 1326 # list and therefore are the ones returned 1327 # ''' 1328 # list=[-8,-9,-6,-1,-4] 1329 # min1, max1 = get_min_max_values(list,-10,10) 1330 # 1331 ## print 'min1,max1',min1,max1 1332 # assert min1==-10 1333 # assert max1==10 1334 1334 1335 1335 def bad_test_make_plots_from_csv_files(self): … … 1472 1472 use_cache=False) 1473 1473 1474 point1_answers_array = [[0.0,1.0,-5.0,3.0,4.0], [2.0,10.0,-5.0,3.0,4.0]] 1474 # point1_answers_array = [[0.0,1.0,-5.0,3.0,4.0], [2.0,10.0,-5.0,3.0,4.0]] 1475 point1_answers_array = [[0.0,1.0,6.0,-5.0,3.0,4.0], [2.0,10.0,15.0,-5.0,3.0,4.0]] 1475 1476 point1_filename = 'gauge_point1.csv' 1476 1477 point1_handle = file(point1_filename) … … 1480 1481 line=[] 1481 1482 for i,row in enumerate(point1_reader): 1482 #print 'i',i,'row',row1483 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]) ])1483 #print 'i',i,'row',row 1484 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])]) 1484 1485 #print 'assert line',line[i],'point1',point1_answers_array[i] 1485 1486 assert allclose(line[i], point1_answers_array[i]) 1486 1487 1487 point2_answers_array = [[0.0,1.0, -0.5,3.0,4.0], [2.0,10.0,-0.5,3.0,4.0]]1488 point2_answers_array = [[0.0,1.0,1.5,-0.5,3.0,4.0], [2.0,10.0,10.5,-0.5,3.0,4.0]] 1488 1489 point2_filename = 'gauge_point2.csv' 1489 1490 point2_handle = file(point2_filename) … … 1493 1494 line=[] 1494 1495 for i,row in enumerate(point2_reader): 1495 #print 'i',i,'row',row1496 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]) ])1496 #print 'i',i,'row',row 1497 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])]) 1497 1498 #print 'assert line',line[i],'point1',point1_answers_array[i] 1498 1499 assert allclose(line[i], point2_answers_array[i]) … … 1587 1588 sww2csv_gauges(sww.filename, 1588 1589 points_file, 1589 quantities=[' Stage', 'elevation'],1590 quantities=['stage', 'elevation'], 1590 1591 use_cache=False, 1591 1592 verbose=False) … … 1641 1642 if __name__ == "__main__": 1642 1643 suite = unittest.makeSuite(Test_Util,'test') 1643 # suite = unittest.makeSuite(Test_Util,'test_sww2 ')1644 # suite = unittest.makeSuite(Test_Util,'test_sww2csv') 1644 1645 # runner = unittest.TextTestRunner(verbosity=2) 1645 1646 runner = unittest.TextTestRunner(verbosity=1) -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r4934 r4935 1532 1532 1533 1533 1534 def csv2timeseries_graphs(directories_dic={},1534 def OLD_csv2timeseries_graphs(directories_dic={}, 1535 1535 output_dir='', 1536 1536 base_name=None, … … 1540 1540 assess_all_csv_files=True, 1541 1541 create_latex=False, 1542 verbose= False):1542 verbose=True): 1543 1543 1544 """ 1545 WARNING!! NO UNIT TESTS... could make some as to test filename..but have 1544 """WARNING!! NO UNIT TESTS... could make some as to test filename..but have 1546 1545 spend ages on this already... 1547 1546 AND NOTE Create_latex is NOT implemented yet. … … 1573 1572 output_dir: directory for the plot outputs 1574 1573 1575 base_name: common name to all the csv files to be read 1574 base_name: common name to all the csv files to be read. if 1575 using plot_numbers must be the maximum common string 1576 eg. gauges0.csv, gauges1.csv and gauges2.csv 1577 base_name must be 'gauges' not 'gau' 1576 1578 1577 1579 plot_numbers: a String list of numbers to plot. For example 1578 1580 [0-4,10,15-17] will read and attempt to plot 1579 1581 the follow 0,1,2,3,4,10,15,16,17 1580 quantities: Currently limited to " Stage", "Speed", and1581 " Momentum", should be changed to incorporate1582 quantities: Currently limited to "stage", "speed", and 1583 "momentum", should be changed to incorporate 1582 1584 any quantity read from CSV file.... 1585 NOTE: ALL QUANTITY NAMES MUST BE lower case! 1583 1586 1584 1587 extra_plot_name: A string that is appended to the end of the … … 1608 1611 each plot will have 2 lines on them. The first plot named 'new' will have the time 1609 1612 offseted by 20secs and the stage height adjusted by -0.1m 1610 1611 1613 1612 1614 """ 1613 import pylab1615 # import pylab 1614 1616 try: 1615 1617 import pylab … … 1648 1650 #so to help find a uniform max and min for the plots... 1649 1651 list_filenames=[] 1652 #print'oaeuaoe',verbose 1650 1653 if verbose: print 'Determining files to access for axes ranges \n' 1654 #print 'heaoeu' 1651 1655 for i,directory in enumerate(directories_dic.keys()): 1656 #print 'base',basename,directory 1652 1657 list_filenames.append(get_all_files_with_extension(directory, 1653 1658 base_name,'.csv')) … … 1660 1665 min_start_time = 100000 1661 1666 1662 1667 print'hello' 1663 1668 new_plot_numbers=[] 1664 1669 #change plot_numbers to list, eg ['0-4','10'] … … 1690 1695 else: 1691 1696 dir_filename=join(directory,filename) 1692 #print'dir_filename',dir_filename1697 print'dir_filename',dir_filename 1693 1698 attribute_dic, title_index_dic = csv2dict(dir_filename+ 1694 1699 '.csv') … … 1735 1740 1736 1741 # print 'min_sp, max_sp',min_sp, max_sp, 1737 #print directory_start_time1742 print directory_start_time 1738 1743 if min_start_time > directory_start_time: 1739 1744 min_start_time = directory_start_time … … 1772 1777 legend_list =[] 1773 1778 for i, directory in enumerate(directories_dic.keys()): 1774 if verbose: print'Plotting in %s', directory 1775 for j, number in enumerate(new_plot_numbers): 1776 if verbose: print'Starting %s',base_name+number 1779 if verbose: print'Plotting in %s' %(directory) 1780 print new_plot_numbers,base_name 1781 1782 if assess_all_csv_files==False: 1783 which_csv_to_assess = new_plot_numbers 1784 else: 1785 which_csv_to_assess = list_filenames[i] 1786 1787 for j, number in enumerate(which_csv_to_assess): 1788 1789 # for j, number in enumerate(new_plot_numbers): 1790 print 'number',number 1791 if verbose: print'Starting %s%s'%(base_name,number) 1777 1792 directory_name = directories_dic[directory][0] 1778 1793 directory_start_time = directories_dic[directory][1] … … 1781 1796 #create an if about the start time and tide hieght 1782 1797 #if they don't exist 1783 file=directory+ sep+base_name+number1798 file=directory+number 1784 1799 #print 'i %s,j %s, number %s, file %s' %(i,j,number,file) 1785 1800 attribute_dic, title_index_dic = csv2dict(file+'.csv') … … 1809 1824 max_ele=-100000 1810 1825 min_ele=100000 1811 elevation = [float(x) for x in attribute_dic["elevation"]] 1826 # legend_list=[] 1827 if "elevation" in quantities: 1828 elevation = [float(x) for x in attribute_dic["elevation"]] 1812 1829 1813 min_ele, max_ele = get_min_max_values(elevation,1830 min_ele, max_ele = get_min_max_values(elevation, 1814 1831 min_ele, 1815 1832 max_ele) 1816 if min_ele != max_ele:1817 print "Note! Elevation changes in %s" %dir_filename1818 # print 'min_ele, max_ele',min_ele, max_ele1833 if min_ele != max_ele: 1834 print "Note! Elevation changes in %s" %dir_filename 1835 # print 'min_ele, max_ele',min_ele, max_ele 1819 1836 1820 1837 1821 #populates the legend_list_dic with dir_name and the elevation1822 if i==0:1823 legend_list_dic.append({directory_name:max_ele})1824 else:1825 legend_list_dic[j][directory_name]=max_ele1838 #populates the legend_list_dic with dir_name and the elevation 1839 if i==0: 1840 legend_list_dic.append({directory_name:max_ele}) 1841 else: 1842 legend_list_dic[j][directory_name]=max_ele 1826 1843 1827 # creates a list for the legend after at "legend_dic" has been fully populated 1828 # only runs on the last iteration for all the gauges(csv) files 1829 # empties the list before creating it 1844 # creates a list for the legend after at "legend_dic" has been fully populated 1845 # only runs on the last iteration for all the gauges(csv) files 1846 # empties the list before creating it 1847 1830 1848 if i==i_max-1: 1831 1849 legend_list=[] 1850 print 'legend',legend_list_dic, j 1832 1851 for k, l in legend_list_dic[j].iteritems(): 1833 legend_list.append('%s (elevation = %sm)'%(k,l)) 1834 #print k,l, legend_list_dic[j] 1852 # if "elevation" in quantities: 1853 # legend_list.append('%s (elevation = %sm)'%(k,l)) 1854 # else: 1855 legend_list.append('%s '%k) 1856 #print k,l, legend_list_dic[j] 1835 1857 1836 1858 if "stage" in quantities: … … 1964 1986 if verbose: print 'Finished closing plots' 1965 1987 1966 def XXX_csv2timeseries_graphs(directories_dic={},1988 def csv2timeseries_graphs(directories_dic={}, 1967 1989 output_dir='', 1968 base_name= '',1990 base_name=None, 1969 1991 plot_numbers='', 1970 1992 quantities=['stage'], 1971 1993 extra_plot_name='', 1972 assess_all_csv_files= False,1994 assess_all_csv_files=True, 1973 1995 create_latex=False, 1974 1996 verbose=False): 1975 1997 1976 """ 1977 NOTE! This code has NOT been removed as it is very close to working 1978 the same as the current code for sww2timeseries_graphs HOWEVER IT WOULD 1979 BE MUCH NICER!! instead of explicit if statments it uses loops and halves 1980 the number of lines of code.... but it doesn't work yet 1981 1982 Read in csv files that have the right header information and 1998 """ Read in csv files that have the right header information and 1983 1999 plot time series such as Stage, Speed, etc. Will also plot several 1984 2000 time series on one plot. Filenames must follow this convention, 1985 2001 <base_name><plot_number>.csv eg gauge_timeseries3.csv 2002 2003 NOTE: relies that 'elevation' is in the csv file! 1986 2004 1987 2005 Each file represents a location and within each file there are … … 1994 2012 one plot for each "quantities". ??? FIXME: unclear. 1995 2013 2014 Usage: 2015 csv2timeseries_graphs(directories_dic={'slide'+sep:['Slide',0, 0], 2016 'fixed_wave'+sep:['Fixed Wave',0,0]}, 2017 output_dir='fixed_wave'+sep, 2018 base_name='gauge_timeseries_', 2019 plot_numbers='', 2020 quantities=['stage','speed'], 2021 extra_plot_name='', 2022 assess_all_csv_files=True, 2023 create_latex=False, 2024 verbose=True) 2025 this will create one plot for stage with both 'slide' and 2026 'fixed_wave' lines on it for stage and speed for each csv 2027 file with 'gauge_timeseries_' as the prefix. The graghs 2028 will be in the output directory 'fixed_wave' and the graph 2029 axis will be determined by assessing all the 2030 2031 ANOTHER EXAMPLE 2032 new_csv2timeseries_graphs(directories_dic={'slide'+sep:['Slide',0, 0], 2033 'fixed_wave'+sep:['Fixed Wave',0,0]}, 2034 output_dir='fixed_wave'+sep, 2035 base_name='gauge_timeseries_', 2036 plot_numbers=['1-3'], 2037 quantities=['stage','speed'], 2038 extra_plot_name='', 2039 assess_all_csv_files=False, 2040 create_latex=False, 2041 verbose=True) 2042 This will plot csv files called gauge_timeseries_1.csv and 2043 gauge_timeseries3.csv from both 'slide' and 'fixed_wave' directories 2044 to 'fixed_wave'. There will be 4 plots created two speed and two stage 2045 one for each csv file. There will be two lines on each of these plots. 2046 And the axis will have been determined from only these files, had 2047 assess_all_csv_files = True all csv file with 'gauges_timeseries_' prefix 2048 would of been assessed. 2049 2050 ANOTHER EXAMPLE 2051 csv2timeseries_graphs({'J:'+sep+'anuga_validation'+sep:['new',20,-.1], 2052 'J:'+sep+'conical_island'+sep:['test',0,0]}, 2053 output_dir='', 2054 plot_numbers=['1','3'], 2055 quantities=['stage','depth','bearing'], 2056 base_name='gauge_b', 2057 assess_all_csv_files=True, 2058 verbose=True) 2059 2060 This will produce one plot for each quantity (therefore 3) in the current directory, 2061 each plot will have 2 lines on them. The first plot named 'new' will have the time 2062 offseted by 20secs and the stage height adjusted by -0.1m 2063 1996 2064 Inputs: 1997 2065 directories_dic: dictionary of directory with values (plot … … 2003 2071 dir3:['b_ons',5000,1.5]} 2004 2072 2005 output_dir: directory for the plot outputs 2006 2007 base_name: common name to all the csv files to be read, Note is 2008 ignored if assess_all_csv_files=True 2073 output_dir: directory for the plot outputs, essential to define 2074 if you want a plot with multiple timeseries. 2075 2076 base_name: Is used a couple of times. 1) to find the csv files to be plotted 2077 if there is no 'plot_numbers' then csv files with 'base_name' are 2078 plotted and 2) in the title of the plots, the lenght of base_name is 2079 removed from the front of the filename to be used in the title. 2080 This could be changed if needed. 2081 Note is ignored if assess_all_csv_files=True 2009 2082 2010 2083 plot_numbers: a String list of numbers to plot. For example 2011 2084 [0-4,10,15-17] will read and attempt to plot 2012 2085 the follow 0,1,2,3,4,10,15,16,17 2013 NOTE: if no plot numbers this will create only2014 one plot per quantity 2086 NOTE: if no plot numbers this will create 2087 one plot per quantity, per gauge 2015 2088 quantities: Currently limited to "stage", "speed", and 2016 2089 "Momentum", should be changed to incorporate … … 2031 2104 OUTPUTS: None, it saves the plots to 2032 2105 <output_dir><base_name><plot_number><extra_plot_name>.png 2106 2107 KNOWN PROBLEMS: Currently the axis for the stage/depth will be incorporate 2108 2033 2109 """ 2034 2110 2035 import pylab# import plot, xlabel, ylabel, savefig, \ 2036 #ion, hold, axis, close, figure, legend 2111 import pylab 2037 2112 from os import sep 2038 2113 from anuga.shallow_water.data_manager import \ 2039 2114 get_all_files_with_extension, csv2dict 2040 #find all the files that meet the specs2041 2115 2042 2116 seconds_in_hour = 3600 2117 seconds_in_minutes = 60 2043 2118 2044 2119 quantities_label={} 2045 quantities_label['time'] = 'time (hour)' 2120 # quantities_label['time'] = 'time (hours)' 2121 quantities_label['time'] = 'time (minutes)' 2046 2122 quantities_label['stage'] = 'wave height (m)' 2047 2123 quantities_label['speed'] = 'speed (m/s)' 2048 2124 quantities_label['momentum'] = 'momentum (m^2/sec)' 2049 quantities_label['depth'] = ' momentum (m^2/sec)'2125 quantities_label['depth'] = 'water depth (m)' 2050 2126 quantities_label['xmomentum'] = 'momentum (m^2/sec)' 2051 2127 quantities_label['ymomentum'] = 'momentum (m^2/sec)' 2052 quantities_label['bearing'] = 'degrees' 2128 quantities_label['bearing'] = 'degrees (o)' 2129 quantities_label['elevation'] = 'elevation (m)' 2130 2053 2131 2054 2132 if extra_plot_name != '': … … 2067 2145 new_plot_numbers.append(num_string) 2068 2146 2069 #finds all the files that fit the specs and return a list of them2147 #finds all the files that fit the specs provided and return a list of them 2070 2148 #so to help find a uniform max and min for the plots... 2071 2149 list_filenames=[] 2072 filenames=[]2073 2150 all_csv_filenames=[] 2074 2151 if verbose: print 'Determining files to access for axes ranges \n' … … 2078 2155 all_csv_filenames.append(get_all_files_with_extension(directory, 2079 2156 base_name,'.csv')) 2080 if assess_all_csv_files==True: 2157 2158 filenames=[] 2159 if plot_numbers == '': 2081 2160 list_filenames.append(get_all_files_with_extension(directory, 2082 2161 base_name,'.csv')) 2083 2162 else: 2084 if plot_numbers == '': 2085 list_filenames.append(base_name) 2086 else: 2087 for number in new_plot_numbers: 2088 filenames.append(base_name+number) 2089 list_filenames.append(filenames) 2090 print "list_filenames", list_filenames 2163 for number in new_plot_numbers: 2164 # print 'number!!!', base_name, number 2165 filenames.append(base_name+number) 2166 # print filenames 2167 list_filenames.append(filenames) 2168 2169 2170 2171 # print "list_filenames", list_filenames 2091 2172 2092 2173 #use all the files to get the values for the plot axis 2093 #max_st=max_sp=max_mom=min_st=min_sp=min_mom=max_t=min_t=0.2094 max_t=-1002095 min_t=1000002096 2174 max_start_time= -1000. 2097 2175 min_start_time = 100000 … … 2101 2179 #axes of the plots 2102 2180 2103 quantities.insert(0,'time') 2181 # quantities.insert(0,'elevation') 2182 quantities.insert(0,'time') 2183 2184 quantity_value={} 2185 min_quantity_value={} 2186 max_quantity_value={} 2187 2104 2188 2105 2189 for i, directory in enumerate(directories_dic.keys()): … … 2113 2197 2114 2198 for j, filename in enumerate(which_csv_to_assess): 2115 # for j, filename in enumerate(list_filenames[i]):2116 2199 2117 2200 dir_filename=join(directory,filename) … … 2122 2205 directory_add_tide = directories_dic[directory][2] 2123 2206 2124 print 'keys',attribute_dic.keys() 2125 quantity_value={} 2126 min_quantity_value={} 2127 max_quantity_value={} 2128 # print 'Quantities',quantities, attribute_dic 2129 2207 # print 'keys',attribute_dic.keys() 2130 2208 #add time to get values 2131 2209 for k, quantity in enumerate(quantities): 2132 2210 quantity_value[quantity] = [float(x) for x in attribute_dic[quantity]] 2133 min_quantity_value[quantity], max_quantity_value[quantity] = get_min_max_values(quantity_value[quantity],\ 2134 min_t,max_t) 2135 2211 2212 #add tide to stage if provided 2136 2213 if quantity == 'stage': 2137 2214 quantity_value[quantity]=array(quantity_value[quantity])+directory_add_tide 2215 2216 #condition to find max and mins for all the plots 2217 # populate the list with something when i=0 and j=0 and 2218 # then compare to the other values to determine abs max and min 2219 if i==0 and j==0: 2220 2221 min_quantity_value[quantity], \ 2222 max_quantity_value[quantity] = get_min_max_values(quantity_value[quantity]) 2223 2224 # print '1 min,max',i,j,k,quantity, min_quantity_value[quantity],max_quantity_value[quantity],directory, filename 2225 else: 2226 # print 'min,max',i,j,k,quantity, min_quantity_value[quantity],max_quantity_value[quantity],directory, filename 2227 min, max = get_min_max_values(quantity_value[quantity]) 2228 2229 if min<min_quantity_value[quantity]: min_quantity_value[quantity]=min 2230 if max>max_quantity_value[quantity]: max_quantity_value[quantity]=max 2231 2232 #print 'min,maj',quantity, min_quantity_value[quantity],max_quantity_value[quantity] 2233 2234 #add tide to stage if provided 2235 # if quantity == 'stage': 2236 # quantity_value[quantity]=array(quantity_value[quantity])+directory_add_tide 2138 2237 2139 2238 #set the time... ??? … … 2142 2241 if max_start_time < directory_start_time: 2143 2242 max_start_time = directory_start_time 2144 #print 'start_time' , max_start_time, min_start_time2243 #print 'start_time' , max_start_time, min_start_time 2145 2244 2146 2245 … … 2148 2247 quantities_axis={} 2149 2248 for i, quantity in enumerate(quantities): 2150 print 'max_t %s max_start_time, seconds_in_hour',max_t, max_start_time, seconds_in_hour2151 quantities_axis[quantity] = (min_start_time/seconds_in_hour,2152 (max_quantity_value['time']+max_start_time)/seconds_in_hour,2249 quantities_axis[quantity] = (min_start_time/seconds_in_minutes, 2250 (max_quantity_value['time']+max_start_time)\ 2251 /seconds_in_minutes, 2153 2252 min_quantity_value[quantity], 2154 2253 max_quantity_value[quantity]) 2155 print 'axis for quantity %s are %s' %(quantity, quantities_axis[quantity]) 2254 if verbose and (quantity != 'time' and quantity != 'elevation'): 2255 print 'axis for quantity %s are x:(%s to %s)%s and y:(%s to %s)%s' %(quantity, 2256 quantities_axis[quantity][0], 2257 quantities_axis[quantity][1], 2258 quantities_label['time'], 2259 quantities_axis[quantity][2], 2260 quantities_axis[quantity][3], 2261 quantities_label[quantity]) 2262 print quantities_axis[quantity] 2156 2263 2157 2264 cstr = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] 2158 2265 2159 2160 2266 if verbose: print 'Now start to plot \n' 2161 2267 … … 2164 2270 legend_list =[] 2165 2271 for i, directory in enumerate(directories_dic.keys()): 2166 if verbose: print'Plotting in %s ' %directory, new_plot_numbers2167 # for j, number in enumerate(new_plot_numbers):2272 if verbose: print'Plotting in %s %s' %(directory, new_plot_numbers) 2273 # print 'LIST',list_filenames 2168 2274 for j, filename in enumerate(list_filenames[i]): 2169 2275 2170 # if verbose: print'Starting %s' %base_name+number2171 2276 if verbose: print'Starting %s' %filename 2172 2277 directory_name = directories_dic[directory][0] … … 2176 2281 #create an if about the start time and tide hieght 2177 2282 #if they don't exist 2178 # file=directory+sep+base_name+number2179 2283 #print 'i %s,j %s, number %s, file %s' %(i,j,number,file) 2180 attribute_dic, title_index_dic = csv2dict( filename+'.csv')2284 attribute_dic, title_index_dic = csv2dict(directory+filename+'.csv') 2181 2285 #get data from dict in to list 2182 2286 t = [float(x) for x in attribute_dic["time"]] 2183 2287 2184 2288 #do maths to list by changing to array 2185 t=(array(t)+directory_start_time)/seconds_in_ hour2289 t=(array(t)+directory_start_time)/seconds_in_minutes 2186 2290 2187 2291 #finds the maximum elevation, used only as a test … … 2191 2295 elevation = [float(x) for x in attribute_dic["elevation"]] 2192 2296 2193 min_ele, max_ele = get_min_max_values(elevation, 2194 min_ele, 2195 max_ele) 2297 min_ele, max_ele = get_min_max_values(elevation) 2298 2196 2299 if min_ele != max_ele: 2197 2300 print "Note! Elevation changes in %s" %dir_filename … … 2199 2302 #populates the legend_list_dic with dir_name and the elevation 2200 2303 if i==0: 2201 legend_list_dic.append({directory_name: max_ele})2304 legend_list_dic.append({directory_name:round(max_ele,2)}) 2202 2305 else: 2203 print j,max_ele, directory_name, legend_list_dic2204 legend_list_dic[j][directory_name]= max_ele2306 #print j,max_ele, directory_name, legend_list_dic 2307 legend_list_dic[j][directory_name]=round(max_ele,2) 2205 2308 2206 2309 # creates a list for the legend after at "legend_dic" has been fully populated … … 2213 2316 #print k,l, legend_list_dic[j] 2214 2317 2215 print 'filename',filename, quantities2318 #print 'filename',filename, quantities 2216 2319 #remove time so it is not plotted! 2217 # quantities.remove('time')2218 2320 for k, quantity in enumerate(quantities): 2219 if quantity != 'time' :2321 if quantity != 'time' and quantity != 'elevation': 2220 2322 quantity_value[quantity] = [float(x) for x in attribute_dic[quantity]] 2221 2222 if quantity=='stage': 2223 quantity_value[quantity] =array(quantity_value[quantity])+directory_add_tide 2224 2225 #Can add tide so plots are all on the same tide height 2226 # print'plot stuff',quantities_label['time'] 2227 # print quantities_label[quantity] 2228 # print quantities_axis[quantity] 2323 2229 2324 num=int(k*100+j) 2230 2325 pylab.figure(num) 2326 # note if elevation is greater than 0m the stage plot is called 'depth' and the stage has 2327 # the elevation minused from it. This allows the plots to make more sense see manual 2328 # section 4.7 2329 # if quantity=='stage': 2330 # quantity_value[quantity] =array(quantity_value[quantity])+directory_add_tide 2331 2332 # if min_ele>=0: 2333 # quantity_value['stage']=array(quantity_value['stage'])-min_ele 2334 # pylab.ylabel(quantities_label['depth']) 2335 # pylab.axis([quantities_axis['stage'][0], 2336 # quantities_axis['stage'][1], 2337 # quantities_axis['stage'][2], 2338 # quantities_axis['stage'][3]])#-quantities_axis['elevation'][3]]) 2339 # print "AXIS", quantities_axis['stage'] 2340 # else: 2341 # pylab.ylabel(quantities_label['stage']) 2342 # else: 2343 # pylab.ylabel(quantities_label[quantity]) 2344 pylab.ylabel(quantities_label[quantity]) 2231 2345 pylab.plot(t, quantity_value[quantity], c = cstr[i], linewidth=1) 2232 2346 pylab.xlabel(quantities_label['time']) 2233 pylab.ylabel(quantities_label[quantity])2234 2347 pylab.axis(quantities_axis[quantity]) 2235 2348 pylab.legend(legend_list,loc='upper right') 2349 pylab.title('%s at %s gauge' %(quantity,filename[len(base_name):])) 2236 2350 if output_dir == '': 2237 2351 figname = '%s%s_%s%s.png' %(directory, … … 2253 2367 2254 2368 2255 def get_min_max_values(list=None,min1=100,max1=-100):2369 def old_get_min_max_values(list=None,min1=100000,max1=-100000): 2256 2370 """ Returns the min and max of the list it was provided. 2257 2371 NOTE: default min and max may need to change depeending on … … 2259 2373 """ 2260 2374 if list == None: print 'List must be provided' 2261 # min = max_list = 02262 2375 if max(list) > max1: 2263 2376 max1 = max(list) … … 2266 2379 2267 2380 return min1, max1 2381 2382 def get_min_max_values(list=None): 2383 """ 2384 Returns the min and max of the list it was provided. 2385 """ 2386 if list == None: print 'List must be provided' 2387 2388 return min(list), max(list) 2268 2389 2269 2390 … … 2322 2443 def sww2csv_gauges(sww_file, 2323 2444 gauge_file, 2324 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],2445 quantities = ['stage','depth', 'elevation', 'xmomentum', 'ymomentum'], 2325 2446 verbose=False, 2326 2447 use_cache = True): … … 2329 2450 Inputs: 2330 2451 2331 sww_file: ... 2452 NOTE: if using csv2timeseries_graphs after creating csv file, it is essential to 2453 export quantities 'depth' and 'elevation'. 'depth' is good to analyse gauges on 2454 land and elevation is used automatically by csv2timeseries_graphs in the legend. 2455 2456 sww_file: path to any sww file 2332 2457 2333 2458 points_file: Assumes that it follows this format … … 2448 2573 heading = [quantity for quantity in quantities] 2449 2574 heading.insert(0,'time') 2575 2450 2576 # print heading, quantities 2451 2577 … … 2453 2579 points_writer = [] 2454 2580 for i,point in enumerate(points): 2455 points_writer.append(writer(file( 'gauge_'+point_name[i]+'.csv', "wb")))2581 points_writer.append(writer(file(dir_name+sep+'gauge_'+point_name[i]+'.csv', "wb"))) 2456 2582 points_writer[i].writerow(heading) 2457 2583
Note: See TracChangeset
for help on using the changeset viewer.