Install


In [ ]:
# git clone https://github.com/malcolmw/seismic-python.git
# cd seismic-python
# pip install -e .

Import modules


In [ ]:
%matplotlib ipympl
%load_ext autoreload

import matplotlib.pyplot as plt
import matplotlib.colors
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import pandas as pd
import seispy

Read data


In [ ]:
# Read text file into Pandas.DataFrame
df = pd.read_table(
    '/Users/malcolmwhite/Downloads/randmeshvp_dws.dat', 
    header=None, 
    delim_whitespace=True,
    names=['lon', 'lat', 'depth', 'vp', 'vs', '??']
)
# Update longitude to in [-180, 180]
df['lon'] -= 360
# Create an empty VelocityModel object
vm = seispy.velocity.VelocityModel()
# Initialize the VelocityModel object with data from the DataFrame
vm.from_DataFrame(df);

In [ ]:
vm.extract_slice?

Plot slices


In [ ]:
norm = matplotlib.colors.Normalize(vmin=3.3, vmax=7.6)
cmap = plt.get_cmap('jet_r')

plt.close('all')
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
for strike in (0, 90):
    # Extract a slice with given strike
    vslice, ned, geo = vm.extract_slice(strike=strike)
    # Convert Geographic coordinates to Cartesian coordinates for plotting on XYZ axes
    xyz = geo.to_cartesian()
    colors = [[cmap(norm(v)) for v in row] for row in vslice]
#     ax.plot_surface(ned[..., 0], ned[..., 1] + shift, ned[..., 2], facecolors=colors)
    ax.plot_surface(xyz[..., 0], xyz[..., 1], xyz[..., 2], facecolors=colors)
ax.invert_zaxis()

Extract velocity value at arbitrary locations


In [ ]:
geo = seispy.coords.as_geographic([[33.5, -116.5, 0], [34.0, -116.5, 0]])
vm('P', geo)