Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions openquake/mbi/wkf/remove_buffer_around_faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@


def main(fname: str, path_point_sources: str, out_path: str, dst: float,
threshold_mag: float=6.5, use: str=''):
threshold_mag: float=6.5, use: str='', remove=False):

if remove in ('true', 'True'):
remove = True

# Create the output folder (if needed)
create_folder(out_path)

# Process sources
remove_buffer_around_faults(fname, path_point_sources, out_path, dst,
remove_buffer_around_faults(fname, path_point_sources, out_path, dst,
threshold_mag, use)


Expand All @@ -24,6 +27,7 @@ def main(fname: str, path_point_sources: str, out_path: str, dst: float,
main.dst = "Distance [km] of the buffer around the fault"
main.threshold_mag = "Threshold magnitude"
main.use = 'A list with the ID of sources that should be considered'
main.remove = 'A boolean. When true, removes the original files'

if __name__ == '__main__':
sap.run(main)
30 changes: 16 additions & 14 deletions openquake/wkf/distributed_seismicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_data(src, coo_pnt_src, pnt_srcs, buffer=1.0):
# Get the fault surface and compute rrup
if isinstance(src, SimpleFaultSource):
sfc = SimpleFaultSurface.from_fault_data(src.fault_trace,
src.upper_seismogenic_depth,
src.upper_seismogenic_depth,
src.lower_seismogenic_depth,
src.dip, 1.0)
else:
Expand Down Expand Up @@ -123,7 +123,8 @@ def get_stacked_mfd(srcs: list, within_idx: list, binw: float):

def remove_buffer_around_faults(fname: str, path_point_sources: str,
out_path: str, dst: float,
threshold_mag: float = 6.5, use: str=''):
threshold_mag: float = 6.5,
use: str='', remove=False):
"""
Remove the seismicity above a magnitude threshold for all the point
sources within a buffer around faults.
Expand All @@ -138,12 +139,12 @@ def remove_buffer_around_faults(fname: str, path_point_sources: str,
:param dst:
The distance in km of the buffer
:param dst:
The threshold distance used to separate seismicity on the fault and
The threshold distance used to separate seismicity on the fault and
in the distributed seismicity sources
:returns:
A .xml file with the ajusted point sources
"""

if len(use) > 0:
use = get_list(use)

Expand Down Expand Up @@ -172,9 +173,10 @@ def remove_buffer_around_faults(fname: str, path_point_sources: str,
# Reading file content
tssm = to_python(fname, sourceconv)

# Removing this file
# Removing this file
tmp_fle = pathlib.Path(fname)
tmp_fle.unlink()
if remove:
tmp_fle.unlink()

# Processing
tcoo = np.array([(p.location.longitude, p.location.latitude) for p in
Expand All @@ -189,18 +191,18 @@ def remove_buffer_around_faults(fname: str, path_point_sources: str,
for grp in ssm_faults:
for s in grp:
faults.append(s)

fig, axs = plt.subplots(1, 1)
plt.plot(coo_pnt_src[:, 0], coo_pnt_src[:, 1], '.')
plt.plot(coo_pnt_src[:, 0], coo_pnt_src[:, 1], '.')

# Processing faults
buffer = []
bco = []
for src in faults:

# Getting the subset of point sources in the surrounding of the fault
# `src`. `coo_pnt_src` is a numpy.array with two columns (i.e. lon and
# lat). `pnt_srcs` is a list containing the point sources that
# `src`. `coo_pnt_src` is a numpy.array with two columns (i.e. lon and
# lat). `pnt_srcs` is a list containing the point sources that
# collectively describe the distributed seismicity souces provided as
# input
pnt_ii, sel_pnt_srcs, sel_pnt_coo, rrup = get_data(src, coo_pnt_src,
Expand All @@ -213,10 +215,10 @@ def remove_buffer_around_faults(fname: str, path_point_sources: str,
within_idx = np.nonzero(rrup < dst)[0]
idxs = sorted([pnt_ii[i] for i in within_idx], reverse=True)

plt.plot(coo_pnt_src[idxs, 0], coo_pnt_src[idxs, 1], 'or', mfc='none')
plt.plot(coo_pnt_src[idxs, 0], coo_pnt_src[idxs, 1], 'or', mfc='none')

for isrc in idxs:

# Updating mmax for the point source
# sel_pnt_srcs[isrc].mfd.max_mag = threshold_mag
pnt_srcs[isrc].mfd.max_mag = threshold_mag
Expand All @@ -232,7 +234,7 @@ def remove_buffer_around_faults(fname: str, path_point_sources: str,
mask = np.ones(len(coo_pnt_src), dtype=bool)
mask[pnt_ii[within_idx]] = False
coo_pnt_src = coo_pnt_src[mask, :]

else:
continue

Expand Down