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 / 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 / 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")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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
@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 / 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 / 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 / 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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / las2ppm.awk
Created March 19, 2021 13:50
Make a plain PPM image from 3 wireline logs in a LAS file
#!/usr/bin/gawk -f
#
# This file makes 8-bit RGB images from 3 logs
# The output is PLAIN (not RAW) PPM
# You need an LAS file containing only these logs
# Then run this script on that LAS file
# The Height should be set to the number of samples in the logs
#
# Set up the PGM Plain File format header
BEGIN {