Changeset 5532
- Timestamp:
- Jul 18, 2008, 3:04:17 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/Hinwood_2008/slope.py
r5503 r5532 24 24 25 25 def load_sensors(quantity_file): 26 """ 27 Load a csv file, where the first row is the column header and 28 the first colum explains the rows. 29 """ 26 30 #slope, _ = csv2dict(file_sim) 27 31 … … 34 38 n_time = len(lines) 35 39 n_sensors = len(lines[0].split(','))-1 # -1 to remove time 36 dtimes = zeros(n_time, Float) #Time40 times = zeros(n_time, Float) #Time 37 41 depths = zeros(n_time, Float) # 38 42 sensors = zeros((n_time,n_sensors), Float) … … 45 49 fields = line.split(',') #(',') 46 50 fields = [float(j) for j in fields] 47 dtimes[i] = fields[0]51 times[i] = fields[0] 48 52 sensors[i] = fields[1:] # 1: to remove time 49 53 50 #print " dtimes",dtimes54 #print "times",times 51 55 #print "locations", locations 52 56 #print "sensors", sensors 53 return dtimes, locations, sensors57 return times, locations, sensors 54 58 55 59 def load_slopes(stage_file): … … 87 91 break_xs=None, 88 92 break_times=None): 93 """ 94 Currently used to generate stage slope contour graphs. 95 96 Has been generalised a bit. 97 """ 89 98 # Do not move these imports. Tornado doesn't have pylab 90 99 from pylab import meshgrid, cm, contourf, contour, ion, plot, xlabel, \ … … 136 145 break_xs=None, 137 146 break_times=None): 147 """ 148 Used to generate a froude Number contour graphs. 149 150 """ 138 151 # Do not move these imports. Tornado doesn't have pylab 139 152 from pylab import meshgrid, cm, contourf, contour, ion, plot, xlabel, \ … … 183 196 184 197 def auto_graph_slopes(outputdir_tag, scenarios, is_interactive=False): 198 """ 199 Used to generate all the stage slope contour graphs of a scenario list 200 """ 185 201 plot_type = ".pdf" 186 202 for run_data in scenarios: … … 214 230 215 231 def auto_graph_froudes(outputdir_tag, scenarios, is_interactive=False): 232 """ 233 Used to generate all the Froude number contour graphs of a scenario list 234 """ 216 235 217 236 plot_type = ".pdf" … … 251 270 def find_froude(times_froude, locations_froude, froudes_array, 252 271 times, locations): 272 """ 273 interpolate across location to find froude number values 274 """ 275 253 276 if len(times) == 0: 254 277 return [] … … 281 304 def auto_find_min_slopes(slope_tag, outputdir_tag, scenarios): 282 305 """ 283 306 Given stage and froude wrt time and location csv files, 307 find the waves and get the froude number and stage slope 308 at the wave face. 309 310 For each wave write a csv file giving the location, stage slope, time and 311 froude number. 284 312 """ 285 313 … … 325 353 froudes)) 326 354 355 def calc_wave_file_min_slope_max_froude(slope_tag, outputdir_tag, scenarios): 356 """ 357 Calc the min slope and max froude number in the wave files 358 Used so all graphs have the same axis. 359 """ 360 min_slope = 0 361 max_froude = 0 362 363 for run_data in scenarios: 364 for wave_file, save_as, wave_number in Get_file_name( 365 run_data, outputdir_tag, slope_tag): 366 simulation, _ = csv2dict(wave_file) 367 slope = [float(x) for x in simulation['min slope']] 368 froude = [float(x) for x in simulation['Froude']] 327 369 370 min_slope = min(min(slope), min_slope) 371 372 max_froude = max(max(froude), max_froude) 373 374 375 return min_slope, max_froude 376 377 class Get_file_name: 378 """ 379 Used to make the file names, and workout the wave number. 380 """ 381 382 def __init__(self, run_data, outputdir_tag, slope_tag): 383 384 self.plot_type = ".pdf" 385 # The scenario data 386 id = run_data['scenario_id'] 387 388 self.outputdir_name = id + outputdir_tag 389 self.pro_instance = project.Project(['data','flumes','Hinwood_2008'], 390 outputdir_name=self.outputdir_name) 391 self.wave_number = -1 392 self.max_waves = len(run_data['break_type']) 393 self.slope_tag = slope_tag 394 self.end = id + ".csv" 395 396 def next(self): 397 self.wave_number += 1 398 if self.wave_number >= self.max_waves: raise StopIteration 399 wave_tag = "wave_" + str(self.wave_number) 400 stage_file = self.pro_instance.outputdir + self.slope_tag + \ 401 "slope_stage_" + self.end 402 wave_file = stage_file[:-4] + '_'+ wave_tag + ".csv" 403 save_as = self.pro_instance.plots_dir + sep + \ 404 self.outputdir_name + "_" + wave_tag + self.plot_type 405 return wave_file, save_as, self.wave_number 406 407 def __iter__(self): 408 return self 409 410 411 412 328 413 def auto_plot_froude_slopes(slope_tag, outputdir_tag, scenarios): 329 414 """ 330 331 """ 332 333 plot_type = ".pdf" 415 Used to generate all the Froude number, stage slope, time graphs 416 of a scenario list 417 """ 418 419 slope_min, froude_max = calc_wave_file_min_slope_max_froude( 420 slope_tag, outputdir_tag, scenarios) 421 334 422 335 423 for run_data in scenarios: 336 id = run_data['scenario_id']337 outputdir_name = id + outputdir_tag338 pro_instance = project.Project(['data','flumes','Hinwood_2008'],339 outputdir_name=outputdir_name)340 341 424 assert len(run_data['break_times']) == len(run_data['break_xs']) 342 425 assert len(run_data['break_times']) == len(run_data['break_type']) 343 344 end = id + ".csv"345 426 346 427 anuga_break_times = [] … … 349 430 break_time - run_data['ANUGA_start_time']) 350 431 351 #run_data['break_type'] = (run_data['break_type'][0]) 352 for i in range(len(run_data['break_type'])): 353 354 wave_tag = "wave_" + str(i) 355 stage_file = pro_instance.outputdir + slope_tag + \ 356 "slope_stage_" + end 357 wave_file = stage_file[:-4] + '_'+ wave_tag + ".csv" 358 save_as = pro_instance.plots_dir + sep + \ 359 outputdir_name + "_" + wave_tag + plot_type 432 for wave_file, save_as, wave_number in Get_file_name( 433 run_data, outputdir_tag, slope_tag): 360 434 print "wave_file", wave_file 361 break_type = run_data['break_type'][i] 362 plot_title = id + ' Wave: ' + str(i) + \ 363 " Break Type: " + break_type + '\n' + \ 364 "File: " + wave_file[34:] # not good! 435 break_type = run_data['break_type'][wave_number] 436 plot_title = run_data['scenario_id'] + \ 437 ' Wave: ' + str(wave_number) + \ 438 ' Break Type: ' + break_type + '\n' + \ 439 'File: ' + wave_file[34:] # not good! 365 440 plot_foude_slope_stage(wave_file, 366 anuga_break_times[ i],367 run_data['break_xs'][ i],441 anuga_break_times[wave_number], 442 run_data['break_xs'][wave_number], 368 443 plot_title=plot_title, 369 444 break_type=break_type, 370 445 save_as=save_as, 371 is_interactive=False) 446 is_interactive=False, 447 froude_min=0, 448 froude_max=froude_max, 449 slope_min=slope_min, 450 slope_max=0) 372 451 373 452 … … 408 487 def find_min_slopes(times, slope_locations, slopes, 409 488 anuga_break_times, band_offset): 489 """ 490 491 """ 410 492 bands = break_times2bands(anuga_break_times, band_offset) 411 493 … … 500 582 is_interactive=False, 501 583 break_type="", 502 use_axis=None): 584 froude_min=None, 585 froude_max=None, 586 slope_min=None, 587 slope_max=None): 503 588 """ 504 589 """ … … 532 617 grid(True) 533 618 axvspan(break_x-0.001,break_x+0.001, facecolor='g') 534 axis(ymin=0, ymax=1.8) 619 if froude_min is not None and froude_max is not None: 620 axis(ymin=froude_min, ymax=froude_max) 535 621 536 622 # The slope subplot … … 546 632 grid(True) 547 633 axvspan(break_x-0.001,break_x+0.001, facecolor='g') 548 axis(ymin=-0.5, ymax=0) 634 if slope_min is not None and slope_max is not None: 635 axis(ymin=slope_min, ymax=slope_max ) 549 636 550 637 # The time, x location subplot … … 568 655 #legend((legend_exp, legend_sim),'upper left') 569 656 #legend(('Wave front'),'upper left') 570 if use_axis is not None:571 axis(use_axis)572 657 573 658 if is_interactive: … … 588 673 #scenarios = [scenarios[0]] 589 674 outputdir_tag = "_good_tri_area_0.01_limiterD" 675 outputdir_tag = "_good_tri_area_0.001_limiterD" 590 676 slope_tag = "" 591 #outputdir_tag = "_good_tri_area_0.01_limiterC"592 #slope_tag = "f"593 677 #outputdir_tag = "_test_limiterC" 594 678 #scenarios = [scenarios[0]] # !!!!!!!!!!!!!!!!!!!!!! … … 600 684 #auto_graph_froudes(outputdir_tag, scenarios) 601 685 auto_plot_froude_slopes(slope_tag, outputdir_tag, scenarios) 686 #g = Get_file_name(scenarios[0], outputdir_tag, slope_tag) 687 #for wave_file, save_as, wave_number in Get_file_name( 688 # scenarios[0], outputdir_tag, slope_tag): 689 # print "**************"
Note: See TracChangeset
for help on using the changeset viewer.