Changeset 5494
- Timestamp:
- Jul 11, 2008, 4:15:59 PM (15 years ago)
- Location:
- anuga_work/development/Hinwood_2008
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/Hinwood_2008/plot.py
r5461 r5494 19 19 """ 20 20 from pylab import ion, plot, xlabel, ylabel, close, legend, \ 21 savefig, title, axis 21 savefig, title, axis, setp 22 22 from anuga.shallow_water.data_manager import csv2dict 23 23 … … 36 36 ion() 37 37 38 plot(time_sim, quantity_sim, time_exp, quantity_exp) 38 l_sim, l_exp = plot(time_sim, quantity_sim, time_exp, quantity_exp) 39 setp(l_sim, color='r') 40 setp(l_exp, color='b') 39 41 40 42 # Add axis stuff and legend … … 70 72 outputdir_name=outputdir_name) 71 73 74 72 75 file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv" 73 76 #print "file_exp",file_exp … … 87 90 return file_exp, file_sim, location_sims, location_exps, outputdir_name, \ 88 91 save_as_list 89 def plot(scenarios, outputdir_tag, quantity = "stage" ):92 def plot(scenarios, outputdir_tag, quantity = "stage",is_interactive=False): 90 93 plot_type = ".pdf" 91 94 … … 120 123 plot_title=plot_title, 121 124 y_label='Water '+ quantity +' (m)', 122 is_interactive= False,125 is_interactive=is_interactive, 123 126 save_as=save_as, 124 127 use_axis=use_axis) 128 if is_interactive is True: 129 break 125 130 126 131 #------------------------------------------------------------- … … 129 134 """ 130 135 from scenarios import scenarios 131 outputdir_tag = "_good_tri_area_0.01_ C"132 outputdir_tag = "_test_C"136 outputdir_tag = "_good_tri_area_0.01_D" 137 #outputdir_tag = "_test_C" 133 138 #scenarios = scenarios[1:] 134 #scenarios = [scenarios[0]] 135 plot(scenarios, outputdir_tag) 139 scenarios = [scenarios[0]] 140 is_interactive = False 141 #is_interactive = True 142 plot(scenarios, outputdir_tag,is_interactive=is_interactive) 136 143 -
anuga_work/development/Hinwood_2008/run_dam.py
r5461 r5494 59 59 metadata_dic, 60 60 boundary_path=None, 61 friction=0.01 ,61 friction=0.012, # planed wood. http://www.lmnoeng.com/manningn.htm 62 62 outputdir_name=None, 63 63 run_type=0): … … 65 65 66 66 basename = 'zz_' + metadata_dic['scenario_id'] 67 end_tag = '_limiterD' 67 68 if run_type == 1: 68 outputdir_name += '_test _D'69 outputdir_name += '_test' + end_tag 69 70 yieldstep = 1.0 70 71 finaltime = 15. … … 72 73 73 74 elif run_type == 2: 74 outputdir_name += '_test_long_time' 75 outputdir_name += '_test_long_time' + end_tag 75 76 yieldstep = 0.5 76 77 finaltime = None … … 78 79 79 80 elif run_type == 3: 80 outputdir_name += '_yieldstep_0.1_tri_area_0.01 _D'81 outputdir_name += '_yieldstep_0.1_tri_area_0.01' + end_tag 81 82 yieldstep = 0.1 82 83 finaltime = None 83 84 maximum_triangle_area=0.01 84 85 elif run_type == 4: 85 outputdir_name += '_good_tri_area_0.01 _D'86 outputdir_name += '_good_tri_area_0.01' + end_tag 86 87 # this is not a test 87 88 # Output will go to a file … … 91 92 maximum_triangle_area=0.01 92 93 elif run_type == 5: 93 outputdir_name += '_good_tri_area_0.001 _D'94 outputdir_name += '_good_tri_area_0.001' + end_tag 94 95 # this is not a test 95 96 # Output will go to a file … … 117 118 #return pro_instance 118 119 if finaltime is None: 119 finaltime = boundary_final_time 120 finaltime = boundary_final_time - 0.1 # Edge boundary problems 120 121 # Boundary file manipulation 121 122 if boundary_path is None: … … 168 169 domain.set_datadir(pro_instance.outputdir) 169 170 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) 170 domain.set_minimum_storable_height(0.001) 171 #domain.set_store_vertices_uniquely(True) # for writting to sww 171 domain.set_minimum_storable_height(0.0001) 172 173 domain.set_default_order(2) # Use second order spatial scheme 174 domain.set_timestepping_method('rk2') 175 domain.use_edge_limiter = True 176 domain.tight_slope_limiters = True 177 178 domain.beta_w = 0.6 179 domain.beta_uh = 0.6 180 domain.beta_vh = 0.6 181 172 182 173 183 #------------------------------------------------------------------------- … … 206 216 207 217 # It seems that ANUGA can't handle a starttime that is >0. 208 domain.starttime = 1.0218 #domain.starttime = 1.0 #!!! what was this doing? 209 219 for t in domain.evolve(yieldstep, finaltime): 210 220 domain.write_time() … … 230 240 pro_instance.outputdir + "velocity_x_" + id, 231 241 pro_instance.outputdir + "velocity_y_" + id, 232 pro_instance.outputdir + "stage_" + id) 242 pro_instance.outputdir + "stage_" + id, 243 pro_instance.outputdir + "froude_" + id) 233 244 234 245 return pro_instance … … 259 270 run_type = run_type, 260 271 outputdir_name=run_data['scenario_id']) 261 gauges_for_slope(pro_instance.outputdir,[run_data])272 #gauges_for_slope(pro_instance.outputdir,[run_data]) -
anuga_work/development/Hinwood_2008/slope.py
r5455 r5494 5 5 from os import sep 6 6 import project 7 from copy import deepcopy 7 8 #from scipy import arange 8 9 from Numeric import arange, array, zeros, Float 9 from csv import writer 10 11 from Numeric import arange, array, zeros, Float, where, greater, less, \ 12 compress, argmin, choose 10 13 11 14 from anuga.fit_interpolate.interpolate import interpolate_sww2csv 12 15 from anuga.shallow_water.data_manager import csv2dict 13 14 def load_depths(slope_file): 16 from anuga.utilities.numerical_tools import ensure_numeric 17 18 19 SLOPE_STR = 'stage_slopes' 20 TIME_STR = 'times' 21 22 TIME_BORDER = 5 23 LOCATION_BORDER = .5 24 25 def load_sensors(quantity_file): 15 26 #slope, _ = csv2dict(file_sim) 16 27 17 28 # Read the depth file 18 dfid = open( slope_file)29 dfid = open(quantity_file) 19 30 lines = dfid.readlines() 20 31 dfid.close() … … 26 37 depths = zeros(n_time, Float) # 27 38 sensors = zeros((n_time,n_sensors), Float) 28 depth_locations = title.split(',') #(',')29 depth_locations.pop(0) # remove 'time'30 # !!!! -3 assumes a31 depths = [float(j.split(':')[0]) for j in depth_locations]39 quantity_locations = title.split(',') #(',') 40 quantity_locations.pop(0) # remove 'time' 41 42 locations = [float(j.split(':')[0]) for j in quantity_locations] 32 43 33 44 for i, line in enumerate(lines): … … 38 49 39 50 #print "dtimes",dtimes 40 #print " depths", depths51 #print "locations", locations 41 52 #print "sensors", sensors 42 return dtimes, depths, sensors53 return dtimes, locations, sensors 43 54 44 def load_slopes(slope_file): 45 times, depths, sensors = load_depths(slope_file) 46 n_slope_locations = len(depths)-1 55 def load_slopes(stage_file): 56 """ 57 Finds the slope, wrt distance of a distance, time, quantity csv file. 58 59 returns the times and slope_locations vectors and the slopes array. 60 """ 61 times, locations, sensors = load_sensors(stage_file) 62 n_slope_locations = len(locations)-1 47 63 n_time = len(times) 48 64 slope_locations = zeros(n_slope_locations, Float) # … … 50 66 51 67 # An array of the sensor spacing values 52 delta_ depths = zeros(n_slope_locations, Float)68 delta_locations = zeros(n_slope_locations, Float) 53 69 54 70 for i in arange(n_slope_locations): 55 slope_locations[i] = ( depths[i+1] + depths[i+1])/2.56 delta_ depths[i] = (depths[i+1] - depths[i])71 slope_locations[i] = (locations[i+1] + locations[i+1])/2. 72 delta_locations[i] = (locations[i+1] - locations[i]) 57 73 58 74 for j in arange(n_time): 59 75 for i in arange(n_slope_locations): 60 slopes[j,i] = (sensors[j,i+1] - sensors[j,i])/delta_ depths[i]76 slopes[j,i] = (sensors[j,i+1] - sensors[j,i])/delta_locations[i] 61 77 62 78 return times, slope_locations, slopes 63 79 64 def graph_slopes(slope_file, break_xs=None, break_times=None): 80 81 def graph_contours(times, x_data, z_data, 82 y_label='Time, seconds', 83 plot_title="slope", 84 x_label='x location, m', 85 save_as=None, 86 is_interactive=False, 87 break_xs=None, 88 break_times=None): 89 # Do not move these imports. Tornado doesn't have pylab 65 90 from pylab import meshgrid, cm, contourf, contour, ion, plot, xlabel, \ 66 91 ylabel, close, legend, savefig, title, figure ,colorbar, show , axis 92 67 93 origin = 'lower' 68 times, slope_locations, slopes = load_slopes(slope_file) 69 #print "times", times 70 #print "slope_locations", slope_locations 71 #print "slopes", slopes 72 94 95 if is_interactive: 96 ion() 97 73 98 # Can't seem to reshape this info once it is in the function 74 CS = contourf(slope_locations, times, slopes, 10, # [-1, -0.1, 0, 0.1], 75 #alpha=0.5, 99 CS = contourf(x_data, times, z_data, 10, 76 100 cmap=cm.bone, 77 101 origin=origin) 78 102 79 #CS2 = contour(slope_locations, times, slopes, CS.levels[::2], 80 # colors = 'r', 81 # origin=origin, 82 # hold='on') 83 84 title('slope') 85 xlabel('x location') 86 ylabel('Time, seconds') 87 #axis([5.0, 5.5, 30, 60]) 88 103 #CS2 = contour(x_data, times, z_data, CS.levels[::1], 104 # colors = 'r', 105 # origin=origin, 106 # hold='on') 107 108 title(plot_title) 109 xlabel(x_label) 110 ylabel(y_label) 89 111 90 112 if break_times is not None and break_xs is not None: 91 113 plot(break_xs, break_times, 'ro') 92 114 115 93 116 # Make a colorbar for the ContourSet returned by the contourf call. 94 117 cbar = colorbar(CS) 95 cbar.ax.set_ylabel('slope') 118 96 119 # Add the contour line levels to the colorbar 120 cbar.ax.set_ylabel('verbosity coefficient') 97 121 #cbar.add_lines(CS2) 98 99 figure() 100 show() 101 102 def auto_graph_slopes(): 103 from scenarios import scenarios 104 105 outputdir_tag = "_good_tri_area_0.01_A" 106 outputdir_tag = "_good_tri_area_0.01_old" 107 #outputdir_tag = "_test" 108 scenarios = [scenarios[1]] # !!!!!!!!!!!!!!!!!!!!!! 122 123 if is_interactive: 124 raw_input() # Wait for enter pressed 125 126 if save_as is not None: 127 savefig(save_as) 128 close() #Need to close this plot 129 130 def graph_froude(times, x_data, z_data, 131 y_label='Time, seconds', 132 plot_title="Froude Number", 133 x_label='x location, m', 134 save_as=None, 135 is_interactive=False, 136 break_xs=None, 137 break_times=None): 138 # Do not move these imports. Tornado doesn't have pylab 139 from pylab import meshgrid, cm, contourf, contour, ion, plot, xlabel, \ 140 ylabel, close, legend, savefig, title, figure ,colorbar, show , axis 141 142 origin = 'lower' 143 144 if is_interactive: 145 ion() 146 147 # Can't seem to reshape this info once it is in the function 148 CS = contourf(x_data, times, z_data, [-1,0.6,0.8,1,2,4], 149 colors = ('black', 'r', 'g', 'b','r'), 150 #cmap=cm.bone, 151 origin=origin) 152 153 #CS2 = contour(x_data, times, z_data, CS.levels[::1], 154 # colors = 'r', 155 # origin=origin, 156 # hold='on') 157 158 title(plot_title) 159 xlabel(x_label) 160 ylabel(y_label) 161 162 if break_times is not None and break_xs is not None: 163 plot(break_xs, break_times, 'yo') 164 165 166 # Make a colorbar for the ContourSet returned by the contourf call. 167 cbar = colorbar(CS) 168 169 # Add the contour line levels to the colorbar 170 cbar.ax.set_ylabel('verbosity coefficient') 171 #cbar.add_lines(CS2) 172 173 if is_interactive: 174 raw_input() # Wait for enter pressed 175 176 if save_as is not None: 177 savefig(save_as) 178 close() #Need to close this plot 179 180 def auto_graph_slopes(outputdir_tag, scenarios, is_interactive=False): 181 plot_type = ".pdf" 109 182 for run_data in scenarios: 110 183 id = run_data['scenario_id'] … … 113 186 outputdir_name=outputdir_name) 114 187 end = id + ".csv" 115 slope_file = pro_instance.outputdir + "bslope_stage_" + end 116 graph_slopes(slope_file, run_data['break_xs'], 117 run_data['break_times']) 188 anuga_break_times = [] 189 for break_time in run_data['break_times']: 190 anuga_break_times.append( \ 191 break_time - run_data['ANUGA_start_time']) 192 193 stage_file = pro_instance.outputdir + "fslope_stage_" + end 194 save_as = pro_instance.plots_dir + sep + \ 195 outputdir_name + "_slope_stage" + plot_type 196 times, locations, slopes = load_slopes(stage_file) 197 times, slopes = get_band(anuga_break_times[0]-TIME_BORDER, 198 100, times, slopes, 0) 199 locations, slopes = get_band( 200 run_data['break_xs'][0]- 2*LOCATION_BORDER, 201 100, locations, slopes, -1) 202 graph_contours(times, locations, slopes, 203 break_xs=run_data['break_xs'], 204 break_times=anuga_break_times, 205 save_as=save_as, 206 is_interactive=is_interactive) 207 208 def auto_graph_froudes(outputdir_tag, scenarios, is_interactive=False): 209 210 plot_type = ".pdf" 211 212 for run_data in scenarios: 213 id = run_data['scenario_id'] 214 outputdir_name = id + outputdir_tag 215 pro_instance = project.Project(['data','flumes','Hinwood_2008'], 216 outputdir_name=outputdir_name) 217 end = id + ".csv" 218 anuga_break_times = [] 219 for break_time in run_data['break_times']: 220 anuga_break_times.append( \ 221 break_time - run_data['ANUGA_start_time']) 222 223 froude_file = pro_instance.outputdir + "fslope_froude_" + end 224 save_as = pro_instance.plots_dir + sep + \ 225 outputdir_name + "_froude" + plot_type 226 dtimes, locations, sensors = load_sensors(froude_file) 227 dtimes, sensors = get_band(anuga_break_times[0]-TIME_BORDER, 228 100, dtimes, sensors, 0) 229 locations, sensors = get_band(run_data['break_xs'][0]-LOCATION_BORDER, 230 100, locations, sensors, -1) 231 #print "dtimes", dtimes 232 #print "sensors", sensors 233 #times, slope_locations, slopes = load_slopes(stage_file) 234 graph_froude(dtimes, locations, sensors, 235 break_xs=run_data['break_xs'], 236 break_times=anuga_break_times, 237 save_as=save_as, 238 is_interactive=is_interactive) 239 240 241 def auto_find_min_slopes(outputdir_tag, scenarios): 242 """ 243 244 """ 245 246 for run_data in scenarios: 247 id = run_data['scenario_id'] 248 outputdir_name = id + outputdir_tag 249 pro_instance = project.Project(['data','flumes','Hinwood_2008'], 250 outputdir_name=outputdir_name) 251 end = id + ".csv" 252 anuga_break_times = [] 253 for break_time in run_data['break_times']: 254 anuga_break_times.append( \ 255 break_time - run_data['ANUGA_start_time']) 256 257 stage_file = pro_instance.outputdir + "fslope_stage_" + end 258 259 times, slope_locations, slopes = load_slopes(stage_file) 260 waves = find_min_slopes(times, slope_locations, slopes, 261 run_data['break_times'], 262 anuga_break_times, 263 run_data['band_offset']) 264 # write the wave info here 265 # return the keys actually. 266 for wave_key in waves.iterkeys(): 267 wave_file = stage_file[:-3] + '_'+ wave_key + ".csv" 268 print "wave_file", wave_file 269 wave_writer = writer(file(wave_file, "wb")) 270 wave_writer.writerow(["x location", "min slope", "Time"]) 271 wave_writer.writerows(map(None, 272 slope_locations, 273 waves[wave_key][SLOPE_STR], 274 waves[wave_key][TIME_STR])) 275 276 #wave_writer.close() 277 278 279 118 280 119 281 def gauges_for_slope(outputdir_tag, scenarios): 120 121 outputdir_tag = "_good_tri_area_0.01_A"122 #outputdir_tag = "_test"123 #scenarios = [scenarios[0]] # !!!!!!!!!!!!!!!!!!!!!!282 """ 283 This is used to create a stage file, using gauges relivent to 284 finding a slope. 285 """ 124 286 dx = 0.05 125 287 for run_data in scenarios: … … 138 300 outputdir_name=outputdir_name) 139 301 end = id + ".csv" 140 interpolate_sww2csv(pro_instance.outputdir + basename +".sww", 141 points, 142 pro_instance.outputdir + "fslope_depth_" + end, 143 pro_instance.outputdir + "fslope_velocity_x_" + end, 144 pro_instance.outputdir + "fslope_velocity_y_" + end, 145 pro_instance.outputdir + "fslope_stage_" + end, 146 time_thinning=1) 147 302 interpolate_sww2csv( \ 303 pro_instance.outputdir + basename +".sww", 304 points, 305 pro_instance.outputdir + "fslope_depth_" + end, 306 pro_instance.outputdir + "fslope_velocity_x_" + end, 307 pro_instance.outputdir + "fslope_velocity_y_" + end, 308 pro_instance.outputdir + "fslope_stage_" + end, 309 pro_instance.outputdir + "fslope_froude_" + end, 310 time_thinning=1) 311 312 def find_min_slopes(times, slope_locations, slopes, 313 break_times, anuga_break_times, band_offset): 314 bands = break_times2bands(break_times, band_offset) 315 316 waves = {} 317 for i,_ in enumerate(bands[0:-1]): 318 id = "wave " + str(i) 319 max_q, max_q_times = get_min_in_band(bands[i], bands[i+1], 320 times, slopes) 321 waves[id] = {SLOPE_STR:max_q, 322 TIME_STR:max_q_times} 323 return waves 324 325 326 def get_band(min, max, vector, quantity_array, axis): 327 """ 328 Return a band of vector and quantity, within (not including) the 329 min, max. 330 331 For a time band, set the axis to 0. 332 For a location band, set the axis to -1. 333 334 """ 335 336 SMALL_MIN = -1e10 # Not that small, but small enough 337 vector = ensure_numeric(vector) 338 quantity_array = ensure_numeric(quantity_array) 339 340 assert min > SMALL_MIN 341 no_maxs = where(less(vector,max), vector, SMALL_MIN) 342 #print "no_maxs", no_maxs 343 band_condition = greater(no_maxs, min) 344 band_vector = compress(band_condition, vector, axis=axis) 345 #print "band_time", band_time 346 #print "quantity_array", quantity_array.shape 347 band_quantity = compress(band_condition, quantity_array, axis=axis) 348 return band_vector, band_quantity 349 350 def get_min_in_band(min_time, max_time, time_vector, quantity_array): 351 """ 352 given a quantity array, with the 2nd axis being 353 time, represented by the time_vector, find the minimum within 354 the time band. 355 356 Assumes times are positive 357 """ 358 359 time_vector = ensure_numeric(time_vector) 360 quantity_array = ensure_numeric(quantity_array) 361 362 band_time, band_quantity = get_band(min_time, max_time, 363 time_vector, quantity_array, 0) 364 #print "band_quantity",band_quantity 365 max_quantity_indices = argmin(band_quantity, axis=0) 366 #print "max_quantity_indices", max_quantity_indices 367 max_quantity_times = choose(max_quantity_indices, band_time) 368 #print "max_quantity_times", max_quantity_times 369 max_quantities = choose(max_quantity_indices, band_quantity) 370 #print "max_quantities", max_quantities 371 372 return max_quantities, max_quantity_times 373 374 def break_times2bands(break_times, band_offset): 375 """ 376 Break_times is a list of times, ascending. 377 bands is a list of times, being the midpoints of break_times, with a min 378 and max band added. 379 """ 380 assert len(break_times)>2 381 382 bands = [] #deepcopy(break_times) 383 bands.append(break_times[0]-0.5*(break_times[1]-break_times[0])) 384 385 for i,break_x in enumerate(break_times[0:-1]): 386 bands.append(break_times[i]+0.5*(break_times[i+1]-break_times[i])) 387 388 bands.append(break_times[-1]+0.5*(break_times[-1]-break_times[-2])) 389 bands = ensure_numeric(bands) 390 bands += band_offset 391 return bands 392 148 393 149 394 … … 154 399 """ 155 400 from scenarios import scenarios 156 scenarios = [scenarios[0]] 157 #gauges_for_slope("_good_tri_area_0.01_A", scenarios) 158 #auto_graph_slopes() 159 401 #scenarios = [scenarios[0]] 402 outputdir_tag = "_good_tri_area_0.01_limiterC" 403 #outputdir_tag = "_test_limiterC" 404 #scenarios = [scenarios[0]] # !!!!!!!!!!!!!!!!!!!!!! 405 #gauges_for_slope(outputdir_tag, scenarios) 406 auto_graph_slopes(outputdir_tag, scenarios) #, is_interactive=True) 407 #auto_find_min_slopes(outputdir_tag, scenarios) 408 auto_graph_froudes(outputdir_tag, scenarios) -
anuga_work/development/Hinwood_2008/test_slope.py
r5447 r5494 10 10 import tempfile 11 11 12 from scipy import array, allclose 12 from Numeric import array, allclose 13 from anuga.utilities.numerical_tools import ensure_numeric 14 13 15 14 16 from slope import * … … 33 35 handle.write(sample) 34 36 handle.close() 35 dtimes, depths, sensors = load_ depths(file_name)37 dtimes, depths, sensors = load_sensors(file_name) 36 38 actual = array([0,0.01,0.02,0.03]) 37 39 self.assert_ (allclose(dtimes, actual, 0.001)) … … 73 75 handle.write(sample) 74 76 handle.close() 75 graph_slopes(file_name)76 77 78 # since it currently graphs 79 #graph_slopes(file_name) 77 80 78 81 os.remove(file_name) 79 82 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 80 161 if __name__ == "__main__": 81 162 82 163 suite = unittest.makeSuite(slopeTestCase,'test') 164 suite = unittest.makeSuite(slopeTestCase,'test_get_band') 165 83 166 runner = unittest.TextTestRunner() #verbosity=2) 84 167 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.