Skip to content

Instantly share code, notes, and snippets.

View kwinkunks's full-sized avatar
🐍
Writing bugs

Matt Hall kwinkunks

🐍
Writing bugs
View GitHub Profile
@kwinkunks
kwinkunks / Mountain_heights.ipynb
Last active August 29, 2015 14:09
Heights of mountains, compared to the centre of the earth. View IPython Notebook... http://nbviewer.ipython.org/gist/kwinkunks/a449bff4c8c35952e6ce
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Seismic_acquisition_oo.ipynb
Last active August 29, 2015 14:11
Simple seismic acquisition modeling
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Colours.py
Created December 28, 2014 21:22
RGB triples for USGS lithology colours http://pubs.usgs.gov/of/2005/1314/
colours = {
'Alkali-feldpar syenite': (244, 60, 108),
'Alkali-feldspar granite': (255, 209, 220),
'Alkali-feldspar rhyolite': (254, 220, 126),
'Alkali-feldspar trachyte': (254, 183, 134),
'Alkalic intrusive rock': (255, 111, 145),
'Alkalic volcanic rock': (194, 65, 0),
'Alkaline basalt': (169, 101, 55),
'Alluvial fan': (255, 255, 183),
'Alluvial terrace': (250, 238, 122),
@kwinkunks
kwinkunks / min-char-rnn.py
Created May 28, 2016 12:42 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@kwinkunks
kwinkunks / Xmas_2017.py
Created November 27, 2017 14:29
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)
@kwinkunks
kwinkunks / README.md
Last active June 11, 2024 14:29
Matplotlib colourmaps for QGIS

mpl2qgis

See script below.

Make sure the Python file is executable. Then:

$ ./mpl2qgis.py viridis bone

This writes a file colourmaps.xml. Result:

@kwinkunks
kwinkunks / README.md
Last active March 16, 2022 08:40
Rip data from a pseudocolour image, given the colourmap

Ripping data from pseudocolour images

Because viridis, like all good colourmaps, is perceptually linear, it's easy to get the data from it: just use a greyscale version of the image. But you can rip the data from any pseudocolour image if you know (or can guess) the colourmap.

In the rip-data.py example, here's the approach:

  1. Read the image and transform the values to the range 0-1.
  2. Guess the colourmap, in this case it's viridis. Matplotlib conveniently gives us the RGB triples that make up a colourmap.
@kwinkunks
kwinkunks / blur_pure_NumPy.py
Created September 26, 2019 15:57
Implementing a 3 x 3 boxcar filter over a 2D image in pure NumPy
import numpy as np
arr = np.random.randint(0, 256, (200, 200), dtype=np.uint8)
def func(arr1d):
kernel = np.ones(3) / 3
return np.convolve(arr1d, kernel, mode='same')
first_pass = np.apply_along_axis(func, axis=0, arr=arr)
final_result = np.apply_along_axis(func, axis=1, arr=first_pass)
@kwinkunks
kwinkunks / volumes.py
Last active October 18, 2019 08:14
Two functions implementing very naive 3d spatial analysis of a point cloud
import numpy as np
import scipy.signal as ss
def to_volume(points, max_mb=10):
"""
Convert N x 3 array of points in a point cloud to a 3D image
or 'volume'. The degree of upscaling is controlled by ``max_mb``
which is the target size of the 3D image in memory.
@kwinkunks
kwinkunks / holiday19.py
Last active November 27, 2019 16:15
A holiday card for 2019
import io
import requests
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap as LSC
from scipy.interpolate import Rbf
class HolidayCard():
"""A holiday card class."""