Skip to content

Instantly share code, notes, and snippets.

View kmader's full-sized avatar

Kevin Mader kmader

  • Zurich, Switzerland
View GitHub Profile
@kmader
kmader / branch_test.ijm
Created March 26, 2014 14:06
Branching Structure Test Image
setBackgroundColor(0,0,0)
newImage("Untitled", "8-bit black", 512, 512, 1);
makeRectangle(236, 86, 65, 218);
run("Invert");
//setTool("polygon");
makePolygon(80,368,244,275,255,305,91,395);
run("Clear", "slice");
run("Invert");
makePolygon(252,285,282,286,285,436,248,434);
run("Clear", "slice");
@kmader
kmader / spark_tests
Last active August 29, 2015 13:57
Performance tests for spark using jython
import timeit
import tipl.spark.SparkGlobal as SG
t=timeit.Timer('CLTest.main(["-boxsize=200"])',setup='import tipl.spark.CL as CLTest')
perfStats=t.repeat(20,2)
@kmader
kmader / simple_layer_code.m
Last active August 29, 2015 13:58
Read In Text File, Plot, and Run K-Means on Volume Column
simplelay=importdata('simple_layer.csv',',',1);
disp(simplelay.colheaders)
%% parse the data in matlab
% A tiny piece of code to find which column the given header is in
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,['"' colName '"']))));
% a function to return all of the data in that column
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName));
%% show the data
@kmader
kmader / findnn.m
Last active August 29, 2015 13:58
Calculate Nearest Neighbor in Matlab
% calculate nearest neighbor
function [nndist,nntheta] = findnn(xcol,ycol)
colIndex=1:length(xcol);
nndist=zeros(1,length(xcol));
nntheta=zeros(1,length(xcol));
for i=colIndex
curX=xcol(i);
curY=ycol(i);
[mindist,minind]=min(sqrt((xcol(find(colIndex~=i))-curX).^2+(ycol(find(colIndex~=i))-curY).^2));
@kmader
kmader / nndist_layer_code.m
Last active August 29, 2015 13:58
Read in text file, plot, calculate nearest neighbors, and classify based on distance
spacinglay=importdata('spacing_layer_grid.csv',',',1);
disp(spacinglay.colheaders)
%% parse the data in matlab
% A tiny piece of code to find which column the given header is in
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,['"' colName '"']))));
% a function to return all of the data in that column
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName));
%% calculate the nearest neighbor distance and angle
[nndist,nnangle]=findnn(getColumn(spacinglay,'x'),getColumn(spacinglay,'y'));
@kmader
kmader / imagej_kmeans.m
Last active August 29, 2015 13:58
Read in an analysis from ImageJ's Analyze Particles and group into different groups using k-means
imagejdata=importdata('analyzeParticlesOutput.txt','\t',1)
disp(imagejdata.colheaders)
%% parse the data in matlab
% A tiny piece of code to find which column the given header is in
% note imagej exports do not need the extra quotation marks like R does
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,[ colName ]))));
% a function to return all of the data in that column
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName));
%% calculate the nearest neighbor distance and angle
@kmader
kmader / calc_alignment.m
Created April 2, 2014 16:46
Calculate Alignment from Orientation Data
aligndata=importdata('align_a.csv',',',1)
disp(aligndata.colheaders)
%% parse the data in matlab
% A tiny piece of code to find which column the given header is in
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,['"' colName '"']))));
% a function to return all of the data in that column
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName));
@kmader
kmader / simple_layer_weighted.m
Last active August 29, 2015 13:58
Simple layers with weighted k-means
simplelay=importdata('simple_layer.csv',',',1);
disp(simplelay.colheaders)
%% parse the data in matlab
% A tiny piece of code to find which column the given header is in
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,['"' colName '"']))));
% a function to return all of the data in that column
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName));
%% show the data
@kmader
kmader / read_nn.R
Created April 3, 2014 07:00
Read in data and find nearest neighbor in R
require("ggplot2") # for plots
require("plyr") # for processing dataframes
# the function to find nearest neighbors
# requires data with x, y, and val columns (val is a unique identifier)
find.nn<-function(in.df) {
ddply(in.df,.(val),function(c.group) {
cur.val<-c.group$val[1]
cur.x<-c.group$x[1]
cur.y<-c.group$y[1]
all.butme<-subset(in.df,val!=cur.val)
@kmader
kmader / useful_commands.bash
Last active August 29, 2015 13:59
Useful Linux / Merlin Commands
# check the status of your jobs
qstat
# check the status of all jobs
qstat -u '*'
# check the status of the merlin cluster
qhost
# run an interactive analysis (default is one core and no memory)