Changeset 5670 for anuga_work/development/Hinwood_2008/plot.py
- Timestamp:
- Aug 20, 2008, 2:56:51 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/Hinwood_2008/plot.py
r5664 r5670 96 96 save_as_list 97 97 98 def plot(scenarios, outputdir_tag, quantity = "stage",is_interactive=False, 98 def plot_exp_sim_comparision(scenarios, outputdir_tag, 99 quantity = "stage",is_interactive=False, 99 100 y_location_tag=':0.0'): 100 101 plot_type = ".pdf" 101 102 plot_files = {} # Index scenario (T1R3) value, list of files 102 103 for run_data in scenarios: 103 104 … … 108 109 file_exp, file_sim, location_sims, location_exps, outputdir_name, \ 109 110 save_as_list = temp 111 plot_files[run_data['scenario_id']] = save_as_list 110 112 print "file_exp",file_exp 111 113 print "run_data['scenario_id']", run_data['scenario_id'] … … 146 148 if is_interactive is True: 147 149 break 150 return plot_files 151 152 153 def auto_plot_compare_csv_subfigures(scenarios, outputdir_tag, 154 to_publish_indexes, 155 quantity = "stage",is_interactive=False, 156 y_location_tag=':0.0', 157 add_run_info=False): 158 plot_type = ".pdf" 159 save_as_list = [] 160 for run_data in scenarios: 161 162 id = run_data['scenario_id'] 163 if not to_publish_indexes.has_key(id): 164 continue 165 166 outputdir_name = id + outputdir_tag 167 pro_instance = project.Project(['data','flumes','Hinwood_2008'], 168 outputdir_name=outputdir_name) 169 170 171 file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv" 172 file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \ 173 + quantity + '.csv' 174 175 if add_run_info is True: 176 plot_title = "Title will not be in final draft \n" + \ 177 id + outputdir_tag 178 else: 179 plot_title = "" 180 #save_as = pro_instance.plots_dir + sep + \ 181 # outputdir_name + "_" + quantity + "_" + plot_type 182 save_as = pro_instance.plots_dir + sep + id + quantity + \ 183 '_compare' + plot_type 184 save_as_list.append(save_as) 185 186 187 plot_compare_csv_subfigures(file_sim, 188 file_exp, 189 to_publish_indexes[id], 190 run_data, 191 plot_title=plot_title, 192 save_as=save_as, 193 y_label='Water '+ quantity +' (m)', 194 is_interactive=is_interactive, 195 y_location_tag=y_location_tag) 196 return save_as_list 197 198 def plot_compare_csv_subfigures(file_sim, 199 file_exp, 200 gauge_indexs, 201 run_data, 202 save_as=None, 203 plot_title="", 204 x_label='Time (s)', 205 y_label=None, 206 legend_sim='ANUGA simulation', 207 legend_exp='Measured flume result', 208 is_interactive=False, 209 x_axis=None, 210 y_axis=None, 211 y_location_tag=':0.0'): 212 """ 213 """ 214 from pylab import ion, plot, xlabel, ylabel, close, legend, \ 215 savefig, title, axis, setp, subplot, grid, figlegend, gca, \ 216 text 217 218 from anuga.shallow_water.data_manager import csv2dict 219 220 print "file_sim", file_sim 221 # Load in the csv files and convert info from strings to floats 222 simulation, _ = csv2dict(file_sim) 223 experiment, _ = csv2dict(file_exp) 224 time_sim = [float(x) for x in simulation['time']] 225 time_exp = [float(x) for x in experiment['Time']] 226 227 228 if is_interactive: 229 ion() 230 231 for position, i in enumerate(gauge_indexs): 232 gauge_x = run_data['gauge_x'][i] 233 grid_position = (len(gauge_indexs)+1)*100 + 10 + position +1 234 subplot(grid_position) 235 location_sim = str(gauge_x) + y_location_tag 236 location_exp = str(gauge_x) 237 238 quantity_sim = [float(x) for x in simulation[location_sim]] 239 quantity_exp = [float(x) for x in experiment[location_exp]] 240 241 242 l_sim, l_exp = plot(time_sim, quantity_sim, time_exp, quantity_exp) 243 setp(l_sim, color='r', linestyle='--') 244 setp(l_exp, color='b') 245 grid(True) 246 247 # When the shore gauges out of the are used, don't 248 # use the standard y axis scale 249 gauge_elev = run_data['gauge_bed_elevation'][i] 250 x_axis = run_data['wave_times'] 251 if gauge_x < run_data['axis_maximum_x']: 252 y_axis = [run_data['axis'][2],run_data['axis'][3]] 253 setp(gca(), yticks=[-0.04,-0.02, 0.0, 0.02, 0.04]) 254 y_text = -0.035 255 else: 256 y_axis = [run_data['axis'][2] + gauge_elev, 257 run_data['axis'][3] + gauge_elev] 258 setp(gca(), yticks=[0.02, 0.04, 0.06, 0.08, 0.1]) 259 y_text = 0.025 260 text(x_axis[0]+5,y_text, str(round(gauge_x,1)) + " m gauge") 261 if position == 0: 262 title(plot_title) 263 if position == 1: 264 ylabel(y_label) 265 #legend((legend_sim, legend_exp),'lower center') 266 if y_axis is not None: 267 axis(ymin=y_axis[0]-0.001, ymax=y_axis[1]-0.001) 268 # the fudge -0.001 is to reduce the ytick's 269 270 # need to drop the axis name being printed 271 if x_axis is not None: 272 axis(xmin=x_axis[0], xmax=x_axis[1]) 273 274 # Only do tick marks on the final graph 275 if not position == 2: 276 setp(gca(), xticklabels=[]) 277 278 # Add axis stuff and legend 279 xlabel(x_label) 280 281 #ylabel(y_label) 282 # The order defines the label 283 #legend((legend_exp, legend_sim),'upper left') 284 figlegend((l_sim, l_exp), 285 (legend_sim, legend_exp), 286 'lower center') 287 288 if is_interactive: 289 # Wait for enter pressed 290 raw_input() 291 292 if save_as is not None: 293 savefig(save_as) 294 295 #Need to close this plot 296 close() 148 297 149 298 #------------------------------------------------------------- … … 162 311 is_interactive = False 163 312 #is_interactive = True 164 plot(scenarios, outputdir_tag,is_interactive=is_interactive, 165 y_location_tag=':0.0') 166 313 plot_exp_sim_comparision(scenarios, outputdir_tag, 314 is_interactive=is_interactive, 315 y_location_tag=':0.0') 316
Note: See TracChangeset
for help on using the changeset viewer.