Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Commit 9df9bc4

Browse files
committed
Structure for cloud analysis
1 parent bd8e4cc commit 9df9bc4

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

notebooks/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.ipynb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 1,
23+
"execution_count": 2,
2424
"metadata": {},
2525
"outputs": [
2626
{
27-
"ename": "SyntaxError",
28-
"evalue": "invalid syntax (utils.py, line 434)",
27+
"ename": "ModuleNotFoundError",
28+
"evalue": "No module named 'scipy'",
2929
"output_type": "error",
3030
"traceback": [
31-
"Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n",
32-
" 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",
33-
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-1-a0f7315c782f>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0;36m, in \u001b[0;35m<module>\u001b[0;36m\u001b[0m\n\u001b[0;31m from rmtk.vulnerability.common import utils\u001b[0m\n",
34-
"\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"
31+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
32+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
33+
"\u001b[0;32m<ipython-input-2-a0f7315c782f>\u001b[0m in \u001b[0;36m<module>\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",
34+
"\u001b[0;32m~/Dropbox/GEM/git/gem/rmtk/rmtk/vulnerability/common/utils.py\u001b[0m in \u001b[0;36m<module>\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",
35+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'scipy'"
3536
]
3637
}
3738
],
@@ -148,7 +149,7 @@
148149
"source": [
149150
"damping_ratio = 0.05\n",
150151
"degradation = True\n",
151-
"PDM, Sds = NLTHA_on_SDOF.calculate_fragility(capacity_curves, hysteresis, gmrs, damage_model, damping_ratio, degradation)\n",
152+
"EDPs = NLTHA_on_SDOF.calculate_response(capacity_curves, hysteresis, gmrs, damage_model, damping_ratio, degradation)\n",
152153
"utils.save_result(PDM,'../../../../../rmtk_data/PDM.csv')"
153154
]
154155
},
@@ -170,8 +171,8 @@
170171
"outputs": [],
171172
"source": [
172173
"minT, maxT,stepT = 0.0, 2.0, 0.1\n",
173-
"regression_method = 'least squares'\n",
174-
"utils.evaluate_optimal_IM(gmrs,PDM,minT,maxT,stepT,damage_model,damping_ratio,regression_method)"
174+
"regression_method = 'cloud analysis'\n",
175+
"utils.evaluate_optimal_IM(gmrs,EDPs,minT,maxT,stepT,damage_model,damping_ratio,regression_method)"
175176
]
176177
},
177178
{

rmtk/vulnerability/common/utils.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def calculate_iml(igmr, gmrs, IMT, T, damping):
600600

601601
return iml
602602

603-
def calculate_mean_fragility(gmrs, PDM, T, damping, IMT, damage_model, method):
603+
def calculate_mean_fragility(gmrs, EDPs, T, damping, IMT, damage_model, method):
604604

605605
imls = calculate_imls(gmrs, T, damping)
606606

@@ -613,31 +613,40 @@ def calculate_mean_fragility(gmrs, PDM, T, damping, IMT, damage_model, method):
613613
elif IMT == 'PGA':
614614
imls = imls[2]
615615

616-
cumPDM = convert_damage_matrix_to_probability(PDM)
616+
if method == 'cloud analysis':
617+
Sds = EDPs[1]
618+
#calculate log(SDs) versus log(IMLs)
619+
#regression analysis using censored
620+
#with
621+
622+
else:
623+
PDM = response[0]
624+
cumPDM = convert_damage_matrix_to_probability(PDM)
625+
626+
logmeans, logstddev = [], []
627+
if method == 'least squares':
628+
for iDS in range(len(damage_model['damage_states'])):
629+
solution, _ = optimize.leastsq(residual_lognormal_dist,[0.1, 0.6],args=(imls, cumPDM[iDS+1]))
630+
logmeans.append(solution[0])
631+
logstddev.append(solution[1])
617632

618-
logmeans, logstddev = [], []
619-
if method == 'least squares':
620-
for iDS in range(len(damage_model['damage_states'])):
621-
solution, _ = optimize.leastsq(residual_lognormal_dist,[0.1, 0.6],args=(imls, cumPDM[iDS+1]))
622-
logmeans.append(solution[0])
623-
logstddev.append(solution[1])
624-
625-
elif method == 'max likelihood':
626-
# the imls and the PDM are sorted to be used in the maximum likelihood approach
627-
# the PDM should be a list of integers in this approach
628-
I = np.argsort(imls, axis=0)
629-
imls = np.array(imls)
630-
imls = imls[I]
631-
PDM_mle = []
632-
for iDS in range(len(damage_model['damage_states'])):
633-
temp = cumPDM[iDS+1][I]*no_assets
634-
temp2 = temp.astype(int)
635-
PDM_mle = temp2.tolist()
636-
solution = mle(PDM_mle,imls,no_assets,1)
637-
logmeans.append(solution[0])
638-
logstddev.append(solution[1])
633+
elif method == 'max likelihood':
634+
# the imls and the PDM are sorted to be used in the maximum likelihood approach
635+
# the PDM should be a list of integers in this approach
636+
I = np.argsort(imls, axis=0)
637+
imls = np.array(imls)
638+
imls = imls[I]
639+
PDM_mle = []
640+
for iDS in range(len(damage_model['damage_states'])):
641+
temp = cumPDM[iDS+1][I]*no_assets
642+
temp2 = temp.astype(int)
643+
PDM_mle = temp2.tolist()
644+
solution = mle(PDM_mle,imls,no_assets,1)
645+
logmeans.append(solution[0])
646+
logstddev.append(solution[1])
639647

640-
Rsquare = calculate_correlation(logmeans,logstddev,cumPDM,imls)
648+
Rsquare = calculate_correlation(logmeans,logstddev,cumPDM,imls)
649+
641650

642651
fragility_model = {'damage_states': None, 'logmean': None,'logstddev': None, 'IMT': None}
643652
fragility_model['damage_states'] = damage_model['damage_states']

rmtk/vulnerability/derivation_fragility/NLTHA_on_SDOF/NLTHA_on_SDOF.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package_directory = os.path.dirname(os.path.abspath(__file__))
1616

1717

18-
def calculate_fragility(capacity_curves, hysteresis, gmrs, damage_model,
18+
def calculate_response(capacity_curves, hysteresis, gmrs, damage_model,
1919
damping, degradation):
2020
no_damage_states = len(damage_model['damage_states'])
2121
no_gmrs = len(gmrs['time'])
@@ -33,7 +33,8 @@ def calculate_fragility(capacity_curves, hysteresis, gmrs, damage_model,
3333
Sdi = max(numpy.abs(numpy.array(disps)))
3434
[PDM, ds] = utils.allocate_damage(igmr, PDM, Sdi, limit_states)
3535
Sds[igmr][icc] = Sdi
36-
return PDM, Sds
36+
37+
return [PDM, Sds]
3738

3839

3940
def run_time_history_analysis(capacity_curves, hysteresis, icc, gmrs, igmr,

0 commit comments

Comments
 (0)