Skip to content

Instantly share code, notes, and snippets.

View suessspeise's full-sized avatar
🍜
soup

h_campos suessspeise

🍜
soup
  • hamburg
View GitHub Profile
@suessspeise
suessspeise / pixelfy.py
Created March 12, 2026 12:45
module to apply retro pixel art effects to a PIL Image
from PIL import Image, ImageEnhance
import warnings
try: import matplotlib
except: warnings.warn('matplotlib not available.')
__all__ = ['PixelfyOps', 'Pixelfy']
class PixelfyOps:
"""
Stateless toolkit of image processing operations for the pixel art effect.
@suessspeise
suessspeise / deepfrier.py
Created January 16, 2026 00:26
a class for image frying (display function intended to be used inside a notebook)
import cv2
import numpy as np
import sklearn.cluster
import matplotlib.pyplot as plt
# https://pypi.org/project/MemePy/
# https://kitchencrafthubs.com/how-do-you-make-deep-fried-pictures/
class Deepfrier:
def __init__(self, path):
dictionary_path = "/usr/share/dict/words"
# On Unix systems you may have /usr/share/dict/words installed
# but this can really be whatever you provide
with open(dictionary_path) as f:
WORDS = {w.strip().lower() for w in f}
def in_wordlist(word):
return word.lower() in WORDS
def permutations(letters):
@suessspeise
suessspeise / make_contact_sheets.py
Last active January 28, 2025 08:26
creates a PDF with thumbnails of the contained images. designed for printing out overview pages ("contact sheets") for scanned 35mm film rolls.
import os
import re
from PIL import Image
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from datetime import datetime
def get_scan_dirs(dirname):
filelist = os.listdir(dirname)
pattern = re.compile(r'^\d{3}_\d{10}$')
@suessspeise
suessspeise / visualise_correlation.py
Created September 26, 2024 15:24
Generates a plot of random data with a specified Pearson correlation coefficient.
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats
def ax_example_correlation(ax, correlation):
"""
Generates a plot of random data with a specified Pearson correlation coefficient.
Parameters:
correlation (float): A number between 0 and 1 representing the Pearson correlation coefficient.
@suessspeise
suessspeise / rockpaperscissors.py
Created May 24, 2024 19:40
A framework for a algorhitmic rock paper scissors competition, inspired by game theory experiment setups.
from abc import ABC, abstractmethod
import json
class RPSCompetitor(ABC):
@abstractmethod
def play(self):
"""
Returns the competitor's move.
Returns:
@suessspeise
suessspeise / numpy2wav.py
Last active May 8, 2024 14:02
I wrote this AudioBuffer class to encode data with differential manchester encoding and write it to wav. With this AmplitudeBinaryEncoder it can be used to write numpy arrays to wav. The little example shows how it can be used to record a melody.
import numpy as np
import struct
class MonoAudioBuffer:
"""
A class to generate audio data and store it for playback or further processing.
Attributes:
sample_rate (int): The sample rate of the audio data.
audio_buffer (bytearray): The buffer to store the generated audio data.
@suessspeise
suessspeise / mixed_signals.py
Last active May 9, 2024 07:13
I want to make music with numpy eventually. This is a finger warming excercise.
import numpy as np
import matplotlib.pyplot as plt
def fig_time_series(t, y, focus=(0,1)):
fig, axs = plt.subplots(1, 2, figsize=(20,2))
ax = axs[0]
ax.set_title('mixed signal')
ax.plot(t,y)
ax.axvspan(*focus, color='tab:blue', alpha=0.2)
ax = axs[1]
@suessspeise
suessspeise / heart.py
Created May 2, 2024 15:53
Plots a heart
import sympy
import numpy as np
import matplotlib.pyplot as plt
# use sympy to solve for y
x, y = sympy.symbols('x y')
equation = x**2 + (y - sympy.root(x**2, 3))**2 - 1
solutions = sympy.solve(equation, y)
# nice things up
@suessspeise
suessspeise / cloud_cover_timeseries.py
Created April 16, 2024 08:14
This creates a plot of cloud cover over Disco island during the last 40 years
import os
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
def smooth_timeseries(timeseries: xr.DataArray, window_size: int = 3, method: str = 'running_mean') -> xr.DataArray:
"""
Smooths a timeseries using a specified method.
Parameters: