[7542] | 1 | """ |
---|
| 2 | Program to plot the results from the Phase 2 comparisions. |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | Creator: Jonathan Griffin |
---|
| 6 | Created: 29 September 2009 |
---|
| 7 | """ |
---|
| 8 | import os |
---|
| 9 | import sys |
---|
| 10 | from os.path import join |
---|
| 11 | import csv |
---|
| 12 | |
---|
| 13 | import matplotlib |
---|
| 14 | matplotlib.use('Agg') |
---|
| 15 | import pylab |
---|
| 16 | from pylab import * |
---|
| 17 | import numpy |
---|
| 18 | |
---|
| 19 | path = r'/nas/gemd/georisk_models/inundation/data/australia_ph2/documents/250m comparisons' |
---|
| 20 | path_list = [] |
---|
| 21 | model_list = ['BatemansBay', 'Busselton', 'Carnarvon', 'Geraldton', 'GoldCoast', 'Gosford', 'Pt_hedland'] |
---|
| 22 | |
---|
| 23 | # Choose figure name here! This controls what is plotted |
---|
| 24 | #figure_name = 'Phase2comparions_percent.png' # Plots the mean percentage difference in stage |
---|
| 25 | figure_name = 'Phase2comparions.png' # Plots the absolute difference in stage |
---|
| 26 | figure_folder = join(path, 'figures') |
---|
| 27 | figure_path = join(figure_folder, figure_name) |
---|
| 28 | |
---|
| 29 | for model in model_list: |
---|
| 30 | model_path = join(path, model, 'comparisons.csv') |
---|
| 31 | path_list.append(model_path) |
---|
| 32 | |
---|
| 33 | plot_dict = {'BatemansBay':'x', 'Busselton':'^', 'Carnarvon':'x', 'Geraldton':'h', 'GoldCoast': 'v', 'Gosford':'+', 'Pt_hedland':'+'} |
---|
| 34 | colour_dict = {'BatemansBay':'r', 'Busselton':'b', 'Carnarvon': 2.03, 'Geraldton':'b', 'GoldCoast': 'r', 'Gosford':'r', 'Pt_hedland':'b'} |
---|
| 35 | |
---|
| 36 | mean_100m_stage = {'BatemansBay': 1.10, 'Busselton': 0.98, 'Carnarvon': 2.03, 'Geraldton':0.95, |
---|
| 37 | 'GoldCoast': 2.22, 'Gosford': 1.86, 'Hobart': 2.05,'Pt_hedland': 0.77} |
---|
| 38 | event_dict = {'BatemansBay': 58284, 'Busselton': 27283, 'Carnarvon': 27283, 'Geraldton':27283, |
---|
| 39 | 'GoldCoast': 51469, 'Gosford': 51436, 'Hobart': 58260, 'Pt_hedland': 27283} |
---|
| 40 | # |
---|
| 41 | pylab.cla() |
---|
| 42 | counter = 0 |
---|
| 43 | for file_path in path_list: |
---|
| 44 | reader = csv.reader(open(file_path)) |
---|
| 45 | header = reader.next() |
---|
| 46 | depth_index = header.index('VALUE_') |
---|
| 47 | stage_diff_index = header.index('STAGE_DIFF') |
---|
| 48 | orig_stage_index = header.index('stage_high_res_model') |
---|
| 49 | print depth_index, stage_diff_index, orig_stage_index |
---|
| 50 | depth = [] |
---|
| 51 | stage_diff = [] |
---|
| 52 | orig_stage = [] |
---|
| 53 | for row in reader: |
---|
| 54 | depth.append(float(row[depth_index])) |
---|
| 55 | stage_diff.append(abs((float(row[stage_diff_index])))) |
---|
| 56 | orig_stage.append(float(row[orig_stage_index])) |
---|
| 57 | depth_dict = dict.fromkeys(depth).keys() |
---|
| 58 | |
---|
| 59 | stage_diff_dict = {} |
---|
| 60 | orig_stage_dict = {} |
---|
| 61 | percent_diff_dict = {} |
---|
| 62 | stage_diff_mean_dict = {} |
---|
| 63 | orig_stage_mean_dict = {} |
---|
| 64 | percent_diff_mean_dict = {} |
---|
| 65 | key_list = [] |
---|
| 66 | |
---|
| 67 | diff_mean_list = [] |
---|
| 68 | percent_mean_list = [] |
---|
| 69 | |
---|
| 70 | for key in depth_dict: |
---|
| 71 | |
---|
| 72 | stage_diff_list = [] |
---|
| 73 | orig_stage_list = [] |
---|
| 74 | percent_diff_list = [] |
---|
| 75 | for i in range(len(depth)): |
---|
| 76 | if depth[i] == key: |
---|
| 77 | stage_diff_list.append(stage_diff[i]) |
---|
| 78 | orig_stage_list.append(orig_stage[i]) |
---|
| 79 | percent_diff_list.append((stage_diff[i]/orig_stage[i])*100) |
---|
| 80 | stage_diff_dict[key] = stage_diff_list |
---|
| 81 | orig_stage_dict[key] = orig_stage_list |
---|
| 82 | percent_diff_dict[key] = percent_diff_list |
---|
| 83 | |
---|
| 84 | stage_diff_mean_dict[key] = numpy.mean(stage_diff_dict[key]) |
---|
| 85 | orig_stage_mean_dict[key] = numpy.mean(orig_stage_dict[key]) |
---|
| 86 | percent_diff_mean_dict[key] = numpy.mean( percent_diff_dict[key]) |
---|
| 87 | key_list.append(key) |
---|
| 88 | diff_mean_list.append(stage_diff_mean_dict[key]) |
---|
| 89 | percent_mean_list.append(percent_diff_mean_dict[key]) |
---|
| 90 | |
---|
| 91 | pylab.semilogy() |
---|
| 92 | pylab.xlabel('Depth (m)') |
---|
| 93 | |
---|
| 94 | if figure_name == 'Phase2comparions.png': |
---|
| 95 | pylab.title('Mean difference in stage height (m)') |
---|
| 96 | pylab.ylabel('Difference (m)') |
---|
| 97 | pylab.scatter(key_list,diff_mean_list, marker = plot_dict[model_list[counter]],color = colour_dict[model_list[counter]]) |
---|
| 98 | if figure_name == 'Phase2comparions_percent.png': |
---|
| 99 | pylab.title('Mean percentage difference in stage height') |
---|
| 100 | pylab.ylabel('Difference %') |
---|
| 101 | pylab.scatter(key_list,percent_mean_list, marker = plot_dict[model_list[counter]],color = colour_dict[model_list[counter]]) |
---|
| 102 | |
---|
| 103 | counter+=1 |
---|
| 104 | |
---|
| 105 | if figure_name == 'Phase2comparions.png': |
---|
| 106 | pylab.text(-58, 50, 'East Coast', color = 'r') |
---|
| 107 | pylab.text(-58, 30, 'West Coast', color = 'b') |
---|
| 108 | |
---|
| 109 | if figure_name == 'Phase2comparions_percent.png': |
---|
| 110 | pylab.text(-58, 600, 'East Coast', color = 'r') |
---|
| 111 | pylab.text(-58, 400, 'West Coast', color = 'b') |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | pylab.savefig(figure_path) |
---|
| 115 | |
---|
| 116 | |
---|