diff --git a/notebooks/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.ipynb b/notebooks/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.ipynb index f7489dd..09034ec 100644 --- a/notebooks/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.ipynb +++ b/notebooks/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.ipynb @@ -20,18 +20,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (utils.py, line 434)", + "ename": "ModuleNotFoundError", + "evalue": "No module named 'scipy'", "output_type": "error", "traceback": [ - "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n", - " File \u001b[1;32m\"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py\"\u001b[0m, line \u001b[1;32m2961\u001b[0m, in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\n", - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0;36m, in \u001b[0;35m\u001b[0;36m\u001b[0m\n\u001b[0;31m from rmtk.vulnerability.common import utils\u001b[0m\n", - "\u001b[0;36m File \u001b[0;32m\"/Users/vitorsilva/Dropbox/GEM/git/gem/rmtk/rmtk/vulnerability/common/utils.py\"\u001b[0;36m, line \u001b[0;32m434\u001b[0m\n\u001b[0;31m print str((it+1)*100/len(T))+'%'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mrmtk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvulnerability\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommon\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mutils\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mrmtk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvulnerability\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mderivation_fragility\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNLTHA_on_SDOF\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mNLTHA_on_SDOF\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mrmtk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvulnerability\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mderivation_fragility\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNLTHA_on_SDOF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_pinching_parameters\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mread_parameters\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'matplotlib'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'inline'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Dropbox/GEM/git/gem/rmtk/rmtk/vulnerability/common/utils.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mintegrate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptimize\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstats\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mshapely\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeometry\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mLineString\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mMultiPoint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mPoint\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minterpolate\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0minterp1d\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'scipy'" ] } ], @@ -148,7 +149,7 @@ "source": [ "damping_ratio = 0.05\n", "degradation = True\n", - "PDM, Sds = NLTHA_on_SDOF.calculate_fragility(capacity_curves, hysteresis, gmrs, damage_model, damping_ratio, degradation)\n", + "EDPs = NLTHA_on_SDOF.calculate_response(capacity_curves, hysteresis, gmrs, damage_model, damping_ratio, degradation)\n", "utils.save_result(PDM,'../../../../../rmtk_data/PDM.csv')" ] }, @@ -170,8 +171,8 @@ "outputs": [], "source": [ "minT, maxT,stepT = 0.0, 2.0, 0.1\n", - "regression_method = 'least squares'\n", - "utils.evaluate_optimal_IM(gmrs,PDM,minT,maxT,stepT,damage_model,damping_ratio,regression_method)" + "regression_method = 'cloud analysis'\n", + "utils.evaluate_optimal_IM(gmrs,EDPs,minT,maxT,stepT,damage_model,damping_ratio,regression_method)" ] }, { diff --git a/rmtk/vulnerability/common/utils.py b/rmtk/vulnerability/common/utils.py index e4899f6..9efd537 100644 --- a/rmtk/vulnerability/common/utils.py +++ b/rmtk/vulnerability/common/utils.py @@ -600,7 +600,7 @@ def calculate_iml(igmr, gmrs, IMT, T, damping): return iml -def calculate_mean_fragility(gmrs, PDM, T, damping, IMT, damage_model, method): +def calculate_mean_fragility(gmrs, EDPs, T, damping, IMT, damage_model, method): imls = calculate_imls(gmrs, T, damping) @@ -613,31 +613,40 @@ def calculate_mean_fragility(gmrs, PDM, T, damping, IMT, damage_model, method): elif IMT == 'PGA': imls = imls[2] - cumPDM = convert_damage_matrix_to_probability(PDM) + if method == 'cloud analysis': + Sds = EDPs[1] + #calculate log(SDs) versus log(IMLs) + #regression analysis using censored + #with + + else: + PDM = response[0] + cumPDM = convert_damage_matrix_to_probability(PDM) + + logmeans, logstddev = [], [] + if method == 'least squares': + for iDS in range(len(damage_model['damage_states'])): + solution, _ = optimize.leastsq(residual_lognormal_dist,[0.1, 0.6],args=(imls, cumPDM[iDS+1])) + logmeans.append(solution[0]) + logstddev.append(solution[1]) - logmeans, logstddev = [], [] - if method == 'least squares': - for iDS in range(len(damage_model['damage_states'])): - solution, _ = optimize.leastsq(residual_lognormal_dist,[0.1, 0.6],args=(imls, cumPDM[iDS+1])) - logmeans.append(solution[0]) - logstddev.append(solution[1]) - - elif method == 'max likelihood': - # the imls and the PDM are sorted to be used in the maximum likelihood approach - # the PDM should be a list of integers in this approach - I = np.argsort(imls, axis=0) - imls = np.array(imls) - imls = imls[I] - PDM_mle = [] - for iDS in range(len(damage_model['damage_states'])): - temp = cumPDM[iDS+1][I]*no_assets - temp2 = temp.astype(int) - PDM_mle = temp2.tolist() - solution = mle(PDM_mle,imls,no_assets,1) - logmeans.append(solution[0]) - logstddev.append(solution[1]) + elif method == 'max likelihood': + # the imls and the PDM are sorted to be used in the maximum likelihood approach + # the PDM should be a list of integers in this approach + I = np.argsort(imls, axis=0) + imls = np.array(imls) + imls = imls[I] + PDM_mle = [] + for iDS in range(len(damage_model['damage_states'])): + temp = cumPDM[iDS+1][I]*no_assets + temp2 = temp.astype(int) + PDM_mle = temp2.tolist() + solution = mle(PDM_mle,imls,no_assets,1) + logmeans.append(solution[0]) + logstddev.append(solution[1]) - Rsquare = calculate_correlation(logmeans,logstddev,cumPDM,imls) + Rsquare = calculate_correlation(logmeans,logstddev,cumPDM,imls) + fragility_model = {'damage_states': None, 'logmean': None,'logstddev': None, 'IMT': None} fragility_model['damage_states'] = damage_model['damage_states'] diff --git a/rmtk/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.py b/rmtk/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.py index 5f580f3..d23f8aa 100644 --- a/rmtk/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.py +++ b/rmtk/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.py @@ -15,7 +15,7 @@ package_directory = os.path.dirname(os.path.abspath(__file__)) -def calculate_fragility(capacity_curves, hysteresis, gmrs, damage_model, +def calculate_response(capacity_curves, hysteresis, gmrs, damage_model, damping, degradation): no_damage_states = len(damage_model['damage_states']) no_gmrs = len(gmrs['time']) @@ -33,7 +33,8 @@ def calculate_fragility(capacity_curves, hysteresis, gmrs, damage_model, Sdi = max(numpy.abs(numpy.array(disps))) [PDM, ds] = utils.allocate_damage(igmr, PDM, Sdi, limit_states) Sds[igmr][icc] = Sdi - return PDM, Sds + + return [PDM, Sds] def run_time_history_analysis(capacity_curves, hysteresis, icc, gmrs, igmr,