Skip to content

Instantly share code, notes, and snippets.

@VolkerH
VolkerH / pprint_numpy.py
Created September 5, 2023 14:51 — forked from eric-wieser/pprint_numpy.py
A super janky example of how _repr_html_ could be implemented
import numpy as np
def _html_repr_helper(contents, index=()):
dims_left = contents.ndim - len(index)
if dims_left == 0:
s = contents[index]
else:
s = ''.join(_html_repr_helper(contents, index + (i,)) for i in range(contents.shape[len(index)]))
return "<div class='numpy-array-ndim-{} numpy-array-ndim-m{}' title='[{}]'>{}</div>".format(
@VolkerH
VolkerH / PY-CircleFitting.ipynb
Created March 29, 2023 11:21 — forked from WetHat/PY-CircleFitting.ipynb
Fitting a Circle to a 2d Point Cloud by Linear Least Squares
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@VolkerH
VolkerH / stable_diffusion_walk.py
Created September 1, 2022 15:07 — forked from nateraw/stable_diffusion_walk.py
Walk between stable diffusion text prompts
"""
Built on top of this gist by @karpathy:
https://gist.github.com/karpathy/00103b0037c5aaea32fe1da1af553355
stable diffusion dreaming over text prompts
creates hypnotic moving videos by smoothly walking randomly through the sample space
example way to run this script:
$ python stable_diffusion_walk.py --prompts "['blueberry spaghetti', 'strawberry spaghetti']" --seeds 243,523 --name berry_good_spaghetti
@VolkerH
VolkerH / contours.ipynb
Last active May 10, 2022 14:43
Visualize contours from cecog explorer
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@VolkerH
VolkerH / points_update.py
Created May 6, 2022 09:37
Update points for point scanner, compare different approaches.
import time
import napari
import numpy as np
from napari.qt import thread_worker
from qtpy.QtWidgets import QPushButton, QVBoxLayout, QWidget
# Point property for MALDI points
PROPNAME_ACQUIRED = "acquired"
@VolkerH
VolkerH / points_recoloring.py
Last active May 6, 2022 08:59
Point recoloring in napari
import time
import napari
import numpy as np
from napari.qt import thread_worker
from qtpy.QtWidgets import QPushButton, QVBoxLayout, QWidget
PROPNAME_ACQUIRED = "acquired"
#def generate_point_grid(nx=500, ny=100, dx=20, dy=20): # starting to lag with current napari master
def generate_point_grid(nx=1500, ny=100, dx=20, dy=20): # still working with Martin's branch
@VolkerH
VolkerH / napari_shapely.py
Created July 20, 2021 15:13
Napari to shapeley
import numpy as np
from shapely.geometry.polygon import Polygon
from shapely.geometry import GeometryCollection, LineString
def napari_shape_to_shapely(coords: np.ndarray, shape_type: str = "polygon"):
"""
Convert an individual napari shape from a shapes layer to a shapely object
There is no direct correspondence between a 'rectangle' in napari and a 'box' in
@VolkerH
VolkerH / map_array_example.ipynb
Created March 4, 2021 10:12
map_array example mapping measurements to labels
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@VolkerH
VolkerH / paramiko_example.py
Created March 2, 2021 20:50 — forked from batok/paramiko_example.py
Paramiko example using private key
import paramiko
k = paramiko.RSAKey.from_private_key_file("/Users/whatever/Downloads/mykey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "www.acme.com", username = "ubuntu", pkey = k )
print "connected"
commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ]
for command in commands:
print "Executing {}".format( command )
@VolkerH
VolkerH / feret_diameter.py
Created January 12, 2021 19:45
Calculate minimum and maximum feret diameters for connected components in label images in python
# Volker Hilsenstein
# BSD-3 license
import numpy as np
import skimage.morphology
from rotating_calipers import min_max_feret
def get_min_max_feret_from_labelim(label_im, labels=None):
""" given a label image, calculate the oriented
bounding box of each connected component with