Skip to content

Instantly share code, notes, and snippets.

View skuschel's full-sized avatar
💡
_

Stephan Kuschel skuschel

💡
_
View GitHub Profile
@skuschel
skuschel / readpng.py
Last active February 9, 2017 15:41
Reading pngs with variable bit depth (for example: LabView wrote a png from a 12-bit camera).
def readpng(filename, hotpixelremove=False):
'''
Reads a png file and returns appropriate count vales, even if a bit depth
other than 8 or 16 is used. An example this might be needed is having a
12-bit png recorded from a 12-bit camera using LabViews IMAQ toolset.
In this case the PIL (python image library) fails to retrieve the
original count values.
'''
import png # pypng
import scipy.misc as sm
@skuschel
skuschel / BincountAndSearchsorted
Created September 22, 2014 23:49
Benchmark between numpys bincount and searchsorted functions. ipython notebook.
{
"metadata": {
"name": "",
"signature": "sha256:47fd176dfa0c93311b89f99a57b966e98062a2e958745ba99fd68a4f7f94ed68"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@skuschel
skuschel / histogrambench.py
Last active August 29, 2015 14:07
numpy histogram benchmark
#!/usr/bin/env python2
import numpy as np
import timeit
datax = np.random.random(50e6)
datay = np.random.random(50e6)
print 'creating histogram'
hist, edx, edy = np.histogram2d(datax, datay, bins=[700,700])
@skuschel
skuschel / argparsedemo.py
Created January 15, 2015 22:20
Argparse demo
#!/usr/bin/env python2
# argparse demo with multiple arguments. Try the following
# python2 argparsedemo.py xx yy --optional 5 6 7
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
@skuschel
skuschel / avgperformance.py
Last active January 29, 2019 23:34
test performance of numpy.mean and np.average functions
#!/usr/bin/env python3
#Stephan Kuschel, 2014
import timeit
s='''
import numpy as np
a = np.random.random(int(5e7))
b = np.random.random(int(5e7))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@skuschel
skuschel / python_scope.py
Created January 9, 2016 12:56
dont do this!
#!/bin/env python
# Stephan Kuschel, 2016
def f(x):
return x + y
if __name__=='__main__':
y = 2
print(f(5))
@skuschel
skuschel / addcolorbar.py
Last active August 6, 2019 13:39
Matplotlib addcolorbar
def addcolorbar(ax, im, pos='right', size='5%', pad=0.05, orientation='vertical',
stub=False, max_ticks=None, label=None):
'''
add a colorbar to a matplotlib image.
ax -- the axis object the image is drawn in
im -- the image (return value of ax.imshow(...))
When changed, please update:
https://gist.github.com/skuschel/85f0645bd6e37509164510290435a85a
@skuschel
skuschel / install ipyparallel.ipynb
Created January 20, 2017 16:33
Installs ipyparallel in userspace and activates the profile on the "IPython Clusters" tab in jupyter.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@skuschel
skuschel / epoch_exampledata.tar.xz
Last active March 6, 2018 17:19
epoch exampledata
This file has been truncated, but you can view the full file.