forked from preinh/pshab
/
01_catalog_plots.py
274 lines (184 loc) · 7.36 KB
/
01_catalog_plots.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# -*- coding: utf-8 -*-
###
### Imports
###
import pickle
# Python Numerical and Plotting Libraries
import numpy as np
import matplotlib.pyplot as plt
plt.xkcd()
# HMTK Catalogue Import/Export Libraries
from hmtk.parsers.catalogue.csv_catalogue_parser import CsvCatalogueParser, CsvCatalogueWriter
# HMTK Plotting Tools
from hmtk.plotting.seismicity.catalogue_plots import (plot_depth_histogram,
plot_magnitude_time_scatter,
plot_magnitude_time_density,
plot_magnitude_depth_density,
plot_observed_recurrence)
from hmtk.plotting.mapping import HMTKBaseMap
print 'Imports OK!'
###
### Map Config
###
map_dpi = 90
add_geology = True
add_sourcemodel = True
savefig=False
plot_mag_time_count = False
#map_title = 'Brazilian Seismic Zones'
map_title = '\gls{bsb2013}.08 Catalogue and Seismic Zoning'
#map_title = 'ISC-GEM Catalogue'
#map_title = 'South-American Lithology'
###
### Catalogue
###
#input_catalogue_file = 'data_input/hmtk_sa3'
input_catalogue_file = 'data_input/hmtk_bsb2013'
###
### Catalogue cache or read/cache
###
try:
catalogue = pickle.load(open(input_catalogue_file + ".pkl", 'rb'))
except:
parser = CsvCatalogueParser(input_catalogue_file + ".csv")
catalogue = parser.read_file()
print 'Input complete: %s events in catalogue' % catalogue.get_number_events()
print 'Catalogue Covers the Period: %s to %s' % (catalogue.start_year, catalogue.end_year)
# Sort catalogue chronologically
catalogue.sort_catalogue_chronologically()
print 'Catalogue sorted chronologically!'
valid_magnitudes = np.logical_not(np.isnan(catalogue.data['magnitude']))
catalogue.select_catalogue_events(valid_magnitudes)
valid_magnitudes = catalogue.data['magnitude'] >= 3.0
catalogue.select_catalogue_events(valid_magnitudes)
#print catalogue.data['magnitude']
valid_depths = np.logical_not(np.isnan(catalogue.data['depth']))
catalogue.select_catalogue_events(valid_depths)
# Set-up the file writer
output_file_name = 'data_input/hmtk_sa3.csv'
writer = CsvCatalogueWriter(output_file_name)
# Write the catalogue to file
writer.write_file(catalogue)
#exit()
print 'File %s written' % output_file_name
f=open(input_catalogue_file + ".pkl",'wb')
pickle.dump(catalogue, f)
f.close()
###
### Source Model
###
if add_sourcemodel:
from hmtk.parsers.source_model.nrml04_parser import nrmlSourceModelParser
source_model_file = "/Users/pirchiner/dev/pshab/dourado_reproduction/source_model.xml"
# read source model file
parser = nrmlSourceModelParser(source_model_file)
source_model = parser.read_file(2.0)
# add source model
#basemap1.add_source_model(source_model, area_border, border_width, point_marker, point_size, overlay)
#basemap1.add_source_model(source_model, overlay=True)
if plot_mag_time_count:
filename = "/Users/pirchiner/Desktop/tmp_plot.png"
# Limit the catalogue to the time period 1960 - 2012
valid_time = np.logical_and(catalogue.data['year'] >= 1960,
catalogue.data['year'] <= 2014)
catalogue.select_catalogue_events(valid_time)
plot_magnitude_time_density(catalogue, 0.5, 1.0, filename=filename, figsize=(18,6))
print 'Catalogue now contains %s events' % catalogue.get_number_events()
# Show distribution of magnitudes with time
#plot_magnitude_time_scatter(catalogue, fmt_string='o', alpha=0.3, linewidth=0.0)
# Depth histogram
# plot_depth_histogram(catalogue, 10.)
filename = "/Users/pirchiner/Desktop/tmp_plot.png"
# Time-varying completeness
completeness = np.array([[1980., 3.0],
[1985., 4.0],
[1964., 5.0],
[1910., 6.5],
[1900., 9.0]])
plot_observed_recurrence(catalogue, completeness, 0.2,
catalogue.end_year,
title="Recurrence [#Eq / Time]",
overlay=False,
markersize=10,
color=['#FEF2D8','#F18C79'],
#linewidth=3,
alpha=0.6,
)
plt.show()
exit()
input_catalogue_file = 'data_input/hmtk_sa3'
#input_catalogue_file = 'data_input/hmtk_bsb2013'
###
### Catalogue cache or read/cache
###
try:
catalogue = pickle.load(open(input_catalogue_file + ".pkl", 'rb'))
except:
parser = CsvCatalogueParser(input_catalogue_file + ".csv")
catalogue = parser.read_file()
print 'Input complete: %s events in catalogue' % catalogue.get_number_events()
print 'Catalogue Covers the Period: %s to %s' % (catalogue.start_year, catalogue.end_year)
# Sort catalogue chronologically
catalogue.sort_catalogue_chronologically()
print 'Catalogue sorted chronologically!'
valid_magnitudes = np.logical_not(np.isnan(catalogue.data['magnitude']))
catalogue.select_catalogue_events(valid_magnitudes)
valid_magnitudes = catalogue.data['magnitude'] >= 3.0
catalogue.select_catalogue_events(valid_magnitudes)
#print catalogue.data['magnitude']
valid_depths = np.logical_not(np.isnan(catalogue.data['depth']))
catalogue.select_catalogue_events(valid_depths)
# Set-up the file writer
output_file_name = 'data_input/hmtk_sa3.csv'
writer = CsvCatalogueWriter(output_file_name)
# Write the catalogue to file
writer.write_file(catalogue)
#exit()
print 'File %s written' % output_file_name
f=open(input_catalogue_file + ".pkl",'wb')
pickle.dump(catalogue, f)
f.close()
filename = "/Users/pirchiner/Desktop/tmp_plot.png"
# Time-varying completeness
completeness = np.array([[1980., 3.0],
[1985., 4.0],
[1964., 5.0],
[1910., 6.5],
[1900., 9.0]])
plot_observed_recurrence(catalogue, completeness, 0.2,
catalogue.end_year,
title="Recurrence [Rate / Time]",
filename=filename,
overlay=True,
color=['#036F73','#84CDC2'],
markersize=10,
#linewidth=3,
alpha=0.6)
plt.show()
exit()
plt.show()
exit()
# In[ ]:
# Limit the catalogue to depths less than 50 km
#valid_depth = catalogue.data['depth'] <= 50.
#catalogue.select_catalogue_events(valid_depth)
plot_depth_histogram(catalogue, 2.0)
exit()
# In[ ]:
# Set-up the file writer
output_file_name = 'data_output/basic_demo_catalogue_1.csv'
writer = CsvCatalogueWriter(output_file_name)
# Write the catalogue to file
writer.write_file(catalogue)
print 'File %s written' % output_file_name
# In[ ]:
completeness = np.array([[1985., 4.0],
[1964., 5.0],
[1910., 6.5]])
# Set-up the exporter
output_file_name = 'data_output/basic_demo_catalogue_complete_1.csv'
writer = CsvCatalogueWriter(output_file_name)
# Write the catalogue to file, purging events from the incomplete period
writer.write_file(catalogue, magnitude_table=completeness)
print 'File %s written' % output_file_name
# In[ ]: