""" Script for calculating maximum inundation at building locations Inputs: swwfile - name of sww file - assume that all conserved quantities have been stored buildings_filename - name of file containing building data, sourced from NBED Output: - building_filename (.csv) augmented to include maximum depth, momentum and velocity and stored in same location as swwfile Name = augmented_buildings.csv """ from os import sep from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage from os.path import join from setup_model import project import csv directory = project.output_folder + sep time_dir1 = '20090324_134328_run_final_0.6_27255_Bt_kvanputt' time_dir2 = '20090324_140747_run_final_0.6_68693_Bt_kvanputt' time_dir3 = '20090327_152717_run_final_0.6_27283_Bt_kvanputt' time_dir4 = '20090327_160646_run_final_0_27255_Bt_kvanputt' time_dir5 = '20090327_161520_run_final_0_68693_Bt_kvanputt' time_dir6 = '20090330_120458_run_final_0_27283_Bt_kvanputt' time_dirs = [time_dir6] #, time_dir3, time_dir4, time_dir5, time_dir6] buildings = project.building_exposure for time_dir in time_dirs: time_dir_name = time_dir[-20:][:-12] print time_dir_name building_marker = '_m_'+ time_dir_name basename = join(directory, time_dir, project.scenario_name) #basename for the sww files inundation_damage(basename, buildings, building_marker) #add_depth_and_momentum2csv(name, buildings, building_marker) building_marker_dir_name = join(project.gauges_folder, project.building_exposure_filename[:-4]) + building_marker + '.csv' out_file = basename + '_res.csv' print 'out file %s' %out_file print 'building_marker_dir_name %s' %building_marker_dir_name csv_fd = open(building_marker_dir_name, 'r') output_file = open(out_file, 'w') reader = csv.reader(csv_fd) writer = csv.writer(output_file, lineterminator='\n') for record in reader: newline = record[-8:] newline.insert(0,record[0]) newline.insert(1,record[1]) newline.insert(2,record[2]) writer.writerow(newline) print 'output file printed to: %s' %out_file csv_fd.close() output_file.close()