Skip to content

Instantly share code, notes, and snippets.

@blink1073
blink1073 / mpld3_rect_plugin.py
Last active August 29, 2015 14:11
MplD3 plugin to draw a rectangle that can be manipulated
"""
Rectangle Plugin
=================
This is a demo adapted from a `matplotlib gallery example
<http://matplotlib.org/examples/shapes_and_collections/path_patch_demo.html>`_
This example adds a custom D3 plugin allowing the user to drag a
rectangle and adjust the rectangle shape.
Use the toolbar buttons at the bottom-right of the plot to enable zooming
@blink1073
blink1073 / read_csv.py
Last active August 29, 2015 14:11
Read CSV to Numpy Record using Pandas Read_CSV
import pandas as pd
import numpy as np
def read_csv(fname, **kwargs):
df = pd.read_csv(fname, **kwargs)
arrs = [df.icol(i).data for i in range(df.shape[1])]
dtype = [(h, df.dtypes[h]) for h in df.columns]
arr = np.rec.fromarrays(arrs, dtype=dtype)
arr.columns = df.columns.tolist()
@blink1073
blink1073 / aimq_msg_store.py
Last active August 29, 2015 14:11
Aimq messaging and storage
"""
AIMQ messaging:
Start with a dictionary
Convert to raw Avro
Send raw Avro over the wire
Convert to dict on the other end
@blink1073
blink1073 / skimage_py2exe_setup.diff
Created December 13, 2014 14:41
Scikit Image py2exe Changes
diff --git a/setup.py b/setup.py
index 01b6962..fa3f50e 100755
--- a/setup.py
+++ b/setup.py
@@ -20,14 +20,29 @@ DOWNLOAD_URL = 'http://github.com/scikit-image/scikit-image'
VERSION = '0.11dev'
PYTHON_VERSION = (2, 6)
-import re
import os
@blink1073
blink1073 / valgrind_report
Created December 13, 2014 10:57
Valgrind Python 2 Report for Test_Unwrap
==15942== Memcheck, a memory error detector
==15942== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==15942== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==15942== Command: /usr/bin/python skimage/restoration/tests/test_unwrap.py
==15942==
==15942== Invalid read of size 4
==15942== at 0x56E90A: PyObject_GC_Del (in /usr/bin/python2.7)
==15942== by 0x538FC6: ??? (in /usr/bin/python2.7)
==15942== by 0x54B7B5: ??? (in /usr/bin/python2.7)
==15942== by 0x579F2C: ??? (in /usr/bin/python2.7)
@blink1073
blink1073 / live_image_plugin.py
Created December 8, 2014 03:42
Python to ImageJ (FIJI) Bridge
# Live streaming 2D monochrome image receiver
# We can start this from python to view images
# So we get the live image or a current image from Python, and
# send it to ImageJ through this interface. Boom!
from ij import IJ
from ij.process import ByteProcessor, ShortProcessor, LUT
import jarray
@blink1073
blink1073 / phantom_3d.py
Last active November 6, 2023 01:38
3D Phantom
from __future__ import division
import numpy as np
def phantom3d(phantom='modified-shepp-logan', n=64):
"""Three-dimensional Shepp-Logan phantom
Can be used to test 3-D reconstruction algorithms.
Parameters
@blink1073
blink1073 / json_pickle.py
Last active August 29, 2015 14:10
Simple JSON protocol that falls back on pickle
import numpy as np
import json
import sys
try:
import cPickle as pickle
except ImportError:
import pickle
if sys.version.startswith('3'):
@blink1073
blink1073 / octave_metakernel.py
Last active August 29, 2015 14:10
Octave Metakernel
from subprocess import check_output
import os
from metakernel import ProcessMetaKernel, REPLWrapper, u
class OctaveKernel(ProcessMetaKernel):
# Identifiers:
implementation = 'octave_metakernel'
language = 'octave'
@blink1073
blink1073 / avro_ser_deser.py
Last active August 7, 2021 11:16
Avro Serializer/Deserializer with Numpy Support
from ast import literal_eval
from avro.io import DatumReader, DatumWriter, BinaryEncoder, BinaryDecoder
from avro.schema import Names, SchemaFromJSONData
import yaml
import numpy as np
class BinaryDatumWriter(object):