Skip to content

Instantly share code, notes, and snippets.

@kwinkunks
Created November 27, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kwinkunks/57540e112d17d6c0c5968ad51c3a6566 to your computer and use it in GitHub Desktop.
Save kwinkunks/57540e112d17d6c0c5968ad51c3a6566 to your computer and use it in GitHub Desktop.
Makes a festive and reproducible image from a wireline log
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import requests
from io import StringIO
from welly import Well
# Fetch LAS file.
url = "https://dropbox.com/s/n52qezp5byap4mi/WellA.las?raw=1"
r = requests.get(url)
las = StringIO(r.text)
# Load and condition the data.
w = Well.from_las(las)
sp = w.data['SP'].to_basis(start=170, stop=449)
sp = sp.to_basis(start=100, stop=520).smooth(10)
# Set up the figure.
fig = plt.figure(figsize=(9,12))
fig.patch.set_facecolor('navy')
ax = fig.add_subplot(111)
# Plot tree.
ax.plot(sp, sp.basis, lw=2, c='darkgreen', zorder=50)
ax.fill_betweenx(sp.basis, sp, np.nanmax(sp),
facecolor='green', zorder=40)
right = 2 * np.nanmax(sp) - sp
ax.plot(right, sp.basis, lw=2, c='green',zorder=51)
ax.fill_betweenx(sp.basis, np.nanmax(sp),right,
facecolor='limegreen', zorder=41)
ax.invert_yaxis()
# Plot the snow.
flakes = 2000
xrange = 2*np.nanmax(sp)
yrange = sp.basis[-1] - 100
size = np.random.randint(15,45, (flakes))
color = np.ones((flakes, 4))
color[:, 3] = np.random.random(flakes)
snow = np.random.random((2,flakes))
snow[0,:] = snow[0] * xrange
snow[1,:] = snow[1] * yrange + 100
back, front = np.hsplit(snow, [int(0.7*flakes)])
ax.scatter(*back, c=color, lw=0, s=size, zorder=1)
color[:, 3] = (np.random.random(flakes) + 0.5) / 1.5
ax.scatter(*front, c=color, lw=0, s=size, zorder=80)
# Plot the ground.
ground = Rectangle((0, 448), xrange, 100, color='w',
alpha=0.95, zorder=90)
ax.add_patch(ground)
# Plot star.
stardict = {'family': 'Ubuntu', 'color': 'yellow',
'rotation': '20', 'size': 240,}
ax.text(260, 220, '*', fontdict=stardict)
plt.axis('off')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment