Commit 9746879a authored by Tara Evaz Zadeh's avatar Tara Evaz Zadeh
Browse files

reduced lines of Fragility2Dictionary.py to less than 79 characters

parent cefece17
......@@ -3,14 +3,16 @@ import csv
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'.
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:
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'], [...]
......@@ -24,10 +26,11 @@ def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir):
Output:
Dictionary containing the taxonomy to fragility function map considering the ground-motion types.
It follows the format:
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]}
{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],
......@@ -38,13 +41,19 @@ def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir):
# 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]]]
for mappingItem in taxonomyToFragilitySource:
# Open the fragility-function file corresponding to the taxonomy in
# 'mappingitem[1]'
fragilityFunction = list(csv.reader(open(fragilityFileDir + "/" + \
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