Changeset 4935


Ignore:
Timestamp:
Jan 15, 2008, 9:08:44 AM (17 years ago)
Author:
nick
Message:

more updates to csv2timeseries_graphs

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  
    13151315       
    13161316        list=[-8,-9,-6,-1,-4]
    1317         min1, max1 = get_min_max_values(list,10,-10)
     1317        min1, max1 = get_min_max_values(list)
    13181318       
    13191319#        print 'min1,max1',min1,max1
     
    13211321        assert max1==-1
    13221322
    1323     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
     1323#    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
    13341334       
    13351335    def bad_test_make_plots_from_csv_files(self):
     
    14721472                            use_cache=False)
    14731473
    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]]
    14751476        point1_filename = 'gauge_point1.csv'
    14761477        point1_handle = file(point1_filename)
     
    14801481        line=[]
    14811482        for i,row in enumerate(point1_reader):
    1482 #            print 'i',i,'row',row
    1483             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])])
    14841485            #print 'assert line',line[i],'point1',point1_answers_array[i]
    14851486            assert allclose(line[i], point1_answers_array[i])
    14861487
    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]]
    14881489        point2_filename = 'gauge_point2.csv'
    14891490        point2_handle = file(point2_filename)
     
    14931494        line=[]
    14941495        for i,row in enumerate(point2_reader):
    1495 #            print 'i',i,'row',row
    1496             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])])
    14971498            #print 'assert line',line[i],'point1',point1_answers_array[i]
    14981499            assert allclose(line[i], point2_answers_array[i])
     
    15871588        sww2csv_gauges(sww.filename,
    15881589                            points_file,
    1589                             quantities=['Stage', 'elevation'],
     1590                            quantities=['stage', 'elevation'],
    15901591                            use_cache=False,
    15911592                            verbose=False)
     
    16411642if __name__ == "__main__":
    16421643    suite = unittest.makeSuite(Test_Util,'test')
    1643 #    suite = unittest.makeSuite(Test_Util,'test_sww2')
     1644#    suite = unittest.makeSuite(Test_Util,'test_sww2csv')
    16441645#    runner = unittest.TextTestRunner(verbosity=2)
    16451646    runner = unittest.TextTestRunner(verbosity=1)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4934 r4935  
    15321532   
    15331533
    1534 def csv2timeseries_graphs(directories_dic={},
     1534def OLD_csv2timeseries_graphs(directories_dic={},
    15351535                            output_dir='',
    15361536                            base_name=None,
     
    15401540                            assess_all_csv_files=True,                           
    15411541                            create_latex=False,
    1542                             verbose=False):
     1542                            verbose=True):
    15431543                               
    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
    15461545    spend ages on this already...
    15471546    AND NOTE Create_latex is NOT implemented yet.
     
    15731572        output_dir: directory for the plot outputs
    15741573       
    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'
    15761578       
    15771579        plot_numbers: a String list of numbers to plot. For example
    15781580                      [0-4,10,15-17] will read and attempt to plot
    15791581                       the follow 0,1,2,3,4,10,15,16,17
    1580         quantities: Currently limited to "Stage", "Speed", and
    1581                      "Momentum", should be changed to incorporate
     1582        quantities: Currently limited to "stage", "speed", and
     1583                     "momentum", should be changed to incorporate
    15821584                    any quantity read from CSV file....
     1585                    NOTE: ALL QUANTITY NAMES MUST BE lower case!
    15831586                   
    15841587        extra_plot_name: A string that is appended to the end of the
     
    16081611            each plot will have 2 lines on them. The first plot named 'new' will have the time
    16091612            offseted by 20secs and the stage height adjusted by -0.1m
    1610 
    16111613   
    16121614    """
    1613     import pylab
     1615#    import pylab
    16141616    try:
    16151617        import pylab
     
    16481650    #so to help find a uniform max and min for the plots...
    16491651    list_filenames=[]
     1652    #print'oaeuaoe',verbose
    16501653    if verbose: print 'Determining files to access for axes ranges \n'
     1654    #print 'heaoeu'
    16511655    for i,directory in enumerate(directories_dic.keys()):
     1656        #print 'base',basename,directory
    16521657        list_filenames.append(get_all_files_with_extension(directory,
    16531658                              base_name,'.csv'))
     
    16601665    min_start_time = 100000
    16611666
    1662    
     1667    print'hello'
    16631668    new_plot_numbers=[]
    16641669    #change plot_numbers to list, eg ['0-4','10']
     
    16901695            else:
    16911696                dir_filename=join(directory,filename)
    1692 #            print'dir_filename',dir_filename
     1697            print'dir_filename',dir_filename
    16931698            attribute_dic, title_index_dic = csv2dict(dir_filename+
    16941699                                                       '.csv')
     
    17351740                                                                     
    17361741#            print 'min_sp, max_sp',min_sp, max_sp,
    1737             # print directory_start_time
     1742            print directory_start_time
    17381743            if min_start_time > directory_start_time:
    17391744                min_start_time = directory_start_time
     
    17721777    legend_list =[]
    17731778    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) 
    17771792            directory_name = directories_dic[directory][0]
    17781793            directory_start_time = directories_dic[directory][1]
     
    17811796            #create an if about the start time and tide hieght
    17821797            #if they don't exist
    1783             file=directory+sep+base_name+number
     1798            file=directory+number
    17841799            #print 'i %s,j %s, number %s, file %s' %(i,j,number,file)
    17851800            attribute_dic, title_index_dic = csv2dict(file+'.csv')
     
    18091824            max_ele=-100000
    18101825            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"]]
    18121829           
    1813             min_ele, max_ele = get_min_max_values(elevation,
     1830                min_ele, max_ele = get_min_max_values(elevation,
    18141831                                                  min_ele,
    18151832                                                  max_ele)
    1816             if min_ele != max_ele:
    1817                 print "Note! Elevation changes in %s" %dir_filename
    1818 #            print 'min_ele, max_ele',min_ele, max_ele
     1833                if min_ele != max_ele:
     1834                    print "Note! Elevation changes in %s" %dir_filename
     1835#                print 'min_ele, max_ele',min_ele, max_ele
    18191836           
    18201837
    1821             #populates the legend_list_dic with dir_name and the elevation
    1822             if i==0:
    1823                 legend_list_dic.append({directory_name:max_ele})
    1824             else:
    1825                 legend_list_dic[j][directory_name]=max_ele
     1838                #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
    18261843           
    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 
    18301848            if i==i_max-1:
    18311849                legend_list=[]
     1850                print 'legend',legend_list_dic, j
    18321851                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]
    18351857         
    18361858            if "stage" in quantities:
     
    19641986    if verbose: print 'Finished closing plots'
    19651987   
    1966 def XXX_csv2timeseries_graphs(directories_dic={},
     1988def csv2timeseries_graphs(directories_dic={},
    19671989                            output_dir='',
    1968                             base_name='',
     1990                            base_name=None,
    19691991                            plot_numbers='',
    19701992                            quantities=['stage'],
    19711993                            extra_plot_name='',
    1972                             assess_all_csv_files=False,                           
     1994                            assess_all_csv_files=True,                           
    19731995                            create_latex=False,
    19741996                            verbose=False):
    19751997                               
    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
    19831999    plot time series such as Stage, Speed, etc. Will also plot several
    19842000    time series on one plot. Filenames must follow this convention,
    19852001    <base_name><plot_number>.csv eg gauge_timeseries3.csv
     2002   
     2003    NOTE: relies that 'elevation' is in the csv file!
    19862004
    19872005    Each file represents a location and within each file there are
     
    19942012    one plot for each "quantities".  ??? FIXME: unclear.
    19952013   
     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       
    19962064    Inputs:
    19972065        directories_dic: dictionary of directory with values (plot
     
    20032071                         dir3:['b_ons',5000,1.5]}
    20042072                         
    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
    20092082       
    20102083        plot_numbers: a String list of numbers to plot. For example
    20112084                      [0-4,10,15-17] will read and attempt to plot
    20122085                       the follow 0,1,2,3,4,10,15,16,17
    2013                        NOTE: if no plot numbers this will create only
    2014                        one plot per quantity
     2086                       NOTE: if no plot numbers this will create
     2087                       one plot per quantity, per gauge
    20152088        quantities: Currently limited to "stage", "speed", and
    20162089                     "Momentum", should be changed to incorporate
     
    20312104    OUTPUTS: None, it saves the plots to
    20322105              <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     
    20332109    """
    20342110
    2035     import pylab# import plot, xlabel, ylabel, savefig, \
    2036                 #ion, hold, axis, close, figure, legend
     2111    import pylab
    20372112    from os import sep
    20382113    from anuga.shallow_water.data_manager import \
    20392114                               get_all_files_with_extension, csv2dict
    2040     #find all the files that meet the specs
    20412115
    20422116    seconds_in_hour = 3600
     2117    seconds_in_minutes = 60
    20432118   
    20442119    quantities_label={}
    2045     quantities_label['time'] = 'time (hour)'
     2120#    quantities_label['time'] = 'time (hours)'
     2121    quantities_label['time'] = 'time (minutes)'
    20462122    quantities_label['stage'] = 'wave height (m)'
    20472123    quantities_label['speed'] = 'speed (m/s)'
    20482124    quantities_label['momentum'] = 'momentum (m^2/sec)'
    2049     quantities_label['depth'] = 'momentum (m^2/sec)'
     2125    quantities_label['depth'] = 'water depth (m)'
    20502126    quantities_label['xmomentum'] = 'momentum (m^2/sec)'
    20512127    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
    20532131   
    20542132    if extra_plot_name != '':
     
    20672145            new_plot_numbers.append(num_string)
    20682146
    2069     #finds all the files that fit the specs and return a list of them
     2147    #finds all the files that fit the specs provided and return a list of them
    20702148    #so to help find a uniform max and min for the plots...
    20712149    list_filenames=[]
    2072     filenames=[]
    20732150    all_csv_filenames=[]
    20742151    if verbose: print 'Determining files to access for axes ranges \n'
     
    20782155        all_csv_filenames.append(get_all_files_with_extension(directory,
    20792156                                  base_name,'.csv'))
    2080         if assess_all_csv_files==True:
     2157
     2158        filenames=[]
     2159        if plot_numbers == '':
    20812160            list_filenames.append(get_all_files_with_extension(directory,
    20822161                                  base_name,'.csv'))
    20832162        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
    20912172
    20922173    #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=-100
    2095     min_t=100000
    20962174    max_start_time= -1000.
    20972175    min_start_time = 100000
     
    21012179    #axes of the plots
    21022180
    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
    21042188   
    21052189    for i, directory in enumerate(directories_dic.keys()):
     
    21132197       
    21142198        for j, filename in enumerate(which_csv_to_assess):
    2115 #        for j, filename in enumerate(list_filenames[i]):
    21162199
    21172200            dir_filename=join(directory,filename)
     
    21222205            directory_add_tide = directories_dic[directory][2]
    21232206
    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()
    21302208            #add time to get values
    21312209            for k, quantity in enumerate(quantities):
    21322210                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
    21362213                if quantity == 'stage':
    21372214                     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
    21382237
    21392238            #set the time... ???
     
    21422241            if max_start_time < directory_start_time:
    21432242                max_start_time = directory_start_time
    2144 #            print 'start_time' , max_start_time, min_start_time
     2243            #print 'start_time' , max_start_time, min_start_time
    21452244   
    21462245
     
    21482247    quantities_axis={}
    21492248    for i, quantity in enumerate(quantities):
    2150         print 'max_t %s max_start_time, seconds_in_hour',max_t, max_start_time, seconds_in_hour
    2151         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,
    21532252                                         min_quantity_value[quantity],
    21542253                                         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]
    21562263
    21572264    cstr = ['b', 'r', 'g', 'c', 'm', 'y', 'k']
    21582265
    2159    
    21602266    if verbose: print 'Now start to plot \n'
    21612267   
     
    21642270    legend_list =[]
    21652271    for i, directory in enumerate(directories_dic.keys()):
    2166         if verbose: print'Plotting in %s' %directory, new_plot_numbers
    2167 #        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
    21682274        for j, filename in enumerate(list_filenames[i]):
    21692275           
    2170 #            if verbose: print'Starting %s' %base_name+number 
    21712276            if verbose: print'Starting %s' %filename 
    21722277            directory_name = directories_dic[directory][0]
     
    21762281            #create an if about the start time and tide hieght
    21772282            #if they don't exist
    2178 #            file=directory+sep+base_name+number
    21792283            #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')
    21812285            #get data from dict in to list
    21822286            t = [float(x) for x in attribute_dic["time"]]
    21832287
    21842288            #do maths to list by changing to array
    2185             t=(array(t)+directory_start_time)/seconds_in_hour
     2289            t=(array(t)+directory_start_time)/seconds_in_minutes
    21862290
    21872291            #finds the maximum elevation, used only as a test
     
    21912295            elevation = [float(x) for x in attribute_dic["elevation"]]
    21922296           
    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           
    21962299            if min_ele != max_ele:
    21972300                print "Note! Elevation changes in %s" %dir_filename
     
    21992302            #populates the legend_list_dic with dir_name and the elevation
    22002303            if i==0:
    2201                 legend_list_dic.append({directory_name:max_ele})
     2304                legend_list_dic.append({directory_name:round(max_ele,2)})
    22022305            else:
    2203                 print j,max_ele, directory_name, legend_list_dic
    2204                 legend_list_dic[j][directory_name]=max_ele
     2306                #print j,max_ele, directory_name, legend_list_dic
     2307                legend_list_dic[j][directory_name]=round(max_ele,2)
    22052308
    22062309            # creates a list for the legend after at "legend_dic" has been fully populated
     
    22132316                    #print k,l, legend_list_dic[j]
    22142317           
    2215             print 'filename',filename, quantities
     2318            #print 'filename',filename, quantities
    22162319            #remove time so it is not plotted!
    2217 #            quantities.remove('time')
    22182320            for k, quantity in enumerate(quantities):
    2219                 if quantity != 'time':
     2321                if quantity != 'time' and quantity != 'elevation':
    22202322                    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       
    22292324                    num=int(k*100+j)
    22302325                    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])
    22312345                    pylab.plot(t, quantity_value[quantity], c = cstr[i], linewidth=1)
    22322346                    pylab.xlabel(quantities_label['time'])
    2233                     pylab.ylabel(quantities_label[quantity])
    22342347                    pylab.axis(quantities_axis[quantity])
    22352348                    pylab.legend(legend_list,loc='upper right')
     2349                    pylab.title('%s at %s gauge' %(quantity,filename[len(base_name):]))
    22362350                    if output_dir == '':
    22372351                        figname = '%s%s_%s%s.png' %(directory,
     
    22532367
    22542368
    2255 def get_min_max_values(list=None,min1=100,max1=-100):
     2369def old_get_min_max_values(list=None,min1=100000,max1=-100000):
    22562370    """ Returns the min and max of the list it was provided.
    22572371    NOTE: default min and max may need to change depeending on
     
    22592373    """
    22602374    if list == None: print 'List must be provided'
    2261 #    min = max_list = 0
    22622375    if max(list) > max1:
    22632376        max1 = max(list)
     
    22662379       
    22672380    return min1, max1
     2381
     2382def 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)
    22682389
    22692390
     
    23222443def sww2csv_gauges(sww_file,
    23232444                   gauge_file,
    2324                    quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
     2445                   quantities = ['stage','depth', 'elevation', 'xmomentum', 'ymomentum'],
    23252446                   verbose=False,
    23262447                   use_cache = True):
     
    23292450    Inputs:
    23302451       
    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
    23322457       
    23332458        points_file: Assumes that it follows this format
     
    24482573    heading = [quantity for quantity in quantities]
    24492574    heading.insert(0,'time')
     2575
    24502576#    print heading, quantities
    24512577
     
    24532579    points_writer = []
    24542580    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")))
    24562582        points_writer[i].writerow(heading)
    24572583
Note: See TracChangeset for help on using the changeset viewer.