Changeset 4983


Ignore:
Timestamp:
Jan 30, 2008, 11:36:42 AM (16 years ago)
Author:
nick
Message:

cleaned up old code

File:
1 edited

Legend:

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

    r4982 r4983  
    15271527                                 )
    15281528   
    1529 
    1530 #def OLD_csv2timeseries_graphs(directories_dic={},
    1531 #                            output_dir='',
    1532 #                            base_name=None,
    1533 #                            plot_numbers='0',
    1534 #                            quantities=['stage'],
    1535 #                            extra_plot_name='',
    1536 #                            assess_all_csv_files=True,                           
    1537 #                            create_latex=False,
    1538 #                            verbose=True):
    1539 #                               
    1540 #    """WARNING!! NO UNIT TESTS... could make some as to test filename..but have
    1541 #    spend ages on this already...
    1542 #    AND NOTE Create_latex is NOT implemented yet.
    1543 #   
    1544 #   
    1545 #    Read in csv files that have the right header information and
    1546 #    plot time series such as Stage, Speed, etc. Will also plot several
    1547 #    time series on one plot. Filenames must follow this convention,
    1548 #    <base_name><plot_number>.csv eg gauge_timeseries3.csv
    1549 #
    1550 #    Each file represents a location and within each file there are
    1551 #    time, quantity columns.
    1552 #   
    1553 #    For example:   
    1554 #    if "directories_dic" defines 4 directories and in each directories
    1555 #    there is a csv files corresponding to the right "plot_numbers",
    1556 #    this will create a plot with 4 lines one for each directory AND
    1557 #    one plot for each "quantities". 
    1558 #   
    1559 #    Inputs:
    1560 #        directories_dic: dictionary of directory with values (plot
    1561 #                         legend name for directory), (start time of
    1562 #                         the time series) and the (value to add to
    1563 #                         stage if needed). For example
    1564 #                        {dir1:['Anuga_ons',5000, 0],
    1565 #                         dir2:['b_emoth',5000,1.5],
    1566 #                         dir3:['b_ons',5000,1.5]}
    1567 #                         
    1568 #        output_dir: directory for the plot outputs
    1569 #       
    1570 #        base_name: common name to all the csv files to be read. if
    1571 #                   using plot_numbers must be the maximum common string
    1572 #                   eg. gauges0.csv, gauges1.csv and gauges2.csv
    1573 #                   base_name must be 'gauges' not 'gau'
    1574 #       
    1575 #        plot_numbers: a String list of numbers to plot. For example
    1576 #                      [0-4,10,15-17] will read and attempt to plot
    1577 #                       the follow 0,1,2,3,4,10,15,16,17
    1578 #        quantities: Currently limited to "stage", "speed", and
    1579 #                     "momentum", should be changed to incorporate
    1580 #                    any quantity read from CSV file....
    1581 #                    NOTE: ALL QUANTITY NAMES MUST BE lower case!
    1582 #                   
    1583 #        extra_plot_name: A string that is appended to the end of the
    1584 #                         output filename.
    1585 #                   
    1586 #        assess_all_csv_files: if true it will read ALL csv file with
    1587 #                             "base_name", regardless of 'plot_numbers'
    1588 #                              and determine a uniform set of axes for
    1589 #                              Stage, Speed and Momentum. IF FALSE it
    1590 #                              will only read the csv file within the
    1591 #                             'plot_numbers'
    1592 #                             
    1593 #        create_latex: NOT IMPLEMENTED YET!! sorry Jane....
    1594 #       
    1595 #        OUTPUTS: None, it saves the plots to
    1596 #              <output_dir><base_name><plot_number><extra_plot_name>.png
    1597 #
    1598 #    Usage:  csv2timeseries_graphs({'J:'+sep+'anuga_validation'+sep:['new',20,-.1],
    1599 #                                   'J:'+sep+'conical_island'+sep:['test',0,0]},
    1600 #                                   output_dir='',
    1601 #                                   plot_numbers=['1','3'],
    1602 #                                   quantities=['stage','depth','bearing'],
    1603 #                                   base_name='gauge_b',
    1604 #                                   assess_all_csv_files=True,
    1605 #                                  verbose=True)   
    1606 #            This will produce one plot for each quantity (therefore 3) in the current directory,
    1607 #            each plot will have 2 lines on them. The first plot named 'new' will have the time
    1608 #            offseted by 20secs and the stage height adjusted by -0.1m
    1609 #   
    1610 #    """
    1611 ##    import pylab
    1612 #    try:
    1613 #        import pylab
    1614 #    except ImportError:
    1615 #        msg='csv2timeseries_graphs needs pylab to be installed correctly'
    1616 #        raise msg
    1617 #            #ANUGA don't need pylab to work so the system doesn't
    1618 #            #rely on pylab being installed
    1619 #        return
    1620 #    from os import sep
    1621 #    from anuga.shallow_water.data_manager import \
    1622 #                               get_all_files_with_extension, csv2dict
    1623 #    #find all the files that meet the specs
    1624 #    #FIXME remove all references to word that such as Stage
    1625 #    #(with a Capital letter) could use the header info from
    1626 #    #the dictionary that is returned from the csv2dict this could
    1627 #    #be very good and very flexable.... but this works for now!
    1628 #
    1629 #    #FIXME MAKE NICER at the end i have started a new version...
    1630 #    # it almost completely works...
    1631 #
    1632 #    seconds_in_hour = 3600
    1633 #    time_label = 'time (hour)'
    1634 #    stage_label = 'wave height (m)'
    1635 #    speed_label = 'speed (m/s)'
    1636 #    momentum_label = 'momentum (m^2/sec)'
    1637 #    xmomentum_label = 'momentum (m^2/sec)'
    1638 #    ymomentum_label = 'momentum (m^2/sec)'
    1639 #    depth_label = 'water depth (m)'
    1640 #    bearing_label = 'degrees (o)'
    1641 #   
    1642 #    if extra_plot_name != '':
    1643 #        extra_plot_name='_'+extra_plot_name
    1644 #
    1645 #    #finds all the files that fit the specs and return a list of them
    1646 #    #so to help find a uniform max and min for the plots...
    1647 #    list_filenames=[]
    1648 #    #print'oaeuaoe',verbose
    1649 #    if verbose: print 'Determining files to access for axes ranges \n'
    1650 #    #print 'heaoeu'
    1651 #    for i,directory in enumerate(directories_dic.keys()):
    1652 #        #print 'base',basename,directory
    1653 #        list_filenames.append(get_all_files_with_extension(directory,
    1654 #                              base_name,'.csv'))
    1655 ##    print 'list_filenames',list_filenames
    1656 #
    1657 #    #use all the files to get the values for the plot axis
    1658 #    max_xmom=min_xmom=max_ymom=min_ymom=max_st=max_sp=max_mom=min_st=min_sp=min_mom=\
    1659 #    max_depth=min_depth=max_bearing=min_bearing=max_t=min_t=0.
    1660 #    max_start_time= 0.
    1661 #    min_start_time = 100000
    1662 #
    1663 #    print'hello'
    1664 #    new_plot_numbers=[]
    1665 #    #change plot_numbers to list, eg ['0-4','10']
    1666 #    #to ['0','1','2','3','4','10']
    1667 #    for i, num_string in enumerate(plot_numbers):
    1668 #        if '-' in num_string:
    1669 #            start = int(num_string[:num_string.rfind('-')])
    1670 #            end = int(num_string[num_string.rfind('-')+1:])+1
    1671 #            for x in range(start, end):
    1672 #                new_plot_numbers.append(str(x))
    1673 #        else:
    1674 #            new_plot_numbers.append(num_string)
    1675 ##    print 'new_plot_numbers',new_plot_numbers
    1676 #   
    1677 #    if verbose: print 'Determining uniform axes \n'
    1678 #    #this entire loop is to determine the min and max range for the
    1679 #    #axes of the plot
    1680 #    for i, directory in enumerate(directories_dic.keys()):
    1681 #       
    1682 #        if assess_all_csv_files==False:
    1683 #            which_csv_to_assess = new_plot_numbers
    1684 #        else:
    1685 #            which_csv_to_assess = list_filenames[i]
    1686 #
    1687 #        for j, filename in enumerate(which_csv_to_assess):
    1688 #            if assess_all_csv_files==False:
    1689 ##                dir_filename=directory+sep+base_name+filename
    1690 #                dir_filename=join(directory,base_name+filename)
    1691 #            else:
    1692 #                dir_filename=join(directory,filename)
    1693 #            print'dir_filename',dir_filename
    1694 #            attribute_dic, title_index_dic = csv2dict(dir_filename+
    1695 #                                                       '.csv')
    1696 #
    1697 #            directory_start_time = directories_dic[directory][1]
    1698 #            directory_add_tide = directories_dic[directory][2]
    1699 #
    1700 #            time = [float(x) for x in attribute_dic["time"]]
    1701 #            min_t, max_t = get_min_max_values(time,min_t,max_t)
    1702 #           
    1703 #            stage = [float(x) for x in attribute_dic["stage"]]
    1704 #            stage =array(stage)+directory_add_tide
    1705 #            min_st, max_st = get_min_max_values(stage,min_st,max_st)
    1706 #       
    1707 #            if "speed" in quantities:
    1708 #                speed = [float(x) for x in attribute_dic["speed"]]
    1709 #                min_sp, max_sp = get_min_max_values(speed,min_sp,max_sp)
    1710 #           
    1711 #            if "momentum" in quantities:
    1712 #                momentum = [float(x) for x in attribute_dic["momentum"]]
    1713 #                min_mom, max_mom = get_min_max_values(momentum,
    1714 #                                                  min_mom,
    1715 #                                                  max_mom)
    1716 #            if "xmomentum" in quantities:
    1717 #                xmomentum = [float(x) for x in attribute_dic["xmomentum"]]
    1718 #                min_xmom, max_xmom = get_min_max_values(xmomentum,
    1719 #                                                  min_xmom,
    1720 #                                                  max_xmom)
    1721 #            if "ymomentum" in quantities:
    1722 #                ymomentum = [float(x) for x in attribute_dic["ymomentum"]]
    1723 #                min_ymom, max_ymom = get_min_max_values(ymomentum,
    1724 #                                                  min_ymom,
    1725 #                                                  max_ymom)
    1726 #            if "depth" in quantities:
    1727 #                depth = [float(x) for x in attribute_dic["depth"]]
    1728 #                min_depth, max_depth = get_min_max_values(depth,
    1729 #                                                  min_depth,
    1730 #                                                  max_depth)
    1731 #            if "bearing" in quantities:
    1732 #                bearing = [float(x) for x in attribute_dic["bearing"]]
    1733 #                min_bearing, max_bearing = get_min_max_values(bearing,
    1734 #                                                  min_bearing,
    1735 #                                                  max_bearing)
    1736 #                                                                     
    1737 ##            print 'min_sp, max_sp',min_sp, max_sp,
    1738 #            print directory_start_time
    1739 #            if min_start_time > directory_start_time:
    1740 #                min_start_time = directory_start_time
    1741 #            if max_start_time < directory_start_time:
    1742 #                max_start_time = directory_start_time
    1743 ##            print 'start_time' , max_start_time, min_start_time
    1744 #   
    1745 #    stage_axis = (min_start_time/seconds_in_hour,
    1746 #                 (max_t+max_start_time)/seconds_in_hour,
    1747 #                  min_st, max_st)
    1748 #    speed_axis = (min_start_time/seconds_in_hour,
    1749 #                 (max_t+max_start_time)/seconds_in_hour,
    1750 #                 min_sp, max_sp)
    1751 #    xmomentum_axis = (min_start_time/seconds_in_hour,
    1752 #                    (max_t+max_start_time)/seconds_in_hour,
    1753 #                     min_xmom, max_xmom)
    1754 #    ymomentum_axis = (min_start_time/seconds_in_hour,
    1755 #                    (max_t+max_start_time)/seconds_in_hour,
    1756 #                     min_ymom, max_ymom)
    1757 #    momentum_axis = (min_start_time/seconds_in_hour,
    1758 #                    (max_t+max_start_time)/seconds_in_hour,
    1759 #                     min_mom, max_mom)
    1760 #    depth_axis = (min_start_time/seconds_in_hour,
    1761 #                    (max_t+max_start_time)/seconds_in_hour,
    1762 #                     min_depth, max_depth)
    1763 #    bearing_axis = (min_start_time/seconds_in_hour,
    1764 #                    (max_t+max_start_time)/seconds_in_hour,
    1765 #                     min_bearing, max_bearing)
    1766 
    1767 #    cstr = ['b', 'r', 'g', 'c', 'm', 'y', 'k']
    1768 #   
    1769 ##    if verbose: print 'Now start to plot \n'
    1770 #   
    1771 #    i_max = len(directories_dic.keys())
    1772 #    legend_list_dic =[]
    1773 #    legend_list =[]
    1774 #    for i, directory in enumerate(directories_dic.keys()):
    1775 #        if verbose: print'Plotting in %s' %(directory)
    1776 #        print new_plot_numbers,base_name
    1777 #       
    1778 #        if assess_all_csv_files==False:
    1779 #            which_csv_to_assess = new_plot_numbers
    1780 #        else:
    1781 #            which_csv_to_assess = list_filenames[i]
    1782 #
    1783 #        for j, number in enumerate(which_csv_to_assess):
    1784 #       
    1785 ##        for j, number in enumerate(new_plot_numbers):
    1786 #            print 'number',number
    1787 #            if verbose: print'Starting %s%s'%(base_name,number) 
    1788 #            directory_name = directories_dic[directory][0]
    1789 #            directory_start_time = directories_dic[directory][1]
    1790 #            directory_add_tide = directories_dic[directory][2]
    1791 #           
    1792 #            #create an if about the start time and tide hieght
    1793 #            #if they don't exist
    1794 #            file=directory+number
    1795 #            #print 'i %s,j %s, number %s, file %s' %(i,j,number,file)
    1796 #            attribute_dic, title_index_dic = csv2dict(file+'.csv')
    1797 #            #get data from dict in to list
    1798 #            t = [float(x) for x in attribute_dic["time"]]
    1799 #
    1800 #            #do maths to list by changing to array
    1801 #            t=(array(t)+directory_start_time)/seconds_in_hour
    1802 #            stage = [float(x) for x in attribute_dic["stage"]]
    1803 #            if "speed" in quantities:
    1804 #                speed = [float(x) for x in attribute_dic["speed"]]
    1805 #            if "xmomentum" in quantities:
    1806 #                xmomentum = [float(x) for x in attribute_dic["xmomentum"]]
    1807 #            if "ymomentum" in quantities:
    1808 #                ymomentum = [float(x) for x in attribute_dic["ymomentum"]]
    1809 #            if "momentum" in quantities:
    1810 #                momentum = [float(x) for x in attribute_dic["momentum"]]
    1811 #            if "depth" in quantities:
    1812 #                depth = [float(x) for x in attribute_dic["depth"]]
    1813 #            if "bearing" in quantities:
    1814 #                bearing = [float(x) for x in attribute_dic["bearing"]]
    1815 #                       
    1816 #            #Can add tide so plots are all on the same tide height
    1817 #            stage =array(stage)+directory_add_tide
    1818 #           
    1819 #            #finds the maximum elevation
    1820 #            max_ele=-100000
    1821 #            min_ele=100000
    1822 ##            legend_list=[]
    1823 #            if "elevation" in quantities:
    1824 #                elevation = [float(x) for x in attribute_dic["elevation"]]
    1825 #           
    1826 #                min_ele, max_ele = get_min_max_values(elevation,
    1827 #                                                  min_ele,
    1828 #                                                  max_ele)
    1829 #                if min_ele != max_ele:
    1830 #                    print "Note! Elevation changes in %s" %dir_filename
    1831 ##                print 'min_ele, max_ele',min_ele, max_ele
    1832 #           
    1833 #
    1834 #                #populates the legend_list_dic with dir_name and the elevation
    1835 #                if i==0:
    1836 #                    legend_list_dic.append({directory_name:max_ele})
    1837 #                else:
    1838 #                    legend_list_dic[j][directory_name]=max_ele
    1839 #           
    1840 #                # creates a list for the legend after at "legend_dic" has been fully populated
    1841 #                # only runs on the last iteration for all the gauges(csv) files
    1842 #                # empties the list before creating it
    1843 #
    1844 #            if i==i_max-1:
    1845 #                legend_list=[]
    1846 #                print 'legend',legend_list_dic, j
    1847 #                for k, l in legend_list_dic[j].iteritems():
    1848 ##                    if "elevation" in quantities:
    1849 ##                        legend_list.append('%s (elevation = %sm)'%(k,l))
    1850 ##                    else:
    1851 #                    legend_list.append('%s '%k)
    1852 #            #print k,l, legend_list_dic[j]
    1853 #         
    1854 #            if "stage" in quantities:
    1855 #                pylab.figure(100+j)
    1856 #                pylab.plot(t, stage, c = cstr[i], linewidth=1)
    1857 #                pylab.xlabel(time_label)
    1858 #                pylab.ylabel(stage_label)
    1859 #                pylab.axis(stage_axis)
    1860 #                pylab.legend(legend_list,loc='upper right')
    1861 #                if output_dir =='':
    1862 #                    figname = '%sstage_%s%s.png' %(directory+sep,
    1863 #                                               base_name+number,
    1864 #                                               extra_plot_name)
    1865 #                else:   
    1866 #                    figname = '%sstage_%s%s.png' %(output_dir+sep,
    1867 #                                               base_name+number,
    1868 #                                               extra_plot_name)
    1869 #                if verbose: print 'saving figure here %s' %figname
    1870 #                pylab.savefig(figname)
    1871 #
    1872 #            if "speed" in quantities:
    1873 #                pylab.figure(200+j)
    1874 #                pylab.plot(t, speed, c = cstr[i], linewidth=1)
    1875 #                pylab.xlabel(time_label)
    1876 #                pylab.ylabel(speed_label)
    1877 #                pylab.axis(speed_axis)
    1878 #                pylab.legend(legend_list,loc='upper right')
    1879 #                if output_dir =='':
    1880 #                    figname = '%sspeed_%s%s.png' %(directory+sep,
    1881 #                                               base_name+number,
    1882 #                                               extra_plot_name)
    1883 #                else:
    1884 #                    figname = '%sspeed_%s%s.png' %(output_dir+sep,
    1885 #                                               base_name+number,
    1886 #                                               extra_plot_name)
    1887 #                if verbose: print 'saving figure here %s' %figname
    1888 #                pylab.savefig(figname)
    1889 #            if "xmomentum" in quantities:
    1890 #                pylab.figure(300+j)
    1891 #                pylab.plot(t, xmomentum, c = cstr[i], linewidth=1)
    1892 #                pylab.xlabel(time_label)
    1893 #                pylab.ylabel(xmomentum_label)
    1894 #                pylab.axis(xmomentum_axis)
    1895 #                pylab.legend(legend_list,loc='upper right')
    1896 #                if output_dir =='':
    1897 #                    figname = '%sxmomentum_%s%s.png' %(directory+sep,
    1898 #                                                  base_name+number,
    1899 #                                                  extra_plot_name)
    1900 #                else:
    1901 #                    figname = '%sxmomentum_%s%s.png' %(output_dir+sep,
    1902 #                                                  base_name+number,
    1903 #                                                  extra_plot_name)
    1904 #                if verbose: print 'saving figure here %s' %figname
    1905 #                pylab.savefig(figname)
    1906 #               
    1907 #            if "ymomentum" in quantities:
    1908 #                pylab.figure(400+j)
    1909 #                pylab.plot(t, ymomentum, c = cstr[i], linewidth=1)
    1910 #                pylab.xlabel(time_label)
    1911 #                pylab.ylabel(ymomentum_label)
    1912 #                pylab.axis(ymomentum_axis)
    1913 #                pylab.legend(legend_list,loc='upper right')
    1914 #                if output_dir =='':
    1915 #                    figname = '%symomentum_%s%s.png' %(directory+sep,
    1916 #                                                  base_name+number,
    1917 #                                                  extra_plot_name)
    1918 #                else:
    1919 #                    figname = '%symomentum_%s%s.png' %(output_dir+sep,
    1920 #                                                  base_name+number,
    1921 #                                                  extra_plot_name)
    1922 #                if verbose: print 'saving figure here %s' %figname
    1923 #                pylab.savefig(figname)
    1924 #
    1925 #            if "momentum" in quantities:
    1926 #                pylab.figure(500+j)
    1927 #                pylab.plot(t, momentum, c = cstr[i], linewidth=1)
    1928 #                pylab.xlabel(time_label)
    1929 #                pylab.ylabel(momentum_label)
    1930 #                pylab.axis(momentum_axis)
    1931 #                pylab.legend(legend_list,loc='upper right')
    1932 #                if output_dir =='':
    1933 #                    figname = '%smomentum_%s%s.png' %(directory+sep,
    1934 #                                                  base_name+number,
    1935 #                                                  extra_plot_name)
    1936 #                else:
    1937 #                    figname = '%smomentum_%s%s.png' %(output_dir+sep,
    1938 #                                                  base_name+number,
    1939 #                                                  extra_plot_name)
    1940 #                if verbose: print 'saving figure here %s' %figname
    1941 #                pylab.savefig(figname)
    1942 #
    1943 #            if "bearing" in quantities:
    1944 #                pylab.figure(600+j)
    1945 #                pylab.plot(t, bearing, c = cstr[i], linewidth=1)
    1946 #                pylab.xlabel(time_label)
    1947 #                pylab.ylabel(bearing_label)
    1948 #                pylab.axis(bearing_axis)
    1949 #                pylab.legend(legend_list,loc='upper right')
    1950 #                if output_dir =='':
    1951 #                    figname = '%sbearing_%s%s.png' %(output_dir+sep,
    1952 #                                                  base_name+number,
    1953 #                                                  extra_plot_name)
    1954 #                else:
    1955 #                    figname = '%sbearing_%s%s.png' %(output_dir+sep,
    1956 #                                                  base_name+number,
    1957 #                                                  extra_plot_name)
    1958 #                if verbose: print 'saving figure here %s' %figname
    1959 #                pylab.savefig(figname)
    1960 #
    1961 #            if "depth" in quantities:
    1962 #                pylab.figure(700+j)
    1963 #                pylab.plot(t, depth, c = cstr[i], linewidth=1)
    1964 #                pylab.xlabel(time_label)
    1965 #                pylab.ylabel(depth_label)
    1966 #                pylab.axis(depth_axis)
    1967 #                pylab.legend(legend_list,loc='upper right')
    1968 #                if output_dir == '':
    1969 #                    figname = '%sdepth_%s%s.png' %(directory,
    1970 #                                                  base_name+number,
    1971 #                                                  extra_plot_name)
    1972 #                else:
    1973 #                    figname = '%sdepth_%s%s.png' %(output_dir+sep,
    1974 #                                                  base_name+number,
    1975 #                                                  extra_plot_name)
    1976 #                if verbose: print 'saving figure here %s' %figname
    1977 #                pylab.savefig(figname)
    1978 #               
    1979 #    if verbose: print 'Closing all plots'
    1980 #    pylab.close('all')
    1981 #    del pylab
    1982 #    if verbose: print 'Finished closing plots'
    1983    
    19841529def csv2timeseries_graphs(directories_dic={},
    19851530                            output_dir='',
     
    23811926    del pylab
    23821927    if verbose: print 'Finished closing plots'
    2383 
    2384 
    2385 #def old_get_min_max_values(list=None,min1=100000,max1=-100000):
    2386 #    """ Returns the min and max of the list it was provided.
    2387 #    NOTE: default min and max may need to change depeending on
    2388 #    your list
    2389 #    """
    2390 #    if list == None: print 'List must be provided'
    2391 #    if max(list) > max1:
    2392 #        max1 = max(list)
    2393 #    if min(list) < min1:
    2394 #        min1 = min(list)
    2395 #       
    2396 #    return min1, max1
    23971928
    23981929def get_min_max_values(list=None):
Note: See TracChangeset for help on using the changeset viewer.