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 / read_zmapplus.py
Created February 3, 2022 02:51 — forked from wassname/read_zmapplus.py
python function to read zmap plus asci grid format
def read_zmapplusgrid(inputfile,dtype=np.float64):
"""Read ZmapPlus grids
Format is explained here http://lists.osgeo.org/pipermail/gdal-dev/2011-June/029173.html"""
# read header, read until second '@', record header lines and content
infile = open(inputfile,'r')
comments=[]
head=[]
a=0 # count '@'s
headers=0 # cound header+comment lines
@kwinkunks
kwinkunks / dtw.py
Last active April 25, 2022 23:56
Dynamic Thing Warping
# DTW, Dynamic Thing Warping
# Where Thing might be time, or depth, or some other linear basis.
# Apache 2.0 licence.
import numpy as np
def cost(s1, s2):
"""
Very basic algorithm, no windowing.
This cost matrix algorithm was adapted from this blog post by Abhishek Mishra:
@kwinkunks
kwinkunks / aoc21-day07.py
Last active December 7, 2021 14:59
A solution to AOC 2021, Day 7
import numpy as np
def get_data(day, dataset):
with open(f'../js/day{day:02d}/{dataset}.txt', 'r') as f:
return np.array(list(map(int, f.read().split(','))))
def part1(data):
return np.abs(data - np.median(data)).sum()
def part2(data):
@kwinkunks
kwinkunks / SOM.ipynb
Last active November 14, 2021 20:27
Self-organizing maps of seismic
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Custom_colourmaps.ipynb
Last active November 9, 2021 18:40
Custom colourmaps for matplotlib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Publishable_graphics_with_Python.ipynb
Created November 8, 2021 18:47
Publishable graphics with Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Reading_files_from_the_web.ipynb
Last active January 25, 2022 13:42
Reading files from the web in various ways
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Sampling map by indexing.ipynb
Created September 29, 2021 03:06
Indexing a 2D NumPy array to sample a map
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Striplog_from_DataFrame.ipynb
Created September 27, 2021 14:08
Making a striplog from a DataFrame
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / minimum_phase.py
Created September 24, 2021 20:39
A minimum phase wavelet
from scipy.signal import remez, minimum_phase
import matplotlib.pyplot as plt
# Based on this example from the scipy docs:
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.minimum_phase.html
freq = [0, 0.2, 0.3, 1.0]
desired = [1, 0]
h_linear = remez(151, freq, desired, Hz=2.0)
h_min_hil = minimum_phase(h_linear, method='hilbert')