Ignore:
Timestamp:
Jul 11, 2008, 4:15:59 PM (15 years ago)
Author:
duncan
Message:

Current Hinwood scenario - added plotting of froude number

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/Hinwood_2008/test_slope.py

    r5447 r5494  
    1010import tempfile
    1111
    12 from scipy import array, allclose
     12from Numeric import array, allclose
     13from anuga.utilities.numerical_tools import ensure_numeric
     14
    1315
    1416from slope import *
     
    3335        handle.write(sample)
    3436        handle.close()
    35         dtimes, depths, sensors = load_depths(file_name)
     37        dtimes, depths, sensors = load_sensors(file_name)
    3638        actual = array([0,0.01,0.02,0.03])
    3739        self.assert_ (allclose(dtimes, actual, 0.001))
     
    7375        handle.write(sample)
    7476        handle.close()
    75         graph_slopes(file_name)
    7677
     78        # since it currently graphs
     79        #graph_slopes(file_name)
    7780       
    7881        os.remove(file_name)
    7982             
     83    def test_get_min_in_band(self):
     84        time = array([0,1,2,3,4,5])
     85        slopes = array([[10,12],
     86                        [9,10],
     87                        [8,9],
     88                        [9,7],
     89                        [10,6],
     90                        [7,2]])
     91
     92        max_q, max_q_times = get_min_in_band(0,5,time,slopes)
     93        actual = array([8,6])
     94        self.assert_ (allclose(max_q, actual, 0.001))
     95        actual = array([2,4])
     96        self.assert_ (allclose(max_q_times, actual, 0.001))
     97
     98       
     99        max_q, max_q_times = get_min_in_band(1,4,time,slopes)
     100        actual = array([8,7])
     101        self.assert_ (allclose(max_q, actual, 0.001))
     102        actual = array([2,3])
     103        self.assert_ (allclose(max_q_times, actual, 0.001))
     104       
     105    def test_break_times2bands(self):
     106        break_times = [1,3,4,8]
     107        band_offset = 0.0
     108        bands  = break_times2bands(break_times, band_offset)
     109        #print "bands", bands
     110        actual = array([0,2,3.5,6,10 ])
     111        self.assert_ (allclose(ensure_numeric(bands), actual, 0.001))
     112       
     113    def test_get_time_band(self):
     114        time = array([0,1,2,3,4,5])
     115        slopes = array([[10,12],
     116                        [9,10],
     117                        [8,9],
     118                        [9,7],
     119                        [10,6],
     120                        [7,2]])
     121
     122        band_time, band_quantity = get_time_band(0,5,time,slopes)
     123        actual = array([1,2,3,4])
     124        self.assert_ (allclose(band_time, actual, 0.001))
     125        actual = array([[9,10],
     126                        [8,9],
     127                        [9,7],
     128                        [10,6]])
     129        self.assert_ (allclose(band_quantity, actual, 0.001))
     130
     131   
     132    def test_get_band(self):
     133        time = array([0,1,2,3,4,5])
     134        slopes = array([[10,12],
     135                        [9,10],
     136                        [8,9],
     137                        [9,7],
     138                        [10,6],
     139                        [7,2]])
     140
     141        band_time, band_quantity = get_band(0,5,time,slopes,0)
     142        actual = array([1,2,3,4])
     143        self.assert_ (allclose(band_time, actual, 0.001))
     144        actual = array([[9,10],
     145                        [8,9],
     146                        [9,7],
     147                        [10,6]])
     148        self.assert_ (allclose(band_quantity, actual, 0.001))
     149       
     150        location = array([0,1,2,3,4,5])
     151        slopes = array([[0,1,2,3,4,5],
     152                        [0,10,20,30,40,50]])
     153
     154        band_time, band_quantity = get_band(0,5,location,slopes,-1)
     155        actual = array([1,2,3,4])
     156        self.assert_ (allclose(band_time, actual, 0.001))
     157        actual = array([[1,2,3,4],
     158                        [10,20,30,40]])
     159        self.assert_ (allclose(band_quantity, actual, 0.001))     
     160       
    80161if __name__ == "__main__":
    81162
    82163    suite = unittest.makeSuite(slopeTestCase,'test')
     164    suite = unittest.makeSuite(slopeTestCase,'test_get_band')
     165
    83166    runner = unittest.TextTestRunner()  #verbosity=2)
    84167    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.