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 / plot_stereonet.py
Last active January 12, 2021 13:33
x lines of Python: Stereonets with mplstereonet
import pandas as pd
import mplstereonet as mpl
# Load the data.
df = pd.read_csv("https://raw.githubusercontent.com/ICWallis/fractoolbox/master/testdata-fractures.csv")
# Create a stereonet with grid lines.
fig, ax = mpl.subplots(figsize=(9, 6))
ax.grid(color='k', alpha=0.2)
@kwinkunks
kwinkunks / wiggle.py
Last active October 16, 2024 14:15
Wiggle plot for seismic
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
def wiggle_2d(data,
time,
ax=None,
skip=1,
perc=99.0,
@kwinkunks
kwinkunks / polarity_cartoon.py
Last active July 20, 2020 23:58
Generate polarity cartoons with a Python CLI
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Author: Matt Hall, Agile Scientific
Licence: Apache 2.0, please re-use this code!
To use the CLI type this on the command line:
python polarity_cartoon.py --help
There is a web app running at agile.geosci.ai/polarity
@kwinkunks
kwinkunks / rms.py
Created May 26, 2020 10:43
RMS of a cube
import numpy as np
from scipy.ndimage import generic_filter
def rms_1d(trace_segment):
"""
This function runs on every piece of `size` defined in the
generic_filter, below. It returns a single value.
"""
return np.sqrt(np.sum(trace_segment**2)/trace_segment.size)
@kwinkunks
kwinkunks / Nonspatial_clustering_of_map_features.py
Created April 22, 2020 16:26
Small demo of how you might cluster mapped features, ignore (x, y) location and accounting for some NaNs around the edge.
import numpy as np
# Make some fake data
# Make array with 100 rows, 100 columns, and 6 'features' (different maps)
shape = (100, 100, 3)
data = np.random.random(shape)
# Pretend it has NaNs around edge.
data[:10] = np.nan
data[-10:] = np.nan
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / birthquakes.py
Last active October 26, 2022 09:36
Get earthquakes on your birthday
import pandas as pd
from datetime import timedelta
from urllib.parse import urlencode
def birthquakes(birthday:str) -> pd.DataFrame:
"""
Make a DataFrame of earthquakes on a given day.
Example: birthquake("1971-05-26")
@kwinkunks
kwinkunks / SEG-Y_revisions_and_segyio.md
Last active January 27, 2020 17:21
How various features map to SEG-Y Revision numbers and `segyio`'s capability
Rev 0 Rev 1 Rev 2 segyio r segyio w
Byte order
Big endian 1 1 1
Little endian 0 0 1
Pairwise byte-swapped 0 0 1
Number formats
8-bit int 0 1 1
@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."""
@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.