Skip to content

Instantly share code, notes, and snippets.

Avatar

ES-Alexander

View GitHub Profile
@ES-Alexander
ES-Alexander / voronoi.py
Last active Mar 25, 2022
image-based radial voronoi diagram with rectangular bounds
View voronoi.py
from scipy.spatial import KDTree
import matplotlib.pyplot as plt
import numpy as np
# SETUP
points = np.array([[1,2],[5,9],[-8,-2],[5,-5],[-4,-1]])
xmin, xmax, ymin, ymax = -10, 10, -10, 10
x_resolution = y_resolution = 300
pixel_size = max((xmax-xmin)/x_resolution, (ymax-ymin)/y_resolution)
radius = 3
@ES-Alexander
ES-Alexander / whalesong.py
Created Feb 14, 2022
Very rough initial analysis of some sound recordings to identify whale songs
View whalesong.py
from pathlib import Path
from scipy.io import wavfile
from scipy.fft import fft, fftfreq
import matplotlib.pyplot as plt
import numpy as np
path = Path('.') # path to whale song files
files = list(path.glob('*.wav'))
View voltage_divider.py
#!/usr/bin/env python3
from itertools import combinations_with_replacement
from typing import List, Tuple, Generator
VALID_E_SERIES = (3, 6, 12, 24, 48, 96, 192)
def E(m: int) -> Generator[float, None, None]:
""" A generator of IEEE E-series values.
@ES-Alexander
ES-Alexander / mavlogparse.py
Last active Mar 28, 2022
A MAVLink telemetry (.tlog) file parser - similarish to mavlogdump, but (I think) nicer to use and process afterwards
View mavlogparse.py
#!/usr/bin/env python3
''' Mavlink telemetry (.tlog) file parser.
Operates as a generator. Allows csv output or listing useful types/fields.
'''
import json
from pathlib import Path
from fnmatch import fnmatch
from pymavlink import mavutil
@ES-Alexander
ES-Alexander / mavactive.py
Last active May 16, 2022
An example of using `RC_OVERRIDE`s for basic vehicle control with Pymavlink
View mavactive.py
from builtins import object
from time import sleep
from threading import Thread, Event, Lock
from pymavlink import mavutil
mavlink = mavutil.mavlink
class WriteLockedFile(object):
""" A file with thread-locked writing. """
@ES-Alexander
ES-Alexander / ssa_encoder.py
Last active Oct 5, 2021
SubStation Alpha (SSA/ASS) embedded file encoder
View ssa_encoder.py
#!/usr/bin/env python3
def parse(file):
''' Generates encoded characters from file byte data.
Encoding is suitable for embedded [Graphics] in SubStation Alpha files.
See here for encoding specification and other details:
http://www.tcax.org/docs/ass-specs.htm
Bytes are split into groups of 6 bits, then 33 is added to each group
@ES-Alexander
ES-Alexander / inpaint-stitching-edges.py
Last active Oct 1, 2021
Inpaint black regions around stitched images with a blurred effect using the image edge colours.
View inpaint-stitching-edges.py
import cv2
image = cv2.imread('combine.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
mask = (gray == 0).astype('uint8') * 255
blurred = cv2.GaussianBlur(mask, (15,15), 10)
result = cv2.inpaint(image, blurred, 3, cv2.INPAINT_TELEA)
cv2.imshow('result', result)
print('press any key to exit')