Skip to content

Instantly share code, notes, and snippets.

View ptweir's full-sized avatar

Peter Weir ptweir

View GitHub Profile
@ptweir
ptweir / make_svg.py
Created March 13, 2018 23:58
code to convert to svg
#! /usr/bin/env python2.7
import matplotlib.pyplot as plt
import numpy as np
import scipy.misc
import tifffile
DOWNSAMPLE = 20 # determines the smoothing in pixels
METERS_PER_FOOT = .3048 # for conversion from feet to meters
ELEVATIONS = [-2000., -200., 0., 200., 2000.] # elevations (in feet) that will become layers
@ptweir
ptweir / SaveImageToAviEx.cpp
Created July 7, 2016 00:51
my modified version of the Point Grey camera save to avi example
//=============================================================================
// Copyright © 2009 Point Grey Research, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of Point
// Grey Research, Inc. ("Confidential Information"). You shall not
// disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with PGR.
//
// PGR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
@ptweir
ptweir / matplotlibrc
Last active June 24, 2016 18:07
matplotlibrc
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overwritten in your next install.
# If you want to keep a permanent local copy that will not be
# overwritten, place it in the following location:
# unix/linux:
# $HOME/.config/matplotlib/matplotlibrc or
import numpy as np
import matplotlib.pyplot as plt
from figurefirst import FigureLayout
layout = FigureLayout('hello_world_layout.svg')
layout.make_mplfigures()
ax = layout.axes['ax_name']['axis']
x = np.arange(10)
y = x**2
@ptweir
ptweir / fractal.py
Last active November 12, 2015 22:14
A quick script to play with recursion, fractals, and pyqtgraph
import pyqtgraph as pg
import numpy as np
import pyqtgraph.exporters
def make_tree(order, theta, sz, basePosition, heading, data):
trunk_ratio = 0.55
trunk = sz * trunk_ratio
deltaX = trunk * np.cos(heading)
deltaY = trunk * np.sin(heading)
@ptweir
ptweir / tiff.py
Last active August 29, 2015 14:14
A snippet that demonstrates using PyLibTiff to open a .tiff file containing a 2-color image stack
import numpy as np
from libtiff import TIFFfile
from libtiff import TIFF
def read(fileName):
"""
Script to import tif file from imageJ,
usage: zstack = tiff.read(inFileName)
PTW 2015/01/29
@ptweir
ptweir / open_lsm.py
Created January 8, 2015 00:39
Open a LSM image stack and display a maximum Z projection
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
from pylsm import lsmreader
imageFile = lsmreader.Lsmimage(lsmFileName)
imageFile.open()
xLen = imageFile.header['Image'][0]['CZ LSM info']['Dimension X']
yLen = imageFile.header['Image'][0]['CZ LSM info']['Dimension Y']
@ptweir
ptweir / hstack_uneven.py
Created June 10, 2014 23:43
scripts to stack two numpy arrays of possibly unequal dimensions with options for filling and dealing with truncating
import numpy as np
def hstack_uneven(a,b,mxn=max,align='top',fill=0):
heighta, widtha = a.shape[0], a.shape[1]
heightb, widthb = b.shape[0], b.shape[1]
outShape = np.array(a.shape)
outShape[0] = mxn(heighta,heightb)
outShape[1] = widtha+widthb
out = np.zeros(outShape,dtype=a.dtype)+fill
@ptweir
ptweir / discreet_time.py
Created March 22, 2014 00:41
scripts to deal with data acquired at different (or non-uniform) sample rates.
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
import scipy.interpolate
def interpolate_to_common_samplerate(Y, X=None, t=None):
if t is None:
if X is None:
t = np.arange(len(Y[0]),dtype='float')
else:
@ptweir
ptweir / makeFmfStrokelitudeMovie.py
Last active October 13, 2015 17:27
A Python script to save a .mpeg in which wingstroke amplitudes from a strokelitude .bag file are superimposed on original .fmf frames
import argparse # need to install argparse: sudo apt-get install python-argparse
import os, ast
import numpy as np
import motmot.FlyMovieFormat.FlyMovieFormat as FMF
import pylab
pylab.ion()
import roslib
roslib.load_manifest('rosbag')
import rosbag