def inundation_damage(sww_base_name, exposure_files_in, exposure_file_out_marker=None, ground_floor_height=0.3, overwrite=False, verbose=True, use_cache = True): """ This is the main function for calculating tsunami damage due to inundation. It gets the location of structures from the exposure file and gets the inundation of these structures from the sww file. It then calculates the damage loss. Note, structures outside of the sww file get the minimum inundation (-ground_floor_height). These calculations are done over all the sww files with the sww_base_name in the specified directory. exposure_files_in - a file or a list of files to input from exposure_file_out_marker - this string will be added to the input file name to get the output file name """ if isinstance(exposure_files_in, basestring): exposure_files_in = [exposure_files_in] for exposure_file_in in exposure_files_in: csv = Exposure(exposure_file_in, title_check_list=[SHORE_DIST_LABEL,WALL_TYPE_LABEL, STR_VALUE_LABEL,CONT_VALUE_LABEL]) geospatial = csv.get_location() geospatial = ensure_absolute(geospatial) max_depths, max_momentums = calc_max_depth_and_momentum(sww_base_name, geospatial, ground_floor_height=ground_floor_height, verbose=verbose, use_cache=use_cache) edm = EventDamageModel(max_depths, csv.get_column(SHORE_DIST_LABEL), csv.get_column(WALL_TYPE_LABEL), csv.get_column(STR_VALUE_LABEL), csv.get_column(CONT_VALUE_LABEL) ) results_dic = edm.calc_damage_and_costs(verbose_csv=True, verbose=verbose) for title, value in results_dic.iteritems(): csv.set_column(title, value, overwrite=overwrite) # Save info back to csv file if exposure_file_out_marker == None: exposure_file_out = exposure_file_in else: # split off extension, in such a way to deal with more than one '.' in the name of file split_name = exposure_file_in.split('.') exposure_file_out = '.'.join(split_name[:-1]) + exposure_file_out_marker + \ '.' + split_name[-1] csv.save(exposure_file_out) if verbose: log.critical('Augmented building file written to %s' % exposure_file_out)
def add_depth_and_momentum2csv(sww_base_name, exposure_file_in, exposure_file_out=None, overwrite=False, verbose=True, use_cache=True): """ Calculate the maximum depth and momemtum in an sww file, for locations specified in an csv exposure file. These calculations are done over all the sww files with the sww_base_name in the specified directory. """ csv = Exposure(exposure_file_in) geospatial = csv.get_location() max_depths, max_momentums = calc_max_depth_and_momentum( sww_base_name, geospatial, verbose=verbose, use_cache=use_cache) csv.set_column("MAX INUNDATION DEPTH (m)", max_depths, overwrite=overwrite) csv.set_column("MOMENTUM (m^2/s) ", max_momentums, overwrite=overwrite) csv.save(exposure_file_out)
def add_depth_and_momentum2csv(sww_base_name, exposure_file_in, exposure_file_out=None, overwrite=False, verbose=True, use_cache = True): """ Calculate the maximum depth and momemtum in an sww file, for locations specified in an csv exposure file. These calculations are done over all the sww files with the sww_base_name in the specified directory. """ csv = Exposure(exposure_file_in) geospatial = csv.get_location() max_depths, max_momentums = calc_max_depth_and_momentum(sww_base_name, geospatial, verbose=verbose, use_cache=use_cache) csv.set_column("MAX INUNDATION DEPTH (m)",max_depths, overwrite=overwrite) csv.set_column("MOMENTUM (m^2/s) ",max_momentums, overwrite=overwrite) csv.save(exposure_file_out)
def inundation_damage(sww_base_name, exposure_files_in, exposure_file_out_marker=None, ground_floor_height=0.3, overwrite=False, verbose=True, use_cache=True): """ This is the main function for calculating tsunami damage due to inundation. It gets the location of structures from the exposure file and gets the inundation of these structures from the sww file. It then calculates the damage loss. Note, structures outside of the sww file get the minimum inundation (-ground_floor_height). These calculations are done over all the sww files with the sww_base_name in the specified directory. exposure_files_in - a file or a list of files to input from exposure_file_out_marker - this string will be added to the input file name to get the output file name """ if isinstance(exposure_files_in, basestring): exposure_files_in = [exposure_files_in] for exposure_file_in in exposure_files_in: csv = Exposure(exposure_file_in, title_check_list=[ SHORE_DIST_LABEL, WALL_TYPE_LABEL, STR_VALUE_LABEL, CONT_VALUE_LABEL ]) geospatial = csv.get_location() geospatial = ensure_absolute(geospatial) max_depths, max_momentums = calc_max_depth_and_momentum( sww_base_name, geospatial, ground_floor_height=ground_floor_height, verbose=verbose, use_cache=use_cache) edm = EventDamageModel(max_depths, csv.get_column(SHORE_DIST_LABEL), csv.get_column(WALL_TYPE_LABEL), csv.get_column(STR_VALUE_LABEL), csv.get_column(CONT_VALUE_LABEL)) results_dic = edm.calc_damage_and_costs(verbose_csv=True, verbose=verbose) for title, value in results_dic.iteritems(): csv.set_column(title, value, overwrite=overwrite) # Save info back to csv file if exposure_file_out_marker is None: exposure_file_out = exposure_file_in else: # split off extension, in such a way to deal with more than one '.' in the name of file split_name = exposure_file_in.split('.') exposure_file_out = '.'.join(split_name[:-1]) + exposure_file_out_marker + \ '.' + split_name[-1] csv.save(exposure_file_out) if verbose: log.critical('Augmented building file written to %s' % exposure_file_out)