See script below.
Make sure the Python file is executable. Then:
$ ./mpl2qgis.py viridis bone
This writes a file colourmaps.xml
. Result:
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), |
""" | |
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) |
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) |
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:
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) |
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. | |
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.""" |