Skip to content

Instantly share code, notes, and snippets.

View almarklein's full-sized avatar

Almar Klein almarklein

View GitHub Profile
@almarklein
almarklein / test_warmup.py
Last active August 29, 2015 13:59
Testing warmup issue for vispy
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
from __future__ import print_function
import sys
import ctypes
@almarklein
almarklein / _angle.py
Last active August 29, 2015 14:05
angle backend that I wrote about half a year ago and is tight to Qt
# -*- coding: utf-8 -*-
# Copyright (c) 2014, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
"""
vispy backend for Qt (PySide and PyQt4).
"""
from __future__ import division
@almarklein
almarklein / vispy_pres.py
Created August 28, 2014 14:24
Vispy pres minimal
import itertools
import os
import hashlib
import numpy as np
import vispy
from vispy import app
from vispy import scene
from vispy import gloo
c:\Anaconda34>Scripts\conda-build c:\almar\devel\conda-recipes\freeimage
Removing old build environment
Removing old work directory
BUILD START: freeimage-3.17.0-vc10_1
Fetching package metadata: ......
Solving package specifications: .........
The following NEW packages will be INSTALLED:
pip: 7.1.2-py34_0
python: 3.4.3-0
@almarklein
almarklein / bokeh_line_pick.py
Last active November 24, 2015 16:01
How to pick a line among multiple lines in Bokeh
import numpy as np
from bokeh.plotting import output_notebook, show, figure
from bokeh.models import Plot, CustomJS, TapTool, ColumnDataSource, Line, DataRange1d
output_notebook()
p = figure()
t = np.linspace(0, 5, 100)
l1 = p.line(t, np.sin(t), color='#ff0000', nonselection_color='#888', line_width=5)
l2 = p.line(t, np.sin(t+1), color='#00ff00', nonselection_color='#888', line_width=5)
#l3 = p.line(t, np.sin(t+2), color='#0000ff', nonselection_color='#888', line_width=5)
class MouseEvent(Event):
""" Class describing mouse events.
Input arguments
---------------
source : object
The visualization object that this event is created from or applies to.
type : str
string indicating the event type (e.g. mouse_press, key_release)
kwds : keyword arguments
from skimage.graph.heap import BinaryHeap as BinaryHeap_sk
import time
VALUE_T = nb.float64
REFERENCE_T = nb.int32
@nb.jit # jit is slightly faster, compile time for autojit is ~2s
class BinaryHeap:
@nb.void(nb.int32)
@almarklein
almarklein / git_black_magic.py
Created August 23, 2013 19:49
Some tools for analyzing the files (also deleted files) in the repo and removing them completely from history. Warning: black magic is involved, and the commit hashes will be changed.
#!/usr/bin/env python3
"""
Functionality for cleaning up your git repository.
This uses commands found on:
https://help.github.com/articles/remove-sensitive-data
"""
class PointSet(np.ndarray):
""" The PointSet class can be used to represent sets of points or
vectors, as well as singleton points. The dimensionality of the
vectors in the pointset can be anything, and the dtype can be any
of those supported by numpy.
This class inherits from np.ndarray, which makes it very flexible;
you can threat it as a regular array, and also pass it to functions
that require a numpy array. The shape of the array is NxD, with N
the number of points, and D the dimensionality of each point.
class Image(np.ndarray):
def __new__(cls, array):
return array.view(cls)
def __repr__(self):
n = 'x'.join([str(i) for i in self.shape])
dtype = self.dtype
ndim = self.ndim
if self.shape[-1] in (1,3,4):