-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
executable file
·108 lines (82 loc) · 2.66 KB
/
__init__.py
File metadata and controls
executable file
·108 lines (82 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
"""
Test of the package
"""
import Forecasts
import IMRs
import SHA
import Sites
from utils import *
wrk = '/Users/fengw/local/pylib/pysha'
datapth = os.path.join(wrk,'data/')
MetaPth = os.path.join(wrk,'metadata')
plotpth = os.path.join( wrk, 'plots' )
SiteInfo = {'SiteName':'STNI',}
SiteInfo = {'SiteName':'s758',}
SiteInfo = {'SiteName':'s115',}
ERF = 'UCERF2'
SourceType = 'NonPoisson'
ERFinfo = (35,5,3,1) # will change depend on different IMRs and different ERFs
Ti = 3.0
IMTdict = {'-1.0':'PGA', '-2.0':'PGV', 'T':'PSA'}
if Ti != -2.0:
if Ti == -1.0:
filen = 'PGA'
xlab = 'PGA (g)'
else:
filen = 'PSA%s'%('%.3f'%Ti)
xlab = '%s sec PSA (g)'%('%.3f'%Ti)
else:
xlab = 'PGV (cm/s)'
self.filen = 'PGV'
pfmt = 'png'
if __name__ == '__main__':
import os, sys
opt = sys.argv[1] # CalcHC, PlotHC, Disaggregation
if opt == 'CalcHC':
#IMRs = ['CyberShake','CB08','BA08','CY08','AS08']
IMR = sys.argv[2]
IMLs = np.arange(0.01,3,0.2) # in (g)
P = SHA.PSHA(ERF=ERF, IMR=IMR, SourceType=SourceType, ERFinfo=ERFinfo, Ti=Ti)
SiteData = datapth + 'Sites/cs_site_types.txt'
P.HazardCurveCalc(IMLs,SiteInfo,SiteData,MetaPth = MetaPth)
if opt == 'PlotHC':
IMR = sys.argv[2]
SiteName = SiteInfo['SiteName']
plotpth = plotpth + '/%s'%SiteName
if not os.path.exists(plotpth):
os.mkdir( plotpth )
# Plot Comparison of Hazard Curves (with CyberShake)
IMR_all = ['CyberShake','CB08','BA08','CY08','AS08']
clrs = ['k','#FFC0CB','b','g','#FFA500']
lss = ['-','--','--','--','--']
marker=['o','','','','']
if IMR == 'IMRs':
IMRmodel = IMR_all
itmp = 0
else:
IMRmodel = [IMR,]
for i in xrange( len(IMR_all) ):
if IMR == IMR_all[i]:
itmp = i
break
import matplotlib.pyplot as plt
fig = plt.figure(1)
ax = fig.add_subplot( 111 )
for i in xrange( len(IMRmodel) ):
IMR0 = IMRmodel[i]
MetaFile = MetaPth + '/%s/Meta_HazardCurve_%s_%s_%s.py'%(SiteName, IMR0, SiteName, filen)
meta = load(MetaFile)
IMLs = meta.IMLs
PoE = meta.PoE
ax.loglog(IMLs,PoE,c = clrs[i+itmp], ls=lss[i+itmp], marker=marker[i+itmp],mfc='None',mec=clrs[0],label=IMR_all[i+itmp],lw=2)
lg = plt.legend( title='IMRs' )
lg.draw_frame(False)
ax.set_xlim([0,2.0])
ax.set_ylim([1.e-6,1])
plt.grid(True)
plt.grid(b=True,which='minor')
ax.set_xlabel( xlab )
ax.set_ylabel( 'Probability Rate (1/yr)' ) # this depends on the rupture probability used in UCERF2 (whether it is 1 year span or T year span)
ax.set_title( 'Hazard Curve for %s'%SiteName )
fig.savefig( plotpth + '/HazardCurves_%s_%s_%s.%s'%(IMR, SiteName, filen, pfmt), format=pfmt )