Commit cefece17 authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

Update Fragility_to_Dictionary.py

parent 4491d9aa
import csv
# INPUTS:
# gmDict: Dictionary with keys as gm-type and
# values as the relative column number
# taxonomyConversionCsv : A file with first column
# as taxonomies and the second column as the name of
# relative fragility function(type : _csv.reader matrix)
# fragilities_path: Path to the folder of fragility functions
# OUTPUT:
# This Function returns a dictionary with
# taxonomies as keys and their relative
# fragility names, the ground-motion-type based
# on which the fragility function is defind;
# and the specific gm-type column-number in
# the ground-motion-field file.
def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir):
"""
Creates an extended map of taxonomies to fragility function.
The input map 'taxonomyToFragilitySource' contains the mapping for each taxonomy to a fragility
function file from which the ground-motion type is read to be written to the extended map
'taxonomyToFragilityMap'.
Input:
gmDict: dictionary (key: ground-motion type; value: column number in the ground-motion field file)
taxonomyToFragilitySource: taxonomy to fragility-function file map, following the format:
[taxonomy_string, fragility-function_filename, 'weight'], [...]
Example file extract:
['CR/LDUAL+CDM/HBET:6-/11.0', 'CR_LDUAL-DUM_H6', '1']
['CR/LDUAL+CDM/HBET:6-/5.0', 'CR_LDUAL-DUL_H6', '1']
['CR/LDUAL+CDM/HBET:6-/SOS/11.0', 'CR_LDUAL-DUL_H6', '1']
...
fragilityFileDir: directory of fragility-function files
Output:
Dictionary containing the taxonomy to fragility function map considering the ground-motion types.
It follows the format:
{taxonomy_string: [fragility-function_filename, column of ground-motion_type in ground-motion_field file]}
Example extract:
{'CR/LDUAL+CDM/HBET:6-/11.0': ['CR_LDUAL-DUM_H6', 4],
'CR/LDUAL+CDM/HBET:6-/5.0': ['CR_LDUAL-DUL_H6', 'SA(0.6)', 4],
'CR/LDUAL+CDM/HBET:6-/SOS/11.0': ['CR_LDUAL-DUL_H6', 'SA(0.6)', 4], ... }
"""
taxonomyToFragilityMap = {}
for mappingItem in taxonomyToFragilitySource:
fragilityFunction = list(csv.reader(open(fragilities_path + "/" + mappingItem[1] + ".csv")))
if mappingItem[0] in taxonomyToFragilityMap:
# implement your duplicate row handling here
pass
taxonomyToFragilityMap[mappingItem[0]] = [mappingItem[1], gmDict[fragilityFunction[0][0]]]
return(taxonomyToFragilityMap)
# Prepare return variable
taxonomyToFragilityMap = {}
# Loop through the taxonomy-to-fragility-function map
for mappingItem in taxonomyToFragilitySource:
# Open the fragility-function file corresponding to the taxonomy in 'mappingitem[1]'
fragilityFunction = list(csv.reader(open(fragilities_path + "/" + mappingItem[1] + ".csv")))
# Check if already one fragility function for a given GM type has been selected
if mappingItem[0] in taxonomyToFragilityMap:
# Ignore the additional fragility function to keep everything unambiguous
pass
# Create the entry in the extended map with adding the type of ground motion 'fragilityFunction[0][0]'
taxonomyToFragilityMap[mappingItem[0]] = [mappingItem[1], gmDict[fragilityFunction[0][0]]]
return(taxonomyToFragilityMap)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment