Index: anuga_work/development/Hinwood_2008/slope.py
===================================================================
--- anuga_work/development/Hinwood_2008/slope.py	(revision 5503)
+++ anuga_work/development/Hinwood_2008/slope.py	(revision 5532)
@@ -24,4 +24,8 @@
 
 def load_sensors(quantity_file):
+    """
+    Load a csv file, where the first row is the column header and
+    the first colum explains the rows.
+    """
     #slope, _ = csv2dict(file_sim)
     
@@ -34,5 +38,5 @@
     n_time = len(lines)
     n_sensors = len(lines[0].split(','))-1  # -1 to remove time
-    dtimes = zeros(n_time, Float)  #Time
+    times = zeros(n_time, Float)  #Time
     depths = zeros(n_time, Float)  #
     sensors = zeros((n_time,n_sensors), Float)
@@ -45,11 +49,11 @@
         fields = line.split(',') #(',')
         fields = [float(j) for j in fields]
-        dtimes[i] = fields[0]
+        times[i] = fields[0]
         sensors[i] = fields[1:] # 1: to remove time
 
-    #print "dtimes",dtimes
+    #print "times",times
     #print "locations", locations
     #print "sensors", sensors
-    return dtimes, locations, sensors
+    return times, locations, sensors
    
 def load_slopes(stage_file):
@@ -87,4 +91,9 @@
                  break_xs=None,
                  break_times=None):
+    """
+    Currently used to generate stage slope contour graphs.
+
+    Has been generalised a bit.
+    """
     # Do not move these imports.  Tornado doesn't have pylab
     from pylab import meshgrid, cm, contourf, contour, ion, plot, xlabel, \
@@ -136,4 +145,8 @@
                  break_xs=None,
                  break_times=None):
+    """
+    Used to generate a froude Number contour graphs.
+
+    """
     # Do not move these imports.  Tornado doesn't have pylab
     from pylab import meshgrid, cm, contourf, contour, ion, plot, xlabel, \
@@ -183,4 +196,7 @@
     
 def auto_graph_slopes(outputdir_tag, scenarios, is_interactive=False):
+    """
+    Used to generate all the stage slope contour graphs of a scenario list
+    """
     plot_type = ".pdf"
     for run_data in scenarios:
@@ -214,4 +230,7 @@
 
 def auto_graph_froudes(outputdir_tag, scenarios, is_interactive=False):
+    """
+    Used to generate all the Froude number contour graphs of a scenario list
+    """
     
     plot_type = ".pdf"
@@ -251,4 +270,8 @@
 def find_froude(times_froude, locations_froude, froudes_array,
                 times, locations):
+    """
+    interpolate across location to find froude number values
+    """
+    
     if len(times) == 0:
         return []
@@ -281,5 +304,10 @@
 def auto_find_min_slopes(slope_tag, outputdir_tag, scenarios):
     """
-    
+    Given stage and froude wrt time and location csv files,
+    find the waves and get the froude number and stage slope
+    at the wave face.
+
+    For each wave write a csv file giving the location, stage slope, time and
+    froude number.
     """
     
@@ -325,22 +353,75 @@
                                       froudes))
 
+def calc_wave_file_min_slope_max_froude(slope_tag, outputdir_tag, scenarios):
+    """
+    Calc the min slope and max froude number in the wave files
+    Used so all graphs have the same axis.
+    """
+    min_slope = 0
+    max_froude = 0
+    
+    for run_data in scenarios:
+        for wave_file, save_as, wave_number in Get_file_name(
+        run_data, outputdir_tag, slope_tag):
+            simulation, _ = csv2dict(wave_file)
+            slope = [float(x) for x in simulation['min slope']]
+            froude = [float(x) for x in simulation['Froude']]
             
+            min_slope = min(min(slope), min_slope)
+            
+            max_froude = max(max(froude), max_froude)
+           
+    
+    return min_slope, max_froude
+
+class Get_file_name:
+    """
+    Used to make the file names, and workout the wave number.
+    """
+    
+    def __init__(self, run_data, outputdir_tag, slope_tag):
+        
+        self.plot_type = ".pdf"
+        # The scenario data
+        id = run_data['scenario_id']
+        
+        self.outputdir_name = id + outputdir_tag
+        self.pro_instance = project.Project(['data','flumes','Hinwood_2008'],
+                                            outputdir_name=self.outputdir_name)
+        self.wave_number = -1
+        self.max_waves = len(run_data['break_type'])
+        self.slope_tag = slope_tag
+        self.end = id + ".csv"
+
+    def next(self):
+        self.wave_number += 1
+        if self.wave_number >= self.max_waves: raise StopIteration
+        wave_tag = "wave_" + str(self.wave_number)
+        stage_file = self.pro_instance.outputdir + self.slope_tag + \
+                     "slope_stage_" + self.end
+        wave_file = stage_file[:-4] + '_'+ wave_tag + ".csv"
+        save_as = self.pro_instance.plots_dir + sep + \
+                  self.outputdir_name + "_" + wave_tag + self.plot_type
+        return wave_file, save_as, self.wave_number
+
+    def __iter__(self):
+        return self
+        
+
+
+
 def auto_plot_froude_slopes(slope_tag, outputdir_tag, scenarios):
     """
-    
-    """
-    
-    plot_type = ".pdf"
+    Used to generate all the Froude number, stage slope, time graphs
+    of a scenario list
+    """
+
+    slope_min, froude_max = calc_wave_file_min_slope_max_froude(
+        slope_tag, outputdir_tag, scenarios)
+    
     
     for run_data in scenarios:
-        id = run_data['scenario_id']
-        outputdir_name = id + outputdir_tag
-        pro_instance = project.Project(['data','flumes','Hinwood_2008'],
-                                       outputdir_name=outputdir_name)
-
         assert len(run_data['break_times']) == len(run_data['break_xs'])
         assert len(run_data['break_times']) == len(run_data['break_type'])
-        
-        end = id + ".csv"
         
         anuga_break_times = []
@@ -349,25 +430,23 @@
                 break_time -  run_data['ANUGA_start_time'])
             
-        #run_data['break_type'] = (run_data['break_type'][0])
-        for i in range(len(run_data['break_type'])):
-            
-            wave_tag = "wave_" + str(i)
-            stage_file = pro_instance.outputdir + slope_tag + \
-                         "slope_stage_" + end
-            wave_file = stage_file[:-4] + '_'+ wave_tag + ".csv"
-            save_as = pro_instance.plots_dir + sep + \
-                            outputdir_name + "_" + wave_tag + plot_type
+        for wave_file, save_as, wave_number in Get_file_name(
+        run_data, outputdir_tag, slope_tag):
             print "wave_file", wave_file
-            break_type = run_data['break_type'][i]
-            plot_title = id  + ' Wave: ' + str(i) + \
-                        " Break Type: " + break_type + '\n' + \
-                        "File: " + wave_file[34:] # not good!
+            break_type = run_data['break_type'][wave_number]
+            plot_title = run_data['scenario_id'] + \
+                         ' Wave: ' + str(wave_number) + \
+                         ' Break Type: ' + break_type + '\n' + \
+                         'File: ' + wave_file[34:] # not good!
             plot_foude_slope_stage(wave_file,
-                                   anuga_break_times[i],
-                                   run_data['break_xs'][i],
+                                   anuga_break_times[wave_number],
+                                   run_data['break_xs'][wave_number],
                                    plot_title=plot_title,
                                    break_type=break_type,
                                    save_as=save_as,
-                                   is_interactive=False)
+                                   is_interactive=False,
+                                   froude_min=0,
+                                   froude_max=froude_max,
+                                   slope_min=slope_min,
+                                   slope_max=0)
         
         
@@ -408,4 +487,7 @@
 def find_min_slopes(times, slope_locations, slopes,
                     anuga_break_times, band_offset):
+    """
+    
+    """
     bands = break_times2bands(anuga_break_times, band_offset)
 
@@ -500,5 +582,8 @@
                            is_interactive=False,
                            break_type="",
-                           use_axis=None):
+                           froude_min=None,
+                           froude_max=None,
+                           slope_min=None,
+                           slope_max=None):
     """ 
     """
@@ -532,5 +617,6 @@
     grid(True)
     axvspan(break_x-0.001,break_x+0.001, facecolor='g')
-    axis(ymin=0, ymax=1.8)
+    if froude_min is not None and froude_max is not None:
+        axis(ymin=froude_min, ymax=froude_max)
     
     # The slope subplot
@@ -546,5 +632,6 @@
     grid(True)
     axvspan(break_x-0.001,break_x+0.001, facecolor='g')
-    axis(ymin=-0.5, ymax=0)
+    if slope_min is not None and slope_max is not None:
+        axis(ymin=slope_min, ymax=slope_max )
 
     # The time, x location subplot
@@ -568,6 +655,4 @@
     #legend((legend_exp, legend_sim),'upper left')
     #legend(('Wave front'),'upper left')
-    if use_axis is not None:
-        axis(use_axis)
     
     if is_interactive:
@@ -588,7 +673,6 @@
     #scenarios = [scenarios[0]]
     outputdir_tag = "_good_tri_area_0.01_limiterD"
+    outputdir_tag = "_good_tri_area_0.001_limiterD"
     slope_tag = ""
-    #outputdir_tag = "_good_tri_area_0.01_limiterC"
-    #slope_tag = "f"
     #outputdir_tag = "_test_limiterC"
     #scenarios = [scenarios[0]] # !!!!!!!!!!!!!!!!!!!!!!
@@ -600,2 +684,6 @@
     #auto_graph_froudes(outputdir_tag, scenarios) 
     auto_plot_froude_slopes(slope_tag, outputdir_tag, scenarios)
+    #g = Get_file_name(scenarios[0], outputdir_tag, slope_tag)
+    #for wave_file, save_as, wave_number in Get_file_name(
+     #   scenarios[0], outputdir_tag, slope_tag):
+      #  print "**************"
