Skip to content

Instantly share code, notes, and snippets.

View npyoung's full-sized avatar

Noah Young npyoung

  • IndustrialNext
  • San Francisco
View GitHub Profile
@npyoung
npyoung / analyze_stack.py
Created July 11, 2017 08:30
Localize small particles and determine how the presence of cells affects their position.
#!/usr/bin/env python
import argparse as ap
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
VOXEL_SIZE = (0.2059, 0.2059, 0.5669)
@npyoung
npyoung / sympytools.py
Created June 30, 2017 07:56
Implementing Mathematica's solve and eliminate functions using SymPy
import sympy as sp
def eliminate(system, symbols):
"""Eliminates given variables from a system of equations.
Args:
system: List of SymPy equations.
symbols: List of SymPy symbols to eliminate. Must be shorter than list of equations.
Returns:
@npyoung
npyoung / .pythonrc.py
Created June 28, 2017 23:31
Python configuration
quantities_unicode = True
@npyoung
npyoung / fnrepl.sh
Last active March 7, 2017 02:11
Substring replacement in file names in the working directory
#!/bin/bash
for fn in *;
do mv "$fn" "${fn//$1/$2}";
done;
@npyoung
npyoung / range_slider_test.py
Created January 20, 2017 03:22
Bokeh server app for adjusting a data range with a slider
from bokeh.layouts import widgetbox, column
from bokeh.models.widgets import RangeSlider
from bokeh.models.ranges import Range
from bokeh.plotting import figure, curdoc
range_slider = RangeSlider(start=0, end=10, range=(1,9), step=.1, title="Stuff")
p = figure(x_range=range_slider.range)
p.line(x=range(10), y=[x**2 for x in range(10)])
@npyoung
npyoung / tone_sync.m
Created November 3, 2016 23:34
Play a tone periodically and output an analog sync signal in Matlab
% params
interval = 10;
f = 2800;
fs = 8192;
dur = 2;
% Generate waveforms
t = 0:1/fs:dur;
tone = sin(2 * pi * f * t);
@npyoung
npyoung / Vec.m
Created October 5, 2016 22:16
A simple Java Vector-like class for Matlab.
classdef Vec < handle
%VEC An efficient expandable array class
% Vec tries to emulate the behind-the-scenes array doubling behavior of the Vector class from Java.
properties(SetAccess = private, GetAccess = private)
ptr = 0
data = []
end
properties(Dependent)
@npyoung
npyoung / disk_strel.py
Created October 1, 2016 23:37
Visual demonstration of what the disk structuring element in scikit-image is and how it scales.
import numpy as np
import matplotlib.pyplot as plt
from skimage.morphology import disk
N = 5
fig, axes = plt.subplots(1, N, figsize=(16, 3))
for n, ax in enumerate(axes):
np1 = n + 1
ax.imshow(np.pad(disk(np1), N-n, 'constant'), interpolation='nearest')
c = plt.Circle((np1 + N - n, np1 + N - n), radius=np1, fill=False, lw=4, color='b')
@npyoung
npyoung / resize_img.sh
Created September 12, 2016 21:56
Resize an image by scaling it down until it matches one dimension, then cropping the other dimension to center.
fname=$1
dims="180x120"
convert "$fname" -resize "$dims^" -gravity center -crop "$dims+0+0" +repage "$fname"
@npyoung
npyoung / nbmerge.py
Created September 2, 2016 01:19 — forked from fperez/nbmerge.py
Merge/concatenate multiple IPython notebooks into one.
#!/usr/bin/env python
# Note, updated version of
# https://github.com/ipython/ipython-in-depth/blob/master/tools/nbmerge.py
"""
usage:
python nbmerge.py A.ipynb B.ipynb C.ipynb > merged.ipynb
"""
import io