-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmd.py
61 lines (55 loc) · 1.88 KB
/
fmd.py
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
from math import *
class TruncatedGutenbergRichter:
"""
Class defining Truncated Gutenberg-Richter frequency magnitude distribution.
"""
def __init__(self,a_value,b_value,min_mag,max_mag,bin_width):
"""
Define Gutenberg-Richter frequency magnitude distribution.
a_value: cumulative a value (10**a_value is the rate of earthquakes
[# of earthquakes / year] with magniutde greater or equal to 0)
b_value: b value
min_mag: minimum magnitude
max_mag: maximum magnitude
bin_width: bin width for occurrence rate calculation
"""
# TODO: check b value is greater than zero
# TODO: check max_mag is greater or equal than min_mag
self.a_value = a_value
self.b_value = b_value
self.min_mag = min_mag
self.max_mag = max_mag
self.bin_width = bin_width
def getWeightedMfd(self,weight):
"""
Return new truncated fdm with weighted
a value, that is a new fmd with annual
occurrence rates scaled by a factor equal
to weight.
"""
# TODO: check weight > 0
a_value_new = self.a_value + log10(weight)
return TruncatedGutenbergRichter(a_value_new,self.b_value,self.min_mag,self.max_mag,self.bin_width)
def getAnnualOccurrenceRates(self):
"""
Compute annual occurrence rates.
"""
min = round(self.min_mag / self.bin_width) * self.bin_width
max = round(self.max_mag / self.bin_width) * self.bin_width
if min != max:
min = min + self.bin_width / 2
max = max - self.bin_width / 2
n_bins = int((max - min) / self.bin_width) + 1
rates = []
for i in range(n_bins):
mag = min + i * self.bin_width
rate = 10**(self.a_value - self.b_value * (mag - self.bin_width / 2)) - 10**(self.a_value - self.b_value * (mag + self.bin_width / 2))
point = (mag,rate)
rates.append(point)
return rates
def printAnnualOccurrenceRates(self):
"""
Print annual occurrence rates to standard output.
"""
for point in self.getAnnualOccurrenceRates():
print point