-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSplitDuration.py
More file actions
167 lines (149 loc) · 5.2 KB
/
SplitDuration.py
File metadata and controls
167 lines (149 loc) · 5.2 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
==============================================================================
~~~ SplitDuration ~~~
Calculate the expected time periods of time-delay (acquired from shear-wave splitting)
increase and decrease according to the empirical relation
of Crampin et al. (2013).
For inquiries, bug reports or other information please contact me at:
ispingos[at]geol.uoa.gr
Ioannis Spingos (c) 2019
Reference:
Crampin, S., Gao, Y. & De Santis, A. (2013) A few earthquake conundrums resolved.
J Asian Earth Sci 62, 501-509. doi: 10.1016/j.jseaes.2012.10.036
==============================================================================
"""
#########################################################################################
#########################################################################################
# intial imports
from __future__ import division
from builtins import input
import sys, getopt
# console?
consoleMode=False
opts,args=getopt.getopt(sys.argv[1:],"c:",["console="])
for opt,arg in opts:
if opt in ("-c","--console"):
consoleMode = arg
# make sure it's true or false in any form
consoleMode = eval(consoleMode[0].upper()+consoleMode[1:].lower())
##
try:
from PyQt5 import QtWidgets, QtCore
except ImportError:
print("..: PyQt5 is not installed! Reverting to console mode...")
consoleMode=True
##
_VERSION="1.0.0"
_VERDATE="30/01/2019"
## functions ##
def accumulation(M):
"""
calculate accumulation period from equation
M = 2.16log10(days)+0.37 => log10(days) = (M-0.37)/2.16
days = 10**((M-0.37)/2.16)
"""
return 10 ** (( M - 0.37 ) / 2.16)
def relaxation(M):
"""
calculate relaxation period from equation
M = 1.17log10(days)+4.01 =>
days = 10**((M-4.01)/1.17)
"""
return 10 ** (( M - 4.01) / 1.17)
def days2time(inp):
"""
convert the input time (in days) to a more
convenient format (yy-MM-DD hh:mm:ss)
"""
# first get years
years = inp // 365
yy = years
# months
months = (inp % 365) // 30
MM = months
#
days = (inp % 365) % 30
DD = days // 1
# now get the hours
hours = 24 * (days % 1)
hh = hours // 1
# now converts minutes
minutes = 60 * (hours % 1)
mm = minutes // 1
# now seconds
seconds = 60 *(minutes % 1)
ss = seconds
return "%03d year(s), %02d month(s), %02d day(s) %02d:%02d:%06.3f (%.2e days in total)" \
% (yy,MM,DD,hh,mm,ss,inp)
## get cute?
if consoleMode:
class SplitDurationConsole():
def __init__(self):
self.globName="SplitDuration"
self.titleString="%s v.%s" % (self.globName,_VERSION)
print("\n")
print(self.titleString)
print("\n")
M=float(input("Please specify an input earthquake magnitude: "))
print("\n")
# calculations
acc=accumulation(M)
rel=relaxation(M)
#
print("Accumulation period: %s" % days2time(acc))
print("Relaxation period: %s" % days2time(rel))
print("\n")
else:
class SplitDuration(QtWidgets.QMainWindow):
def __init__(self):
"""
initialize
"""
self.globName="SplitDuration"
self.titleString="%s v.%s" % (self.globName,_VERSION)
QtWidgets.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.setWindowTitle(self.titleString)
self.resize(400, 150)
self.mainWidg=QtWidgets.QWidget(self)
self.gLayout=QtWidgets.QGridLayout(self.mainWidg)
# make labels
self.magLabel=QtWidgets.QLabel("Magnitude:",self)
self.magInput=QtWidgets.QLineEdit("0",self)
self.accLabel=QtWidgets.QLabel("Accumulation (days):",self)
self.accResLabel=QtWidgets.QLabel("",self)
self.relLabel=QtWidgets.QLabel("Relaxation (days):",self)
self.relResLabel=QtWidgets.QLabel("",self)
self.updButton=QtWidgets.QPushButton("Calculate",self)
self.updButton.clicked.connect(self.launch)
## add created to layout
self.gLayout.addWidget(self.magLabel)
self.gLayout.addWidget(self.magInput)
self.gLayout.addWidget(self.accLabel)
self.gLayout.addWidget(self.accResLabel)
self.gLayout.addWidget(self.relLabel)
self.gLayout.addWidget(self.relResLabel)
self.gLayout.addWidget(self.updButton)
self.setCentralWidget(self.mainWidg)
def launch(self,consoleMode=False):
"""
do the calculations
"""
M=float(self.magInput.text())
acc=accumulation(M)
rel=relaxation(M)
# set results to view
self.accResLabel.setText(days2time(acc))
self.relResLabel.setText(days2time(rel))
## LAUNCH
if not consoleMode:
if __name__=='__main__':
## initialize app ##
app=QtWidgets.QApplication(sys.argv)
SplitDuration=SplitDuration()
## show app ##
SplitDuration.show()
sys.exit(app.exec_())
else:
SplitDurationConsole()