<commit_before># -*- coding: utf-8 -*-
import os
import numpy
import math
from scipy import interpolate
from scipy import optimize
import matplotlib.pyplot as plt
from rmtk.vulnerability.common import utils

def calculate_fragility(capacity_curves,gmrs,damage_model,damping):
#This function returns a damage probability matrix (PDM) and the corresponding spectral displacements
    
    no_damage_states = len(damage_model['damage_states'])
    no_gmrs = len(gmrs['time'])
    no_capacity_curves = len(capacity_curves['Sd'])
    PDM = numpy.zeros((no_gmrs,no_damage_states+1))
    Sds = numpy.zeros((no_gmrs,no_capacity_curves))
    for icc in range(no_capacity_curves):
        print str((icc+1)*100/no_capacity_curves) + '%'
        limit_states = utils.define_limit_states(capacity_curves,icc,damage_model)
        for igmr in range(no_gmrs):
            Sdi = calculate_target_Sd(gmrs,igmr,capacity_curves,icc,damping)
            [PDM, ds] = utils.allocate_damage(igmr,PDM,Sdi,limit_states)
            Sds[igmr][icc] = Sdi
    return PDM, Sds

def calculate_target_Sd(gmrs,igmr,capacity_curves,icc,damping):
#This function calculates the target displacement of the SDOF as per EC-8

    Sd = capacity_curves['Sd'][icc]
    Sa = capacity_curves['Sa'][icc]
    Sdy = capacity_curves['Sdy'][icc]
    Say = capacity_curves['Say'][icc]
    Te = capacity_curves['periods'][icc]
    Sdu = Sd[-1]
    Sau = Sa[-1]
    time = gmrs['time'][igmr]
    acc = gmrs['acc'][igmr]  
    Ty = 2*math.pi*math.sqrt(Sdy/(Say*9.81))
    
    spec_Ty = utils.NigamJennings(time,acc,[Ty],damping)
    demand_Sd_Ty = spec_Ty['Sd']
    spec_10sec = utils.NigamJennings(time,acc,[1.0],damping) 
    spec_03sec = utils.NigamJennings(time,acc,[0.3],damping) 
    Tc = spec_10sec['Sa']/spec_03sec['Sa'];
                          
    if Ty < Tc:
        
        if Sdy>demand_Sd_Ty:
            spectrum = utils.NigamJennings(time,acc,[Te],damping) 
            Sdi = spectrum['Sd']
        
        else:
            qu=demand_Sd_Ty/Say
            Sdi = max([demand_Sd_Ty/qu*(1+(qu-1)*Tc/Ty),demand_Sd_Ty])
            if Sdi > 3*demand_Sd_Ty:
                Sdi = demand_Sd_Ty
                
    else:
        Sdi = demand_Sd_Ty
        
    return Sdi<commit_msg>limit states sampled for each gmr<commit_after># -*- coding: utf-8 -*-
import os
import numpy
import math
from scipy import interpolate
from scipy import optimize
import matplotlib.pyplot as plt
from rmtk.vulnerability.common import utils

def calculate_fragility(capacity_curves,gmrs,damage_model,damping):
#This function returns a damage probability matrix (PDM) and the corresponding spectral displacements
    
    no_damage_states = len(damage_model['damage_states'])
    no_gmrs = len(gmrs['time'])
    no_capacity_curves = len(capacity_curves['Sd'])
    PDM = numpy.zeros((no_gmrs,no_damage_states+1))
    Sds = numpy.zeros((no_gmrs,no_capacity_curves))
    for icc in range(no_capacity_curves):
        print str((icc+1)*100/no_capacity_curves) + '%'
        for igmr in range(no_gmrs):
            limit_states = utils.define_limit_states(capacity_curves,icc,damage_model)
            Sdi = calculate_target_Sd(gmrs,igmr,capacity_curves,icc,damping)
            [PDM, ds] = utils.allocate_damage(igmr,PDM,Sdi,limit_states)
            Sds[igmr][icc] = Sdi
    return PDM, Sds

def calculate_target_Sd(gmrs,igmr,capacity_curves,icc,damping):
#This function calculates the target displacement of the SDOF as per EC-8

    Sd = capacity_curves['Sd'][icc]
    Sa = capacity_curves['Sa'][icc]
    Sdy = capacity_curves['Sdy'][icc]
    Say = capacity_curves['Say'][icc]
    Te = capacity_curves['periods'][icc]
    Sdu = Sd[-1]
    Sau = Sa[-1]
    time = gmrs['time'][igmr]
    acc = gmrs['acc'][igmr]  
    Ty = 2*math.pi*math.sqrt(Sdy/(Say*9.81))
    
    spec_Ty = utils.NigamJennings(time,acc,[Ty],damping)
    demand_Sd_Ty = spec_Ty['Sd']
    spec_10sec = utils.NigamJennings(time,acc,[1.0],damping) 
    spec_03sec = utils.NigamJennings(time,acc,[0.3],damping) 
    Tc = spec_10sec['Sa']/spec_03sec['Sa'];
                          
    if Ty < Tc:
        
        if Sdy>demand_Sd_Ty:
            spectrum = utils.NigamJennings(time,acc,[Te],damping) 
            Sdi = spectrum['Sd']
        
        else:
            qu=demand_Sd_Ty/Say
            Sdi = max([demand_Sd_Ty/qu*(1+(qu-1)*Tc/Ty),demand_Sd_Ty])
            if Sdi > 3*demand_Sd_Ty:
                Sdi = demand_Sd_Ty
                
    else:
        Sdi = demand_Sd_Ty
        
    return Sdi
{'fraction_non_alphanumeric': 0.12035398230088495, 'fraction_numerical': 0.012389380530973451, 'mean_word_length': 3.0510752688172045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2405502', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1694, 'n_words': 282}