bruges
¶In general bruges
is not yet directly compatible with xarray
's objects. You can always pass the internal NumPy data from an xarray.DataAarray
called x
like:
x.data
So it shouldn't cause too many problems.
import numpy as np
import segyio
ds = np.DataSource('../data') # <- Local target.
url = 'https://geocomp.s3.amazonaws.com/data/F3_8-bit_int.sgy'
with segyio.open(ds.open(url).name) as s:
seismic = segyio.cube(s)
# Volume is int16. Turn it into floats.
seismic = (seismic / np.max(np.abs(seismic))).astype(float)
seismic.shape
(225, 300, 463)
import matplotlib.pyplot as plt
plt.imshow(seismic[50].T)
<matplotlib.image.AxesImage at 0x7f41d4104400>
We don't really need to do this, but let's turn this volume into an xarray.DataArray
object like so:
import xarray as xr
i, x, t = seismic.shape
# I don't have the inline, xline numbers, so I'll just use the shape.
iline = np.arange(i)
xline = np.arange(x)
twt = np.arange(t) * 0.004
seismic_xr = xr.DataArray(seismic,
name='amplitude',
coords=[iline, xline, twt],
dims=['iline', 'xline', 'twt']
)
Later on, this will let us easily display attributes and seismic together, for example.
import bruges as bg
env = bg.attribute.envelope(seismic)
plt.figure(figsize=(6, 10))
plt.imshow(env[100].T, interpolation='bicubic')
<matplotlib.image.AxesImage at 0x7f028250d1f0>
phase = bg.attribute.instantaneous_phase(seismic)
plt.figure(figsize=(6, 10))
plt.imshow(phase[100].T, cmap='twilight_shifted', interpolation='none')
# Needs a circular cmap and no interpolation.
<matplotlib.image.AxesImage at 0x7f02824fd6a0>
freq = bg.attribute.instantaneous_frequency(seismic, dt=0.004)
plt.figure(figsize=(6, 10))
plt.imshow(freq[100].T, cmap='gist_rainbow', interpolation='bicubic', vmin=-10)
<matplotlib.image.AxesImage at 0x7f02648918b0>
⚠️ This one takes quite a bit longer than the simpler attributes above, so I'll just compute on a sub-cube:
seismic.shape
(225, 300, 463)
subcube = seismic[50:150, 120:220, :350]
# ⚠️ SLOW
semb = bg.attribute.similarity(subcube, duration=0.036, dt=0.004, kind='gst')
plt.figure(figsize=(6, 10))
plt.imshow(semb[50].T, cmap='gray', interpolation='bicubic')
<matplotlib.image.AxesImage at 0x7f02647a85e0>
xarray
¶Let's look at how to make this into an xarray.DataArray
:
env_xr = xr.DataArray(seismic,
name='envelope',
coords=seismic_xr.coords,
dims=seismic_xr.dims,
)
plt.figure(figsize=(15, 10))
env_xr[100].T.plot.imshow(origin='upper')
<matplotlib.image.AxesImage at 0x7f026445e700>
You could also add it to a DataSet
:
# Make a Dataset for the original amplitude data:
ds = xr.Dataset({'amplitude': seismic_xr})
ds['envelope'] = env_xr
ds
<xarray.Dataset> Dimensions: (iline: 225, xline: 300, twt: 463) Coordinates: * iline (iline) int64 0 1 2 3 4 5 6 7 ... 217 218 219 220 221 222 223 224 * xline (xline) int64 0 1 2 3 4 5 6 7 ... 292 293 294 295 296 297 298 299 * twt (twt) float64 0.0 0.004 0.008 0.012 ... 1.836 1.84 1.844 1.848 Data variables: amplitude (iline, xline, twt) float64 0.0 0.0 0.0 ... 1.0 0.4882 0.03937 envelope (iline, xline, twt) float64 0.0 0.0 0.0 ... 1.0 0.4882 0.03937
array([ 0, 1, 2, ..., 222, 223, 224])
array([ 0, 1, 2, ..., 297, 298, 299])
array([0. , 0.004, 0.008, ..., 1.84 , 1.844, 1.848])
array([[[ 0. , 0. , 0. , ..., -0.96850394, -0.38582677, 0.61417323], [ 0. , 0. , 0. , ..., -0.96062992, -0.61417323, 0.30708661], [ 0. , 0. , 0. , ..., -0.71653543, -0.64566929, 0.00787402], ..., [ 0. , 0. , 0. , ..., -0.22834646, -0.55905512, -0.30708661], [ 0. , 0. , 0. , ..., 0.15748031, -0.00787402, -0.60629921], [ 0. , 0. , 0. , ..., 0.18897638, 0.24409449, -0.39370079]], [[ 0. , 0. , 0. , ..., -0.62992126, -0.64566929, 0.12598425], [ 0. , 0. , 0. , ..., -0.67716535, -0.72440945, 0.03937008], [ 0. , 0. , 0. , ..., -0.49606299, -0.72440945, -0.31496063], ... [ 0. , 0. , 0. , ..., -0.73228346, -0.59055118, 0.16535433], [ 0. , 0. , 0. , ..., -0.1023622 , 0.63779528, 1. ], [ 0. , 0. , 0. , ..., 1. , 1. , 0.28346457]], [[ 0. , 0. , 0. , ..., 0.50393701, 0.33858268, -0.25984252], [ 0. , 0. , 0. , ..., 0.4488189 , 0.2992126 , -0.25984252], [ 0. , 0. , 0. , ..., 0.65354331, 0.39370079, -0.29133858], ..., [ 0. , 0. , 0. , ..., -0.59055118, 0.06299213, 0.93700787], [ 0. , 0. , 0. , ..., 0.73228346, 1. , 1. ], [ 0. , 0. , 0. , ..., 1. , 0.48818898, 0.03937008]]])
array([[[ 0. , 0. , 0. , ..., -0.96850394, -0.38582677, 0.61417323], [ 0. , 0. , 0. , ..., -0.96062992, -0.61417323, 0.30708661], [ 0. , 0. , 0. , ..., -0.71653543, -0.64566929, 0.00787402], ..., [ 0. , 0. , 0. , ..., -0.22834646, -0.55905512, -0.30708661], [ 0. , 0. , 0. , ..., 0.15748031, -0.00787402, -0.60629921], [ 0. , 0. , 0. , ..., 0.18897638, 0.24409449, -0.39370079]], [[ 0. , 0. , 0. , ..., -0.62992126, -0.64566929, 0.12598425], [ 0. , 0. , 0. , ..., -0.67716535, -0.72440945, 0.03937008], [ 0. , 0. , 0. , ..., -0.49606299, -0.72440945, -0.31496063], ... [ 0. , 0. , 0. , ..., -0.73228346, -0.59055118, 0.16535433], [ 0. , 0. , 0. , ..., -0.1023622 , 0.63779528, 1. ], [ 0. , 0. , 0. , ..., 1. , 1. , 0.28346457]], [[ 0. , 0. , 0. , ..., 0.50393701, 0.33858268, -0.25984252], [ 0. , 0. , 0. , ..., 0.4488189 , 0.2992126 , -0.25984252], [ 0. , 0. , 0. , ..., 0.65354331, 0.39370079, -0.29133858], ..., [ 0. , 0. , 0. , ..., -0.59055118, 0.06299213, 0.93700787], [ 0. , 0. , 0. , ..., 0.73228346, 1. , 1. ], [ 0. , 0. , 0. , ..., 1. , 0.48818898, 0.03937008]]])
© Agile Scientific 2021 — licensed CC BY / Apache 2.0