In [2]:
import os
import sys
import pySW4 as sw4
import obspy
import matplotlib.pyplot as plt
import numpy as np
In [3]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=00000.z=0.topo.sw4img'
topo = sw4.read_image(f)
topo.plot(cmap='terrain')
Out[3]:
In [4]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=00000.z=0.p.sw4img'
input_, output_ = sw4.read_metadata('../sw4-v1.1/examples/rfile/berkeley.sw4',
'../sw4-v1.1/examples/rfile/mon.txt')
image = sw4.read_image(f, input_)
print image
for patch in image.patches:
print patch
fig, ax, cb = image.plot()
Velocity magnitude plots
In [5]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=01402.z=0.magdudt.sw4img'
input_, output_ = sw4.read_metadata('../sw4-v1.1/examples/rfile/berkeley.sw4',
'../sw4-v1.1/examples/rfile/mon.txt')
image = sw4.read_image(f, input_)
fig, ax, cb = image.plot(vmax='3', cmap='jet')
Horizontal Peak Ground Velocity (HPGV) plots
In [6]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=14016.z=0.hmaxdudt.sw4img'
input_, output_ = sw4.read_metadata('../sw4-v1.1/examples/rfile/berkeley.sw4',
'../sw4-v1.1/examples/rfile/mon.txt')
image = sw4.read_image(f, input_)
fig, ax, cb = image.plot(vmax='3', cmap='hot_r')
In [7]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=00000.x=2500.p.sw4img'
image = sw4.read_image(f, input_)
print image
for patch in image.patches:
print patch
print image.curvilinear_grid_patch
image.patches[1].plot()
image.patches[0].plot()
Out[7]:
In [8]:
fig, ax, cb = image.plot(projection_distance=1000)
ax.set_ylim(image.extent[3], image.extent[2]-300)
Out[8]:
In [9]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=01402.x=2500.magdudt.sw4img'
image = sw4.read_image(f, input_)
fig, ax, cb = image.plot(vmax='3', projection_distance=1000)
ax.set_ylim(image.extent[3], image.extent[2]-300)
Out[9]:
In [10]:
f = '../sw4-v1.1/examples/rfile/results/berkeley.cycle=00000.y=2500.p.sw4img'
image = sw4.read_image(f, input_)
print image
for patch in image.patches:
print patch
print image.curvilinear_grid_patch
image.patches[1].plot()
image.patches[0].plot()
fig, ax, cb = image.plot(projection_distance=1800)
ax.set_ylim(image.extent[3], image.extent[2]-300)
Out[10]:
Reading an array or a line of stations added to the input file by station_array or station_line.
In [11]:
name = 'surface'
path = '../sw4-v1.1/examples/rfile/results'
array = sw4.read_stations(name, path, 'velocity')
In [12]:
for sta in array:
x, y, z = (sta.stats.coordinates.x,
sta.stats.coordinates.y,
sta.stats.coordinates.z)
plt.plot(y, x,'kv', mfc='none')
In [13]:
array[10].plot()
Plot time slices of the Z component through all stations of the array
In [14]:
x, y = input_.source[0].x, input_.source[0].y
z_data = array.get_data('*Z')
for time in (3.5, 5.0, 6.2):
fig, ax = plt.subplots()
step = int(time / array.delta)
values_t = z_data[:, :, step]
max_ = np.abs(values_t).max()
im = ax.imshow(values_t, interpolation='nearest', extent=array.extent,
cmap='seismic', vmin=-max_, vmax=max_, origin='lower')
plt.colorbar(im)
ax.set_title('time: {:.3f}, s'.format(array.times()[step]))
ax.plot(y, x, 'k*', mfc='none', ms=10)
[ax.plot(y_, x_, 'kv', mfc='none') for x_ in array.xi for y_ in array.yi ]
In [15]:
st = obspy.read('../sw4-v1.1/examples/rfile/results/BDSN.BKS*', 'SAC')
st.plot(size=(800, 400))
Reading and plotting with pySW4
In [16]:
name = 'BDSN.BKS'
path = '../sw4-v1.1/examples/rfile/results'
st = sw4.read_stations(name, path, 'velocity')
starttime = st.starttime
st.trim(endtime=starttime + 20)
fig, ax = st.plot_traces(lw=1)